3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 * Utilities for accessing persistent device configuration on
26 #include <platform/internal/CHIPDeviceLayerInternal.h>
29 namespace DeviceLayer {
33 * Provides functions and definitions for accessing device configuration information on Zephyr platforms.
35 * This implementation uses Zephyr Settings API as the underlying storage layer.
37 * This class is designed to be mixed-in to concrete implementation classes as a means to
38 * provide access to configuration information to generic base classes.
43 using Key = const char[];
45 // Key definitions for well-known keys.
46 static const Key kConfigKey_SerialNum;
47 static const Key kConfigKey_MfrDeviceId;
48 static const Key kConfigKey_MfrDeviceCert;
49 static const Key kConfigKey_MfrDeviceICACerts;
50 static const Key kConfigKey_MfrDevicePrivateKey;
51 static const Key kConfigKey_ProductRevision;
52 static const Key kConfigKey_ManufacturingDate;
53 static const Key kConfigKey_SetupPinCode;
54 static const Key kConfigKey_SetupDiscriminator;
55 static const Key kConfigKey_FabricId;
56 static const Key kConfigKey_ServiceConfig;
57 static const Key kConfigKey_PairedAccountId;
58 static const Key kConfigKey_ServiceId;
59 static const Key kConfigKey_FabricSecret;
60 static const Key kConfigKey_GroupKeyIndex;
61 static const Key kConfigKey_LastUsedEpochKeyId;
62 static const Key kConfigKey_FailSafeArmed;
63 static const Key kConfigKey_OperationalDeviceId;
64 static const Key kConfigKey_OperationalDeviceCert;
65 static const Key kConfigKey_OperationalDeviceICACerts;
66 static const Key kConfigKey_OperationalDevicePrivateKey;
68 static CHIP_ERROR Init(void);
70 // Config value accessors.
71 static CHIP_ERROR ReadConfigValue(Key key, bool & val);
72 static CHIP_ERROR ReadConfigValue(Key key, uint32_t & val);
73 static CHIP_ERROR ReadConfigValue(Key key, uint64_t & val);
74 static CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen);
75 static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen);
76 static CHIP_ERROR ReadConfigValueCounter(::chip::Platform::PersistedStorage::Key counterId, uint32_t & val);
77 static CHIP_ERROR WriteConfigValue(Key key, bool val);
78 static CHIP_ERROR WriteConfigValue(Key key, uint32_t val);
79 static CHIP_ERROR WriteConfigValue(Key key, uint64_t val);
80 static CHIP_ERROR WriteConfigValueStr(Key key, const char * str);
81 static CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen);
82 static CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen);
83 static CHIP_ERROR WriteConfigValueCounter(::chip::Platform::PersistedStorage::Key counterId, uint32_t val);
84 static CHIP_ERROR ClearConfigValue(Key key);
85 static bool ConfigValueExists(Key key);
86 static CHIP_ERROR FactoryResetConfig(void);
88 static void RunConfigUnitTest(void);
91 static bool BuildCounterConfigKey(::chip::Platform::PersistedStorage::Key counterId, char key[]);
93 } // namespace Internal
94 } // namespace DeviceLayer