From c43609436f1bddc389f879f77a54d0c625216923 Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Fri, 19 May 2023 10:02:59 -0400 Subject: [PATCH] =?UTF-8?q?[Silabs]Add=20fallback=20test=20value=20for=20m?= =?UTF-8?q?andatory=20attributes=20VendorName=20and=20Produ=E2=80=A6=20(#2?= =?UTF-8?q?6642)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add fallback test value for mandatory attributes VendorName and ProductName * remplace memcpy by copystring * efr32+wf200 platform didn't previously use ChipMemString, add the header so it reconize the function within the namespace --- .../silabs/SilabsDeviceDataProvider.cpp | 30 +++++++++++++++++-- scripts/build/builders/efr32.py | 2 +- scripts/examples/gn_efr32_example.sh | 2 +- .../silabs/CHIPDevicePlatformConfig.h | 22 ++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/examples/platform/silabs/SilabsDeviceDataProvider.cpp b/examples/platform/silabs/SilabsDeviceDataProvider.cpp index 53e3e5fa3da259..eb0f8fee82ff1c 100644 --- a/examples/platform/silabs/SilabsDeviceDataProvider.cpp +++ b/examples/platform/silabs/SilabsDeviceDataProvider.cpp @@ -18,6 +18,7 @@ #include "SilabsDeviceDataProvider.h" #include #include +#include #include #include #include @@ -313,7 +314,17 @@ CHIP_ERROR SilabsDeviceDataProvider::GetSetupPayload(MutableCharSpan & payloadBu CHIP_ERROR SilabsDeviceDataProvider::GetVendorName(char * buf, size_t bufSize) { size_t vendorNameLen = 0; // without counting null-terminator - return SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_VendorName, buf, bufSize, vendorNameLen); + CHIP_ERROR err = SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_VendorName, buf, bufSize, vendorNameLen); +#if defined(CHIP_DEVICE_CONFIG_TEST_VENDOR_NAME) + if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + VerifyOrReturnError(buf != nullptr, CHIP_ERROR_NO_MEMORY); + VerifyOrReturnError(bufSize > strlen(CHIP_DEVICE_CONFIG_TEST_VENDOR_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); + Platform::CopyString(buf, bufSize, CHIP_DEVICE_CONFIG_TEST_VENDOR_NAME); + err = CHIP_NO_ERROR; + } +#endif + return err; } CHIP_ERROR SilabsDeviceDataProvider::GetVendorId(uint16_t & vendorId) @@ -339,7 +350,17 @@ CHIP_ERROR SilabsDeviceDataProvider::GetVendorId(uint16_t & vendorId) CHIP_ERROR SilabsDeviceDataProvider::GetProductName(char * buf, size_t bufSize) { size_t productNameLen = 0; // without counting null-terminator - return SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_ProductName, buf, bufSize, productNameLen); + CHIP_ERROR err = SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_ProductName, buf, bufSize, productNameLen); +#if defined(CHIP_DEVICE_CONFIG_TEST_PRODUCT_NAME) + if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + VerifyOrReturnError(buf != nullptr, CHIP_ERROR_NO_MEMORY); + VerifyOrReturnError(bufSize > strlen(CHIP_DEVICE_CONFIG_TEST_VENDOR_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); + Platform::CopyString(buf, bufSize, CHIP_DEVICE_CONFIG_TEST_PRODUCT_NAME); + err = CHIP_NO_ERROR; + } +#endif + return err; } CHIP_ERROR SilabsDeviceDataProvider::GetProductId(uint16_t & productId) @@ -370,7 +391,10 @@ CHIP_ERROR SilabsDeviceDataProvider::GetHardwareVersionString(char * buf, size_t #if defined(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING) if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { - memcpy(buf, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING, bufSize); + VerifyOrReturnError(buf != nullptr, CHIP_ERROR_NO_MEMORY); + VerifyOrReturnError(bufSize > strlen(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING), + CHIP_ERROR_BUFFER_TOO_SMALL); + Platform::CopyString(buf, bufSize, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING); err = CHIP_NO_ERROR; } #endif // CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING diff --git a/scripts/build/builders/efr32.py b/scripts/build/builders/efr32.py index de9184ec58a10c..32edf5b966606e 100644 --- a/scripts/build/builders/efr32.py +++ b/scripts/build/builders/efr32.py @@ -216,7 +216,7 @@ def __init__(self, ['git', 'describe', '--always', '--dirty', '--exclude', '*']).decode('ascii').strip() branchName = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('ascii').strip() self.extra_gn_options.append( - 'sl_matter_version_str="v1.0-%s-%s"' % (branchName, shortCommitSha)) + 'sl_matter_version_str="v1.1-%s-%s"' % (branchName, shortCommitSha)) if "GSDK_ROOT" in os.environ: # EFR32 SDK is very large. If the SDK path is already known (the diff --git a/scripts/examples/gn_efr32_example.sh b/scripts/examples/gn_efr32_example.sh index e19f031184da0c..4b00c3aff8fb60 100755 --- a/scripts/examples/gn_efr32_example.sh +++ b/scripts/examples/gn_efr32_example.sh @@ -276,7 +276,7 @@ else { ShortCommitSha=$(git describe --always --dirty --exclude '*') branchName=$(git rev-parse --abbrev-ref HEAD) - optArgs+="sl_matter_version_str=\"v1.0-$branchName-$ShortCommitSha\" " + optArgs+="sl_matter_version_str=\"v1.1-$branchName-$ShortCommitSha\" " } &>/dev/null fi diff --git a/src/platform/silabs/CHIPDevicePlatformConfig.h b/src/platform/silabs/CHIPDevicePlatformConfig.h index fb749556e19b2c..3462402a228a58 100644 --- a/src/platform/silabs/CHIPDevicePlatformConfig.h +++ b/src/platform/silabs/CHIPDevicePlatformConfig.h @@ -61,6 +61,28 @@ #define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION SL_HARDWARE_VERSION #endif +/** + * Allow for some test/fall-back values to be used + * Production builds shall set to 0 or remove this option + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_TEST_SETUP_PARAMS +#define CHIP_DEVICE_CONFIG_ENABLE_TEST_SETUP_PARAMS 1 +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_TEST_SETUP_PARAMS +/** + * @brief Fallback value for the basic information cluster's Vendor name attribute + * if the actual vendor name is not provisioned in the device memory. + */ +#define CHIP_DEVICE_CONFIG_TEST_VENDOR_NAME "Silabs" + +/** + * @brief Fallback value for the basic information cluster's product name attribute + * if the actual vendor name is not provisioned in the device memory. + */ +#define CHIP_DEVICE_CONFIG_TEST_PRODUCT_NAME "SL_Sample" +#endif // CHIP_DEVICE_CONFIG_ENABLE_TEST_SETUP_PARAMS + #if defined(SL_WIFI) #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 1 #else