Skip to content

Commit

Permalink
[nrfconnect] Added calculating unique id length based on kconfig
Browse files Browse the repository at this point in the history
Currently the unique id length is fixed to 16 B and in nrfconnect
platform we allow to set unique id value through kconfig, which may
lead to a problem that length of selected data will not match the
unique id length hardcoded to 16 B.

Added calculating the unique id length based on Kconfig
or assigning the max value assumed for the factory data storage.
  • Loading branch information
kkasperczyk-no committed Jun 2, 2023
1 parent dad733c commit 71dc663
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config/nrfconnect/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ config CHIP_DEVICE_GENERATE_ROTATING_DEVICE_UID

endif #CHIP_FACTORY_DATA_BUILD

config CHIP_FACTORY_DATA_ROTATING_DEVICE_UID_MAX_LEN
bool "Maximum length of rotating device ID unique ID in bytes"
default 16
depends on CHIP_FACTORY_DATA
help
Maximum acceptable length of rotating device ID unique ID in bytes.

# See config/zephyr/Kconfig for full definition
config CHIP_FACTORY_RESET_ERASE_NVS
bool
Expand Down
7 changes: 7 additions & 0 deletions src/platform/nrfconnect/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,10 @@
#ifdef CONFIG_CHIP_EXTENDED_DISCOVERY
#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1
#endif // CONFIG_CHIP_EXTENDED_DISCOVERY

#ifndef CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID_LENGTH
#if CONFIG_CHIP_FACTORY_DATA
#define CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID_LENGTH CONFIG_CHIP_FACTORY_DATA_ROTATING_DEVICE_UID_MAX_LEN
#else
#define CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID_LENGTH ((sizeof(CONFIG_CHIP_DEVICE_ROTATING_DEVICE_UID) - 1) / 2)
#endif // CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID_LENGTH
2 changes: 2 additions & 0 deletions src/platform/nrfconnect/FactoryDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetRotatingDeviceIdUniqueId(Mu

memcpy(uniqueIdSpan.data(), mFactoryData.rd_uid.data, mFactoryData.rd_uid.len);

uniqueIdSpan.reduce_size(mFactoryData.rd_uid.len);

return CHIP_NO_ERROR;
}

Expand Down

0 comments on commit 71dc663

Please sign in to comment.