Skip to content

Commit 8e4258f

Browse files
committed
Implement for ssid a similar approach as for passphrase
1 parent 324b3f9 commit 8e4258f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
187187

188188
WifiAPEntry newAP;
189189

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

232232
bool ESP8266WiFiMulti::APlistExists(const char* ssid, const char *passphrase) {
233-
if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
233+
if(!ssid || *ssid == 0x00 || strlen(ssid) > 32) {
234234
// fail SSID too long or missing!
235235
DEBUG_WIFI_MULTI("[WIFI][APlistExists] no ssid or ssid too long\n");
236236
return false;

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
108108
return WL_CONNECT_FAILED;
109109
}
110110

111-
if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
111+
if(!ssid || *ssid == 0x00 || strlen(ssid) > 32) {
112112
// fail SSID too long or missing!
113113
return WL_CONNECT_FAILED;
114114
}
@@ -119,10 +119,12 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
119119
}
120120

121121
struct station_config conf;
122-
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
122+
if(strlen(ssid) == 32)
123+
memcpy(reinterpret_cast<char*>(conf.ssid), ssid, 32); //copied in without null term
124+
else
125+
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
123126

124127
conf.threshold.authmode = AUTH_OPEN;
125-
126128
if(passphrase) {
127129
conf.threshold.authmode = _useInsecureWEP ? AUTH_WEP : AUTH_WPA_PSK;
128130
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() {
524526
String ESP8266WiFiSTAClass::SSID() const {
525527
struct station_config conf;
526528
wifi_station_get_config(&conf);
527-
return String(reinterpret_cast<char*>(conf.ssid));
529+
char tmp[33]; //ssid can be up to 32chars, => plus null term
530+
memcpy(tmp, conf.ssid, sizeof(conf.ssid));
531+
tmp[32] = 0; //nullterm in case of 32 char ssid
532+
return String(reinterpret_cast<char*>(tmp));
528533
}
529534

530535
/**

0 commit comments

Comments
 (0)