From 1b8f6d2e8e2dc7008660732b96197fd1ae1a1439 Mon Sep 17 00:00:00 2001 From: 4m1g0 Date: Sun, 3 Apr 2016 03:31:57 +0200 Subject: [PATCH] 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. --- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index 0d34a5a64b..e8f538dfe5 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -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(conf.ssid), ssid); if(passphrase) { - strcpy(reinterpret_cast(conf.password), passphrase); + if (strlen(passphrase) == 64) // it's not a passphrase, is the PSK + memcpy(reinterpret_cast(conf.password), passphrase, 64); + else + strcpy(reinterpret_cast(conf.password), passphrase); } else { *conf.password = 0; }