diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index 8f3b7d2ba614a7..db87f396faa104 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -1616,7 +1616,7 @@ "enabled": 0, "commands": [ { - "name": "GetFabricId", + "name": "SetFabric", "code": 0, "mfgCode": null, "source": "client", @@ -1638,6 +1638,14 @@ "source": "client", "incoming": 1, "outgoing": 1 + }, + { + "name": "RemoveAllFabrics", + "code": 11, + "mfgCode": null, + "source": "client", + "incoming": 1, + "outgoing": 1 } ], "attributes": [ @@ -1667,7 +1675,7 @@ "enabled": 1, "commands": [ { - "name": "GetFabricIdResponse", + "name": "SetFabricResponse", "code": 1, "mfgCode": null, "source": "server", @@ -8446,7 +8454,7 @@ "outgoing": 1 }, { - "name": "TestSpecific", + "name": "TestNotHandled", "code": 1, "mfgCode": null, "source": "client", @@ -11878,4 +11886,4 @@ } ], "log": [] -} +} \ No newline at end of file diff --git a/examples/all-clusters-app/all-clusters-common/gen/IMClusterCommandHandler.cpp b/examples/all-clusters-app/all-clusters-common/gen/IMClusterCommandHandler.cpp index c4b9adcd04513b..d4ca60f1c9d5d3 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/IMClusterCommandHandler.cpp +++ b/examples/all-clusters-app/all-clusters-common/gen/IMClusterCommandHandler.cpp @@ -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. diff --git a/examples/all-clusters-app/all-clusters-common/gen/call-command-handler.cpp b/examples/all-clusters-app/all-clusters-common/gen/call-command-handler.cpp index 5aeb7e7274b8fe..d680f1183e8d5c 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/call-command-handler.cpp +++ b/examples/all-clusters-app/all-clusters-common/gen/call-command-handler.cpp @@ -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; diff --git a/examples/all-clusters-app/all-clusters-common/gen/callback.h b/examples/all-clusters-app/all-clusters-common/gen/callback.h index 98929ba3fcbf74..bc694f65f61bef 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/callback.h +++ b/examples/all-clusters-app/all-clusters-common/gen/callback.h @@ -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 diff --git a/examples/all-clusters-app/all-clusters-common/gen/client-command-macro.h b/examples/all-clusters-app/all-clusters-common/gen/client-command-macro.h index 1ac6d9550498d1..b12eea3dbc3a23 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/client-command-macro.h +++ b/examples/all-clusters-app/all-clusters-common/gen/client-command-macro.h @@ -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 diff --git a/examples/all-clusters-app/all-clusters-common/gen/command-id.h b/examples/all-clusters-app/all-clusters-common/gen/command-id.h index cbda27333416da..00dc797c84a98f 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/command-id.h +++ b/examples/all-clusters-app/all-clusters-common/gen/command-id.h @@ -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) diff --git a/examples/all-clusters-app/all-clusters-common/gen/endpoint_config.h b/examples/all-clusters-app/all-clusters-common/gen/endpoint_config.h index 8b9ac541cb8b32..f2249594fdcd06 100644 --- a/examples/all-clusters-app/all-clusters-common/gen/endpoint_config.h +++ b/examples/all-clusters-app/all-clusters-common/gen/endpoint_config.h @@ -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 \ { \ \ @@ -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 */ \ diff --git a/examples/bridge-app/bridge-common/gen/client-command-macro.h b/examples/bridge-app/bridge-common/gen/client-command-macro.h index 1ac6d9550498d1..b12eea3dbc3a23 100644 --- a/examples/bridge-app/bridge-common/gen/client-command-macro.h +++ b/examples/bridge-app/bridge-common/gen/client-command-macro.h @@ -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 diff --git a/examples/bridge-app/bridge-common/gen/command-id.h b/examples/bridge-app/bridge-common/gen/command-id.h index cbda27333416da..00dc797c84a98f 100644 --- a/examples/bridge-app/bridge-common/gen/command-id.h +++ b/examples/bridge-app/bridge-common/gen/command-id.h @@ -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) diff --git a/examples/chip-tool/chip-tool.zap b/examples/chip-tool/chip-tool.zap index db6a262eca390d..375022f725859f 100644 --- a/examples/chip-tool/chip-tool.zap +++ b/examples/chip-tool/chip-tool.zap @@ -1616,7 +1616,7 @@ "enabled": 1, "commands": [ { - "name": "GetFabricId", + "name": "SetFabric", "code": 0, "mfgCode": null, "source": "client", @@ -1638,6 +1638,14 @@ "source": "client", "incoming": 1, "outgoing": 1 + }, + { + "name": "RemoveAllFabrics", + "code": 11, + "mfgCode": null, + "source": "client", + "incoming": 1, + "outgoing": 1 } ], "attributes": [ @@ -1667,7 +1675,7 @@ "enabled": 0, "commands": [ { - "name": "GetFabricIdResponse", + "name": "SetFabricResponse", "code": 1, "mfgCode": null, "source": "server", @@ -6033,4 +6041,4 @@ } ], "log": [] -} +} \ No newline at end of file diff --git a/examples/chip-tool/commands/clusters/Commands.h b/examples/chip-tool/commands/clusters/Commands.h index 4491175bbc6fe1..0ee7d276847495 100644 --- a/examples/chip-tool/commands/clusters/Commands.h +++ b/examples/chip-tool/commands/clusters/Commands.h @@ -10498,6 +10498,7 @@ class ReadOnOffClusterRevision : public ModelCommand | Cluster OperationalCredentials | 0x003E | |------------------------------------------------------------------------------| | Commands: | | +| * RemoveAllFabrics | 0x0B | | * RemoveFabric | 0x0A | | * SetFabric | 0x00 | | * UpdateFabricLabel | 0x09 | @@ -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 * onSuccessCallback = + new chip::Callback::Callback(OnDefaultSuccessResponse, this); + chip::Callback::Callback * onFailureCallback = + new chip::Callback::Callback(OnDefaultFailureResponse, this); +}; + /* * Command RemoveFabric */ @@ -14923,9 +14953,10 @@ void registerClusterOperationalCredentials(Commands & commands) const char * clusterName = "OperationalCredentials"; commands_list clusterCommands = { - make_unique(), make_unique(), - make_unique(), make_unique(), - make_unique(), make_unique(), + make_unique(), make_unique(), + make_unique(), make_unique(), + make_unique(), make_unique(), + make_unique(), }; commands.Register(clusterName, clusterCommands); diff --git a/examples/chip-tool/gen/CHIPClusters.cpp b/examples/chip-tool/gen/CHIPClusters.cpp index 9b3266936b1045..c3b051266383b9 100644 --- a/examples/chip-tool/gen/CHIPClusters.cpp +++ b/examples/chip-tool/gen/CHIPClusters.cpp @@ -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) diff --git a/examples/chip-tool/gen/CHIPClusters.h b/examples/chip-tool/gen/CHIPClusters.h index 0b6700348d3678..8d2117bdd1ef71 100644 --- a/examples/chip-tool/gen/CHIPClusters.h +++ b/examples/chip-tool/gen/CHIPClusters.h @@ -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); @@ -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; diff --git a/examples/chip-tool/gen/CHIPClustersObjc.h b/examples/chip-tool/gen/CHIPClustersObjc.h index 50045a1bd724f4..0d6d737bf4361f 100644 --- a/examples/chip-tool/gen/CHIPClustersObjc.h +++ b/examples/chip-tool/gen/CHIPClustersObjc.h @@ -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 diff --git a/examples/chip-tool/gen/CHIPClustersObjc.mm b/examples/chip-tool/gen/CHIPClustersObjc.mm index 8b236ee878ae9f..60f04472de669b 100644 --- a/examples/chip-tool/gen/CHIPClustersObjc.mm +++ b/examples/chip-tool/gen/CHIPClustersObjc.mm @@ -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 diff --git a/examples/chip-tool/gen/client-command-macro.h b/examples/chip-tool/gen/client-command-macro.h index 1ac6d9550498d1..b12eea3dbc3a23 100644 --- a/examples/chip-tool/gen/client-command-macro.h +++ b/examples/chip-tool/gen/client-command-macro.h @@ -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 diff --git a/examples/chip-tool/gen/command-id.h b/examples/chip-tool/gen/command-id.h index cbda27333416da..00dc797c84a98f 100644 --- a/examples/chip-tool/gen/command-id.h +++ b/examples/chip-tool/gen/command-id.h @@ -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) diff --git a/examples/chip-tool/gen/endpoint_config.h b/examples/chip-tool/gen/endpoint_config.h index 9edc8106c64547..584608dba0fe68 100644 --- a/examples/chip-tool/gen/endpoint_config.h +++ b/examples/chip-tool/gen/endpoint_config.h @@ -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 \ { \ \ @@ -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 */ \ diff --git a/examples/lighting-app/lighting-common/gen/client-command-macro.h b/examples/lighting-app/lighting-common/gen/client-command-macro.h index 1ac6d9550498d1..b12eea3dbc3a23 100644 --- a/examples/lighting-app/lighting-common/gen/client-command-macro.h +++ b/examples/lighting-app/lighting-common/gen/client-command-macro.h @@ -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 diff --git a/examples/lighting-app/lighting-common/gen/command-id.h b/examples/lighting-app/lighting-common/gen/command-id.h index cbda27333416da..00dc797c84a98f 100644 --- a/examples/lighting-app/lighting-common/gen/command-id.h +++ b/examples/lighting-app/lighting-common/gen/command-id.h @@ -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) diff --git a/examples/lock-app/lock-common/gen/client-command-macro.h b/examples/lock-app/lock-common/gen/client-command-macro.h index 1ac6d9550498d1..b12eea3dbc3a23 100644 --- a/examples/lock-app/lock-common/gen/client-command-macro.h +++ b/examples/lock-app/lock-common/gen/client-command-macro.h @@ -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 diff --git a/examples/lock-app/lock-common/gen/command-id.h b/examples/lock-app/lock-common/gen/command-id.h index cbda27333416da..00dc797c84a98f 100644 --- a/examples/lock-app/lock-common/gen/command-id.h +++ b/examples/lock-app/lock-common/gen/command-id.h @@ -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) diff --git a/examples/temperature-measurement-app/esp32/main/gen/client-command-macro.h b/examples/temperature-measurement-app/esp32/main/gen/client-command-macro.h index 1ac6d9550498d1..b12eea3dbc3a23 100644 --- a/examples/temperature-measurement-app/esp32/main/gen/client-command-macro.h +++ b/examples/temperature-measurement-app/esp32/main/gen/client-command-macro.h @@ -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 diff --git a/examples/temperature-measurement-app/esp32/main/gen/command-id.h b/examples/temperature-measurement-app/esp32/main/gen/command-id.h index cbda27333416da..00dc797c84a98f 100644 --- a/examples/temperature-measurement-app/esp32/main/gen/command-id.h +++ b/examples/temperature-measurement-app/esp32/main/gen/command-id.h @@ -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) diff --git a/examples/tv-app/tv-common/gen/client-command-macro.h b/examples/tv-app/tv-common/gen/client-command-macro.h index 1ac6d9550498d1..b12eea3dbc3a23 100644 --- a/examples/tv-app/tv-common/gen/client-command-macro.h +++ b/examples/tv-app/tv-common/gen/client-command-macro.h @@ -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 diff --git a/examples/tv-app/tv-common/gen/command-id.h b/examples/tv-app/tv-common/gen/command-id.h index cbda27333416da..00dc797c84a98f 100644 --- a/examples/tv-app/tv-common/gen/command-id.h +++ b/examples/tv-app/tv-common/gen/command-id.h @@ -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) diff --git a/examples/window-app/common/gen/client-command-macro.h b/examples/window-app/common/gen/client-command-macro.h index 1ac6d9550498d1..b12eea3dbc3a23 100644 --- a/examples/window-app/common/gen/client-command-macro.h +++ b/examples/window-app/common/gen/client-command-macro.h @@ -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 diff --git a/examples/window-app/common/gen/command-id.h b/examples/window-app/common/gen/command-id.h index cbda27333416da..00dc797c84a98f 100644 --- a/examples/window-app/common/gen/command-id.h +++ b/examples/window-app/common/gen/command-id.h @@ -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) diff --git a/src/app/chip-zcl-zpro-codec-api.h b/src/app/chip-zcl-zpro-codec-api.h index 149b37133852a7..ce4a46303cfee4 100644 --- a/src/app/chip-zcl-zpro-codec-api.h +++ b/src/app/chip-zcl-zpro-codec-api.h @@ -2362,6 +2362,7 @@ chip::System::PacketBufferHandle encodeOnOffClusterReadClusterRevisionAttribute( | Cluster OperationalCredentials | 0x003E | |------------------------------------------------------------------------------| | Commands: | | +| * RemoveAllFabrics | 0x0B | | * RemoveFabric | 0x0A | | * SetFabric | 0x00 | | * UpdateFabricLabel | 0x09 | @@ -2371,6 +2372,13 @@ chip::System::PacketBufferHandle encodeOnOffClusterReadClusterRevisionAttribute( | * ClusterRevision | 0xFFFD | \*----------------------------------------------------------------------------*/ +/** + * @brief + * Encode an RemoveAllFabrics command for Operational Credentials server into buffer including the APS frame + */ +chip::System::PacketBufferHandle encodeOperationalCredentialsClusterRemoveAllFabricsCommand(uint8_t seqNum, + chip::EndpointId destinationEndpoint); + /** * @brief * Encode an RemoveFabric command for Operational Credentials server into buffer including the APS frame diff --git a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp index 5bca1d6626355c..b9c35cb4225eaf 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -273,3 +273,12 @@ bool emberAfOperationalCredentialsClusterUpdateFabricLabelCallback(chip::app::Co emberAfSendImmediateDefaultResponse(status); return true; } + +// Up for discussion in Multi-Admin TT: chip-spec:#2891 +bool emberAfOperationalCredentialsClusterRemoveAllFabricsCallback(chip::app::Command * commandObj) +{ + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Remove all Fabrics"); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); + OpenDefaultPairingWindow(ResetAdmins::kYes); + return true; +} diff --git a/src/app/encoder.cpp b/src/app/encoder.cpp index f298266a98d0b2..0de6aca53300c9 100644 --- a/src/app/encoder.cpp +++ b/src/app/encoder.cpp @@ -302,6 +302,7 @@ uint16_t encodeApsFrame(uint8_t * buffer, uint16_t buf_length, EmberApsFrame * a #define ZCL_TOGGLE_COMMAND_ID (0x02) #define OPERATIONAL_CREDENTIALS_CLUSTER_ID 0x003E +#define ZCL_REMOVE_ALL_FABRICS_COMMAND_ID (0x0B) #define ZCL_REMOVE_FABRIC_COMMAND_ID (0x0A) #define ZCL_SET_FABRIC_COMMAND_ID (0x00) #define ZCL_UPDATE_FABRIC_LABEL_COMMAND_ID (0x09) @@ -4142,6 +4143,7 @@ PacketBufferHandle encodeOnOffClusterReadClusterRevisionAttribute(uint8_t seqNum | Cluster OperationalCredentials | 0x003E | |------------------------------------------------------------------------------| | Commands: | | +| * RemoveAllFabrics | 0x0B | | * RemoveFabric | 0x0A | | * SetFabric | 0x00 | | * UpdateFabricLabel | 0x09 | @@ -4151,6 +4153,16 @@ PacketBufferHandle encodeOnOffClusterReadClusterRevisionAttribute(uint8_t seqNum | * ClusterRevision | 0xFFFD | \*----------------------------------------------------------------------------*/ +/* + * Command RemoveAllFabrics + */ +PacketBufferHandle encodeOperationalCredentialsClusterRemoveAllFabricsCommand(uint8_t seqNum, EndpointId destinationEndpoint) +{ + COMMAND_HEADER("RemoveAllFabrics", OPERATIONAL_CREDENTIALS_CLUSTER_ID); + buf.Put8(kFrameControlClusterSpecificCommand).Put8(seqNum).Put8(ZCL_REMOVE_ALL_FABRICS_COMMAND_ID); + COMMAND_FOOTER(); +} + /* * Command RemoveFabric */ diff --git a/src/app/zap-templates/zcl/operational-credentials-cluster.xml b/src/app/zap-templates/zcl/operational-credentials-cluster.xml index b87b48fd9f484a..dec963047f6b28 100644 --- a/src/app/zap-templates/zcl/operational-credentials-cluster.xml +++ b/src/app/zap-templates/zcl/operational-credentials-cluster.xml @@ -59,5 +59,10 @@ fabric-scoped data. + // Up for discussion in Multi-Admin TT: chip-spec:#2891 + + Removes all fabrics. + + diff --git a/src/controller/controller-clusters.zap b/src/controller/controller-clusters.zap index ea6130657d280f..c90a7031444bb0 100644 --- a/src/controller/controller-clusters.zap +++ b/src/controller/controller-clusters.zap @@ -1616,7 +1616,7 @@ "enabled": 0, "commands": [ { - "name": "GetFabricId", + "name": "SetFabric", "code": 0, "mfgCode": null, "source": "client", @@ -1638,6 +1638,14 @@ "source": "client", "incoming": 1, "outgoing": 1 + }, + { + "name": "RemoveAllFabrics", + "code": 11, + "mfgCode": null, + "source": "client", + "incoming": 1, + "outgoing": 1 } ], "attributes": [ @@ -1667,7 +1675,7 @@ "enabled": 1, "commands": [ { - "name": "GetFabricIdResponse", + "name": "SetFabricResponse", "code": 1, "mfgCode": null, "source": "server", @@ -8994,4 +9002,4 @@ } ], "log": [] -} +} \ No newline at end of file diff --git a/src/controller/python/chip/clusters/CHIPClusters.cpp b/src/controller/python/chip/clusters/CHIPClusters.cpp index 25b5b90ccdbaad..e172cd3441d4e9 100644 --- a/src/controller/python/chip/clusters/CHIPClusters.cpp +++ b/src/controller/python/chip/clusters/CHIPClusters.cpp @@ -2170,6 +2170,14 @@ CHIP_ERROR chip_ime_ReadAttribute_OnOff_ClusterRevision(chip::Controller::Device // End of Cluster OnOff // Cluster OperationalCredentials +CHIP_ERROR chip_ime_AppendCommand_OperationalCredentials_RemoveAllFabrics(chip::Controller::Device * device, + chip::EndpointId ZCLendpointId, chip::GroupId) +{ + VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + chip::Controller::OperationalCredentialsCluster cluster; + cluster.Associate(device, ZCLendpointId); + return cluster.RemoveAllFabrics(gDefaultSuccessCallback.Cancel(), gDefaultFailureCallback.Cancel()); +} CHIP_ERROR chip_ime_AppendCommand_OperationalCredentials_RemoveFabric(chip::Controller::Device * device, chip::EndpointId ZCLendpointId, chip::GroupId, chip::FabricId fabricId, chip::NodeId nodeId, diff --git a/src/controller/python/chip/clusters/CHIPClusters.py b/src/controller/python/chip/clusters/CHIPClusters.py index cacf420d2332f1..e91070fd3f437f 100644 --- a/src/controller/python/chip/clusters/CHIPClusters.py +++ b/src/controller/python/chip/clusters/CHIPClusters.py @@ -481,6 +481,8 @@ def ListClusterCommands(self): }, }, "OperationalCredentials": { + "RemoveAllFabrics": { + }, "RemoveFabric": { "fabricId": "int", "nodeId": "int", @@ -1279,6 +1281,10 @@ def ClusterOnOff_CommandToggle(self, device: ctypes.c_void_p, ZCLendpoint: int, return self._chipLib.chip_ime_AppendCommand_OnOff_Toggle( device, ZCLendpoint, ZCLgroupid ) + def ClusterOperationalCredentials_CommandRemoveAllFabrics(self, device: ctypes.c_void_p, ZCLendpoint: int, ZCLgroupid: int): + return self._chipLib.chip_ime_AppendCommand_OperationalCredentials_RemoveAllFabrics( + device, ZCLendpoint, ZCLgroupid + ) def ClusterOperationalCredentials_CommandRemoveFabric(self, device: ctypes.c_void_p, ZCLendpoint: int, ZCLgroupid: int, fabricId: int, nodeId: int, vendorId: int): return self._chipLib.chip_ime_AppendCommand_OperationalCredentials_RemoveFabric( device, ZCLendpoint, ZCLgroupid, fabricId, nodeId, vendorId @@ -2478,6 +2484,9 @@ def InitLib(self, chipLib): self._chipLib.chip_ime_ReadAttribute_OnOff_ClusterRevision.argtypes = [ctypes.c_void_p, ctypes.c_uint8, ctypes.c_uint16] self._chipLib.chip_ime_ReadAttribute_OnOff_ClusterRevision.restype = ctypes.c_uint32 # Cluster OperationalCredentials + # Cluster OperationalCredentials Command RemoveAllFabrics + self._chipLib.chip_ime_AppendCommand_OperationalCredentials_RemoveAllFabrics.argtypes = [ctypes.c_void_p, ctypes.c_uint8, ctypes.c_uint16] + self._chipLib.chip_ime_AppendCommand_OperationalCredentials_RemoveAllFabrics.restype = ctypes.c_uint32 # Cluster OperationalCredentials Command RemoveFabric self._chipLib.chip_ime_AppendCommand_OperationalCredentials_RemoveFabric.argtypes = [ctypes.c_void_p, ctypes.c_uint8, ctypes.c_uint16, ctypes.c_uint64, ctypes.c_uint64, ctypes.c_uint16] self._chipLib.chip_ime_AppendCommand_OperationalCredentials_RemoveFabric.restype = ctypes.c_uint32 diff --git a/src/controller/python/gen/CHIPClusters.cpp b/src/controller/python/gen/CHIPClusters.cpp index 1a6deb926c5223..59b6767b4924c3 100644 --- a/src/controller/python/gen/CHIPClusters.cpp +++ b/src/controller/python/gen/CHIPClusters.cpp @@ -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) diff --git a/src/controller/python/gen/CHIPClusters.h b/src/controller/python/gen/CHIPClusters.h index 1a8e5d93fed59b..dfb1d26f9f0d79 100644 --- a/src/controller/python/gen/CHIPClusters.h +++ b/src/controller/python/gen/CHIPClusters.h @@ -818,6 +818,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); @@ -830,6 +831,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; diff --git a/src/controller/python/gen/CHIPClustersObjc.h b/src/controller/python/gen/CHIPClustersObjc.h index 2df796e1bb82a7..f84daeca21765c 100644 --- a/src/controller/python/gen/CHIPClustersObjc.h +++ b/src/controller/python/gen/CHIPClustersObjc.h @@ -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 diff --git a/src/controller/python/gen/CHIPClustersObjc.mm b/src/controller/python/gen/CHIPClustersObjc.mm index ca29cdb86ff577..9195ff70a0ec1f 100644 --- a/src/controller/python/gen/CHIPClustersObjc.mm +++ b/src/controller/python/gen/CHIPClustersObjc.mm @@ -10106,6 +10106,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 diff --git a/src/controller/python/gen/client-command-macro.h b/src/controller/python/gen/client-command-macro.h index 1ac6d9550498d1..b12eea3dbc3a23 100644 --- a/src/controller/python/gen/client-command-macro.h +++ b/src/controller/python/gen/client-command-macro.h @@ -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 diff --git a/src/controller/python/gen/command-id.h b/src/controller/python/gen/command-id.h index cbda27333416da..00dc797c84a98f 100644 --- a/src/controller/python/gen/command-id.h +++ b/src/controller/python/gen/command-id.h @@ -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) diff --git a/src/controller/python/gen/endpoint_config.h b/src/controller/python/gen/endpoint_config.h index a927535f5aeb5d..26ef960ee479b1 100644 --- a/src/controller/python/gen/endpoint_config.h +++ b/src/controller/python/gen/endpoint_config.h @@ -326,7 +326,7 @@ // Array of EmberAfCommandMetadata structs. #define ZAP_COMMAND_MASK(mask) COMMAND_MASK_##mask -#define EMBER_AF_GENERATED_COMMAND_COUNT (198) +#define EMBER_AF_GENERATED_COMMAND_COUNT (199) #define GENERATED_COMMANDS \ { \ \ @@ -416,6 +416,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 */ \ diff --git a/src/controller/python/local-clusters.zap b/src/controller/python/local-clusters.zap index 0b072d62b5b24b..ad79ef71effa90 100644 --- a/src/controller/python/local-clusters.zap +++ b/src/controller/python/local-clusters.zap @@ -1616,7 +1616,7 @@ "enabled": 1, "commands": [ { - "name": "GetFabricId", + "name": "SetFabric", "code": 0, "mfgCode": null, "source": "client", @@ -1638,6 +1638,14 @@ "source": "client", "incoming": 0, "outgoing": 1 + }, + { + "name": "RemoveAllFabrics", + "code": 11, + "mfgCode": null, + "source": "client", + "incoming": 0, + "outgoing": 1 } ], "attributes": [ @@ -1667,7 +1675,7 @@ "enabled": 0, "commands": [ { - "name": "GetFabricIdResponse", + "name": "SetFabricResponse", "code": 1, "mfgCode": null, "source": "server", @@ -6277,4 +6285,4 @@ } ], "log": [] -} +} \ No newline at end of file diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/Fabric/FabricUIViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/Fabric/FabricUIViewController.m index e91a0eaed1730f..aa3deaf6fdffde 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/Fabric/FabricUIViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/Fabric/FabricUIViewController.m @@ -112,6 +112,24 @@ - (void)setupUIElements removeFabricView.translatesAutoresizingMaskIntoConstraints = false; [removeFabricView.trailingAnchor constraintEqualToAnchor:_stackView.trailingAnchor].active = YES; + // Remove All Fabrics + + UIButton * removeAllFabricsButton = [UIButton new]; + removeAllFabricsButton.titleLabel.font = [UIFont systemFontOfSize:17]; + removeAllFabricsButton.titleLabel.textColor = [UIColor blackColor]; + removeAllFabricsButton.layer.cornerRadius = 5; + removeAllFabricsButton.clipsToBounds = YES; + removeAllFabricsButton.backgroundColor = UIColor.systemBlueColor; + [removeAllFabricsButton setTitle:@"Remove All Fabrics" forState:UIControlStateNormal]; + [removeAllFabricsButton addTarget:self + action:@selector(removeAllFabricsButtonPressed:) + forControlEvents:UIControlEventTouchUpInside]; + [_stackView addArrangedSubview:removeAllFabricsButton]; + + removeAllFabricsButton.translatesAutoresizingMaskIntoConstraints = false; + [removeAllFabricsButton.trailingAnchor constraintEqualToAnchor:_stackView.trailingAnchor].active = YES; + [removeAllFabricsButton.leadingAnchor constraintEqualToAnchor:_stackView.leadingAnchor].active = YES; + // Get Fabrics List UIButton * getFabricsListButton = [UIButton new]; @@ -223,6 +241,41 @@ - (void)fetchFabricsList // MARK: UIButton methods +- (IBAction)removeAllFabricsButtonPressed:(id)sender +{ + NSLog(@"Request to Remove All Fabrics."); + UIAlertController * alert = + [UIAlertController alertControllerWithTitle:@"Remove All Fabrics?" + message:@"Are you sure you want to remove all fabrics, this will remove all fabrics on " + @"accessory, including this one, and put the device back in commissioning." + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction * defaultAction = + [UIAlertAction actionWithTitle:@"Remove" + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + [self.cluster removeAllFabrics:^(NSError * error, NSDictionary * values) { + BOOL errorOccured = (error != nil); + NSString * resultString = errorOccured + ? [NSString stringWithFormat:@"An error occured: 0x%02lx", error.code] + : @"Remove all fabrics success"; + dispatch_async(dispatch_get_main_queue(), ^{ + [self updateResult:resultString isError:errorOccured]; + }); + }]; + }]; + + UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel" + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { + }]; + + [alert addAction:cancelAction]; + [alert addAction:defaultAction]; + + [self presentViewController:alert animated:YES completion:nil]; +} + - (IBAction)updateFabricLabelButtonPressed:(id)sender { NSString * label = _updateFabricLabelTextField.text; diff --git a/src/darwin/Framework/CHIP/chip-tool.zap b/src/darwin/Framework/CHIP/chip-tool.zap index 5b4977e1735510..1d10688a931398 100644 --- a/src/darwin/Framework/CHIP/chip-tool.zap +++ b/src/darwin/Framework/CHIP/chip-tool.zap @@ -1616,7 +1616,7 @@ "enabled": 1, "commands": [ { - "name": "GetFabricId", + "name": "SetFabric", "code": 0, "mfgCode": null, "source": "client", @@ -1638,6 +1638,14 @@ "source": "client", "incoming": 1, "outgoing": 1 + }, + { + "name": "RemoveAllFabrics", + "code": 11, + "mfgCode": null, + "source": "client", + "incoming": 1, + "outgoing": 1 } ], "attributes": [ @@ -1667,7 +1675,7 @@ "enabled": 0, "commands": [ { - "name": "GetFabricIdResponse", + "name": "SetFabricResponse", "code": 1, "mfgCode": null, "source": "server", @@ -4987,4 +4995,4 @@ } ], "log": [] -} +} \ No newline at end of file diff --git a/src/darwin/Framework/CHIP/gen/CHIPClusters.cpp b/src/darwin/Framework/CHIP/gen/CHIPClusters.cpp index f54b07907e2e16..a53d9ca5b1a24d 100644 --- a/src/darwin/Framework/CHIP/gen/CHIPClusters.cpp +++ b/src/darwin/Framework/CHIP/gen/CHIPClusters.cpp @@ -3704,6 +3704,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) diff --git a/src/darwin/Framework/CHIP/gen/CHIPClusters.h b/src/darwin/Framework/CHIP/gen/CHIPClusters.h index d4aa3fd1af4608..1871d25266b683 100644 --- a/src/darwin/Framework/CHIP/gen/CHIPClusters.h +++ b/src/darwin/Framework/CHIP/gen/CHIPClusters.h @@ -640,6 +640,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); @@ -652,6 +653,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; diff --git a/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.h b/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.h index 52ba9308e8ad8c..c80acefdc35749 100644 --- a/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.h +++ b/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.h @@ -578,6 +578,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 diff --git a/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm b/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm index 618dab45d9fe9e..c42244b115d9e9 100644 --- a/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm +++ b/src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm @@ -8464,6 +8464,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 diff --git a/src/darwin/Framework/CHIP/gen/client-command-macro.h b/src/darwin/Framework/CHIP/gen/client-command-macro.h index 1ac6d9550498d1..b12eea3dbc3a23 100644 --- a/src/darwin/Framework/CHIP/gen/client-command-macro.h +++ b/src/darwin/Framework/CHIP/gen/client-command-macro.h @@ -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 diff --git a/src/darwin/Framework/CHIP/gen/command-id.h b/src/darwin/Framework/CHIP/gen/command-id.h index cbda27333416da..00dc797c84a98f 100644 --- a/src/darwin/Framework/CHIP/gen/command-id.h +++ b/src/darwin/Framework/CHIP/gen/command-id.h @@ -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) diff --git a/src/darwin/Framework/CHIP/gen/endpoint_config.h b/src/darwin/Framework/CHIP/gen/endpoint_config.h index aefcc4b9237a23..63b01921e7c271 100644 --- a/src/darwin/Framework/CHIP/gen/endpoint_config.h +++ b/src/darwin/Framework/CHIP/gen/endpoint_config.h @@ -260,7 +260,7 @@ // Array of EmberAfCommandMetadata structs. #define ZAP_COMMAND_MASK(mask) COMMAND_MASK_##mask -#define EMBER_AF_GENERATED_COMMAND_COUNT (146) +#define EMBER_AF_GENERATED_COMMAND_COUNT (147) #define GENERATED_COMMANDS \ { \ \ @@ -350,6 +350,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 */ \