Skip to content

Commit

Permalink
[Silabs]Add fallback test value for mandatory attributes VendorName a…
Browse files Browse the repository at this point in the history
…nd Produ… (#26642)

* 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
  • Loading branch information
jmartinez-silabs authored and pull[bot] committed Nov 2, 2023
1 parent 12d7253 commit 9592ece
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
30 changes: 27 additions & 3 deletions examples/platform/silabs/SilabsDeviceDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "SilabsDeviceDataProvider.h"
#include <crypto/CHIPCryptoPAL.h>
#include <lib/support/Base64.h>
#include <lib/support/CHIPMemString.h>
#include <platform/silabs/SilabsConfig.h>
#include <setup_payload/Base38Encode.h>
#include <setup_payload/SetupPayload.h>
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/builders/efr32.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples/gn_efr32_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit 9592ece

Please sign in to comment.