Skip to content

Commit fbcbcb7

Browse files
committed
NoC: Remove Fabric Support
1 parent 5e7e788 commit fbcbcb7

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

matter/src/data_model/sdm/noc.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,23 @@ impl NocCluster {
263263
Ok(())
264264
}
265265

266+
fn handle_command_rmfabric(&mut self, cmd_req: &mut CommandReq) -> Result<(), IMStatusCode> {
267+
cmd_enter!("Remove Fabric");
268+
let req =
269+
RemoveFabricReq::from_tlv(&cmd_req.data).map_err(|_| IMStatusCode::InvalidCommand)?;
270+
if self.fabric_mgr.remove(req.fab_idx).is_ok() {
271+
cmd_req.trans.terminate();
272+
} else {
273+
NocCluster::create_nocresponse(
274+
cmd_req.resp,
275+
NocStatus::InvalidFabricIndex,
276+
req.fab_idx,
277+
"".to_string(),
278+
);
279+
}
280+
Ok(())
281+
}
282+
266283
fn handle_command_addnoc(&mut self, cmd_req: &mut CommandReq) -> Result<(), IMStatusCode> {
267284
cmd_enter!("AddNOC");
268285
if let Err(e) = self._handle_command_addnoc(cmd_req) {
@@ -437,6 +454,7 @@ impl ClusterType for NocCluster {
437454
Commands::AttReq => self.handle_command_attrequest(cmd_req),
438455
Commands::CertChainReq => self.handle_command_certchainrequest(cmd_req),
439456
Commands::UpdateFabricLabel => self.handle_command_updatefablabel(cmd_req),
457+
Commands::RemoveFabric => self.handle_command_rmfabric(cmd_req),
440458
_ => Err(IMStatusCode::UnsupportedCommand),
441459
}
442460
}
@@ -566,6 +584,11 @@ struct CertChainReq {
566584
cert_type: u8,
567585
}
568586

587+
#[derive(FromTLV)]
588+
struct RemoveFabricReq {
589+
fab_idx: u8,
590+
}
591+
569592
fn get_certchainrequest_params(data: &TLVElement) -> Result<DataType, Error> {
570593
let cert_type = CertChainReq::from_tlv(data)?.cert_type;
571594

matter/src/fabric.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,17 @@ impl Fabric {
195195
}
196196
}
197197

198+
fn rm_store(&self, index: usize, psm: &MutexGuard<Psm>) {
199+
psm.rm(fb_key!(index, ST_RCA));
200+
psm.rm(fb_key!(index, ST_ICA));
201+
psm.rm(fb_key!(index, ST_NOC));
202+
psm.rm(fb_key!(index, ST_IPK));
203+
psm.rm(fb_key!(index, ST_LBL));
204+
psm.rm(fb_key!(index, ST_PBKEY));
205+
psm.rm(fb_key!(index, ST_PRKEY));
206+
psm.rm(fb_key!(index, ST_VID));
207+
}
208+
198209
fn store(&self, index: usize, psm: &MutexGuard<Psm>) -> Result<(), Error> {
199210
let mut key = [0u8; MAX_CERT_TLV_LEN];
200211
let len = self.root_ca.as_tlv(&mut key)?;
@@ -335,6 +346,19 @@ impl FabricMgr {
335346
Ok(index as u8)
336347
}
337348

349+
pub fn remove(&self, fab_idx: u8) -> Result<(), Error> {
350+
let fab_idx = fab_idx as usize;
351+
let mut mgr = self.inner.write().unwrap();
352+
let psm = self.psm.lock().unwrap();
353+
if let Some(f) = &mgr.fabrics[fab_idx] {
354+
f.rm_store(fab_idx, &psm);
355+
mgr.fabrics[fab_idx] = None;
356+
Ok(())
357+
} else {
358+
Err(Error::NotFound)
359+
}
360+
}
361+
338362
pub fn match_dest_id(&self, random: &[u8], target: &[u8]) -> Result<usize, Error> {
339363
let mgr = self.inner.read()?;
340364
for i in 0..MAX_SUPPORTED_FABRICS {

matter/src/sys/posix.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use std::{
1919
convert::TryInto,
20-
fs::{DirBuilder, File},
20+
fs::{remove_file, DirBuilder, File},
2121
io::{Read, Write},
2222
sync::{Arc, Mutex, Once},
2323
};
@@ -89,4 +89,8 @@ impl Psm {
8989
*val = u64::from_be_bytes(vec.as_slice().try_into()?);
9090
Ok(())
9191
}
92+
93+
pub fn rm(&self, key: &str) {
94+
let _ = remove_file(psm_path!(key));
95+
}
9296
}

0 commit comments

Comments
 (0)