Skip to content

Fix some WiFi issues #5395

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

Merged
merged 5 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cores/esp32/stdlib_noniso.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include <stdint.h>
#include <math.h>
#include "stdlib_noniso.h"
#include "esp_system.h"

#if !CONFIG_DSP_ANSI && !CONFIG_DSP_OPTIMIZED
void reverse(char* begin, char* end) {
char *is = begin;
char *ie = end - 1;
Expand All @@ -40,6 +42,9 @@ void reverse(char* begin, char* end) {
--ie;
}
}
#else
void reverse(char* begin, char* end);
#endif

char* ltoa(long value, char* result, int base) {
if(base < 2 || base > 16) {
Expand Down
8 changes: 4 additions & 4 deletions libraries/WiFi/src/WiFiAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ static bool softap_config_equal(const wifi_config_t& lhs, const wifi_config_t& r
*/
static bool softap_config_equal(const wifi_config_t& lhs, const wifi_config_t& rhs)
{
if(strcmp(reinterpret_cast<const char*>(lhs.ap.ssid), reinterpret_cast<const char*>(rhs.ap.ssid)) != 0) {
if(strncmp(reinterpret_cast<const char*>(lhs.ap.ssid), reinterpret_cast<const char*>(rhs.ap.ssid), 32) != 0) {
return false;
}
if(strcmp(reinterpret_cast<const char*>(lhs.ap.password), reinterpret_cast<const char*>(rhs.ap.password)) != 0) {
if(strncmp(reinterpret_cast<const char*>(lhs.ap.password), reinterpret_cast<const char*>(rhs.ap.password), 64) != 0) {
return false;
}
if(lhs.ap.channel != rhs.ap.channel) {
Expand Down Expand Up @@ -98,12 +98,12 @@ void wifi_softap_config(wifi_config_t *wifi_config, const char * ssid=NULL, cons
wifi_config->ap.password[0] = 0;
wifi_config->ap.ftm_responder = ftm_responder;
if(ssid != NULL && ssid[0] != 0){
snprintf((char*)wifi_config->ap.ssid, 32, ssid);
strncpy((char*)wifi_config->ap.ssid, ssid, 32);
wifi_config->ap.ssid_len = strlen(ssid);
if(password != NULL && password[0] != 0){
wifi_config->ap.authmode = authmode;
wifi_config->ap.pairwise_cipher = WIFI_CIPHER_TYPE_CCMP; // Disable by default enabled insecure TKIP and use just CCMP.
snprintf((char*)wifi_config->ap.password, 64, password);
strncpy((char*)wifi_config->ap.password, password, 64);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions libraries/WiFi/src/WiFiGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ bool wifiLowLevelInit(bool persistent){
if(!persistent){
lowLevelInitDone = esp_wifi_set_storage(WIFI_STORAGE_RAM) == ESP_OK;
}
if(lowLevelInitDone){
arduino_event_t arduino_event;
arduino_event.event_id = ARDUINO_EVENT_WIFI_READY;
postArduinoEvent(&arduino_event);
}
}
return lowLevelInitDone;
}
Expand Down
22 changes: 7 additions & 15 deletions libraries/WiFi/src/WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,10 @@ static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL,
wifi_config->sta.ssid[0] = 0;
wifi_config->sta.password[0] = 0;
if(ssid != NULL && ssid[0] != 0){
snprintf((char*)wifi_config->sta.ssid, 32, ssid);
strncpy((char*)wifi_config->sta.ssid, ssid, 32);
if(password != NULL && password[0] != 0){
wifi_config->sta.threshold.authmode = WIFI_AUTH_WEP;
if(strlen(password) == 64){
memcpy((char*)wifi_config->sta.password, password, 64);
} else {
snprintf((char*)wifi_config->sta.password, 64, password);
}
strncpy((char*)wifi_config->sta.password, password, 64);
}
if(bssid != NULL){
wifi_config->sta.bssid_set = 1;
Expand Down Expand Up @@ -165,15 +161,11 @@ wl_status_t WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_

wifi_config_t conf;
memset(&conf, 0, sizeof(wifi_config_t));
strcpy(reinterpret_cast<char*>(conf.sta.ssid), ssid);
strncpy(reinterpret_cast<char*>(conf.sta.ssid), ssid, 32);
conf.sta.scan_method = WIFI_ALL_CHANNEL_SCAN; //force full scan to be able to choose the nearest / strongest AP

if(passphrase) {
if (strlen(passphrase) == 64){ // it's not a passphrase, is the PSK
memcpy(reinterpret_cast<char*>(conf.sta.password), passphrase, 64);
} else {
strcpy(reinterpret_cast<char*>(conf.sta.password), passphrase);
}
strncpy(reinterpret_cast<char*>(conf.sta.password), passphrase, 64);
}

wifi_config_t current_conf;
Expand Down Expand Up @@ -370,14 +362,14 @@ bool WiFiSTAClass::getAutoReconnect()
* returns the status reached or disconnect if STA is off
* @return wl_status_t
*/
uint8_t WiFiSTAClass::waitForConnectResult()
uint8_t WiFiSTAClass::waitForConnectResult(unsigned long timeoutLength)
{
//1 and 3 have STA enabled
if((WiFiGenericClass::getMode() & WIFI_MODE_STA) == 0) {
return WL_DISCONNECTED;
}
int i = 0;
while((!status() || status() >= WL_DISCONNECTED) && i++ < 100) {
unsigned long start = millis();
while((!status() || status() >= WL_DISCONNECTED) && (millis() - start) < timeoutLength) {
delay(100);
}
return status();
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class WiFiSTAClass
bool setAutoReconnect(bool autoReconnect);
bool getAutoReconnect();

uint8_t waitForConnectResult();
uint8_t waitForConnectResult(unsigned long timeoutLength = 60000);

// STA network info
IPAddress localIP();
Expand Down