Skip to content

Commit

Permalink
[ESP32] Handling Wifi-diagnostic events at esp32 side (#17631)
Browse files Browse the repository at this point in the history
* Handling Wifi-diagnostic events at esp32 side

* Address review comments

Co-authored-by: Boris Zbarsky <[email protected]>

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 22, 2023
1 parent 7753c27 commit 1694780
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/DiagnosticDataProvider.h>
#include <platform/ESP32/ESP32Utils.h>
#include <platform/ESP32/NetworkCommissioningDriver.h>
#include <platform/internal/BLEManager.h>
Expand Down Expand Up @@ -661,6 +662,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();
}
Expand All @@ -674,6 +682,70 @@ void ConnectivityManagerImpl::OnStationDisconnected()
event.Type = DeviceEventType::kWiFiConnectivityChange;
event.WiFiConnectivityChange.Result = kConnectivity_Lost;
PlatformMgr().PostEventOrDie(&event);
WiFiDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetWiFiDiagnosticsDelegate();
uint16_t reason = NetworkCommissioning::ESPWiFiDriver::GetInstance().GetLastDisconnectReason();
uint8_t associationFailureCause =
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCause::kUnknown);

switch (reason)
{
case WIFI_REASON_ASSOC_TOOMANY:
case WIFI_REASON_NOT_ASSOCED:
case WIFI_REASON_ASSOC_NOT_AUTHED:
case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT:
case WIFI_REASON_GROUP_CIPHER_INVALID:
case WIFI_REASON_UNSUPP_RSN_IE_VERSION:
case WIFI_REASON_AKMP_INVALID:
case WIFI_REASON_CIPHER_SUITE_REJECTED:
case WIFI_REASON_PAIRWISE_CIPHER_INVALID:
associationFailureCause =
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCause::kAssociationFailed);
if (delegate)
{
delegate->OnAssociationFailureDetected(associationFailureCause, reason);
}
break;
case WIFI_REASON_NOT_AUTHED:
case WIFI_REASON_MIC_FAILURE:
case WIFI_REASON_IE_IN_4WAY_DIFFERS:
case WIFI_REASON_INVALID_RSN_IE_CAP:
case WIFI_REASON_INVALID_PMKID:
case WIFI_REASON_802_1X_AUTH_FAILED:
associationFailureCause =
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCause::kAuthenticationFailed);
if (delegate)
{
delegate->OnAssociationFailureDetected(associationFailureCause, reason);
}
break;
case WIFI_REASON_NO_AP_FOUND:
associationFailureCause =
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCause::kSsidNotFound);
if (delegate)
{
delegate->OnAssociationFailureDetected(associationFailureCause, reason);
}
case WIFI_REASON_BEACON_TIMEOUT:
case WIFI_REASON_AUTH_EXPIRE:
case WIFI_REASON_AUTH_LEAVE:
case WIFI_REASON_ASSOC_LEAVE:
case WIFI_REASON_ASSOC_EXPIRE:
break;

default:
if (delegate)
{
delegate->OnAssociationFailureDetected(associationFailureCause, reason);
}
break;
}

if (delegate)
{
delegate->OnDisconnectionDetected(reason);
delegate->OnConnectionStatusChanged(
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::WiFiConnectionStatus::kNotConnected));
}

UpdateInternetConnectivityState();
}
Expand Down

0 comments on commit 1694780

Please sign in to comment.