Skip to content

Commit

Permalink
Allow Config Manager on the Darwin platform to store Discriminator in…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>
  • Loading branch information
selissia and restyled-commits authored Oct 20, 2021
1 parent ff6f5b1 commit 1cd23a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/platform/Darwin/PosixConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/platform/Darwin/PosixConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1cd23a2

Please sign in to comment.