@@ -180,16 +180,43 @@ void WiFiManager::IPv6MgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mg
180
180
}
181
181
}
182
182
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
+
183
208
CHIP_ERROR WiFiManager::Init ()
184
209
{
185
210
mNetIf = InetUtils::GetWiFiInterface ();
186
211
VerifyOrReturnError (mNetIf != nullptr , INET_ERROR_UNKNOWN_INTERFACE);
187
212
188
213
net_mgmt_init_event_callback (&mWiFiMgmtClbk , WifiMgmtEventHandler, kWifiManagementEvents );
189
214
net_mgmt_init_event_callback (&mIPv6MgmtClbk , IPv6MgmtEventHandler, kIPv6ManagementEvents );
215
+ net_mgmt_init_event_callback (&mSuppClbk , SuppEventHandler, kSupplicantEvents );
190
216
191
217
net_mgmt_add_event_callback (&mWiFiMgmtClbk );
192
218
net_mgmt_add_event_callback (&mIPv6MgmtClbk );
219
+ net_mgmt_add_event_callback (&mSuppClbk );
193
220
194
221
ChipLogDetail (DeviceLayer, " WiFiManager has been initialized" );
195
222
@@ -576,19 +603,7 @@ void WiFiManager::DisconnectHandler(Platform::UniquePtr<uint8_t> data, size_t le
576
603
reason = WLAN_REASON_UNSPECIFIED;
577
604
break ;
578
605
}
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);
592
607
});
593
608
594
609
if (CHIP_NO_ERROR == err)
@@ -598,6 +613,23 @@ void WiFiManager::DisconnectHandler(Platform::UniquePtr<uint8_t> data, size_t le
598
613
}
599
614
}
600
615
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
+
601
633
void WiFiManager::IPv6AddressChangeHandler (const void * data)
602
634
{
603
635
const in6_addr * addr = reinterpret_cast <const in6_addr *>(data);
@@ -692,7 +724,8 @@ CHIP_ERROR WiFiManager::SetLowPowerMode(bool onoff)
692
724
if ((currentConfig.ps_params .enabled == WIFI_PS_ENABLED && onoff == false ) ||
693
725
(currentConfig.ps_params .enabled == WIFI_PS_DISABLED && onoff == true ))
694
726
{
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 };
696
729
if (net_mgmt (NET_REQUEST_WIFI_PS, mNetIf , ¶ms, sizeof (params)))
697
730
{
698
731
ChipLogError (DeviceLayer, " Set low power mode request failed" );
0 commit comments