Skip to content

Commit

Permalink
Allow PSK instead of passphrase in WiFiSTA::begin
Browse files Browse the repository at this point in the history
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.
4m1g0 committed Apr 3, 2016
1 parent 5dd6acc commit 1b8f6d2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
return WL_CONNECT_FAILED;
}

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

if(passphrase) {
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
if (strlen(passphrase) == 64) // it's not a passphrase, is the PSK
memcpy(reinterpret_cast<char*>(conf.password), passphrase, 64);
else
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
} else {
*conf.password = 0;
}

0 comments on commit 1b8f6d2

Please sign in to comment.