Skip to content

Commit 4f3f5bb

Browse files
refactor test event trigger for efr32 hardware
1 parent 696ae98 commit 4f3f5bb

File tree

10 files changed

+137
-65
lines changed

10 files changed

+137
-65
lines changed

examples/lit-icd-app/silabs/openthread.gni

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ chip_enable_openthread = true
2626
openthread_external_platform =
2727
"${chip_root}/third_party/openthread/platforms/efr32:libopenthread-efr32"
2828

29+
sl_enable_test_event_trigger = true
30+
2931
# ICD Default configurations
3032
chip_enable_icd_server = true
3133
chip_subscription_timeout_resumption = false

examples/platform/silabs/MatterConfig.cpp

+2-16
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,9 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
280280

281281
initParams.reportScheduler = &sReportScheduler;
282282

283-
#if SILABS_TEST_EVENT_TRIGGER_ENABLED
284-
if (Encoding::HexToBytes(SILABS_TEST_EVENT_TRIGGER_ENABLE_KEY, strlen(SILABS_TEST_EVENT_TRIGGER_ENABLE_KEY),
285-
sTestEventTriggerEnableKey,
286-
TestEventTriggerDelegate::kEnableKeyLength) != TestEventTriggerDelegate::kEnableKeyLength)
287-
{
288-
SILABS_LOG("Failed to convert the EnableKey string to octstr type value");
289-
memset(sTestEventTriggerEnableKey, 0, sizeof(sTestEventTriggerEnableKey));
290-
}
283+
#if SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
291284
// TODO(#31723): Show to customers that they can do `Server::GetInstance().GetTestEventTriggerDelegate().AddHandler()`
292-
static SilabsTestEventTriggerDelegate sTestEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) };
285+
static SilabsTestEventTriggerDelegate sTestEventTriggerDelegate;
293286
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;
294287
#endif // SILABS_TEST_EVENT_TRIGGER_ENABLED
295288

@@ -300,13 +293,6 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
300293
initParams.operationalKeystore = &gOperationalKeystore;
301294
#endif
302295

303-
#ifdef PERFORMANCE_TEST_ENABLED
304-
// Set up Test Event Trigger command of the General Diagnostics cluster. Used only in performance testing
305-
// TODO(#31723): Show to customers that they can do `Server::GetInstance().GetTestEventTriggerDelegate().AddHandler()`
306-
static SilabsTestEventTriggerDelegate sTestEventTriggerDelegate{ ByteSpan(kTestEventTriggerEnableKey) };
307-
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;
308-
#endif
309-
310296
// Initialize the remaining (not overridden) providers to the SDK example defaults
311297
(void) initParams.InitializeStaticResourcesBeforeServerInit();
312298

examples/platform/silabs/SilabsDeviceDataProvider.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,43 @@ CHIP_ERROR SilabsDeviceDataProvider::GetProductLabel(char * buf, size_t bufSize)
510510
return SilabsConfig::ReadConfigValueStr(SilabsConfig::KConfigKey_ProductLabel, buf, bufSize, productLabelLen);
511511
}
512512

513+
#ifdef SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
514+
/**
515+
* @brief Reads the test event trigger key from NVM. If the key isn't present, returns default value if defined.
516+
*
517+
* @param[out] keySpan output buffer. Must be at least large enough for 16 bytes (ken length)
518+
* @return CHIP_ERROR
519+
*/
520+
CHIP_ERROR SilabsDeviceDataProvider::GetTestEventTriggerKey(MutableByteSpan & keySpan)
521+
{
522+
constexpr size_t kEnableKeyLength = 16; // Expected byte size of the EnableKey
523+
CHIP_ERROR err = CHIP_NO_ERROR;
524+
size_t keyLength = 0;
525+
526+
VerifyOrReturnError(keySpan.size() >= kEnableKeyLength, CHIP_ERROR_BUFFER_TOO_SMALL);
527+
528+
err = SilabsConfig::ReadConfigValueBin(SilabsConfig::kConfigKey_Test_Event_Trigger_Key, keySpan.data(), kEnableKeyLength,
529+
keyLength);
530+
#ifndef NDEBUG
531+
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
532+
{
533+
534+
constexpr char enableKey[] = SL_MATTER_TEST_EVENT_TRIGGER_ENABLE_KEY;
535+
if (Encoding::HexToBytes(enableKey, strlen(enableKey), keySpan.data(), kEnableKeyLength) != kEnableKeyLength)
536+
{
537+
// enableKey Hex String doesn't have the correct length
538+
memset(keySpan.data(), 0, keySpan.size());
539+
return CHIP_ERROR_INTERNAL;
540+
}
541+
err = CHIP_NO_ERROR;
542+
}
543+
#endif // NDEBUG
544+
545+
keySpan.reduce_size(kEnableKeyLength);
546+
return err;
547+
}
548+
#endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLED
549+
513550
SilabsDeviceDataProvider & SilabsDeviceDataProvider::GetDeviceDataProvider()
514551
{
515552
static SilabsDeviceDataProvider sDataProvider;

examples/platform/silabs/SilabsDeviceDataProvider.h

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class SilabsDeviceDataProvider : public CommissionableDataProvider,
6868
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
6969
CHIP_ERROR GetProductURL(char * buf, size_t bufSzie) override;
7070
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
71+
72+
// ===== Member functions that are Silabs Specific
73+
CHIP_ERROR GetTestEventTriggerKey(MutableByteSpan & keySpan);
7174
};
7275

7376
} // namespace Silabs

examples/platform/silabs/SilabsTestEventTriggerDelegate.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,22 @@
1717
*/
1818

1919
#include "SilabsTestEventTriggerDelegate.h"
20+
#include "SilabsDeviceDataProvider.h"
2021

2122
using namespace ::chip::DeviceLayer;
2223

2324
namespace chip {
2425

2526
bool SilabsTestEventTriggerDelegate::DoesEnableKeyMatch(const ByteSpan & enableKey) const
2627
{
27-
return !mEnableKey.empty() && mEnableKey.data_equal(enableKey);
28+
uint8_t mEnableKey[TestEventTriggerDelegate::kEnableKeyLength];
29+
MutableByteSpan enableKeySpan(mEnableKey);
30+
31+
// Return false if we were not able to get the enableKey
32+
VerifyOrReturnValue(
33+
Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().GetTestEventTriggerKey(enableKeySpan) == CHIP_NO_ERROR, false);
34+
35+
return (!enableKeySpan.empty() && enableKeySpan.data_equal(enableKey));
2836
}
2937

3038
} // namespace chip

examples/platform/silabs/SilabsTestEventTriggerDelegate.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ namespace chip {
4646
class SilabsTestEventTriggerDelegate : public TestEventTriggerDelegate, TestEventTriggerHandler
4747
{
4848
public:
49-
explicit SilabsTestEventTriggerDelegate(const ByteSpan & enableKey) : mEnableKey(enableKey)
50-
{
51-
VerifyOrDie(AddHandler(this) == CHIP_NO_ERROR);
52-
}
49+
explicit SilabsTestEventTriggerDelegate() { VerifyOrDie(AddHandler(this) == CHIP_NO_ERROR); }
5350

5451
/**
5552
* @brief Checks to see if `enableKey` provided matches value chosen by the manufacturer.
@@ -69,9 +66,6 @@ class SilabsTestEventTriggerDelegate : public TestEventTriggerDelegate, TestEven
6966
// WARNING: LEGACY SUPPORT ONLY, DO NOT EXTEND FOR STANDARD CLUSTERS
7067
return (emberAfHandleEventTrigger(eventTrigger)) ? CHIP_NO_ERROR : CHIP_ERROR_INVALID_ARGUMENT;
7168
}
72-
73-
private:
74-
ByteSpan mEnableKey;
7569
};
7670

7771
} // namespace chip

examples/platform/silabs/efr32/BUILD.gn

+34-12
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ declare_args() {
4141
chip_default_wifi_psk = ""
4242

4343
# Enable TestEventTrigger in GeneralDiagnostics cluster
44-
silabs_test_event_trigger_enabled = false
44+
sl_enable_test_event_trigger = false
4545

4646
# The EnableKey in hex string format used by TestEventTrigger command in
47-
# GeneralDiagnostics cluster. The length of the string should be 32.
48-
silabs_test_event_trigger_enable_key = "00112233445566778899aabbccddeeff"
47+
# GeneralDiagnostics cluster. The length of the string should be 16 bytes.
48+
sl_test_event_trigger_enable_key = "00112233445566778899AABBCCDDEEFF"
4949
}
5050

5151
silabs_common_plat_dir = "${chip_root}/examples/platform/silabs"
@@ -94,6 +94,29 @@ config("chip_examples_project_config") {
9494
]
9595
}
9696

97+
config("test-event-trigger-config") {
98+
defines = [ "SL_MATTER_TEST_EVENT_TRIGGER_ENABLED" ]
99+
100+
if (sl_test_event_trigger_enable_key != "") {
101+
defines += [ "SL_MATTER_TEST_EVENT_TRIGGER_ENABLE_KEY=\"${sl_test_event_trigger_enable_key}\"" ]
102+
}
103+
}
104+
105+
source_set("test-event-trigger") {
106+
sources = [
107+
"${silabs_common_plat_dir}/SilabsTestEventTriggerDelegate.cpp",
108+
"${silabs_common_plat_dir}/SilabsTestEventTriggerDelegate.h",
109+
]
110+
111+
public_configs = [ ":test-event-trigger-config" ]
112+
113+
public_deps = [
114+
":silabs-factory-data-provider",
115+
"${chip_root}/src/lib/core",
116+
"${chip_root}/src/lib/support",
117+
]
118+
}
119+
97120
source_set("openthread_core_config_efr32_chip_examples") {
98121
if (chip_enable_openthread) {
99122
sources = [ "project_include/OpenThreadConfig.h" ]
@@ -157,6 +180,10 @@ source_set("silabs-factory-data-provider") {
157180
"${chip_root}/src/platform:platform_base",
158181
"${chip_root}/src/setup_payload",
159182
]
183+
184+
if (sl_enable_test_event_trigger) {
185+
public_configs = [ ":test-event-trigger-config" ]
186+
}
160187
}
161188

162189
config("efr32-common-config") {
@@ -322,22 +349,17 @@ source_set("efr32-common") {
322349
public_deps += [ ":silabs-factory-data-provider" ]
323350
}
324351

325-
if (silabs_test_event_trigger_enabled) {
326-
sources +=
327-
[ "${silabs_common_plat_dir}/SilabsTestEventTriggerDelegate.cpp" ]
328-
defines += [
329-
"SILABS_TEST_EVENT_TRIGGER_ENABLED=true",
330-
"SILABS_TEST_EVENT_TRIGGER_ENABLE_KEY=\"${silabs_test_event_trigger_enable_key}\"",
331-
]
332-
}
333-
334352
public_deps += [
335353
"${chip_root}/examples/providers:device_info_provider",
336354
"${chip_root}/src/app/server",
337355
"${chip_root}/src/lib",
338356
"${chip_root}/src/setup_payload",
339357
]
340358

359+
if (sl_enable_test_event_trigger) {
360+
public_deps += [ ":test-event-trigger" ]
361+
}
362+
341363
if (app_data_model != "") {
342364
public_deps += [ app_data_model ]
343365
}

examples/smoke-co-alarm-app/silabs/openthread.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ check_system_includes = true
2323
default_args = {
2424
target_cpu = "arm"
2525
target_os = "freertos"
26-
chip_openthread_ftd = true
26+
chip_openthread_ftd = false
2727

2828
import("//openthread.gni")
2929
}

examples/smoke-co-alarm-app/silabs/openthread.gni

+19
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,22 @@ chip_enable_openthread = true
2525

2626
openthread_external_platform =
2727
"${chip_root}/third_party/openthread/platforms/efr32:libopenthread-efr32"
28+
29+
sl_enable_test_event_trigger = true
30+
31+
# ICD Default configurations
32+
chip_enable_icd_server = true
33+
chip_subscription_timeout_resumption = false
34+
sl_use_subscription_synching = true
35+
icd_enforce_sit_slow_poll_limit = true
36+
chip_icd_report_on_active_mode = true
37+
chip_enable_icd_lit = true
38+
39+
# Openthread Configuration flags
40+
sl_ot_idle_interval_ms = 3600000 # 60mins Idle Polling Interval
41+
sl_ot_active_interval_ms = 1000 # 1000ms Active Polling Interval
42+
43+
# ICD Matter Configuration flags
44+
sl_idle_mode_duration_s = 3600 # 60min Idle Mode Duration
45+
sl_active_mode_duration_ms = 0 # 0 Active Mode Duration
46+
sl_active_mode_threshold_ms = 5000 # 5s Active Mode Threshold

src/platform/silabs/SilabsConfig.h

+29-28
Original file line numberDiff line numberDiff line change
@@ -93,34 +93,35 @@ class SilabsConfig
9393

9494
// Key definitions for well-known configuration values.
9595
// Factory config keys
96-
static constexpr Key kConfigKey_SerialNum = SilabsConfigKey(kMatterFactory_KeyBase, 0x00);
97-
static constexpr Key kConfigKey_MfrDeviceId = SilabsConfigKey(kMatterFactory_KeyBase, 0x01);
98-
static constexpr Key kConfigKey_MfrDeviceCert = SilabsConfigKey(kMatterFactory_KeyBase, 0x02);
99-
static constexpr Key kConfigKey_MfrDevicePrivateKey = SilabsConfigKey(kMatterFactory_KeyBase, 0x03);
100-
static constexpr Key kConfigKey_ManufacturingDate = SilabsConfigKey(kMatterFactory_KeyBase, 0x04);
101-
static constexpr Key kConfigKey_SetupPayloadBitSet = SilabsConfigKey(kMatterFactory_KeyBase, 0x05);
102-
static constexpr Key kConfigKey_MfrDeviceICACerts = SilabsConfigKey(kMatterFactory_KeyBase, 0x06);
103-
static constexpr Key kConfigKey_SetupDiscriminator = SilabsConfigKey(kMatterFactory_KeyBase, 0x07);
104-
static constexpr Key kConfigKey_Spake2pIterationCount = SilabsConfigKey(kMatterFactory_KeyBase, 0x08);
105-
static constexpr Key kConfigKey_Spake2pSalt = SilabsConfigKey(kMatterFactory_KeyBase, 0x09);
106-
static constexpr Key kConfigKey_Spake2pVerifier = SilabsConfigKey(kMatterFactory_KeyBase, 0x0A);
107-
static constexpr Key kConfigKey_ProductId = SilabsConfigKey(kMatterFactory_KeyBase, 0x0B);
108-
static constexpr Key kConfigKey_VendorId = SilabsConfigKey(kMatterFactory_KeyBase, 0x0C);
109-
static constexpr Key kConfigKey_VendorName = SilabsConfigKey(kMatterFactory_KeyBase, 0x0D);
110-
static constexpr Key kConfigKey_ProductName = SilabsConfigKey(kMatterFactory_KeyBase, 0x0E);
111-
static constexpr Key kConfigKey_HardwareVersionString = SilabsConfigKey(kMatterFactory_KeyBase, 0x0F);
112-
static constexpr Key KConfigKey_ProductLabel = SilabsConfigKey(kMatterFactory_KeyBase, 0x10);
113-
static constexpr Key kConfigKey_ProductURL = SilabsConfigKey(kMatterFactory_KeyBase, 0x11);
114-
static constexpr Key kConfigKey_PartNumber = SilabsConfigKey(kMatterFactory_KeyBase, 0x12);
115-
static constexpr Key kConfigKey_UniqueId = SilabsConfigKey(kMatterFactory_KeyBase, 0x1F);
116-
static constexpr Key kConfigKey_Creds_KeyId = SilabsConfigKey(kMatterFactory_KeyBase, 0x20);
117-
static constexpr Key kConfigKey_Creds_Base_Addr = SilabsConfigKey(kMatterFactory_KeyBase, 0x21);
118-
static constexpr Key kConfigKey_Creds_DAC_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x22);
119-
static constexpr Key kConfigKey_Creds_DAC_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x23);
120-
static constexpr Key kConfigKey_Creds_PAI_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x24);
121-
static constexpr Key kConfigKey_Creds_PAI_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x25);
122-
static constexpr Key kConfigKey_Creds_CD_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x26);
123-
static constexpr Key kConfigKey_Creds_CD_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x27);
96+
static constexpr Key kConfigKey_SerialNum = SilabsConfigKey(kMatterFactory_KeyBase, 0x00);
97+
static constexpr Key kConfigKey_MfrDeviceId = SilabsConfigKey(kMatterFactory_KeyBase, 0x01);
98+
static constexpr Key kConfigKey_MfrDeviceCert = SilabsConfigKey(kMatterFactory_KeyBase, 0x02);
99+
static constexpr Key kConfigKey_MfrDevicePrivateKey = SilabsConfigKey(kMatterFactory_KeyBase, 0x03);
100+
static constexpr Key kConfigKey_ManufacturingDate = SilabsConfigKey(kMatterFactory_KeyBase, 0x04);
101+
static constexpr Key kConfigKey_SetupPayloadBitSet = SilabsConfigKey(kMatterFactory_KeyBase, 0x05);
102+
static constexpr Key kConfigKey_MfrDeviceICACerts = SilabsConfigKey(kMatterFactory_KeyBase, 0x06);
103+
static constexpr Key kConfigKey_SetupDiscriminator = SilabsConfigKey(kMatterFactory_KeyBase, 0x07);
104+
static constexpr Key kConfigKey_Spake2pIterationCount = SilabsConfigKey(kMatterFactory_KeyBase, 0x08);
105+
static constexpr Key kConfigKey_Spake2pSalt = SilabsConfigKey(kMatterFactory_KeyBase, 0x09);
106+
static constexpr Key kConfigKey_Spake2pVerifier = SilabsConfigKey(kMatterFactory_KeyBase, 0x0A);
107+
static constexpr Key kConfigKey_ProductId = SilabsConfigKey(kMatterFactory_KeyBase, 0x0B);
108+
static constexpr Key kConfigKey_VendorId = SilabsConfigKey(kMatterFactory_KeyBase, 0x0C);
109+
static constexpr Key kConfigKey_VendorName = SilabsConfigKey(kMatterFactory_KeyBase, 0x0D);
110+
static constexpr Key kConfigKey_ProductName = SilabsConfigKey(kMatterFactory_KeyBase, 0x0E);
111+
static constexpr Key kConfigKey_HardwareVersionString = SilabsConfigKey(kMatterFactory_KeyBase, 0x0F);
112+
static constexpr Key KConfigKey_ProductLabel = SilabsConfigKey(kMatterFactory_KeyBase, 0x10);
113+
static constexpr Key kConfigKey_ProductURL = SilabsConfigKey(kMatterFactory_KeyBase, 0x11);
114+
static constexpr Key kConfigKey_PartNumber = SilabsConfigKey(kMatterFactory_KeyBase, 0x12);
115+
static constexpr Key kConfigKey_UniqueId = SilabsConfigKey(kMatterFactory_KeyBase, 0x1F);
116+
static constexpr Key kConfigKey_Creds_KeyId = SilabsConfigKey(kMatterFactory_KeyBase, 0x20);
117+
static constexpr Key kConfigKey_Creds_Base_Addr = SilabsConfigKey(kMatterFactory_KeyBase, 0x21);
118+
static constexpr Key kConfigKey_Creds_DAC_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x22);
119+
static constexpr Key kConfigKey_Creds_DAC_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x23);
120+
static constexpr Key kConfigKey_Creds_PAI_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x24);
121+
static constexpr Key kConfigKey_Creds_PAI_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x25);
122+
static constexpr Key kConfigKey_Creds_CD_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x26);
123+
static constexpr Key kConfigKey_Creds_CD_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x27);
124+
static constexpr Key kConfigKey_Test_Event_Trigger_Key = SilabsConfigKey(kMatterFactory_KeyBase, 0x28);
124125
// Matter Config Keys
125126
static constexpr Key kConfigKey_ServiceConfig = SilabsConfigKey(kMatterConfig_KeyBase, 0x01);
126127
static constexpr Key kConfigKey_PairedAccountId = SilabsConfigKey(kMatterConfig_KeyBase, 0x02);

0 commit comments

Comments
 (0)