Skip to content

Commit 701d35f

Browse files
committed
Some cleanup and do not print zone in IPAddress
1 parent c4f366c commit 701d35f

File tree

10 files changed

+120
-83
lines changed

10 files changed

+120
-83
lines changed

cores/esp32/IPAddress.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,12 @@ size_t IPAddress::printTo(Print& p) const
355355
}
356356
}
357357
// add a zone if zone-id is non-zero
358-
if(_zone > 0){
359-
n += p.print('%');
360-
char if_name[NETIF_NAMESIZE];
361-
netif_index_to_name(_zone, if_name);
362-
n += p.print(if_name);
363-
}
358+
// if(_zone > 0){
359+
// n += p.print('%');
360+
// char if_name[NETIF_NAMESIZE];
361+
// netif_index_to_name(_zone, if_name);
362+
// n += p.print(if_name);
363+
// }
364364
return n;
365365
}
366366

docs/source/api/wifi.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ Function used to enable the IPv6 support.
334334

335335
.. code-block:: arduino
336336
337-
bool softAPenableIPv6();
337+
bool softAPenableIPv6(bool enable=true);
338338
339339
The function will return ``true`` if the configuration is successful.
340340

libraries/Ethernet/src/ETH.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,13 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq,
401401

402402
// Init SPI bus
403403
if(_pin_sck >= 0 && _pin_miso >= 0 && _pin_mosi >= 0){
404-
spi_bus_config_t buscfg = {
405-
.mosi_io_num = _pin_mosi,
406-
.miso_io_num = _pin_miso,
407-
.sclk_io_num = _pin_sck,
408-
.quadwp_io_num = -1,
409-
.quadhd_io_num = -1,
410-
};
404+
spi_bus_config_t buscfg;
405+
memset(&buscfg, 0, sizeof(spi_bus_config_t));
406+
buscfg.mosi_io_num = _pin_mosi;
407+
buscfg.miso_io_num = _pin_miso;
408+
buscfg.sclk_io_num = _pin_sck;
409+
buscfg.quadwp_io_num = -1;
410+
buscfg.quadhd_io_num = -1;
411411
ret = spi_bus_initialize(spi_host, &buscfg, SPI_DMA_CH_AUTO);
412412
if(ret != ESP_OK){
413413
log_e("SPI bus initialize failed: %d", ret);
@@ -433,13 +433,13 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq,
433433
phy_config.reset_gpio_num = _pin_rst;
434434

435435
// Configure SPI interface for specific SPI module
436-
spi_device_interface_config_t spi_devcfg = {
437-
.mode = 0,
438-
.clock_speed_hz = _spi_freq_mhz * 1000 * 1000,
439-
.input_delay_ns = 20,
440-
.spics_io_num = _pin_cs,
441-
.queue_size = 20,
442-
};
436+
spi_device_interface_config_t spi_devcfg;
437+
memset(&spi_devcfg, 0, sizeof(spi_device_interface_config_t));
438+
spi_devcfg.mode = 0;
439+
spi_devcfg.clock_speed_hz = _spi_freq_mhz * 1000 * 1000;
440+
spi_devcfg.input_delay_ns = 20;
441+
spi_devcfg.spics_io_num = _pin_cs;
442+
spi_devcfg.queue_size = 20;
443443

444444
esp_eth_mac_t *mac = NULL;
445445
esp_eth_phy_t *phy = NULL;
@@ -863,15 +863,16 @@ bool ETHClass::setHostname(const char * hostname)
863863

864864
bool ETHClass::enableIPv6(bool en)
865865
{
866-
if(_esp_netif == NULL){
867-
return false;
866+
// if(_esp_netif == NULL){
867+
// return false;
868+
// }
869+
// return esp_netif_create_ip6_linklocal(_esp_netif) == 0;
870+
if (en) {
871+
WiFiGenericClass::setStatusBits(ETH_WANT_IP6_BIT);
872+
} else {
873+
WiFiGenericClass::clearStatusBits(ETH_WANT_IP6_BIT);
868874
}
869-
return esp_netif_create_ip6_linklocal(_esp_netif) == 0;
870-
// if (en)
871-
// WiFiGenericClass::setStatusBits(ETH_WANT_IP6_BIT);
872-
// else
873-
// WiFiGenericClass::clearStatusBits(ETH_WANT_IP6_BIT);
874-
// return true;
875+
return true;
875876
}
876877

877878
IPAddress ETHClass::localIPv6()
@@ -1048,7 +1049,7 @@ void ETHClass::printInfo(Print & out){
10481049
out.print(dnsIP());
10491050
out.println();
10501051

1051-
const char * types[] = { "UNKNOWN", "GLOBAL", "LINK_LOCAL", "SITE_LOCAL", "UNIQUE_LOCAL", "IPV4_MAPPED_IPV6" };
1052+
static const char * types[] = { "UNKNOWN", "GLOBAL", "LINK_LOCAL", "SITE_LOCAL", "UNIQUE_LOCAL", "IPV4_MAPPED_IPV6" };
10521053
esp_ip6_addr_t if_ip6[5];
10531054
int v6addrs = esp_netif_get_all_ip6(_esp_netif, if_ip6);
10541055
for (int i = 0; i < v6addrs; ++i){

libraries/WiFi/examples/WiFiIPv6/WiFiIPv6.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ void WiFiEvent(WiFiEvent_t event){
7070
case ARDUINO_EVENT_WIFI_AP_START:
7171
//can set ap hostname here
7272
WiFi.softAPsetHostname(AP_SSID);
73-
//enable ap ipv6 here
74-
WiFi.softAPenableIPv6();
7573
break;
7674
case ARDUINO_EVENT_WIFI_STA_START:
7775
//set sta hostname here
@@ -105,6 +103,8 @@ void setup(){
105103
WiFi.disconnect(true);
106104
WiFi.onEvent(WiFiEvent); // Will call WiFiEvent() from another thread.
107105
WiFi.mode(WIFI_MODE_APSTA);
106+
//enable ap ipv6 here
107+
WiFi.softAPenableIPv6();
108108
WiFi.softAP(AP_SSID);
109109
//enable sta ipv6 here
110110
WiFi.enableIPv6();

libraries/WiFi/src/WiFiAP.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,18 @@ bool WiFiAPClass::softAPsetHostname(const char * hostname)
411411
* Enable IPv6 on the softAP interface.
412412
* @return true on success
413413
*/
414-
bool WiFiAPClass::softAPenableIPv6()
414+
bool WiFiAPClass::softAPenableIPv6(bool enable)
415415
{
416-
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
417-
return false;
416+
if (enable) {
417+
WiFiGenericClass::setStatusBits(AP_WANT_IP6_BIT);
418+
} else {
419+
WiFiGenericClass::clearStatusBits(AP_WANT_IP6_BIT);
418420
}
419-
return esp_netif_create_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_AP)) == ESP_OK;
421+
return true;
422+
// if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
423+
// return false;
424+
// }
425+
// return esp_netif_create_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_AP)) == ESP_OK;
420426
}
421427

422428
/**
@@ -430,6 +436,7 @@ IPAddress WiFiAPClass::softAPIPv6()
430436
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
431437
return IPAddress(IPv6);
432438
}
439+
433440
if(esp_netif_get_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_STA), &addr)){
434441
return IPAddress(IPv6);
435442
}

libraries/WiFi/src/WiFiAP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class WiFiAPClass
5656
IPAddress softAPSubnetMask();
5757
uint8_t softAPSubnetCIDR();
5858

59-
bool softAPenableIPv6();
59+
bool softAPenableIPv6(bool enable=true);
6060
IPAddress softAPIPv6();
6161

6262
const char * softAPgetHostname();

libraries/WiFi/src/WiFiGeneric.cpp

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ extern "C" {
4242
#include "lwip/opt.h"
4343
#include "lwip/err.h"
4444
#include "lwip/dns.h"
45+
#include "lwip/netif.h"
4546
#include "dhcpserver/dhcpserver.h"
4647
#include "dhcpserver/dhcpserver_options.h"
4748

@@ -459,7 +460,13 @@ static void _arduino_event_cb(void* arg, esp_event_base_t event_base, int32_t ev
459460
} else if (event_base == IP_EVENT && event_id == IP_EVENT_GOT_IP6) {
460461
ip_event_got_ip6_t * event = (ip_event_got_ip6_t*)event_data;
461462
esp_interface_t iface = get_esp_netif_interface(event->esp_netif);
462-
log_v("IF[%d] Got IPv6: IP Index: %d, Zone: %d, " IPV6STR, iface, event->ip_index, event->ip6_info.ip.zone, IPV62STR(event->ip6_info.ip));
463+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
464+
char if_name[NETIF_NAMESIZE] = {0,};
465+
netif_index_to_name(event->ip6_info.ip.zone, if_name);
466+
esp_ip6_addr_type_t addr_type = esp_netif_ip6_get_addr_type(&event->ip6_info.ip);
467+
static const char * addr_types[] = { "UNKNOWN", "GLOBAL", "LINK_LOCAL", "SITE_LOCAL", "UNIQUE_LOCAL", "IPV4_MAPPED_IPV6" };
468+
log_v("IF %s Got IPv6: Interface: %d, IP Index: %d, Type: %s, Zone: %d (%s), Address: " IPV6STR, esp_netif_get_desc(event->esp_netif), iface, event->ip_index, addr_types[addr_type], event->ip6_info.ip.zone, if_name, IPV62STR(event->ip6_info.ip));
469+
#endif
463470
memcpy(&arduino_event.event_info.got_ip6, event_data, sizeof(ip_event_got_ip6_t));
464471
if(iface == ESP_IF_WIFI_STA){
465472
arduino_event.event_id = ARDUINO_EVENT_WIFI_STA_GOT_IP6;
@@ -554,14 +561,16 @@ static void _arduino_event_cb(void* arg, esp_event_base_t event_base, int32_t ev
554561
}
555562
}
556563

564+
static uint32_t _initial_bits = NET_DNS_IDLE_BIT;
565+
557566
static bool _start_network_event_task(){
558567
if(!_arduino_event_group){
559568
_arduino_event_group = xEventGroupCreate();
560569
if(!_arduino_event_group){
561570
log_e("Network Event Group Create Failed!");
562571
return false;
563572
}
564-
xEventGroupSetBits(_arduino_event_group, WIFI_DNS_IDLE_BIT);
573+
xEventGroupSetBits(_arduino_event_group, _initial_bits);
565574
}
566575
if(!_arduino_event_queue){
567576
_arduino_event_queue = xQueueCreate(32, sizeof(arduino_event_t*));
@@ -909,21 +918,23 @@ bool WiFiGenericClass::setHostname(const char * hostname)
909918

910919
int WiFiGenericClass::setStatusBits(int bits){
911920
if(!_arduino_event_group){
912-
return 0;
921+
_initial_bits |= bits;
922+
return _initial_bits;
913923
}
914924
return xEventGroupSetBits(_arduino_event_group, bits);
915925
}
916926

917927
int WiFiGenericClass::clearStatusBits(int bits){
918928
if(!_arduino_event_group){
919-
return 0;
929+
_initial_bits &= ~bits;
930+
return _initial_bits;
920931
}
921932
return xEventGroupClearBits(_arduino_event_group, bits);
922933
}
923934

924935
int WiFiGenericClass::getStatusBits(){
925936
if(!_arduino_event_group){
926-
return 0;
937+
return _initial_bits;
927938
}
928939
return xEventGroupGetBits(_arduino_event_group);
929940
}
@@ -1114,6 +1125,9 @@ esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event)
11141125

11151126
} else if(event->event_id == ARDUINO_EVENT_WIFI_AP_START) {
11161127
setStatusBits(AP_STARTED_BIT);
1128+
if (getStatusBits() & AP_WANT_IP6_BIT){
1129+
esp_netif_create_ip6_linklocal(get_esp_interface_netif(ESP_IF_WIFI_AP));
1130+
}
11171131
} else if(event->event_id == ARDUINO_EVENT_WIFI_AP_STOP) {
11181132
clearStatusBits(AP_STARTED_BIT | AP_HAS_CLIENT_BIT);
11191133
} else if(event->event_id == ARDUINO_EVENT_WIFI_AP_STACONNECTED) {
@@ -1150,16 +1164,25 @@ esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event)
11501164
clearStatusBits(ETH_HAS_IP_BIT);
11511165

11521166
} else if(event->event_id == ARDUINO_EVENT_WIFI_STA_GOT_IP6) {
1153-
setStatusBits(STA_CONNECTED_BIT | STA_HAS_IP6_BIT);
1154-
if(esp_netif_ip6_get_addr_type((esp_ip6_addr_t*)&(event->event_info.got_ip6.ip6_info.ip)) == ESP_IP6_ADDR_IS_GLOBAL){
1167+
setStatusBits(STA_CONNECTED_BIT);
1168+
esp_ip6_addr_type_t addr_type = esp_netif_ip6_get_addr_type((esp_ip6_addr_t*)&(event->event_info.got_ip6.ip6_info.ip));
1169+
if(addr_type == ESP_IP6_ADDR_IS_GLOBAL){
11551170
setStatusBits(STA_HAS_IP6_GLOBAL_BIT);
1171+
} else if(addr_type == ESP_IP6_ADDR_IS_LINK_LOCAL){
1172+
setStatusBits(STA_HAS_IP6_BIT);
11561173
}
11571174
} else if(event->event_id == ARDUINO_EVENT_WIFI_AP_GOT_IP6) {
1158-
setStatusBits(AP_HAS_IP6_BIT);
1175+
esp_ip6_addr_type_t addr_type = esp_netif_ip6_get_addr_type((esp_ip6_addr_t*)&(event->event_info.got_ip6.ip6_info.ip));
1176+
if(addr_type == ESP_IP6_ADDR_IS_LINK_LOCAL){
1177+
setStatusBits(AP_HAS_IP6_BIT);
1178+
}
11591179
} else if(event->event_id == ARDUINO_EVENT_ETH_GOT_IP6) {
1160-
setStatusBits(ETH_CONNECTED_BIT | ETH_HAS_IP6_BIT);
1161-
if(esp_netif_ip6_get_addr_type((esp_ip6_addr_t*)&(event->event_info.got_ip6.ip6_info.ip)) == ESP_IP6_ADDR_IS_GLOBAL){
1180+
setStatusBits(ETH_CONNECTED_BIT);
1181+
esp_ip6_addr_type_t addr_type = esp_netif_ip6_get_addr_type((esp_ip6_addr_t*)&(event->event_info.got_ip6.ip6_info.ip));
1182+
if(addr_type == ESP_IP6_ADDR_IS_GLOBAL){
11621183
setStatusBits(ETH_HAS_IP6_GLOBAL_BIT);
1184+
} else if(addr_type == ESP_IP6_ADDR_IS_LINK_LOCAL){
1185+
setStatusBits(ETH_HAS_IP6_BIT);
11631186
}
11641187
} else if(event->event_id == ARDUINO_EVENT_SC_GOT_SSID_PSWD) {
11651188
WiFi.begin(
@@ -1589,7 +1612,7 @@ static void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, v
15891612
} else {
15901613
parameters->result = -1;
15911614
}
1592-
xEventGroupSetBits(_arduino_event_group, WIFI_DNS_DONE_BIT);
1615+
xEventGroupSetBits(_arduino_event_group, NET_DNS_DONE_BIT);
15931616
}
15941617

15951618
/**
@@ -1632,8 +1655,8 @@ int WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, bool
16321655
aResult.to_ip_addr_t(&(params.addr));
16331656

16341657
if (!aResult.fromString(aHostname)) {
1635-
waitStatusBits(WIFI_DNS_IDLE_BIT, 16000);
1636-
clearStatusBits(WIFI_DNS_IDLE_BIT | WIFI_DNS_DONE_BIT);
1658+
waitStatusBits(NET_DNS_IDLE_BIT, 16000);
1659+
clearStatusBits(NET_DNS_IDLE_BIT | NET_DNS_DONE_BIT);
16371660

16381661
err = esp_netif_tcpip_exec(wifi_gethostbyname_tcpip_ctx, &params);
16391662
if (err == ERR_OK) {
@@ -1646,14 +1669,14 @@ int WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, bool
16461669
}
16471670
Serial.println();
16481671
} else if (err == ERR_INPROGRESS) {
1649-
waitStatusBits(WIFI_DNS_DONE_BIT, 15000); //real internal timeout in lwip library is 14[s]
1650-
clearStatusBits(WIFI_DNS_DONE_BIT);
1672+
waitStatusBits(NET_DNS_DONE_BIT, 15000); //real internal timeout in lwip library is 14[s]
1673+
clearStatusBits(NET_DNS_DONE_BIT);
16511674
if (params.result == 1) {
16521675
aResult.from_ip_addr_t(&(params.addr));
16531676
err = ERR_OK;
16541677
}
16551678
}
1656-
setStatusBits(WIFI_DNS_IDLE_BIT);
1679+
setStatusBits(NET_DNS_IDLE_BIT);
16571680
}
16581681
if (err == ERR_OK) {
16591682
return 1;

libraries/WiFi/src/WiFiGeneric.h

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,34 @@ typedef void (*WiFiEventSysCb)(arduino_event_t *event);
112112

113113
typedef size_t wifi_event_id_t;
114114

115+
// General Flags
116+
static const int NET_DNS_IDLE_BIT = BIT0;
117+
static const int NET_DNS_DONE_BIT = BIT1;
118+
// WiFi Scan Flags
119+
static const int WIFI_SCANNING_BIT = BIT2;
120+
static const int WIFI_SCAN_DONE_BIT = BIT3;
121+
// AP Flags
122+
static const int AP_STARTED_BIT = BIT4;
123+
static const int AP_HAS_IP6_BIT = BIT5;
124+
static const int AP_HAS_CLIENT_BIT = BIT6;
125+
static const int AP_WANT_IP6_BIT = BIT7;
126+
// STA Flags
127+
static const int STA_STARTED_BIT = BIT8;
128+
static const int STA_CONNECTED_BIT = BIT9;
129+
static const int STA_HAS_IP_BIT = BIT10;
130+
static const int STA_HAS_IP6_BIT = BIT11;
131+
static const int STA_HAS_IP6_GLOBAL_BIT = BIT12;
132+
static const int STA_WANT_IP6_BIT = BIT13;
133+
// ETH Flags
134+
static const int ETH_STARTED_BIT = BIT14;
135+
static const int ETH_CONNECTED_BIT = BIT15;
136+
static const int ETH_HAS_IP_BIT = BIT16;
137+
static const int ETH_HAS_IP6_BIT = BIT17;
138+
static const int ETH_HAS_IP6_GLOBAL_BIT = BIT18;
139+
static const int ETH_WANT_IP6_BIT = BIT19;
140+
// Masks
141+
static const int NET_HAS_IP6_GLOBAL_BIT = STA_HAS_IP6_GLOBAL_BIT | ETH_HAS_IP6_GLOBAL_BIT;
142+
115143
typedef enum {
116144
WIFI_POWER_19_5dBm = 78,// 19.5dBm
117145
WIFI_POWER_19dBm = 76,// 19dBm
@@ -127,30 +155,6 @@ typedef enum {
127155
WIFI_POWER_MINUS_1dBm = -4// -1dBm
128156
} wifi_power_t;
129157

130-
static const int AP_STARTED_BIT = BIT0;
131-
static const int AP_HAS_IP6_BIT = BIT1;
132-
static const int AP_HAS_CLIENT_BIT = BIT2;
133-
static const int STA_STARTED_BIT = BIT3;
134-
static const int STA_CONNECTED_BIT = BIT4;
135-
static const int STA_HAS_IP_BIT = BIT5;
136-
static const int STA_HAS_IP6_BIT = BIT6;
137-
static const int ETH_STARTED_BIT = BIT7;
138-
static const int ETH_CONNECTED_BIT = BIT8;
139-
static const int ETH_HAS_IP_BIT = BIT9;
140-
static const int ETH_HAS_IP6_BIT = BIT10;
141-
142-
static const int WIFI_SCANNING_BIT = BIT11;
143-
static const int WIFI_SCAN_DONE_BIT= BIT12;
144-
static const int WIFI_DNS_IDLE_BIT = BIT13;
145-
static const int WIFI_DNS_DONE_BIT = BIT14;
146-
147-
static const int STA_WANT_IP6_BIT = BIT15;
148-
static const int ETH_WANT_IP6_BIT = BIT16;
149-
150-
static const int STA_HAS_IP6_GLOBAL_BIT = BIT17;
151-
static const int ETH_HAS_IP6_GLOBAL_BIT = BIT18;
152-
static const int NET_HAS_IP6_GLOBAL_BIT = STA_HAS_IP6_GLOBAL_BIT | ETH_HAS_IP6_GLOBAL_BIT;
153-
154158
typedef enum {
155159
WIFI_RX_ANT0 = 0,
156160
WIFI_RX_ANT1,

libraries/WiFi/src/WiFiMulti.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ uint8_t WiFiMulti::run(uint32_t connectTimeout)
160160
if(bestNetwork.ssid) {
161161
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);
162162

163-
if (ipv6_support == true)
163+
if (ipv6_support == true) {
164164
WiFi.enableIPv6();
165+
}
165166
WiFi.begin(bestNetwork.ssid, bestNetwork.passphrase, bestChannel, bestBSSID);
166167
status = WiFi.status();
167168

0 commit comments

Comments
 (0)