class Matter::FailsafeContext

Overview

FailsafeContext manages commissioning state and coordinates rollback on failure

The failsafe context is created when ArmFailSafe is invoked and tracks all commissioning state changes (fabric operations, network config, etc.) so that they can be rolled back if the failsafe timer expires.

Matter Core Spec §11.10.7 - General Commissioning Cluster Matter Core Spec §5.5 - Commissioning Flows

Defined in:

matter/failsafe_context.cr

Constant Summary

Log = ::Log.for("matter.failsafe_context")

Constructors

Instance Method Summary

Constructor Detail

def self.new(associated_fabric_index : UInt8 | Nil, breadcrumb : UInt64, expiry_callback : Proc(Nil)) #

Create a new failsafe context

@param fabric_index Fabric index for CASE sessions (nil for PASE) @param breadcrumb Progress tracking value @param expiry_callback Callback invoked when failsafe expires (performs rollback)


[View source]

Instance Method Detail

def added_fabric_index : UInt8 | Nil #

Whether a new fabric was added during this context


[View source]
def added_fabric_index=(added_fabric_index : UInt8 | Nil) #

Whether a new fabric was added during this context


[View source]
def arm(expiry_length : UInt16, max_cumulative : UInt16) : Nil #

Arm the failsafe timer with specified durations

@param expiry_length Primary timer duration in seconds (0 = disarm) @param max_cumulative Maximum cumulative duration in seconds


[View source]
def armed? : Bool #

Check if the failsafe timer is currently armed


[View source]
def associated_fabric_index : UInt8 | Nil #

Fabric index associated with this context (nil for PASE/initial commissioning)


[View source]
def associated_fabric_index=(associated_fabric_index : UInt8 | Nil) #

Fabric index associated with this context (nil for PASE/initial commissioning)


[View source]
def breadcrumb : UInt64 #

Breadcrumb value for progress tracking


[View source]
def breadcrumb=(breadcrumb : UInt64) #

Breadcrumb value for progress tracking


[View source]
def close : Nil #

Close and cleanup the failsafe context

Should be called when context is destroyed.


[View source]
def csr_nonce : Bytes | Nil #

CSR nonce for pairing (tracks session ID)


[View source]
def csr_nonce=(csr_nonce : Bytes | Nil) #

CSR nonce for pairing (tracks session ID)


[View source]
def cumulative_time_remaining : Time::Span | Nil #

Get time remaining on cumulative timer


[View source]
def disarm : Nil #

Disarm the failsafe timer (mark as completed without triggering rollback)


[View source]
def for_update_noc : Bool #

Whether this is for updating an existing NOC (vs adding new)


[View source]
def for_update_noc=(for_update_noc : Bool) #

Whether this is for updating an existing NOC (vs adding new)


[View source]
def mark_for_update_noc : Nil #

Mark this context as being for UpdateNOC (vs AddNOC)


[View source]
def matches_fabric?(fabric_index : UInt8 | Nil) : Bool #

Validate that fabric index matches this context

@param fabric_index Fabric index to validate @return true if matches, false otherwise


[View source]
def max_cumulative_seconds : UInt16 #

Maximum cumulative failsafe timeout (hard limit)


[View source]
def max_cumulative_seconds=(max_cumulative_seconds : UInt16) #

Maximum cumulative failsafe timeout (hard limit)


[View source]
def network_state_snapshot : Hash(String, String) | Nil #

Network commissioning state snapshot (for rollback)


[View source]
def network_state_snapshot=(network_state_snapshot : Hash(String, String) | Nil) #

Network commissioning state snapshot (for rollback)


[View source]
def noc_update_snapshot : Tuple(UInt8, Bytes, Bytes) | Nil #

NOC update snapshot (for UpdateNOC rollback) Stores: (fabric_index, operational_cert, operational_key)


[View source]
def noc_update_snapshot=(noc_update_snapshot : Tuple(UInt8, Bytes, Bytes) | Nil) #

NOC update snapshot (for UpdateNOC rollback) Stores: (fabric_index, operational_cert, operational_key)


[View source]
def primary_time_remaining : Time::Span | Nil #

Get time remaining on primary timer


[View source]
def record_added_fabric(fabric_index : UInt8) : Nil #

Record that a new fabric was added during commissioning

This will be rolled back if failsafe expires.


[View source]
def record_csr_nonce(nonce : Bytes) : Nil #

Record CSR nonce for session tracking

@param nonce CSR nonce bytes


[View source]
def record_network_state(state : Hash(String, String)) : Nil #

Record network commissioning state for rollback

@param state Snapshot of network configuration


[View source]
def record_noc_update(fabric_index : UInt8, operational_cert : Bytes, operational_key : Bytes) : Nil #

Record NOC state before UpdateNOC for rollback

@param fabric_index Fabric index being updated @param operational_cert Current operational certificate @param operational_key Current operational private key


[View source]
def record_regulatory_config(location_type : UInt8, country_code : String) : Nil #

Record regulatory config state for rollback

@param location_type Current regulatory location type (as UInt8) @param country_code Current country code (2-character string)


[View source]
def record_root_cert(cert : Bytes) : Nil #

Record root certificate for validation

@param cert Root certificate bytes


[View source]
def regulatory_config_snapshot : Tuple(UInt8, String) | Nil #

Regulatory config snapshot (for rollback)


[View source]
def regulatory_config_snapshot=(regulatory_config_snapshot : Tuple(UInt8, String) | Nil) #

Regulatory config snapshot (for rollback)


[View source]
def rollback(fabric_manager : FabricManager | Nil = nil, session_manager : SessionManager | Nil = nil, network_commissioning : Cluster::NetworkCommissioningCluster | Nil = nil, commissioning_window : CommissioningWindow | Nil = nil, general_commissioning : Cluster::GeneralCommissioningCluster | Nil = nil) : Nil #

Perform complete rollback of all commissioning state

This implements the 9-step rollback sequence from Matter spec:

  1. Revoke added fabric (if AddNOC was used)
  2. Revert UpdateNOC changes
  3. Restore network commissioning state
  4. Clear PASE sessions
  5. Reset breadcrumb to 0
  6. Close commissioning windows
  7. Clear CSR session
  8. Reset regulatory config
  9. Clean up temporary state

@param fabric_manager FabricManager for fabric operations @param session_manager SessionManager for PASE cleanup @param network_commissioning NetworkCommissioning cluster for network state restoration @param commissioning_window For closing windows @param general_commissioning GeneralCommissioning cluster for regulatory config reset


[View source]
def root_cert : Bytes | Nil #

Root certificate bytes (for validation)


[View source]
def root_cert=(root_cert : Bytes | Nil) #

Root certificate bytes (for validation)


[View source]