blob: 95fc03971808c8a6a6bbb320e2b1776ec10a109c [file] [log] [blame]
* Copyright (c) 2020-2022 Project CHIP Authors
* 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
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
#pragma once
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include "chip_porting.h"
#include <string.h>
namespace chip {
namespace DeviceLayer {
namespace Internal {
class AmebaConfig
struct Key;
// Maximum length of an NVS key name.
static constexpr size_t kMaxConfigKeyNameLength = 15;
// NVS namespaces used to store device configuration information.
static const char kConfigNamespace_ChipFactory[];
static const char kConfigNamespace_ChipConfig[];
static const char kConfigNamespace_ChipCounters[];
static const char kConfigNamespace_ChipFabric1[];
static const char kConfigNamespace_ChipFabric2[];
static const char kConfigNamespace_ChipFabric3[];
static const char kConfigNamespace_ChipFabric4[];
static const char kConfigNamespace_ChipFabric5[];
static const char kConfigNamespace_ChipACL[];
static const char kConfigNamespace_ChipGroupMessageCounters[];
static const char kConfigNamespace_ChipAttributes[];
static const char kConfigNamespace_ChipBindingTable[];
static const char kConfigNamespace_ChipOTA[];
static const char kConfigNamespace_ChipFailSafe[];
static const char kConfigNamespace_ChipSessionResumption[];
static const char kConfigNamespace_ChipDeviceInfoProvider[];
static const char kConfigNamespace_ChipGroupDataProvider[];
static const char kConfigNamespace_ChipOthers[];
static const char kConfigNamespace_ChipOthers2[];
// Key definitions for well-known keys.
static const Key kConfigKey_SerialNum;
static const Key kConfigKey_MfrDeviceId;
static const Key kConfigKey_MfrDeviceCert;
static const Key kConfigKey_MfrDeviceICACerts;
static const Key kConfigKey_MfrDevicePrivateKey;
static const Key kConfigKey_HardwareVersion;
static const Key kConfigKey_ManufacturingDate;
static const Key kConfigKey_SetupPinCode;
static const Key kConfigKey_ServiceConfig;
static const Key kConfigKey_PairedAccountId;
static const Key kConfigKey_ServiceId;
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 Key kConfigKey_SetupDiscriminator;
static const Key kConfigKey_RegulatoryLocation;
static const Key kConfigKey_CountryCode;
static const Key kConfigKey_Spake2pIterationCount;
static const Key kConfigKey_Spake2pSalt;
static const Key kConfigKey_Spake2pVerifier;
// Counter keys
static const Key kConfigKey_UniqueId;
static const Key kCounterKey_RebootCount;
static const Key kCounterKey_UpTime;
static const Key kCounterKey_TotalOperationalHours;
static const Key kCounterKey_BootReason;
// Config value accessors.
static CHIP_ERROR ReadConfigValue(Key key, bool & val);
static CHIP_ERROR ReadConfigValue(Key key, uint32_t & val);
static CHIP_ERROR ReadConfigValue(Key key, uint64_t & val);
static CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen);
static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen);
static CHIP_ERROR WriteConfigValue(Key key, bool val);
static CHIP_ERROR WriteConfigValue(Key key, uint32_t val);
static CHIP_ERROR WriteConfigValue(Key key, uint64_t val);
static CHIP_ERROR WriteConfigValueStr(Key key, const char * str);
static CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen);
static CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen);
static CHIP_ERROR ClearConfigValue(Key key);
static bool ConfigValueExists(Key key);
static CHIP_ERROR EnsureNamespace(const char * ns);
static CHIP_ERROR EnsureNamespace2(const char * ns);
static CHIP_ERROR ClearNamespace(const char * ns);
static void RunConfigUnitTest(void);
struct AmebaConfig::Key
const char * Namespace;
const char * Name;
bool operator==(const Key & other) const;
inline bool AmebaConfig::Key::operator==(const Key & other) const
return strcmp(Namespace, other.Namespace) == 0 && strcmp(Name, other.Name) == 0;
} // namespace Internal
} // namespace DeviceLayer
} // namespace chip