3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2020 Texas Instruments Incorporated
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * Utilities for accessing persisted device configuration on
22 * Texas Instruments cc13x2_26x2 SoCs.
27 #include <platform/internal/CHIPDeviceLayerInternal.h>
29 #include <ti/common/nv/nvintf.h>
32 namespace DeviceLayer {
35 class CC13X2_26X2Config
40 // TODO: Define a proper system ID in upstream driver
41 static constexpr uint16_t kNvinf_sysid_chip = (13);
43 static const uint16_t kCC13X2_26X2ChipConfig_Sysid = kNvinf_sysid_chip;
44 static const uint16_t kCC13X2_26X2ChipFactory_Sysid = kNvinf_sysid_chip;
45 static const uint16_t kCC13X2_26X2ChipCounters_Sysid = kNvinf_sysid_chip;
47 // Key definitions for well-known keys.
48 static const Key kConfigKey_SerialNum;
49 static const Key kConfigKey_MfrDeviceId;
50 static const Key kConfigKey_MfrDeviceCert;
51 static const Key kConfigKey_MfrDeviceICACerts;
52 static const Key kConfigKey_MfrDevicePrivateKey;
53 static const Key kConfigKey_ProductRevision;
54 static const Key kConfigKey_ManufacturingDate;
55 static const Key kConfigKey_SetupPinCode;
56 static const Key kConfigKey_SetupDiscriminator;
57 static const Key kConfigKey_FabricId;
58 static const Key kConfigKey_ServiceConfig;
59 static const Key kConfigKey_PairedAccountId;
60 static const Key kConfigKey_ServiceId;
61 static const Key kConfigKey_FabricSecret;
62 static const Key kConfigKey_GroupKeyIndex;
63 static const Key kConfigKey_LastUsedEpochKeyId;
64 static const Key kConfigKey_FailSafeArmed;
65 static const Key kConfigKey_WiFiStationSecType;
66 static const Key kConfigKey_OperationalDeviceId;
67 static const Key kConfigKey_OperationalDeviceCert;
68 static const Key kConfigKey_OperationalDeviceICACerts;
69 static const Key kConfigKey_OperationalDevicePrivateKey;
71 static CHIP_ERROR Init(void);
73 // Config value accessors.
74 static CHIP_ERROR ReadConfigValue(Key key, bool & val);
75 static CHIP_ERROR ReadConfigValue(Key key, uint32_t & val);
76 static CHIP_ERROR ReadConfigValue(Key key, uint64_t & val);
77 static CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen);
78 static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen);
79 static CHIP_ERROR WriteConfigValue(Key key, bool val);
80 static CHIP_ERROR WriteConfigValue(Key key, uint32_t val);
81 static CHIP_ERROR WriteConfigValue(Key key, uint64_t val);
82 static CHIP_ERROR WriteConfigValueStr(Key key, const char * str);
83 static CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen);
84 static CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen);
85 static CHIP_ERROR ClearConfigValue(Key key);
86 static bool ConfigValueExists(Key key);
87 static CHIP_ERROR FactoryResetConfig(void);
89 static void RunConfigUnitTest(void);
92 struct CC13X2_26X2Config::Key
96 bool operator==(const Key & other) const;
99 inline bool CC13X2_26X2Config::Key::operator==(const Key & other) const
101 return (nvID.systemID == other.nvID.systemID && nvID.itemID == other.nvID.itemID && nvID.subID == other.nvID.subID);
104 } // namespace Internal
105 } // namespace DeviceLayer