From 2591e37203b7ec6bf0b294aa4d5f1907da56513b Mon Sep 17 00:00:00 2001 From: chendejin Date: Wed, 12 Jun 2024 13:17:55 +0800 Subject: [PATCH] Revert server-side changes --- .../ESP32/ConnectivityManagerImpl_WiFi.cpp | 4 -- .../ESP32/NetworkCommissioningDriver.cpp | 49 ------------------- .../ESP32/NetworkCommissioningDriver.h | 3 -- ...enericNetworkCommissioningThreadDriver.cpp | 37 -------------- .../GenericNetworkCommissioningThreadDriver.h | 3 -- ...nericThreadStackManagerImpl_OpenThread.hpp | 17 ++----- 6 files changed, 5 insertions(+), 108 deletions(-) diff --git a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp index aed25e2356cbcc..bbeaf6cdbc7169 100644 --- a/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp +++ b/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp @@ -391,10 +391,6 @@ CHIP_ERROR ConnectivityManagerImpl::InitWiFi() mWiFiStationMode = kWiFiStationMode_Disabled; mWiFiStationState = kWiFiStationState_NotConnected; mWiFiStationReconnectInterval = System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_WIFI_STATION_RECONNECT_INTERVAL); - if (!NetworkCommissioning::ESPWiFiDriver::GetInstance().GetEnabled()) - { - mWiFiStationMode = kWiFiStationMode_ApplicationControlled; - } #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP mLastAPDemandTime = System::Clock::kZero; diff --git a/src/platform/ESP32/NetworkCommissioningDriver.cpp b/src/platform/ESP32/NetworkCommissioningDriver.cpp index bf4bc98a1fbb87..2871c4c3f2031d 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.cpp +++ b/src/platform/ESP32/NetworkCommissioningDriver.cpp @@ -147,11 +147,6 @@ CHIP_ERROR ESPWiFiDriver::CommitConfiguration() CHIP_ERROR ESPWiFiDriver::RevertConfiguration() { mStagingNetwork = mSavedNetwork; - if (!GetEnabled()) - { - // When reverting, set InterfaceEnabled to default value (true). - ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Delete(kInterfaceEnabled)); - } return CHIP_NO_ERROR; } @@ -201,12 +196,6 @@ Status ESPWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableC CHIP_ERROR ESPWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen) { - if (!GetEnabled()) - { - // Set InterfaceEnabled to default value (true). - ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Delete(kInterfaceEnabled)); - } - // If device is already connected to WiFi, then disconnect the WiFi, // clear the WiFi configurations and add the newly provided WiFi configurations. if (chip::DeviceLayer::Internal::ESP32Utils::IsStationProvisioned()) @@ -318,44 +307,6 @@ void ESPWiFiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callbac } } -CHIP_ERROR ESPWiFiDriver::SetEnabled(bool enabled) -{ - if (enabled == GetEnabled()) - { - return CHIP_NO_ERROR; - } - - ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(kInterfaceEnabled, &enabled, sizeof(enabled))); - - if (!enabled) - { - if (chip::DeviceLayer::Internal::ESP32Utils::IsStationProvisioned()) - { - ChipLogProgress(DeviceLayer, "Disconnecting WiFi station interface"); - esp_err_t err = esp_wifi_disconnect(); - if (err != ESP_OK) - { - ChipLogError(DeviceLayer, "esp_wifi_disconnect() failed: %s", esp_err_to_name(err)); - return chip::DeviceLayer::Internal::ESP32Utils::MapError(err); - } - return ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_ApplicationControlled); - } - } - else - { - ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Enabled)); - } - return CHIP_NO_ERROR; -} - -bool ESPWiFiDriver::GetEnabled() -{ - bool value; - // InterfaceEnabled default value is true. - VerifyOrReturnValue(PersistedStorage::KeyValueStoreMgr().Get(kInterfaceEnabled, &value, sizeof(value)) == CHIP_NO_ERROR, true); - return value; -} - CHIP_ERROR ESPWiFiDriver::StartScanWiFiNetworks(ByteSpan ssid) { esp_err_t err = ESP_OK; diff --git a/src/platform/ESP32/NetworkCommissioningDriver.h b/src/platform/ESP32/NetworkCommissioningDriver.h index 5e85c0e61a2e08..447d6346dcbd1c 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.h +++ b/src/platform/ESP32/NetworkCommissioningDriver.h @@ -94,8 +94,6 @@ class ESPWiFiDriver final : public WiFiDriver // BaseDriver NetworkIterator * GetNetworks() override { return new WiFiNetworkIterator(this); } CHIP_ERROR Init(NetworkStatusChangeCallback * networkStatusChangeCallback) override; - CHIP_ERROR SetEnabled(bool enabled) override; - bool GetEnabled() override; void Shutdown() override; // WirelessDriver @@ -133,7 +131,6 @@ class ESPWiFiDriver final : public WiFiDriver } private: - static constexpr const char * kInterfaceEnabled = "g/esp/en"; bool NetworkMatch(const WiFiNetwork & network, ByteSpan networkId); CHIP_ERROR StartScanWiFiNetworks(ByteSpan ssid); diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp index af517afe62ca20..0a961a9f8e4afa 100644 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp +++ b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp @@ -95,12 +95,6 @@ CHIP_ERROR GenericThreadDriver::RevertConfiguration() // since the fail-safe was armed, so return with no error. ReturnErrorCodeIf(error == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND, CHIP_NO_ERROR); - if (!GetEnabled()) - { - // If backup is found, set InterfaceEnabled to default value (true). - ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Delete(kInterfaceEnabled)); - } - ChipLogProgress(NetworkProvisioning, "Reverting Thread operational dataset"); if (error == CHIP_NO_ERROR) @@ -172,12 +166,6 @@ void GenericThreadDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * c { NetworkCommissioning::Status status = MatchesNetworkId(mStagingNetwork, networkId); - if (!GetEnabled()) - { - // Set InterfaceEnabled to default value (true). - ReturnOnFailure(PersistedStorage::KeyValueStoreMgr().Delete(kInterfaceEnabled)); - } - if (status == Status::kSuccess && BackupConfiguration() != CHIP_NO_ERROR) { status = Status::kUnknownError; @@ -195,31 +183,6 @@ void GenericThreadDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * c } } -CHIP_ERROR GenericThreadDriver::SetEnabled(bool enabled) -{ - if (enabled == GetEnabled()) - { - return CHIP_NO_ERROR; - } - - ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(kInterfaceEnabled, &enabled, sizeof(enabled))); - - if ((!enabled && DeviceLayer::ThreadStackMgrImpl().IsThreadEnabled()) || - (enabled && DeviceLayer::ThreadStackMgrImpl().IsThreadProvisioned())) - { - ReturnErrorOnFailure(DeviceLayer::ThreadStackMgrImpl().SetThreadEnabled(enabled)); - } - return CHIP_NO_ERROR; -} - -bool GenericThreadDriver::GetEnabled() -{ - bool value; - // InterfaceEnabled default value is true. - VerifyOrReturnValue(PersistedStorage::KeyValueStoreMgr().Get(kInterfaceEnabled, &value, sizeof(value)) == CHIP_NO_ERROR, true); - return value; -} - void GenericThreadDriver::ScanNetworks(ThreadDriver::ScanCallback * callback) { if (DeviceLayer::ThreadStackMgrImpl().StartThreadScan(callback) != CHIP_NO_ERROR) diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h index e98b9393818abe..28dc8f176ddd1f 100644 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h +++ b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h @@ -90,8 +90,6 @@ class GenericThreadDriver final : public ThreadDriver // BaseDriver NetworkIterator * GetNetworks() override { return new ThreadNetworkIterator(this); } CHIP_ERROR Init(Internal::BaseDriver::NetworkStatusChangeCallback * statusChangeCallback) override; - CHIP_ERROR SetEnabled(bool enabled) override; - bool GetEnabled() override; void Shutdown() override; // WirelessDriver @@ -116,7 +114,6 @@ class GenericThreadDriver final : public ThreadDriver void ScanNetworks(ThreadDriver::ScanCallback * callback) override; private: - static constexpr const char * kInterfaceEnabled = "g/gtd/en"; uint8_t scanNetworkTimeoutSeconds; uint8_t connectNetworkTimeout; static void OnThreadStateChangeHandler(const ChipDeviceEvent * event, intptr_t arg); diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp index 5ef4d8e748d08a..2056699d77c8c0 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp @@ -76,7 +76,8 @@ static_assert(OPENTHREAD_API_VERSION >= 219, "OpenThread version too old"); namespace { #ifndef _NO_NETWORK_COMMISSIONING_DRIVER_ NetworkCommissioning::GenericThreadDriver sGenericThreadDriver; -app::Clusters::NetworkCommissioning::Instance sThreadNetworkCommissioningInstance(0 /* Endpoint Id */, &sGenericThreadDriver); +app::Clusters::NetworkCommissioning::Instance + sThreadNetworkCommissioningInstance(CHIP_DEVICE_CONFIG_THREAD_NETWORK_ENDPOINT_ID /* Endpoint Id */, &sGenericThreadDriver); #endif void initNetworkCommissioningThreadDriver(void) @@ -1093,9 +1094,6 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::DoInit(otInstanc CHIP_ERROR err = CHIP_NO_ERROR; otError otErr = OT_ERROR_NONE; - // If InterfaceEnabled is false, do not start Thread - bool InterfaceEnabled = true; - // Arrange for OpenThread errors to be translated to text. RegisterOpenThreadErrorFormatter(); @@ -1133,15 +1131,8 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::DoInit(otInstanc memset(&mSrpClient, 0, sizeof(mSrpClient)); #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT - initNetworkCommissioningThreadDriver(); - -#ifndef _NO_NETWORK_COMMISSIONING_DRIVER_ - InterfaceEnabled = sGenericThreadDriver.GetEnabled(); - ChipLogError(DeviceLayer, "%s:%d interface:%d", __FILE__, __LINE__, InterfaceEnabled); -#endif - // If the Thread stack has been provisioned, but is not currently enabled, enable it now. - if (InterfaceEnabled && otThreadGetDeviceRole(mOTInst) == OT_DEVICE_ROLE_DISABLED && otDatasetIsCommissioned(otInst)) + if (otThreadGetDeviceRole(mOTInst) == OT_DEVICE_ROLE_DISABLED && otDatasetIsCommissioned(otInst)) { // Enable the Thread IPv6 interface. otErr = otIp6SetEnabled(otInst, true); @@ -1153,6 +1144,8 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::DoInit(otInstanc ChipLogProgress(DeviceLayer, "OpenThread ifconfig up and thread start"); } + initNetworkCommissioningThreadDriver(); + exit: ChipLogProgress(DeviceLayer, "OpenThread started: %s", otThreadErrorToString(otErr));