Unverified Commit dd25e2b9 authored by Me No Dev's avatar Me No Dev Committed by GitHub

Fix some WiFi issues (#5395)

* Add back ARDUINO_EVENT_WIFI_READY

Fixes: https://github.com/espressif/arduino-esp32/issues/5315

* use strncpy and strncmp for WiFi SSID and Password in AP and STA

Fixes: https://github.com/espressif/arduino-esp32/issues/5367

* Implement timeout for waitForConnectResult

Fixes: https://github.com/espressif/arduino-esp32/issues/5330

* Remove old definition of "reverse" from stdlib_noniso

Fixes: https://github.com/espressif/arduino-esp32/issues/5045

* Make "reverse" noniso conditional on ESP_DSP
parent cf6ab9c8
......@@ -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;
......@@ -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) {
......
......@@ -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) {
......@@ -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);
}
}
}
......
......@@ -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;
}
......
......@@ -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;
......@@ -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;
......@@ -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();
......
......@@ -56,7 +56,7 @@ public:
bool setAutoReconnect(bool autoReconnect);
bool getAutoReconnect();
uint8_t waitForConnectResult();
uint8_t waitForConnectResult(unsigned long timeoutLength = 60000);
// STA network info
IPAddress localIP();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment