From c4b81ccdae505daf03f281b9f99de01b56658b95 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Thu, 13 Jan 2022 16:38:51 -0800 Subject: [PATCH] Implement NOCs attribute in Node Operational Credentials Cluster --- .../all-clusters-common/all-clusters-app.zap | 15 +++++++++ .../bridge-app/bridge-common/bridge-app.zap | 15 +++++++++ .../door-lock-common/door-lock-app.zap | 15 +++++++++ .../lighting-common/lighting-app.zap | 15 +++++++++ examples/lock-app/lock-common/lock-app.zap | 15 +++++++++ .../ota-provider-common/ota-provider-app.zap | 15 +++++++++ .../ota-requestor-app.zap | 15 +++++++++ examples/pump-app/pump-common/pump-app.zap | 15 +++++++++ .../pump-controller-app.zap | 15 +++++++++ .../esp32/main/temperature-measurement.zap | 15 +++++++++ .../thermostat-common/thermostat.zap | 15 +++++++++ examples/tv-app/tv-common/tv-app.zap | 15 +++++++++ .../tv-casting-common/tv-casting-app.zap | 17 +++++++++- examples/window-app/common/window-app.zap | 15 +++++++++ .../operational-credentials-server.cpp | 31 +++++++++++++++++++ .../chip/operational-credentials-cluster.xml | 6 ++-- .../data_model/controller-clusters.zap | 30 ++++++++++++++++++ src/credentials/FabricTable.h | 4 +-- 18 files changed, 278 insertions(+), 5 deletions(-) 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 29a874b0118ef9..90ddac7d87f30d 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 @@ -4355,6 +4355,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/bridge-app/bridge-common/bridge-app.zap b/examples/bridge-app/bridge-common/bridge-app.zap index 074fef3c6e5c3b..ceab47a82bb9be 100644 --- a/examples/bridge-app/bridge-common/bridge-app.zap +++ b/examples/bridge-app/bridge-common/bridge-app.zap @@ -2918,6 +2918,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/door-lock-app/door-lock-common/door-lock-app.zap b/examples/door-lock-app/door-lock-common/door-lock-app.zap index e0811fbe202f99..1a7e40362e00b4 100644 --- a/examples/door-lock-app/door-lock-common/door-lock-app.zap +++ b/examples/door-lock-app/door-lock-common/door-lock-app.zap @@ -3885,6 +3885,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/lighting-app/lighting-common/lighting-app.zap b/examples/lighting-app/lighting-common/lighting-app.zap index 5c63eaa227ffbb..fb1e68cb44bec1 100644 --- a/examples/lighting-app/lighting-common/lighting-app.zap +++ b/examples/lighting-app/lighting-common/lighting-app.zap @@ -4143,6 +4143,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/lock-app/lock-common/lock-app.zap b/examples/lock-app/lock-common/lock-app.zap index 0365ec7275c95e..08b8f6614b3cbb 100644 --- a/examples/lock-app/lock-common/lock-app.zap +++ b/examples/lock-app/lock-common/lock-app.zap @@ -3885,6 +3885,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/ota-provider-app/ota-provider-common/ota-provider-app.zap b/examples/ota-provider-app/ota-provider-common/ota-provider-app.zap index f806fa5a73f4f7..c447385b451e87 100644 --- a/examples/ota-provider-app/ota-provider-common/ota-provider-app.zap +++ b/examples/ota-provider-app/ota-provider-common/ota-provider-app.zap @@ -1721,6 +1721,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.zap b/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.zap index 364b27439619af..9f9ca70a12c219 100644 --- a/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.zap +++ b/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.zap @@ -1820,6 +1820,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/pump-app/pump-common/pump-app.zap b/examples/pump-app/pump-common/pump-app.zap index 547b2575f3240a..27899b8e60278c 100644 --- a/examples/pump-app/pump-common/pump-app.zap +++ b/examples/pump-app/pump-common/pump-app.zap @@ -3661,6 +3661,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/pump-controller-app/pump-controller-common/pump-controller-app.zap b/examples/pump-controller-app/pump-controller-common/pump-controller-app.zap index dac6c8c62b9387..a3f8134ecae07f 100644 --- a/examples/pump-controller-app/pump-controller-common/pump-controller-app.zap +++ b/examples/pump-controller-app/pump-controller-common/pump-controller-app.zap @@ -3661,6 +3661,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/temperature-measurement-app/esp32/main/temperature-measurement.zap b/examples/temperature-measurement-app/esp32/main/temperature-measurement.zap index 8a2b672613c4f7..018ede5303867b 100644 --- a/examples/temperature-measurement-app/esp32/main/temperature-measurement.zap +++ b/examples/temperature-measurement-app/esp32/main/temperature-measurement.zap @@ -2274,6 +2274,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/thermostat/thermostat-common/thermostat.zap b/examples/thermostat/thermostat-common/thermostat.zap index c4f33595c982f9..705464718d4a8c 100644 --- a/examples/thermostat/thermostat-common/thermostat.zap +++ b/examples/thermostat/thermostat-common/thermostat.zap @@ -3991,6 +3991,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/tv-app/tv-common/tv-app.zap b/examples/tv-app/tv-common/tv-app.zap index 819488c416eb25..437564af70bcc5 100644 --- a/examples/tv-app/tv-common/tv-app.zap +++ b/examples/tv-app/tv-common/tv-app.zap @@ -4006,6 +4006,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, diff --git a/examples/tv-casting-app/tv-casting-common/tv-casting-app.zap b/examples/tv-casting-app/tv-casting-common/tv-casting-app.zap index a0a56f806f7c10..e9050524569460 100644 --- a/examples/tv-casting-app/tv-casting-common/tv-casting-app.zap +++ b/examples/tv-casting-app/tv-casting-common/tv-casting-app.zap @@ -3991,6 +3991,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, @@ -16504,4 +16519,4 @@ "deviceIdentifier": 263 } ] -} +} \ No newline at end of file diff --git a/examples/window-app/common/window-app.zap b/examples/window-app/common/window-app.zap index 847536871850f5..11b170b5edaf53 100644 --- a/examples/window-app/common/window-app.zap +++ b/examples/window-app/common/window-app.zap @@ -3666,6 +3666,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, 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 becb7d9a2b42d8..3842fbd4eb0d47 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -70,12 +70,40 @@ class OperationalCredentialsAttrAccess : public AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; private: + CHIP_ERROR ReadNOCs(EndpointId endpoint, AttributeValueEncoder & aEncoder); CHIP_ERROR ReadSupportedFabrics(EndpointId endpoint, AttributeValueEncoder & aEncoder); CHIP_ERROR ReadCommissionedFabrics(EndpointId endpoint, AttributeValueEncoder & aEncoder); CHIP_ERROR ReadFabricsList(EndpointId endpoint, AttributeValueEncoder & aEncoder); CHIP_ERROR ReadRootCertificates(EndpointId endpoint, AttributeValueEncoder & aEncoder); }; +CHIP_ERROR OperationalCredentialsAttrAccess::ReadNOCs(EndpointId endpoint, AttributeValueEncoder & aEncoder) +{ + auto accessingFabricIndex = aEncoder.AccessingFabricIndex(); + + return aEncoder.EncodeList([accessingFabricIndex](const auto & encoder) -> CHIP_ERROR { + for (auto & fabricInfo : Server::GetInstance().GetFabricTable()) + { + Clusters::OperationalCredentials::Structs::NOCStruct::Type noc; + + if (!fabricInfo.IsInitialized()) + continue; + + noc.fabricIndex = fabricInfo.GetFabricIndex(); + + if (accessingFabricIndex == fabricInfo.GetFabricIndex()) + { + ReturnErrorOnFailure(fabricInfo.GetNOCCert(noc.noc)); + ReturnErrorOnFailure(fabricInfo.GetICACert(noc.icac)); + } + + ReturnErrorOnFailure(encoder.Encode(noc)); + } + + return CHIP_NO_ERROR; + }); +} + CHIP_ERROR OperationalCredentialsAttrAccess::ReadSupportedFabrics(EndpointId endpoint, AttributeValueEncoder & aEncoder) { uint8_t fabricCount = CHIP_CONFIG_MAX_DEVICE_ADMINS; @@ -142,6 +170,9 @@ CHIP_ERROR OperationalCredentialsAttrAccess::Read(const ConcreteReadAttributePat switch (aPath.mAttributeId) { + case Attributes::NOCs::Id: { + return ReadNOCs(aPath.mEndpointId, aEncoder); + } case Attributes::SupportedFabrics::Id: { return ReadSupportedFabrics(aPath.mEndpointId, aEncoder); } diff --git a/src/app/zap-templates/zcl/data-model/chip/operational-credentials-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/operational-credentials-cluster.xml index a6e0012cd14dec..f24ff35b33539a 100644 --- a/src/app/zap-templates/zcl/data-model/chip/operational-credentials-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/operational-credentials-cluster.xml @@ -19,7 +19,7 @@ limitations under the License. - + @@ -43,8 +43,9 @@ limitations under the License. - + + @@ -54,6 +55,7 @@ limitations under the License. OPERATIONAL_CREDENTIALS_CLUSTER This cluster is used to add or remove Operational Credentials on a Commissionee or Node, as well as manage the associated Fabrics. + NOCs fabrics list SupportedFabrics CommissionedFabrics diff --git a/src/controller/data_model/controller-clusters.zap b/src/controller/data_model/controller-clusters.zap index 482e0223506022..f0bf6fbcaa7517 100644 --- a/src/controller/data_model/controller-clusters.zap +++ b/src/controller/data_model/controller-clusters.zap @@ -6139,6 +6139,21 @@ } ], "attributes": [ + { + "name": "NOCs", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "fabrics list", "code": 1, @@ -6229,6 +6244,21 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "FeatureMap", + "code": 65532, + "mfgCode": null, + "side": "server", + "included": 0, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 0, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, { "name": "ClusterRevision", "code": 65533, diff --git a/src/credentials/FabricTable.h b/src/credentials/FabricTable.h index 7457b2f4b28e55..02f984666f8914 100644 --- a/src/credentials/FabricTable.h +++ b/src/credentials/FabricTable.h @@ -200,13 +200,13 @@ class DLL_EXPORT FabricInfo return CHIP_NO_ERROR; } - CHIP_ERROR GetICACert(ByteSpan & cert) + CHIP_ERROR GetICACert(ByteSpan & cert) const { cert = mICACert; return CHIP_NO_ERROR; } - CHIP_ERROR GetNOCCert(ByteSpan & cert) + CHIP_ERROR GetNOCCert(ByteSpan & cert) const { ReturnErrorCodeIf(mNOCCert.empty(), CHIP_ERROR_INCORRECT_STATE); cert = mNOCCert;