Skip to content

Commit

Permalink
Revert server-side changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DejinChen committed Jun 12, 2024
1 parent 6668373 commit 2591e37
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 108 deletions.
4 changes: 0 additions & 4 deletions src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 0 additions & 49 deletions src/platform/ESP32/NetworkCommissioningDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/platform/ESP32/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1093,9 +1094,6 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::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();

Expand Down Expand Up @@ -1133,15 +1131,8 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::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);
Expand All @@ -1153,6 +1144,8 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::DoInit(otInstanc
ChipLogProgress(DeviceLayer, "OpenThread ifconfig up and thread start");
}

initNetworkCommissioningThreadDriver();

exit:

ChipLogProgress(DeviceLayer, "OpenThread started: %s", otThreadErrorToString(otErr));
Expand Down

0 comments on commit 2591e37

Please sign in to comment.