Skip to content

Commit

Permalink
[photon/p1] wlan: make sure to close all sockets when deinitializing …
Browse files Browse the repository at this point in the history
…WICED WLAN connectivity subsystem
  • Loading branch information
avtolstoy committed May 18, 2021
1 parent 4518b51 commit 12d0b28
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hal/src/photon/wlan_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ int wlan_supplicant_stop()
}

int wlan_restart(void* reserved) {
// XXX: make sure to close all sockets, as wiced_wlan_connectivity_deinit() will deinitialize LwIP
// which in turn invalidates LwIP netconns in use by WICED sockets and our socket layer.
socket_close_all();
wiced_wlan_connectivity_deinit();
wiced_wlan_connectivity_init();

Expand Down
43 changes: 43 additions & 0 deletions user/tests/wiring/no_fixture/wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,49 @@ test(WIFI_14_wifi_class_methods_work_correctly_when_wifi_interface_is_off) {
assertTrue(!memcmp(bssidRef, bssid, sizeof(bssidRef)) || !memcmp(bssidRefFf, bssid, sizeof(bssidRefFf)));
}

#if HAL_PLATFORM_GEN == 2 // Photon and P1

test(WIFI_15_entering_listening_mode_and_enabling_softap_closes_active_sockets_cleanly) {
const char testHost[] = "google.com";
const uint16_t testPort = 80;
const int resolveAttempts = 5;
const auto listenTime = 2s;

Serial.printlnf("on/connect");
WiFi.on();
WiFi.connect();
Particle.connect();
assertTrue(waitFor(Particle.connected, 30000));

IPAddress address;
for (int i = 0; i < resolveAttempts; i++) {
address = WiFi.resolve(testHost);
if (address) {
break;
}
}
assertNotEqual(address, 0);

TCPClient client;
assertEqual(1, client.connect(address, testPort));
assertTrue(client.connected());

WiFi.setListenTimeout(listenTime);
WiFi.listen(true);
if (system_thread_get_state(nullptr) == spark::feature::ENABLED) {
delay(listenTime);
}
WiFi.listen(false);

waitFor(Particle.connected, 30000);
assertFalse(client.connected());
client.stop();
}

#endif // HAL_PLATFORM_GEN == 2

#endif // !HAL_PLATFORM_WIFI_SCAN_ONLY



#endif

0 comments on commit 12d0b28

Please sign in to comment.