From 1cd23a2f051b6937f78ba31680c8d506a7c3dae7 Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi <54454955+selissia@users.noreply.github.com> Date: Wed, 20 Oct 2021 16:20:07 -0400 Subject: [PATCH] Allow Config Manager on the Darwin platform to store Discriminator in RAM (#10584) * Allow Config Manager on the Darwin platform to store Discriminator in RAM * Restyled by clang-format * Make mPosixSetupDiscriminator class member static * Define the static member in the .cpp file * Restyled by clang-format * Use explicit value in the initializer * Restyled by clang-format * Minor refactoring to address PR comments * Delete unused labels Co-authored-by: Restyled.io --- src/platform/Darwin/PosixConfig.cpp | 16 ++++++++++++---- src/platform/Darwin/PosixConfig.h | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/platform/Darwin/PosixConfig.cpp b/src/platform/Darwin/PosixConfig.cpp index e15bab933eb6b6..4959b2ff293c5e 100644 --- a/src/platform/Darwin/PosixConfig.cpp +++ b/src/platform/Darwin/PosixConfig.cpp @@ -70,6 +70,8 @@ const PosixConfig::Key PosixConfig::kConfigKey_Breadcrumb = { kConfigNam // Prefix used for NVS keys that contain Chip group encryption keys. const char PosixConfig::kGroupKeyNamePrefix[] = "gk-"; +uint16_t PosixConfig::mPosixSetupDiscriminator = 0xF00; // CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR + CHIP_ERROR PosixConfig::Init() { CHIP_ERROR err = CHIP_NO_ERROR; @@ -88,9 +90,12 @@ CHIP_ERROR PosixConfig::ReadConfigValue(Key key, bool & val) CHIP_ERROR PosixConfig::ReadConfigValue(Key key, uint32_t & val) { CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - SuccessOrExit(err); -exit: + if (key == kConfigKey_SetupDiscriminator) + { + val = mPosixSetupDiscriminator; + return CHIP_NO_ERROR; + } return err; } @@ -133,9 +138,12 @@ CHIP_ERROR PosixConfig::WriteConfigValue(Key key, bool val) CHIP_ERROR PosixConfig::WriteConfigValue(Key key, uint32_t val) { CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - SuccessOrExit(err); -exit: + if (key == kConfigKey_SetupDiscriminator) + { + mPosixSetupDiscriminator = val; + return CHIP_NO_ERROR; + } return err; } diff --git a/src/platform/Darwin/PosixConfig.h b/src/platform/Darwin/PosixConfig.h index 2964199bce4f49..1dcd7158c39431 100644 --- a/src/platform/Darwin/PosixConfig.h +++ b/src/platform/Darwin/PosixConfig.h @@ -100,6 +100,10 @@ class PosixConfig // NVS Namespace helper functions. static CHIP_ERROR EnsureNamespace(const char * ns); static CHIP_ERROR ClearNamespace(const char * ns); + +private: + // TODO: This is temporary until Darwin implements a proper ReadConfigValue + static uint16_t mPosixSetupDiscriminator; }; struct PosixConfig::Key