Skip to content

Commit f3b8c91

Browse files
committed
Set ICD Active/Idle Mode duration to linux cmdline
1 parent 8e0efad commit f3b8c91

8 files changed

+106
-21
lines changed

examples/chef/chef.py

-11
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,6 @@ def main() -> int:
326326
action="store_true", dest="do_interact")
327327
parser.add_option("-I", "--enable_icd", help="enable ICD (Intermittently Connected Device)",
328328
action="store_true", default=False)
329-
parser.add_option("", "--icd_idle_duration_sec", type=int,
330-
help="ICD idle mode duration (seconds). Default is 60", metavar="ICD_IDLE_SEC", default=60)
331-
parser.add_option("", "--icd_active_duration_ms", type=int,
332-
help="ICD active mode duration (milliseconds). Default is 10000", metavar="ICD_ACTIVE_DURATION_MS", default=10000)
333-
parser.add_option("", "--icd_active_threshold_ms", type=int,
334-
help="ICD idle mode threshold (milliseconds). Default is 5000", metavar="ICD_ACTIVE_THRESHOLD_MS", default=5000)
335329
parser.add_option("-m", "--menuconfig", help="runs menuconfig on platforms that support it",
336330
action="store_true", dest="do_menuconfig")
337331
parser.add_option("-z", "--zap", help="runs zap to generate data model & interaction model artifacts",
@@ -878,18 +872,13 @@ def main() -> int:
878872
linux_args.append("chip_inet_config_enable_ipv4=true")
879873
else:
880874
linux_args.append("chip_inet_config_enable_ipv4=false")
881-
882-
flush_print("{options.icd_idle_duration_sec}")
883875

884876
if options.enable_icd:
885877
linux_args.append("chip_enable_icd_server = true")
886878
linux_args.append("chip_subscription_timeout_resumption = true")
887879
linux_args.append("chip_icd_report_on_active_mode = true")
888880
linux_args.append("chip_enable_icd_lit = true")
889881
linux_args.append("chip_enable_icd_dsls = true")
890-
linux_args.append(f'chip_config_icd_idle_mode_duration_sec = {options.icd_idle_duration_sec}')
891-
linux_args.append(f'chip_config_icd_active_mode_duration_ms = {options.icd_active_duration_ms}')
892-
linux_args.append(f'chip_config_icd_active_mode_threshold_ms = {options.icd_active_threshold_ms}')
893882

894883
if sw_ver_string:
895884
linux_args.append(

examples/chef/devices/rootnode_contactsensor_ed3b19ec55.matter examples/chef/devices/icd_rootnode_contactsensor_ed3b19ec55.matter

+29-6
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ enum TestGlobalEnum : enum8 {
213213
}
214214

215215
enum ThreeLevelAutoEnum : enum8 {
216-
kLow = 0;
217-
kMedium = 1;
218-
kHigh = 2;
219-
kAutomatic = 3;
216+
kAuto = 0;
217+
kLow = 1;
218+
kMedium = 2;
219+
kHigh = 3;
220220
}
221221

222222
bitmap TestGlobalBitmap : bitmap32 {
@@ -1443,12 +1443,14 @@ cluster OperationalCredentials = 62 {
14431443
fabric_id fabricID = 3;
14441444
node_id nodeID = 4;
14451445
char_string<32> label = 5;
1446+
optional octet_string<85> vidVerificationStatement = 6;
14461447
fabric_idx fabricIndex = 254;
14471448
}
14481449

14491450
fabric_scoped struct NOCStruct {
1450-
fabric_sensitive octet_string noc = 1;
1451-
nullable fabric_sensitive octet_string icac = 2;
1451+
octet_string noc = 1;
1452+
nullable octet_string icac = 2;
1453+
optional octet_string vvsc = 3;
14521454
fabric_idx fabricIndex = 254;
14531455
}
14541456

@@ -1523,6 +1525,23 @@ cluster OperationalCredentials = 62 {
15231525
octet_string rootCACertificate = 0;
15241526
}
15251527

1528+
request struct SetVidVerificationStatementRequest {
1529+
optional vendor_id vendorID = 0;
1530+
optional octet_string vidVerificationStatement = 1;
1531+
optional octet_string vvsc = 2;
1532+
}
1533+
1534+
request struct SignVidVerificationRequestRequest {
1535+
fabric_idx fabricIndex = 0;
1536+
octet_string<32> clientChallenge = 1;
1537+
}
1538+
1539+
response struct SignVidVerificationResponse = 14 {
1540+
fabric_idx fabricIndex = 0;
1541+
int8u fabricBindingVersion = 1;
1542+
octet_string signature = 2;
1543+
}
1544+
15261545
/** Sender is requesting attestation information from the receiver. */
15271546
command access(invoke: administer) AttestationRequest(AttestationRequestRequest): AttestationResponse = 0;
15281547
/** Sender is requesting a device attestation certificate from the receiver. */
@@ -1539,6 +1558,10 @@ cluster OperationalCredentials = 62 {
15391558
command access(invoke: administer) RemoveFabric(RemoveFabricRequest): NOCResponse = 10;
15401559
/** This command SHALL add a Trusted Root CA Certificate, provided as its CHIP Certificate representation. */
15411560
command access(invoke: administer) AddTrustedRootCertificate(AddTrustedRootCertificateRequest): DefaultSuccess = 11;
1561+
/** This command SHALL be used to update any of the accessing fabric's associated VendorID, VidVerificatioNStatement or VVSC (Vendor Verification Signing Certificate). */
1562+
fabric command access(invoke: administer) SetVidVerificationStatement(SetVidVerificationStatementRequest): DefaultSuccess = 12;
1563+
/** This command SHALL be used to request that the server authenticate the fabric associated with the FabricIndex given. */
1564+
command access(invoke: administer) SignVidVerificationRequest(SignVidVerificationRequestRequest): SignVidVerificationResponse = 13;
15421565
}
15431566

15441567
/** The Group Key Management Cluster is the mechanism by which group keys are managed. */

examples/chef/linux/include/CHIPProjectAppConfig.h

-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@
3535

3636
// Enable subscriptions synchronization
3737
#define CHIP_CONFIG_SYNCHRONOUS_REPORTS_ENABLED 1
38-

examples/chef/linux/main.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ using namespace chip::app;
3030
using namespace chip::app::Clusters;
3131

3232
#if CHIP_CONFIG_ENABLE_ICD_CIP
33+
// Wake up periodically to send Check-in message since Linux application doesn't have physical button
3334
void notifyIcdActive(System::Layer * layer, void *)
3435
{
3536
ICDNotifier::GetInstance().NotifyNetworkActivityNotification();
36-
DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC*1000), notifyIcdActive, nullptr);
37+
38+
ChipLogDetail(Shell, "Periodic wakeup to notify ICD active");
39+
DeviceLayer::SystemLayer().StartTimer(
40+
chip::System::Clock::Milliseconds32(LinuxDeviceOptions::GetInstance().icdPeriodicWakeupDurationMs), notifyIcdActive,
41+
nullptr);
3742
}
3843
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
3944

@@ -58,7 +63,8 @@ int main(int argc, char * argv[])
5863
#endif
5964

6065
#if CHIP_CONFIG_ENABLE_ICD_CIP
61-
DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC*1000), notifyIcdActive, nullptr);
66+
// Send notification right away after init
67+
DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(0), notifyIcdActive, nullptr);
6268
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
6369

6470
ChipLinuxAppMainLoop();

examples/platform/linux/AppMain.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ void InitNetworkCommissioning()
267267
#endif // CHIP_APP_MAIN_HAS_ETHERNET_DRIVER
268268
}
269269
}
270+
270271
} // anonymous namespace
271272

272273
#if defined(ENABLE_CHIP_SHELL)
@@ -526,6 +527,11 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions,
526527
}
527528
#endif // CHIP_ENABLE_OPENTHREAD
528529

530+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
531+
Server::GetInstance().GetICDManager().SetModeDurations(LinuxDeviceOptions::GetInstance().icdActiveModeDurationMs,
532+
LinuxDeviceOptions::GetInstance().icdIdleModeDurationMs);
533+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
534+
529535
exit:
530536
if (err != CHIP_NO_ERROR)
531537
{

examples/platform/linux/Options.cpp

+57-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <crypto/CHIPCryptoPAL.h>
2929
#include <json/json.h>
3030
#include <lib/core/CHIPError.h>
31+
#include <lib/core/CHIPConfig.h>
3132
#include <lib/support/Base64.h>
3233
#include <lib/support/BytesToHex.h>
3334
#include <lib/support/CHIPMemString.h>
@@ -132,6 +133,11 @@ enum
132133
kDeviceOption_TermsAndConditions_Version,
133134
kDeviceOption_TermsAndConditions_Required,
134135
#endif
136+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
137+
kDeviceOption_icdActiveModeDurationMs,
138+
kDeviceOption_icdIdleModeDuration,
139+
kDeviceOption_icdPeriodicWakeupDurationMs,
140+
#endif // CHIP_ENABLE_ICD_SERVER
135141
};
136142

137143
constexpr unsigned kAppUsageLength = 64;
@@ -212,6 +218,11 @@ OptionDef sDeviceOptionDefs[] = {
212218
{ "tc-version", kArgumentRequired, kDeviceOption_TermsAndConditions_Version },
213219
{ "tc-required", kArgumentRequired, kDeviceOption_TermsAndConditions_Required },
214220
#endif
221+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
222+
{ "icdActiveModeDurationMs", kArgumentRequired, kDeviceOption_icdActiveModeDurationMs },
223+
{ "icdIdleModeDuration", kArgumentRequired, kDeviceOption_icdIdleModeDuration },
224+
{ "icdPeriodicWakeupDurationMs", kArgumentRequired, kDeviceOption_icdPeriodicWakeupDurationMs },
225+
#endif // CHIP_ENABLE_ICD_SERVER
215226
{}
216227
};
217228

@@ -383,8 +394,21 @@ const char * sDeviceOptionHelp =
383394
" --faults <fault-string,...>\n"
384395
" Inject specified fault(s) at runtime.\n"
385396
#endif
386-
" --dac_provider <filepath>\n"
397+
" --dac_provider <filepath>\n"
387398
" A json file with data used by the example dac provider to validate device attestation procedure.\n"
399+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
400+
" --icdActiveModeDurationMs <icdActiveModeDurationMs>\n"
401+
" Sets the ICD active mode threshold (in milliseconds). (Default: 300) \n"
402+
" This defines the how long the the server typically will stay in active mode after \n"
403+
" initial transition out of idle mode.\n"
404+
" --icdIdleModeDuration <icdIdleModeDuration>\n"
405+
" Sets the ICD idle mode durations (in seconds). (Default: 300) \n"
406+
" This defines the how long the ICD server can stay in idle mode.\n"
407+
" --icdPeriodicWakeupDurationMs <icdPeriodicWakupDurationMs>\n"
408+
" Sets the ICD periodic wakeup (in milliseconds). (Default: 6000)\n"
409+
" This is for testing purpose on Linux which defines the internal to wakeup periodically to send \n"
410+
" Check-In messages since Linux application doesn't have a physical button to trigger wakeup\n"
411+
#endif
388412
"\n";
389413

390414
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
@@ -774,6 +798,38 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
774798
LinuxDeviceOptions::GetInstance().tcRequired.SetValue(static_cast<uint16_t>(atoi(aValue)));
775799
break;
776800
}
801+
#endif
802+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
803+
case kDeviceOption_icdActiveModeDurationMs: {
804+
uint32_t value = static_cast<uint32_t>(strtoul(aValue, nullptr, 0));
805+
if (value < 1)
806+
{
807+
PrintArgError("%s: invalid value specified for icdActiveModeDurationMs: %s\n", aProgram, aValue);
808+
retval = false;
809+
}
810+
else
811+
{
812+
LinuxDeviceOptions::GetInstance().icdActiveModeDurationMs.SetValue(chip::System::Clock::Milliseconds32(value));
813+
}
814+
break;
815+
}
816+
case kDeviceOption_icdIdleModeDuration: {
817+
uint32_t value = static_cast<uint32_t>(strtoul(aValue, nullptr, 0));
818+
if ((value < 1) || (value > 86400))
819+
{
820+
PrintArgError("%s: invalid value specified for icdIdleModeDuration: %s\n", aProgram, aValue);
821+
retval = false;
822+
}
823+
else
824+
{
825+
// Covert from seconds to mini seconds
826+
LinuxDeviceOptions::GetInstance().icdIdleModeDurationMs.SetValue(chip::System::Clock::Milliseconds32(value * 1000));
827+
}
828+
break;
829+
}
830+
case kDeviceOption_icdPeriodicWakeupDurationMs:
831+
LinuxDeviceOptions::GetInstance().icdPeriodicWakeupDurationMs = static_cast<uint32_t>(atoi(aValue));
832+
break;
777833
#endif
778834
default:
779835
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);

examples/platform/linux/Options.h

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <lib/core/Optional.h>
3636
#include <lib/support/CHIPArgParser.hpp>
3737
#include <platform/CHIPDeviceConfig.h>
38+
#include <platform/CHIPDeviceLayer.h>
3839
#include <setup_payload/SetupPayload.h>
3940

4041
#include <credentials/DeviceAttestationCredsProvider.h>
@@ -96,6 +97,11 @@ struct LinuxDeviceOptions
9697
#if CHIP_CONFIG_TERMS_AND_CONDITIONS_REQUIRED
9798
chip::Optional<uint16_t> tcVersion;
9899
chip::Optional<uint16_t> tcRequired;
100+
#endif
101+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
102+
chip::Optional<chip::System::Clock::Milliseconds32> icdActiveModeDurationMs;
103+
chip::Optional<chip::System::Clock::Milliseconds32> icdIdleModeDurationMs;
104+
uint32_t icdPeriodicWakeupDurationMs = 60000;
99105
#endif
100106
static LinuxDeviceOptions & GetInstance();
101107
};

0 commit comments

Comments
 (0)