CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::core::SystemLock Class Reference

Global lockdown latch. More...

#include <SystemLock.h>

Public Types

using ShutdownHandler = void (*)(LockdownReason reason, const char* detail)
 UI handler invoked from main context just before deep sleep.

Public Member Functions

bool isLocked () const
 Returns true once a lockdown has been latched.
LockdownReason getReason () const
 Reason captured at the first triggerLockdown call.
const char * getDetail () const
 Returns the optional detail string captured at the first triggerLockdown call, or nullptr if none was provided. Caller must ensure pointed-to memory has static lifetime.
void triggerLockdown (LockdownReason reason, const char *detail=nullptr)
 Latches the lockdown flag. Idempotent and ISR-safe.
void setShutdownHandler (ShutdownHandler handler)
 Installs an optional UI handler invoked just before deep sleep. Must be set from main task before main loop starts polling.
void enforceIfLocked ()
 If locked, runs the shutdown sequence and never returns. Otherwise returns immediately. Call from main loop top.

Static Public Member Functions

static SystemLock & instance ()
 Returns the process-wide lockdown latch singleton.

Detailed Description

Global lockdown latch.

Any task may call triggerLockdown to mark the system as compromised. The lockdown is monotonic: once set it cannot be cleared except by a power cycle / hard reset.

The main loop calls enforceIfLocked at the top of every iteration to perform the shutdown sequence: optional UI handler (drawn from main context) then esp_deep_sleep_start with no wake source enabled. Other tasks check isLocked to fail-fast their own operations.

Definition at line 31 of file SystemLock.h.

Member Typedef Documentation

◆ ShutdownHandler

using cdc::core::SystemLock::ShutdownHandler = void (*)(LockdownReason reason, const char* detail)

UI handler invoked from main context just before deep sleep.

Definition at line 34 of file SystemLock.h.

Member Function Documentation

◆ enforceIfLocked()

void cdc::core::SystemLock::enforceIfLocked ( )

If locked, runs the shutdown sequence and never returns. Otherwise returns immediately. Call from main loop top.

Main-loop poll. Runs the shutdown sequence if the latch is set.

Definition at line 53 of file SystemLock.cpp.

Referenced by runMainLoopIteration().

◆ getDetail()

const char * cdc::core::SystemLock::getDetail ( ) const
inline

Returns the optional detail string captured at the first triggerLockdown call, or nullptr if none was provided. Caller must ensure pointed-to memory has static lifetime.

Definition at line 49 of file SystemLock.h.

◆ getReason()

LockdownReason cdc::core::SystemLock::getReason ( ) const
inline

Reason captured at the first triggerLockdown call.

Definition at line 42 of file SystemLock.h.

◆ instance()

◆ isLocked()

bool cdc::core::SystemLock::isLocked ( ) const
inline

Returns true once a lockdown has been latched.

Definition at line 39 of file SystemLock.h.

◆ setShutdownHandler()

void cdc::core::SystemLock::setShutdownHandler ( ShutdownHandler handler)

Installs an optional UI handler invoked just before deep sleep. Must be set from main task before main loop starts polling.

Stores the UI shutdown handler pointer.

Parameters
handlerFunction pointer, or nullptr to clear.
handlerHandler invoked once from main context before deep sleep.

Definition at line 46 of file SystemLock.cpp.

Referenced by initDisplay().

◆ triggerLockdown()

void cdc::core::SystemLock::triggerLockdown ( LockdownReason reason,
const char * detail = nullptr )

Latches the lockdown flag. Idempotent and ISR-safe.

Latches the lockdown flag. Idempotent.

Parameters
reasonReason to record; ignored if already locked.
detailOptional pointer to a string literal with static lifetime describing the specific failure (for example lt_ret_verbose(ret) or "PSA Crypto init failed").
reasonReason recorded only on the first call.
detailOptional static-lifetime string with extra context.

Definition at line 30 of file SystemLock.cpp.

References LOG_E, and TAG.

Referenced by checkBuildProfileAndWipeNvs(), and cdc::hal::Tropic01Element::init().


The documentation for this class was generated from the following files: