Skip to content

Commit 4735f66

Browse files
committed
IPv6 support: Add proper link-local and SLAAC in STA and WifiMulti
This patch partially depends on: espressif/esp32-arduino-lib-builder#67 Without this patch we will get only Link local IPv6 (still useful for MDNS and etc). With patch we will get also global IPv6 address by SLAAC. By default IPv6 disabled, until it is properly tested. Tested on BasicHttpClient by adding: wifiMulti.IPv6(true); before: wifiMulti.addAP() call Enabling Core Debug Level: verbose If IP6 obtained, in logs will be visible: [ 8028][V][WiFiGeneric.cpp:380] _arduino_event_cb(): IF[0] Got IPv6: IP Index: 0, Zone: 2, fe80:0000:0000:0000:xxxx:xxxx:xxxx:xxxx [ 8028][D][WiFiGeneric.cpp:852] _eventCallback(): Arduino Event: 8 - STA_GOT_IP6 [ 11028][V][WiFiGeneric.cpp:380] _arduino_event_cb(): IF[0] Got IPv6: IP Index: 1, Zone: 0, 2a0d:yyyy:0000:4000:yyyy:yyyy:yyyy:yyyy [ 11028][D][WiFiGeneric.cpp:852] _eventCallback(): Arduino Event: 8 - STA_GOT_IP6 This is linked to: espressif#6242 Signed-off-by: Denys Fedoryshchenko <[email protected]>
1 parent 0b3f1a9 commit 4735f66

File tree

6 files changed

+26
-2
lines changed

6 files changed

+26
-2
lines changed

Diff for: libraries/WiFi/src/WiFiGeneric.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,8 @@ esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event)
866866
} else if(event->event_id == ARDUINO_EVENT_WIFI_STA_CONNECTED) {
867867
WiFiSTAClass::_setStatus(WL_IDLE_STATUS);
868868
setStatusBits(STA_CONNECTED_BIT);
869-
870-
//esp_netif_create_ip6_linklocal(esp_netifs[ESP_IF_WIFI_STA]);
869+
if (getStatusBits() & WIFI_WANT_IP6_BIT)
870+
esp_netif_create_ip6_linklocal(esp_netifs[ESP_IF_WIFI_STA]);
871871
} else if(event->event_id == ARDUINO_EVENT_WIFI_STA_DISCONNECTED) {
872872
uint8_t reason = event->event_info.wifi_sta_disconnected.reason;
873873
log_w("Reason: %u - %s", reason, reason2str(reason));

Diff for: libraries/WiFi/src/WiFiGeneric.h

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static const int WIFI_SCANNING_BIT = BIT11;
138138
static const int WIFI_SCAN_DONE_BIT= BIT12;
139139
static const int WIFI_DNS_IDLE_BIT = BIT13;
140140
static const int WIFI_DNS_DONE_BIT = BIT14;
141+
static const int WIFI_WANT_IP6_BIT = BIT15;
141142

142143
typedef enum {
143144
WIFI_RX_ANT0 = 0,

Diff for: libraries/WiFi/src/WiFiMulti.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
WiFiMulti::WiFiMulti()
3232
{
33+
ipv6_support = false;
3334
}
3435

3536
WiFiMulti::~WiFiMulti()
@@ -160,6 +161,8 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout)
160161
log_i("[WIFI] Connecting BSSID: %02X:%02X:%02X:%02X:%02X:%02X SSID: %s Channel: %d (%d)", bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3], bestBSSID[4], bestBSSID[5], bestNetwork.ssid, bestChannel, bestNetworkDb);
161162

162163
WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
164+
if (ipv6_support == true)
165+
WiFi.IPv6(true);
163166
status = WiFi.status();
164167

165168
auto startTime = millis();
@@ -202,3 +205,7 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout)
202205

203206
return status;
204207
}
208+
209+
void WiFiMulti::IPv6(bool state) {
210+
ipv6_support = state;
211+
}

Diff for: libraries/WiFi/src/WiFiMulti.h

+2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ class WiFiMulti
4242

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

45+
void IPv6(bool state);
4546
uint8_t run(uint32_t connectTimeout=5000);
4647

4748
private:
4849
std::vector<WifiAPlist_t> APlist;
50+
bool ipv6_support;
4951
};
5052

5153
#endif /* WIFICLIENTMULTI_H_ */

Diff for: libraries/WiFi/src/WiFiSTA.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,19 @@ bool WiFiSTAClass::enableIpV6()
726726
return esp_netif_create_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_STA)) == ESP_OK;
727727
}
728728

729+
/**
730+
* Enable IPv6 support on the station interface.
731+
* @return true on success
732+
*/
733+
bool WiFiSTAClass::IPv6(bool state)
734+
{
735+
if (state)
736+
WiFiGenericClass::setStatusBits(WIFI_WANT_IP6_BIT);
737+
else
738+
WiFiGenericClass::clearStatusBits(WIFI_WANT_IP6_BIT);
739+
return true;
740+
}
741+
729742
/**
730743
* Get the station interface IPv6 address.
731744
* @return IPv6Address

Diff for: libraries/WiFi/src/WiFiSTA.h

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class WiFiSTAClass
8484
uint8_t subnetCIDR();
8585

8686
bool enableIpV6();
87+
bool IPv6(bool state);
8788
IPv6Address localIPv6();
8889

8990
// STA WiFi info

0 commit comments

Comments
 (0)