Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RemoveAllFabrics command to OpCreds cluster #6513

Merged
merged 6 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@
"enabled": 0,
"commands": [
{
"name": "GetFabricId",
"name": "SetFabric",
"code": 0,
"mfgCode": null,
"source": "client",
Expand All @@ -1638,6 +1638,14 @@
"source": "client",
"incoming": 1,
"outgoing": 1
},
{
"name": "RemoveAllFabrics",
"code": 11,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 1
}
],
"attributes": [
Expand Down Expand Up @@ -1667,7 +1675,7 @@
"enabled": 1,
"commands": [
{
"name": "GetFabricIdResponse",
"name": "SetFabricResponse",
"code": 1,
"mfgCode": null,
"source": "server",
Expand Down Expand Up @@ -8446,7 +8454,7 @@
"outgoing": 1
},
{
"name": "TestSpecific",
"name": "TestNotHandled",
"code": 1,
"mfgCode": null,
"source": "client",
Expand Down Expand Up @@ -11878,4 +11886,4 @@
}
],
"log": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7023,6 +7023,12 @@ void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, En
{
switch (aCommandId)
{
case ZCL_REMOVE_ALL_FABRICS_COMMAND_ID: {

// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
emberAfOperationalCredentialsClusterRemoveAllFabricsCallback(apCommandObj);
break;
}
case ZCL_REMOVE_FABRIC_COMMAND_ID: {
// We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV
// When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,10 @@ EmberAfStatus emberAfOperationalCredentialsClusterServerCommandParse(EmberAfClus
{
switch (cmd->commandId)
{
case ZCL_REMOVE_ALL_FABRICS_COMMAND_ID: {
wasHandled = emberAfOperationalCredentialsClusterRemoveAllFabricsCallback(nullptr);
break;
}
case ZCL_REMOVE_FABRIC_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::FabricId FabricId;
Expand Down
6 changes: 6 additions & 0 deletions examples/all-clusters-app/all-clusters-common/gen/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,12 @@ bool emberAfOnOffClusterOnCallback(chip::app::Command * commandObj);

bool emberAfOnOffClusterToggleCallback(chip::app::Command * commandObj);

/**
* @brief Operational Credentials Cluster RemoveAllFabrics Command callback
*/

bool emberAfOperationalCredentialsClusterRemoveAllFabricsCallback(chip::app::Command * commandObj);

/**
* @brief Operational Credentials Cluster RemoveFabric Command callback
* @param fabricId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,15 @@
\
ZCL_REMOVE_FABRIC_COMMAND_ID, "uuu", FabricId, NodeId, VendorId);

/** @brief Command description for RemoveAllFabrics
*
* Command: RemoveAllFabrics
*/
#define emberAfFillCommandOperational \
CredentialsClusterRemoveAllFabrics() emberAfFillExternalBuffer(mask, \
\
ZCL_REMOVE_ALL_FABRICS_COMMAND_ID, "", );

/** @brief Command description for LockDoor
*
* Command: LockDoor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
#define ZCL_SET_FABRIC_RESPONSE_COMMAND_ID (0x01)
#define ZCL_UPDATE_FABRIC_LABEL_COMMAND_ID (0x09)
#define ZCL_REMOVE_FABRIC_COMMAND_ID (0x0A)
#define ZCL_REMOVE_ALL_FABRICS_COMMAND_ID (0x0B)

// Commands for cluster: Door Lock
#define ZCL_LOCK_DOOR_COMMAND_ID (0x00)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@

// Array of EmberAfCommandMetadata structs.
#define ZAP_COMMAND_MASK(mask) COMMAND_MASK_##mask
#define EMBER_AF_GENERATED_COMMAND_COUNT (140)
#define EMBER_AF_GENERATED_COMMAND_COUNT (141)
#define GENERATED_COMMANDS \
{ \
\
Expand Down Expand Up @@ -1306,6 +1306,7 @@
{ 0x003E, 0x01, ZAP_COMMAND_MASK(INCOMING_CLIENT) }, /* SetFabricResponse */ \
{ 0x003E, 0x09, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* UpdateFabricLabel */ \
{ 0x003E, 0x0A, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* RemoveFabric */ \
{ 0x003E, 0x0B, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* RemoveAllFabrics */ \
\
/* Endpoint: 0, Cluster: Test Cluster (server) */ \
{ 0x050F, 0x00, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* Test */ \
Expand Down
9 changes: 9 additions & 0 deletions examples/bridge-app/bridge-common/gen/client-command-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,15 @@
\
ZCL_REMOVE_FABRIC_COMMAND_ID, "uuu", FabricId, NodeId, VendorId);

/** @brief Command description for RemoveAllFabrics
*
* Command: RemoveAllFabrics
*/
#define emberAfFillCommandOperational \
CredentialsClusterRemoveAllFabrics() emberAfFillExternalBuffer(mask, \
\
ZCL_REMOVE_ALL_FABRICS_COMMAND_ID, "", );

/** @brief Command description for LockDoor
*
* Command: LockDoor
Expand Down
1 change: 1 addition & 0 deletions examples/bridge-app/bridge-common/gen/command-id.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
#define ZCL_SET_FABRIC_RESPONSE_COMMAND_ID (0x01)
#define ZCL_UPDATE_FABRIC_LABEL_COMMAND_ID (0x09)
#define ZCL_REMOVE_FABRIC_COMMAND_ID (0x0A)
#define ZCL_REMOVE_ALL_FABRICS_COMMAND_ID (0x0B)

// Commands for cluster: Door Lock
#define ZCL_LOCK_DOOR_COMMAND_ID (0x00)
Expand Down
14 changes: 11 additions & 3 deletions examples/chip-tool/chip-tool.zap
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@
"enabled": 1,
"commands": [
{
"name": "GetFabricId",
"name": "SetFabric",
"code": 0,
"mfgCode": null,
"source": "client",
Expand All @@ -1638,6 +1638,14 @@
"source": "client",
"incoming": 1,
"outgoing": 1
},
{
"name": "RemoveAllFabrics",
"code": 11,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 1
}
],
"attributes": [
Expand Down Expand Up @@ -1667,7 +1675,7 @@
"enabled": 0,
"commands": [
{
"name": "GetFabricIdResponse",
"name": "SetFabricResponse",
"code": 1,
"mfgCode": null,
"source": "server",
Expand Down Expand Up @@ -6033,4 +6041,4 @@
}
],
"log": []
}
}
37 changes: 34 additions & 3 deletions examples/chip-tool/commands/clusters/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -10498,6 +10498,7 @@ class ReadOnOffClusterRevision : public ModelCommand
| Cluster OperationalCredentials | 0x003E |
|------------------------------------------------------------------------------|
| Commands: | |
| * RemoveAllFabrics | 0x0B |
| * RemoveFabric | 0x0A |
| * SetFabric | 0x00 |
| * UpdateFabricLabel | 0x09 |
Expand All @@ -10507,6 +10508,35 @@ class ReadOnOffClusterRevision : public ModelCommand
| * ClusterRevision | 0xFFFD |
\*----------------------------------------------------------------------------*/

/*
* Command RemoveAllFabrics
*/
class OperationalCredentialsRemoveAllFabrics : public ModelCommand
{
public:
OperationalCredentialsRemoveAllFabrics() : ModelCommand("remove-all-fabrics") { ModelCommand::AddArguments(); }
~OperationalCredentialsRemoveAllFabrics()
{
delete onSuccessCallback;
delete onFailureCallback;
}

CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster (0x003E) command (0x0B) on endpoint %" PRIu16, endpointId);

chip::Controller::OperationalCredentialsCluster cluster;
cluster.Associate(device, endpointId);
return cluster.RemoveAllFabrics(onSuccessCallback->Cancel(), onFailureCallback->Cancel());
}

private:
chip::Callback::Callback<DefaultSuccessCallback> * onSuccessCallback =
new chip::Callback::Callback<DefaultSuccessCallback>(OnDefaultSuccessResponse, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback =
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};

/*
* Command RemoveFabric
*/
Expand Down Expand Up @@ -14923,9 +14953,10 @@ void registerClusterOperationalCredentials(Commands & commands)
const char * clusterName = "OperationalCredentials";

commands_list clusterCommands = {
make_unique<OperationalCredentialsRemoveFabric>(), make_unique<OperationalCredentialsSetFabric>(),
make_unique<OperationalCredentialsUpdateFabricLabel>(), make_unique<DiscoverOperationalCredentialsAttributes>(),
make_unique<ReadOperationalCredentialsFabricsList>(), make_unique<ReadOperationalCredentialsClusterRevision>(),
make_unique<OperationalCredentialsRemoveAllFabrics>(), make_unique<OperationalCredentialsRemoveFabric>(),
make_unique<OperationalCredentialsSetFabric>(), make_unique<OperationalCredentialsUpdateFabricLabel>(),
make_unique<DiscoverOperationalCredentialsAttributes>(), make_unique<ReadOperationalCredentialsFabricsList>(),
make_unique<ReadOperationalCredentialsClusterRevision>(),
};

commands.Register(clusterName, clusterCommands);
Expand Down
26 changes: 26 additions & 0 deletions examples/chip-tool/gen/CHIPClusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4511,6 +4511,32 @@ CHIP_ERROR OnOffCluster::ReadAttributeClusterRevision(Callback::Cancelable * onS
}

// OperationalCredentials Cluster Commands
CHIP_ERROR OperationalCredentialsCluster::RemoveAllFabrics(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
#if CHIP_ENABLE_INTERACTION_MODEL
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
(void) onSuccessCallback;
(void) onFailureCallback;

app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kRemoveAllFabricsCommandId,
(chip::app::CommandPathFlags::kEndpointIdValid) };
app::Command * ZCLcommand = mDevice->GetCommandSender();

ReturnErrorOnFailure(ZCLcommand->PrepareCommand(&cmdParams));

// Command takes no arguments.

ReturnErrorOnFailure(ZCLcommand->FinishCommand());

return mDevice->SendCommands();
#else
uint8_t seqNum = mDevice->GetNextSequenceNumber();
System::PacketBufferHandle encodedCommand = encodeOperationalCredentialsClusterRemoveAllFabricsCommand(seqNum, mEndpoint);
return SendCommand(seqNum, std::move(encodedCommand), onSuccessCallback, onFailureCallback);
#endif
}

CHIP_ERROR OperationalCredentialsCluster::RemoveFabric(Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, chip::FabricId fabricId,
chip::NodeId nodeId, uint16_t vendorId)
Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/gen/CHIPClusters.h
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ class DLL_EXPORT OperationalCredentialsCluster : public ClusterBase
~OperationalCredentialsCluster() {}

// Cluster Commands
CHIP_ERROR RemoveAllFabrics(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback);
CHIP_ERROR RemoveFabric(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback,
chip::FabricId fabricId, chip::NodeId nodeId, uint16_t vendorId);
CHIP_ERROR SetFabric(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback, uint16_t vendorId);
Expand All @@ -829,6 +830,7 @@ class DLL_EXPORT OperationalCredentialsCluster : public ClusterBase
CHIP_ERROR ReadAttributeClusterRevision(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback);

private:
static constexpr CommandId kRemoveAllFabricsCommandId = 0x0B;
static constexpr CommandId kRemoveFabricCommandId = 0x0A;
static constexpr CommandId kSetFabricCommandId = 0x00;
static constexpr CommandId kUpdateFabricLabelCommandId = 0x09;
Expand Down
1 change: 1 addition & 0 deletions examples/chip-tool/gen/CHIPClustersObjc.h
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface CHIPOperationalCredentials : CHIPCluster

- (void)removeAllFabrics:(ResponseHandler)responseHandler;
- (void)removeFabric:(uint64_t)fabricId
nodeId:(uint64_t)nodeId
vendorId:(uint16_t)vendorId
Expand Down
26 changes: 26 additions & 0 deletions examples/chip-tool/gen/CHIPClustersObjc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10180,6 +10180,32 @@ @implementation CHIPOperationalCredentials
return &_cppCluster;
}

- (void)removeAllFabrics:(ResponseHandler)responseHandler
{
CHIPDefaultSuccessCallbackBridge * onSuccess = new CHIPDefaultSuccessCallbackBridge(responseHandler, [self callbackQueue]);
if (!onSuccess) {
responseHandler([CHIPError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE], nil);
return;
}

CHIPDefaultFailureCallbackBridge * onFailure = new CHIPDefaultFailureCallbackBridge(responseHandler, [self callbackQueue]);
if (!onFailure) {
delete onSuccess;
responseHandler([CHIPError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE], nil);
return;
}

__block CHIP_ERROR err;
dispatch_sync([self chipWorkQueue], ^{
err = self.cppCluster.RemoveAllFabrics(onSuccess->Cancel(), onFailure->Cancel());
});

if (err != CHIP_NO_ERROR) {
delete onSuccess;
delete onFailure;
responseHandler([CHIPError errorForCHIPErrorCode:err], nil);
}
}
- (void)removeFabric:(uint64_t)fabricId
nodeId:(uint64_t)nodeId
vendorId:(uint16_t)vendorId
Expand Down
9 changes: 9 additions & 0 deletions examples/chip-tool/gen/client-command-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,15 @@
\
ZCL_REMOVE_FABRIC_COMMAND_ID, "uuu", FabricId, NodeId, VendorId);

/** @brief Command description for RemoveAllFabrics
*
* Command: RemoveAllFabrics
*/
#define emberAfFillCommandOperational \
CredentialsClusterRemoveAllFabrics() emberAfFillExternalBuffer(mask, \
\
ZCL_REMOVE_ALL_FABRICS_COMMAND_ID, "", );

/** @brief Command description for LockDoor
*
* Command: LockDoor
Expand Down
1 change: 1 addition & 0 deletions examples/chip-tool/gen/command-id.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
#define ZCL_SET_FABRIC_RESPONSE_COMMAND_ID (0x01)
#define ZCL_UPDATE_FABRIC_LABEL_COMMAND_ID (0x09)
#define ZCL_REMOVE_FABRIC_COMMAND_ID (0x0A)
#define ZCL_REMOVE_ALL_FABRICS_COMMAND_ID (0x0B)

// Commands for cluster: Door Lock
#define ZCL_LOCK_DOOR_COMMAND_ID (0x00)
Expand Down
3 changes: 2 additions & 1 deletion examples/chip-tool/gen/endpoint_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@

// Array of EmberAfCommandMetadata structs.
#define ZAP_COMMAND_MASK(mask) COMMAND_MASK_##mask
#define EMBER_AF_GENERATED_COMMAND_COUNT (191)
#define EMBER_AF_GENERATED_COMMAND_COUNT (192)
#define GENERATED_COMMANDS \
{ \
\
Expand Down Expand Up @@ -410,6 +410,7 @@
{ 0x003E, 0x01, ZAP_COMMAND_MASK(INCOMING_CLIENT) }, /* SetFabricResponse */ \
{ 0x003E, 0x09, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* UpdateFabricLabel */ \
{ 0x003E, 0x0A, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* RemoveFabric */ \
{ 0x003E, 0x0B, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* RemoveAllFabrics */ \
\
/* Endpoint: 1, Cluster: Door Lock (client) */ \
{ 0x0101, 0x00, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* LockDoor */ \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,15 @@
\
ZCL_REMOVE_FABRIC_COMMAND_ID, "uuu", FabricId, NodeId, VendorId);

/** @brief Command description for RemoveAllFabrics
*
* Command: RemoveAllFabrics
*/
#define emberAfFillCommandOperational \
CredentialsClusterRemoveAllFabrics() emberAfFillExternalBuffer(mask, \
\
ZCL_REMOVE_ALL_FABRICS_COMMAND_ID, "", );

/** @brief Command description for LockDoor
*
* Command: LockDoor
Expand Down
Loading