Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / Darwin / PosixConfig.cpp
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2019-2020 Google LLC.
5  *    Copyright (c) 2018 Nest Labs, Inc.
6  *    All rights reserved.
7  *
8  *    Licensed under the Apache License, Version 2.0 (the "License");
9  *    you may not use this file except in compliance with the License.
10  *    You may obtain a copy of the License at
11  *
12  *        http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing, software
15  *    distributed under the License is distributed on an "AS IS" BASIS,
16  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *    See the License for the specific language governing permissions and
18  *    limitations under the License.
19  */
20
21 /**
22  *    @file
23  *          Utilities for interacting with multiple file partitions and maps
24  *          key-value config calls to the correct partition.
25  */
26
27 #include <platform/internal/CHIPDeviceLayerInternal.h>
28 #include <platform/internal/testing/ConfigUnitTest.h>
29
30 #include <core/CHIPEncoding.h>
31 #include <platform/Darwin/PosixConfig.h>
32 #include <support/CodeUtils.h>
33
34 namespace chip {
35 namespace DeviceLayer {
36 namespace Internal {
37
38 // *** CAUTION ***: Changing the names or namespaces of these values will *break* existing devices.
39
40 // NVS namespaces used to store device configuration information.
41 const char PosixConfig::kConfigNamespace_ChipFactory[]  = "chip-factory";
42 const char PosixConfig::kConfigNamespace_ChipConfig[]   = "chip-config";
43 const char PosixConfig::kConfigNamespace_ChipCounters[] = "chip-counters";
44
45 // Keys stored in the Chip-factory namespace
46 const PosixConfig::Key PosixConfig::kConfigKey_SerialNum           = { kConfigNamespace_ChipFactory, "serial-num" };
47 const PosixConfig::Key PosixConfig::kConfigKey_MfrDeviceId         = { kConfigNamespace_ChipFactory, "device-id" };
48 const PosixConfig::Key PosixConfig::kConfigKey_MfrDeviceCert       = { kConfigNamespace_ChipFactory, "device-cert" };
49 const PosixConfig::Key PosixConfig::kConfigKey_MfrDeviceICACerts   = { kConfigNamespace_ChipFactory, "device-ca-certs" };
50 const PosixConfig::Key PosixConfig::kConfigKey_MfrDevicePrivateKey = { kConfigNamespace_ChipFactory, "device-key" };
51 const PosixConfig::Key PosixConfig::kConfigKey_ProductRevision     = { kConfigNamespace_ChipFactory, "product-rev" };
52 const PosixConfig::Key PosixConfig::kConfigKey_ManufacturingDate   = { kConfigNamespace_ChipFactory, "mfg-date" };
53 const PosixConfig::Key PosixConfig::kConfigKey_SetupPinCode        = { kConfigNamespace_ChipFactory, "pin-code" };
54 const PosixConfig::Key PosixConfig::kConfigKey_SetupDiscriminator  = { kConfigNamespace_ChipFactory, "discriminator" };
55
56 // Keys stored in the Chip-config namespace
57 const PosixConfig::Key PosixConfig::kConfigKey_FabricId                    = { kConfigNamespace_ChipConfig, "fabric-id" };
58 const PosixConfig::Key PosixConfig::kConfigKey_ServiceConfig               = { kConfigNamespace_ChipConfig, "service-config" };
59 const PosixConfig::Key PosixConfig::kConfigKey_PairedAccountId             = { kConfigNamespace_ChipConfig, "account-id" };
60 const PosixConfig::Key PosixConfig::kConfigKey_ServiceId                   = { kConfigNamespace_ChipConfig, "service-id" };
61 const PosixConfig::Key PosixConfig::kConfigKey_FabricSecret                = { kConfigNamespace_ChipConfig, "fabric-secret" };
62 const PosixConfig::Key PosixConfig::kConfigKey_GroupKeyIndex               = { kConfigNamespace_ChipConfig, "group-key-index" };
63 const PosixConfig::Key PosixConfig::kConfigKey_LastUsedEpochKeyId          = { kConfigNamespace_ChipConfig, "last-ek-id" };
64 const PosixConfig::Key PosixConfig::kConfigKey_FailSafeArmed               = { kConfigNamespace_ChipConfig, "fail-safe-armed" };
65 const PosixConfig::Key PosixConfig::kConfigKey_WiFiStationSecType          = { kConfigNamespace_ChipConfig, "sta-sec-type" };
66 const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceId         = { kConfigNamespace_ChipConfig, "op-device-id" };
67 const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceCert       = { kConfigNamespace_ChipConfig, "op-device-cert" };
68 const PosixConfig::Key PosixConfig::kConfigKey_OperationalDeviceICACerts   = { kConfigNamespace_ChipConfig, "op-device-ca-certs" };
69 const PosixConfig::Key PosixConfig::kConfigKey_OperationalDevicePrivateKey = { kConfigNamespace_ChipConfig, "op-device-key" };
70
71 // Prefix used for NVS keys that contain Chip group encryption keys.
72 const char PosixConfig::kGroupKeyNamePrefix[] = "gk-";
73
74 CHIP_ERROR PosixConfig::Init()
75 {
76     CHIP_ERROR err = CHIP_NO_ERROR;
77     return err;
78 }
79
80 CHIP_ERROR PosixConfig::ReadConfigValue(Key key, bool & val)
81 {
82     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
83     SuccessOrExit(err);
84
85 exit:
86     return err;
87 }
88
89 CHIP_ERROR PosixConfig::ReadConfigValue(Key key, uint32_t & val)
90 {
91     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
92     SuccessOrExit(err);
93
94 exit:
95     return err;
96 }
97
98 CHIP_ERROR PosixConfig::ReadConfigValue(Key key, uint64_t & val)
99 {
100     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
101     SuccessOrExit(err);
102
103 exit:
104     return err;
105 }
106
107 CHIP_ERROR PosixConfig::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen)
108 {
109     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
110     SuccessOrExit(err);
111
112 exit:
113     return err;
114 }
115
116 CHIP_ERROR PosixConfig::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen)
117 {
118     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
119     SuccessOrExit(err);
120
121 exit:
122     return err;
123 }
124
125 CHIP_ERROR PosixConfig::WriteConfigValue(Key key, bool val)
126 {
127     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
128     SuccessOrExit(err);
129
130 exit:
131     return err;
132 }
133
134 CHIP_ERROR PosixConfig::WriteConfigValue(Key key, uint32_t val)
135 {
136     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
137     SuccessOrExit(err);
138
139 exit:
140     return err;
141 }
142
143 CHIP_ERROR PosixConfig::WriteConfigValue(Key key, uint64_t val)
144 {
145     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
146     SuccessOrExit(err);
147
148 exit:
149     return err;
150 }
151
152 CHIP_ERROR PosixConfig::WriteConfigValueStr(Key key, const char * str)
153 {
154     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
155     SuccessOrExit(err);
156
157 exit:
158     return err;
159 }
160
161 CHIP_ERROR PosixConfig::WriteConfigValueStr(Key key, const char * str, size_t strLen)
162 {
163     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
164     SuccessOrExit(err);
165
166 exit:
167     return err;
168 }
169
170 CHIP_ERROR PosixConfig::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen)
171 {
172     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
173     SuccessOrExit(err);
174
175 exit:
176     return err;
177 }
178
179 CHIP_ERROR PosixConfig::ClearConfigValue(Key key)
180 {
181     CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
182     SuccessOrExit(err);
183
184 exit:
185     return err;
186 }
187
188 bool PosixConfig::ConfigValueExists(Key key)
189 {
190     return false;
191 }
192
193 CHIP_ERROR PosixConfig::EnsureNamespace(const char * ns)
194 {
195     CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
196     SuccessOrExit(err);
197
198 exit:
199     return err;
200 }
201
202 CHIP_ERROR PosixConfig::ClearNamespace(const char * ns)
203 {
204     CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
205     SuccessOrExit(err);
206
207 exit:
208     return err;
209 }
210
211 CHIP_ERROR PosixConfig::FactoryResetConfig(void)
212 {
213     CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
214     SuccessOrExit(err);
215
216 exit:
217     return err;
218 }
219
220 void PosixConfig::RunConfigUnitTest() {}
221
222 } // namespace Internal
223 } // namespace DeviceLayer
224 } // namespace chip