Skip to content

Commit 2aad912

Browse files
authored
Merge pull request #538 from arduino/wifi-status
WHD: correctly report AP disconnection
2 parents 87543ab + 16379b0 commit 2aad912

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

Diff for: libraries/WiFi/src/WiFi.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ int arduino::WiFiClass::begin(const char* ssid, const char* passphrase) {
1717
return 0;
1818
}
1919

20+
wifi_if->attach(&arduino::WiFiClass::statusCallback);
21+
2022
scanNetworks();
2123
// use scan result to populate security field
2224
if (!isVisible(ssid)) {
@@ -26,7 +28,11 @@ int arduino::WiFiClass::begin(const char* ssid, const char* passphrase) {
2628

2729
nsapi_error_t result = wifi_if->connect(ssid, passphrase, ap_list[connected_ap].get_security());
2830

31+
if(result == NSAPI_ERROR_IS_CONNECTED) {
32+
wifi_if->disconnect();
33+
}
2934
_currentNetworkStatus = (result == NSAPI_ERROR_OK && setSSID(ssid)) ? WL_CONNECTED : WL_CONNECT_FAILED;
35+
3036
return _currentNetworkStatus;
3137
}
3238

@@ -160,9 +166,10 @@ static uint8_t sec2enum(nsapi_security_t sec) {
160166

161167
int8_t arduino::WiFiClass::scanNetworks() {
162168
uint8_t count = 10;
163-
if (ap_list == nullptr) {
164-
ap_list = new WiFiAccessPoint[count];
169+
if (ap_list != nullptr) {
170+
free(ap_list);
165171
}
172+
ap_list = new WiFiAccessPoint[count];
166173
return wifi_if->scan(ap_list, count);
167174
}
168175

@@ -210,6 +217,15 @@ unsigned long arduino::WiFiClass::getTime() {
210217
return 0;
211218
}
212219

220+
void arduino::WiFiClass::statusCallback(nsapi_event_t status, intptr_t param)
221+
{
222+
if (((param == NSAPI_STATUS_DISCONNECTED) ||
223+
(param == NSAPI_STATUS_CONNECTING)) &&
224+
(WiFi.status() == WL_CONNECTED)) {
225+
WiFi._currentNetworkStatus = WL_CONNECTION_LOST;
226+
}
227+
}
228+
213229
#if defined(COMPONENT_4343W_FS)
214230

215231
#define WIFI_FIRMWARE_PATH "/wlan/4343WA1.BIN"

Diff for: libraries/WiFi/src/WiFi.h

+1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class WiFiClass : public MbedSocketClass {
209209
void ensureDefaultAPNetworkConfiguration();
210210
static void* handleAPEvents(whd_interface_t ifp, const whd_event_header_t* event_header, const uint8_t* event_data, void* handler_user_data);
211211
bool isVisible(const char* ssid);
212+
static void statusCallback(nsapi_event_t status, intptr_t param);
212213
};
213214

214215
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
From 7d59d1e04f2cc6872d07c30cb6f66457dbd383f2 Mon Sep 17 00:00:00 2001
2+
From: pennam <[email protected]>
3+
Date: Thu, 11 Aug 2022 10:29:34 +0200
4+
Subject: [PATCH] WHD: force disconnect on roamed due to low RSSI
5+
6+
---
7+
.../drivers/emac/COMPONENT_WHD/interface/WhdSTAInterface.cpp | 5 ++++-
8+
1 file changed, 4 insertions(+), 1 deletion(-)
9+
10+
diff --git a/connectivity/drivers/emac/COMPONENT_WHD/interface/WhdSTAInterface.cpp b/connectivity/drivers/emac/COMPONENT_WHD/interface/WhdSTAInterface.cpp
11+
index 6fec15adb0..509a2c0981 100644
12+
--- a/connectivity/drivers/emac/COMPONENT_WHD/interface/WhdSTAInterface.cpp
13+
+++ b/connectivity/drivers/emac/COMPONENT_WHD/interface/WhdSTAInterface.cpp
14+
@@ -178,7 +178,10 @@ static void *whd_wifi_link_state_change_handler(whd_interface_t ifp,
15+
(event_header->event_type == WLC_E_DISASSOC_IND) ||
16+
((event_header->event_type == WLC_E_PSK_SUP) &&
17+
(event_header->status == WLC_SUP_KEYED) &&
18+
- (event_header->reason == WLC_E_SUP_DEAUTH))) {
19+
+ (event_header->reason == WLC_E_SUP_DEAUTH)) ||
20+
+ ((event_header->event_type == WLC_E_LINK) &&
21+
+ (event_header->status == WLC_E_STATUS_SUCCESS) &&
22+
+ (event_header->reason == WLC_E_REASON_LOW_RSSI))) {
23+
whd_emac_wifi_link_state_changed(ifp, WHD_FALSE);
24+
return handler_user_data;
25+
}
26+
--
27+
2.37.1
28+

0 commit comments

Comments
 (0)