@@ -54,10 +54,13 @@ static bool softap_config_equal(const softap_config& lhs, const softap_config& r
54
54
* @return equal
55
55
*/
56
56
static bool softap_config_equal (const softap_config& lhs, const softap_config& rhs) {
57
- if (strcmp ( reinterpret_cast < const char *>( lhs.ssid ), reinterpret_cast < const char *>(rhs. ssid )) != 0 ) {
57
+ if (lhs.ssid_len != rhs. ssid_len ) {
58
58
return false ;
59
59
}
60
- if (strcmp (reinterpret_cast <const char *>(lhs.password ), reinterpret_cast <const char *>(rhs.password )) != 0 ) {
60
+ if (memcmp (lhs.ssid , rhs.ssid , lhs.ssid_len ) != 0 ) {
61
+ return false ;
62
+ }
63
+ if (strncmp (reinterpret_cast <const char *>(lhs.password ), reinterpret_cast <const char *>(rhs.password ), sizeof (softap_config::password)) != 0 ) {
61
64
return false ;
62
65
}
63
66
if (lhs.channel != rhs.channel ) {
@@ -85,7 +88,7 @@ static bool softap_config_equal(const softap_config& lhs, const softap_config& r
85
88
86
89
/* *
87
90
* Set up an access point
88
- * @param ssid Pointer to the SSID (max 31 char).
91
+ * @param ssid Pointer to the SSID (max 32 char).
89
92
* @param passphrase For WPA2 min 8 char, for open use NULL (max 63 char).
90
93
* @param channel WiFi channel number, 1 - 13.
91
94
* @param ssid_hidden Network cloaking (0 = broadcast SSID, 1 = hide SSID)
@@ -99,13 +102,15 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
99
102
return false ;
100
103
}
101
104
102
- if (!ssid || strlen (ssid) == 0 || strlen (ssid) > 31 ) {
105
+ size_t ssid_len = strlen (ssid);
106
+ if (!ssid || ssid_len == 0 || ssid_len > 32 ) {
103
107
// fail SSID too long or missing!
104
108
DEBUG_WIFI (" [AP] SSID too long or missing!\n " );
105
109
return false ;
106
110
}
107
111
108
- if (passphrase && strlen (passphrase) > 0 && (strlen (passphrase) > 63 || strlen (passphrase) < 8 )) {
112
+ size_t pass_len = strlen (passphrase);
113
+ if (passphrase && pass_len > 0 && (pass_len > 63 || pass_len < 8 )) {
109
114
// fail passphrase to long or short!
110
115
DEBUG_WIFI (" [AP] fail passphrase too long or short!\n " );
111
116
return false ;
@@ -114,21 +119,25 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
114
119
bool ret = true ;
115
120
116
121
struct softap_config conf;
117
- strcpy (reinterpret_cast <char *>(conf.ssid ), ssid);
118
- conf.channel = channel;
119
- conf.ssid_len = strlen (ssid);
120
- conf.ssid_hidden = ssid_hidden;
121
- conf.max_connection = max_connection;
122
- conf.beacon_interval = 100 ;
122
+ memcpy (reinterpret_cast <char *>(conf.ssid ), ssid, ssid_len);
123
+ if (ssid_len < 32 ) {
124
+ conf.ssid [ssid_len] = ' \0 ' ;
125
+ }
126
+ conf.ssid_len = ssid_len;
123
127
124
- if (!passphrase || strlen (passphrase) == 0 ) {
128
+ if (!passphrase || pass_len == 0 ) {
125
129
conf.authmode = AUTH_OPEN;
126
130
*conf.password = 0 ;
127
131
} else {
128
132
conf.authmode = AUTH_WPA2_PSK;
129
133
strcpy (reinterpret_cast <char *>(conf.password ), passphrase);
130
134
}
131
135
136
+ conf.channel = channel;
137
+ conf.ssid_hidden = ssid_hidden;
138
+ conf.max_connection = max_connection;
139
+ conf.beacon_interval = 100 ;
140
+
132
141
struct softap_config conf_compare;
133
142
if (WiFi._persistent ){
134
143
wifi_softap_get_config_default (&conf_compare);
@@ -358,25 +367,19 @@ String ESP8266WiFiAPClass::softAPmacAddress(void) {
358
367
String ESP8266WiFiAPClass::softAPSSID () const {
359
368
struct softap_config config;
360
369
wifi_softap_get_config (&config);
361
- char * name = reinterpret_cast <char *>(config.ssid );
362
- char ssid[sizeof (config.ssid ) + 1 ];
363
- memcpy (ssid, name, sizeof (config.ssid ));
364
- ssid[sizeof (config.ssid )] = ' \0 ' ;
365
-
366
- return String (ssid);
370
+ String ssid;
371
+ ssid.concat (reinterpret_cast <const char *>(config.ssid ), config.ssid_len );
372
+ return ssid;
367
373
}
368
374
369
375
/* *
370
- * Get the configured(Not-In-Flash) softAP PSK or PASSWORD.
371
- * @return String psk .
376
+ * Get the configured(Not-In-Flash) softAP PASSWORD.
377
+ * @return String password .
372
378
*/
373
379
String ESP8266WiFiAPClass::softAPPSK () const {
374
380
struct softap_config config;
375
381
wifi_softap_get_config (&config);
376
382
char * pass = reinterpret_cast <char *>(config.password );
377
- char psk[sizeof (config.password ) + 1 ];
378
- memcpy (psk, pass, sizeof (config.password ));
379
- psk[sizeof (config.password )] = ' \0 ' ;
380
-
381
- return String (psk);
383
+ pass[sizeof (config.password ) - 1 ] = ' \0 ' ; // it is impossible to set PSK through the Arduino API because we only support WPA2
384
+ return pass;
382
385
}
0 commit comments