blob: 6fd9a22f16e5776c253ede623f599f0fbfe2c1a1 [file] [log] [blame]
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// THIS FILE IS GENERATED BY ZAP
#include "CHIPClusters.h"
#include <app-common/zap-generated/ids/Attributes.h>
#include <zap-generated/CHIPClientCallbacks.h>
namespace chip {
using namespace app::Clusters;
using namespace System;
using namespace Encoding::LittleEndian;
namespace Controller {
// TODO(#4502): onCompletion is not used by IM for now.
// TODO(#4503): length should be passed to commands when byte string is in argument list.
// TODO(#4503): Commands should take group id as an argument.
// GeneralCommissioning Cluster Commands
CHIP_ERROR GeneralCommissioningCluster::ArmFailSafe(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint16_t expiryLengthSeconds,
uint64_t breadcrumb, uint32_t timeoutMs)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, GeneralCommissioning::Commands::ArmFailSafe::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// expiryLengthSeconds: int16u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), expiryLengthSeconds));
// breadcrumb: int64u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), breadcrumb));
// timeoutMs: int32u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), timeoutMs));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
CHIP_ERROR GeneralCommissioningCluster::CommissioningComplete(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId,
GeneralCommissioning::Commands::CommissioningComplete::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
// Command takes no arguments.
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
CHIP_ERROR GeneralCommissioningCluster::SetRegulatoryConfig(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint8_t location,
chip::CharSpan countryCode, uint64_t breadcrumb, uint32_t timeoutMs)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId,
GeneralCommissioning::Commands::SetRegulatoryConfig::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// location: regulatoryLocationType
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), location));
// countryCode: charString
SuccessOrExit(err = writer->PutString(TLV::ContextTag(argSeqNumber++), countryCode));
// breadcrumb: int64u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), breadcrumb));
// timeoutMs: int32u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), timeoutMs));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
// GeneralCommissioning Cluster Attributes
CHIP_ERROR GeneralCommissioningCluster::ReadAttributeBreadcrumb(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x00000000;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int64uAttributeCallback>);
}
CHIP_ERROR GeneralCommissioningCluster::WriteAttributeBreadcrumb(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint64_t value)
{
app::WriteClientHandle handle;
ReturnErrorOnFailure(
app::InteractionModelEngine::GetInstance()->NewWriteClient(handle, mDevice->GetInteractionModelDelegate()));
ReturnErrorOnFailure(handle.EncodeAttributeWritePayload(
chip::app::AttributePathParams(mEndpoint, mClusterId, GeneralCommissioning::Attributes::Breadcrumb::Id), value));
return mDevice->SendWriteAttributeRequest(std::move(handle), onSuccessCallback, onFailureCallback);
}
CHIP_ERROR GeneralCommissioningCluster::SubscribeAttributeBreadcrumb(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint16_t minInterval,
uint16_t maxInterval)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = GeneralCommissioning::Attributes::Breadcrumb::Id;
return mDevice->SendSubscribeAttributeRequest(attributePath, minInterval, maxInterval, onSuccessCallback, onFailureCallback);
}
CHIP_ERROR GeneralCommissioningCluster::ReportAttributeBreadcrumb(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(GeneralCommissioning::Attributes::Breadcrumb::Id, onReportCallback,
BasicAttributeFilter<Int64uAttributeCallback>);
}
CHIP_ERROR GeneralCommissioningCluster::ReadAttributeBasicCommissioningInfoList(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x00000001;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
GeneralCommissioningClusterBasicCommissioningInfoListListAttributeFilter);
}
CHIP_ERROR GeneralCommissioningCluster::ReadAttributeRegulatoryConfig(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x00000002;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR GeneralCommissioningCluster::ReadAttributeLocationCapability(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x00000003;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR GeneralCommissioningCluster::ReadAttributeFeatureMap(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x0000FFFC;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int32uAttributeCallback>);
}
CHIP_ERROR GeneralCommissioningCluster::ReadAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x0000FFFD;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
CHIP_ERROR GeneralCommissioningCluster::SubscribeAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback,
uint16_t minInterval, uint16_t maxInterval)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = Globals::Attributes::ClusterRevision::Id;
return mDevice->SendSubscribeAttributeRequest(attributePath, minInterval, maxInterval, onSuccessCallback, onFailureCallback);
}
CHIP_ERROR GeneralCommissioningCluster::ReportAttributeClusterRevision(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(Globals::Attributes::ClusterRevision::Id, onReportCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
// NetworkCommissioning Cluster Commands
CHIP_ERROR NetworkCommissioningCluster::DisableNetwork(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, chip::ByteSpan networkID,
uint64_t breadcrumb, uint32_t timeoutMs)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId,
NetworkCommissioning::Commands::DisableNetwork::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// networkID: octetString
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), networkID));
// breadcrumb: int64u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), breadcrumb));
// timeoutMs: int32u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), timeoutMs));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
CHIP_ERROR NetworkCommissioningCluster::EnableNetwork(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, chip::ByteSpan networkID,
uint64_t breadcrumb, uint32_t timeoutMs)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, NetworkCommissioning::Commands::EnableNetwork::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// networkID: octetString
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), networkID));
// breadcrumb: int64u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), breadcrumb));
// timeoutMs: int32u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), timeoutMs));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
CHIP_ERROR NetworkCommissioningCluster::RemoveNetwork(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, chip::ByteSpan networkID,
uint64_t breadcrumb, uint32_t timeoutMs)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, NetworkCommissioning::Commands::RemoveNetwork::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// networkID: octetString
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), networkID));
// breadcrumb: int64u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), breadcrumb));
// timeoutMs: int32u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), timeoutMs));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
CHIP_ERROR NetworkCommissioningCluster::ScanNetworks(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, chip::ByteSpan ssid,
uint64_t breadcrumb, uint32_t timeoutMs)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, NetworkCommissioning::Commands::ScanNetworks::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// ssid: octetString
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), ssid));
// breadcrumb: int64u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), breadcrumb));
// timeoutMs: int32u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), timeoutMs));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
// NetworkCommissioning Cluster Attributes
CHIP_ERROR NetworkCommissioningCluster::ReadAttributeFeatureMap(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x0000FFFC;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int32uAttributeCallback>);
}
CHIP_ERROR NetworkCommissioningCluster::ReadAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x0000FFFD;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
CHIP_ERROR NetworkCommissioningCluster::SubscribeAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback,
uint16_t minInterval, uint16_t maxInterval)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = Globals::Attributes::ClusterRevision::Id;
return mDevice->SendSubscribeAttributeRequest(attributePath, minInterval, maxInterval, onSuccessCallback, onFailureCallback);
}
CHIP_ERROR NetworkCommissioningCluster::ReportAttributeClusterRevision(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(Globals::Attributes::ClusterRevision::Id, onReportCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
// OperationalCredentials Cluster Commands
CHIP_ERROR OperationalCredentialsCluster::AddNOC(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback,
chip::ByteSpan NOCValue, chip::ByteSpan ICACValue, chip::ByteSpan IPKValue,
chip::NodeId caseAdminNode, uint16_t adminVendorId)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, OperationalCredentials::Commands::AddNOC::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// NOCValue: octetString
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), NOCValue));
// ICACValue: octetString
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), ICACValue));
// IPKValue: octetString
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), IPKValue));
// caseAdminNode: nodeId
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), caseAdminNode));
// adminVendorId: int16u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), adminVendorId));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
CHIP_ERROR OperationalCredentialsCluster::AddTrustedRootCertificate(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback,
chip::ByteSpan rootCertificate)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId,
OperationalCredentials::Commands::AddTrustedRootCertificate::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// rootCertificate: octetString
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), rootCertificate));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
CHIP_ERROR OperationalCredentialsCluster::AttestationRequest(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback,
chip::ByteSpan attestationNonce)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId,
OperationalCredentials::Commands::AttestationRequest::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// attestationNonce: octetString
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), attestationNonce));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
CHIP_ERROR OperationalCredentialsCluster::CertificateChainRequest(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint8_t certificateType)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId,
OperationalCredentials::Commands::CertificateChainRequest::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// certificateType: int8u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), certificateType));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
CHIP_ERROR OperationalCredentialsCluster::OpCSRRequest(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, chip::ByteSpan CSRNonce)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId,
OperationalCredentials::Commands::OpCSRRequest::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// CSRNonce: octetString
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), CSRNonce));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
CHIP_ERROR OperationalCredentialsCluster::RemoveFabric(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, uint8_t fabricIndex)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId,
OperationalCredentials::Commands::RemoveFabric::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// fabricIndex: int8u
SuccessOrExit(err = writer->Put(TLV::ContextTag(argSeqNumber++), fabricIndex));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
CHIP_ERROR OperationalCredentialsCluster::UpdateFabricLabel(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, chip::CharSpan label)
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVWriter * writer = nullptr;
uint8_t argSeqNumber = 0;
// Used when encoding non-empty command. Suppress error message when encoding empty commands.
(void) writer;
(void) argSeqNumber;
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId,
OperationalCredentials::Commands::UpdateFabricLabel::Id,
(app::CommandPathFlags::kEndpointIdValid) };
CommandSenderHandle sender(
Platform::New<app::CommandSender>(mDevice->GetInteractionModelDelegate(), mDevice->GetExchangeManager()));
VerifyOrReturnError(sender != nullptr, CHIP_ERROR_NO_MEMORY);
SuccessOrExit(err = sender->PrepareCommand(cmdParams));
VerifyOrExit((writer = sender->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
// label: charString
SuccessOrExit(err = writer->PutString(TLV::ContextTag(argSeqNumber++), label));
SuccessOrExit(err = sender->FinishCommand());
// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(sender.get(), onSuccessCallback, onFailureCallback);
SuccessOrExit(err = mDevice->SendCommands(sender.get()));
// We have successfully sent the command, and the callback handler will be responsible to free the object, release the object
// now.
sender.release();
exit:
return err;
}
// OperationalCredentials Cluster Attributes
CHIP_ERROR OperationalCredentialsCluster::ReadAttributeFabricsList(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x00000001;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
OperationalCredentialsClusterFabricsListListAttributeFilter);
}
CHIP_ERROR OperationalCredentialsCluster::ReadAttributeSupportedFabrics(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x00000002;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR OperationalCredentialsCluster::SubscribeAttributeSupportedFabrics(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback,
uint16_t minInterval, uint16_t maxInterval)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = OperationalCredentials::Attributes::SupportedFabrics::Id;
return mDevice->SendSubscribeAttributeRequest(attributePath, minInterval, maxInterval, onSuccessCallback, onFailureCallback);
}
CHIP_ERROR OperationalCredentialsCluster::ReportAttributeSupportedFabrics(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(OperationalCredentials::Attributes::SupportedFabrics::Id, onReportCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR OperationalCredentialsCluster::ReadAttributeCommissionedFabrics(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x00000003;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR OperationalCredentialsCluster::SubscribeAttributeCommissionedFabrics(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback,
uint16_t minInterval, uint16_t maxInterval)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = OperationalCredentials::Attributes::CommissionedFabrics::Id;
return mDevice->SendSubscribeAttributeRequest(attributePath, minInterval, maxInterval, onSuccessCallback, onFailureCallback);
}
CHIP_ERROR OperationalCredentialsCluster::ReportAttributeCommissionedFabrics(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(OperationalCredentials::Attributes::CommissionedFabrics::Id, onReportCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR OperationalCredentialsCluster::ReadAttributeTrustedRootCertificates(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x00000004;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
OperationalCredentialsClusterTrustedRootCertificatesListAttributeFilter);
}
CHIP_ERROR OperationalCredentialsCluster::ReadAttributeCurrentFabricIndex(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x00000005;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR OperationalCredentialsCluster::SubscribeAttributeCurrentFabricIndex(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback,
uint16_t minInterval, uint16_t maxInterval)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = OperationalCredentials::Attributes::CurrentFabricIndex::Id;
return mDevice->SendSubscribeAttributeRequest(attributePath, minInterval, maxInterval, onSuccessCallback, onFailureCallback);
}
CHIP_ERROR OperationalCredentialsCluster::ReportAttributeCurrentFabricIndex(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(OperationalCredentials::Attributes::CurrentFabricIndex::Id, onReportCallback,
BasicAttributeFilter<Int8uAttributeCallback>);
}
CHIP_ERROR OperationalCredentialsCluster::ReadAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = 0x0000FFFD;
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
CHIP_ERROR OperationalCredentialsCluster::SubscribeAttributeClusterRevision(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback,
uint16_t minInterval, uint16_t maxInterval)
{
chip::app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = Globals::Attributes::ClusterRevision::Id;
return mDevice->SendSubscribeAttributeRequest(attributePath, minInterval, maxInterval, onSuccessCallback, onFailureCallback);
}
CHIP_ERROR OperationalCredentialsCluster::ReportAttributeClusterRevision(Callback::Cancelable * onReportCallback)
{
return RequestAttributeReporting(Globals::Attributes::ClusterRevision::Id, onReportCallback,
BasicAttributeFilter<Int16uAttributeCallback>);
}
} // namespace Controller
} // namespace chip