From 1017295f755eb1df982c607b2de3867e1371e5f3 Mon Sep 17 00:00:00 2001 From: Terence Hampson Date: Tue, 25 Apr 2023 09:29:37 -0400 Subject: [PATCH] Fix Disconnect RPC for ESP 32 (#26231) * Fix Disconnect RPC for ESP 32 * Restyle --- examples/platform/esp32/Rpc.cpp | 10 +++++++--- src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/platform/esp32/Rpc.cpp b/examples/platform/esp32/Rpc.cpp index 3d865ed13bdc7a..1ad91dddef4253 100644 --- a/examples/platform/esp32/Rpc.cpp +++ b/examples/platform/esp32/Rpc.cpp @@ -204,8 +204,11 @@ class Esp32WiFi final : public WiFi size_t password_size = std::min(sizeof(password) - 1, static_cast(request.secret.size)); memcpy(password, request.secret.bytes, password_size); password[password_size] = '\0'; - if (chip::DeviceLayer::NetworkCommissioning::ESPWiFiDriver::GetInstance().ConnectWiFiNetwork( - ssid, strlen(ssid), password, strlen(password)) != CHIP_NO_ERROR) + chip::DeviceLayer::PlatformMgr().LockChipStack(); + CHIP_ERROR error = chip::DeviceLayer::NetworkCommissioning::ESPWiFiDriver::GetInstance().ConnectWiFiNetwork( + ssid, strlen(ssid), password, strlen(password)); + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); + if (error != CHIP_NO_ERROR) { return pw::Status::Internal(); } @@ -214,8 +217,9 @@ class Esp32WiFi final : public WiFi pw::Status Disconnect(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override { + chip::DeviceLayer::PlatformMgr().LockChipStack(); chip::DeviceLayer::ConnectivityMgr().ClearWiFiStationProvision(); - chip::DeviceLayer::ConnectivityMgr().SetWiFiStationMode(chip::DeviceLayer::ConnectivityManager::kWiFiStationMode_Disabled); + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); return pw::OkStatus(); } diff --git a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp index 4c962d24a5e5b0..48251a27129962 100644 --- a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp +++ b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp @@ -105,6 +105,12 @@ void ConnectivityManagerImpl::_ClearWiFiStationProvision(void) { if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled) { + CHIP_ERROR error = chip::DeviceLayer::Internal::ESP32Utils::ClearWiFiStationProvision(); + if (error != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "ClearWiFiStationProvision failed: %s", chip::ErrorStr(error)); + return; + } DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP DeviceLayer::SystemLayer().ScheduleWork(DriveAPState, NULL);