Skip to content

Commit ef28056

Browse files
[chip-tool][ICD] Store ICDClientInfo when running icd registration independently (#33690)
* Store ICDClientInfo when running icd registration independently * Restyled by clang-format * address comments --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 405a083 commit ef28056

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

examples/chip-tool/commands/clusters/ClusterCommand.h

+36-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818

1919
#pragma once
2020

21-
#include <app/tests/suites/commands/interaction_model/InteractionModel.h>
22-
2321
#include "DataModelLogger.h"
2422
#include "ModelCommand.h"
23+
#include <app/tests/suites/commands/interaction_model/InteractionModel.h>
2524

2625
class ClusterCommand : public InteractionModelCommands, public ModelCommand, public chip::app::CommandSender::Callback
2726
{
@@ -64,6 +63,17 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
6463
return CHIP_NO_ERROR;
6564
}
6665

66+
CHIP_ERROR SendCommand(chip::DeviceProxy * device, chip::EndpointId endpointId, chip::ClusterId clusterId,
67+
chip::CommandId commandId,
68+
const chip::app::Clusters::IcdManagement::Commands::RegisterClient::Type & value)
69+
{
70+
ReturnErrorOnFailure(InteractionModelCommands::SendCommand(device, endpointId, clusterId, commandId, value));
71+
mScopedNodeId = chip::ScopedNodeId(value.checkInNodeID, device->GetSecureSession().Value()->GetFabricIndex());
72+
mMonitoredSubject = value.monitoredSubject;
73+
memcpy(mICDSymmetricKey, value.key.data(), value.key.size());
74+
return CHIP_NO_ERROR;
75+
}
76+
6777
CHIP_ERROR SendCommand(chip::DeviceProxy * device, chip::EndpointId endpointId, chip::ClusterId clusterId,
6878
chip::CommandId commandId,
6979
const chip::app::Clusters::DiagnosticLogs::Commands::RetrieveLogsRequest::Type & value)
@@ -117,11 +127,32 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
117127
mError = error;
118128
return;
119129
}
130+
if ((path.mEndpointId == chip::kRootEndpointId) && (path.mClusterId == chip::app::Clusters::IcdManagement::Id) &&
131+
(path.mCommandId == chip::app::Clusters::IcdManagement::Commands::RegisterClient::Id))
132+
{
133+
chip::TLV::TLVReader counterTlvReader;
134+
counterTlvReader.Init(*data);
135+
chip::app::Clusters::IcdManagement::Commands::RegisterClientResponse::DecodableType value;
136+
CHIP_ERROR err = chip::app::DataModel::Decode(counterTlvReader, value);
137+
if (CHIP_NO_ERROR != err)
138+
{
139+
ChipLogError(chipTool, "Failed to decode ICD counter: %" CHIP_ERROR_FORMAT, err.Format());
140+
return;
141+
}
142+
143+
chip::app::ICDClientInfo clientInfo;
144+
clientInfo.peer_node = mScopedNodeId;
145+
clientInfo.monitored_subject = mMonitoredSubject;
146+
clientInfo.start_icd_counter = value.ICDCounter;
147+
148+
StoreICDEntryWithKey(clientInfo, chip::ByteSpan(mICDSymmetricKey));
149+
}
120150
}
151+
121152
if ((path.mEndpointId == chip::kRootEndpointId) && (path.mClusterId == chip::app::Clusters::IcdManagement::Id) &&
122153
(path.mCommandId == chip::app::Clusters::IcdManagement::Commands::UnregisterClient::Id))
123154
{
124-
ModelCommand::ClearICDEntry(mScopedNodeId);
155+
ClearICDEntry(mScopedNodeId);
125156
}
126157
}
127158

@@ -223,6 +254,8 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
223254
chip::ClusterId mClusterId;
224255
chip::CommandId mCommandId;
225256
chip::ScopedNodeId mScopedNodeId;
257+
uint64_t mMonitoredSubject = static_cast<uint64_t>(0);
258+
uint8_t mICDSymmetricKey[chip::Crypto::kAES_CCM128_Key_Length];
226259
CHIP_ERROR mError = CHIP_NO_ERROR;
227260
CustomArgument mPayload;
228261
};

examples/chip-tool/commands/clusters/ModelCommand.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void ModelCommand::Shutdown()
7676
CHIPCommand::Shutdown();
7777
}
7878

79-
void ModelCommand::ClearICDEntry(const chip::ScopedNodeId & nodeId)
79+
void ModelCommand::ClearICDEntry(const ScopedNodeId & nodeId)
8080
{
8181
CHIP_ERROR deleteEntryError = CHIPCommand::sICDClientStorage.DeleteEntry(nodeId);
8282
if (deleteEntryError != CHIP_NO_ERROR)
@@ -85,6 +85,22 @@ void ModelCommand::ClearICDEntry(const chip::ScopedNodeId & nodeId)
8585
}
8686
}
8787

88+
void ModelCommand::StoreICDEntryWithKey(app::ICDClientInfo & clientInfo, ByteSpan key)
89+
{
90+
CHIP_ERROR err = CHIPCommand::sICDClientStorage.SetKey(clientInfo, key);
91+
if (err == CHIP_NO_ERROR)
92+
{
93+
err = CHIPCommand::sICDClientStorage.StoreEntry(clientInfo);
94+
}
95+
96+
if (err != CHIP_NO_ERROR)
97+
{
98+
CHIPCommand::sICDClientStorage.RemoveKey(clientInfo);
99+
ChipLogError(chipTool, "Failed to persist symmetric key with error: %" CHIP_ERROR_FORMAT, err.Format());
100+
return;
101+
}
102+
}
103+
88104
void ModelCommand::CheckPeerICDType()
89105
{
90106
if (mIsPeerLIT.HasValue())

examples/chip-tool/commands/clusters/ModelCommand.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class ModelCommand : public CHIPCommand
6767

6868
virtual CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex) { return CHIP_ERROR_BAD_REQUEST; };
6969

70-
virtual void ClearICDEntry(const chip::ScopedNodeId & nodeId);
71-
70+
void ClearICDEntry(const chip::ScopedNodeId & nodeId);
71+
void StoreICDEntryWithKey(chip::app::ICDClientInfo & clientinfo, chip::ByteSpan key);
7272
void Shutdown() override;
7373

7474
protected:

examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@ void ModelCommand::Shutdown()
8282
mOnDeviceConnectionFailureCallback.Cancel();
8383
}
8484

85-
void ModelCommand::ClearICDEntry(const chip::ScopedNodeId & nodeId)
85+
void ModelCommand::ClearICDEntry(const ScopedNodeId & nodeId)
8686
{
8787
ChipLogError(chipTool, "ClearICDEntry is not implemented in tv-casting-app");
8888
}
8989

90+
void ModelCommand::StoreICDEntryWithKey(app::ICDClientInfo & clientinfo, ByteSpan key)
91+
{
92+
ChipLogError(chipTool, "StoreICDEntryWithKey is not implemented in tv-casting-app");
93+
}
94+
9095
bool ModelCommand::IsPeerLIT()
9196
{
9297
// Does not support tv-casting-app

0 commit comments

Comments
 (0)