Skip to content

Commit 34e90f3

Browse files
acevestdevyte
authored andcommitted
fix bug. in sta mode, empty passphrase should not use secure auth mode (#5516)
* in sta mode, empty passphrase should not use secure auth mode * use nullptr, camelCase and parenthesis
1 parent 3348ddf commit 34e90f3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Diff for: libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,22 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
113113
return WL_CONNECT_FAILED;
114114
}
115115

116-
if(passphrase && strlen(passphrase) > 64) {
116+
int passphraseLen = passphrase == nullptr ? 0 : strlen(passphrase);
117+
if(passphraseLen > 64) {
117118
// fail passphrase too long!
118119
return WL_CONNECT_FAILED;
119120
}
120121

121122
struct station_config conf;
123+
conf.threshold.authmode = (passphraseLen == 0) ? AUTH_OPEN : (_useInsecureWEP ? AUTH_WEP : AUTH_WPA_PSK);
124+
122125
if(strlen(ssid) == 32)
123126
memcpy(reinterpret_cast<char*>(conf.ssid), ssid, 32); //copied in without null term
124127
else
125128
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
126129

127-
conf.threshold.authmode = AUTH_OPEN;
128130
if(passphrase) {
129-
conf.threshold.authmode = _useInsecureWEP ? AUTH_WEP : AUTH_WPA_PSK;
130-
if (strlen(passphrase) == 64) // it's not a passphrase, is the PSK, which is copied into conf.password without null term
131+
if (passphraseLen == 64) // it's not a passphrase, is the PSK, which is copied into conf.password without null term
131132
memcpy(reinterpret_cast<char*>(conf.password), passphrase, 64);
132133
else
133134
strcpy(reinterpret_cast<char*>(conf.password), passphrase);

0 commit comments

Comments
 (0)