From 74d8cd2c7b59ad15a856387b569571cc1be63c60 Mon Sep 17 00:00:00 2001 From: Marcin Kajor Date: Thu, 1 Dec 2022 16:48:31 +0100 Subject: [PATCH] wifi: RevertConfiguration optimization. Do not disconnect/reconnect to the already attached network. Signed-off-by: Marcin Kajor --- src/platform/nrfconnect/wifi/NrfWiFiDriver.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/platform/nrfconnect/wifi/NrfWiFiDriver.cpp b/src/platform/nrfconnect/wifi/NrfWiFiDriver.cpp index 03720199961931..e8e5d10d73ae97 100644 --- a/src/platform/nrfconnect/wifi/NrfWiFiDriver.cpp +++ b/src/platform/nrfconnect/wifi/NrfWiFiDriver.cpp @@ -147,13 +147,21 @@ CHIP_ERROR NrfWiFiDriver::CommitConfiguration() CHIP_ERROR NrfWiFiDriver::RevertConfiguration() { + LoadFromStorage(); + if (WiFiManager::StationStatus::CONNECTING <= WiFiManager::Instance().GetStationStatus()) { + WiFiManager::WiFiInfo wifiInfo; + ReturnErrorOnFailure(WiFiManager::Instance().GetWiFiInfo(wifiInfo)); + if (mStagingNetwork.GetSsidSpan().data_equal(ByteSpan(wifiInfo.mSsid, wifiInfo.mSsidLen))) + { + // we are already connected to this network, so return prematurely + return CHIP_NO_ERROR; + } + WiFiManager::Instance().Disconnect(); } - LoadFromStorage(); - if (mStagingNetwork.IsConfigured()) { WiFiManager::ConnectionHandling handling{ [] { Instance().OnNetworkStatusChanged(Status::kSuccess); },