From 6fa4554d6d42c2bf8b3d951c1a2d596efea6260b Mon Sep 17 00:00:00 2001 From: Kedar Sovani Date: Fri, 20 Jan 2023 06:36:01 +0530 Subject: [PATCH] NOC: Add support for 2 attributes --- matter/src/data_model/sdm/noc.rs | 53 +++++++++++++++++++------------- matter/src/fabric.rs | 11 +++++++ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/matter/src/data_model/sdm/noc.rs b/matter/src/data_model/sdm/noc.rs index c15f607..2d3beeb 100644 --- a/matter/src/data_model/sdm/noc.rs +++ b/matter/src/data_model/sdm/noc.rs @@ -23,7 +23,7 @@ use crate::cert::Cert; use crate::crypto::{self, CryptoKeyPair, KeyPair}; use crate::data_model::objects::*; use crate::data_model::sdm::dev_att; -use crate::fabric::{Fabric, FabricMgr}; +use crate::fabric::{Fabric, FabricMgr, MAX_SUPPORTED_FABRICS}; use crate::interaction_model::command::CommandReq; use crate::interaction_model::core::IMStatusCode; use crate::interaction_model::messages::ib; @@ -125,8 +125,33 @@ impl NocCluster { failsafe, base: Cluster::new(ID)?, }); - c.base.add_attribute(attr_currfabindex_new()?)?; - c.base.add_attribute(attr_fabrics_new()?)?; + let attrs = [ + Attribute::new( + Attributes::CurrentFabricIndex as u16, + AttrValue::Custom, + Access::RV, + Quality::NONE, + )?, + Attribute::new( + Attributes::Fabrics as u16, + AttrValue::Custom, + Access::RV | Access::FAB_SCOPED, + Quality::NONE, + )?, + Attribute::new( + Attributes::SupportedFabrics as u16, + AttrValue::Uint8(MAX_SUPPORTED_FABRICS as u8), + Access::RV, + Quality::FIXED, + )?, + Attribute::new( + Attributes::CommissionedFabrics as u16, + AttrValue::Custom, + Access::RV, + Quality::NONE, + )?, + ]; + c.base.add_attributes(&attrs[..])?; Ok(c) } @@ -389,24 +414,6 @@ impl NocCluster { } } -fn attr_currfabindex_new() -> Result { - Attribute::new( - Attributes::CurrentFabricIndex as u16, - AttrValue::Custom, - Access::RV, - Quality::NONE, - ) -} - -fn attr_fabrics_new() -> Result { - Attribute::new( - Attributes::Fabrics as u16, - AttrValue::Custom, - Access::RV | Access::FAB_SCOPED, - Quality::NONE, - ) -} - impl ClusterType for NocCluster { fn base(&self) -> &Cluster { &self.base @@ -450,6 +457,10 @@ impl ClusterType for NocCluster { }); let _ = tw.end_container(); })), + Some(Attributes::CommissionedFabrics) => { + let count = self.fabric_mgr.used_count() as u8; + encoder.encode(EncodeValue::Value(&count)) + } _ => { error!("Attribute not supported: this shouldn't happen"); } diff --git a/matter/src/fabric.rs b/matter/src/fabric.rs index bb729ae..c5a2ce6 100644 --- a/matter/src/fabric.rs +++ b/matter/src/fabric.rs @@ -364,6 +364,17 @@ impl FabricMgr { true } + pub fn used_count(&self) -> usize { + let mgr = self.inner.read().unwrap(); + let mut count = 0; + for i in 1..MAX_SUPPORTED_FABRICS { + if mgr.fabrics[i].is_some() { + count += 1; + } + } + count + } + // Parameters to T are the Fabric and its Fabric Index pub fn for_each(&self, mut f: T) -> Result<(), Error> where