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

[Telink] Read certificate declaration from storage #25072

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions examples/lighting-app/telink/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ CONFIG_CHIP_LIB_SHELL=n
CONFIG_CHIP_FACTORY_DATA=n
CONFIG_CHIP_FACTORY_DATA_BUILD=n
CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE=n
CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE=n

# Enable Button IRQ mode. The poling mode is used by default.
CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE=n
Expand Down
4 changes: 4 additions & 0 deletions src/platform/telink/FactoryDataParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData
{
res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->user);
}
else if (strncmp("cert_dclrn", (const char *) currentString.value, currentString.len) == 0)
{
res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->certificate_declaration);
}
else
{
res = res && zcbor_any_skip(states, NULL);
Expand Down
1 change: 1 addition & 0 deletions src/platform/telink/FactoryDataParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct FactoryData
uint32_t passcode;
struct FactoryDataString enable_key;
struct FactoryDataString user;
struct FactoryDataString certificate_declaration;

bool vendorIdPresent;
bool productIdPresent;
Expand Down
15 changes: 7 additions & 8 deletions src/platform/telink/FactoryDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ template <class FlashFactoryData>
CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetCertificationDeclaration(MutableByteSpan & outBuffer)
{
#if CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE
size_t cdLen = 0;
ReturnErrorCodeIf(outBuffer.size() < mFactoryData.certificate_declaration.len, CHIP_ERROR_BUFFER_TOO_SMALL);
ReturnErrorCodeIf(!mFactoryData.certificate_declaration.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);

if (Internal::ZephyrConfig::ReadConfigValueBin(Internal::ZephyrConfig::kConfigKey_CertificationDeclaration,
reinterpret_cast<uint8_t *>(outBuffer.data()), outBuffer.size(),
cdLen) == CHIP_NO_ERROR)
{
outBuffer.reduce_size(cdLen);
return CHIP_NO_ERROR;
}
memcpy(outBuffer.data(), mFactoryData.certificate_declaration.data, mFactoryData.certificate_declaration.len);

outBuffer.reduce_size(mFactoryData.certificate_declaration.len);

return CHIP_NO_ERROR;
#endif
constexpr uint8_t kCdForAllExamples[] = CHIP_DEVICE_CONFIG_CERTIFICATION_DECLARATION;

Expand Down