Skip to content

Commit da5081d

Browse files
committed
DNS: Hack chip-tool for sending batch command
1 parent 8fbe0a7 commit da5081d

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

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

+15-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "DataModelLogger.h"
2424
#include "ModelCommand.h"
2525

26-
class ClusterCommand : public InteractionModelCommands, public ModelCommand, public chip::app::CommandSender::Callback
26+
class ClusterCommand : public InteractionModelCommands, public ModelCommand, public chip::app::CommandSender::ExtendableCallback
2727
{
2828
public:
2929
ClusterCommand(CredentialIssuerCommands * credsIssuerConfig) :
@@ -83,25 +83,25 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
8383
return InteractionModelCommands::SendGroupCommand(groupId, fabricIndex, clusterId, commandId, value);
8484
}
8585

86-
/////////// CommandSender Callback Interface /////////
87-
virtual void OnResponse(chip::app::CommandSender * client, const chip::app::ConcreteCommandPath & path,
88-
const chip::app::StatusIB & status, chip::TLV::TLVReader * data) override
86+
/////////// CommandSender ExtendableCallback Interface /////////
87+
virtual void OnResponse(chip::app::CommandSender * client, const chip::app::CommandSender::ResponseData & responseData) override
8988
{
90-
CHIP_ERROR error = status.ToChipError();
89+
CHIP_ERROR error = responseData.statusIB.ToChipError();
9190
if (CHIP_NO_ERROR != error)
9291
{
93-
LogErrorOnFailure(RemoteDataModelLogger::LogErrorAsJSON(path, status));
92+
LogErrorOnFailure(RemoteDataModelLogger::LogErrorAsJSON(responseData.path, responseData.statusIB));
9493

9594
ChipLogError(chipTool, "Response Failure: %s", chip::ErrorStr(error));
95+
// TODO should we be overriding this error on the success case if we had an error previously
9696
mError = error;
9797
return;
9898
}
9999

100-
if (data != nullptr)
100+
if (responseData.data != nullptr)
101101
{
102-
LogErrorOnFailure(RemoteDataModelLogger::LogCommandAsJSON(path, data));
102+
LogErrorOnFailure(RemoteDataModelLogger::LogCommandAsJSON(responseData.path, responseData.data));
103103

104-
error = DataModelLogger::LogCommand(path, data);
104+
error = DataModelLogger::LogCommand(responseData.path, responseData.data);
105105
if (CHIP_NO_ERROR != error)
106106
{
107107
ChipLogError(chipTool, "Response Failure: Can not decode Data");
@@ -111,12 +111,12 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
111111
}
112112
}
113113

114-
virtual void OnError(const chip::app::CommandSender * client, CHIP_ERROR error) override
114+
virtual void OnError(const chip::app::CommandSender * client, const chip::app::CommandSender::ErrorData & errorData) override
115115
{
116-
LogErrorOnFailure(RemoteDataModelLogger::LogErrorAsJSON(error));
116+
LogErrorOnFailure(RemoteDataModelLogger::LogErrorAsJSON(errorData.error));
117117

118-
ChipLogProgress(chipTool, "Error: %s", chip::ErrorStr(error));
119-
mError = error;
118+
ChipLogProgress(chipTool, "Error: %s", chip::ErrorStr(errorData.error));
119+
mError = errorData.error;
120120
}
121121

122122
virtual void OnDone(chip::app::CommandSender * client) override
@@ -199,6 +199,8 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
199199
"the Matter specification.");
200200
AddArgument("busyWaitForMs", 0, UINT16_MAX, &mBusyWaitForMs,
201201
"If provided, block the main thread processing for the given time right after sending a command.");
202+
AddArgument("hackedBatchCommand", 0, 1, &mHackedBatchCommand,
203+
"Hacks sending a batch command. Second command added by duplicating the provided command but adding 1 to the provided endpoint.");
202204
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
203205
AddArgument("repeat-count", 1, UINT16_MAX, &mRepeatCount);
204206
AddArgument("repeat-delay-ms", 0, UINT16_MAX, &mRepeatDelayInMs);

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,15 @@ void InteractionModel::OnDone(WriteClient * client)
186186
ContinueOnChipMainThread(CHIP_NO_ERROR);
187187
}
188188

189-
/////////// CommandSender Callback Interface /////////
190-
void InteractionModel::OnResponse(CommandSender * client, const ConcreteCommandPath & path, const StatusIB & status,
191-
TLV::TLVReader * data)
189+
/////////// CommandSender ExtendableCallback Interface /////////
190+
void InteractionModel::OnResponse(CommandSender * client, const CommandSender::ResponseData & responseData)
192191
{
193-
OnResponse(status, data);
192+
OnResponse(responseData.statusIB, responseData.data);
194193
}
195194

196-
void InteractionModel::OnError(const CommandSender * client, CHIP_ERROR error)
195+
void InteractionModel::OnError(const CommandSender * client, const CommandSender::ErrorData & errorData)
197196
{
198-
StatusIB status(error);
197+
StatusIB status(errorData.error);
199198
OnResponse(status, nullptr);
200199
}
201200

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

+26-7
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class InteractionModelReports
238238
class InteractionModelCommands
239239
{
240240
public:
241-
InteractionModelCommands(chip::app::CommandSender::Callback * callback) : mCallback(callback) { ResetOptions(); }
241+
InteractionModelCommands(chip::app::CommandSender::ExtendableCallback * callback) : mCallback(callback) { ResetOptions(); }
242242

243243
protected:
244244
template <class T>
@@ -255,9 +255,27 @@ class InteractionModelCommands
255255
mCallback, device->GetExchangeManager(), mTimedInteractionTimeoutMs.HasValue(), mSuppressResponse.ValueOr(false));
256256
VerifyOrReturnError(commandSender != nullptr, CHIP_ERROR_NO_MEMORY);
257257

258+
if (mHackedBatchCommand.ValueOr(false))
259+
{
260+
chip::app::CommandSender::ConfigParameters config;
261+
auto remoteSessionParameters = device->GetSecureSession().Value()->GetRemoteSessionParameters();
262+
config.SetRemoteMaxPathsPerInvoke(remoteSessionParameters.GetMaxPathsPerInvoke());
263+
ReturnErrorOnFailure(commandSender->SetCommandSenderConfig(config));
264+
}
265+
258266
chip::app::CommandSender::AddRequestDataParameters addRequestDataParams(mTimedInteractionTimeoutMs);
267+
addRequestDataParams.commandRef.SetValue(1);
259268
// Using TestOnly AddRequestData to allow for an intentionally malformed request for server validation testing.
260269
ReturnErrorOnFailure(commandSender->TestOnlyAddRequestDataNoTimedCheck(commandPath, value, addRequestDataParams));
270+
271+
if (mHackedBatchCommand.ValueOr(false))
272+
{
273+
chip::app::CommandPathParams hackedCommandPath = { static_cast<chip::EndpointId>(endpointId+1), clusterId, commandId,
274+
(chip::app::CommandPathFlags::kEndpointIdValid) };
275+
addRequestDataParams.commandRef.SetValue(2);
276+
ReturnErrorOnFailure(commandSender->TestOnlyAddRequestDataNoTimedCheck(hackedCommandPath, value, addRequestDataParams));
277+
}
278+
261279
ReturnErrorOnFailure(commandSender->SendCommandRequest(device->GetSecureSession().Value()));
262280
mCommandSender.push_back(std::move(commandSender));
263281

@@ -302,7 +320,7 @@ class InteractionModelCommands
302320
}
303321

304322
std::vector<std::unique_ptr<chip::app::CommandSender>> mCommandSender;
305-
chip::app::CommandSender::Callback * mCallback;
323+
chip::app::CommandSender::ExtendableCallback * mCallback;
306324

307325
InteractionModelCommands & SetTimedInteractionTimeoutMs(uint16_t timedInteractionTimeoutMs)
308326
{
@@ -371,10 +389,12 @@ class InteractionModelCommands
371389
mRepeatCount = chip::NullOptional;
372390
mRepeatDelayInMs = chip::NullOptional;
373391
mBusyWaitForMs = chip::NullOptional;
392+
mHackedBatchCommand = chip::NullOptional;
374393
}
375394

376395
chip::Optional<uint16_t> mTimedInteractionTimeoutMs;
377396
chip::Optional<bool> mSuppressResponse;
397+
chip::Optional<bool> mHackedBatchCommand;
378398
chip::Optional<uint16_t> mRepeatCount;
379399
chip::Optional<uint16_t> mRepeatDelayInMs;
380400
chip::Optional<uint16_t> mBusyWaitForMs;
@@ -587,7 +607,7 @@ class InteractionModel : public InteractionModelReports,
587607
public InteractionModelWriter,
588608
public chip::app::ReadClient::Callback,
589609
public chip::app::WriteClient::Callback,
590-
public chip::app::CommandSender::Callback
610+
public chip::app::CommandSender::ExtendableCallback
591611
{
592612
public:
593613
InteractionModel() : InteractionModelReports(this), InteractionModelCommands(this), InteractionModelWriter(this){};
@@ -700,9 +720,8 @@ class InteractionModel : public InteractionModelReports,
700720
void OnError(const chip::app::WriteClient * client, CHIP_ERROR error) override;
701721
void OnDone(chip::app::WriteClient * client) override;
702722

703-
/////////// CommandSender Callback Interface /////////
704-
void OnResponse(chip::app::CommandSender * client, const chip::app::ConcreteCommandPath & path,
705-
const chip::app::StatusIB & status, chip::TLV::TLVReader * data) override;
706-
void OnError(const chip::app::CommandSender * client, CHIP_ERROR error) override;
723+
/////////// CommandSender ExtendableCallback Interface /////////
724+
void OnResponse(chip::app::CommandSender * client, const chip::app::CommandSender::ResponseData & responseData) override;
725+
void OnError(const chip::app::CommandSender * client, const chip::app::CommandSender::ErrorData & errorData) override;
707726
void OnDone(chip::app::CommandSender * client) override;
708727
};

0 commit comments

Comments
 (0)