Skip to content

Commit

Permalink
[Telink] Read certificate declaration from storage (#25072)
Browse files Browse the repository at this point in the history
When CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE is enabled read
certificate declaration (CD) from storage instead of using default.

Signed-off-by: Maciej Bojczuk <maciej.bojczuk@telink-semi.com>
  • Loading branch information
Maciej Bojczuk authored and pull[bot] committed Feb 21, 2024
1 parent 4be1147 commit 831a4f3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
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

0 comments on commit 831a4f3

Please sign in to comment.