1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

Implement for ssid a similar approach as for passphrase (#5411)

* Implement for ssid a similar approach as for passphrase

* Additional fixes for 32-char ssid
This commit is contained in:
Develo 2018-12-03 02:25:13 -03:00 committed by Earle F. Philhower, III
parent d8acfffdb0
commit 4941711505
4 changed files with 24 additions and 10 deletions

View File

@ -72,13 +72,19 @@ void ESP8266WiFiClass::printDiag(Print& p) {
struct station_config conf; struct station_config conf;
wifi_station_get_config(&conf); wifi_station_get_config(&conf);
const char* ssid = reinterpret_cast<const char*>(conf.ssid); char ssid[33]; //ssid can be up to 32chars, => plus null term
memcpy(ssid, conf.ssid, sizeof(conf.ssid));
ssid[32] = 0; //nullterm in case of 32 char ssid
p.print("SSID ("); p.print("SSID (");
p.print(strlen(ssid)); p.print(strlen(ssid));
p.print("): "); p.print("): ");
p.println(ssid); p.println(ssid);
const char* passphrase = reinterpret_cast<const char*>(conf.password); char passphrase[65];
memcpy(passphrase, conf.password, sizeof(conf.password));
passphrase[64] = 0;
p.print("Passphrase ("); p.print("Passphrase (");
p.print(strlen(passphrase)); p.print(strlen(passphrase));
p.print("): "); p.print("): ");

View File

@ -187,7 +187,7 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
WifiAPEntry newAP; WifiAPEntry newAP;
if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) { if(!ssid || *ssid == 0x00 || strlen(ssid) > 32) {
// fail SSID too long or missing! // fail SSID too long or missing!
DEBUG_WIFI_MULTI("[WIFI][APlistAdd] no ssid or ssid too long\n"); DEBUG_WIFI_MULTI("[WIFI][APlistAdd] no ssid or ssid too long\n");
return false; return false;
@ -230,7 +230,7 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
} }
bool ESP8266WiFiMulti::APlistExists(const char* ssid, const char *passphrase) { bool ESP8266WiFiMulti::APlistExists(const char* ssid, const char *passphrase) {
if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) { if(!ssid || *ssid == 0x00 || strlen(ssid) > 32) {
// fail SSID too long or missing! // fail SSID too long or missing!
DEBUG_WIFI_MULTI("[WIFI][APlistExists] no ssid or ssid too long\n"); DEBUG_WIFI_MULTI("[WIFI][APlistExists] no ssid or ssid too long\n");
return false; return false;

View File

@ -62,7 +62,7 @@ static bool sta_config_equal(const station_config& lhs, const station_config& rh
* @return equal * @return equal
*/ */
static bool sta_config_equal(const station_config& lhs, const station_config& rhs) { static bool sta_config_equal(const station_config& lhs, const station_config& rhs) {
if(strcmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid)) != 0) { if(strncmp(reinterpret_cast<const char*>(lhs.ssid), reinterpret_cast<const char*>(rhs.ssid), sizeof(lhs.ssid)) != 0) {
return false; return false;
} }
@ -108,7 +108,7 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
return WL_CONNECT_FAILED; return WL_CONNECT_FAILED;
} }
if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) { if(!ssid || *ssid == 0x00 || strlen(ssid) > 32) {
// fail SSID too long or missing! // fail SSID too long or missing!
return WL_CONNECT_FAILED; return WL_CONNECT_FAILED;
} }
@ -119,10 +119,12 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
} }
struct station_config conf; struct station_config conf;
strcpy(reinterpret_cast<char*>(conf.ssid), ssid); if(strlen(ssid) == 32)
memcpy(reinterpret_cast<char*>(conf.ssid), ssid, 32); //copied in without null term
else
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
conf.threshold.authmode = AUTH_OPEN; conf.threshold.authmode = AUTH_OPEN;
if(passphrase) { if(passphrase) {
conf.threshold.authmode = _useInsecureWEP ? AUTH_WEP : AUTH_WPA_PSK; conf.threshold.authmode = _useInsecureWEP ? AUTH_WEP : AUTH_WPA_PSK;
if (strlen(passphrase) == 64) // it's not a passphrase, is the PSK, which is copied into conf.password without null term if (strlen(passphrase) == 64) // it's not a passphrase, is the PSK, which is copied into conf.password without null term
@ -524,7 +526,10 @@ wl_status_t ESP8266WiFiSTAClass::status() {
String ESP8266WiFiSTAClass::SSID() const { String ESP8266WiFiSTAClass::SSID() const {
struct station_config conf; struct station_config conf;
wifi_station_get_config(&conf); wifi_station_get_config(&conf);
return String(reinterpret_cast<char*>(conf.ssid)); char tmp[33]; //ssid can be up to 32chars, => plus null term
memcpy(tmp, conf.ssid, sizeof(conf.ssid));
tmp[32] = 0; //nullterm in case of 32 char ssid
return String(reinterpret_cast<char*>(tmp));
} }
/** /**

View File

@ -186,8 +186,11 @@ String ESP8266WiFiScanClass::SSID(uint8_t i) {
if(!it) { if(!it) {
return ""; return "";
} }
char tmp[33]; //ssid can be up to 32chars, => plus null term
memcpy(tmp, it->ssid, sizeof(it->ssid));
tmp[32] = 0; //nullterm in case of 32 char ssid
return String(reinterpret_cast<const char*>(it->ssid)); return String(reinterpret_cast<const char*>(tmp));
} }