From d9e48d5be181719ec260d5c86bb3064a08c2fd9e Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 25 Dec 2018 17:50:04 +0100 Subject: [PATCH 01/11] add 1 more IPAddress constructor --- cores/esp8266/IPAddress.cpp | 5 +++++ cores/esp8266/IPAddress.h | 1 + 2 files changed, 6 insertions(+) diff --git a/cores/esp8266/IPAddress.cpp b/cores/esp8266/IPAddress.cpp index d121ba6e53..8f7ba0f624 100644 --- a/cores/esp8266/IPAddress.cpp +++ b/cores/esp8266/IPAddress.cpp @@ -27,6 +27,11 @@ IPAddress::IPAddress(const IPAddress& from) ip_addr_copy(_ip, from._ip); } +IPAddress::IPAddress(const ip_addr_t* from) +{ + ip_addr_copy(_ip, *from); +} + IPAddress::IPAddress() { _ip = *IP_ANY_TYPE; // lwIP's v4-or-v6 generic address } diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index cad12c970e..e311a251df 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -73,6 +73,7 @@ class IPAddress: public Printable { // Constructors IPAddress(); IPAddress(const IPAddress& from); + IPAddress(const ip_addr_t* 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); } From e33b35828688997ef386a280dec4e0a8ebaed3ec Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 25 Dec 2018 23:23:30 +0100 Subject: [PATCH 02/11] ditto --- cores/esp8266/IPAddress.cpp | 10 +++++----- cores/esp8266/IPAddress.h | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cores/esp8266/IPAddress.cpp b/cores/esp8266/IPAddress.cpp index 8f7ba0f624..7163517c50 100644 --- a/cores/esp8266/IPAddress.cpp +++ b/cores/esp8266/IPAddress.cpp @@ -27,11 +27,6 @@ IPAddress::IPAddress(const IPAddress& from) ip_addr_copy(_ip, from._ip); } -IPAddress::IPAddress(const ip_addr_t* from) -{ - ip_addr_copy(_ip, *from); -} - IPAddress::IPAddress() { _ip = *IP_ANY_TYPE; // lwIP's v4-or-v6 generic address } @@ -192,6 +187,11 @@ const IPAddress INADDR_NONE(255,255,255,255); #if LWIP_IPV6 +IPAddress::IPAddress(const ip_addr_t* from) +{ + ip_addr_copy(_ip, *from); +} + bool IPAddress::fromString6(const char *address) { // TODO: test test test diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index e311a251df..74c6cd3756 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -73,7 +73,6 @@ class IPAddress: public Printable { // Constructors IPAddress(); IPAddress(const IPAddress& from); - IPAddress(const ip_addr_t* 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); } @@ -164,6 +163,8 @@ class IPAddress: public Printable { #if LWIP_IPV6 + IPAddress(const ip_addr_t* from); + uint16_t* raw6() { setV6(); From 990352f633f9088539465aaa524cacfb137397d0 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 25 Dec 2018 23:32:02 +0100 Subject: [PATCH 03/11] fix IPv6 example with lwip-v1.4 --- libraries/ESP8266WiFi/examples/IPv6/IPv6.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino index eccb30ad1d..be9a3a28ed 100644 --- a/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino +++ b/libraries/ESP8266WiFi/examples/IPv6/IPv6.ino @@ -98,7 +98,11 @@ void setup() { Serial.println(); Serial.println(ESP.getFullVersion()); - Serial.printf("IPV6 is%s enabled\n", LWIP_IPV6 ? emptyString.c_str() : " NOT"); +#if LWIP_IPV6 + Serial.printf("IPV6 is enabled\n"); +#else + Serial.printf("IPV6 is not enabled\n"); +#endif WiFi.mode(WIFI_STA); WiFi.begin(STASSID, STAPSK); From 89102f4c6d56a8377de94b6aa7e8f8bb47b8edda Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 25 Dec 2018 23:55:29 +0100 Subject: [PATCH 04/11] CI with IPv6 --- tests/common.sh | 6 +++--- tools/build.py | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/common.sh b/tests/common.sh index c62369fa38..3e0d833fac 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -42,7 +42,7 @@ function build_sketches() local build_mod=$4 local build_rem=$5 mkdir -p $build_dir - local build_cmd="python tools/build.py -b generic -v -w all -s 4M1M -v -k -p $PWD/$build_dir $build_arg " + local build_cmd="python tools/build.py -b generic -v -w all -s 4M1M -v -k -p $PWD/$build_dir -n lm6f $build_arg " local sketches=$(find $srcpath -name *.ino | sort) print_size_info >size.log export ARDUINO_IDE_PATH=$arduino @@ -116,8 +116,8 @@ function install_ide() debug_flags="-DDEBUG_ESP_PORT=Serial -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_ESP_OOM" fi # Set custom warnings for all builds (i.e. could add -Wextra at some point) - echo "compiler.c.extra_flags=-Wall -Wextra -Werror -DLWIP_IPV6=0 $debug_flags" > esp8266/platform.local.txt - echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror -DLWIP_IPV6=0 $debug_flags" >> esp8266/platform.local.txt + echo "compiler.c.extra_flags=-Wall -Wextra -Werror -DLWIP_IPV6=1 $debug_flags" > esp8266/platform.local.txt + echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror -DLWIP_IPV6=1 $debug_flags" >> esp8266/platform.local.txt echo -e "\n----platform.local.txt----" cat esp8266/platform.local.txt echo -e "\n----\n" diff --git a/tools/build.py b/tools/build.py index 88f8519714..6f5579748c 100755 --- a/tools/build.py +++ b/tools/build.py @@ -50,6 +50,7 @@ def compile(tmp_dir, sketch, tools_dir, hardware_dir, ide_path, f, args): 'FlashMode={flash_mode},' \ 'baud=921600,' \ 'eesz={flash_size},' \ + 'ip={lwIP},' \ 'ResetMethod=nodemcu'.format(**vars(args)) if args.debug_port and args.debug_level: cmd += 'dbg={debug_port},lvl={debug_level}'.format(**vars(args)) @@ -85,6 +86,8 @@ def parse_args(): choices=[80, 160], type=int) parser.add_argument('-m', '--flash_mode', help='Flash mode', default='qio', choices=['dio', 'qio']) + parser.add_argument('-n', '--lwIP', help='lwIP version', default='lm2f', + choices=['lm2f', 'hb2f', 'lm6f', 'hb6f', 'hb1']) parser.add_argument('-w', '--warnings', help='Compilation warnings level', default='none', choices=['none', 'all', 'more']) parser.add_argument('-o', '--output_binary', help='File name for output binary') From 0bb032daa74d0d045f777f849ead0ac39cf779e7 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 26 Dec 2018 00:09:19 +0100 Subject: [PATCH 05/11] CI with IPv6 as an option --- .travis.yml | 8 ++++++++ tests/common.sh | 31 +++++++++++++++++++++++-------- tests/run_CI_locally.sh | 26 ++++++++++++++------------ 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 84c1ddcca6..0e0e5282e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,14 @@ jobs: script: $TRAVIS_BUILD_DIR/tests/common.sh env: - BUILD_TYPE=debug_odd + - name: "Build IPv6 (1)" + script: $TRAVIS_BUILD_DIR/tests/common.sh + env: + - BUILD_TYPE=build6_even + - name: "Build IPv6 (2)" + script: $TRAVIS_BUILD_DIR/tests/common.sh + env: + - BUILD_TYPE=build6_odd - name: "Platformio (1)" script: $TRAVIS_BUILD_DIR/tests/common.sh env: diff --git a/tests/common.sh b/tests/common.sh index 3e0d833fac..71234115f1 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -104,6 +104,7 @@ function install_ide() local ide_path=$1 local core_path=$2 local debug=$3 + local ipv6=$4 test -r arduino.tar.xz || wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz tar xf arduino.tar.xz mv arduino-nightly $ide_path @@ -115,9 +116,13 @@ function install_ide() if [ "$debug" = "debug" ]; then debug_flags="-DDEBUG_ESP_PORT=Serial -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_ESP_OOM" fi + local ipv6_flags="-DLWIP_IPV6=0" + if [ "$ipv6" = "ipv6" ]; then + ipv6_flags="-DLWIP_IPV6=1" + fi # Set custom warnings for all builds (i.e. could add -Wextra at some point) - echo "compiler.c.extra_flags=-Wall -Wextra -Werror -DLWIP_IPV6=1 $debug_flags" > esp8266/platform.local.txt - echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror -DLWIP_IPV6=1 $debug_flags" >> esp8266/platform.local.txt + echo "compiler.c.extra_flags=-Wall -Wextra -Werror $ipv6_flags $debug_flags" > esp8266/platform.local.txt + echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror $ipv6_flags $debug_flags" >> esp8266/platform.local.txt echo -e "\n----platform.local.txt----" cat esp8266/platform.local.txt echo -e "\n----\n" @@ -182,10 +187,11 @@ function build_sketches_with_platformio() function install_arduino() { local debug=$1 + local ipv6=$2 # Install Arduino IDE and required libraries echo -e "travis_fold:start:sketch_test_env_prepare" cd $TRAVIS_BUILD_DIR - install_ide $HOME/arduino_ide $TRAVIS_BUILD_DIR $debug + install_ide $HOME/arduino_ide $TRAVIS_BUILD_DIR $debug $ipv6 which arduino cd $TRAVIS_BUILD_DIR install_libraries @@ -220,19 +226,28 @@ if [ -z "$TRAVIS_BUILD_DIR" ]; then fi if [ "$BUILD_TYPE" = "build" ]; then - install_arduino nodebug + install_arduino nodebug ipv4 + build_sketches_with_arduino 1 0 +if [ "$BUILD_TYPE" = "build6" ]; then + install_arduino nodebug ipv6 build_sketches_with_arduino 1 0 elif [ "$BUILD_TYPE" = "build_even" ]; then - install_arduino nodebug + install_arduino nodebug ipv4 build_sketches_with_arduino 2 0 elif [ "$BUILD_TYPE" = "build_odd" ]; then - install_arduino nodebug + install_arduino nodebug ipv4 build_sketches_with_arduino 2 1 elif [ "$BUILD_TYPE" = "debug_even" ]; then - install_arduino debug + install_arduino debug ipv4 build_sketches_with_arduino 2 0 elif [ "$BUILD_TYPE" = "debug_odd" ]; then - install_arduino debug + install_arduino debug ipv4 + build_sketches_with_arduino 2 1 +elif [ "$BUILD_TYPE" = "build6_even" ]; then + install_arduino nodebug ipv6 + build_sketches_with_arduino 2 0 +elif [ "$BUILD_TYPE" = "build6_odd" ]; then + install_arduino nodebug ipv6 build_sketches_with_arduino 2 1 elif [ "$BUILD_TYPE" = "platformio" ]; then # PlatformIO diff --git a/tests/run_CI_locally.sh b/tests/run_CI_locally.sh index a872e6f989..2518069bff 100755 --- a/tests/run_CI_locally.sh +++ b/tests/run_CI_locally.sh @@ -53,12 +53,13 @@ while true; do cat << EOF Which build? 1. main -2. debug even -3. debug odd -4. platformio -5. package -6. host -7. style +2. main + IPv6 +3. debug even +4. debug odd +5. platformio +6. package +7. host +8. style EOF read ans @@ -66,12 +67,13 @@ EOF BUILD_TYPE="" case "$ans" in 1) BUILD_TYPE=build;; - 2) BUILD_TYPE=debug_even;; - 3) BUILD_TYPE=debug_odd;; - 4) BUILD_TYPE=platformio;; - 5) BUILD_TYPE=package;; - 6) BUILD_TYPE=host;; - 7) BUILD_TYPE=style;; + 2) BUILD_TYPE=build6;; + 3) BUILD_TYPE=debug_even;; + 4) BUILD_TYPE=debug_odd;; + 5) BUILD_TYPE=platformio;; + 6) BUILD_TYPE=package;; + 7) BUILD_TYPE=host;; + 8) BUILD_TYPE=style;; esac test -z "$BUILD_TYPE" || break done From b4cdc5e1c376db4a226f2c076f44acb6b3c77a18 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 26 Dec 2018 00:11:30 +0100 Subject: [PATCH 06/11] ditto typo --- tests/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common.sh b/tests/common.sh index 71234115f1..625fa38c3f 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -228,7 +228,7 @@ fi if [ "$BUILD_TYPE" = "build" ]; then install_arduino nodebug ipv4 build_sketches_with_arduino 1 0 -if [ "$BUILD_TYPE" = "build6" ]; then +elif [ "$BUILD_TYPE" = "build6" ]; then install_arduino nodebug ipv6 build_sketches_with_arduino 1 0 elif [ "$BUILD_TYPE" = "build_even" ]; then From eab33cf681111d8426c0d9a52a9dd4e82f9576cf Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 26 Dec 2018 00:23:36 +0100 Subject: [PATCH 07/11] fix XI with IPv6 --- tests/common.sh | 50 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/tests/common.sh b/tests/common.sh index 625fa38c3f..e3b8fd8d14 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -41,8 +41,9 @@ function build_sketches() local build_dir=build.tmp local build_mod=$4 local build_rem=$5 + local lwip=$6 mkdir -p $build_dir - local build_cmd="python tools/build.py -b generic -v -w all -s 4M1M -v -k -p $PWD/$build_dir -n lm6f $build_arg " + local build_cmd="python tools/build.py -b generic -v -w all -s 4M1M -v -k -p $PWD/$build_dir -n $lwip $build_arg " local sketches=$(find $srcpath -name *.ino | sort) print_size_info >size.log export ARDUINO_IDE_PATH=$arduino @@ -104,7 +105,6 @@ function install_ide() local ide_path=$1 local core_path=$2 local debug=$3 - local ipv6=$4 test -r arduino.tar.xz || wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz tar xf arduino.tar.xz mv arduino-nightly $ide_path @@ -116,13 +116,9 @@ function install_ide() if [ "$debug" = "debug" ]; then debug_flags="-DDEBUG_ESP_PORT=Serial -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_ESP_OOM" fi - local ipv6_flags="-DLWIP_IPV6=0" - if [ "$ipv6" = "ipv6" ]; then - ipv6_flags="-DLWIP_IPV6=1" - fi # Set custom warnings for all builds (i.e. could add -Wextra at some point) - echo "compiler.c.extra_flags=-Wall -Wextra -Werror $ipv6_flags $debug_flags" > esp8266/platform.local.txt - echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror $ipv6_flags $debug_flags" >> esp8266/platform.local.txt + echo "compiler.c.extra_flags=-Wall -Wextra -Werror $debug_flags" > esp8266/platform.local.txt + echo "compiler.cpp.extra_flags=-Wall -Wextra -Werror $debug_flags" >> esp8266/platform.local.txt echo -e "\n----platform.local.txt----" cat esp8266/platform.local.txt echo -e "\n----\n" @@ -187,11 +183,10 @@ function build_sketches_with_platformio() function install_arduino() { local debug=$1 - local ipv6=$2 # Install Arduino IDE and required libraries echo -e "travis_fold:start:sketch_test_env_prepare" cd $TRAVIS_BUILD_DIR - install_ide $HOME/arduino_ide $TRAVIS_BUILD_DIR $debug $ipv6 + install_ide $HOME/arduino_ide $TRAVIS_BUILD_DIR $debug which arduino cd $TRAVIS_BUILD_DIR install_libraries @@ -202,10 +197,11 @@ function build_sketches_with_arduino() { local build_mod=$1 local build_rem=$2 + local lwip=$3 # Compile sketches echo -e "travis_fold:start:sketch_test" - build_sketches $HOME/arduino_ide $TRAVIS_BUILD_DIR/libraries "-l $HOME/Arduino/libraries" $1 $2 + build_sketches $HOME/arduino_ide $TRAVIS_BUILD_DIR/libraries "-l $HOME/Arduino/libraries" $build_mod $build_rem $lwip echo -e "travis_fold:end:sketch_test" # Generate size report @@ -226,29 +222,29 @@ if [ -z "$TRAVIS_BUILD_DIR" ]; then fi if [ "$BUILD_TYPE" = "build" ]; then - install_arduino nodebug ipv4 - build_sketches_with_arduino 1 0 + install_arduino nodebug + build_sketches_with_arduino 1 0 lm2f elif [ "$BUILD_TYPE" = "build6" ]; then - install_arduino nodebug ipv6 - build_sketches_with_arduino 1 0 + install_arduino nodebug + build_sketches_with_arduino 1 0 lm2f elif [ "$BUILD_TYPE" = "build_even" ]; then - install_arduino nodebug ipv4 - build_sketches_with_arduino 2 0 + install_arduino nodebug + build_sketches_with_arduino 2 0 lm2f elif [ "$BUILD_TYPE" = "build_odd" ]; then - install_arduino nodebug ipv4 - build_sketches_with_arduino 2 1 + install_arduino nodebug + build_sketches_with_arduino 2 1 lm2f elif [ "$BUILD_TYPE" = "debug_even" ]; then - install_arduino debug ipv4 - build_sketches_with_arduino 2 0 + install_arduino debug + build_sketches_with_arduino 2 0 lm2f elif [ "$BUILD_TYPE" = "debug_odd" ]; then - install_arduino debug ipv4 - build_sketches_with_arduino 2 1 + install_arduino debug + build_sketches_with_arduino 2 1 lm2f elif [ "$BUILD_TYPE" = "build6_even" ]; then - install_arduino nodebug ipv6 - build_sketches_with_arduino 2 0 + install_arduino nodebug + build_sketches_with_arduino 2 0 lm6f elif [ "$BUILD_TYPE" = "build6_odd" ]; then - install_arduino nodebug ipv6 - build_sketches_with_arduino 2 1 + install_arduino nodebug + build_sketches_with_arduino 2 1 lm6f elif [ "$BUILD_TYPE" = "platformio" ]; then # PlatformIO install_platformio From 220c85d85336f685ce9e993a3a230089bc35c784 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 26 Dec 2018 00:27:18 +0100 Subject: [PATCH 08/11] wip --- tests/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common.sh b/tests/common.sh index e3b8fd8d14..25b7b0a286 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -226,7 +226,7 @@ if [ "$BUILD_TYPE" = "build" ]; then build_sketches_with_arduino 1 0 lm2f elif [ "$BUILD_TYPE" = "build6" ]; then install_arduino nodebug - build_sketches_with_arduino 1 0 lm2f + build_sketches_with_arduino 1 0 lm6f elif [ "$BUILD_TYPE" = "build_even" ]; then install_arduino nodebug build_sketches_with_arduino 2 0 lm2f From d6756316d6a693ce67a5a7fa44943c83ba954561 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 26 Dec 2018 17:04:30 +0100 Subject: [PATCH 09/11] Use IPAddress instead of ip*addr* types, where necessary, with IPAddress & UDP compatibility updates --- cores/esp8266/IPAddress.cpp | 5 --- cores/esp8266/IPAddress.h | 5 +-- .../ESP8266WiFi/src/include/UdpContext.h | 13 +++---- libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp | 4 +-- libraries/ESP8266mDNS/src/LEAmDNS_Helpers.cpp | 9 +++-- .../ESP8266mDNS/src/LEAmDNS_Transfer.cpp | 36 ++++++++----------- 6 files changed, 29 insertions(+), 43 deletions(-) diff --git a/cores/esp8266/IPAddress.cpp b/cores/esp8266/IPAddress.cpp index 7163517c50..d121ba6e53 100644 --- a/cores/esp8266/IPAddress.cpp +++ b/cores/esp8266/IPAddress.cpp @@ -187,11 +187,6 @@ const IPAddress INADDR_NONE(255,255,255,255); #if LWIP_IPV6 -IPAddress::IPAddress(const ip_addr_t* from) -{ - ip_addr_copy(_ip, *from); -} - bool IPAddress::fromString6(const char *address) { // TODO: test test test diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index 74c6cd3756..e93e6cc3c4 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -149,8 +149,8 @@ class IPAddress: public Printable { /* lwIP address compatibility */ + IPAddress(const ipv4_addr& fw_addr) { setV4(); v4() = fw_addr.addr; } IPAddress(const ipv4_addr* fw_addr) { setV4(); v4() = fw_addr->addr; } - IPAddress(const ip_addr_t& lwip_addr) { _ip = lwip_addr; } operator ip_addr_t () const { return _ip; } operator const ip_addr_t*() const { return &_ip; } @@ -163,7 +163,8 @@ class IPAddress: public Printable { #if LWIP_IPV6 - IPAddress(const ip_addr_t* from); + IPAddress(const ip_addr_t& lwip_addr) { ip_addr_copy(_ip, lwip_addr); } + IPAddress(const ip_addr_t* lwip_addr) { ip_addr_copy(_ip, *lwip_addr); } uint16_t* raw6() { diff --git a/libraries/ESP8266WiFi/src/include/UdpContext.h b/libraries/ESP8266WiFi/src/include/UdpContext.h index 65d429c34e..af67ae140a 100644 --- a/libraries/ESP8266WiFi/src/include/UdpContext.h +++ b/libraries/ESP8266WiFi/src/include/UdpContext.h @@ -107,17 +107,14 @@ class UdpContext udp_disconnect(_pcb); } -#if LWIP_VERSION_MAJOR == 1 - void setMulticastInterface(const ip_addr_t addr) + void setMulticastInterface(const IPAddress& addr) { - udp_set_multicast_netif_addr(_pcb, addr); - } +#if LWIP_VERSION_MAJOR == 1 + udp_set_multicast_netif_addr(_pcb, (ip_addr_t)addr); #else - void setMulticastInterface(const ip_addr_t* addr) - { - udp_set_multicast_netif_addr(_pcb, ip_2_ip4(addr)); - } + udp_set_multicast_netif_addr(_pcb, ip_2_ip4((const ip_addr_t*)addr)); #endif + } void setMulticastTTL(int ttl) { diff --git a/libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp b/libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp index 483d1a2577..42de7c29b2 100644 --- a/libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp +++ b/libraries/ESP8266mDNS/src/LEAmDNS_Control.cpp @@ -244,9 +244,9 @@ bool MDNSResponder::_parseQuery(const MDNSResponder::stcMDNS_MsgHeader& p_MsgHea ip_info IPInfo_Remote; if (((IPInfo_Remote.ip.addr = m_pUDPContext->getRemoteAddress())) && (((wifi_get_ip_info(SOFTAP_IF, &IPInfo_Local)) && - (ip_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))) || // Remote IP in SOFTAP's subnet OR + (ip4_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))) || // Remote IP in SOFTAP's subnet OR ((wifi_get_ip_info(STATION_IF, &IPInfo_Local)) && - (ip_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))))) { // Remote IP in STATION's subnet + (ip4_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))))) { // Remote IP in STATION's subnet DEBUG_EX_RX(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _parseQuery: Legacy query from local host %s!\n"), IPAddress(m_pUDPContext->getRemoteAddress()).toString().c_str());); diff --git a/libraries/ESP8266mDNS/src/LEAmDNS_Helpers.cpp b/libraries/ESP8266mDNS/src/LEAmDNS_Helpers.cpp index e8a555e4cb..bf7d8f8495 100644 --- a/libraries/ESP8266mDNS/src/LEAmDNS_Helpers.cpp +++ b/libraries/ESP8266mDNS/src/LEAmDNS_Helpers.cpp @@ -191,19 +191,18 @@ bool MDNSResponder::_allocUDPContext(void) { _releaseUDPContext(); - ip_addr_t multicast_addr; #ifdef MDNS_IP4_SUPPORT - multicast_addr.addr = DNS_MQUERY_IPV4_GROUP_INIT; + ip_addr_t multicast_addr = DNS_MQUERY_IPV4_GROUP_INIT; #endif #ifdef MDNS_IP6_SUPPORT - //TODO: set multicast address + //TODO: set multicast address (lwip_joingroup() is IPv4 only at the time of writing) multicast_addr.addr = DNS_MQUERY_IPV6_GROUP_INIT; #endif - if (ERR_OK == igmp_joingroup(IP_ADDR_ANY, &multicast_addr)) { + if (ERR_OK == igmp_joingroup(IP4_ADDR_ANY4, ip_2_ip4(&multicast_addr))) { m_pUDPContext = new UdpContext; m_pUDPContext->ref(); - if (m_pUDPContext->listen(IP_ADDR_ANY, DNS_MQUERY_PORT)) { + if (m_pUDPContext->listen(IP4_ADDR_ANY, DNS_MQUERY_PORT)) { m_pUDPContext->setMulticastTTL(MDNS_MULTICAST_TTL); m_pUDPContext->onRx(std::bind(&MDNSResponder::_callProcess, this)); diff --git a/libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp b/libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp index f380497905..e163d64daa 100644 --- a/libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp +++ b/libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp @@ -79,10 +79,10 @@ bool MDNSResponder::_sendMDNSMessage(MDNSResponder::stcMDNSSendParameter& p_rSen if (p_rSendParameter.m_bResponse) { if (p_rSendParameter.m_bUnicast) { // Unicast response -> Send to querier DEBUG_EX_ERR(if (!m_pUDPContext->getRemoteAddress()) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage: MISSING remote address for response!\n")); }); - ip_addr_t ipRemote; - ipRemote.addr = m_pUDPContext->getRemoteAddress(); + IPAddress ipRemote; + ipRemote = m_pUDPContext->getRemoteAddress(); bResult = ((_prepareMDNSMessage(p_rSendParameter, _getResponseMulticastInterface(SOFTAP_MODE | STATION_MODE))) && - (m_pUDPContext->send(&ipRemote, m_pUDPContext->getRemotePort()))); + (m_pUDPContext->send(ipRemote, m_pUDPContext->getRemotePort()))); } else { // Multicast response -> Send via the same network interface, that received the query bResult = _sendMDNSMessage_Multicast(p_rSendParameter, (SOFTAP_MODE | STATION_MODE)); @@ -116,26 +116,20 @@ bool MDNSResponder::_sendMDNSMessage_Multicast(MDNSResponder::stcMDNSSendParamet int p_iWiFiOpMode) { bool bResult = false; - ip_addr_t ifFromAddress; - ifFromAddress.addr = _getResponseMulticastInterface(p_iWiFiOpMode); - IPAddress fromIPAddress(ifFromAddress.addr); -#if LWIP_VERSION_MAJOR == 1 - m_pUDPContext->setMulticastInterface(ifFromAddress); -#else - m_pUDPContext->setMulticastInterface(&ifFromAddress); -#endif + IPAddress fromIPAddress; + fromIPAddress = _getResponseMulticastInterface(p_iWiFiOpMode); + m_pUDPContext->setMulticastInterface(fromIPAddress); - ip_addr_t toMulticastAddress; #ifdef MDNS_IP4_SUPPORT - toMulticastAddress.addr = DNS_MQUERY_IPV4_GROUP_INIT; + IPAddress toMulticastAddress(DNS_MQUERY_IPV4_GROUP_INIT); #endif #ifdef MDNS_IP6_SUPPORT //TODO: set multicast address - toMulticastAddress.addr = DNS_MQUERY_IPV6_GROUP_INIT; + IPAddress toMulticastAddress(DNS_MQUERY_IPV6_GROUP_INIT); #endif - DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage_Multicast: Will send to '%s'.\n"), IPAddress(toMulticastAddress.addr).toString().c_str());); + DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage_Multicast: Will send to '%s'.\n"), toMulticastAddress.toString().c_str());); bResult = ((_prepareMDNSMessage(p_rSendParameter, fromIPAddress)) && - (m_pUDPContext->send(&toMulticastAddress, DNS_MQUERY_PORT))); + (m_pUDPContext->send(toMulticastAddress, DNS_MQUERY_PORT))); DEBUG_EX_ERR(if (!bResult) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _sendMDNSMessage_Multicast: FAILED!\n")); }); return bResult; @@ -385,13 +379,13 @@ IPAddress MDNSResponder::_getResponseMulticastInterface(int p_iWiFiOpModes) cons (wifi_get_opmode() & SOFTAP_MODE)) { //DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface: SOFTAP_MODE\n"));); // Get remote IP address - ip_info IPInfo_Remote; - IPInfo_Remote.ip.addr = m_pUDPContext->getRemoteAddress(); + IPAddress IP_Remote; + IP_Remote = m_pUDPContext->getRemoteAddress(); // Get local (AP) IP address wifi_get_ip_info(SOFTAP_IF, &IPInfo_Local); if ((IPInfo_Local.ip.addr) && // Has local AP IP address AND - (ip_addr_netcmp(&IPInfo_Remote.ip, &IPInfo_Local.ip, &IPInfo_Local.netmask))) { // Remote address is in the same subnet as the AP + (ip4_addr_netcmp(ip_2_ip4((const ip_addr_t*)IP_Remote), &IPInfo_Local.ip, &IPInfo_Local.netmask))) { // Remote address is in the same subnet as the AP bFoundMatch = true; } } @@ -402,8 +396,8 @@ IPAddress MDNSResponder::_getResponseMulticastInterface(int p_iWiFiOpModes) cons // Get local (STATION) IP address wifi_get_ip_info(STATION_IF, &IPInfo_Local); } - //DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface(%i): %s\n"), p_iWiFiOpModes, IPAddress(IPInfo_Local.ip.addr).toString().c_str());); - return IPAddress(IPInfo_Local.ip.addr); + //DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] _getResponseMulticastInterface(%i): %s\n"), p_iWiFiOpModes, IPAddress(IPInfo_Local.ip).toString().c_str());); + return IPAddress(IPInfo_Local.ip); } From 9ac8dbab50e2c5a677995e4f4c2771290886027f Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 26 Dec 2018 18:18:27 +0100 Subject: [PATCH 10/11] fix AVRISP --- libraries/ESP8266AVRISP/src/ESP8266AVRISP.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libraries/ESP8266AVRISP/src/ESP8266AVRISP.cpp b/libraries/ESP8266AVRISP/src/ESP8266AVRISP.cpp index 5742aff729..187c917530 100644 --- a/libraries/ESP8266AVRISP/src/ESP8266AVRISP.cpp +++ b/libraries/ESP8266AVRISP/src/ESP8266AVRISP.cpp @@ -74,10 +74,7 @@ AVRISPState_t ESP8266AVRISP::update() { if (_server.hasClient()) { _client = _server.available(); _client.setNoDelay(true); - ip_addr_t lip; - lip.addr = _client.remoteIP(); - AVRISP_DEBUG("client connect %d.%d.%d.%d:%d", IP2STR(&lip), _client.remotePort()); - (void) lip; // Avoid unused warning when not in debug mode + AVRISP_DEBUG("client connect %s:%d", _client.remoteIP().toString().c_str(), _client.remotePort()); _client.setTimeout(100); // for getch() _state = AVRISP_STATE_PENDING; _reject_incoming(); From 3c749b0468ef9fdb63fe68b067cdff1a384021e1 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 26 Dec 2018 18:52:11 +0100 Subject: [PATCH 11/11] fix NetBios --- libraries/ESP8266NetBIOS/ESP8266NetBIOS.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libraries/ESP8266NetBIOS/ESP8266NetBIOS.cpp b/libraries/ESP8266NetBIOS/ESP8266NetBIOS.cpp index 0174e450a8..6e021c8877 100644 --- a/libraries/ESP8266NetBIOS/ESP8266NetBIOS.cpp +++ b/libraries/ESP8266NetBIOS/ESP8266NetBIOS.cpp @@ -154,11 +154,9 @@ bool ESP8266NetBIOS::begin(const char *name) if(_pcb != NULL) { return true; } - ip_addr_t addr; - addr.addr = INADDR_ANY; _pcb = udp_new(); udp_recv(_pcb, &_s_recv, (void *) this); - err_t err = udp_bind(_pcb, &addr, NBNS_PORT); + err_t err = udp_bind(_pcb, INADDR_ANY, NBNS_PORT); if(err != ERR_OK) { end(); return false; @@ -182,9 +180,13 @@ void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, CONST ip_addr_t *addr, uint1 while(pb != NULL) { uint8_t * data = (uint8_t*)((pb)->payload); size_t len = pb->len; - ip_hdr* iphdr = reinterpret_cast(data - UDP_HLEN - IP_HLEN); - ip_addr_t saddr; - saddr.addr = iphdr->src.addr; +#if LWIP_VERSION_MAJOR == 1 + // check UdpContext.h + const ip_addr_t* saddr = ¤t_iphdr_src; +#else + // check UdpContext.h + const ip_addr_t* saddr = &ip_data.current_iphdr_src; +#endif if (len >= sizeof(struct NBNSQUESTION)) { struct NBNSQUESTION * question = (struct NBNSQUESTION *)data; @@ -221,7 +223,7 @@ void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, CONST ip_addr_t *addr, uint1 if(pbt != NULL) { uint8_t* dst = reinterpret_cast(pbt->payload); memcpy(dst, (uint8_t *)&nbnsa, sizeof(nbnsa)); - udp_sendto(_pcb, pbt, &saddr, NBNS_PORT); + udp_sendto(_pcb, pbt, saddr, NBNS_PORT); pbuf_free(pbt); } } else if (0 == strcmp(name, "*")) { @@ -251,7 +253,7 @@ void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, CONST ip_addr_t *addr, uint1 if(pbt != NULL) { uint8_t* dst = reinterpret_cast(pbt->payload); memcpy(dst, (uint8_t *)&nbnsan, sizeof(nbnsan)); - udp_sendto(_pcb, pbt, &saddr, NBNS_PORT); + udp_sendto(_pcb, pbt, saddr, NBNS_PORT); pbuf_free(pbt); } }