presence_link.c
Presence dongle commands (see presence_link.h). prove ends every old Aliro…
Overview
Presence dongle commands (see presence_link.h). prove ends every old Aliro
link, waits for a new trusted credential authentication and a later trusted
UWB range, then signs that post-challenge result under a persistent P-256 key.
These live on the ordinary console rather than a private binary channel, so one
board can be provisioned (aliro-import) and queried for presence without
reflashing between modes, and so a stray log line is just another line instead of
a corrupted frame.
depends on presence_link.h
flowchart TD acquire_fresh --> before_deadline acquire_fresh --> notify_wallet
API
Fstatic void load_or_make_dev_key(void)
Load the device signing key from NVS, generating and persisting one on first boot. This key IS the dongle's identity to every third-party verifier, so it has to outlive reboots: a key regenerated each boot would silently invalidate every public key anyone had already enrolled.
presence_link_initFvoid presence_link_init(bool drive_wallet_grant)
Generate or load the device signing key. Call once after the reader is up. drive_wallet_grant: send the phone the Reader-Status-Changed grant/relock as the presence verdict changes. Pass false from any app that already drives that from its own lock state, or the two owners will contradict each other.
load_or_make_dev_keyFstatic void notify_wallet(bool present)
Send the phone the grant/relock notification when the presence verdict changes. Runs in the console task, never on the UWB RX path, because the send seals on the BLE channel. A no-op with no established session (the reader logs and drops). Off unless the host app asked for it. An app with its own lock state already owns this notification (the Matter lock grants on its approach loop), and two owners would fight over what the phone is being told.
acquire_fresh, proveFstatic void fill_assert(struct aliro_assert *a, const uint8_t nonce[ALIRO_ASSERT_NONCE_LEN], const uint8_t cred_id[ALIRO_ASSERT_CREDID_LEN], int32_t cm, const struct woz_uwb_range_integrity *ig)
Fill one successful assertion. Acquisition already proved that both the credential and range are post-challenge, so this function accepts no latch state and has no ABSENT path it could accidentally sign.
answer_p256Fstatic void emit_hex(const char *tag, const uint8_t *b, size_t n)
Emit one tagged hex line in a single printf. Assembling the line first matters: another task's output can land between two printf calls but not inside one, and the host frames on whole lines.
answer_p256, presence_link_cmdFstatic int hexval(char c)
Return the numeric value 0-15 of a hex digit, or -1 if the character is not a valid hex digit.
parse_hexFstatic int parse_hex(const char *s, uint8_t *out, size_t n)
Parse exactly n bytes of hex. Rejects a short or long string rather than taking a prefix: a truncated nonce that still parsed would silently weaken the challenge.
presence_link_cmd · calls hexvalFstatic int answer_p256(const uint8_t nonce[ALIRO_ASSERT_NONCE_LEN], const uint8_t cred_id[ALIRO_ASSERT_CREDID_LEN], int32_t cm, const struct woz_uwb_range_integrity *ig)
Assemble + sign the assertion for a challenge nonce under the device key, so any holder of the public point can verify it without sharing a secret. That is what makes a presence proof portable to a third party (a CI job, a second reviewer) rather than only to one paired host.
prove · calls emit_hex, fill_assertFstatic bool before_deadline(int64_t deadline_ms)
Return true if the current uptime is before the deadline in milliseconds.
acquire_freshFint presence_link_require_fresh(void)
Require a new credential authentication and a later trusted UWB range. Returns 0 only when the single provisioned credential ranges within policy. Concurrent requests are serialized; no previous authentication or range can authorize the caller.
acquire_freshFint presence_link_cmd(int argc, char **argv)
Console handler for the presence command; registered by the app shell.
emit_hex, parse_hex, proveUndocumented (2)
acquire_fresh, prove