wificfg: correct a few initialization issues (#464)

* Correct checking of the AP password and SSID lengths.

* Only enable AP mode if it is really configured enabled.

* Only start the http server if wifi is enabled.
This commit is contained in:
Our Air Quality 2017-10-19 04:56:17 +10:00 committed by Johan Kanflo
parent ebdd2f983b
commit 8a474d749d

View file

@ -1847,7 +1847,7 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch)
/* If the ssid and password are not valid then disable the AP interface. */ /* If the ssid and password are not valid then disable the AP interface. */
if (!wifi_ap_ssid || strlen(wifi_ap_ssid) < 1 || strlen(wifi_ap_ssid) >= 32 || if (!wifi_ap_ssid || strlen(wifi_ap_ssid) < 1 || strlen(wifi_ap_ssid) >= 32 ||
!wifi_ap_password || strlen(wifi_ap_ssid) < 8 || strlen(wifi_ap_password) >= 64) { !wifi_ap_password || strlen(wifi_ap_password) < 8 || strlen(wifi_ap_password) >= 64) {
wifi_ap_enable = 0; wifi_ap_enable = 0;
} }
} }
@ -1857,7 +1857,7 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch)
wifi_mode = STATIONAP_MODE; wifi_mode = STATIONAP_MODE;
else if (wifi_sta_enable) else if (wifi_sta_enable)
wifi_mode = STATION_MODE; wifi_mode = STATION_MODE;
else else if (wifi_ap_enable)
wifi_mode = SOFTAP_MODE; wifi_mode = SOFTAP_MODE;
sdk_wifi_set_opmode(wifi_mode); sdk_wifi_set_opmode(wifi_mode);
@ -2014,6 +2014,7 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch)
if (wifi_ap_ssid) free(wifi_ap_ssid); if (wifi_ap_ssid) free(wifi_ap_ssid);
if (wifi_ap_password) free(wifi_ap_password); if (wifi_ap_password) free(wifi_ap_password);
if (wifi_mode != NULL_MODE) {
server_params *params = malloc(sizeof(server_params)); server_params *params = malloc(sizeof(server_params));
params->port = port; params->port = port;
params->wificfg_dispatch = wificfg_dispatch_list; params->wificfg_dispatch = wificfg_dispatch_list;
@ -2021,3 +2022,4 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch)
xTaskCreate(server_task, "WiFi Cfg HTTP", 464, params, 2, NULL); xTaskCreate(server_task, "WiFi Cfg HTTP", 464, params, 2, NULL);
} }
}