Skip to content

Commit 293e55c

Browse files
committed
check for WiFi pass < 8 (not allowed for WPA2)
simplify STA config and allow setting of second DNS server for fallback code style
1 parent 7edcda4 commit 293e55c

File tree

5 files changed

+41
-53
lines changed

5 files changed

+41
-53
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,18 @@ static bool softap_config_equal(const softap_config& lhs, const softap_config& r
5454
* @return equal
5555
*/
5656
static bool softap_config_equal(const softap_config& lhs, const softap_config& rhs) {
57-
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0)
57+
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0) {
5858
return false;
59-
if(strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0)
59+
}
60+
if(strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0) {
6061
return false;
61-
if(lhs.channel != rhs.channel)
62+
}
63+
if(lhs.channel != rhs.channel) {
6264
return false;
63-
if(lhs.ssid_hidden != rhs.ssid_hidden)
65+
}
66+
if(lhs.ssid_hidden != rhs.ssid_hidden) {
6467
return false;
68+
}
6569
return true;
6670
}
6771

@@ -89,8 +93,8 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
8993
return false;
9094
}
9195

92-
if(passphrase && strlen(passphrase) > 63) {
93-
// fail passphrase to long!
96+
if(passphrase && (strlen(passphrase) > 63 || strlen(passphrase) < 8)) {
97+
// fail passphrase to long or short!
9498
return false;
9599
}
96100

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void ESP8266WiFiGenericClass::onEvent(WiFiEventCb cbEvent) {
7171
*/
7272
void ESP8266WiFiGenericClass::_eventCallback(void* arg) {
7373
System_Event_t* event = reinterpret_cast<System_Event_t*>(arg);
74-
DEBUGV("wifi evt: %d\r\n", event->event);
74+
DEBUGV("wifi evt: %d\n", event->event);
7575

7676
if(event->event == EVENT_STAMODE_DISCONNECTED) {
7777
WiFiClient::stopAll();
@@ -170,7 +170,7 @@ WiFiMode_t ESP8266WiFiGenericClass::getMode() {
170170
*/
171171
bool ESP8266WiFiGenericClass::enableSTA(bool enable) {
172172

173-
WiFiMode_t currentMode = (WiFiMode_t) wifi_get_opmode();
173+
WiFiMode_t currentMode = getMode();
174174
bool isEnabled = ((currentMode & WIFI_STA) != 0);
175175

176176
if(isEnabled != enable) {
@@ -191,7 +191,7 @@ bool ESP8266WiFiGenericClass::enableSTA(bool enable) {
191191
*/
192192
bool ESP8266WiFiGenericClass::enableAP(bool enable){
193193

194-
WiFiMode_t currentMode = (WiFiMode_t) wifi_get_opmode();
194+
WiFiMode_t currentMode = getMode();
195195
bool isEnabled = ((currentMode & WIFI_AP) != 0);
196196

197197
if(isEnabled != enable) {

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

+26-41
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,22 @@ static bool sta_config_equal(const station_config& lhs, const station_config& rh
5757
* @return equal
5858
*/
5959
static bool sta_config_equal(const station_config& lhs, const station_config& rhs) {
60-
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0)
60+
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0) {
6161
return false;
62+
}
6263

63-
if(strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0)
64+
if(strcmp(reinterpret_cast<const char*>(lhs.password), reinterpret_cast<const char*>(rhs.password)) != 0) {
6465
return false;
66+
}
6567

66-
if(lhs.bssid_set) {
67-
if(!rhs.bssid_set)
68-
return false;
68+
if(lhs.bssid_set != rhs.bssid_set) {
69+
return false;
70+
}
6971

70-
if(memcmp(lhs.bssid, rhs.bssid, 6) != 0)
71-
return false;
72-
} else {
73-
if(rhs.bssid_set)
72+
if(lhs.bssid_set) {
73+
if(memcmp(lhs.bssid, rhs.bssid, 6) != 0) {
7474
return false;
75+
}
7576
}
7677

7778
return true;
@@ -178,39 +179,15 @@ wl_status_t ESP8266WiFiSTAClass::begin() {
178179
}
179180

180181

181-
/**
182-
* Change IP configuration settings disabling the dhcp client
183-
* @param local_ip Static ip configuration
184-
* @param gateway Static gateway configuration
185-
* @param subnet Static Subnet mask
186-
*/
187-
bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
188-
189-
if(!WiFi.enableSTA(true)) {
190-
return false;
191-
}
192-
193-
struct ip_info info;
194-
info.ip.addr = static_cast<uint32_t>(local_ip);
195-
info.gw.addr = static_cast<uint32_t>(gateway);
196-
info.netmask.addr = static_cast<uint32_t>(subnet);
197-
198-
wifi_station_dhcpc_stop();
199-
if(wifi_set_ip_info(STATION_IF, &info)) {
200-
_useStaticIp = true;
201-
return true;
202-
}
203-
return false;
204-
}
205-
206182
/**
207183
* Change IP configuration settings disabling the dhcp client
208184
* @param local_ip Static ip configuration
209185
* @param gateway Static gateway configuration
210186
* @param subnet Static Subnet mask
211-
* @param dns Static DNS server
187+
* @param dns1 Static DNS server 1
188+
* @param dns2 Static DNS server 2
212189
*/
213-
bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns) {
190+
bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2) {
214191

215192
if(!WiFi.enableSTA(true)) {
216193
return false;
@@ -227,11 +204,19 @@ bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddres
227204
} else {
228205
return false;
229206
}
230-
231-
// Set DNS-Server
232207
ip_addr_t d;
233-
d.addr = static_cast<uint32_t>(dns);
234-
dns_setserver(0, &d);
208+
209+
if(dns1 != (uint32_t)0x00000000) {
210+
// Set DNS1-Server
211+
d.addr = static_cast<uint32_t>(dns1);
212+
dns_setserver(0, &d);
213+
}
214+
215+
if(dns2 != (uint32_t)0x00000000) {
216+
// Set DNS2-Server
217+
d.addr = static_cast<uint32_t>(dns2);
218+
dns_setserver(1, &d);
219+
}
235220

236221
return true;
237222
}
@@ -617,7 +602,7 @@ void ESP8266WiFiSTAClass::_smartConfigCallback(uint32_t st, void* result) {
617602
wifi_station_disconnect();
618603
wifi_station_connect();
619604

620-
WiFi._smartConfigDone = true;
605+
_smartConfigDone = true;
621606
} else if(status == SC_STATUS_LINK_OVER) {
622607
WiFi.stopSmartConfig();
623608
}

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ class ESP8266WiFiSTAClass {
3939
wl_status_t begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL);
4040
wl_status_t begin();
4141

42-
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
43-
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns);
42+
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
4443

4544
bool reconnect();
4645
bool disconnect(bool wifioff = false);
@@ -92,6 +91,7 @@ class ESP8266WiFiSTAClass {
9291

9392
static bool _smartConfigStarted;
9493
static bool _smartConfigDone;
94+
9595
static void _smartConfigCallback(uint32_t status, void* result);
9696

9797
};

libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ void ESP8266WiFiScanClass::_scanDone(void* result, int status) {
314314
* @return bss_info *
315315
*/
316316
void * ESP8266WiFiScanClass::_getScanInfoByIndex(int i) {
317-
//TODO why its void * and not bss_info * ?
318317
if(!ESP8266WiFiScanClass::_scanResult || (size_t) i > ESP8266WiFiScanClass::_scanCount) {
319318
return 0;
320319
}

0 commit comments

Comments
 (0)