1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

fixed support for psk in WiFiSTA, added support for psk to WiFiMulti, minor code cleanups (#4076)

This commit is contained in:
Develo
2018-01-10 23:15:24 -03:00
committed by GitHub
parent 332e059724
commit 02259a412c
3 changed files with 24 additions and 25 deletions

View File

@ -38,10 +38,6 @@ bool ESP8266WiFiMulti::addAP(const char* ssid, const char *passphrase) {
return APlistAdd(ssid, passphrase);
}
int ESP8266WiFiMulti::count(void) {
return APlist.size();
}
wl_status_t ESP8266WiFiMulti::run(void) {
wl_status_t status = WiFi.status();
@ -71,7 +67,7 @@ wl_status_t ESP8266WiFiMulti::run(void) {
if(scanResult > 0) {
// scan done, analyze
WifiAPlist_t bestNetwork { NULL, NULL };
WifiAPEntry bestNetwork { NULL, NULL };
int bestNetworkDb = INT_MIN;
uint8 bestBSSID[6];
int32_t bestChannel;
@ -92,16 +88,14 @@ wl_status_t ESP8266WiFiMulti::run(void) {
WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan);
bool known = false;
for(uint32_t x = 0; x < APlist.size(); x++) {
WifiAPlist_t entry = APlist[x];
for(auto entry : APlist) {
if(ssid_scan == entry.ssid) { // SSID match
known = true;
if(rssi_scan > bestNetworkDb) { // best network
if(sec_scan == ENC_TYPE_NONE || entry.passphrase) { // check for passphrase if not open wlan
bestNetworkDb = rssi_scan;
bestChannel = chan_scan;
memcpy((void*) &bestNetwork, (void*) &entry, sizeof(bestNetwork));
bestNetwork = entry;
memcpy((void*) &bestBSSID, (void*) BSSID_scan, sizeof(bestBSSID));
}
}
@ -183,7 +177,7 @@ wl_status_t ESP8266WiFiMulti::run(void) {
bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
WifiAPlist_t newAP;
WifiAPEntry newAP;
if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
// fail SSID to long or missing!
@ -191,7 +185,8 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
return false;
}
if(passphrase && strlen(passphrase) > 63) {
//for passphrase, max is 63 ascii + null. For psk, 64hex + null.
if(passphrase && strlen(passphrase) > 64) {
// fail passphrase to long!
DEBUG_WIFI_MULTI("[WIFI][APlistAdd] passphrase to long\n");
return false;
@ -222,8 +217,7 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
}
void ESP8266WiFiMulti::APlistClean(void) {
for(uint32_t i = 0; i < APlist.size(); i++) {
WifiAPlist_t entry = APlist[i];
for(auto entry : APlist) {
if(entry.ssid) {
free(entry.ssid);
}