Skip to content

Commit

Permalink
[ESP32] Handeled commissioning case with invalid ssid/pass (#18472)
Browse files Browse the repository at this point in the history
* [ESP32] Handeled commissioning case with invalid ssid/pass

* Rebase and send network-not-found message to chip-tool just 1sec before timeout

* Resolved conflict

* Resolved merge conflicts

* Updated comment

* Added delay from device side

* Removed the delay added to client

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Feb 14, 2024
1 parent fb7de2a commit 2108640
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/platform/ESP32/NetworkCommissioningDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,47 @@ void ESPWiFiDriver::OnConnectWiFiNetwork()
{
if (mpConnectCallback)
{
DeviceLayer::SystemLayer().CancelTimer(OnConnectWiFiNetworkFailed, NULL);
mpConnectCallback->OnResult(Status::kSuccess, CharSpan(), 0);
mpConnectCallback = nullptr;
}
}

void ESPWiFiDriver::OnConnectWiFiNetworkFailed()
{
if (mpConnectCallback)
{
mpConnectCallback->OnResult(Status::kNetworkNotFound, CharSpan(), 0);
mpConnectCallback = nullptr;
}
}

void ESPWiFiDriver::OnConnectWiFiNetworkFailed(chip::System::Layer * aLayer, void * aAppState)
{
CHIP_ERROR error = chip::DeviceLayer::Internal::ESP32Utils::ClearWiFiStationProvision();
if (error != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "ClearWiFiStationProvision failed: %s", chip::ErrorStr(error));
}
ESPWiFiDriver::GetInstance().OnConnectWiFiNetworkFailed();
}

void ESPWiFiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callback)
{
CHIP_ERROR err = CHIP_NO_ERROR;
Status networkingStatus = Status::kSuccess;
CHIP_ERROR err = CHIP_NO_ERROR;
Status networkingStatus = Status::kSuccess;
const uint32_t secToMiliSec = 1000;

VerifyOrExit(NetworkMatch(mStagingNetwork, networkId), networkingStatus = Status::kNetworkIDNotFound);
VerifyOrExit(mpConnectCallback == nullptr, networkingStatus = Status::kUnknownError);
ChipLogProgress(NetworkProvisioning, "ESP NetworkCommissioningDelegate: SSID: %.*s", static_cast<int>(networkId.size()),
networkId.data());

err = ConnectWiFiNetwork(reinterpret_cast<const char *>(mStagingNetwork.ssid), mStagingNetwork.ssidLen,
err = ConnectWiFiNetwork(reinterpret_cast<const char *>(mStagingNetwork.ssid), mStagingNetwork.ssidLen,
reinterpret_cast<const char *>(mStagingNetwork.credentials), mStagingNetwork.credentialsLen);

err = DeviceLayer::SystemLayer().StartTimer(
static_cast<System::Clock::Timeout>(kWiFiConnectNetworkTimeoutSeconds * secToMiliSec), OnConnectWiFiNetworkFailed, NULL);
mpConnectCallback = callback;
exit:
if (err != CHIP_NO_ERROR)
Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class ESPWiFiDriver final : public WiFiDriver

CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen);
void OnConnectWiFiNetwork();
void OnConnectWiFiNetworkFailed();
static void OnConnectWiFiNetworkFailed(chip::System::Layer * aLayer, void * aAppState);
void OnScanWiFiNetworkDone();
void OnNetworkStatusChange();

Expand Down

0 comments on commit 2108640

Please sign in to comment.