diff --git a/cores/beken-72xx/arduino/libraries/WiFi/WiFiGeneric.cpp b/cores/beken-72xx/arduino/libraries/WiFi/WiFiGeneric.cpp index 1374c76d3..42b4737be 100644 --- a/cores/beken-72xx/arduino/libraries/WiFi/WiFiGeneric.cpp +++ b/cores/beken-72xx/arduino/libraries/WiFi/WiFiGeneric.cpp @@ -80,7 +80,30 @@ IPAddress WiFiClass::hostByName(const char *hostname) { ip_addr_t ip; int ret = netconn_gethostbyname(hostname, &ip); if (ret == ERR_OK) { - return ip.addr; +#ifdef CONFIG_IPV6 + if (IP_IS_V6(&ip)) { + ip6_addr_t *ip6 = ip_2_ip6(&ip); + return IPAddress( + IP6_ADDR_BLOCK1(ip6) >> 8, + IP6_ADDR_BLOCK1(ip6) & 0xff, + IP6_ADDR_BLOCK2(ip6) >> 8, + IP6_ADDR_BLOCK2(ip6) & 0xff, + IP6_ADDR_BLOCK3(ip6) >> 8, + IP6_ADDR_BLOCK3(ip6) & 0xff, + IP6_ADDR_BLOCK4(ip6) >> 8, + IP6_ADDR_BLOCK4(ip6) & 0xff, + IP6_ADDR_BLOCK5(ip6) >> 8, + IP6_ADDR_BLOCK5(ip6) & 0xff, + IP6_ADDR_BLOCK6(ip6) >> 8, + IP6_ADDR_BLOCK6(ip6) & 0xff, + IP6_ADDR_BLOCK7(ip6) >> 8, + IP6_ADDR_BLOCK7(ip6) & 0xff, + IP6_ADDR_BLOCK8(ip6) >> 8, + IP6_ADDR_BLOCK8(ip6) & 0xff + ); + } +#endif + return IPAddress(ip_addr_get_ip4_u32(&ip)); } return IPAddress(); } diff --git a/cores/beken-72xx/arduino/libraries/WiFi/WiFiSTA.cpp b/cores/beken-72xx/arduino/libraries/WiFi/WiFiSTA.cpp index a5558d101..ee24e1707 100644 --- a/cores/beken-72xx/arduino/libraries/WiFi/WiFiSTA.cpp +++ b/cores/beken-72xx/arduino/libraries/WiFi/WiFiSTA.cpp @@ -246,3 +246,41 @@ WiFiAuthMode WiFiClass::getEncryption() { STA_GET_LINK_STATUS_RETURN(WIFI_AUTH_INVALID); return securityTypeToAuthMode(LINK_STATUS.security); } +#ifdef CONFIG_IPV6 +bool WiFiClass::enableIpV6() { + return true; +} + +IPv6Address WiFiClass::localIPv6() { + struct netif *ifs = (struct netif *)net_get_sta_handle(); + std::vector result; + struct wlan_ip_config addr; + int nr_addresses = 0; + + if (sta_ip_is_start()) + nr_addresses = net_get_if_ipv6_pref_addr(&addr, ifs); + + for (int i = 0; i < nr_addresses; i++) { + if (ip6_addr_islinklocal(&addr.ipv6[i])) + return IPv6Address(addr.ipv6[i].addr); + } + + return IPv6Address(); +} + +std::vector WiFiClass::allLocalIPv6() { + struct netif *ifs = (struct netif *)net_get_sta_handle(); + std::vector result; + struct wlan_ip_config addr; + int nr_addresses = 0; + + if (sta_ip_is_start()) + nr_addresses = net_get_if_ipv6_pref_addr(&addr, ifs); + + for (int i = 0; i < nr_addresses; i++) { + result.push_back(IPv6Address(addr.ipv6[i].addr)); + } + + return result; +} +#endif diff --git a/cores/beken-72xx/base/config/lwipopts.h b/cores/beken-72xx/base/config/lwipopts.h index 07408f1fa..728c2a829 100644 --- a/cores/beken-72xx/base/config/lwipopts.h +++ b/cores/beken-72xx/base/config/lwipopts.h @@ -10,8 +10,10 @@ #define LWIP_NETIF_EXT_STATUS_CALLBACK 1 #define MEMP_NUM_UDP_PCB (MAX_SOCKETS_UDP + 2 + 1) +#ifndef CONFIG_IPV6 #define ip_addr ip4_addr #define ip_addr_t ip4_addr_t +#endif // increase TCP/IP thread stack size (was 512) #undef TCPIP_THREAD_STACKSIZE diff --git a/cores/common/arduino/libraries/api/WiFi/WiFi.h b/cores/common/arduino/libraries/api/WiFi/WiFi.h index 92e0266ce..f77797324 100644 --- a/cores/common/arduino/libraries/api/WiFi/WiFi.h +++ b/cores/common/arduino/libraries/api/WiFi/WiFi.h @@ -129,6 +129,8 @@ class WiFiClass { uint8_t subnetCIDR(); bool enableIpV6(); IPv6Address localIPv6(); + std::vector allLocalIPv6(); + const char *getHostname(); bool setHostname(const char *hostname); bool setMacAddress(const uint8_t *mac); diff --git a/cores/common/arduino/libraries/api/WiFi/WiFiSTA.cpp b/cores/common/arduino/libraries/api/WiFi/WiFiSTA.cpp index 684cc6399..9fcfe59dd 100644 --- a/cores/common/arduino/libraries/api/WiFi/WiFiSTA.cpp +++ b/cores/common/arduino/libraries/api/WiFi/WiFiSTA.cpp @@ -44,5 +44,9 @@ __attribute__((weak)) bool WiFiClass::enableIpV6() { } __attribute__((weak)) IPv6Address WiFiClass::localIPv6() { - return IPv6Address(); + return {}; +} + +__attribute__((weak)) std::vector WiFiClass::allLocalIPv6() { + return {}; } diff --git a/cores/common/arduino/libraries/common/mDNS/LwIPmDNS.cpp b/cores/common/arduino/libraries/common/mDNS/LwIPmDNS.cpp index 0b8c435df..6b0a47616 100644 --- a/cores/common/arduino/libraries/common/mDNS/LwIPmDNS.cpp +++ b/cores/common/arduino/libraries/common/mDNS/LwIPmDNS.cpp @@ -73,9 +73,15 @@ static void mdnsTxtCallback(struct mdns_service *service, void *userdata) { } } +#if LWIP_VERSION_SIMPLE < 20200 // TTL removed in LwIP commit 62fb2fd749b (2.2.0 release) static void mdnsStatusCallback(struct netif *netif, uint8_t result) { LT_DM(MDNS, "Status: netif %u, status %u", netif->num, result); } +#else +static void mdnsStatusCallback(struct netif *netif, uint8_t result, int8_t slot) { + LT_DM(MDNS, "Status: netif %u, status %u slot %d", netif->num, result, slot); +} +#endif #ifdef LWIP_NETIF_EXT_STATUS_CALLBACK static void addServices(struct netif *netif) { @@ -95,7 +101,9 @@ static void addServices(struct netif *netif) { services[i], (mdns_sd_proto)protos[i], ports[i], +#if LWIP_VERSION_SIMPLE < 20200 // TTL removed in LwIP commit 62fb2fd749b (2.2.0 release) 255, +#endif mdnsTxtCallback, reinterpret_cast(i) // index of newly added service ); @@ -111,7 +119,11 @@ static bool enableMDNS(struct netif *netif) { igmp_start(netif); LT_DM(MDNS, "Added IGMP to netif %u", netif->num); } +#if LWIP_VERSION_SIMPLE < 20200 // TTL removed in LwIP commit 62fb2fd749b (2.2.0 release) err_t ret = mdns_resp_add_netif(netif, hostName, 255); +#else + err_t ret = mdns_resp_add_netif(netif, hostName); +#endif if (ret == ERR_OK) { LT_DM(MDNS, "mDNS started on netif %u, announcing it to network", netif->num); #if LWIP_VERSION_SIMPLE >= 20100 @@ -190,7 +202,9 @@ bool mDNS::addServiceImpl(const char *name, const char *service, uint8_t proto, service, (mdns_sd_proto)proto, port, +#if LWIP_VERSION_SIMPLE < 20200 // TTL removed in LwIP commit 62fb2fd749b (2.2.0 release) 255, +#endif mdnsTxtCallback, (void *)services.size() // index of newly added service ); diff --git a/external-libs.json b/external-libs.json index 264e7ba39..9df463188 100644 --- a/external-libs.json +++ b/external-libs.json @@ -90,9 +90,10 @@ "+", "+", "+", + "+", "+", "+", - "+", + "+", "+", "+", "+" @@ -110,9 +111,10 @@ "+", "+", "+", + "+", "+", "+", - "+", + "+", "+", "+" ], @@ -128,9 +130,10 @@ "+", "+", "+", + "+", "+", "+", - "+", + "+", "+", "+", "+" diff --git a/platform.json b/platform.json index f8b81ba2c..6dbf3505a 100644 --- a/platform.json +++ b/platform.json @@ -67,7 +67,8 @@ "2.0.2": "2.0.2-bdk", "2.1.0": "2.1.0-bdk", "2.1.3": "2.1.3-bdk", - "default": "2.1.3-bdk" + "2.2.0": "2.2.0-bdk", + "default": "2.2.0-bdk" } } },