-
Notifications
You must be signed in to change notification settings - Fork 489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wificfg bugfix and enhancements #459
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1775,24 +1775,60 @@ static void dns_task(void *pvParameters) | |
} | ||
} | ||
|
||
/** | ||
* @brief Sanetize SSID. If configuring an AP containing the characters in | ||
* 'illegals', the ESP will start an insecure AP named ESP_<macaddr> | ||
* Any illegal characters will be replaced by _ | ||
* | ||
* @param ssid the SSID | ||
* | ||
* @return true if name got sanetized. | ||
*/ | ||
static bool sanetize_ssid(char *ssid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not aware of any such restrictions. All these characters are accepted in the SSID here and an android tablet still noted it as secure. If there are issues in libmain then I think those should be corrected. If there is some restriction in the wpa library then that would be something else to consider. |
||
{ | ||
bool sanetized = false; | ||
char *illegals = "+-<> "; // There might me more characters that are illegal | ||
uint8_t num_illegals = strlen(illegals); | ||
if (!ssid) { | ||
return sanetized; | ||
} | ||
while(*ssid) { | ||
for (uint32_t i = 0; i < num_illegals; i++) { | ||
if (*ssid == illegals[i]) { | ||
*ssid = '_'; | ||
sanetized = true; | ||
break; | ||
} | ||
} | ||
ssid++; | ||
} | ||
return sanetized; | ||
} | ||
|
||
void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch) | ||
bool wificfg_init(uint32_t port, const wificfg_dispatch *dispatch) | ||
{ | ||
char *wifi_sta_ssid = NULL; | ||
char *wifi_sta_password = NULL; | ||
char *wifi_ap_ssid = NULL; | ||
char *wifi_ap_password = NULL; | ||
bool ap_started = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As noted this name does not look appropriate. If you need a flag then perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might have misinterpreted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
uint32_t base_addr; | ||
uint32_t num_sectors; | ||
if (sysparam_get_info(&base_addr, &num_sectors) != SYSPARAM_OK) { | ||
printf("Warning: WiFi config, sysparam not initialized\n"); | ||
return; | ||
return false; | ||
} | ||
|
||
sysparam_get_string("wifi_ap_ssid", &wifi_ap_ssid); | ||
if (sanetize_ssid(wifi_ap_ssid)) { | ||
sysparam_set_string("wifi_ap_ssid", wifi_ap_ssid); | ||
} | ||
sysparam_get_string("wifi_ap_password", &wifi_ap_password); | ||
sysparam_get_string("wifi_sta_ssid", &wifi_sta_ssid); | ||
if (sanetize_ssid(wifi_sta_ssid)) { | ||
sysparam_set_string("wifi_sta_ssid", wifi_sta_ssid); | ||
} | ||
sysparam_get_string("wifi_sta_password", &wifi_sta_password); | ||
|
||
int8_t wifi_sta_enable = 1; | ||
|
@@ -1819,7 +1855,7 @@ void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch) | |
/* Validate the configuration. */ | ||
|
||
if (wifi_sta_enable && (!wifi_sta_ssid || !wifi_sta_password || | ||
strlen(wifi_sta_ssid) < 1 || | ||
strlen(wifi_sta_ssid) < 8 || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there is such a limit on the ssid length. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will revisit this one as I ran into the insecure ESP_xxxxxx AP being started (instead of the secured one with the selected name) when using a short SSID. |
||
strlen(wifi_sta_ssid) > 32 || | ||
!wifi_sta_password || | ||
strlen(wifi_sta_password) < 8 || | ||
|
@@ -1844,9 +1880,11 @@ 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) { | ||
/* If the ssid and password are not valid then disable the AP interface. | ||
The SSID must be at least 8 characters, if not we will get an | ||
insecure AP named ESP_<macaddr> */ | ||
if (!wifi_ap_ssid || strlen(wifi_ap_ssid) < 8 || strlen(wifi_ap_ssid) >= 32 || | ||
!wifi_ap_password || strlen(wifi_ap_password) < 8 || strlen(wifi_ap_password) >= 64) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there is such a limit on the SSID length, and small ssids work here. The error here was the checking of the wifi_ap_password length which must be at least 8, the check of the ap_ssid length was a typo, sorry. |
||
wifi_ap_enable = 0; | ||
} | ||
} | ||
|
@@ -1856,8 +1894,10 @@ 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, good catch, thanks. |
||
wifi_mode = SOFTAP_MODE; | ||
else | ||
printf("Warning: No AP/STA enabled by wificfg.\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is quite normal for the wifi to not be running, so I would not bother with this. There is already enough output to see which interfaces have been started. |
||
sdk_wifi_set_opmode(wifi_mode); | ||
|
||
if (wifi_sta_enable) { | ||
|
@@ -2013,10 +2053,13 @@ 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; | ||
|
||
xTaskCreate(server_task, "WiFi Cfg HTTP", 464, params, 2, NULL); | ||
if (wifi_mode != NULL_MODE) { | ||
server_params *params = malloc(sizeof(server_params)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that looks appropriate, thanks. |
||
params->port = port; | ||
params->wificfg_dispatch = wificfg_dispatch_list; | ||
params->dispatch = dispatch; | ||
xTaskCreate(server_task, "WiFi Cfg HTTP", 464, params, 2, NULL); | ||
ap_started = true; | ||
} | ||
return ap_started; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,9 +88,10 @@ typedef struct { | |
/* | ||
* Start the Wifi Configuration http server task. The IP port number | ||
* and a path dispatch list are needed. The dispatch list can not be | ||
* stack allocated as it is passed to another task. | ||
* stack allocated as it is passed to another task. Returns true if the | ||
* selected AP was successfully started. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment not appropriate, see above. |
||
*/ | ||
void wificfg_init(uint32_t port, const wificfg_dispatch *dispatch); | ||
bool wificfg_init(uint32_t port, const wificfg_dispatch *dispatch); | ||
|
||
/* | ||
* Support for reading a form name or value from the socket. The name or value | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessarily a failure. In fact the configuration can correctly not start wifi. It seems fine to return a bool flag indicating if any wifi was started, if the http server was started, but that should not be interpreted as an error value. The above warning seems unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, not having an AP up and running on port 80 following the call to wificfg_init is nothing but a failure that needs dealing with. If nothing else, inform the user that the device is malfunctioning.