Skip to content

Commit

Permalink
Add CommissionedFabrics and SupportedFabrics attribute to opCreds clu…
Browse files Browse the repository at this point in the history
…ster (#8138)

* Add attributes + zap files

* Add label in iOS chiptool app

* Restyled by whitespace

* Restyled by clang-format

* Review feedback

* regen files

* address review comments

* use accessor to write fabric count

* Link Accessors.cpp into various example apps

Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Pankaj Garg <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
4 people authored and pull[bot] committed Aug 17, 2021
1 parent 71cb643 commit 1075354
Show file tree
Hide file tree
Showing 31 changed files with 584 additions and 54 deletions.
30 changes: 30 additions & 0 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3355,6 +3355,36 @@
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "supported fabrics",
"code": 2,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "commissioned fabrics",
"code": 3,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "cluster revision",
"code": 65533,
Expand Down
94 changes: 48 additions & 46 deletions examples/all-clusters-app/all-clusters-common/gen/endpoint_config.h

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions examples/chip-tool/commands/clusters/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -14270,6 +14270,8 @@ class ReadOnOffClusterRevision : public ModelCommand
|------------------------------------------------------------------------------|
| Attributes: | |
| * FabricsList | 0x0001 |
| * SupportedFabrics | 0x0002 |
| * CommissionedFabrics | 0x0003 |
| * ClusterRevision | 0xFFFD |
\*----------------------------------------------------------------------------*/

Expand Down Expand Up @@ -14623,6 +14625,74 @@ class ReadOperationalCredentialsFabricsList : public ModelCommand
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};

/*
* Attribute SupportedFabrics
*/
class ReadOperationalCredentialsSupportedFabrics : public ModelCommand
{
public:
ReadOperationalCredentialsSupportedFabrics() : ModelCommand("read")
{
AddArgument("attr-name", "supported-fabrics");
ModelCommand::AddArguments();
}

~ReadOperationalCredentialsSupportedFabrics()
{
delete onSuccessCallback;
delete onFailureCallback;
}

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

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

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

/*
* Attribute CommissionedFabrics
*/
class ReadOperationalCredentialsCommissionedFabrics : public ModelCommand
{
public:
ReadOperationalCredentialsCommissionedFabrics() : ModelCommand("read")
{
AddArgument("attr-name", "commissioned-fabrics");
ModelCommand::AddArguments();
}

~ReadOperationalCredentialsCommissionedFabrics()
{
delete onSuccessCallback;
delete onFailureCallback;
}

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

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

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

/*
* Attribute ClusterRevision
*/
Expand Down Expand Up @@ -24072,6 +24142,8 @@ void registerClusterOperationalCredentials(Commands & commands)
make_unique<OperationalCredentialsUpdateFabricLabel>(), //
make_unique<DiscoverOperationalCredentialsAttributes>(), //
make_unique<ReadOperationalCredentialsFabricsList>(), //
make_unique<ReadOperationalCredentialsSupportedFabrics>(), //
make_unique<ReadOperationalCredentialsCommissionedFabrics>(), //
make_unique<ReadOperationalCredentialsClusterRevision>(), //
};

Expand Down
1 change: 1 addition & 0 deletions examples/lighting-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ target_sources(${APP_TARGET} PRIVATE
${MBED_COMMON}/util/LEDWidget.cpp
${CHIP_ROOT}/src/app/common/gen/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/src/app/common/gen/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
${CHIP_ROOT}/src/app/reporting/reporting.cpp
${CHIP_ROOT}/src/app/util/af-event.cpp
Expand Down
1 change: 1 addition & 0 deletions examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ target_sources(app PRIVATE
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp
${CHIP_ROOT}/src/app/common/gen/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/src/app/common/gen/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
${CHIP_ROOT}/src/app/reporting/reporting.cpp
${CHIP_ROOT}/src/app/util/af-event.cpp
Expand Down
1 change: 1 addition & 0 deletions examples/lighting-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ target_sources(app PRIVATE
${TELINK_COMMON}/util/src/ThreadUtil.cpp
${CHIP_ROOT}/src/app/common/gen/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/src/app/common/gen/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
${CHIP_ROOT}/src/app/reporting/reporting.cpp
${CHIP_ROOT}/src/app/util/af-event.cpp
Expand Down
2 changes: 2 additions & 0 deletions examples/lock-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ idf_component_register(INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/../../common/pigweed"
"${CMAKE_SOURCE_DIR}/../../common/pigweed/esp32"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lock-app/lock-common/gen"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/common/gen/attributes"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/reporting"
Expand Down Expand Up @@ -119,6 +120,7 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lock-app/lock-common/gen"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/common/gen/attributes"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/reporting"
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ target_sources(${APP_TARGET} PRIVATE
${LOCK_COMMON}/gen/IMClusterCommandHandler.cpp
${MBED_COMMON}/util/LEDWidget.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/src/app/common/gen/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
${CHIP_ROOT}/src/app/reporting/reporting.cpp
${CHIP_ROOT}/src/app/util/af-event.cpp
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ target_sources(app PRIVATE
${NRFCONNECT_COMMON}/util/LEDWidget.cpp
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/src/app/common/gen/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
${CHIP_ROOT}/src/app/reporting/reporting.cpp
${CHIP_ROOT}/src/app/util/af-event.cpp
Expand Down
1 change: 1 addition & 0 deletions examples/pump-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ target_sources(app PRIVATE
${NRFCONNECT_COMMON}/util/LEDWidget.cpp
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp
${CHIP_ROOT}/src/app/server/DataModelHandler.cpp
${CHIP_ROOT}/src/app/common/gen/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
${CHIP_ROOT}/src/app/reporting/reporting.cpp
${CHIP_ROOT}/src/app/util/af-event.cpp
Expand Down
1 change: 1 addition & 0 deletions examples/pump-controller-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ target_sources(app PRIVATE
${NRFCONNECT_COMMON}/util/LEDWidget.cpp
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp
${CHIP_ROOT}/src/app/server/DataModelHandler.cpp
${CHIP_ROOT}/src/app/common/gen/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
${CHIP_ROOT}/src/app/reporting/reporting.cpp
${CHIP_ROOT}/src/app/util/af-event.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ idf_component_register(PRIV_INCLUDE_DIRS
SRC_DIRS
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_CURRENT_LIST_DIR}/gen"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/common/gen/attributes"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/reporting"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <app/common/gen/af-structs.h>
#include <app/common/gen/attribute-id.h>
#include <app/common/gen/attribute-type.h>
#include <app/common/gen/attributes/Accessors.h>
#include <app/common/gen/cluster-id.h>
#include <app/common/gen/command-id.h>
#include <app/common/gen/enums.h>
Expand Down Expand Up @@ -81,7 +82,7 @@ EmberAfStatus writeFabricAttribute(uint8_t * buffer, int32_t index = -1)
index + 1);
}

EmberAfStatus writeFabric(FabricId fabricId, NodeId nodeId, uint16_t vendorId, const uint8_t * fabricLabel, int32_t index)
EmberAfStatus writeFabric(FabricId fabricId, NodeId nodeId, uint16_t vendorId, const uint8_t * fabricLabel, uint8_t index)
{
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;

Expand All @@ -99,7 +100,7 @@ EmberAfStatus writeFabric(FabricId fabricId, NodeId nodeId, uint16_t vendorId, c
"OpCreds: Writing fabric into attribute store at index %d: fabricId 0x" ChipLogFormatX64
", nodeId 0x" ChipLogFormatX64 " vendorId 0x%04" PRIX16,
index, ChipLogValueX64(fabricId), ChipLogValueX64(nodeId), vendorId);
status = writeFabricAttribute((uint8_t *) &fabricDescriptor, index);
status = writeFabricAttribute((uint8_t *) &fabricDescriptor, static_cast<int32_t>(index));
return status;
}

Expand All @@ -109,7 +110,7 @@ CHIP_ERROR writeFabricsIntoFabricsListAttribute()
CHIP_ERROR err = CHIP_NO_ERROR;

// Loop through fabrics
int32_t fabricIndex = 0;
uint8_t fabricIndex = 0;
for (auto & pairing : GetGlobalFabricTable())
{
NodeId nodeId = pairing.GetNodeId();
Expand All @@ -121,7 +122,7 @@ CHIP_ERROR writeFabricsIntoFabricsListAttribute()
if (nodeId == kUndefinedNodeId || fabricId == kUndefinedFabricId || vendorId == kUndefinedVendorId)
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG,
"OpCreds: Skipping over unitialized fabric with fabricId 0x" ChipLogFormatX64
"OpCreds: Skipping over uninitialized fabric with fabricId 0x" ChipLogFormatX64
", nodeId 0x" ChipLogFormatX64 " vendorId 0x%04" PRIX16,
ChipLogValueX64(fabricId), ChipLogValueX64(nodeId), vendorId);
continue;
Expand All @@ -138,10 +139,19 @@ CHIP_ERROR writeFabricsIntoFabricsListAttribute()
}

// Store the count of fabrics we just stored
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Stored %" PRIu32 " fabrics in fabrics list attribute.", fabricIndex);
if (writeFabricAttribute((uint8_t *) &fabricIndex) != EMBER_ZCL_STATUS_SUCCESS)
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Stored %" PRIu8 " fabrics in fabrics list attribute.", fabricIndex);
uint16_t u16Index = fabricIndex;
if (writeFabricAttribute(reinterpret_cast<uint8_t *>(&u16Index)) != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Failed to write fabric count %" PRIu8 " in fabrics list", fabricIndex);
err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
}

if (err == CHIP_NO_ERROR &&
app::Clusters::OperationalCredentials::Attributes::SetCommissionedFabrics(0, fabricIndex) != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Failed to write fabric count %" PRIu32 " in fabrics list", fabricIndex);
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Failed to write fabrics count %" PRIu8 " in commissioned fabrics",
fabricIndex);
err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/common/gen/attribute-id.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@

// Server attributes
#define ZCL_FABRICS_ATTRIBUTE_ID (0x0001)
#define ZCL_SUPPORTED_FABRICS_ATTRIBUTE_ID (0x0002)
#define ZCL_COMMISSIONED_FABRICS_ATTRIBUTE_ID (0x0003)

// Attribute ids for cluster: Fixed Label

Expand Down
20 changes: 20 additions & 0 deletions src/app/common/gen/attributes/Accessors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,26 @@ EmberAfStatus SetMultiPressMax(chip::EndpointId endpoint, uint8_t multiPressMax)

namespace OperationalCredentials {
namespace Attributes {
EmberAfStatus GetSupportedFabrics(chip::EndpointId endpoint, uint8_t * supportedFabrics)
{
return emberAfReadServerAttribute(endpoint, OperationalCredentials::Id, Ids::SupportedFabrics, (uint8_t *) supportedFabrics,
sizeof(*supportedFabrics));
}
EmberAfStatus SetSupportedFabrics(chip::EndpointId endpoint, uint8_t supportedFabrics)
{
return emberAfWriteServerAttribute(endpoint, OperationalCredentials::Id, Ids::SupportedFabrics, (uint8_t *) &supportedFabrics,
ZCL_INT8U_ATTRIBUTE_TYPE);
}
EmberAfStatus GetCommissionedFabrics(chip::EndpointId endpoint, uint8_t * commissionedFabrics)
{
return emberAfReadServerAttribute(endpoint, OperationalCredentials::Id, Ids::CommissionedFabrics,
(uint8_t *) commissionedFabrics, sizeof(*commissionedFabrics));
}
EmberAfStatus SetCommissionedFabrics(chip::EndpointId endpoint, uint8_t commissionedFabrics)
{
return emberAfWriteServerAttribute(endpoint, OperationalCredentials::Id, Ids::CommissionedFabrics,
(uint8_t *) &commissionedFabrics, ZCL_INT8U_ATTRIBUTE_TYPE);
}
} // namespace Attributes
} // namespace OperationalCredentials

Expand Down
4 changes: 4 additions & 0 deletions src/app/common/gen/attributes/Accessors.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ EmberAfStatus SetMultiPressMax(chip::EndpointId endpoint, uint8_t multiPressMax)

namespace OperationalCredentials {
namespace Attributes {
EmberAfStatus GetSupportedFabrics(chip::EndpointId endpoint, uint8_t * supportedFabrics); // int8u
EmberAfStatus SetSupportedFabrics(chip::EndpointId endpoint, uint8_t supportedFabrics);
EmberAfStatus GetCommissionedFabrics(chip::EndpointId endpoint, uint8_t * commissionedFabrics); // int8u
EmberAfStatus SetCommissionedFabrics(chip::EndpointId endpoint, uint8_t commissionedFabrics);
} // namespace Attributes
} // namespace OperationalCredentials

Expand Down
4 changes: 3 additions & 1 deletion src/app/common/gen/ids/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@ static constexpr AttributeId MultiPressMax = 0x00000002;
namespace OperationalCredentials {
namespace Attributes {
namespace Ids {
static constexpr AttributeId FabricsList = 0x00000001;
static constexpr AttributeId FabricsList = 0x00000001;
static constexpr AttributeId SupportedFabrics = 0x00000002;
static constexpr AttributeId CommissionedFabrics = 0x00000003;
} // namespace Ids
} // namespace Attributes
} // namespace OperationalCredentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ limitations under the License.
<description>This cluster is used to add or remove Operational Credentials on a Commissionee or Node, as well as manage the associated Fabrics.</description>

<attribute side="server" code="0x0001" define="FABRICS" type="ARRAY" entryType="FabricDescriptor" length="254" writable="false" optional="false">fabrics list</attribute>
<attribute side="server" code="0x0002" define="SUPPORTED_FABRICS" type="INT8U" writable="false" optional="false">SupportedFabrics</attribute>
<attribute side="server" code="0x0003" define="COMMISSIONED_FABRICS" type="INT8U" writable="false" optional="false">CommissionedFabrics</attribute>

<!--
Temporary flow for fabric management until AddOpCert + fabric index are implemented:
Expand Down
30 changes: 30 additions & 0 deletions src/controller/data_model/controller-clusters.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3757,6 +3757,36 @@
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "supported fabrics",
"code": 2,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "commissioned fabrics",
"code": 3,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "cluster revision",
"code": 65533,
Expand Down
Loading

0 comments on commit 1075354

Please sign in to comment.