3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2020 Nest Labs, Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 * Provides the implementation of the Device Layer ConfigurationManager object
23 * for K32W platforms using the NXP SDK.
26 /* this file behaves like a config.h, comes first */
27 #include <platform/internal/CHIPDeviceLayerInternal.h>
29 #include <platform/ConfigurationManager.h>
30 #include <platform/K32W/K32WConfig.h>
31 #include <platform/internal/GenericConfigurationManagerImpl.cpp>
33 #include "fsl_reset.h"
36 namespace DeviceLayer {
38 using namespace ::chip::DeviceLayer::Internal;
40 // TODO: Define a Singleton instance of CHIP Group Key Store here
42 /** Singleton instance of the ConfigurationManager implementation object.
44 ConfigurationManagerImpl ConfigurationManagerImpl::sInstance;
46 CHIP_ERROR ConfigurationManagerImpl::_Init()
51 // Initialize the generic implementation base class.
52 err = Internal::GenericConfigurationManagerImpl<ConfigurationManagerImpl>::_Init();
55 // TODO: Initialize the global GroupKeyStore object here
57 // If the fail-safe was armed when the device last shutdown, initiate a factory reset.
58 if (_GetFailSafeArmed(failSafeArmed) == CHIP_NO_ERROR && failSafeArmed)
60 ChipLogProgress(DeviceLayer, "Detected fail-safe armed on reboot; initiating factory reset");
61 _InitiateFactoryReset();
69 bool ConfigurationManagerImpl::_CanFactoryReset()
71 // TODO: query the application to determine if factory reset is allowed.
75 void ConfigurationManagerImpl::_InitiateFactoryReset()
77 PlatformMgr().ScheduleWork(DoFactoryReset);
80 CHIP_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key persistedStorageKey,
85 err = ReadConfigValueCounter(persistedStorageKey, value);
86 if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
88 err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
96 CHIP_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key persistedStorageKey,
99 // This method reads Chip Persisted Counter type nvm3 objects.
100 // (where persistedStorageKey represents an index to the counter).
103 err = WriteConfigValueCounter(persistedStorageKey, value);
104 if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
106 err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
114 void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
118 ChipLogProgress(DeviceLayer, "Performing factory reset");
120 err = FactoryResetConfig();
121 if (err != CHIP_NO_ERROR)
123 ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", ErrorStr(err));
126 #if CHIP_DEVICE_CONFIG_ENABLE_THREAD
128 ThreadStackMgr().ErasePersistentInfo();
130 #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
132 // Restart the system.
133 ChipLogProgress(DeviceLayer, "System restarting");
137 } // namespace DeviceLayer