Skip to content

Commit dd25e2b

Browse files
authored
Fix some WiFi issues (#5395)
* Add back ARDUINO_EVENT_WIFI_READY Fixes: #5315 * use strncpy and strncmp for WiFi SSID and Password in AP and STA Fixes: #5367 * Implement timeout for waitForConnectResult Fixes: #5330 * Remove old definition of "reverse" from stdlib_noniso Fixes: #5045 * Make "reverse" noniso conditional on ESP_DSP
1 parent cf6ab9c commit dd25e2b

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

cores/esp32/stdlib_noniso.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
#include <stdint.h>
2929
#include <math.h>
3030
#include "stdlib_noniso.h"
31+
#include "esp_system.h"
3132

33+
#if !CONFIG_DSP_ANSI && !CONFIG_DSP_OPTIMIZED
3234
void reverse(char* begin, char* end) {
3335
char *is = begin;
3436
char *ie = end - 1;
@@ -40,6 +42,9 @@ void reverse(char* begin, char* end) {
4042
--ie;
4143
}
4244
}
45+
#else
46+
void reverse(char* begin, char* end);
47+
#endif
4348

4449
char* ltoa(long value, char* result, int base) {
4550
if(base < 2 || base > 16) {

libraries/WiFi/src/WiFiAP.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ static bool softap_config_equal(const wifi_config_t& lhs, const wifi_config_t& r
6060
*/
6161
static bool softap_config_equal(const wifi_config_t& lhs, const wifi_config_t& rhs)
6262
{
63-
if(strcmp(reinterpret_cast<const char*>(lhs.ap.ssid), reinterpret_cast<const char*>(rhs.ap.ssid)) != 0) {
63+
if(strncmp(reinterpret_cast<const char*>(lhs.ap.ssid), reinterpret_cast<const char*>(rhs.ap.ssid), 32) != 0) {
6464
return false;
6565
}
66-
if(strcmp(reinterpret_cast<const char*>(lhs.ap.password), reinterpret_cast<const char*>(rhs.ap.password)) != 0) {
66+
if(strncmp(reinterpret_cast<const char*>(lhs.ap.password), reinterpret_cast<const char*>(rhs.ap.password), 64) != 0) {
6767
return false;
6868
}
6969
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
9898
wifi_config->ap.password[0] = 0;
9999
wifi_config->ap.ftm_responder = ftm_responder;
100100
if(ssid != NULL && ssid[0] != 0){
101-
snprintf((char*)wifi_config->ap.ssid, 32, ssid);
101+
strncpy((char*)wifi_config->ap.ssid, ssid, 32);
102102
wifi_config->ap.ssid_len = strlen(ssid);
103103
if(password != NULL && password[0] != 0){
104104
wifi_config->ap.authmode = authmode;
105105
wifi_config->ap.pairwise_cipher = WIFI_CIPHER_TYPE_CCMP; // Disable by default enabled insecure TKIP and use just CCMP.
106-
snprintf((char*)wifi_config->ap.password, 64, password);
106+
strncpy((char*)wifi_config->ap.password, password, 64);
107107
}
108108
}
109109
}

libraries/WiFi/src/WiFiGeneric.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,11 @@ bool wifiLowLevelInit(bool persistent){
567567
if(!persistent){
568568
lowLevelInitDone = esp_wifi_set_storage(WIFI_STORAGE_RAM) == ESP_OK;
569569
}
570+
if(lowLevelInitDone){
571+
arduino_event_t arduino_event;
572+
arduino_event.event_id = ARDUINO_EVENT_WIFI_READY;
573+
postArduinoEvent(&arduino_event);
574+
}
570575
}
571576
return lowLevelInitDone;
572577
}

libraries/WiFi/src/WiFiSTA.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,10 @@ static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL,
8282
wifi_config->sta.ssid[0] = 0;
8383
wifi_config->sta.password[0] = 0;
8484
if(ssid != NULL && ssid[0] != 0){
85-
snprintf((char*)wifi_config->sta.ssid, 32, ssid);
85+
strncpy((char*)wifi_config->sta.ssid, ssid, 32);
8686
if(password != NULL && password[0] != 0){
8787
wifi_config->sta.threshold.authmode = WIFI_AUTH_WEP;
88-
if(strlen(password) == 64){
89-
memcpy((char*)wifi_config->sta.password, password, 64);
90-
} else {
91-
snprintf((char*)wifi_config->sta.password, 64, password);
92-
}
88+
strncpy((char*)wifi_config->sta.password, password, 64);
9389
}
9490
if(bssid != NULL){
9591
wifi_config->sta.bssid_set = 1;
@@ -165,15 +161,11 @@ wl_status_t WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_
165161

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

171167
if(passphrase) {
172-
if (strlen(passphrase) == 64){ // it's not a passphrase, is the PSK
173-
memcpy(reinterpret_cast<char*>(conf.sta.password), passphrase, 64);
174-
} else {
175-
strcpy(reinterpret_cast<char*>(conf.sta.password), passphrase);
176-
}
168+
strncpy(reinterpret_cast<char*>(conf.sta.password), passphrase, 64);
177169
}
178170

179171
wifi_config_t current_conf;
@@ -370,14 +362,14 @@ bool WiFiSTAClass::getAutoReconnect()
370362
* returns the status reached or disconnect if STA is off
371363
* @return wl_status_t
372364
*/
373-
uint8_t WiFiSTAClass::waitForConnectResult()
365+
uint8_t WiFiSTAClass::waitForConnectResult(unsigned long timeoutLength)
374366
{
375367
//1 and 3 have STA enabled
376368
if((WiFiGenericClass::getMode() & WIFI_MODE_STA) == 0) {
377369
return WL_DISCONNECTED;
378370
}
379-
int i = 0;
380-
while((!status() || status() >= WL_DISCONNECTED) && i++ < 100) {
371+
unsigned long start = millis();
372+
while((!status() || status() >= WL_DISCONNECTED) && (millis() - start) < timeoutLength) {
381373
delay(100);
382374
}
383375
return status();

libraries/WiFi/src/WiFiSTA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class WiFiSTAClass
5656
bool setAutoReconnect(bool autoReconnect);
5757
bool getAutoReconnect();
5858

59-
uint8_t waitForConnectResult();
59+
uint8_t waitForConnectResult(unsigned long timeoutLength = 60000);
6060

6161
// STA network info
6262
IPAddress localIP();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy