diff --git a/src/platform/Ameba/ConnectivityManagerImpl.cpp b/src/platform/Ameba/ConnectivityManagerImpl.cpp index ce2ff544c66d34..6b28a01f0b37ec 100644 --- a/src/platform/Ameba/ConnectivityManagerImpl.cpp +++ b/src/platform/Ameba/ConnectivityManagerImpl.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -584,6 +585,12 @@ void ConnectivityManagerImpl::OnStationConnected() event.Type = DeviceEventType::kWiFiConnectivityChange; event.WiFiConnectivityChange.Result = kConnectivity_Established; PlatformMgr().PostEventOrDie(&event); + WiFiDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetWiFiDiagnosticsDelegate(); + + if (delegate) + { + delegate->OnConnectionStatusChanged(chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::WiFiConnectionStatus::kConnected)); + } UpdateInternetConnectivityState(); } @@ -595,6 +602,42 @@ void ConnectivityManagerImpl::OnStationDisconnected() event.Type = DeviceEventType::kWiFiConnectivityChange; event.WiFiConnectivityChange.Result = kConnectivity_Lost; PlatformMgr().PostEventOrDie(&event); + WiFiDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetWiFiDiagnosticsDelegate(); + uint16_t reason = NetworkCommissioning::AmebaWiFiDriver::GetInstance().GetLastDisconnectReason(); + uint8_t associationFailureCause = chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCause::kUnknown); + + if (delegate) + { + switch (reason) + { + case RTW_NO_ERROR: + case RTW_NONE_NETWORK: + associationFailureCause = chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCause::kSsidNotFound); + delegate->OnAssociationFailureDetected(associationFailureCause, reason); + break; + case RTW_CONNECT_FAIL: + associationFailureCause = chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCause::kAssociationFailed); + delegate->OnAssociationFailureDetected(associationFailureCause, reason); + break; + case RTW_WRONG_PASSWORD: + associationFailureCause = chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCause::kAuthenticationFailed); + delegate->OnAssociationFailureDetected(associationFailureCause, reason); + break; +#if defined(CONFIG_PLATFORM_8710C) + case RTW_4WAY_HANDSHAKE_TIMEOUT: +#endif + case RTW_DHCP_FAIL: + case RTW_UNKNOWN: + break; + + default: + delegate->OnAssociationFailureDetected(associationFailureCause, reason); + break; + } + delegate->OnDisconnectionDetected(reason); + delegate->OnConnectionStatusChanged(chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::WiFiConnectionStatus::kNotConnected)); + } + UpdateInternetConnectivityState(); }