Skip to content

Commit 1b8f6d2

Browse files
committed
Allow PSK instead of passphrase in WiFiSTA::begin
In WPA protocol, the maximum length of the passphrases are 64 characters in order to distinguish them from the actual PSK who is 64 ASCII characters long, so in most systems if a 64 chars string is passed, it is assumed to be a PSK, otherwise is treated as a passphrase and is used to compute the PSK.
1 parent 5dd6acc commit 1b8f6d2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
106106
return WL_CONNECT_FAILED;
107107
}
108108

109-
if(passphrase && strlen(passphrase) > 63) {
109+
if(passphrase && strlen(passphrase) > 64) {
110110
// fail passphrase too long!
111111
return WL_CONNECT_FAILED;
112112
}
@@ -115,7 +115,10 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
115115
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
116116

117117
if(passphrase) {
118-
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
118+
if (strlen(passphrase) == 64) // it's not a passphrase, is the PSK
119+
memcpy(reinterpret_cast<char*>(conf.password), passphrase, 64);
120+
else
121+
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
119122
} else {
120123
*conf.password = 0;
121124
}

0 commit comments

Comments
 (0)