In development. It changes without notice.
Topic
Network Services
The time from the network, the Wi-Fi session that fetches it, the portal's network name, and the request for the portal after a restart.
- The time is one answer of a time server, over a Wi-Fi network saved in the vault, and only when the owner asks, on leaving the portal, or where a code was refused for want of the time. Network time is not authenticated: an answer outside sane bounds is refused, a step backward is refused while a lockout runs, and the clock's trust never rises.
- The session (kleidos::
net:: WifiStaSessionGuard) shuts Bluetooth down, joins the network, and restores both on every way out. - The portal's network name and password are kept until the owner changes them or a factory reset erases them.
- The request for the portal outlives a restart and is used by the next unlock, once. It opens nothing by itself.
Files | |
| file | src/ |
| Implementation of the admin access-point identity policy. | |
| file | src/ |
| Where the admin access point's SSID and password come from. | |
| file | src/ |
| One-shot WiFi-station + NTP clock-sync engine (async, worker-driven). | |
| file | src/ |
| Pure decision logic for the NTP clock sync (host-testable core). | |
| file | src/ |
| RTC-persisted flag that routes the next boot directly to admin mode. | |
| file | src/ |
| Which Bluetooth session, if any, the Wi-Fi station session gives back when it ends. | |
| file | src/ |
| Which access points a clock sync tries, in which order, and for how long. | |
| file | src/ |
| RAII guard for a transient WiFi-station session with BLE exclusivity. | |
Classes | |
| struct | kleidos:: |
| Read-only snapshot of the running (or last) sync, safe to poll from any task. More about kleidos:: | |
| struct | kleidos:: |
| One access point a scan heard, reduced to what the plan needs. More about kleidos:: | |
| struct | kleidos:: |
| One access point the plan says to try. More about kleidos:: | |
| class | kleidos:: |
| RAII transient STA session: BLE off on entry, WiFi off + BLE restored on exit. More about kleidos:: | |
Functions | |
| bool | kleidos:: |
| Whether the owner has pinned the access point's identity. | |
| bool | kleidos:: |
| Read the pinned identity. | |
| bool | kleidos:: |
Pin the access point to ssid and password. | |
| bool | kleidos:: |
| Stop pinning the identity and go back to a random password per session. | |
| bool | kleidos:: |
| Ask for the next session's password to be kept as the fixed one. | |
| bool | kleidos:: |
| Whether a pin request is waiting for the next password draw. | |
| bool | kleidos:: |
| Drop a pending pin request. | |
| bool | kleidos:: |
| Remember the live password so it survives an OTA reboot. | |
| bool | kleidos:: |
| Take the password carried across an OTA reboot, if there is one. | |
| bool | kleidos:: |
| Forget every admin access-point identity this device holds. | |
| constexpr bool | kleidos:: |
| True for a phase the engine ends in (Done, Failed, Cancelled). | |
| constexpr uint8_t | kleidos:: |
| Progress-bar percent for a sync phase. | |
| bool | kleidos:: |
| Arm and start a one-shot sync on the Core-0 worker. | |
| void | kleidos:: |
| Request cancellation of the running sync (idempotent). | |
| bool | kleidos:: |
| True while a sync is running (non-terminal phase). | |
| Status | kleidos:: |
| Copy the current status snapshot. | |
| const char * | kleidos:: |
| Compact console label for a FailReason. | |
| constexpr bool | kleidos:: |
| True when an NTP response epoch lies in the plausible window. | |
| constexpr bool | kleidos:: |
| True when a (plausible) NTP epoch may be committed to the clock. | |
| void | kleidos:: |
| Arm the pending-admin flag in RTC memory. | |
| bool | kleidos:: |
| True while the pending-admin flag is set. | |
| bool | kleidos:: |
| One-shot read: returns true if the flag was set, and clears it so that subsequent boots take the normal unlock → Home path. | |
| constexpr bool | kleidos:: |
| Whether an owner started or stopped the radio while the station session ran. | |
| constexpr BleRestore | kleidos:: |
| What the station session gives back of the Bluetooth session it stopped. | |
| constexpr size_t | kleidos:: |
| Order the access points a sync should try. | |
| constexpr uint32_t | kleidos:: |
| How long the next join attempt may take, given what the phase has spent. | |
Variables | |
| constexpr size_t | kleidos:: |
| Longest accepted SSID, plus the terminator. | |
| constexpr size_t | kleidos:: |
| Longest accepted password, plus the terminator: a Wi-Fi passphrase is at most 63 characters. | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Number of Phase values (the enumerators are dense from 0). | |
| constexpr std::array< uint8_t, kPhaseCount > | kleidos:: |
| Coarse progress-bar fill per Phase, indexed by its value. | |
| constexpr size_t | kleidos:: |
| Buffer sizes for the status snapshot's text fields. | |
| constexpr size_t | kleidos:: |
| Dotted IPv4 + NUL. | |
| constexpr uint32_t | kleidos:: |
| Magic value written to RTC slow memory to request admin mode after reboot. | |
| constexpr size_t | kleidos:: |
| Length of an 802.11 basic service set identifier (an access point's MAC). | |
| constexpr size_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| A scan hit that matches no saved network, and an attempt that names none. | |
Enumeration Type Documentation
BleRestore #
FailReason #
Why a sync ended in Phase::Failed.
| Enumerator | |
|---|---|
| None | Not failed. |
| Busy | Reserved label; a busy begin() leaves the running sync's status untouched. |
| NoSavedNetworks | The encrypted WiFi store is empty (or vault locked). |
| BleStopFailed | BLE teardown timed out; WiFi was never started. |
| NoVisibleNetwork | No saved SSID was found in the scan results. |
| WifiJoinFailed | Every access point the plan tried failed to associate or to lease an address inside the joining phase's budget. Status:: |
| NoServerResponse | No configured server answered within its window. |
| TimeRejected | Response(s) arrived but failed the sanity gates. |
| Internal | Worker spawn or another internal error. |
Phase #
Lifecycle phase of a one-shot NTP clock sync.
| Enumerator | |
|---|---|
| Idle | No sync ever started (terminal phases latch; begin() re-arms). |
| StoppingBle | Tearing the BLE stack down before any WiFi bring-up. |
| Scanning | Scanning for a visible saved network. |
| Joining | Joining the chosen network (waiting for DHCP). |
| Querying | Querying the configured NTP server IPs in order. |
| Done | Clock committed; WiFi off; BLE restored. Terminal. |
| Failed | See FailReason; WiFi off; BLE restored. Terminal. |
| Cancelled | User abort; WiFi off; BLE restored. Terminal. |
Function Documentation
active() #
True while a sync is running (non-terminal phase).
- Return values
-
Value Meaning true The worker is active. false Idle or a terminal phase was published.
armOtaCarryOver() #
Remember the live password so it survives an OTA reboot.
Called when an update is about to restart the device: without it the browser that started the update could not rejoin to see the result. Ignored when the identity is fixed, since that password already survives by definition.
- Parameters
-
Name Direction Meaning password in The password the access point is currently using.
- Return values
-
Value Meaning true Nothing needed carrying, or the copy is on flash. false The copy was not stored: after the reboot the AP draws a fresh password and the browser that started the update cannot rejoin.
begin() #
Arm and start a one-shot sync on the Core-0 worker.
Loads the saved networks AND the user NTP-server list from the encrypted vault store on the CALLING task (so the worker never sees the vault key), then spawns the worker. Server precedence: overrideServerIp (when set) > the vault user list (when non-empty) > the compile-time default table — all literal IPv4, tried in order. Refuses while a sync is active, when the store has no networks, or when overrideServerIp is oversized.
- Parameters
-
Name Direction Meaning vaultKey in 32-byte unlocked vault key (read-only; used only during this call to decrypt the store). overrideServerIp in Optional single literal IPv4 NTP server to use instead of the default table, or nullptr.
- Return values
-
Value Meaning true The worker started; poll status until a terminal phase. false Refused — status carries the FailReason, except on a busy refusal (the running sync's snapshot is left intact; distinguish by active returning true).
bleRestoreAfterStation() #
What the station session gives back of the Bluetooth session it stopped.
- Parameters
-
Name Direction Meaning before in The stack's state when the station session began. standby in That session ran in standby (its pairing window open). stopOk in The station session's own stop completed. ownerActedSince in An owner started or stopped the radio while the station session ran ( ownerActedSince).
- Returns
- The session to restart, or
BleRestore::.None
cancel() #
Request cancellation of the running sync (idempotent).
The worker observes the flag between steps and at every SNTP wait slice; teardown (WiFi off + BLE restore) still runs on the cancel path. A join in flight completes or times out first (bounded by the join timeout).
clearFixed() #
Stop pinning the identity and go back to a random password per session.
Also disarms a pending requestPinOnNextSession marker, so "stop pinning" cannot be undone by a request recorded before it.
- Return values
-
Value Meaning true The stored pair and the pending marker are gone (or there was none) — the next session draws a random password. false At least one of them is still on flash, so the AP keeps advertising the pinned password. The caller must not report the identity as unpinned.
clearPinRequest() #
Drop a pending pin request.
Called once the request has been honored by a password draw, and by any path that turns the setting back off: a marker left armed would silently re-pin at the next session.
- Return values
-
Value Meaning true No request is armed any more. false The marker is still on flash and will re-pin the next session.
consumePendingAdmin() #
One-shot read: returns true if the flag was set, and clears it so that subsequent boots take the normal unlock → Home path.
- Return values
-
Value Meaning true Flag was set; it has now been cleared. false Flag was not set; nothing was changed.
- See also
- isPendingAdmin(), setPendingAdmin()
failReasonLabel() #
Compact console label for a FailReason.
- Parameters
-
Name Direction Meaning reason in The reason to label.
- Returns
- Pointer to a static lowercase string (never nullptr).
forgetAll() #
Forget every admin access-point identity this device holds.
Erases the pinned SSID and password, a deferred pin request, and the one-shot password carried across an OTA reboot. A change of owner runs it: each of those would otherwise let the previous owner's credential reach the next owner's first admin session. Unlike kleidos::
- Return values
-
Value Meaning true None of the identity keys remain. false At least one would not erase; it is logged, and the next session may still advertise or rejoin with it.
isFixed() #
Whether the owner has pinned the access point's identity.
- Return values
-
Value Meaning true A stored SSID/password pair is in use for every session. false The default: a fresh random password each session.
isPendingAdmin() #
True while the pending-admin flag is set.
Non-mutating: prefer consumePendingAdmin() in FSM dispatch code so the flag is cleared exactly once per request.
- Return values
-
Value Meaning true RTC magic word matches kPendingAdminMagic.false Flag is unset (cleared, never armed, or lost with power).
- See also
- consumePendingAdmin()
isTerminal() #
True for a phase the engine ends in (Done, Failed, Cancelled).
A terminal phase latches until the next begin(); Phase::Idle is not terminal (no sync ever ran).
- Parameters
-
Name Direction Meaning phase in The phase to classify.
- Return values
-
Value Meaning true phaseis Done, Failed or Cancelled.false A sync is running, or none ever started.
joinSliceMs() #
How long the next join attempt may take, given what the phase has spent.
The whole joining phase has one budget, so a board that fails every attempt costs a bounded amount of radio time whatever the scan found — the sync is driven from a settings screen the user waits in front of and from the admin exit, which cancels it at a ceiling of its own. Each attempt gets the full per-attempt timeout while the budget covers it, and the remainder goes to the next one.
- Parameters
-
Name Direction Meaning spentMs in Milliseconds the joining phase has already used. perAttemptMs in Timeout one attempt may ask for. budgetMs in Budget for the whole phase.
- Returns
- The timeout for the next attempt, or 0 when none fits and the phase must give up.
loadFixed() #
Read the pinned identity.
- Parameters
-
Name Direction Meaning ssid out Destination for the SSID; untouched when not fixed. ssidCap in Capacity of ssid.password out Destination for the password; untouched when not fixed. passCap in Capacity of password.
- Return values
-
Value Meaning true Both were read; the caller must zeroize password.false Not fixed, or the stored pair is unusable.
ntpCommitAllowed() #
True when a (plausible) NTP epoch may be committed to the clock.
Refuses a BACKWARD step while a brute-force lockout is armed: an attacker spoofing unauthenticated NTP must not be able to rewind the clock past a lockout-until timestamp. Forward steps are always allowed (the forward-jump lockout model fails closed on its own).
- Parameters
-
Name Direction Meaning newEpoch in Candidate server UTC time (UNIX seconds). nowEpoch in Current device clock (UNIX seconds). lockoutArmed in True while an unlock lockout window is active.
- Return values
-
Value Meaning true The commit is safe. false Backward step under an armed lockout; must be rejected.
ntpEpochAcceptable() #
True when an NTP response epoch lies in the plausible window.
- Parameters
-
Name Direction Meaning epoch in Server UTC time as UNIX seconds.
- Return values
-
Value Meaning true epochis within [::kNtpMinEpoch, :: kNtpMaxEpoch). false Implausible response; must not reach the clock.
ownerActedSince() #
Whether an owner started or stopped the radio while the station session ran.
The owner count moves once at every start and stop asked of the Bluetooth facade, the guard's own stop included. Read before that stop and again at the end, it moved by exactly one if only the guard's stop ran, and by none if the guard stopped nothing; any other change is an owner's.
- Parameters
-
Name Direction Meaning epochBefore in The count read before the guard's own stop. epochNow in The count read when the station session ends. guardStopped in The guard asked the facade to stop the radio.
- Return values
-
Value Meaning true An owner acted: what the guard stopped is not its to give back. false Only the guard's own stop moved the count.
pinRequested() #
Whether a pin request is waiting for the next password draw.
- Return values
-
Value Meaning true The next drawn password will be stored as the fixed one. false No request is pending.
planJoinAttempts() #
Order the access points a sync should try.
hits comes in the order the scan returned, which is strongest-RSSI first. The first hit that matches a saved network is the first attempt, unpinned. Each later attempt is the strongest remaining match on a channel no earlier attempt was heard on — channel diversity rather than signal, because the one failure a board can do nothing else about is channel-wide, and because a loaded channel is loaded for every access point on it. Two access points of one channel are therefore never both planned: the time a second one would spend buys more on another channel.
A hit whose channel is 0 (a scan that did not report one) can match at most once, since there is no channel to tell it apart from another such hit.
- Parameters
-
Name Direction Meaning hits in Scan hits, strongest first, each already resolved against the saved networks. out out Destination for the planned attempts, in order.
- Returns
- Number of attempts written to
out:0 when no hit matches a saved network, and never more than the lesser ofout'ssize and kMaxJoinAttempts.
progressPercent() #
Progress-bar percent for a sync phase.
- Parameters
-
Name Direction Meaning phase in The engine phase to show.
- Returns
- 0..100 from kPhaseProgressPercent; 0 for a value outside the enumeration.
requestPinOnNextSession() #
Ask for the next session's password to be kept as the fixed one.
The device's own settings menu offers the same choice the portal does, but it cannot draw the password itself: the draw lives in WifiApLink::, which is reached only by bringing an admin session up.
So the menu records the intent here and the draw stays where it is: the next admin session draws a fresh password as usual and pins that one. That session therefore still shows a new password; every session after it shows the same one.
The draw needs no radio state of its own: the entropy draw is taken once at startup to seed the CSPRNG behind VaultCrypto::, and every secret, this password included, comes from that CSPRNG without bracketing the hardware entropy source, so drawing it with the radios up is as sound as drawing it with them down.
Idempotent, and a no-op in effect when the identity is already fixed.
- Return values
-
Value Meaning true The marker is on flash; the next drawn password will be pinned. false The marker was not stored — the next session draws a random password and the owner's choice never happens.
setFixed() #
Pin the access point to ssid and password.
- Parameters
-
Name Direction Meaning ssid in Network name; empty keeps the device-derived default. password in Passphrase, kMinPasswordLen to 63 characters.
- Return values
-
Value Meaning true Stored; it applies from the next admin session. false Rejected (length) or storage failed; nothing changed.
status() #
Copy the current status snapshot.
- Returns
- A coherent copy of the running/last sync state.
takeOtaCarryOver() #
Take the password carried across an OTA reboot, if there is one.
One shot: the stored copy is erased by this call whether or not it is used, so a carried password can never outlive the reconnection it exists for.
- Parameters
-
Name Direction Meaning password out Destination for the carried password. cap in Capacity of password.
- Return values
-
Value Meaning true A carried password was taken; the caller must zeroize it. false Nothing was carried.
Variable Documentation
kMaxJoinAttempts #
The most access points one sync plans to try. Three covers the saved networks of a home on the three non-overlapping channels; the time budget (joinSliceMs) is what actually stops the loop, and it usually stops it sooner.
kMinPasswordLen #
Shortest accepted password. Above WPA's own floor of 8: this one is typed once and then reused for every session, so it is held to a higher bar.
kNtpSsidTextLen #
Buffer sizes for the status snapshot's text fields.
SSID + NUL.
kPhaseProgressPercent #
Coarse progress-bar fill per Phase, indexed by its value.
Linear over the four working steps (10/