| /* |
| * |
| * Copyright (c) 2019 Google LLC. |
| * Copyright (c) 2018 Nest Labs, Inc. |
| * All rights reserved. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| /** |
| * @file |
| * Utilities for interacting with the the ESP32 "NVS" key-value store. |
| */ |
| |
| #ifndef ESP32_CONFIG_H |
| #define ESP32_CONFIG_H |
| |
| #include <Weave/DeviceLayer/internal/WeaveDeviceLayerInternal.h> |
| |
| namespace nl { |
| namespace Weave { |
| namespace DeviceLayer { |
| namespace Internal { |
| |
| /** |
| * Provides functions and definitions for accessing device configuration information on the ESP32. |
| * |
| * This class is designed to be mixed-in to concrete implementation classes as a means to |
| * provide access to configuration information to generic base classes. |
| */ |
| class ESP32Config |
| { |
| public: |
| |
| struct Key; |
| |
| // Maximum length of an NVS key name, as specified in the ESP-IDF documentation. |
| static constexpr size_t kMaxConfigKeyNameLength = 15; |
| |
| // NVS namespaces used to store device configuration information. |
| static const char kConfigNamespace_WeaveFactory[]; |
| static const char kConfigNamespace_WeaveConfig[]; |
| static const char kConfigNamespace_WeaveCounters[]; |
| |
| // Key definitions for well-known keys. |
| static const Key kConfigKey_SerialNum; |
| static const Key kConfigKey_ManufAttestDeviceId; |
| static const Key kConfigKey_ManufAttestDeviceCert; |
| static const Key kConfigKey_ManufAttestDeviceICACerts; |
| static const Key kConfigKey_ManufAttestDevicePrivateKey; |
| static const Key kConfigKey_ProductRevision; |
| static const Key kConfigKey_ManufacturingDate; |
| static const Key kConfigKey_PairingCode; |
| static const Key kConfigKey_FabricId; |
| static const Key kConfigKey_ServiceConfig; |
| static const Key kConfigKey_PairedAccountId; |
| static const Key kConfigKey_ServiceId; |
| static const Key kConfigKey_FabricSecret; |
| static const Key kConfigKey_GroupKeyIndex; |
| static const Key kConfigKey_LastUsedEpochKeyId; |
| static const Key kConfigKey_FailSafeArmed; |
| static const Key kConfigKey_WiFiStationSecType; |
| static const Key kConfigKey_OperationalDeviceId; |
| static const Key kConfigKey_OperationalDeviceCert; |
| static const Key kConfigKey_OperationalDeviceICACerts; |
| static const Key kConfigKey_OperationalDevicePrivateKey; |
| |
| static const char kGroupKeyNamePrefix[]; |
| |
| // Config value accessors. |
| static WEAVE_ERROR ReadConfigValue(Key key, bool & val); |
| static WEAVE_ERROR ReadConfigValue(Key key, uint32_t & val); |
| static WEAVE_ERROR ReadConfigValue(Key key, uint64_t & val); |
| static WEAVE_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen); |
| static WEAVE_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen); |
| static WEAVE_ERROR WriteConfigValue(Key key, bool val); |
| static WEAVE_ERROR WriteConfigValue(Key key, uint32_t val); |
| static WEAVE_ERROR WriteConfigValue(Key key, uint64_t val); |
| static WEAVE_ERROR WriteConfigValueStr(Key key, const char * str); |
| static WEAVE_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen); |
| static WEAVE_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen); |
| static WEAVE_ERROR ClearConfigValue(Key key); |
| static bool ConfigValueExists(Key key); |
| |
| // NVS Namespace helper functions. |
| static WEAVE_ERROR EnsureNamespace(const char * ns); |
| static WEAVE_ERROR ClearNamespace(const char * ns); |
| }; |
| |
| struct ESP32Config::Key |
| { |
| const char * Namespace; |
| const char * Name; |
| |
| bool operator==(const Key & other) const; |
| }; |
| |
| inline bool ESP32Config::Key::operator==(const Key & other) const |
| { |
| return strcmp(Namespace, other.Namespace) == 0 && strcmp(Name, other.Name) == 0; |
| } |
| |
| |
| } // namespace Internal |
| } // namespace DeviceLayer |
| } // namespace Weave |
| } // namespace nl |
| |
| #endif // ESP32_CONFIG_H |