Skip to content

Commit f0cc721

Browse files
committed
Make IPv6 compatible with Core3 official
1 parent 2b23ded commit f0cc721

File tree

8 files changed

+46
-11
lines changed

8 files changed

+46
-11
lines changed

cores/esp32/IPAddress.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ IPAddress::IPAddress() {
3131
// _ip = *IP_ANY_TYPE; // lwIP's v4-or-v6 generic address
3232
}
3333

34+
IPAddress::IPAddress(IPType type) {
35+
if (type == IPv6) {
36+
_ip = *IP6_ADDR_ANY;
37+
} else {
38+
_ip = *IP_ADDR_ANY;
39+
}
40+
}
41+
3442
IPAddress::IPAddress(const IPAddress& from)
3543
{
3644
ip_addr_copy(_ip, from._ip);
@@ -199,7 +207,7 @@ size_t IPAddress::printTo(Print& p) const {
199207
return n;
200208
}
201209

202-
String IPAddress::toString() const
210+
String IPAddress::toString(bool includeZone) const
203211
{
204212
StreamString sstr;
205213
#if LWIP_IPV6
@@ -247,6 +255,24 @@ bool IPAddress::fromString6(const char *address) {
247255
}
248256
return false;
249257
}
258+
259+
// compatibillity with Core3
260+
261+
esp_ip6_addr_type_t IPAddress::addr_type() const {
262+
if(_ip.type != IPv6){
263+
return ESP_IP6_ADDR_IS_UNKNOWN;
264+
}
265+
return esp_netif_ip6_get_addr_type((esp_ip6_addr_t*)(&(_ip.u_addr.ip6)));
266+
}
267+
268+
void IPAddress::to_ip_addr_t(ip_addr_t* addr) const {
269+
ip_addr_copy(*addr, _ip);
270+
}
271+
272+
IPAddress& IPAddress::from_ip_addr_t(const ip_addr_t* addr) {
273+
ip_addr_copy(_ip, *addr);
274+
return *this;
275+
}
250276
#endif // LWIP_IPV6
251277

252278
// declared one time - as external in IPAddress.h

cores/esp32/IPAddress.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
#include <WString.h>
2424
#include <Printable.h>
2525
#include <lwip/netif.h>
26+
#include "esp_netif_ip_addr.h"
2627

27-
enum IPType
28+
enum IPType : uint8_t
2829
{
2930
IPv4 = IPADDR_TYPE_V4,
3031
IPv6 = IPADDR_TYPE_V6
@@ -51,6 +52,7 @@ class IPAddress: public Printable
5152
public:
5253
// Constructors
5354
IPAddress();
55+
IPAddress(IPType type);
5456
IPAddress(const IPAddress& from);
5557
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
5658
IPAddress(uint8_t o1, uint8_t o2, uint8_t o3, uint8_t o4, uint8_t o5, uint8_t o6, uint8_t o7, uint8_t o8, uint8_t o9, uint8_t o10, uint8_t o11, uint8_t o12, uint8_t o13, uint8_t o14, uint8_t o15, uint8_t o16);
@@ -117,7 +119,8 @@ class IPAddress: public Printable
117119
IPType type() const { return (IPType)_ip.type; }
118120

119121
virtual size_t printTo(Print& p) const;
120-
String toString() const;
122+
// String toString() const;
123+
String toString(bool includeZone = false) const ;
121124

122125
void clear();
123126

@@ -180,6 +183,10 @@ class IPAddress: public Printable
180183
}
181184
}
182185

186+
// compatibility with Core3 version
187+
esp_ip6_addr_type_t addr_type() const;
188+
void to_ip_addr_t(ip_addr_t* addr) const;
189+
IPAddress& from_ip_addr_t(const ip_addr_t* addr);
183190

184191
protected:
185192
bool fromString6(const char *address);

libraries/Ethernet/src/ETH.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class ETHClass {
8686
uint8_t linkSpeed();
8787

8888
bool enableIpV6();
89+
bool enableIPv6() { return enableIpV6(); };
8990
IPv6Address localIPv6();
9091

9192
IPAddress localIP();

libraries/WiFi/src/WiFiGeneric.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ static const int WIFI_DNS_IDLE_BIT = BIT13;
140140
static const int WIFI_DNS_DONE_BIT = BIT14;
141141
static const int WIFI_WANT_IP6_BIT = BIT15;
142142

143+
// Compatibility with Core3
144+
static const int NET_DNS_IDLE_BIT = WIFI_DNS_IDLE_BIT;
145+
static const int NET_DNS_DONE_BIT = WIFI_DNS_DONE_BIT;
146+
143147
typedef enum {
144148
WIFI_RX_ANT0 = 0,
145149
WIFI_RX_ANT1,

libraries/WiFi/src/WiFiMulti.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout)
162162

163163
WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
164164
if (ipv6_support == true)
165-
WiFi.IPv6(true);
165+
WiFi.enableIPv6(true);
166166
status = WiFi.status();
167167

168168
auto startTime = millis();
@@ -206,6 +206,3 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout)
206206
return status;
207207
}
208208

209-
void WiFiMulti::IPv6(bool state) {
210-
ipv6_support = state;
211-
}

libraries/WiFi/src/WiFiMulti.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class WiFiMulti
4242

4343
bool addAP(const char* ssid, const char *passphrase = NULL);
4444

45-
void IPv6(bool state);
45+
void enableIPv6(bool state = true) { ipv6_support = state; }
4646
uint8_t run(uint32_t connectTimeout=5000);
4747

4848
private:

libraries/WiFi/src/WiFiSTA.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,13 +691,12 @@ bool WiFiSTAClass::enableIpV6()
691691
* Enable IPv6 support on the station interface.
692692
* @return true on success
693693
*/
694-
bool WiFiSTAClass::IPv6(bool state)
694+
void WiFiSTAClass::enableIPv6(bool state)
695695
{
696696
if (state)
697697
WiFiGenericClass::setStatusBits(WIFI_WANT_IP6_BIT);
698698
else
699699
WiFiGenericClass::clearStatusBits(WIFI_WANT_IP6_BIT);
700-
return true;
701700
}
702701

703702
/**

libraries/WiFi/src/WiFiSTA.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class WiFiSTAClass
9191
uint8_t subnetCIDR();
9292

9393
bool enableIpV6();
94-
bool IPv6(bool state);
94+
bool IPv6(bool state) { enableIPv6(state); return true; };
95+
void enableIPv6(bool state = true);
9596
IPv6Address localIPv6();
9697

9798
// STA WiFi info

0 commit comments

Comments
 (0)