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

[Silabs] Fix Test Event Trigger processing #36981

Merged
merged 11 commits into from
Feb 12, 2025
7 changes: 5 additions & 2 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
}

if (chip_build_tests) {
deps += [ "//src:tests" ]
deps += [ "//examples:example_tests" ]
deps += [
"//examples:example_tests",
"//src:tests",
"//src/platform/silabs/tests:silabs_platform_tests",
]

if (current_os == "android" && current_toolchain == default_toolchain) {
deps += [ "${chip_root}/build/chip/java/tests:java_build_test" ]
Expand Down
2 changes: 2 additions & 0 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)

#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
static SilabsTestEventTriggerDelegate sTestEventTriggerDelegate;
sTestEventTriggerDelegate.Init(&provision.GetStorage());

initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;
#endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLED

Expand Down
29 changes: 1 addition & 28 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ declare_args() {

# OTA timeout in seconds
ota_periodic_query_timeout_sec = 86400

# The EnableKey in hex string format used by TestEventTrigger command in
# GeneralDiagnostics cluster. The length of the string should be 16 bytes.
sl_test_event_trigger_enable_key = "00112233445566778899AABBCCDDEEFF"
}

# Sanity check
Expand All @@ -58,29 +54,6 @@ config("chip_examples_project_config") {
]
}

config("test-event-trigger-config") {
defines = [ "SL_MATTER_TEST_EVENT_TRIGGER_ENABLED" ]

if (is_debug) {
defines += [ "SL_MATTER_TEST_EVENT_TRIGGER_ENABLE_KEY=\"${sl_test_event_trigger_enable_key}\"" ]
}
}

source_set("test-event-trigger") {
sources = [
"${silabs_common_plat_dir}/SilabsTestEventTriggerDelegate.cpp",
"${silabs_common_plat_dir}/SilabsTestEventTriggerDelegate.h",
]

deps = [ "${sl_provision_root}:headers" ]
public_configs = [ ":test-event-trigger-config" ]
public_deps = [
"${chip_root}/src/app:test-event-trigger",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
]
}

source_set("matter-shell") {
defines = [ "ENABLE_CHIP_SHELL" ]

Expand Down Expand Up @@ -200,7 +173,7 @@ source_set("siwx917-common") {
]

if (sl_enable_test_event_trigger) {
public_deps += [ ":test-event-trigger" ]
public_deps += [ "${silabs_common_plat_dir}/test-event-trigger:sources" ]
}

if (sl_enable_si70xx_sensor) {
Expand Down
38 changes: 0 additions & 38 deletions examples/platform/silabs/SilabsTestEventTriggerDelegate.cpp

This file was deleted.

29 changes: 1 addition & 28 deletions examples/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ declare_args() {

# OTA timeout in seconds
ota_periodic_query_timeout_sec = 86400

# The EnableKey in hex string format used by TestEventTrigger command in
# GeneralDiagnostics cluster. The length of the string should be 16 bytes.
sl_test_event_trigger_enable_key = "00112233445566778899AABBCCDDEEFF"
}

import("${silabs_common_plat_dir}/args.gni")
Expand Down Expand Up @@ -61,29 +57,6 @@ config("chip_examples_project_config") {
]
}

config("test-event-trigger-config") {
defines = [ "SL_MATTER_TEST_EVENT_TRIGGER_ENABLED" ]

if (is_debug) {
defines += [ "SL_MATTER_TEST_EVENT_TRIGGER_ENABLE_KEY=\"${sl_test_event_trigger_enable_key}\"" ]
}
}

source_set("test-event-trigger") {
sources = [
"${silabs_common_plat_dir}/SilabsTestEventTriggerDelegate.cpp",
"${silabs_common_plat_dir}/SilabsTestEventTriggerDelegate.h",
]

deps = [ "${sl_provision_root}:headers" ]
public_configs = [ ":test-event-trigger-config" ]
public_deps = [
"${chip_root}/src/app:test-event-trigger",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
]
}

source_set("openthread_core_config_efr32_chip_examples") {
if (chip_enable_openthread) {
sources = [ "project_include/OpenThreadConfig.h" ]
Expand Down Expand Up @@ -229,7 +202,7 @@ source_set("efr32-common") {
]

if (sl_enable_test_event_trigger) {
public_deps += [ ":test-event-trigger" ]
public_deps += [ "${silabs_common_plat_dir}/test-event-trigger:sources" ]
}

if (sl_enable_si70xx_sensor) {
Expand Down
9 changes: 1 addition & 8 deletions examples/platform/silabs/provision/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ source_set("storage") {
public_deps = [ "${sl_provision_root}:headers" ]

if (sl_enable_test_event_trigger) {
# Temporary workaround since we have duplicated configurations
if (wifi_soc) {
public_configs = [ "${chip_root}/examples/platform/silabs/SiWx917:test-event-trigger-config" ]
} else {
public_configs = [
"${chip_root}/examples/platform/silabs/efr32:test-event-trigger-config",
]
}
public_configs = [ "${chip_root}/examples/platform/silabs/test-event-trigger:test-event-trigger-config" ]
}
}
30 changes: 13 additions & 17 deletions examples/platform/silabs/provision/ProvisionStorageDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
#include <sl_matter_test_event_trigger_config.h>
#endif // defined(SL_MATTER_TEST_EVENT_TRIGGER_ENABLED) && (SL_MATTER_GN_BUILD == 0)
#endif // NDEBUG
#ifdef OTA_ENCRYPTION_ENABLE
#ifdef SL_MATTER_ENABLE_OTA_ENCRYPTION
#include <platform/silabs/multi-ota/OtaTlvEncryptionKey.h>
#endif // OTA_ENCRYPTION_ENABLE
#endif // SL_MATTER_ENABLE_OTA_ENCRYPTION
#ifndef SLI_SI91X_MCU_INTERFACE
#include <psa/crypto.h>
#endif
Expand Down Expand Up @@ -474,7 +474,7 @@ CHIP_ERROR Storage::GetCertificationDeclaration(MutableByteSpan & value)
err = ReadFileByOffset(*this, "GetDeviceAttestationCert", SL_CREDENTIALS_CD_OFFSET, SL_CREDENTIALS_CD_SIZE, value);
}
#endif
#ifdef CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#ifdef SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
if (CHIP_ERROR_NOT_FOUND == err)
{
// Example CD
Expand Down Expand Up @@ -502,7 +502,7 @@ CHIP_ERROR Storage::GetProductAttestationIntermediateCert(MutableByteSpan & valu
err = ReadFileByOffset(*this, "GetDeviceAttestationCert", SL_CREDENTIALS_PAI_OFFSET, SL_CREDENTIALS_PAI_SIZE, value);
}
#endif
#ifdef CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#ifdef SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
if (CHIP_ERROR_NOT_FOUND == err)
{
// Example PAI
Expand Down Expand Up @@ -530,7 +530,7 @@ CHIP_ERROR Storage::GetDeviceAttestationCert(MutableByteSpan & value)
err = ReadFileByOffset(*this, "GetDeviceAttestationCert", SL_CREDENTIALS_DAC_OFFSET, SL_CREDENTIALS_DAC_SIZE, value);
}
#endif
#ifdef CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#ifdef SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
if (CHIP_ERROR_NOT_FOUND == err)
{
// Example DAC
Expand Down Expand Up @@ -569,7 +569,7 @@ CHIP_ERROR Storage::SignWithDeviceAttestationKey(const ByteSpan & message, Mutab
}
else
{
#ifdef CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#ifdef SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
// Example DAC key
return Examples::GetExampleDACProvider()->SignWithDeviceAttestationKey(message, signature);
#else
Expand Down Expand Up @@ -605,7 +605,7 @@ CHIP_ERROR Storage::SignWithDeviceAttestationKey(const ByteSpan & message, Mutab
AttestationKey key(kid);
err = key.SignMessage(message, signature);
}
#ifdef CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#ifdef SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
else
{
// Example DAC key
Expand Down Expand Up @@ -663,21 +663,16 @@ CHIP_ERROR Storage::GetProvisionRequest(bool & value)
return SilabsConfig::ReadConfigValue(SilabsConfig::kConfigKey_Provision_Request, value);
}

#if OTA_ENCRYPTION_ENABLE
#ifdef SL_MATTER_ENABLE_OTA_ENCRYPTION
CHIP_ERROR Storage::SetOtaTlvEncryptionKey(const ByteSpan & value)
{
chip::DeviceLayer::Silabs::OtaTlvEncryptionKey::OtaTlvEncryptionKey key;
ReturnErrorOnFailure(key.Import(value.data(), value.size()));
return SilabsConfig::WriteConfigValue(SilabsConfig::kOtaTlvEncryption_KeyId, key.GetId());
}
#endif // OTA_ENCRYPTION_ENABLE
#endif // SL_MATTER_ENABLE_OTA_ENCRYPTION

/**
* @brief Reads the test event trigger key from NVM. If the key isn't present, returns default value if defined.
*
* @param[out] keySpan output buffer. Must be at least large enough for 16 bytes (ken length)
* @return CHIP_ERROR
*/
#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
CHIP_ERROR Storage::GetTestEventTriggerKey(MutableByteSpan & keySpan)
{
constexpr size_t kEnableKeyLength = 16; // Expected byte size of the EnableKey
Expand All @@ -689,7 +684,7 @@ CHIP_ERROR Storage::GetTestEventTriggerKey(MutableByteSpan & keySpan)
err = SilabsConfig::ReadConfigValueBin(SilabsConfig::kConfigKey_Test_Event_Trigger_Key, keySpan.data(), kEnableKeyLength,
keyLength);
#ifndef NDEBUG
#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLE_KEY
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{

Expand All @@ -702,12 +697,13 @@ CHIP_ERROR Storage::GetTestEventTriggerKey(MutableByteSpan & keySpan)
}
err = CHIP_NO_ERROR;
}
#endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
#endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLE_KEY
#endif // NDEBUG

keySpan.reduce_size(kEnableKeyLength);
return err;
}
#endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLED

} // namespace Provision

Expand Down
26 changes: 14 additions & 12 deletions examples/platform/silabs/provision/ProvisionStorageFlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include <platform/CHIPDeviceConfig.h>
#include <platform/silabs/SilabsConfig.h>
#include <string.h>
#ifdef OTA_ENCRYPTION_ENABLE
#ifdef SL_MATTER_ENABLE_OTA_ENCRYPTION
#include <platform/silabs/multi-ota/OtaTlvEncryptionKey.h>
#endif // OTA_ENCRYPTION_ENABLE
#endif // SL_MATTER_ENABLE_OTA_ENCRYPTION

using namespace chip::Credentials;

Expand Down Expand Up @@ -578,13 +578,13 @@ CHIP_ERROR Storage::GetCertificationDeclaration(MutableByteSpan & value)
{
size_t size = 0;
CHIP_ERROR err = (Flash::Get(Parameters::ID::kCertification, value.data(), value.size(), size));
#ifdef CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#ifdef SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
if (CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND == err)
{
// Example CD
return Examples::GetExampleDACProvider()->GetCertificationDeclaration(value);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#endif // SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
ReturnErrorOnFailure(err);
value.reduce_size(size);
return CHIP_NO_ERROR;
Expand All @@ -599,13 +599,13 @@ CHIP_ERROR Storage::GetProductAttestationIntermediateCert(MutableByteSpan & valu
{
size_t size = 0;
CHIP_ERROR err = (Flash::Get(Parameters::ID::kPaiCert, value.data(), value.size(), size));
#ifdef CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#ifdef SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
if (CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND == err)
{
// Example PAI
return Examples::GetExampleDACProvider()->GetProductAttestationIntermediateCert(value);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#endif // SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
ReturnErrorOnFailure(err);
value.reduce_size(size);
return CHIP_NO_ERROR;
Expand All @@ -620,13 +620,13 @@ CHIP_ERROR Storage::GetDeviceAttestationCert(MutableByteSpan & value)
{
size_t size = 0;
CHIP_ERROR err = (Flash::Get(Parameters::ID::kDacCert, value.data(), value.size(), size));
#ifdef CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#ifdef SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
if (CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND == err)
{
// Example DAC
return Examples::GetExampleDACProvider()->GetDeviceAttestationCert(value);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#endif // SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
ReturnErrorOnFailure(err);
value.reduce_size(size);
return CHIP_NO_ERROR;
Expand All @@ -652,13 +652,13 @@ CHIP_ERROR Storage::SignWithDeviceAttestationKey(const ByteSpan & message, Mutab
uint8_t temp[kDeviceAttestationKeySizeMax] = { 0 };
size_t size = 0;
CHIP_ERROR err = Flash::Get(Parameters::ID::kDacKey, temp, sizeof(temp), size);
#ifdef CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#ifdef SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
if (CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND == err)
{
// Example DAC key
return Examples::GetExampleDACProvider()->SignWithDeviceAttestationKey(message, signature);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_EXAMPLE_CREDENTIALS
#endif // SL_MATTER_ENABLE_EXAMPLE_CREDENTIALS
ReturnErrorOnFailure(err);
#if (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE)
uint8_t key_buffer[kDeviceAttestationKeySizeMax] = { 0 };
Expand Down Expand Up @@ -719,17 +719,19 @@ CHIP_ERROR Storage::GetProvisionRequest(bool & value)
// return Flash::Set(Parameters::ID::kProvisionRequest, value);
return CHIP_ERROR_NOT_IMPLEMENTED;
}
#if OTA_ENCRYPTION_ENABLE
#ifdef SL_MATTER_ENABLE_OTA_ENCRYPTION
CHIP_ERROR Storage::SetOtaTlvEncryptionKey(const ByteSpan & value)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
#endif // OTA_ENCRYPTION_ENABLE
#endif // SL_MATTER_ENABLE_OTA_ENCRYPTION

#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
CHIP_ERROR Storage::GetTestEventTriggerKey(MutableByteSpan & keySpan)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
#endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLED

} // namespace Provision

Expand Down
Loading
Loading