Skip to content

Commit a9f4e57

Browse files
authored
[Ameba][v1.4-branch] Add OnConnectWiFiNetworkFailed to AmebaWiFiDriver (project-chip#40941)
* OnConnectWiFiNetworkFailed is called when Ameba failed to connect into the network * This fixes issue when chip-tool failed to commission Ameba after one failed attempt
1 parent 4725fe1 commit a9f4e57

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

src/platform/Ameba/ConnectivityManagerImpl.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ void ConnectivityManagerImpl::OnStationDisconnected()
601601
{
602602
switch (reason)
603603
{
604-
case RTW_NO_ERROR:
605604
case RTW_NONE_NETWORK:
606605
associationFailureCause =
607606
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kSsidNotFound);
@@ -612,18 +611,16 @@ void ConnectivityManagerImpl::OnStationDisconnected()
612611
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kAssociationFailed);
613612
delegate->OnAssociationFailureDetected(associationFailureCause, reason);
614613
break;
614+
#if defined(CONFIG_PLATFORM_8710C)
615+
case RTW_4WAY_HANDSHAKE_TIMEOUT:
616+
#endif
615617
case RTW_WRONG_PASSWORD:
616618
associationFailureCause = chip::to_underlying(
617619
chip::app::Clusters::WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kAuthenticationFailed);
618620
delegate->OnAssociationFailureDetected(associationFailureCause, reason);
619621
break;
620-
#if defined(CONFIG_PLATFORM_8710C)
621-
case RTW_4WAY_HANDSHAKE_TIMEOUT:
622-
#endif
623622
case RTW_DHCP_FAIL:
624623
case RTW_UNKNOWN:
625-
break;
626-
627624
default:
628625
delegate->OnAssociationFailureDetected(associationFailureCause, reason);
629626
break;
@@ -633,6 +630,11 @@ void ConnectivityManagerImpl::OnStationDisconnected()
633630
chip::to_underlying(chip::app::Clusters::WiFiNetworkDiagnostics::ConnectionStatusEnum::kNotConnected));
634631
}
635632

633+
if (reason != RTW_NO_ERROR)
634+
{
635+
NetworkCommissioning::AmebaWiFiDriver::GetInstance().OnConnectWiFiNetworkFailed(reason);
636+
}
637+
636638
UpdateInternetConnectivityState();
637639
}
638640

src/platform/Ameba/NetworkCommissioningDriver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class AmebaWiFiDriver final : public WiFiDriver
110110

111111
CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen);
112112
void OnConnectWiFiNetwork();
113+
void OnConnectWiFiNetworkFailed(uint16_t reason);
113114
void OnScanWiFiNetworkDone();
114115
void OnNetworkStatusChange();
115116

src/platform/Ameba/NetworkCommissioningWiFiDriver.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,34 @@ void AmebaWiFiDriver::OnConnectWiFiNetwork()
172172
}
173173
}
174174

175+
void AmebaWiFiDriver::OnConnectWiFiNetworkFailed(uint16_t reason)
176+
{
177+
if (mpConnectCallback)
178+
{
179+
Status status;
180+
switch (reason)
181+
{
182+
case RTW_NONE_NETWORK:
183+
status = Status::kNetworkNotFound;
184+
break;
185+
case RTW_CONNECT_FAIL:
186+
#if defined(CONFIG_PLATFORM_8710C)
187+
case RTW_4WAY_HANDSHAKE_TIMEOUT:
188+
#endif
189+
case RTW_WRONG_PASSWORD:
190+
status = Status::kAuthFailure;
191+
break;
192+
case RTW_DHCP_FAIL:
193+
case RTW_UNKNOWN:
194+
default:
195+
status = Status::kUnknownError;
196+
break;
197+
}
198+
mpConnectCallback->OnResult(status, CharSpan(), 0);
199+
mpConnectCallback = nullptr;
200+
}
201+
}
202+
175203
void AmebaWiFiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callback)
176204
{
177205
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -189,6 +217,7 @@ void AmebaWiFiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callb
189217
{
190218
networkingStatus = Status::kUnknownError;
191219
}
220+
192221
if (networkingStatus != Status::kSuccess)
193222
{
194223
ChipLogError(NetworkProvisioning, "Failed to connect to WiFi network:%s", chip::ErrorStr(err));

0 commit comments

Comments
 (0)