|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#include <TropicStorage.h>
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 |
Definition at line 9 of file TropicStorage.h.
| using cdc::core::TropicStorage::RebuildLogFn = void(*)(uint16_t slot, const char* message, void* ctx) |
Definition at line 21 of file TropicStorage.h.
| using cdc::core::TropicStorage::SlotCallback = void(*)(uint16_t slot, const CacheEntry& entry, void* ctx) |
Definition at line 20 of file TropicStorage.h.
| struct cdc::core::TropicStorage::CacheEntry cdc::core::TropicStorage::__attribute__ | ( | (packed) | ) |
| bool cdc::core::TropicStorage::cleanup | ( | ) |
Removes cache entries and chip records that violate slot/module mapping.
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().
| bool cdc::core::TropicStorage::eraseSlot | ( | uint8_t | moduleId, |
| uint16_t | slot ) |
Clears cached metadata entry for one slot.
| moduleId | Module identifier owning the slot. |
| slot | Absolute R-MEM slot index. |
Definition at line 200 of file TropicStorage.cpp.
References moduleId.
Referenced by cdc::mod_2fa::OathStore::deleteAccount(), and cdc::mod_password::PasswordStore::deleteEntry().
| bool cdc::core::TropicStorage::forEachSlot | ( | uint8_t | moduleId, |
| SlotCallback | cb, | ||
| void * | ctx ) |
Iterates all cached slots for one module across its allowed range.
| moduleId | Module identifier. |
| cb | Callback invoked per matching slot. |
| ctx | Opaque callback context. |
Definition at line 80 of file TropicStorage.cpp.
References forEachSlot(), and moduleId.
Referenced by cdc::mod_2fa::OathStore::clearUsbCrFlagExcept(), cdc::mod_2fa::cmd_totp_list(), cdc::mod_2fa::TwoFaModule::exportBackup(), cdc::mod_password::PasswordModule::exportBackup(), cdc::mod_2fa::OathStore::findByName(), cdc::mod_password::PasswordStore::findByTitle(), cdc::core::SlotManager::findFreeSlot(), cdc::mod_2fa::findSlotByIndex(), cdc::mod_2fa::OathStore::findUsbCrSlot(), forEachSlot(), cdc::mod_password::PasswordStore::listEntriesSorted(), and cdc::mod_2fa::rebuildList().
| 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.
| moduleId | Module identifier. |
| fromSlot | Inclusive start slot or 0 for module range start. |
| toSlot | Inclusive end slot or 0xFFFF for module range end. |
| cb | Callback invoked per matching slot. |
| ctx | Opaque callback context. |
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.
|
inlineoverridevirtual |
Get service name (for logging/debugging)
Implements cdc::core::IService.
Definition at line 30 of file TropicStorage.h.
| 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.
| moduleId | Module identifier. |
| index | Zero-based index within module slot range. |
| cb | Callback receiving resolved slot and entry. |
| ctx | Opaque callback context. |
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().
|
inlineoverridevirtual |
Get current service state
Implements cdc::core::IService.
Definition at line 29 of file TropicStorage.h.
Referenced by cdc::core::ModuleRegistry::runAllInitializers().
|
overridevirtual |
Initializes cache metadata and validates persisted cache header.
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().
|
static |
Returns singleton instance of TROPIC metadata cache manager.
Definition at line 21 of file TropicStorage.cpp.
Referenced by cdc::mod_password::PasswordStore::addEntry(), cdc::mod_2fa::OathStore::clearUsbCrFlagExcept(), cdc::mod_2fa::cmd_totp_list(), cdc::serial::cmdTr01CacheRebuild(), cdc::serial::cmdTr01Cleanup(), cdc::mod_2fa::OathStore::deleteAccount(), cdc::mod_password::PasswordStore::deleteEntry(), cdc::mod_2fa::TwoFaModule::exportBackup(), cdc::mod_password::PasswordModule::exportBackup(), cdc::mod_2fa::OathStore::findByName(), cdc::mod_password::PasswordStore::findByTitle(), cdc::core::SlotManager::findFreeSlot(), cdc::mod_2fa::findSlotByIndex(), cdc::mod_2fa::OathStore::findUsbCrSlot(), initTropicStorage(), cdc::mod_password::PasswordStore::listEntriesSorted(), cdc::mod_2fa::rebuildList(), cdc::core::ModuleRegistry::runAllInitializers(), cdc::ui::runTropicCacheCleanup(), cdc::ui::runTropicCacheRebuild(), cdc::mod_password::PasswordStore::updateEntry(), and cdc::mod_2fa::writePayload().
|
inline |
Definition at line 34 of file TropicStorage.h.
| bool cdc::core::TropicStorage::rebuild | ( | ) |
Rebuilds cache contents from secure-element R-MEM without verbose logging.
Definition at line 213 of file TropicStorage.cpp.
References rebuildVerbose().
Referenced by cleanup(), and cdc::ui::runTropicCacheRebuild().
| bool cdc::core::TropicStorage::rebuildVerbose | ( | RebuildLogFn | logFn, |
| void * | ctx ) |
Rebuilds cache contents from secure-element R-MEM with optional logging callback.
| logFn | Optional callback to receive per-slot progress/status strings. |
| ctx | Opaque callback context passed to logFn. |
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().
|
inline |
Definition at line 32 of file TropicStorage.h.
|
overridevirtual |
Starts cache service, initializing first if required.
Implements cdc::core::IService.
Definition at line 58 of file TropicStorage.cpp.
References init(), cdc::core::STARTED, and cdc::core::UNINITIALIZED.
Referenced by getSlot().
|
overridevirtual |
Stops cache service.
Implements cdc::core::IService.
Definition at line 69 of file TropicStorage.cpp.
References cdc::core::STOPPED.
| 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.
| moduleId | Module identifier owning the slot. |
| slot | Absolute R-MEM slot index. |
| name | Optional entry name. |
| flags | Entry flags. |
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().
|
staticconstexpr |
Definition at line 18 of file TropicStorage.h.
Referenced by cleanup(), forEachSlot(), init(), and rebuildVerbose().
|
staticconstexpr |
Definition at line 17 of file TropicStorage.h.
Referenced by rebuildVerbose(), and writeSlot().