mirror of
				https://github.com/esp8266/Arduino.git
				synced 2025-11-03 14:33:37 +03:00 
			
		
		
		
	Check if AP exists before adding it (#5373)
This commit is contained in:
		@@ -38,6 +38,10 @@ bool ESP8266WiFiMulti::addAP(const char* ssid, const char *passphrase) {
 | 
			
		||||
    return APlistAdd(ssid, passphrase);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ESP8266WiFiMulti::existsAP(const char* ssid, const char *passphrase) {
 | 
			
		||||
    return APlistExists(ssid, passphrase);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
wl_status_t ESP8266WiFiMulti::run(void) {
 | 
			
		||||
 | 
			
		||||
    wl_status_t status = WiFi.status();
 | 
			
		||||
@@ -184,18 +188,23 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
 | 
			
		||||
    WifiAPEntry newAP;
 | 
			
		||||
 | 
			
		||||
    if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
 | 
			
		||||
        // fail SSID to long or missing!
 | 
			
		||||
        DEBUG_WIFI_MULTI("[WIFI][APlistAdd] no ssid or ssid to long\n");
 | 
			
		||||
        // fail SSID too long or missing!
 | 
			
		||||
        DEBUG_WIFI_MULTI("[WIFI][APlistAdd] no ssid or ssid too long\n");
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //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");
 | 
			
		||||
        // fail passphrase too long!
 | 
			
		||||
        DEBUG_WIFI_MULTI("[WIFI][APlistAdd] passphrase too long\n");
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(APlistExists(ssid, passphrase)) {
 | 
			
		||||
        DEBUG_WIFI_MULTI("[WIFI][APlistAdd] SSID: %s already exists\n", ssid);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    newAP.ssid = strdup(ssid);
 | 
			
		||||
 | 
			
		||||
    if(!newAP.ssid) {
 | 
			
		||||
@@ -220,6 +229,28 @@ bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ESP8266WiFiMulti::APlistExists(const char* ssid, const char *passphrase) {
 | 
			
		||||
    if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
 | 
			
		||||
        // fail SSID too long or missing!
 | 
			
		||||
        DEBUG_WIFI_MULTI("[WIFI][APlistExists] no ssid or ssid too long\n");
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    for(auto entry : APlist) {
 | 
			
		||||
        if(!strcmp(entry.ssid, ssid)) {
 | 
			
		||||
            if(!passphrase) {
 | 
			
		||||
                if(!strcmp(entry.passphrase, "")) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                if(!strcmp(entry.passphrase, passphrase)) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ESP8266WiFiMulti::APlistClean(void) {
 | 
			
		||||
    for(auto entry : APlist) {
 | 
			
		||||
        if(entry.ssid) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user