In development. It changes without notice.
Topic
State Context & Shared Flows
What every state handler shares: the context and its sleep path, the handler's interface, and the flows that several states run.
Those flows are the pairing prompt, the choice of a host, the page that adds a host, and the binding of the unlock entry to the vault. They take the context; what can do without it is in Shared Screen Parts or State Rules.
Files | |
| file | src/ |
| Shared mutable application context passed between FSM state handlers. | |
| file | src/ |
Thin seam exposing the few main.cpp-local runtime symbols that the serial console of a debug build needs. | |
| file | src/ |
| Abstract interface implemented by every FSM state handler. | |
| file | src/ |
| The numeric-comparison prompt every pairing surface shows, and the pairing-window state they all read. | |
| file | src/ |
Shared chrome, geometry, constants, and debug fixtures for the two BLE host screens extracted from HomeStateHandler. | |
| file | src/ |
| Settings' add-host page: opens the pairing window for one more host. | |
| file | src/ |
| How a board's keys drive its secret's entry, the same on every screen that asks for it. | |
Classes | |
| struct | kleidos:: |
| All shared mutable state and hardware references exchanged between FSM state handlers. Constructed once in main.cpp and passed by reference. More about kleidos:: | |
| class | kleidos:: |
| Lifecycle interface for a single FSM state; subclasses own one screen flow. More about kleidos:: | |
| class | kleidos:: |
| Settings' add-host page: owns one pairing-window session. More about kleidos:: | |
Typedefs | |
| using | kleidos:: |
| What the owner answered the numeric-comparison prompt (pair_ | |
Enumerations | |
| enum class | kleidos:: |
| What one tick of the add-host page decided. More about kleidos:: | |
| enum class | kleidos:: |
| Which keys drive a board's secret entry. More about kleidos:: | |
| enum class | kleidos:: |
| What pollCountedEntryKeys read from the keys around a counted entry. More about kleidos:: | |
Functions | |
| void | kleidos:: |
Zeroize the session row cache (defined in cred_). | |
| void | kleidos:: |
Refill the session row cache from the open vault's list index (defined in cred_). | |
| void | kleidos:: |
Drop the vault facade's copy of the session key material (defined in app_). | |
| AppContext & | kleidos:: |
| Reference to the file-scoped AppContext singleton (valid after setup()). | |
| AppStateHandler * | kleidos:: |
| Resolve the FSM handler for a state, or nullptr for transient states. | |
| void | kleidos:: |
Run the exit/enter transition between FSM states: exit the current handler, swap appState, enter the new handler and take its entry step. | |
| const char * | kleidos:: |
| Uppercase debug name of an application state. | |
| const char * | kleidos:: |
| Uppercase debug name of a BLE stack state. | |
| PairPromptResult | kleidos:: |
| Show the numeric-comparison prompt when one is pending, and answer it. | |
| BleLink | kleidos:: |
| What the link is doing, as every pairing surface shows it. | |
| bool | kleidos:: |
| Whether a pairing is in flight. | |
| bool | kleidos:: |
| Whether the radio will admit nothing more. | |
| bool | kleidos:: |
| Stop the Bluetooth stack if any part of it is still up. | |
| ui:: | kleidos:: |
| const char * | kleidos:: |
| The bond manager's title: "BLE hosts" where it fits, "Hosts" on the narrow Stick header. | |
| bool | kleidos:: |
| Whether the host screens draw the header back chip: on the boards that draw their own touch controls. | |
| int16_t | kleidos:: |
| Header band height for the host screens (no subtitle; the back chip raises it to the tap floor where it is drawn). | |
| ui::Rect | kleidos:: |
| The header back chip's hit box (empty where no chip is drawn). | |
| ui::Rect | kleidos:: |
| Body rect between the header and the footer shelf the list draws into, ending above the first row the pointer does not own. | |
| ui:: | kleidos:: |
Header props shared by every host frame: brand mark + the picker's "Send to…" title plus the live status cluster (the bond manager swaps in bondListTitle or the host's name). | |
| constexpr PinEntryBinding | kleidos:: |
| Pick the keys that drive a board's secret entry. | |
| PinEntryBinding | kleidos:: |
| The keys that drive this board's secret entry. | |
| ButtonInput & | kleidos:: |
| The key a PIN is dialed with on this board. | |
| void | kleidos:: |
| Start the secret's entry the way this board enters it. | |
| ui:: | kleidos:: |
| The brute-force lockout, as an entry that counts a wrong secret reads it: the seconds it holds and why. | |
| void | kleidos:: |
| Close an entry surface: wipe what it collected and release what beginPinEntry holds for it. | |
| bool | kleidos:: |
| Whether someone is driving an input on this tick: a key, a button the board maps, or a finger on the glass. | |
| bool | kleidos:: |
| Clear the entered digits on a ▲ press, where ▲ clears (the CoreInk dial). | |
| bool | kleidos:: |
| Read ▲ and clear the entered digits, where ▲ clears (the CoreInk dial). | |
| EntryKeys | kleidos:: |
| Read the keys a counted entry outside the unlock screen shares with it. | |
Variables | |
| std::array< CredentialEntry, kMaxCredentials > | kleidos:: |
Backing store for AppContext::. | |
| std::array< CredentialEntry, kMaxTotp > | kleidos:: |
Backing store for AppContext::. | |
| OnboardingStateHandler * | kleidos:: |
| Live onboarding handler (button-driven variants only). | |
| constexpr uint8_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| constexpr int16_t | kleidos:: |
| constexpr int16_t | kleidos:: |
Enumeration Type Documentation
EntryKeys #
What pollCountedEntryKeys read from the keys around a counted entry.
PairHostResult #
What one tick of the add-host page decided.
| Enumerator | |
|---|---|
| Stay | The page keeps the frame (and the radio). |
| Paired | A new host bonded; PairHostPage:: |
| Cancelled | The owner left the page. |
| TimedOut | Nothing paired before the page gave up. |
| ListFull | The table is full; the radio was never started. |
| RadioFailed | Bluetooth would not start. |
PinEntryBinding #
Which keys drive a board's secret entry.
Function Documentation
appStateName() #
Uppercase debug name of an application state.
Used by the serial debug log line and the debug console's state command to print the active FSM state in human-readable form. The mapping is one-to-one with the AppState enum.
- Parameters
-
Name Direction Meaning state in State to name.
- Returns
- Static, NUL-terminated uppercase name (e.g. "PIN_ENTRY"), or "UNKNOWN" for out-of-range values.
arcKey() #
The key a PIN is dialed with on this board.
- Parameters
-
Name Direction Meaning ctx in The application context.
- Returns
- The center press on the CoreInk dial, the primary key elsewhere.
beginPinEntry() #
Start the secret's entry the way this board enters it.
Where the entry method has a shake gesture (the dial's shake-to-clear, AuthEntryUI::) it also holds the IMU for it, powered and behind its motion gate (ShakeDetector::), and hands the entry the detector as its samples: the shake-to-lock gesture, which owns the sensor's power and is off by default in every debug build, would otherwise leave it suspended under a reader that cannot see that, and a read made past the detector would be one the main loop's idle rule does not know of. An entry method without the gesture (the touch keyboard, the passphrase) holds nothing. The hold is a single slot rather than a count: one AuthEntryUI exists, so at most one entry surface is live, and a flow that re-opens entry per step (change of secret, re-encryption) must not take a hold per step. endPinEntry releases it.
- Parameters
-
Name Direction Meaning ctx in, out The application context (its entry UI and keys). verify in Called with the entered secret. lockout in Returns the remaining lockout, or null for none.
- See also
- endPinEntry
bleLinkNow() #
What the link is doing, as every pairing surface shows it.
Read from the stack's published state, so a surface that repaints right after the owner answered the prompt shows a host that is still pairing as pairing (BleLink::), never as the page it showed before a host came: the answer returns only once the state it leaves is published.
- Returns
Connectedwhile a host holds the link,Pairingwhile one is pairing,Visibleotherwise.
blePairingInFlight() #
Whether a pairing is in flight.
True while a numeric comparison is pending, and while a link is up that has not authenticated yet — the window between an accepted prompt and the bond. A surface that closes its pairing window on a clock must hold while this is true, or it cuts the bond it asked the owner for.
- Returns
- Whether a pairing is under way.
bleRadioSpent() #
Whether the radio will admit nothing more.
True when the stack never came up (a failed or vetoed start) and when its advertising budget is spent, which leaves the stack initialized but silent. A pairing page with nothing linked and nothing pairing has no reason to wait past that point.
- Returns
- Whether nothing more can connect.
bleStackStateName() #
Uppercase debug name of a BLE stack state.
Used by the serial debug log line that fires on every BLE-state transition. The mapping is one-to-one with the kleidos:: enum.
- Parameters
-
Name Direction Meaning state in BLE stack state to name.
- Returns
- Static, NUL-terminated uppercase name, or "UNKNOWN" for out-of-range values.
boardBinding() #
The keys that drive this board's secret entry.
- Parameters
-
Name Direction Meaning ctx in The application context (its third key, if any).
- Returns
- The binding pinEntryBindingFor picks for this board.
bondListTitle() #
The bond manager's title: "BLE hosts" where it fits, "Hosts" on the narrow Stick header.
- Parameters
-
Name Direction Meaning layout in Active layout context.
- Returns
- The localized title.
clearOnUpPress() #
Clear the entered digits on a ▲ press, where ▲ clears (the CoreInk dial).
- Parameters
-
Name Direction Meaning ctx in, out The application context. upPressed in True when ▲ was pressed this frame.
- Returns
- True when the digits were cleared.
ctx() #
Reference to the file-scoped AppContext singleton (valid after setup()).
Return a reference to the file-scoped AppContext singleton (valid after setup()).
- Returns
- Reference to the shared application context.
dropVaultSessionKeys() #
Drop the vault facade's copy of the session key material (defined in app_).
The facade keeps the key it last unlocked with, the kleidos-enc / kleidos-mac sub-keys derived from it and the authenticated meta.bin snapshot, so a list read does not re-derive them per unit. Wiping VaultSession:: leaves that copy in RAM. Runs VaultStore::, which wipes it on the vault worker, after any vault call already in flight rather than under it.
Declared here rather than reached through the vault facade (vault_store.h), which is heavy: every file including this header would parse it. AppContext::
- See also
- VaultStore::
invalidateSession
endPinEntry() #
Close an entry surface: wipe what it collected and release what beginPinEntry holds for it.
The entry forgets everything entered on it (AuthEntryUI::), so an abandoned prompt, by whatever route the state was left, keeps neither a half-entered secret nor the last digit of a whole one. Then the IMU hold goes. Idempotent, so a state whose exit runs without an entry surface having opened costs nothing, and a surface left by an unusual path (a debug console's jump, a lock-out) cannot leak the hold or the digits. Called from the exit() of every state that can host one: the unlock screen itself, HOME (which hosts the change-PIN and re-encryption flows and the backup passphrase prompts) and first-run setup.
- Parameters
-
Name Direction Meaning ctx in, out The application context.
- See also
- beginPinEntry
fillCredRowCache() #
Refill the session row cache from the open vault's list index (defined in cred_).
The second half of the same inversion as wipeCredRowCache, and for the same reason: cred_ includes THIS header, so the dependency only works in this direction. AppContext::
- Parameters
-
Name Direction Meaning ctx in, out Context whose list the cache is keyed against. tick in Between-unit paint slot, or nullptrfor none.
- See also
- CredRowCache::
fillFromOpenVault
getHandler() #
Resolve the FSM handler for a state, or nullptr for transient states.
Return the FSM handler for the given application state, or nullptr.
Called by the dispatcher in loop() to translate ctx().appState into the live handler pointer. Returns nullptr for transient / terminal states (e.g. AppState::) that have no live handler; the dispatcher treats a nullptr return as a hard error and falls into goToSleep().
- Parameters
-
Name Direction Meaning state in Application state to resolve.
- Returns
- Pointer to the active handler, or
nullptrfor unhandled states.
- See also
- appStateName(), currentDebugScreenName()
hostBackHit() #
The header back chip's hit box (empty where no chip is drawn).
- Parameters
-
Name Direction Meaning layout in Active layout context.
- Returns
- The rect a tap on the chip answers in.
hostBodyRect() #
Body rect between the header and the footer shelf the list draws into, ending above the first row the pointer does not own.
- Parameters
-
Name Direction Meaning layout in Active layout context (screen geometry).
- Returns
- The list body rectangle between the header and footer bands.
hostHeaderH() #
Header band height for the host screens (no subtitle; the back chip raises it to the tap floor where it is drawn).
- Parameters
-
Name Direction Meaning layout in Active layout context (screen geometry).
- Returns
- Header band height in pixels.
hostRowSize() #
Host row density: label + MAC sub-line. On a 1-bit panel the list's own row (the name at body size, like every other list there), and on the short keyboard panel the compact row so two hosts show at once; elsewhere the roomy density, fewer per screen.
- Parameters
-
Name Direction Meaning layout in Responsive context.
- Returns
- The row size host lists draw with.
hostSelectHeaderProps() #
Header props shared by every host frame: brand mark + the picker's "Send to…" title plus the live status cluster (the bond manager swaps in bondListTitle or the host's name).
- Parameters
-
Name Direction Meaning ctx in Application context (battery / BLE status for the cluster).
- Returns
- Populated header props for a host screen frame.
hostShowsBack() #
Whether the host screens draw the header back chip: on the boards that draw their own touch controls.
- Parameters
-
Name Direction Meaning layout in Active layout context.
- Returns
truewhere the chip is drawn.
inputActive() #
Whether someone is driving an input on this tick: a key, a button the board maps, or a finger on the glass.
For a prompt that has to tell someone who is typing from someone who walked away (entry_
- Return values
-
Value Meaning true A key waits to be read, a button is down or the glass is touched. false No input.
lockoutStatus() #
The brute-force lockout, as an entry that counts a wrong secret reads it: the seconds it holds and why.
Every counted entry (the unlock screen, Change PIN's current secret, Re-encrypt's proof, the vault-only wipe's confirm) passes this as its lockout callback, so a lockout in force refuses input and counts down on every one of them. While a lock holds because the build binds the vault to a device key this chip does not hold, the cause is named instead of a countdown that never runs (lockout_
A surface asks on every tick, and the guard is not read on every one of them: on a build that binds the attempt counter to the device a read drives the hardware SHA/AES engines, and a sound that is playing gives way to each use of them. The read is made when a surface opens, when the guard's record has changed (a counted wrong secret, a reset, a lock cleared) and twice a second while a lock holds; the last read answers in between (lockout_
- Returns
- The lockout read; 0 seconds when no lockout is active.
pinEntryBindingFor() #
Pick the keys that drive a board's secret entry.
- Parameters
-
Name Direction Meaning epaper in True on the e-paper dial board. hasThirdButton in True when the board wires a third navigation key. keyboard in True on a keyboard board.
- Returns
- The board's binding.
pollArcClear() #
Read ▲ and clear the entered digits, where ▲ clears (the CoreInk dial).
Reads ▲ only on that board, so the key stays untouched elsewhere.
- Parameters
-
Name Direction Meaning ctx in, out The application context.
- Returns
- True when the digits were cleared.
pollCountedEntryKeys() #
Read the keys a counted entry outside the unlock screen shares with it.
Change PIN's current-secret step and the vault wipe's prompt answer the same keys the unlock screen does, so a mis-dialed digit can be cleared instead of submitted as a counted failure:
- the dedicated back key (AppContext::
consumeBack) backs out; - the CoreInk dial's ▲ clears the digits (pollArcClear);
- on two buttons, a B hold backs out and a B tap clears the digits.
Reads B only on the two-button boards, where the dial holds A; elsewhere B belongs to the entry.
- Parameters
-
Name Direction Meaning ctx in, out The application context.
- Returns
- EntryKeys::
Back when the entry was backed out of; otherwise EntryKeys:: None, with any clear already applied.
showBlePairPrompt() #
Show the numeric-comparison prompt when one is pending, and answer it.
Blocks on the modal until the owner answers or it lapses, then resolves the request either way: an unanswered request is refused by the stack after 30 s and the host's pairing fails. The modal closes at once when the request stops pending without it (the debug console answered it, or the stack let it go): that answer stands, the prompt tells the stack nothing more, and it returns that answer, so every surface reacts to a console answer as to the same answer on the glass. The passkey is zeroized once it is drawn.
- Parameters
-
Name Direction Meaning confirmBtn in, out The caller's A slot, which accepts. cancelBtn in, out The caller's B slot, which refuses (may be null).
- Returns
- What was answered, or
NotAskedwhen no request was pending.
stopBleRadio() #
Stop the Bluetooth stack if any part of it is still up.
The call a surface that owns a pairing window makes when it closes it. Blocks for up to 1.5 s inside the facade's teardown; a stack already off costs nothing.
- Return values
-
Value Meaning true Something was running and the teardown completed. false Nothing was running, or the teardown timed out.
transitionTo() #
Run the exit/enter transition between FSM states: exit the current handler, swap appState, enter the new handler and take its entry step.
Defined by the serial console (debug_), which runs between the main loop's ticks, outside every frame, so it takes the entering state's entry step (AppStateHandler:: the admin portal's bring-up) right after enter(), as the state's first update() would take it: a command that moved to a state and reads what its entry did (the console's LAN portal command, a power-measurement run's admin phase) reads it done.
- Parameters
-
Name Direction Meaning target in State to transition into.
- Note
- Updates
ctx().prevState as a side effect.
wipeCredRowCache() #
Zeroize the session row cache (defined in cred_).
Declared here rather than included: cred_ includes THIS header, so the dependency only works in this direction. AppContext::
- See also
- CredRowCache::
reset
Variable Documentation
kHostFooterH #
Reserved footer band for the host screens' ActionBar shelf. Matches the band the vault menu / settings reserve so the content geometry is identical.
kHostMacChars #
Sizes each per-row sub-line buffer. Both host screens write the same thing there — the address's last three octets, enough to tell two bonds apart on a 135 px row — or, on a narrow row, the live link's own word, which is longer than an address in some languages.
kHostMaxBonds #
Bond-table capacity (mirrors ble::). Both host screens materialize at most this many bonded-host rows.
kHostNameChars #
Sizes each row's own copy of the host's name. A row's label points into this copy, never into the bond record it was read from, which lives only as long as the loop that read it. It holds the bond table's whole name (ble::, checked where the rows are built).
kNarrowTitleWidthPx #
Widest panel that takes the short host-list title ("Hosts"): the 135 px Stick header beside the brand mark.
s_ menuCredEntries #
Backing store for AppContext::.
The two menu arrays are the only capacity-scaled statics in AppContext, and they are the reason the storage lives out here instead of inside the struct: a section attribute applies to a whole VARIABLE, never to one member, so the only way to park them in external RAM would be to tag the enclosing AppContext — which also holds VaultSession:: and the staged plaintext VaultSession::. MenuModel therefore holds these two objects by reference and AppContext itself stays in internal DRAM by construction.
- Warning
- SECURITY: this array may be PSRAM-resident (see KLEIDOS_
EXT_ RAM_ BSS_ DEFINE). It holds credential DISPLAY NAMES, ids and list ordering only — no password, no key material. Never widen CredentialEntrywith secret-bearing fields, and never moveVaultSessionnext to it.
- See also
- AppContext::
wipeVaultSession
s_ menuTotpEntries #
Backing store for AppContext::.
Same rationale, security boundary and lifetime as s_CredentialEntry (id + display name), NOT TotpEntry — the TOTP shared secret is never part of the menu model.