@@ -129,18 +129,27 @@ CHIP_ERROR NXPWiFiDriver::RevertConfiguration()
129129{
130130 struct wlan_network searchedNetwork = { 0 };
131131
132- /* If network was added we have to remove it (as the connection failed) from wifi driver to be able
133- to connect to another network next commissioning */
134- if (wlan_get_network_byname (mStagingNetwork .ssid , &searchedNetwork) == WM_SUCCESS)
132+ /* If network was added we have to remove it (only if device is not connected to a wifi network) from wifi driver to be able
133+ to connect to another network next commissioning.
134+ Do not remove the network if the device is already connected to a WiFi network,
135+ example scenario: TC-CNET-4.9
136+ */
137+ if (!is_sta_connected () && wlan_get_network_byname (mStagingNetwork .ssid , &searchedNetwork) == WM_SUCCESS)
135138 {
136139 if (wlan_remove_network (mStagingNetwork .ssid ) != WM_SUCCESS)
137140 {
138141 return CHIP_ERROR_INTERNAL;
139142 }
140143 }
144+
145+ /* Reset mStagingNetwork as it may have been updated during add/update network operation */
141146 mStagingNetwork = mSavedNetwork ;
142147
143- return CHIP_NO_ERROR;
148+ // succeed right away if no saved network
149+ VerifyOrReturnError (mStagingNetwork .ssidLen > 0 , CHIP_NO_ERROR);
150+ // Connect to saved network
151+ return ConnectWiFiNetwork (mStagingNetwork .ssid , mStagingNetwork .ssidLen , mStagingNetwork .credentials ,
152+ mStagingNetwork .credentialsLen );
144153}
145154
146155bool NXPWiFiDriver::NetworkMatch (const WiFiNetwork & network, ByteSpan networkId)
0 commit comments