Skip to content

Commit

Permalink
[DGWiFi] Handle WiFi-Diagnostics events
Browse files Browse the repository at this point in the history
- After receiving WiFi-Diagnostic events, call WiFiDiagnosticsDelegate functions
  • Loading branch information
pankore committed Jun 21, 2022
1 parent c482ef1 commit 0de3014
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/platform/Ameba/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <platform/Ameba/AmebaUtils.h>
#include <platform/Ameba/NetworkCommissioningDriver.h>
#include <platform/internal/BLEManager.h>
#include <platform/DiagnosticDataProvider.h>
#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>

Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down

0 comments on commit 0de3014

Please sign in to comment.