openaliro
Aliro reader: UWB/CCC core and ESP32-S3/C5/C6 port
Loading...
Searching...
No Matches
fira_session.h
Go to the documentation of this file.
1
3#ifndef WOZ_UWB_FIRA_SESSION_H_
4#define WOZ_UWB_FIRA_SESSION_H_
5
6#include <stdbool.h>
7#include <stdint.h>
8
10bool fira_session_last_range(int32_t *cm_out, uint16_t *addr_out, uint8_t *nlos_out,
11 uint32_t *block_out, int64_t *age_ms_out);
12
13#if defined(CONFIG_WOZ_ALIRO)
15void fira_session_set_provisioned_ursk(const uint8_t *ursk);
16
18const uint8_t *fira_session_get_ursk(void);
19
21void fira_session_set_ccc_range_cm(int32_t cm, uint32_t block);
22
34void fira_session_set_ccc_range_sts(int32_t driver_verdict, int16_t quality_index);
35
37struct fira_range_integrity {
38 bool sts_ok;
39 int16_t sts_quality;
40 uint8_t trust_level;
41};
42
51bool fira_session_last_range_integrity(struct fira_range_integrity *out);
52
56void fira_session_reset_ranges(void);
57
59uint32_t fira_session_range_generation(void);
60
62uint32_t fira_session_current_slot(void);
63
64/* ── Range-integrity gate (anti-spoof / anti Ghost-Peak) ─────────────────────
65 *
66 * A DS-TWR distance is trustworthy only when it is (1) physically plausible,
67 * (2) backed by a well-correlated STS, and (4) consistent with recent blocks.
68 * (Layer 3, an Ipatov first-path check, was removed — untunable on this HW —
69 * so the numbering keeps a gap.) Layers 1 and 4 are enforced in the range
70 * store (fira_session_set_ccc_range_cm); layer 2 is a pure predicate the
71 * responder RX path evaluates, since it owns the DW3000 diagnostics. Every
72 * threshold below is a bring-up default — tune on the bench.
73 *
74 * Layer 2 is recorded rather than enforced here, on purpose, because its two
75 * consumers want opposite failure modes. A door lock must not refuse to open
76 * on a marginal block — a mis-tuned floor locks a human out of their house —
77 * so it keeps the shadow behaviour and only drops blocks under
78 * CONFIG_WOZ_RANGE_GATE_STRICT. A signed presence assertion is the opposite:
79 * it exists to be believed by someone who was not there, so it must refuse to
80 * state a distance it cannot vouch for. The store therefore carries the
81 * verdict alongside the range and lets each consumer pick.
82 */
83
84/* Layer 1 — plausibility band. Below -NEG_TOL is physically impossible (an
85 * early-first-path / Ghost-Peak spoof drives ToF sharply negative); above MAX
86 * is outside any Aliro proximity envelope. A small negative is legitimate
87 * point-blank calibration slop and reads as 0 cm rather than being dropped. */
88#define FIRA_RANGE_NEG_TOL_CM 30 /* legit point-blank slop; drop beyond */
89#define FIRA_RANGE_MAX_CM 3000 /* usable envelope (30 m); tune to radio */
90
92bool fira_session_range_plausible(int32_t cm);
93
94/* Layer 2 — STS quality floor. dwt_readstsquality() returns >=0 for good STS,
95 * <0 for bad, and its signed index is "good" at >= ~60% of the STS length. A
96 * spoofed early path cannot reproduce the scrambled sequence, so its STS
97 * quality collapses. Raise MIN toward the 60%-of-length index to tighten. */
98#define FIRA_STS_QUALITY_MIN 0 /* index floor; 0 = defer to driver verdict */
99
103bool fira_session_sts_quality_ok(int32_t driver_verdict, int16_t quality_index);
104
105/* Layer 4 — cross-block consensus. A single injected block cannot move an
106 * unlock decision alone: a range is "trusted" only once K consecutive plausible
107 * blocks agree to within SPREAD. This does not gate the latched last-range (the
108 * shell/telemetry still track live values); it is the trust bit now wired into
109 * the unlock path via woz_uwb_trusted_range_cm(), which surfaces a distance only
110 * once trust is built. */
111#define FIRA_RANGE_TRUST_K 3 /* consecutive agreeing blocks to trust */
112#define FIRA_RANGE_SPREAD_CM 50 /* max block-to-block delta to stay agreed */
113
116bool fira_session_range_trusted(void);
117
120uint8_t fira_session_trust_level(void);
121
124void fira_session_set_range_listener(void (*cb)(void));
125#endif /* CONFIG_WOZ_ALIRO */
126
127#endif /* WOZ_UWB_FIRA_SESSION_H_ */
bool fira_session_last_range(int32_t *cm_out, uint16_t *addr_out, uint8_t *nlos_out, uint32_t *block_out, int64_t *age_ms_out)
Fetch the most recent valid DS-TWR range; out-params optional (NULL to skip).
Definition fira_session.c:76