NOC: Support read attribute for current fabric index

This commit is contained in:
Kedar Sovani 2023-01-01 15:55:34 +05:30
parent 1048b781f1
commit 59ebfa06c9

View file

@ -78,6 +78,16 @@ pub enum Commands {
AddTrustedRootCert = 0x0b,
}
#[derive(FromPrimitive)]
enum Attributes {
NOCs = 0,
Fabrics = 1,
SupportedFabrics = 2,
CommissionedFabrics = 3,
TrustedRootCerts = 4,
CurrentFabricIndex = 5,
}
pub struct NocCluster {
base: Cluster,
dev_att: Box<dyn DevAttDataFetcher>,
@ -106,13 +116,15 @@ impl NocCluster {
acl_mgr: Arc<AclMgr>,
failsafe: Arc<FailSafe>,
) -> Result<Box<Self>, Error> {
Ok(Box::new(Self {
let mut c = Box::new(Self {
dev_att,
fabric_mgr,
acl_mgr,
failsafe,
base: Cluster::new(ID)?,
}))
});
c.base.add_attribute(attr_currfabindex_new()?)?;
Ok(c)
}
fn add_acl(&self, fab_idx: u8, admin_subject: u64) -> Result<(), Error> {
@ -342,6 +354,15 @@ impl NocCluster {
}
}
fn attr_currfabindex_new() -> Result<Attribute, Error> {
Attribute::new(
Attributes::CurrentFabricIndex as u16,
AttrValue::Custom,
Access::RV,
Quality::NONE,
)
}
impl ClusterType for NocCluster {
fn base(&self) -> &Cluster {
&self.base
@ -367,6 +388,17 @@ impl ClusterType for NocCluster {
_ => Err(IMStatusCode::UnsupportedCommand),
}
}
fn read_custom_attribute(&self, encoder: &mut dyn Encoder, attr: &AttrDetails) {
match num::FromPrimitive::from_u16(attr.attr_id) {
Some(Attributes::CurrentFabricIndex) => {
encoder.encode(EncodeValue::Value(&attr.fab_idx))
}
_ => {
error!("Attribute not supported: this shouldn't happen");
}
}
}
}
fn add_attestation_element(