@@ -180,16 +180,43 @@ void WiFiManager::IPv6MgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mg
180180 }
181181}
182182
183+ void WiFiManager::SuppEventHandler (net_mgmt_event_callback * cb, uint32_t mgmtEvent, net_if * iface)
184+ {
185+ if (mgmtEvent == NET_EVENT_SUPPLICANT_NOT_READY)
186+ {
187+ SystemLayer ().ScheduleLambda ([] {
188+ if (Instance ().mWiFiState == WIFI_STATE_COMPLETED)
189+ {
190+ Instance ().mReconnect = true ;
191+ Instance ().NotifyDisconnected (WLAN_REASON_UNSPECIFIED);
192+ }
193+ });
194+ }
195+ else if (mgmtEvent == NET_EVENT_SUPPLICANT_READY)
196+ {
197+ SystemLayer ().ScheduleLambda ([] {
198+ if (Instance ().mWantedNetwork .IsConfigured () && Instance ().mReconnect )
199+ {
200+ Instance ().mReconnect = false ;
201+ Instance ().SetLowPowerMode (Instance ().mWiFiPsEnabled );
202+ Instance ().Scan (Instance ().mWantedNetwork .GetSsidSpan (), nullptr , nullptr , true /* internal scan */ );
203+ }
204+ });
205+ }
206+ }
207+
183208CHIP_ERROR WiFiManager::Init ()
184209{
185210 mNetIf = InetUtils::GetWiFiInterface ();
186211 VerifyOrReturnError (mNetIf != nullptr , INET_ERROR_UNKNOWN_INTERFACE);
187212
188213 net_mgmt_init_event_callback (&mWiFiMgmtClbk , WifiMgmtEventHandler, kWifiManagementEvents );
189214 net_mgmt_init_event_callback (&mIPv6MgmtClbk , IPv6MgmtEventHandler, kIPv6ManagementEvents );
215+ net_mgmt_init_event_callback (&mSuppClbk , SuppEventHandler, kSupplicantEvents );
190216
191217 net_mgmt_add_event_callback (&mWiFiMgmtClbk );
192218 net_mgmt_add_event_callback (&mIPv6MgmtClbk );
219+ net_mgmt_add_event_callback (&mSuppClbk );
193220
194221 ChipLogDetail (DeviceLayer, " WiFiManager has been initialized" );
195222
@@ -576,19 +603,7 @@ void WiFiManager::DisconnectHandler(Platform::UniquePtr<uint8_t> data, size_t le
576603 reason = WLAN_REASON_UNSPECIFIED;
577604 break ;
578605 }
579- Instance ().SetLastDisconnectReason (reason);
580-
581- ChipLogProgress (DeviceLayer, " WiFi station disconnected" );
582- Instance ().mWiFiState = WIFI_STATE_DISCONNECTED;
583- Instance ().PostConnectivityStatusChange (kConnectivity_Lost );
584-
585- WiFiDiagnosticsDelegate * delegate = GetDiagnosticDataProvider ().GetWiFiDiagnosticsDelegate ();
586- if (delegate)
587- {
588- delegate->OnConnectionStatusChanged (
589- to_underlying (app::Clusters::WiFiNetworkDiagnostics::ConnectionStatusEnum::kNotConnected ));
590- delegate->OnDisconnectionDetected (reason);
591- }
606+ Instance ().NotifyDisconnected (reason);
592607 });
593608
594609 if (CHIP_NO_ERROR == err)
@@ -598,6 +613,23 @@ void WiFiManager::DisconnectHandler(Platform::UniquePtr<uint8_t> data, size_t le
598613 }
599614}
600615
616+ void WiFiManager::NotifyDisconnected (uint16_t reason)
617+ {
618+ SetLastDisconnectReason (reason);
619+
620+ ChipLogProgress (DeviceLayer, " WiFi station disconnected" );
621+ mWiFiState = WIFI_STATE_DISCONNECTED;
622+ PostConnectivityStatusChange (kConnectivity_Lost );
623+
624+ WiFiDiagnosticsDelegate * delegate = GetDiagnosticDataProvider ().GetWiFiDiagnosticsDelegate ();
625+ if (delegate)
626+ {
627+ delegate->OnConnectionStatusChanged (
628+ to_underlying (app::Clusters::WiFiNetworkDiagnostics::ConnectionStatusEnum::kNotConnected ));
629+ delegate->OnDisconnectionDetected (reason);
630+ }
631+ }
632+
601633void WiFiManager::IPv6AddressChangeHandler (const void * data)
602634{
603635 const in6_addr * addr = reinterpret_cast <const in6_addr *>(data);
@@ -692,7 +724,8 @@ CHIP_ERROR WiFiManager::SetLowPowerMode(bool onoff)
692724 if ((currentConfig.ps_params .enabled == WIFI_PS_ENABLED && onoff == false ) ||
693725 (currentConfig.ps_params .enabled == WIFI_PS_DISABLED && onoff == true ))
694726 {
695- wifi_ps_params params{ .enabled = onoff ? WIFI_PS_ENABLED : WIFI_PS_DISABLED };
727+ mWiFiPsEnabled = onoff;
728+ wifi_ps_params params{ .enabled = mWiFiPsEnabled ? WIFI_PS_ENABLED : WIFI_PS_DISABLED };
696729 if (net_mgmt (NET_REQUEST_WIFI_PS, mNetIf , ¶ms, sizeof (params)))
697730 {
698731 ChipLogError (DeviceLayer, " Set low power mode request failed" );
0 commit comments