Skip to main content

FailSafe

Struct FailSafe 

Source
pub struct FailSafe { /* private fields */ }

Implementations§

Source§

impl FailSafe

Source

pub const fn new() -> Self

Source

pub fn init() -> impl Init<Self>

Source

pub fn set_max_cumulative_secs(&mut self, secs: u16)

Set MaxCumulativeFailsafeSeconds, the longest a fail-safe context lasts however often it is re-armed. Applies to the contexts created from now on: an armed one keeps its lifetime.

Source

pub fn check_failsafe_timeout<S>( &mut self, fabrics: &mut Fabrics, remove_pase_sessions: impl FnOnce(), kv: S, mdns_notif: impl FnMut(), notify_change: impl FnMut(EndptId, ClusterId), ) -> Result<Option<Expiry>, Error>

Check if the fail-safe timer has expired and if so disarms and restores the state of the fabric as well as the basic info settings.

This should be called periodically to ensure that the fail-safe state is updated in a timely manner. Ideally, it should also be called at the beginning of any API that requires the fail-safe to be armed to ensure that the state is up to date.

Returns the outcome of the expiry, if the fail-safe did expire (see FailSafe::expire).

Source

pub fn expire<S>( &mut self, fabrics: &mut Fabrics, remove_pase_sessions: impl FnOnce(), kv: S, mdns_notif: impl FnMut(), notify_change: impl FnMut(EndptId, ClusterId), ) -> Result<Option<Expiry>, Error>

Force the fail-safe context to expire immediately, rolling back any fabric changes that the in-flight commissioning had staged and resetting the breadcrumb to 0.

remove_pase_sessions removes the PASE sessions, which are orphaned by the rollback. When the trigger arrived over PASE, it should keep the session of the triggering exchange alive (marked expired), so that the response can still be sent before the slot is reclaimed.

Returns None if the fail-safe was not armed. Otherwise, the caller must broadcast LifecycleOp::FailSafeExpiry once the Matter state lock is released, so that the handlers drop what they staged (networks and the like), and HandlerContext::notify_fabric_removed for the returned removed fabric. That is a fabric added by the in-flight AddNOC, which has no persisted copy yet; a pre-existing fabric mutated by UpdateNOC is resurrected from its persisted copy instead.

Source

pub fn arm( &mut self, timeout_secs: u16, breadcrumb: u64, session_mode: &SessionMode, comm_window_open: bool, ) -> Result<(), Error>

Source

pub fn disarm<'a>( &mut self, session_mode: &SessionMode, fabrics: &'a mut Fabrics, ) -> Result<&'a mut Fabric, Error>

Source

pub fn disarm_with<'a, F>( &mut self, session_mode: &SessionMode, fabrics: &'a mut Fabrics, commit: F, ) -> Result<&'a mut Fabric, Error>
where F: FnOnce(&Fabric) -> Result<(), Error>,

Like Self::disarm, running commit on the fabric first. If commit fails, the fail-safe stays armed, for its expiry to revert the fabric.

Source

pub fn expires_at(&self) -> Option<Instant>

When the armed fail-safe expires, or None if it is not armed.

Source

pub fn is_armed(&self) -> bool

Source

pub fn pending_root_ca(&self) -> Option<&[u8]>

Return the trusted root certificate that has been staged via AddTrustedRootCertificate while the fail-safe is armed but has not yet been bound to a fabric via AddNOC / UpdateNOC.

Once AddNOC or UpdateNOC is processed the root certificate is owned by the (new or updated) fabric and is reported through the fabric table; until then it has no fabric association but the spec still requires it to appear in the TrustedRootCertificates list (Matter Core spec, NodeOperationalCredentials cluster).

Source

pub fn drop_pending_root_ca(&mut self)

Drop the trusted root certificate staged via AddTrustedRootCertificate, if no AddNOC / UpdateNOC has bound it to a fabric yet.

For fabric removal: the root is then not referenced by any operational certificate, so it must go. The fail-safe stays armed, and another AddTrustedRootCertificate in it is still refused.

Source

pub fn is_armed_for(&self, caller_fab_idx: u8) -> bool

Source

pub fn has_pending_noc_for(&self, caller_fab_idx: NonZeroU8) -> bool

Whether the current fail-safe context already has an in-flight AddNOC or UpdateNOC for caller_fab_idx. Used by SetVIDVerificationStatement to decide whether the VID-verification mutation rides along with the pending fabric (and thus rolls back on fail-safe expiry) or is committed to storage immediately.

Source

pub fn check_armed(&self, session_mode: &SessionMode) -> Result<(), Error>

Source

pub fn add_trusted_root_cert<C: Crypto>( &mut self, crypto: C, time: UtcTime, session_mode: &SessionMode, root_ca: &[u8], buf: &mut [u8], ) -> Result<(), Error>

Source

pub fn add_csr_req<C: Crypto>( &mut self, crypto: C, session_mode: &SessionMode, ) -> Result<CanonPkcSecretKeyRef<'_>, Error>

Source

pub fn update_csr_req<C: Crypto>( &mut self, crypto: C, session_mode: &SessionMode, ) -> Result<CanonPkcSecretKeyRef<'_>, Error>

Source

pub fn update_noc<'a, C: Crypto>( &mut self, crypto: C, time: UtcTime, fabrics: &'a mut Fabrics, session_mode: &SessionMode, icac: Option<&[u8]>, noc: &[u8], buf: &mut [u8], mdns_notif: impl FnMut(), ) -> Result<&'a mut Fabric, Error>

Source

pub fn add_noc<'a, C: Crypto>( &mut self, crypto: C, time: UtcTime, fabrics: &'a mut Fabrics, session_mode: &SessionMode, vendor_id: u16, icac: Option<&[u8]>, noc: &[u8], ipk: &[u8], case_admin_subject: u64, buf: &mut [u8], mdns_notif: impl FnMut(), ) -> Result<&'a mut Fabric, Error>

Source

pub fn breadcrumb(&self) -> u64

Source

pub fn set_breadcrumb(&mut self, value: u64)

Source

pub fn pending_add_noc(&self) -> Option<(NonZeroU8, u16)>

The fabric added by AddNOC in the current fail-safe context and the seconds left until expiry; None if there is no such fabric.

Source

pub fn arm_resumed( &mut self, fab_idx: NonZeroU8, timeout_secs: u16, breadcrumb: u64, ) -> Result<(), Error>

Arm the fail-safe for a fabric resumed from a commissioning handover, as if AddNOC had just been processed for it. Busy if already armed.

Source

pub fn check_new_noc<C: Crypto>( crypto: &C, time: UtcTime, fabrics: &Fabrics, root_ca: &[u8], icac: Option<&[u8]>, noc: &[u8], secret_key: CanonPkcSecretKeyRef<'_>, buf: &mut [u8], ) -> Result<(), Error>

Check that a NOC is acceptable for a new fabric: the chain verifies against root_ca, the NOC public key matches secret_key, and no existing fabric has the same fabric ID under the same root.

Trait Implementations§

Source§

impl Default for FailSafe

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Init<T> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), !>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, I> IntoFallibleInit<T> for I
where I: Init<T>,

Source§

fn into_fallible<E>(self) -> impl Init<T, E>

Convert the infallible initializer to a fallible one.
Source§

impl<T> MaybeSend for T
where T: ?Sized,

Source§

impl<T> MaybeSendSync for T
where T: ?Sized,

Source§

impl<T> PinInit<T> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), !>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.