-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: master
Are you sure you want to change the base?
Changes from 11 commits
901253c
6c62371
1af5cfd
42ded2d
9e642fa
49c388e
a98cc54
4ad0269
8d787ed
800c565
b19ffdf
94944cb
2470475
a351120
ff682fb
6536e33
2bf83ef
4268b10
2242d54
9fcc343
40d1a1a
399ddb7
7c468b9
c4c0e91
21328d8
f350454
cea2b21
e217a7f
67e1c3d
009b934
3cd2bf4
db6a9dd
9accc81
9736791
08b7479
84b9f51
bb8b3c6
16406e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,15 +351,50 @@ 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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_SerialNum, serialNum, serialNumLen); | ||
return WriteConfigValueStr(ConfigClass::kConfigKey_SoftwareVersionString, softwareVersionString.data(), | ||
softwareVersionString.size()); | ||
} | ||
|
||
template <class ConfigClass> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,18 +38,41 @@ 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
ChipError err = CHIP_NO_ERROR; | ||
size_t productNameLen = 0; // without counting null-terminator | ||
|
||
return CHIP_NO_ERROR; | ||
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> | ||
|
@@ -96,19 +119,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; | ||
} | ||
|
@@ -176,9 +195,23 @@ 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.