From 71dc663f45fac8a4d104bfa9cc0e8bed9b15773e Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Fri, 2 Jun 2023 10:39:41 +0200 Subject: [PATCH] [nrfconnect] Added calculating unique id length based on kconfig 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. --- config/nrfconnect/chip-module/Kconfig | 7 +++++++ src/platform/nrfconnect/CHIPDevicePlatformConfig.h | 7 +++++++ src/platform/nrfconnect/FactoryDataProvider.cpp | 2 ++ 3 files changed, 16 insertions(+) diff --git a/config/nrfconnect/chip-module/Kconfig b/config/nrfconnect/chip-module/Kconfig index e5fbdb405e365d..e3d311808a7466 100644 --- a/config/nrfconnect/chip-module/Kconfig +++ b/config/nrfconnect/chip-module/Kconfig @@ -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 diff --git a/src/platform/nrfconnect/CHIPDevicePlatformConfig.h b/src/platform/nrfconnect/CHIPDevicePlatformConfig.h index f92203a93e1641..2a5c45abcb3136 100644 --- a/src/platform/nrfconnect/CHIPDevicePlatformConfig.h +++ b/src/platform/nrfconnect/CHIPDevicePlatformConfig.h @@ -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 diff --git a/src/platform/nrfconnect/FactoryDataProvider.cpp b/src/platform/nrfconnect/FactoryDataProvider.cpp index 86fb8a354b9a5a..45adec502140e5 100644 --- a/src/platform/nrfconnect/FactoryDataProvider.cpp +++ b/src/platform/nrfconnect/FactoryDataProvider.cpp @@ -323,6 +323,8 @@ CHIP_ERROR FactoryDataProvider::GetRotatingDeviceIdUniqueId(Mu memcpy(uniqueIdSpan.data(), mFactoryData.rd_uid.data, mFactoryData.rd_uid.len); + uniqueIdSpan.reduce_size(mFactoryData.rd_uid.len); + return CHIP_NO_ERROR; }