Skip to content

Commit 219c3f0

Browse files
authored
[chip-tool] Support LIT ICD in chip-tool for subscriptions (#31576)
1 parent bdbd6de commit 219c3f0

File tree

9 files changed

+86
-5
lines changed

9 files changed

+86
-5
lines changed

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

+30
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "ModelCommand.h"
2020

2121
#include <app/InteractionModelEngine.h>
22+
#include <app/icd/client/DefaultICDClientStorage.h>
2223
#include <inttypes.h>
2324

2425
using namespace ::chip;
@@ -35,6 +36,7 @@ CHIP_ERROR ModelCommand::RunCommand()
3536
}
3637

3738
ChipLogProgress(chipTool, "Sending command to node 0x%" PRIx64, mDestinationId);
39+
CheckPeerICDType();
3840

3941
CommissioneeDeviceProxy * commissioneeDeviceProxy = nullptr;
4042
if (CHIP_NO_ERROR == CurrentCommissioner().GetDeviceBeingCommissioned(mDestinationId, &commissioneeDeviceProxy))
@@ -73,3 +75,31 @@ void ModelCommand::Shutdown()
7375

7476
CHIPCommand::Shutdown();
7577
}
78+
79+
void ModelCommand::CheckPeerICDType()
80+
{
81+
if (mIsPeerLIT.HasValue())
82+
{
83+
ChipLogProgress(chipTool, "Peer ICD type is set to %s", mIsPeerLIT.Value() == 1 ? "LIT-ICD" : "non LIT-ICD");
84+
return;
85+
}
86+
87+
app::ICDClientInfo info;
88+
auto destinationPeerId = chip::ScopedNodeId(mDestinationId, CurrentCommissioner().GetFabricIndex());
89+
auto iter = CHIPCommand::sICDClientStorage.IterateICDClientInfo();
90+
if (iter == nullptr)
91+
{
92+
return;
93+
}
94+
app::DefaultICDClientStorage::ICDClientInfoIteratorWrapper clientInfoIteratorWrapper(iter);
95+
96+
while (iter->Next(info))
97+
{
98+
if (ScopedNodeId(info.peer_node.GetNodeId(), info.peer_node.GetFabricIndex()) == destinationPeerId)
99+
{
100+
ChipLogProgress(chipTool, "Peer is a registered LIT ICD.");
101+
mIsPeerLIT.SetValue(true);
102+
return;
103+
}
104+
}
105+
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class ModelCommand : public CHIPCommand
5252
"Endpoint the command is targeted at.");
5353
}
5454
}
55+
AddArgument(
56+
"lit-icd-peer", 0, 1, &mIsPeerLIT,
57+
"Whether to treat the peer as a LIT ICD. false: Always no, true: Always yes, (not set): Yes if the peer is registered "
58+
"to this controller.");
5559
AddArgument("timeout", 0, UINT16_MAX, &mTimeout);
5660
}
5761

@@ -66,11 +70,16 @@ class ModelCommand : public CHIPCommand
6670
void Shutdown() override;
6771

6872
protected:
73+
bool IsPeerLIT() { return mIsPeerLIT.ValueOr(false); }
74+
6975
chip::Optional<uint16_t> mTimeout;
7076

7177
private:
7278
chip::NodeId mDestinationId;
7379
std::vector<chip::EndpointId> mEndPointId;
80+
chip::Optional<bool> mIsPeerLIT;
81+
82+
void CheckPeerICDType();
7483

7584
static void OnDeviceConnectedFn(void * context, chip::Messaging::ExchangeManager & exchangeMgr,
7685
const chip::SessionHandle & sessionHandle);

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

+3
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ class SubscribeAttribute : public SubscribeCommand
277277

278278
CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
279279
{
280+
SubscribeCommand::SetPeerLIT(IsPeerLIT());
280281
return SubscribeCommand::SubscribeAttribute(device, endpointIds, mClusterIds, mAttributeIds);
281282
}
282283

@@ -407,6 +408,7 @@ class SubscribeEvent : public SubscribeCommand
407408

408409
CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
409410
{
411+
SubscribeCommand::SetPeerLIT(IsPeerLIT());
410412
return SubscribeCommand::SubscribeEvent(device, endpointIds, mClusterIds, mEventIds);
411413
}
412414

@@ -538,6 +540,7 @@ class SubscribeAll : public SubscribeCommand
538540

539541
CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
540542
{
543+
SubscribeCommand::SetPeerLIT(IsPeerLIT());
541544
return SubscribeCommand::SubscribeAll(device, endpointIds, mClusterIds, mAttributeIds, mEventIds);
542545
}
543546

examples/chip-tool/commands/icd/ICDCommand.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "ICDCommand.h"
2020

21+
#include <app/icd/client/DefaultICDClientStorage.h>
2122
#include <crypto/DefaultSessionKeystore.h>
2223
#include <crypto/RawKeySessionKeystore.h>
2324

@@ -29,6 +30,11 @@ CHIP_ERROR ICDListCommand::RunCommand()
2930
auto iter = CHIPCommand::sICDClientStorage.IterateICDClientInfo();
3031
char icdAesKeyHex[Crypto::kAES_CCM128_Key_Length * 2 + 1];
3132
char icdHmacKeyHex[Crypto::kHMAC_CCM128_Key_Length * 2 + 1];
33+
if (iter == nullptr)
34+
{
35+
return CHIP_ERROR_NO_MEMORY;
36+
}
37+
app::DefaultICDClientStorage::ICDClientInfoIteratorWrapper clientInfoIteratorWrapper(iter);
3238
fprintf(stderr, " +-----------------------------------------------------------------------------+\n");
3339
fprintf(stderr, " | %-75s |\n", "Known ICDs:");
3440
fprintf(stderr, " +-----------------------------------------------------------------------------+\n");
@@ -54,8 +60,6 @@ CHIP_ERROR ICDListCommand::RunCommand()
5460
}
5561

5662
fprintf(stderr, " +-----------------------------------------------------------------------------+\n");
57-
58-
iter->Release();
5963
SetCommandExitStatus(CHIP_NO_ERROR);
6064
return CHIP_NO_ERROR;
6165
}

src/app/icd/client/DefaultICDClientStorage.h

+22
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ class DefaultICDClientStorage : public ICDClientStorage
5353
public:
5454
using ICDClientInfoIterator = CommonIterator<ICDClientInfo>;
5555

56+
// ICDClientInfoIterator wrapper to release ICDClientInfoIterator when it is out of scope
57+
class ICDClientInfoIteratorWrapper
58+
{
59+
public:
60+
ICDClientInfoIteratorWrapper(ICDClientInfoIterator * apICDClientInfoIterator)
61+
{
62+
mpICDClientInfoIterator = apICDClientInfoIterator;
63+
}
64+
65+
~ICDClientInfoIteratorWrapper()
66+
{
67+
if (mpICDClientInfoIterator != nullptr)
68+
{
69+
mpICDClientInfoIterator->Release();
70+
mpICDClientInfoIterator = nullptr;
71+
}
72+
}
73+
74+
private:
75+
ICDClientInfoIterator * mpICDClientInfoIterator = nullptr;
76+
};
77+
5678
static constexpr size_t kIteratorsMax = CHIP_CONFIG_MAX_ICD_CLIENTS_INFO_STORAGE_CONCURRENT_ITERATORS;
5779

5880
CHIP_ERROR Init(PersistentStorageDelegate * clientInfoStore, Crypto::SymmetricKeystore * keyStore);

src/app/tests/TestDefaultICDClientStorage.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ void TestClientInfoCountMultipleFabric(nlTestSuite * apSuite, void * apContext)
179179
err = manager.DeleteEntry(ScopedNodeId(nodeId1, fabricId1));
180180
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
181181
iterator = manager.IterateICDClientInfo();
182+
NL_TEST_ASSERT(apSuite, iterator != nullptr);
183+
DefaultICDClientStorage::ICDClientInfoIteratorWrapper clientInfoIteratorWrapper(iterator);
182184
NL_TEST_ASSERT(apSuite, iterator->Count() == 2);
183185

184186
err = manager.DeleteEntry(ScopedNodeId(nodeId2, fabricId1));
@@ -196,7 +198,7 @@ void TestClientInfoCountMultipleFabric(nlTestSuite * apSuite, void * apContext)
196198
{
197199
count++;
198200
}
199-
iterator->Release();
201+
200202
NL_TEST_ASSERT(apSuite, count == 0);
201203
}
202204

src/app/tests/suites/commands/interaction_model/InteractionModel.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ CHIP_ERROR InteractionModelReports::ReportAttribute(DeviceProxy * device, std::v
350350
{
351351
params.mKeepSubscriptions = mKeepSubscriptions.Value();
352352
}
353+
params.mIsPeerLIT = mIsPeerLIT;
353354
}
354355

355356
auto client = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), device->GetExchangeManager(),
@@ -479,6 +480,7 @@ CHIP_ERROR InteractionModelReports::ReportEvent(DeviceProxy * device, std::vecto
479480
{
480481
params.mKeepSubscriptions = mKeepSubscriptions.Value();
481482
}
483+
params.mIsPeerLIT = mIsPeerLIT;
482484
}
483485

484486
auto client = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), device->GetExchangeManager(),
@@ -652,6 +654,7 @@ CHIP_ERROR InteractionModelReports::ReportAll(chip::DeviceProxy * device, std::v
652654
{
653655
params.mKeepSubscriptions = mKeepSubscriptions.Value();
654656
}
657+
params.mIsPeerLIT = mIsPeerLIT;
655658
}
656659

657660
auto client = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance(), device->GetExchangeManager(),

src/app/tests/suites/commands/interaction_model/InteractionModel.h

+8
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ class InteractionModelReports
205205
return *this;
206206
}
207207

208+
InteractionModelReports & SetPeerLIT(bool isPeerLIT)
209+
{
210+
mIsPeerLIT = isPeerLIT;
211+
return *this;
212+
}
213+
208214
void ResetOptions()
209215
{
210216
mDataVersions = chip::NullOptional;
@@ -213,6 +219,7 @@ class InteractionModelReports
213219
mFabricFiltered = chip::Optional<bool>(true);
214220
mKeepSubscriptions = chip::NullOptional;
215221
mAutoResubscribe = chip::NullOptional;
222+
mIsPeerLIT = false;
216223
mMinInterval = 0;
217224
mMaxInterval = 0;
218225
}
@@ -223,6 +230,7 @@ class InteractionModelReports
223230
chip::Optional<bool> mFabricFiltered;
224231
chip::Optional<bool> mKeepSubscriptions;
225232
chip::Optional<bool> mAutoResubscribe;
233+
bool mIsPeerLIT;
226234
uint16_t mMinInterval;
227235
uint16_t mMaxInterval;
228236
};

src/controller/java/CHIPDeviceController-JNI.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,8 @@ JNI_METHOD(jobject, getICDClientInfo)(JNIEnv * env, jobject self, jlong handle,
21762176
ChipLogError(Controller, "CreateArrayList failed!: %" CHIP_ERROR_FORMAT, err.Format()));
21772177

21782178
auto iter = wrapper->getICDClientStorage()->IterateICDClientInfo();
2179+
VerifyOrReturnValue(iter != nullptr, nullptr, ChipLogError(Controller, "IterateICDClientInfo failed!"));
2180+
app::DefaultICDClientStorage::ICDClientInfoIteratorWrapper clientInfoIteratorWrapper(iter);
21792181

21802182
jmethodID constructor;
21812183
jclass infoClass;
@@ -2219,8 +2221,6 @@ JNI_METHOD(jobject, getICDClientInfo)(JNIEnv * env, jobject self, jlong handle,
22192221
ChipLogError(Controller, "AddToList error!: %" CHIP_ERROR_FORMAT, err.Format()));
22202222
}
22212223

2222-
iter->Release();
2223-
22242224
return jInfo;
22252225
}
22262226

0 commit comments

Comments
 (0)