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

#include <TropicStorage.h>

Inheritance diagram for cdc::core::TropicStorage:
cdc::core::IService

Classes

struct  CacheEntry

Public Types

using SlotCallback = void(*)(uint16_t slot, const CacheEntry& entry, void* ctx)
using RebuildLogFn = void(*)(uint16_t slot, const char* message, void* ctx)

Public Member Functions

struct cdc::core::TropicStorage::CacheEntry __attribute__ ((packed))
bool init () override
 Initializes cache metadata and validates persisted cache header.
bool start () override
 Starts cache service, initializing first if required.
void stop () override
 Stops cache service.
ServiceState getState () const override
const char * getName () const override
void setSecureElement (cdc::hal::ISecureElement *se)
bool isCacheValid () const
bool forEachSlot (uint8_t moduleId, SlotCallback cb, void *ctx)
 Iterates all cached slots for one module across its allowed range.
bool forEachSlot (uint8_t moduleId, uint16_t fromSlot, uint16_t toSlot, SlotCallback cb, void *ctx)
 Iterates cached slots for one module within optional slot bounds.
bool getSlot (uint8_t moduleId, uint16_t index, SlotCallback cb, void *ctx)
 Resolves one module-relative index to slot entry and invokes callback.
bool writeSlot (uint8_t moduleId, uint16_t slot, const char *name, uint8_t flags)
 Writes or updates cached metadata entry for one slot.
bool eraseSlot (uint8_t moduleId, uint16_t slot)
 Clears cached metadata entry for one slot.
bool rebuild ()
 Rebuilds cache contents from secure-element R-MEM without verbose logging.
bool rebuildVerbose (RebuildLogFn logFn, void *ctx)
 Rebuilds cache contents from secure-element R-MEM with optional logging callback.
bool cleanup ()
 Removes cache entries and chip records that violate slot/module mapping.
Public Member Functions inherited from cdc::core::IService
virtual ~IService ()=default

Static Public Member Functions

static TropicStorage & instance ()
 Returns singleton instance of TROPIC metadata cache manager.

Static Public Attributes

static constexpr uint8_t FLAG_USED = 0x01
static constexpr uint16_t CHUNK_SLOTS = 64

Detailed Description

Definition at line 9 of file TropicStorage.h.

Member Typedef Documentation

◆ RebuildLogFn

using cdc::core::TropicStorage::RebuildLogFn = void(*)(uint16_t slot, const char* message, void* ctx)

Definition at line 21 of file TropicStorage.h.

◆ SlotCallback

using cdc::core::TropicStorage::SlotCallback = void(*)(uint16_t slot, const CacheEntry& entry, void* ctx)

Definition at line 20 of file TropicStorage.h.

Member Function Documentation

◆ __attribute__()

struct cdc::core::TropicStorage::CacheEntry cdc::core::TropicStorage::__attribute__ ( (packed) )

◆ cleanup()

bool cdc::core::TropicStorage::cleanup ( )

Removes cache entries and chip records that violate slot/module mapping.

Returns
true on success, otherwise false.

Definition at line 287 of file TropicStorage.cpp.

References CHUNK_SLOTS, cdc::core::TropicSlotMap::instance(), LOG_E, LOG_W, cdc::core::TropicStorage::CacheEntry::moduleId, rebuild(), cdc::core::TropicSlotMap::rmemMax(), and TAG.

Referenced by cdc::ui::runTropicCacheCleanup().

◆ eraseSlot()

bool cdc::core::TropicStorage::eraseSlot ( uint8_t moduleId,
uint16_t slot )

Clears cached metadata entry for one slot.

Parameters
moduleIdModule identifier owning the slot.
slotAbsolute R-MEM slot index.
Returns
true on success, otherwise false.

Definition at line 200 of file TropicStorage.cpp.

References moduleId.

Referenced by cdc::mod_2fa::OathStore::deleteAccount(), and cdc::mod_password::PasswordStore::deleteEntry().

◆ forEachSlot() [1/2]

bool cdc::core::TropicStorage::forEachSlot ( uint8_t moduleId,
SlotCallback cb,
void * ctx )

◆ forEachSlot() [2/2]

bool cdc::core::TropicStorage::forEachSlot ( uint8_t moduleId,
uint16_t fromSlot,
uint16_t toSlot,
SlotCallback cb,
void * ctx )

Iterates cached slots for one module within optional slot bounds.

Parameters
moduleIdModule identifier.
fromSlotInclusive start slot or 0 for module range start.
toSlotInclusive end slot or 0xFFFF for module range end.
cbCallback invoked per matching slot.
ctxOpaque callback context.
Returns
true on success, otherwise false.

Definition at line 93 of file TropicStorage.cpp.

References CHUNK_SLOTS, cdc::core::TropicSlotMap::SlotRange::end, cdc::core::TropicSlotMap::instance(), cdc::core::TropicStorage::CacheEntry::moduleId, moduleId, cdc::core::TropicSlotMap::RMEM, and cdc::core::TropicSlotMap::SlotRange::start.

◆ getName()

const char * cdc::core::TropicStorage::getName ( ) const
inlineoverridevirtual

Get service name (for logging/debugging)

Implements cdc::core::IService.

Definition at line 30 of file TropicStorage.h.

◆ getSlot()

bool cdc::core::TropicStorage::getSlot ( uint8_t moduleId,
uint16_t index,
SlotCallback cb,
void * ctx )

Resolves one module-relative index to slot entry and invokes callback.

Parameters
moduleIdModule identifier.
indexZero-based index within module slot range.
cbCallback receiving resolved slot and entry.
ctxOpaque callback context.
Returns
true on success, otherwise false.

Definition at line 139 of file TropicStorage.cpp.

References cdc::core::TropicSlotMap::SlotRange::end, cdc::core::TropicSlotMap::instance(), cdc::core::TropicStorage::CacheEntry::moduleId, moduleId, cdc::core::TropicSlotMap::RMEM, cdc::core::TropicSlotMap::SlotRange::start, and start().

◆ getState()

ServiceState cdc::core::TropicStorage::getState ( ) const
inlineoverridevirtual

Get current service state

Implements cdc::core::IService.

Definition at line 29 of file TropicStorage.h.

Referenced by cdc::core::ModuleRegistry::runAllInitializers().

◆ init()

bool cdc::core::TropicStorage::init ( )
overridevirtual

Initializes cache metadata and validates persisted cache header.

Returns
true on success, otherwise false.

Implements cdc::core::IService.

Definition at line 30 of file TropicStorage.cpp.

References cdc::core::CACHE_VERSION, CHUNK_SLOTS, cdc::core::INITIALIZED, LOG_W, cdc::core::STARTED, TAG, and cdc::core::UNINITIALIZED.

Referenced by start().

◆ instance()

◆ isCacheValid()

bool cdc::core::TropicStorage::isCacheValid ( ) const
inline

Definition at line 34 of file TropicStorage.h.

◆ rebuild()

bool cdc::core::TropicStorage::rebuild ( )

Rebuilds cache contents from secure-element R-MEM without verbose logging.

Returns
true on success, otherwise false.

Definition at line 213 of file TropicStorage.cpp.

References rebuildVerbose().

Referenced by cleanup(), and cdc::ui::runTropicCacheRebuild().

◆ rebuildVerbose()

bool cdc::core::TropicStorage::rebuildVerbose ( RebuildLogFn logFn,
void * ctx )

Rebuilds cache contents from secure-element R-MEM with optional logging callback.

Parameters
logFnOptional callback to receive per-slot progress/status strings.
ctxOpaque callback context passed to logFn.
Returns
true on success, otherwise false.

Definition at line 223 of file TropicStorage.cpp.

References CHUNK_SLOTS, FLAG_USED, cdc::core::TropicStorage::CacheEntry::flags, cdc::core::TropicSlotMap::instance(), LOG_E, cdc::core::TropicStorage::CacheEntry::moduleId, cdc::core::TropicStorage::CacheEntry::name, cdc::hal::OK, cdc::core::TropicSlotMap::rmemMax(), cdc::hal::SLOT_EMPTY, and TAG.

Referenced by rebuild().

◆ setSecureElement()

void cdc::core::TropicStorage::setSecureElement ( cdc::hal::ISecureElement * se)
inline

Definition at line 32 of file TropicStorage.h.

◆ start()

bool cdc::core::TropicStorage::start ( )
overridevirtual

Starts cache service, initializing first if required.

Returns
true on success, otherwise false.

Implements cdc::core::IService.

Definition at line 58 of file TropicStorage.cpp.

References init(), cdc::core::STARTED, and cdc::core::UNINITIALIZED.

Referenced by getSlot().

◆ stop()

void cdc::core::TropicStorage::stop ( )
overridevirtual

Stops cache service.

Implements cdc::core::IService.

Definition at line 69 of file TropicStorage.cpp.

References cdc::core::STOPPED.

◆ writeSlot()

bool cdc::core::TropicStorage::writeSlot ( uint8_t moduleId,
uint16_t slot,
const char * name,
uint8_t flags )

Writes or updates cached metadata entry for one slot.

Parameters
moduleIdModule identifier owning the slot.
slotAbsolute R-MEM slot index.
nameOptional entry name.
flagsEntry flags.
Returns
true on success, otherwise false.

Definition at line 174 of file TropicStorage.cpp.

References FLAG_USED, cdc::core::TropicStorage::CacheEntry::flags, flags, cdc::core::TropicStorage::CacheEntry::moduleId, moduleId, cdc::core::TropicStorage::CacheEntry::name, and name.

Referenced by cdc::mod_password::PasswordStore::addEntry(), cdc::mod_password::PasswordStore::updateEntry(), and cdc::mod_2fa::writePayload().

Member Data Documentation

◆ CHUNK_SLOTS

uint16_t cdc::core::TropicStorage::CHUNK_SLOTS = 64
staticconstexpr

Definition at line 18 of file TropicStorage.h.

Referenced by cleanup(), forEachSlot(), init(), and rebuildVerbose().

◆ FLAG_USED

uint8_t cdc::core::TropicStorage::FLAG_USED = 0x01
staticconstexpr

Definition at line 17 of file TropicStorage.h.

Referenced by rebuildVerbose(), and writeSlot().


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