Skip to content

Commit

Permalink
[ICD] Add ClientType support to the ICDManager and ICD Management clu…
Browse files Browse the repository at this point in the history
…ster (#33811)

* update icdm xml

* generated files

* Add clientType to the ICDMonitoring table

* Add client type buisness logic to ICDM cluster

* Add client type logic to the ICDManager

* finish clean up

* make ClientType arg mandatory

* regen

---------

Co-authored-by: yunhanw <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 29, 2024
1 parent f146ebd commit 0700231
Show file tree
Hide file tree
Showing 64 changed files with 478 additions and 59 deletions.
7 changes: 6 additions & 1 deletion examples/chip-tool/commands/clusters/ClusterCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "DataModelLogger.h"
#include "ModelCommand.h"
#include <app/tests/suites/commands/interaction_model/InteractionModel.h>
#include <lib/core/ClusterEnums.h>

class ClusterCommand : public InteractionModelCommands, public ModelCommand, public chip::app::CommandSender::Callback
{
Expand Down Expand Up @@ -70,6 +71,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
ReturnErrorOnFailure(InteractionModelCommands::SendCommand(device, endpointId, clusterId, commandId, value));
mScopedNodeId = chip::ScopedNodeId(value.checkInNodeID, device->GetSecureSession().Value()->GetFabricIndex());
mMonitoredSubject = value.monitoredSubject;
mClientType = value.clientType;
memcpy(mICDSymmetricKey, value.key.data(), value.key.size());
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -148,6 +150,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
clientInfo.peer_node = mScopedNodeId;
clientInfo.monitored_subject = mMonitoredSubject;
clientInfo.start_icd_counter = value.ICDCounter;
clientInfo.client_type = mClientType;

StoreICDEntryWithKey(clientInfo, chip::ByteSpan(mICDSymmetricKey));
}
Expand Down Expand Up @@ -258,8 +261,10 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
chip::ClusterId mClusterId;
chip::CommandId mCommandId;
chip::ScopedNodeId mScopedNodeId;
uint64_t mMonitoredSubject = static_cast<uint64_t>(0);
uint64_t mMonitoredSubject = static_cast<uint64_t>(0);
chip::app::Clusters::IcdManagement::ClientTypeEnum mClientType = chip::app::Clusters::IcdManagement::ClientTypeEnum::kPermanent;
uint8_t mICDSymmetricKey[chip::Crypto::kAES_CCM128_Key_Length];

CHIP_ERROR mError = CHIP_NO_ERROR;
CustomArgument mPayload;
};
24 changes: 13 additions & 11 deletions examples/chip-tool/commands/icd/ICDCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <app/icd/client/DefaultICDClientStorage.h>
#include <crypto/DefaultSessionKeystore.h>
#include <crypto/RawKeySessionKeystore.h>
#include <string>

using namespace ::chip;
using namespace ::chip::app;
Expand All @@ -36,31 +37,32 @@ CHIP_ERROR ICDListCommand::RunCommand()
return CHIP_ERROR_NO_MEMORY;
}
app::DefaultICDClientStorage::ICDClientInfoIteratorWrapper clientInfoIteratorWrapper(iter);
fprintf(stderr, " +-----------------------------------------------------------------------------+\n");
fprintf(stderr, " | %-75s |\n", "Known ICDs:");
fprintf(stderr, " +-----------------------------------------------------------------------------+\n");
fprintf(stderr, " | %20s | %15s | %15s | %16s |\n", "Fabric Index:Node ID", "Start Counter", "Counter Offset",
"MonitoredSubject");
fprintf(stderr, " +------------------------------------------------------------------------------------------+\n");
fprintf(stderr, " | %-88s |\n", "Known ICDs:");
fprintf(stderr, " +------------------------------------------------------------------------------------------+\n");
fprintf(stderr, " | %20s | %15s | %15s | %16s | %10s |\n", "Fabric Index:Node ID", "Start Counter", "Counter Offset",
"MonitoredSubject", "ClientType");

while (iter->Next(info))
{
fprintf(stderr, " +-----------------------------------------------------------------------------+\n");
fprintf(stderr, " | %3" PRIu32 ":" ChipLogFormatX64 " | %15" PRIu32 " | %15" PRIu32 " | " ChipLogFormatX64 " |\n",
fprintf(stderr, " +------------------------------------------------------------------------------------------+\n");
fprintf(stderr, " | %3" PRIu32 ":" ChipLogFormatX64 " | %15" PRIu32 " | %15" PRIu32 " | " ChipLogFormatX64 " | %10u |\n",
static_cast<uint32_t>(info.peer_node.GetFabricIndex()), ChipLogValueX64(info.peer_node.GetNodeId()),
info.start_icd_counter, info.offset, ChipLogValueX64(info.monitored_subject));
info.start_icd_counter, info.offset, ChipLogValueX64(info.monitored_subject),
static_cast<uint8_t>(info.client_type));

static_assert(std::is_same<decltype(CHIPCommand::sSessionKeystore), Crypto::RawKeySessionKeystore>::value,
"The following BytesToHex can copy/encode the key bytes from sharedKey to hexadecimal format, which only "
"works for RawKeySessionKeystore");
Encoding::BytesToHex(info.aes_key_handle.As<Crypto::Symmetric128BitsKeyByteArray>(), Crypto::kAES_CCM128_Key_Length,
icdAesKeyHex, sizeof(icdAesKeyHex), chip::Encoding::HexFlags::kNullTerminate);
fprintf(stderr, " | aes key: %60s |\n", icdAesKeyHex);
fprintf(stderr, " | aes key: %60s |\n", icdAesKeyHex);
Encoding::BytesToHex(info.hmac_key_handle.As<Crypto::Symmetric128BitsKeyByteArray>(), Crypto::kHMAC_CCM128_Key_Length,
icdHmacKeyHex, sizeof(icdHmacKeyHex), chip::Encoding::HexFlags::kNullTerminate);
fprintf(stderr, " | hmac key: %60s |\n", icdHmacKeyHex);
fprintf(stderr, " | hmac key: %60s |\n", icdHmacKeyHex);
}

fprintf(stderr, " +-----------------------------------------------------------------------------+\n");
fprintf(stderr, " +------------------------------------------------------------------------------------------+\n");
SetCommandExitStatus(CHIP_NO_ERROR);
return CHIP_NO_ERROR;
}
Expand Down
7 changes: 6 additions & 1 deletion examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ CommissioningParameters PairingCommand::GetCommissioningParameters()
{
mICDMonitoredSubject.SetValue(mICDCheckInNodeId.Value());
}
if (!mICDClientType.HasValue())
{
mICDClientType.SetValue(app::Clusters::IcdManagement::ClientTypeEnum::kPermanent);
}
// These Optionals must have values now.
// The commissioner will verify these values.
params.SetICDSymmetricKey(mICDSymmetricKey.Value());
Expand All @@ -166,6 +170,7 @@ CommissioningParameters PairingCommand::GetCommissioningParameters()
}
params.SetICDCheckInNodeId(mICDCheckInNodeId.Value());
params.SetICDMonitoredSubject(mICDMonitoredSubject.Value());
params.SetICDClientType(mICDClientType.Value());
}

return params;
Expand Down Expand Up @@ -459,7 +464,7 @@ void PairingCommand::OnICDRegistrationComplete(ScopedNodeId nodeId, uint32_t icd
sizeof(icdSymmetricKeyHex), chip::Encoding::HexFlags::kNullTerminate);

app::ICDClientInfo clientInfo;
clientInfo.peer_node = nodeId;
clientInfo.peer_node = chip::ScopedNodeId(mICDCheckInNodeId.Value(), nodeId.GetFabricIndex());
clientInfo.monitored_subject = mICDMonitoredSubject.Value();
clientInfo.start_icd_counter = icdCounter;

Expand Down
3 changes: 3 additions & 0 deletions examples/chip-tool/commands/pairing/PairingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class PairingCommand : public CHIPCommand,
"The check-in node id for the ICD, default: node id of the commissioner.");
AddArgument("icd-monitored-subject", 0, UINT64_MAX, &mICDMonitoredSubject,
"The monitored subject of the ICD, default: The node id used for icd-check-in-nodeid.");
AddArgument("icd-client-type", 0, 1, &mICDClientType,
"The ClientType of the client registering, default: Permanent client - 0");
AddArgument("icd-symmetric-key", &mICDSymmetricKey, "The 16 bytes ICD symmetric key, default: randomly generated.");
AddArgument("icd-stay-active-duration", 0, UINT32_MAX, &mICDStayActiveDurationMsec,
"If set, a LIT ICD that is commissioned will be requested to stay active for this many milliseconds");
Expand Down Expand Up @@ -245,6 +247,7 @@ class PairingCommand : public CHIPCommand,
chip::Optional<NodeId> mICDCheckInNodeId;
chip::Optional<chip::ByteSpan> mICDSymmetricKey;
chip::Optional<uint64_t> mICDMonitoredSubject;
chip::Optional<chip::app::Clusters::IcdManagement::ClientTypeEnum> mICDClientType;
chip::Optional<uint32_t> mICDStayActiveDurationMsec;
chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type> mTimeZoneList;
TypedComplexArgument<chip::app::DataModel::List<chip::app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,11 @@ cluster BooleanState = 69 {
cluster IcdManagement = 70 {
revision 2;

enum ClientTypeEnum : enum8 {
kPermanent = 0;
kEphemeral = 1;
}

enum OperatingModeEnum : enum8 {
kSIT = 0;
kLIT = 1;
Expand Down Expand Up @@ -1349,6 +1354,7 @@ cluster IcdManagement = 70 {
fabric_scoped struct MonitoringRegistrationStruct {
fabric_sensitive node_id checkInNodeID = 1;
fabric_sensitive int64u monitoredSubject = 2;
fabric_sensitive ClientTypeEnum clientType = 4;
fabric_idx fabricIndex = 254;
}

Expand All @@ -1373,6 +1379,7 @@ cluster IcdManagement = 70 {
int64u monitoredSubject = 1;
octet_string<16> key = 2;
optional octet_string<16> verificationKey = 3;
ClientTypeEnum clientType = 4;
}

response struct RegisterClientResponse = 1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,11 @@ cluster BooleanState = 69 {
cluster IcdManagement = 70 {
revision 2;

enum ClientTypeEnum : enum8 {
kPermanent = 0;
kEphemeral = 1;
}

enum OperatingModeEnum : enum8 {
kSIT = 0;
kLIT = 1;
Expand Down Expand Up @@ -1349,6 +1354,7 @@ cluster IcdManagement = 70 {
fabric_scoped struct MonitoringRegistrationStruct {
fabric_sensitive node_id checkInNodeID = 1;
fabric_sensitive int64u monitoredSubject = 2;
fabric_sensitive ClientTypeEnum clientType = 4;
fabric_idx fabricIndex = 254;
}

Expand All @@ -1373,6 +1379,7 @@ cluster IcdManagement = 70 {
int64u monitoredSubject = 1;
octet_string<16> key = 2;
optional octet_string<16> verificationKey = 3;
ClientTypeEnum clientType = 4;
}

response struct RegisterClientResponse = 1 {
Expand Down
7 changes: 6 additions & 1 deletion examples/fabric-admin/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ CommissioningParameters PairingCommand::GetCommissioningParameters()
{
mICDMonitoredSubject.SetValue(mICDCheckInNodeId.Value());
}
if (!mICDClientType.HasValue())
{
mICDClientType.SetValue(app::Clusters::IcdManagement::ClientTypeEnum::kPermanent);
}
// These Optionals must have values now.
// The commissioner will verify these values.
params.SetICDSymmetricKey(mICDSymmetricKey.Value());
Expand All @@ -166,6 +170,7 @@ CommissioningParameters PairingCommand::GetCommissioningParameters()
}
params.SetICDCheckInNodeId(mICDCheckInNodeId.Value());
params.SetICDMonitoredSubject(mICDMonitoredSubject.Value());
params.SetICDClientType(mICDClientType.Value());
}

return params;
Expand Down Expand Up @@ -459,7 +464,7 @@ void PairingCommand::OnICDRegistrationComplete(ScopedNodeId nodeId, uint32_t icd
sizeof(icdSymmetricKeyHex), chip::Encoding::HexFlags::kNullTerminate);

app::ICDClientInfo clientInfo;
clientInfo.peer_node = nodeId;
clientInfo.peer_node = chip::ScopedNodeId(mICDCheckInNodeId.Value(), nodeId.GetFabricIndex());
clientInfo.monitored_subject = mICDMonitoredSubject.Value();
clientInfo.start_icd_counter = icdCounter;

Expand Down
3 changes: 3 additions & 0 deletions examples/fabric-admin/commands/pairing/PairingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class PairingCommand : public CHIPCommand,
"The check-in node id for the ICD, default: node id of the commissioner.");
AddArgument("icd-monitored-subject", 0, UINT64_MAX, &mICDMonitoredSubject,
"The monitored subject of the ICD, default: The node id used for icd-check-in-nodeid.");
AddArgument("icd-client-type", 0, 1, &mICDClientType,
"The ClientType of the client registering, default: Permanent client - 0");
AddArgument("icd-symmetric-key", &mICDSymmetricKey, "The 16 bytes ICD symmetric key, default: randomly generated.");
AddArgument("icd-stay-active-duration", 0, UINT32_MAX, &mICDStayActiveDurationMsec,
"If set, a LIT ICD that is commissioned will be requested to stay active for this many milliseconds");
Expand Down Expand Up @@ -258,6 +260,7 @@ class PairingCommand : public CHIPCommand,
chip::Optional<char *> mCountryCode;
chip::Optional<bool> mICDRegistration;
chip::Optional<NodeId> mICDCheckInNodeId;
chip::Optional<chip::app::Clusters::IcdManagement::ClientTypeEnum> mICDClientType;
chip::Optional<chip::ByteSpan> mICDSymmetricKey;
chip::Optional<uint64_t> mICDMonitoredSubject;
chip::Optional<uint32_t> mICDStayActiveDurationMsec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,11 @@ cluster UserLabel = 65 {
cluster IcdManagement = 70 {
revision 2;

enum ClientTypeEnum : enum8 {
kPermanent = 0;
kEphemeral = 1;
}

enum OperatingModeEnum : enum8 {
kSIT = 0;
kLIT = 1;
Expand Down Expand Up @@ -1973,6 +1978,7 @@ cluster IcdManagement = 70 {
fabric_scoped struct MonitoringRegistrationStruct {
fabric_sensitive node_id checkInNodeID = 1;
fabric_sensitive int64u monitoredSubject = 2;
fabric_sensitive ClientTypeEnum clientType = 4;
fabric_idx fabricIndex = 254;
}

Expand All @@ -1997,6 +2003,7 @@ cluster IcdManagement = 70 {
int64u monitoredSubject = 1;
octet_string<16> key = 2;
optional octet_string<16> verificationKey = 3;
ClientTypeEnum clientType = 4;
}

response struct RegisterClientResponse = 1 {
Expand Down
7 changes: 7 additions & 0 deletions examples/light-switch-app/qpg/zap/switch.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,11 @@ cluster UserLabel = 65 {
cluster IcdManagement = 70 {
revision 2;

enum ClientTypeEnum : enum8 {
kPermanent = 0;
kEphemeral = 1;
}

enum OperatingModeEnum : enum8 {
kSIT = 0;
kLIT = 1;
Expand Down Expand Up @@ -1770,6 +1775,7 @@ cluster IcdManagement = 70 {
fabric_scoped struct MonitoringRegistrationStruct {
fabric_sensitive node_id checkInNodeID = 1;
fabric_sensitive int64u monitoredSubject = 2;
fabric_sensitive ClientTypeEnum clientType = 4;
fabric_idx fabricIndex = 254;
}

Expand All @@ -1794,6 +1800,7 @@ cluster IcdManagement = 70 {
int64u monitoredSubject = 1;
octet_string<16> key = 2;
optional octet_string<16> verificationKey = 3;
ClientTypeEnum clientType = 4;
}

response struct RegisterClientResponse = 1 {
Expand Down
7 changes: 7 additions & 0 deletions examples/lit-icd-app/lit-icd-common/lit-icd-server-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,11 @@ cluster BooleanState = 69 {
cluster IcdManagement = 70 {
revision 2;

enum ClientTypeEnum : enum8 {
kPermanent = 0;
kEphemeral = 1;
}

enum OperatingModeEnum : enum8 {
kSIT = 0;
kLIT = 1;
Expand Down Expand Up @@ -1447,6 +1452,7 @@ cluster IcdManagement = 70 {
fabric_scoped struct MonitoringRegistrationStruct {
fabric_sensitive node_id checkInNodeID = 1;
fabric_sensitive int64u monitoredSubject = 2;
fabric_sensitive ClientTypeEnum clientType = 4;
fabric_idx fabricIndex = 254;
}

Expand All @@ -1471,6 +1477,7 @@ cluster IcdManagement = 70 {
int64u monitoredSubject = 1;
octet_string<16> key = 2;
optional octet_string<16> verificationKey = 3;
ClientTypeEnum clientType = 4;
}

response struct RegisterClientResponse = 1 {
Expand Down
7 changes: 7 additions & 0 deletions examples/lock-app/lock-common/lock-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,11 @@ cluster UserLabel = 65 {
cluster IcdManagement = 70 {
revision 2;

enum ClientTypeEnum : enum8 {
kPermanent = 0;
kEphemeral = 1;
}

enum OperatingModeEnum : enum8 {
kSIT = 0;
kLIT = 1;
Expand Down Expand Up @@ -1790,6 +1795,7 @@ cluster IcdManagement = 70 {
fabric_scoped struct MonitoringRegistrationStruct {
fabric_sensitive node_id checkInNodeID = 1;
fabric_sensitive int64u monitoredSubject = 2;
fabric_sensitive ClientTypeEnum clientType = 4;
fabric_idx fabricIndex = 254;
}

Expand All @@ -1814,6 +1820,7 @@ cluster IcdManagement = 70 {
int64u monitoredSubject = 1;
octet_string<16> key = 2;
optional octet_string<16> verificationKey = 3;
ClientTypeEnum clientType = 4;
}

response struct RegisterClientResponse = 1 {
Expand Down
7 changes: 7 additions & 0 deletions examples/lock-app/qpg/zap/lock.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,11 @@ cluster UserLabel = 65 {
cluster IcdManagement = 70 {
revision 2;

enum ClientTypeEnum : enum8 {
kPermanent = 0;
kEphemeral = 1;
}

enum OperatingModeEnum : enum8 {
kSIT = 0;
kLIT = 1;
Expand Down Expand Up @@ -1446,6 +1451,7 @@ cluster IcdManagement = 70 {
fabric_scoped struct MonitoringRegistrationStruct {
fabric_sensitive node_id checkInNodeID = 1;
fabric_sensitive int64u monitoredSubject = 2;
fabric_sensitive ClientTypeEnum clientType = 4;
fabric_idx fabricIndex = 254;
}

Expand All @@ -1470,6 +1476,7 @@ cluster IcdManagement = 70 {
int64u monitoredSubject = 1;
octet_string<16> key = 2;
optional octet_string<16> verificationKey = 3;
ClientTypeEnum clientType = 4;
}

response struct RegisterClientResponse = 1 {
Expand Down
Loading

0 comments on commit 0700231

Please sign in to comment.