Modified to cover all possible options

Case scenario:
-new AP SSID without password, keep old password and auth mode
-new AP SSID with password empty, auth mode set to OPEN
-new AP SSID with password, default auth mode WPA2
pull/84/head
KatAst 9 years ago
parent c8aab7611b
commit 0f1ddae28e
  1. 19
      esp-link/cgiwifi.c

@ -877,17 +877,19 @@ void ICACHE_FLASH_ATTR wifiInit() {
#endif #endif
// Change SOFT_AP settings if defined // Change SOFT_AP settings if defined
#if defined(AP_SSID) && defined(AP_PASS) #if defined(AP_SSID)
// Check if both ssid and pass are alphanumeric values // Check if ssid and pass are alphanumeric values
if(checkString(VERS_STR(AP_SSID)) && checkString(VERS_STR(AP_PASS))){ int ssidlen = os_strlen(VERS_STR(AP_SSID));
if(checkString(VERS_STR(AP_SSID)) && ssidlen > 7 && ssidlen < 32){
// Clean memory and set the value of SSID // Clean memory and set the value of SSID
os_memset(apconf.ssid, 0, 32); os_memset(apconf.ssid, 0, 32);
os_memcpy(apconf.ssid, VERS_STR(AP_SSID), os_strlen(VERS_STR(AP_SSID))); os_memcpy(apconf.ssid, VERS_STR(AP_SSID), os_strlen(VERS_STR(AP_SSID)));
// Specify the length of pass // Specify the length of pass
apconf.ssid_len= os_strlen((char*)VERS_STR(AP_SSID)); apconf.ssid_len= ssidlen;
#if defined(AP_PASS)
// If pass is at least 8 and less than 64 // If pass is at least 8 and less than 64
int passlen = os_strlen(VERS_STR(AP_PASS)); int passlen = os_strlen(VERS_STR(AP_PASS));
if( passlen > 7 && passlen < 64 ){ if( checkString(VERS_STR(AP_PASS)) && passlen > 7 && passlen < 64 ){
// Clean memory and set the value of PASS // Clean memory and set the value of PASS
os_memset(apconf.password, 0, 64); os_memset(apconf.password, 0, 64);
os_memcpy(apconf.password, VERS_STR(AP_PASS), passlen); os_memcpy(apconf.password, VERS_STR(AP_PASS), passlen);
@ -898,15 +900,16 @@ void ICACHE_FLASH_ATTR wifiInit() {
if(AP_AUTH_MODE >= 0 && AP_AUTH_MODE <=4) if(AP_AUTH_MODE >= 0 && AP_AUTH_MODE <=4)
apconf.authmode = AP_AUTH_MODE; apconf.authmode = AP_AUTH_MODE;
#else #else
// If not, use OPEN // If not, use WPA2
apconf.authmode = AUTH_OPEN; apconf.authmode = AUTH_WPA_WPA2_PSK;
#endif #endif
}else if ( passlen == 0){ }else if ( passlen == 0){
// If ssid is ok and no pass set auth open // If ssid is ok and no pass, set auth open
apconf.authmode = AUTH_OPEN; apconf.authmode = AUTH_OPEN;
// Remove stored password // Remove stored password
os_memset(apconf.password, 0, 64); os_memset(apconf.password, 0, 64);
} }
#endif
}// end of ssid and pass check }// end of ssid and pass check
#ifdef AP_SSID_HIDDEN #ifdef AP_SSID_HIDDEN
// If set, use specified ssid hidden parameter // If set, use specified ssid hidden parameter

Loading…
Cancel
Save