提交 14ff3114 编写于 作者: M Mark D 提交者: Me No Dev

make WiFi.softAP() more robust (#1925)

* make WiFi.softAP() more robust

* WiFi.softAP() revert fallback to WIFI_AUTH_OPEN
上级 a3ed5118
...@@ -94,25 +94,28 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, ...@@ -94,25 +94,28 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel,
if(!WiFi.enableAP(true)) { if(!WiFi.enableAP(true)) {
// enable AP failed // enable AP failed
log_e("enable AP first!");
return false; return false;
} }
if(!ssid || *ssid == 0 || strlen(ssid) > 31) { if(!ssid || *ssid == 0) {
// fail SSID too long or missing! // fail SSID missing
log_e("SSID missing!");
return false; return false;
} }
if(passphrase && (strlen(passphrase) > 63 || strlen(passphrase) < 8)) { if(passphrase && (strlen(passphrase) > 0 && strlen(passphrase) < 8)) {
// fail passphrase to long or short! // fail passphrase too short
log_e("passphrase too short!");
return false; return false;
} }
esp_wifi_start(); esp_wifi_start();
wifi_config_t conf; wifi_config_t conf;
strcpy(reinterpret_cast<char*>(conf.ap.ssid), ssid); strlcpy(reinterpret_cast<char*>(conf.ap.ssid), ssid, sizeof(conf.ap.ssid));
conf.ap.channel = channel; conf.ap.channel = channel;
conf.ap.ssid_len = strlen(ssid); conf.ap.ssid_len = strlen(reinterpret_cast<char *>(conf.ap.ssid));
conf.ap.ssid_hidden = ssid_hidden; conf.ap.ssid_hidden = ssid_hidden;
conf.ap.max_connection = max_connection; conf.ap.max_connection = max_connection;
conf.ap.beacon_interval = 100; conf.ap.beacon_interval = 100;
...@@ -122,7 +125,7 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, ...@@ -122,7 +125,7 @@ bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel,
*conf.ap.password = 0; *conf.ap.password = 0;
} else { } else {
conf.ap.authmode = WIFI_AUTH_WPA2_PSK; conf.ap.authmode = WIFI_AUTH_WPA2_PSK;
strcpy(reinterpret_cast<char*>(conf.ap.password), passphrase); strlcpy(reinterpret_cast<char*>(conf.ap.password), passphrase, sizeof(conf.ap.password));
} }
wifi_config_t conf_current; wifi_config_t conf_current;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册