Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add add some basic information cluster attributes to cmd line args to the reference app #33303

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
901253c
added code to read vendor_name, product_name, hardware_version_string…
cjandhyala May 3, 2024
6c62371
fixed few typos
May 3, 2024
1af5cfd
added few comments
May 3, 2024
42ded2d
fixed review comments, changed functions to taking spans, not separat…
May 9, 2024
9e642fa
defined vendor_name, product_name, hardware_version_string and softwa…
Jul 1, 2024
49c388e
add the new config params to different platforms
Jul 8, 2024
a98cc54
fix compilation errors
Jul 8, 2024
4ad0269
updated command line arg comments
Jul 9, 2024
8d787ed
fix fake and tizen platform test errors
Jul 10, 2024
800c565
[Tizen] Initialize vendor and product names
arkq Jul 16, 2024
b19ffdf
Restyled by clang-format
restyled-commits Jul 16, 2024
94944cb
added code to read vendor_name, product_name, hardware_version_string…
cjandhyala May 3, 2024
2470475
fixed few typos
May 3, 2024
a351120
added few comments
May 3, 2024
ff682fb
fixed review comments, changed functions to taking spans, not separat…
May 9, 2024
6536e33
defined vendor_name, product_name, hardware_version_string and softwa…
Jul 1, 2024
2bf83ef
add the new config params to different platforms
Jul 8, 2024
4268b10
fix compilation errors
Jul 8, 2024
2242d54
updated command line arg comments
Jul 9, 2024
9fcc343
fix fake and tizen platform test errors
Jul 10, 2024
40d1a1a
[Tizen] Initialize vendor and product names
arkq Jul 16, 2024
399ddb7
Restyled by clang-format
restyled-commits Jul 16, 2024
7c468b9
fixed merged conflicts with latest code
cjandhyala Oct 9, 2024
c4c0e91
Merge branch 'master' into serial_number_args_to_app
cjandhyala Oct 9, 2024
21328d8
fixed a merge conflict
cjandhyala Oct 9, 2024
f350454
Merge branch 'serial_number_args_to_app' of github.com:cjandhyala/con…
cjandhyala Oct 9, 2024
cea2b21
Merge branch 'master' into serial_number_args_to_app
cjandhyala Oct 9, 2024
e217a7f
added code to read vendor_name, product_name, hardware_version_string…
cjandhyala May 3, 2024
67e1c3d
fixed few typos
May 3, 2024
009b934
updated PSOC6 and K32W0 Configs
Oct 10, 2024
3cd2bf4
Merge branch 'master' into serial_number_args_to_app
cjandhyala Oct 10, 2024
db6a9dd
Merge branch 'project-chip:master' into serial_number_args_to_app
cjandhyala Oct 11, 2024
9accc81
updated virtual functions to override
Oct 11, 2024
9736791
fix restyle comments and compilation errors
Oct 12, 2024
08b7479
Restyled by clang-format
restyled-commits Oct 12, 2024
84b9f51
fix compilation errors
Oct 14, 2024
bb8b3c6
fix compilation error on fake platform
Oct 14, 2024
16406e3
fix compilation error on k32w0 platform, disabled chip logging
Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions examples/platform/linux/CommissionableInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/TestOnlyCommissionableDataProvider.h>
#include <stdio.h>
cjandhyala marked this conversation as resolved.
Show resolved Hide resolved

#include "CommissionableInit.h"

Expand Down Expand Up @@ -99,6 +100,35 @@ CHIP_ERROR InitConfigurationManager(ConfigurationManagerImpl & configManager, Li
configManager.StoreProductId(options.payload.productID);
}

if (options.vendorName.HasValue())
{
CharSpan vendor_name(options.vendorName.Value().c_str(), options.vendorName.Value().size());
VerifyOrDie(configManager.StoreVendorName(vendor_name) == CHIP_NO_ERROR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these verify or die calls, is the user going to be able to tell what went wrong? This can happen fairly easily, right? If the user enters a too-long name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify or die, throws error if the user does not provide value to cmd line arg. if the user enters too long name, it doesn't throw error, but when we read from the basic information cluster, we get IM Error 0x00000501: General error: 0x01 (FAILURE). BTW its same API used for other cmd line args.

}
if (options.productName.HasValue())
{
CharSpan product_name(options.productName.Value().c_str(), options.productName.Value().size());
VerifyOrDie(configManager.StoreProductName(product_name) == CHIP_NO_ERROR);
}
if (options.hardwareVersionString.HasValue())
{
CharSpan hardware_version_string(options.hardwareVersionString.Value().c_str(),
options.hardwareVersionString.Value().size());
VerifyOrDie(configManager.StoreHardwareVersionString(hardware_version_string) == CHIP_NO_ERROR);
}
if (options.softwareVersionString.HasValue())
{
CharSpan software_version_string(options.softwareVersionString.Value().c_str(),
options.softwareVersionString.Value().size());
VerifyOrDie(configManager.StoreSoftwareVersionString(software_version_string) == CHIP_NO_ERROR);
}

if (options.serialNumber.HasValue())
{
CharSpan serial_number(options.serialNumber.Value().c_str(), options.serialNumber.Value().size());
VerifyOrDie(configManager.StoreSerialNumber(serial_number) == CHIP_NO_ERROR);
}

return CHIP_NO_ERROR;
}

Expand Down
48 changes: 48 additions & 0 deletions examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,17 @@ enum
#if CHIP_WITH_NLFAULTINJECTION
kDeviceOption_FaultInjection,
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
kDeviceOption_WiFi_PAF,
#endif

kDeviceOption_VendorName = 0x1028,
kDeviceOption_ProductName = 0x1029,
kDeviceOption_HardwareVersionString = 0x102a,
kDeviceOption_SoftwareVersionString = 0x102b,
kDeviceOption_SerialNumber = 0x102c,

};

constexpr unsigned kAppUsageLength = 64;
Expand All @@ -140,6 +148,11 @@ OptionDef sDeviceOptionDefs[] = {
{ "version", kArgumentRequired, kDeviceOption_Version },
{ "vendor-id", kArgumentRequired, kDeviceOption_VendorID },
{ "product-id", kArgumentRequired, kDeviceOption_ProductID },
{ "vendor-name", kArgumentRequired, kDeviceOption_VendorName },
{ "product-name", kArgumentRequired, kDeviceOption_ProductName },
{ "hardware-version-string", kArgumentRequired, kDeviceOption_HardwareVersionString },
{ "software-version-string", kArgumentRequired, kDeviceOption_SoftwareVersionString },
{ "serial-number", kArgumentRequired, kDeviceOption_SerialNumber },
{ "custom-flow", kArgumentRequired, kDeviceOption_CustomFlow },
{ "capabilities", kArgumentRequired, kDeviceOption_Capabilities },
{ "discriminator", kArgumentRequired, kDeviceOption_Discriminator },
Expand Down Expand Up @@ -230,6 +243,21 @@ const char * sDeviceOptionHelp =
" --product-id <id>\n"
" The Product ID is specified by vendor.\n"
"\n"
" --vendor-name <name>\n"
" The vendor name specified by the vendor.\n"
"\n"
" --product-name <name>\n"
" The product name specified by vendor.\n"
"\n"
" --hardware-version-string <string>\n"
" The HardwareVersionString used in the basic information cluster.\n"
"\n"
" --software-version-string <string>\n"
" The SoftwareVersionString used in the basic information cluster.\n"
"\n"
" --serial-number <serial_number>\n"
" The serial number specified by vendor.\n"
"\n"
" --custom-flow <Standard = 0 | UserActionRequired = 1 | Custom = 2>\n"
" A 2-bit unsigned enumeration specifying manufacturer-specific custom flow options.\n"
"\n"
Expand Down Expand Up @@ -685,6 +713,26 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
break;
}
#endif
case kDeviceOption_VendorName:
LinuxDeviceOptions::GetInstance().vendorName.SetValue(std::string{ aValue });
break;

case kDeviceOption_ProductName:
LinuxDeviceOptions::GetInstance().productName.SetValue(std::string{ aValue });
break;

case kDeviceOption_HardwareVersionString:
LinuxDeviceOptions::GetInstance().hardwareVersionString.SetValue(std::string{ aValue });
break;

case kDeviceOption_SoftwareVersionString:
LinuxDeviceOptions::GetInstance().softwareVersionString.SetValue(std::string{ aValue });
break;

case kDeviceOption_SerialNumber:
LinuxDeviceOptions::GetInstance().serialNumber.SetValue(std::string{ aValue });
break;

default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
retval = false;
Expand Down
8 changes: 8 additions & 0 deletions examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,18 @@ struct LinuxDeviceOptions
int32_t subscriptionCapacity = CHIP_IM_MAX_NUM_SUBSCRIPTIONS;
int32_t subscriptionResumptionRetryIntervalSec = -1;
#endif

#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
chip::Optional<std::vector<chip::Access::AccessRestrictionProvider::Entry>> commissioningArlEntries;
chip::Optional<std::vector<chip::Access::AccessRestrictionProvider::Entry>> arlEntries;
#endif

chip::Optional<std::string> vendorName;
chip::Optional<std::string> productName;
chip::Optional<std::string> hardwareVersionString;
chip::Optional<std::string> softwareVersionString;
chip::Optional<std::string> serialNumber;
cjandhyala marked this conversation as resolved.
Show resolved Hide resolved

static LinuxDeviceOptions & GetInstance();
};

Expand Down
11 changes: 10 additions & 1 deletion src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class ConfigurationManager
#endif
virtual CHIP_ERROR GetRegulatoryLocation(uint8_t & location) = 0;
virtual CHIP_ERROR GetCountryCode(char * buf, size_t bufSize, size_t & codeLen) = 0;
virtual CHIP_ERROR StoreSerialNumber(const char * serialNum, size_t serialNumLen) = 0;
virtual CHIP_ERROR StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) = 0;
virtual CHIP_ERROR StoreSoftwareVersion(uint32_t softwareVer) = 0;
virtual CHIP_ERROR StoreHardwareVersion(uint16_t hardwareVer) = 0;
Expand All @@ -133,6 +132,16 @@ class ConfigurationManager
virtual CHIP_ERROR SetFailSafeArmed(bool val) = 0;

virtual CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) = 0;
virtual CHIP_ERROR StoreSerialNumber(CharSpan serialNumber) = 0;
virtual CHIP_ERROR StoreVendorName(CharSpan vendorName) = 0;
virtual CHIP_ERROR StoreProductName(CharSpan productName) = 0;
virtual CHIP_ERROR StoreHardwareVersionString(CharSpan hardwareVersionString) = 0;
virtual CHIP_ERROR StoreSoftwareVersionString(CharSpan softwareVersionString) = 0;

virtual CHIP_ERROR StoreVendorName(const char * vendorName, size_t vendorNameLen) = 0;
virtual CHIP_ERROR StoreProductName(const char * productName, size_t productNameLen) = 0;
virtual CHIP_ERROR StoreHardwareVersionString(const char * hardwareVersionString, size_t hardwareVersionStringLen) = 0;
virtual CHIP_ERROR StoreSoftwareVersionString(const char * softwareVersionString, size_t softwareVersionStringLen) = 0;

#if CHIP_CONFIG_TEST
virtual void RunUnitTests() = 0;
Expand Down
13 changes: 12 additions & 1 deletion src/include/platform/internal/GenericConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
CHIP_ERROR StoreSoftwareVersion(uint32_t softwareVer) override;
CHIP_ERROR GetFirmwareBuildChipEpochTime(System::Clock::Seconds32 & buildTime) override;
CHIP_ERROR SetFirmwareBuildChipEpochTime(System::Clock::Seconds32 buildTime) override;
CHIP_ERROR StoreSerialNumber(const char * serialNum, size_t serialNumLen) override;
CHIP_ERROR StoreSerialNumber(CharSpan serialNumber) override;
CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) override;
CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) override;
CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf) override;
Expand Down Expand Up @@ -103,6 +103,17 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) override;
CHIP_ERROR StoreUniqueId(const char * uniqueId, size_t uniqueIdLen) override;
CHIP_ERROR GenerateUniqueId(char * buf, size_t bufSize) override;

CHIP_ERROR StoreVendorName(CharSpan vendorName) override;
CHIP_ERROR StoreProductName(CharSpan productName) override;
CHIP_ERROR StoreHardwareVersionString(CharSpan hardwareVersionString) override;
CHIP_ERROR StoreSoftwareVersionString(CharSpan softwareVersionString) override;

CHIP_ERROR StoreVendorName(const char * vendorName, size_t vendorNameLen) override;
CHIP_ERROR StoreProductName(const char * productName, size_t productNameLen) override;
CHIP_ERROR StoreHardwareVersionString(const char * hardwareVersionString, size_t hardwareVersionStringLen) override;
CHIP_ERROR StoreSoftwareVersionString(const char * softwareVersionString, size_t softwareVersionStringLen) override;

#if CHIP_CONFIG_TEST
void RunUnitTests() override;
#endif
Expand Down
69 changes: 64 additions & 5 deletions src/include/platform/internal/GenericConfigurationManagerImpl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,74 @@ CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetSecondaryPairingHint
template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetSoftwareVersionString(char * buf, size_t bufSize)
{
ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL);
strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);
return CHIP_NO_ERROR;

CHIP_ERROR err = CHIP_NO_ERROR;
size_t softwareVersionStringLen = 0; // without counting null-terminator

err = ReadConfigValueStr(ConfigClass::kConfigKey_SoftwareVersionString, buf, bufSize, softwareVersionStringLen);

if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING, sizeof(CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this is no longer using strcpy?


return CHIP_NO_ERROR;
}

VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL);

return err;
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::StoreSerialNumber(const char * serialNum, size_t serialNumLen)
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::StoreSerialNumber(CharSpan serialNumber)
{
return WriteConfigValueStr(ConfigClass::kConfigKey_SerialNum, serialNumber.data(), serialNumber.size());
}
template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::StoreVendorName(CharSpan vendorName)
{

return WriteConfigValueStr(ConfigClass::kConfigKey_VendorName, vendorName.data(), vendorName.size());
}
template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::StoreProductName(CharSpan productName)
{
return WriteConfigValueStr(ConfigClass::kConfigKey_ProductName, productName.data(), productName.size());
}
template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::StoreHardwareVersionString(CharSpan hardwareVersionString)
{
return WriteConfigValueStr(ConfigClass::kConfigKey_HardwareVersionString, hardwareVersionString.data(),
hardwareVersionString.size());
}
template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::StoreSoftwareVersionString(CharSpan softwareVersionString)
{
return WriteConfigValueStr(ConfigClass::kConfigKey_SoftwareVersionString, softwareVersionString.data(),
softwareVersionString.size());
}
template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::StoreVendorName(const char * vendorName, size_t vendorNameLen)
{
Comment on lines +367 to +403
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not add this to the Generic configuration manager.

Overall, all the settings for this should com from overrides to DeviceInstanceInfoProvider on Linux only, and NOT by adding more ways to store data in here, which may clash with some external platforms, or require additional flash.

return WriteConfigValueStr(ConfigClass::kConfigKey_VendorName, vendorName, vendorNameLen);
}
template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::StoreProductName(const char * productName, size_t productNameLen)
{
return WriteConfigValueStr(ConfigClass::kConfigKey_ProductName, productName, productNameLen);
}
template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::StoreHardwareVersionString(const char * hardwareVersionString,
size_t hardwareVersionStringLen)
{
return WriteConfigValueStr(ConfigClass::kConfigKey_HardwareVersionString, hardwareVersionString, hardwareVersionStringLen);
}
template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::StoreSoftwareVersionString(const char * softwareVersionString,
size_t softwareVersionStringLen)
{
return WriteConfigValueStr(ConfigClass::kConfigKey_SerialNum, serialNum, serialNumLen);
return WriteConfigValueStr(ConfigClass::kConfigKey_SoftwareVersionString, softwareVersionString, softwareVersionStringLen);
}

template <class ConfigClass>
Expand Down
69 changes: 52 additions & 17 deletions src/include/platform/internal/GenericDeviceInstanceInfoProvider.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,42 @@ CHIP_ERROR GenericDeviceInstanceInfoProvider<ConfigClass>::GetProductId(uint16_t
template <class ConfigClass>
CHIP_ERROR GenericDeviceInstanceInfoProvider<ConfigClass>::GetVendorName(char * buf, size_t bufSize)
{
ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME), CHIP_ERROR_BUFFER_TOO_SMALL);
strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME);
return CHIP_NO_ERROR;
ChipError err = CHIP_NO_ERROR;
size_t vendorNameLen = 0; // without counting null-terminator

err = mGenericConfigManager.ReadConfigValueStr(ConfigClass::kConfigKey_VendorName, buf, bufSize, vendorNameLen);

if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME), CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME, sizeof(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why is this not strcpy?

Same for the similar bits below.

err = CHIP_NO_ERROR;
}

VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL);

return err;
}

template <class ConfigClass>
CHIP_ERROR GenericDeviceInstanceInfoProvider<ConfigClass>::GetProductName(char * buf, size_t bufSize)
{
ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME), CHIP_ERROR_BUFFER_TOO_SMALL);
strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME);

return CHIP_NO_ERROR;
ChipError err = CHIP_NO_ERROR;
size_t productNameLen = 0; // without counting null-terminator

err = mGenericConfigManager.ReadConfigValueStr(ConfigClass::kConfigKey_ProductName, buf, bufSize, productNameLen);

if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME), CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME, sizeof(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME));
err = CHIP_NO_ERROR;
}

VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL);

return err;
}

template <class ConfigClass>
Expand Down Expand Up @@ -96,19 +120,15 @@ CHIP_ERROR GenericDeviceInstanceInfoProvider<ConfigClass>::GetSerialNumber(char

err = mGenericConfigManager.ReadConfigValueStr(ConfigClass::kConfigKey_SerialNum, buf, bufSize, serialNumLen);

#ifdef CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER
if (CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER[0] != 0 && err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
ReturnErrorCodeIf(sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER) > bufSize, CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(buf, CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER, sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER));
serialNumLen = sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER) - 1;
err = CHIP_NO_ERROR;

err = CHIP_NO_ERROR;
}
#endif // CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER
ReturnErrorOnFailure(err);

ReturnErrorCodeIf(serialNumLen >= bufSize, CHIP_ERROR_BUFFER_TOO_SMALL);
ReturnErrorCodeIf(buf[serialNumLen] != 0, CHIP_ERROR_INVALID_STRING_LENGTH);
VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL);

return err;
}
Expand Down Expand Up @@ -176,9 +196,24 @@ CHIP_ERROR GenericDeviceInstanceInfoProvider<ConfigClass>::GetHardwareVersion(ui
template <class ConfigClass>
CHIP_ERROR GenericDeviceInstanceInfoProvider<ConfigClass>::GetHardwareVersionString(char * buf, size_t bufSize)
{
ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL);
strcpy(buf, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING);
return CHIP_NO_ERROR;

ChipError err = CHIP_NO_ERROR;
size_t hardwareVersionStringLen = 0; // without counting null-terminator

err = mGenericConfigManager.ReadConfigValueStr(ConfigClass::kConfigKey_HardwareVersionString, buf, bufSize,
hardwareVersionStringLen);

if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(buf, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strcpy?

sizeof(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING));
err = CHIP_NO_ERROR;
}

VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_ERROR_INTERNAL);

return err;
}

template <class ConfigClass>
Expand Down
5 changes: 5 additions & 0 deletions src/platform/ASR/ASRConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ const ASRConfig::Key ASRConfig::kConfigKey_WiFiSecurity = { kConfigNamespa
const ASRConfig::Key ASRConfig::kConfigKey_WiFiMode = { kConfigNamespace_ChipConfig, "wifimode" };
const ASRConfig::Key ASRConfig::kConfigKey_UniqueId = { kConfigNamespace_ChipConfig, "unique-id" };

const ASRConfig::Key ASRConfig::kConfigKey_VendorName = { kConfigNamespace_ChipConfig, "vendor-name" };
const ASRConfig::Key ASRConfig::kConfigKey_ProductName = { kConfigNamespace_ChipConfig, "product-name" };
const ASRConfig::Key ASRConfig::kConfigKey_HardwareVersionString = { kConfigNamespace_ChipConfig, "hardware-version-string" };
const ASRConfig::Key ASRConfig::kConfigKey_SoftwareVersionString = { kConfigNamespace_ChipConfig, "software-version-string" };

// Keys stored in the Chip-counters namespace
const ASRConfig::Key ASRConfig::kCounterKey_RebootCount = { kConfigNamespace_ChipCounters, "reboot-count" };
const ASRConfig::Key ASRConfig::kCounterKey_UpTime = { kConfigNamespace_ChipCounters, "up-time" };
Expand Down
5 changes: 5 additions & 0 deletions src/platform/ASR/ASRConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class ASRConfig
static const Key kCounterKey_UpTime;
static const Key kCounterKey_TotalOperationalHours;

static const Key kConfigKey_VendorName;
static const Key kConfigKey_ProductName;
static const Key kConfigKey_HardwareVersionString;
static const Key kConfigKey_SoftwareVersionString;

// Config value accessors.
static CHIP_ERROR ReadConfigValue(Key key, bool & val);
static CHIP_ERROR ReadConfigValue(Key key, uint32_t & val);
Expand Down
Loading
Loading