From 18456332d200a2e3a37e64c4b3c6692235bd9ed3 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Tue, 21 Jun 2022 21:43:29 +0800 Subject: [PATCH] [Ameba] Handle WiFi-Diagnostic events and add SupportsWatermarks (#19795) * [DGSW] Add SupportsWatermarks method that returns true - Also fixes feature-map, kWaterMarks bit will be set * [DGWiFi] Handle WiFi-Diagnostics events - After receiving WiFi-Diagnostic events, call WiFiDiagnosticsDelegate functions * Restyled by clang-format Co-authored-by: Restyled.io --- .../Ameba/ConnectivityManagerImpl.cpp | 48 +++++++++++++++++++ .../Ameba/DiagnosticDataProviderImpl.h | 1 + 2 files changed, 49 insertions(+) diff --git a/src/platform/Ameba/ConnectivityManagerImpl.cpp b/src/platform/Ameba/ConnectivityManagerImpl.cpp index ce2ff544c66d34..8c4ede5aaa05b9 100644 --- a/src/platform/Ameba/ConnectivityManagerImpl.cpp +++ b/src/platform/Ameba/ConnectivityManagerImpl.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -584,6 +585,13 @@ 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 +603,46 @@ 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(); } diff --git a/src/platform/Ameba/DiagnosticDataProviderImpl.h b/src/platform/Ameba/DiagnosticDataProviderImpl.h index ae060e037c15b9..d6c062fdbf0812 100644 --- a/src/platform/Ameba/DiagnosticDataProviderImpl.h +++ b/src/platform/Ameba/DiagnosticDataProviderImpl.h @@ -37,6 +37,7 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider // ===== Methods that implement the PlatformManager abstract interface. + bool SupportsWatermarks() override { return true; } CHIP_ERROR GetCurrentHeapFree(uint64_t & currentHeapFree) override; CHIP_ERROR GetCurrentHeapUsed(uint64_t & currentHeapUsed) override; CHIP_ERROR GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark) override;