From 8a474d749d69d21cdd09c8e0b3481744c01e3968 Mon Sep 17 00:00:00 2001 From: Our Air Quality Date: Thu, 19 Oct 2017 04:56:17 +1000 Subject: [PATCH] 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. --- extras/wificfg/wificfg.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/extras/wificfg/wificfg.c b/extras/wificfg/wificfg.c index c2ca1ed..5c7a089 100644 --- a/extras/wificfg/wificfg.c +++ b/extras/wificfg/wificfg.c @@ -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 (!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; } } @@ -1857,7 +1857,7 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch) wifi_mode = STATIONAP_MODE; else if (wifi_sta_enable) wifi_mode = STATION_MODE; - else + else if (wifi_ap_enable) wifi_mode = SOFTAP_MODE; sdk_wifi_set_opmode(wifi_mode); @@ -2014,10 +2014,12 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch) if (wifi_ap_ssid) free(wifi_ap_ssid); if (wifi_ap_password) free(wifi_ap_password); - server_params *params = malloc(sizeof(server_params)); - params->port = port; - params->wificfg_dispatch = wificfg_dispatch_list; - params->dispatch = dispatch; + if (wifi_mode != NULL_MODE) { + server_params *params = malloc(sizeof(server_params)); + params->port = port; + params->wificfg_dispatch = wificfg_dispatch_list; + params->dispatch = dispatch; - xTaskCreate(server_task, "WiFi Cfg HTTP", 464, params, 2, NULL); + xTaskCreate(server_task, "WiFi Cfg HTTP", 464, params, 2, NULL); + } }