Skip to content

Commit

Permalink
Implement NOCs attribute in Node Operational Credentials Cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Jan 18, 2022
1 parent 628d7ba commit db718fa
Show file tree
Hide file tree
Showing 18 changed files with 278 additions and 5 deletions.
15 changes: 15 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 @@ -4355,6 +4355,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
15 changes: 15 additions & 0 deletions examples/bridge-app/bridge-common/bridge-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
15 changes: 15 additions & 0 deletions examples/door-lock-app/door-lock-common/door-lock-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3885,6 +3885,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
15 changes: 15 additions & 0 deletions examples/lighting-app/lighting-common/lighting-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -4143,6 +4143,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
15 changes: 15 additions & 0 deletions examples/lock-app/lock-common/lock-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3885,6 +3885,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
15 changes: 15 additions & 0 deletions examples/ota-provider-app/ota-provider-common/ota-provider-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
15 changes: 15 additions & 0 deletions examples/pump-app/pump-common/pump-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3661,6 +3661,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3661,6 +3661,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
15 changes: 15 additions & 0 deletions examples/thermostat/thermostat-common/thermostat.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3991,6 +3991,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
15 changes: 15 additions & 0 deletions examples/tv-app/tv-common/tv-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -4006,6 +4006,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
17 changes: 16 additions & 1 deletion examples/tv-casting-app/tv-casting-common/tv-casting-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3991,6 +3991,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down Expand Up @@ -16504,4 +16519,4 @@
"deviceIdentifier": 22
}
]
}
}
15 changes: 15 additions & 0 deletions examples/window-app/common/window-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3666,6 +3666,21 @@
}
],
"attributes": [
{
"name": "NOCs",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "fabrics list",
"code": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -139,6 +167,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

<struct name="FabricDescriptor">
<cluster code="0x003E"/>
<item name="FabricIndex" type="INT8U"/>
<item name="FabricIndex" type="fabric_idx"/>
<item name="RootPublicKey" type="OCTET_STRING" length="65"/>
<item name="VendorId" type="INT16U"/> <!-- Change INT16U to new type VendorID #2395 -->
<item name="FabricId" type="FABRIC_ID"/>
Expand All @@ -43,8 +43,9 @@ limitations under the License.

<struct name="NOCStruct">
<cluster code="0x003E"/>
<item name="FabricIndex" type="INT8U"/>
<item name="FabricIndex" type="fabric_idx"/>
<item name="NOC" type="OCTET_STRING"/>
<item name="ICAC" type="OCTET_STRING"/>
</struct>

<cluster>
Expand All @@ -54,6 +55,7 @@ limitations under the License.
<define>OPERATIONAL_CREDENTIALS_CLUSTER</define>
<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="0x0000" define="NOCS" type="ARRAY" entryType="NOCStruct" writable="false" optional="false">NOCs</attribute>
<attribute side="server" code="0x0001" define="FABRICS" type="ARRAY" entryType="FabricDescriptor" length="320" 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>
Expand Down
Loading

0 comments on commit db718fa

Please sign in to comment.