Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / firmware / findfamily-tracker / docs / INTENDED_BEHAVIOUR.md

INTENDED_BEHAVIOUR.md78.8 KiBRenderedCodeRaw
1# FindFamily UWB Tracker — Intended Behaviour (clean-room specification)
2
3## 0. Scope, method and how to read this document
4
5This is an **independent statement of what the tracker firmware is supposed to do**, derived
6only from documentation and from vendor reference code. It was written without reading any of
7`firmware/findfamily-tracker/src`, `firmware/qorvo-uwb`, or `findfamily/src`, so that it can be
8diffed against the implementation to find where the two disagree.
9
10### 0.1 Sources
11
12| Tag | Source |
13|---|---|
14| **DESIGN** | `c:\Users\Vayun\Documents\code\Modern-Apps\FINDFAMILY_UWB_TRACKER_DESIGN.md` |
15| **HW** | `c:\Users\Vayun\Documents\code\Modern-Apps\FINDFAMILY_UWB_TRACKER_HARDWARE.md` |
16| **PLAN** | `C:\Users\Vayun\.llms\plans\findfamily_tracker_firmware.plan.md` |
17| **QSDK** | Qorvo DW3/QM33 SDK at `C:\qorvo` (headers, vendor sample apps, vendor platform layer) |
18| **ZEPHYR** | nRF Connect SDK v3.4.0 at `C:\ncs\v3.4.0` (Zephyr headers, Kconfig, host stack) |
19
20Every normative statement below cites the file and line that justifies it. Vendor sample code
21(`C:\qorvo\Src\Apps\Src\fira\*`, `C:\qorvo\Projects\FreeRTOS\QANI\*`) is treated as **normative
22documentation of intended API usage** — it is the only description Qorvo ships of the required
23call sequence.
24
25### 0.2 Conventions
26
27- **MUST / MUST NOT** — directly supported by a cited source.
28- **SHOULD** — strongly implied by a cited source but not stated as a hard rule.
29- **OPEN QUESTION** — the documentation is silent, ambiguous, or self-contradictory. These are
30 numbered `OQ-n` and indexed in §9. **Do not treat an OPEN QUESTION as a requirement**; treat it
31 as something that must be resolved by test or by a source I did not have.
32- **TRAP** — a place where a plausible, natural implementation choice is wrong. These are the
33 highest-value part of this document; indexed in §10.
34
35### 0.3 Hardware baseline
36
37Bench target is a **Qorvo DWM3001CDK**: DWM3001C module = **nRF52833** (Cortex-M4F, 512 kB flash,
38128 kB RAM, **no USB peripheral**) + **DW3110** (HW:5–12). The custom-board BOM in HW §1–§4
39specifies an nRF52840 and does **not** describe the bench target (HW:5–12). The DW3110 has a
40**single RF port and therefore no on-chip PDoA/AoA** (DESIGN:70–74); the phone measures angle with
41its own array, and the tracker only has to be a plain ranging responder.
42
43---
44
45## 1. BLE roles and advertising
46
47### 1.1 Two advertising modes on one state machine
48
49The tracker MUST implement exactly two advertising modes, and MUST NOT run both at once
50(PLAN:37–41, HW:145–158):
51
52| Mode | When | PDU type | Contents |
53|---|---|---|---|
54| **Pairing** | unprovisioned, or after a long button press | **legacy**, connectable | `Flags` + complete list of 128-bit service UUIDs containing `…2f01…` |
55| **Beacon** | provisioned | **BLE 5 extended**, connectable | Service Data — 128-bit UUID `…2f00…` carrying `[16B epochId][1B battery%]` |
56
57**Pairing mode MUST stay legacy.** DESIGN:206–207 and HW:156–157 state the reason: the phone
58discovers an unprovisioned tracker using *default* `ScanSettings`, which are legacy-only, so an
59extended pairing advertisement would be invisible. The AD budget is `Flags (3) + 128-bit service
60UUID AD (1 len + 1 type + 16 UUID = 18) = 21` bytes, inside the 31-byte legacy limit
61(DESIGN:206, HW:156).
62
63**Beacon mode MUST be extended advertising.** The service-data AD structure costs
64`1 (length) + 1 (AD type) + 16 (UUID) + 17 (payload) = 35` bytes on air, against the 31-byte
65legacy `AdvData` limit (DESIGN:196–204, HW:152–157, PLAN:9). Zephyr codifies the same two limits:
66`BT_GAP_ADV_MAX_ADV_DATA_LEN` is 31 and `BT_GAP_ADV_MAX_EXT_ADV_DATA_LEN` is 1650
67(`C:\ncs\v3.4.0\zephyr\include\zephyr\bluetooth\gap.h:140,146`).
68
69The full 16-byte UUID MUST be on air un-shortened, because the finder reads the payload back with
70`ScanRecord.getServiceData(ParcelUuid)`, which keys on the full UUID (DESIGN:200–203, PLAN:9).
71A 16-bit UUID alias is therefore not an option.
72
73### 1.2 The beacon set MUST be connectable, and that is legal
74
75The beacon advertising set MUST be **connectable**, because a bound tracker has to remain
76writable so the owner can hand over per-find UWB parameters on `…2f03…` (DESIGN:203–204,
77HW:159–161, PLAN:40).
78
79A connectable **extended** advertising set MAY carry advertising data. Zephyr states the rule
80directly: *"When both `BT_LE_ADV_OPT_EXT_ADV` and `BT_LE_ADV_OPT_SCANNABLE` are enabled then
81advertising data is ignored and only scan response data is used. When `BT_LE_ADV_OPT_SCANNABLE` is
82not enabled then scan response data is ignored and only advertising data is used"*
83(`C:\ncs\v3.4.0\zephyr\include\zephyr\bluetooth\bluetooth.h:1475–1478`). So for a
84connectable-but-not-scannable extended set, `ad` is the live field and `sd` is ignored.
85
86Consequences that MUST be respected:
87
881. **The beacon set MUST NOT be scannable.** With extended PDUs, scannable and connectable are
89 mutually exclusive: *"When used together with `BT_LE_ADV_OPT_EXT_ADV` then this option cannot
90 be used together with the `BT_LE_ADV_OPT_CONN` option"*
91 (`bluetooth.h:776–781`). `BT_LE_EXT_ADV_CONN` (`bluetooth.h:1193`) is the correct parameter
92 preset; `BT_LE_EXT_ADV_SCAN` (`bluetooth.h:1197`) is not.
932. **There is no scan response.** Everything an Android `ScanFilter` needs MUST be in the
94 advertising data. Nothing may be deferred to a scan response.
953. **Zephyr does not insert `Flags` for you.** `adv.c` only *inspects* `BT_DATA_FLAGS` to detect
96 limited discoverability (`C:\ncs\v3.4.0\zephyr\subsys\bluetooth\host\adv.c:747–755,1343`); it
97 does not synthesise the element. If a `Flags` AD element is wanted it MUST be supplied by the
98 application in the `ad` array. The 21-byte pairing figure in DESIGN:206 already assumes this.
994. **Secondary PHY MUST be pinned to 1M**, so the phone needs no coded-PHY scan configuration
100 (DESIGN:203, PLAN:41).
1015. Finder phones MUST scan with `ScanSettings.Builder().setLegacy(false)` to see the beacon
102 (DESIGN:204, PLAN:72). `setLegacy(false)` is documented in PLAN:72 as returning both legacy and
103 extended results, so a single scanner can serve both modes.
1046. Enabling extended advertising on nRF forces the **MULTIROLE** SoftDevice Controller variant:
105 `BT_CTLR_ADV_EXT` appears in the `default BT_LL_SOFTDEVICE_MULTIROLE if (…)` condition
106 (`C:\ncs\v3.4.0\nrf\subsys\bluetooth\controller\Kconfig:303–320`). That is a real flash/RAM cost
107 on a 512 kB / 128 kB nRF52833 that also has to hold the Qorvo UWB stack.
108
109### 1.3 Refreshing the beacon each epoch
110
111The epoch ID rotates every 900 s (§5), so the advertising data MUST be updated in place once per
112epoch. In-place update is permitted here: *"When updating the advertising data while advertising
113the advertising data and scan response data length must be smaller or equal to what can be fit in
114a single advertising packet. Otherwise the advertiser must be stopped"*
115(`bluetooth.h:1490–1493`). 35 bytes fits a single `AUX_ADV_IND`, so the set does not need to be
116stopped. The return value of `bt_le_ext_adv_set_data()` MUST still be checked, because the real
117extended-advertising data limit is *"defined by the controller"* (`bluetooth.h:1483–1485`).
118
119### 1.4 Transition on successful provisioning
120
121On a successful provisioning write the tracker MUST, in this order (HW:176–178):
122persist the blob → **stop the unprovisioned/pairing advertisement** → start the rotating beacon.
123The GATT characteristics MUST remain registered for the life of the device even though the
124`…2f01…` service is no longer advertised, so the owner can still write UWB parameters to a bound
125tracker (HW:159–161).
126
127### 1.5 What is deliberately *not* specified
128
129- **OQ-1** — Nothing in DESIGN/HW/PLAN specifies the beacon advertising interval. HW:203 assumes
130 "every 1–2 s" for the power budget and HW:206 says "~1 s beacon interval", but that is a power
131 estimate, not a requirement, and no interval is given for pairing mode either.
132- **OQ-2** — No source specifies whether the beacon should be motion-gated. HW:194 says
133 "Accelerometer INT → wake, refresh beacon, allow ranging" and HW:206 says motion-gating
134 "extends" battery life, which is suggestive but not a requirement. The DWM3001CDK has no
135 accelerometer wired for this purpose in any cited source.
136- **OQ-3** — No source states what the tracker should advertise between "provisioned" and
137 "pairing mode re-entered by long press", i.e. whether a long press while provisioned should
138 advertise *both* services or switch to pairing-only. HW:193 says long-press → advertise
139 unprovisioned service; it does not say what happens to the beacon.
140
141---
142
143## 2. Address types
144
145### 2.1 What a Zephyr peripheral advertises by default
146
147A Zephyr device's default identity is a **random static** address, not a public address:
148`bt_id_create()` documents that when `addr` is NULL or `BT_ADDR_LE_ANY`, *"the stack will generate
149a new random static address for the identity address"*
150(`C:\ncs\v3.4.0\zephyr\include\zephyr\bluetooth\bluetooth.h:466–468`). A public address is only
151used if `CONFIG_BT_HCI_SET_PUBLIC_ADDR` is enabled and set before `bt_enable()`
152(`bluetooth.h:462–464`).
153
154`CONFIG_BT_PRIVACY` — which would make the device *"use Resolvable Private Addresses (RPAs) by
155default"* — is a plain `bool` with no `default y`
156(`C:\ncs\v3.4.0\zephyr\subsys\bluetooth\host\Kconfig:537–541`), so it is **off** unless explicitly
157enabled. Therefore, absent extra configuration, the tracker advertises a **stable random static
158address** — not an RPA.
159
160This matters both ways:
161
162- It is what makes DESIGN:138–139 workable: the phone persists "the tracker's BLE address (needed
163 to re-open GATT for a UWB find)". A stable address is required for that to be meaningful.
164- **The tracker MUST NOT enable `CONFIG_BT_PRIVACY`.** With RPAs the stored address rotates and
165 the owner can never re-open GATT by address. (Note the privacy cost: DESIGN:5.1 wanted "no
166 static identifier is ever broadcast" so "the tracker can't be followed by ID"
167 (DESIGN:164–166) — a stable random static BLE address defeats that at the link layer even
168 though the *payload* rotates. **OQ-4**: no source reconciles the rotating-epoch-ID privacy goal
169 with the stable BLE address that owner reconnection requires.)
170
171### 2.2 What the Android client must do
172
173**TRAP-1.** Android's `BluetoothAdapter.getRemoteDevice(String)` produces a `BluetoothDevice` that
174assumes a **public** address type. Reconnecting to a random-static peripheral from a stored address
175string therefore needs either the `BluetoothDevice` object retained from the `ScanResult`, or
176`BluetoothAdapter.getRemoteLeDevice(address, BluetoothDevice.ADDRESS_TYPE_RANDOM)`. PLAN:72 notes
177the app's `minSdk = 31`, which is above the API level where `getRemoteLeDevice` is available.
178
179- **OQ-5** — I could not find an authoritative citation for Android's exact behaviour here. An
180 internal knowledge search returned nothing on `getRemoteLeDevice` / address-type handling, and no
181 Android SDK sources are present on this machine. The failure mode (a connect attempt that times
182 out or reports GATT error 133 despite the device being present and connectable) is worth testing
183 directly rather than assumed. **No source in DESIGN/HW/PLAN mentions address type at all** — this
184 is a genuine gap in the design documents, not just in my research.
185- **OQ-6** — No source states whether the phone should store the address at all versus re-scanning
186 for the `…2f00…` beacon immediately before a find. Re-scanning would sidestep the whole address
187 type problem. DESIGN:139 chose to store.
188
189---
190
191## 3. GATT services, characteristics, and write sizes
192
193### 3.1 UUIDs
194
195From HW:145–188 and DESIGN:196:
196
197| UUID | Kind | Purpose |
198|---|---|---|
199| `6b1d2f00-4b3a-4c7e-9a10-1f2e3d4c5b6a` | service | **Beacon service** — identifies the crowd-finding advertisement and keys the Service Data AD element. Advertised only, in beacon mode. |
200| `6b1d2f01-…` (`…2f01…`) | service | **Binding service** — GATT service holding the two characteristics below. Advertised only while unprovisioned; registered for the life of the device. |
201| `6b1d2f02-…` (`…2f02…`) | characteristic, **write** | Provisioning blob (§4). |
202| `6b1d2f03-…` (`…2f03…`) | characteristic, **write + notify** | Per-find FiRa parameters (§6.6). |
203
204The base is the same 128-bit UUID with the 3rd–4th nibble pair varying — `…2f00…` through
205`…2f03…` (HW:145,159,162,180). The beacon UUID `…2f00…` is a **service UUID used only as the key
206of a Service Data AD element**; there is no requirement in any source for a GATT service with that
207UUID to exist in the attribute table.
208
209- **OQ-7** — No source specifies the `…2f03…` **notify** semantics: what is notified, when, or
210 what the payload is. HW:180 says "write/notify" and DESIGN:218 says the params are delivered over
211 a "session characteristic", but nothing says the tracker notifies e.g. "UWB session started" or
212 "ranging failed". Given the phone must know when the responder is live before it starts its own
213 session, this is a substantive gap (see §6.9 / OQ-19).
214- **OQ-8** — No source specifies characteristic **permissions**. The GATT link is explicitly
215 described as "unbonded and unencrypted" (DESIGN:92–94, HW:181–182), so the write permission is
216 presumably plain `BT_GATT_PERM_WRITE`, but "no encryption required" is inferred from the threat
217 model discussion rather than stated.
218- **OQ-9** — No source specifies what the tracker should do with a provisioning write **while
219 already provisioned**. DESIGN:141 says "Unbind requires the secret (anti-theft lock), so a found
220 tracker can't be silently re-bound", which implies a provisioned tracker MUST reject a bare
221 re-provisioning write, but no unbind protocol, opcode, or characteristic is defined anywhere.
222 As specified, the anti-theft claim in DESIGN:141 has no mechanism behind it.
223
224### 3.2 Write sizes and MTU — the 48-byte problem
225
226The provisioning blob is **48 bytes** (40 accepted for the legacy form) (HW:163–170, PLAN:21).
227On a default-configuration Zephyr peripheral, a 48-byte characteristic write **cannot succeed**:
228
2291. `CONFIG_BT_L2CAP_TX_MTU` defaults to **23**, rising to 65 only if `BT_SMP` is enabled
230 (`C:\ncs\v3.4.0\zephyr\subsys\bluetooth\host\Kconfig.l2cap:28,40`). With ATT_MTU 23 the maximum
231 `ATT_WRITE_REQ` value is **MTU − 3 = 20 bytes**.
2322. `CONFIG_BT_ATT_PREPARE_COUNT` defaults to **0**, and its help text says plainly: *"Number of
233 buffers available for ATT prepare write, setting this to 0 **disables GATT long/reliable
234 writes**"* (`C:\ncs\v3.4.0\zephyr\subsys\bluetooth\host\Kconfig.gatt:25`). All the
235 prepare/execute-write handling in the host is compiled out under
236 `#if CONFIG_BT_ATT_PREPARE_COUNT > 0`
237 (`C:\ncs\v3.4.0\zephyr\subsys\bluetooth\host\att.c:73,153,2229,2500,2859,3153,3256`).
238
239**TRAP-2.** So a naive Zephyr GATT server with default `prj.conf` will reject the 48-byte
240provisioning write, and the failure looks like a client-side GATT error rather than anything
241obviously MTU-related. Exactly one of the following MUST be true:
242
243- **(a) Large ATT MTU.** `CONFIG_BT_L2CAP_TX_MTU` ≥ 51 on the tracker **and** the Android client
244 calls `requestMtu()` and waits for `onMtuChanged` before writing. The negotiated ATT_MTU is the
245 minimum of the two sides, so raising it on the tracker alone is not enough. The vendor QANI log
246 shows this negotiation happening in practice — the peer requests 293 and the accessory clamps to
247 100 (`C:\qorvo\Projects\FreeRTOS\QANI\README.md`, sample output) — which is evidence that a
248 ~100-byte MTU is a workable target on this class of device.
249- **(b) Long write.** `CONFIG_BT_ATT_PREPARE_COUNT` > 0 on the tracker, and the write handler
250 tolerates the long-write path.
251
252Option (a) is simpler and is the one to prefer, because it also removes any dependence on
253Android's long-write behaviour (OQ-10).
254
255### 3.3 If long writes are used, the handler MUST handle offsets and flags
256
257Should route (b) be taken, the write callback contract is:
258
259- The callback receives an `offset` and a `flags` bitmask
260 (`C:\ncs\v3.4.0\zephyr\include\zephyr\bluetooth\gatt.h:174–200`).
261- `BT_GATT_WRITE_FLAG_PREPARE` means *"write callback should only check if the device is
262 authorized but no data shall be written"* (`gatt.h:112–118`). It is only delivered at all if the
263 attribute carries `BT_GATT_PERM_PREPARE_WRITE` (`gatt.h:84`, `att.c:2262–2264`).
264- On `ATT_EXECUTE_WRITE`, Zephyr reassembles the queued fragments itself and calls the write
265 callback once with the reassembled buffer and the first fragment's offset
266 (`att.c:2440–2470`). The reassembly capacity is `CONFIG_BT_ATT_PREPARE_COUNT * BT_ATT_BUF_SIZE`
267 (`att.c:2434`), so `PREPARE_COUNT` MUST be large enough for 48 bytes at the negotiated MTU.
268- `BT_GATT_WRITE_FLAG_CMD` distinguishes Write-Without-Response, which produces no error back to
269 the client (`gatt.h:120–125`). A provisioning write MUST NOT be a Write Command, because the
270 phone needs to know the blob was accepted.
271
272Regardless of route, the handler MUST reject any length that is not exactly 40 or 48
273(HW:163–170, PLAN:21) rather than accepting a short prefix, and MUST NOT assume `offset == 0`.
274
275- **OQ-10** — Whether Android's GATT client automatically promotes an over-MTU
276 `writeCharacteristic()` to a prepare/execute sequence is not documented in any source I could
277 cite, and internal knowledge search found nothing. Do not rely on it.
278
279---
280
281## 4. Provisioning blob
282
283### 4.1 Layout
284
28548 bytes, big-endian (HW:163–170, DESIGN:131–137, PLAN:21):
286
287```
288offset size field
289 0 8 trackerUserId uint64, big-endian
290 8 32 beaconSecret raw bytes
291 40 8 unixSeconds uint64, big-endian, seconds since Unix epoch
292```
293
294The 40-byte form (no timestamp) MUST also be accepted (HW:170, PLAN:21).
295
296**No UWB parameters are in this blob** (DESIGN:135–137). Channel and preamble arrive per-find on
297`…2f03…`; the STS key and the tracker's UWB address are derived, never transmitted (§7).
298
299### 4.2 Semantics of the time base
300
301The trailing timestamp is the tracker's **only** source of wall-clock time — there is no
302battery-backed RTC (DESIGN:133–136, HW:167–172, PLAN:10). It exists solely because
303`epoch = unix_seconds / 900`, and the owner searches a bounded window of recent epochs
304(`recentEpochIds(back = 8)` ≈ 2.25 h per PLAN:10). Without a time base the tracker would beacon
305IDs outside that window and resolve to nothing.
306
307The firmware MUST therefore:
308
3091. Persist `unixSeconds` at provisioning time (HW:171–172).
3102. Compute current time as `unix_at_provision + elapsed`, where `elapsed` comes from a
311 sleep-surviving monotonic clock — PLAN:44 names `k_uptime_get()` and notes it is LFCLK-backed
312 and survives sleep (HW:171–172, PLAN:44).
3133. **Re-persist the current time to NVS once per epoch**, so that a reset costs one epoch of drift
314 rather than the whole time base (HW:172, PLAN:44).
3154. Persist `trackerUserId`, the 32-byte secret, and a provisioned flag (PLAN:62).
316
317**TRAP-3.** `unixSeconds` is a *point-in-time* value, not a monotonic base. If the firmware
318re-persists only `unix_at_provision` and not `unix_at_provision + elapsed`, or if it re-derives
319`elapsed` from an uptime counter that resets while the persisted base does not advance, the tracker
320silently drifts out of the owner's search window and the failure mode is "no map pin ever appears"
321with no error anywhere. PLAN:116 explicitly calls out that a tracker left unpowered for a long
322period falls outside the window and needs re-provisioning to resync.
323
324- **OQ-11** — No source specifies whether the tracker should keep beaconing after a reset if the
325 time base was never persisted, or with what value. Beaconing a wrong epoch ID is
326 indistinguishable from a stranger's tracker to a finder, and would still consume the finder's
327 upload budget.
328- **OQ-12** — No source specifies the byte-order or units of the battery percentage byte beyond
329 "battery%" (HW:148, DESIGN:196). One byte, presumably 0–100. HW:68 says it is fed from a SAADC
330 divider; the DWM3001CDK has no such divider described in any cited source, so what the bench
331 build should report is undefined.
332
333---
334
335## 5. Crowd finding
336
337### 5.1 The shipped scheme (rotating hash), not the design's Option B
338
339DESIGN §5.1–5.4 describes a per-epoch elliptic-curve scheme, and DESIGN:150–156 says explicitly
340that **this is not what shipped** and is retained only as the privacy target to aim for. The
341shipped scheme is:
342
343```
344epoch = unix_seconds / 900 (15-minute rotation)
345epochId = HMAC-SHA256(beaconSecret, "fftrk1" || u64_be(epoch))[0..16]
346```
347
348(HW:150–151, DESIGN:153–155, PLAN:63). The advertised payload is `[16B epochId][1B battery%]` as
349Service Data under `…2f00…` (HW:147–149, DESIGN:196).
350
351The firmware MUST produce byte-identical output to the Kotlin and Rust implementations; PLAN:42
352requires using PSA Crypto (via nrf_security/mbedTLS) for the HMAC for exactly that reason.
353
354Note the ASCII label is `"fftrk1"` with **no separator and no length prefix** before the
355big-endian epoch counter (HW:150). Domain separation rests entirely on that fixed 6-byte prefix.
356
357### 5.2 How a finder resolves it
358
359Any FindFamily phone (DESIGN:169–176, PLAN:5):
360
3611. Scans for `…2f00…` service data, with `setLegacy(false)` (§1.2).
3622. Builds a `LocationValue` at the **finder's own** GPS.
3633. Seals it to the tracker's ML-KEM public bundle, which the **server** serves to finders
364 (DESIGN:153–155).
3654. Uploads `{ epochId-derived key, ciphertext }` via the tracker opcodes `0x06`–`0x0B`
366 (DESIGN:25,31).
3675. Rate-limits/dedups per `(id, coarse-time)` and requires decent GPS accuracy (DESIGN:175).
3686. Never learns whose tracker it is (DESIGN:176).
369
370The owner recomputes the expected epoch IDs for the last N epochs, fetches matching ciphertexts,
371decrypts, and emits a `LocationValue` keyed on the tracker's `userid`, which flows through the
372existing pipeline to a map pin with no UI change (DESIGN:186–191).
373
374### 5.3 What the server must do
375
376Server work lives outside this repo, in `location_share_server` (DESIGN:30–32,178–184):
377
378- Opcodes `0x06`–`0x0B`: `TRACKER_REGISTER` / `RESOLVE` / `REPORT_PUT` / `REPORT_GET`
379 (DESIGN:31).
380- Store `{ id, ciphertext }` with a retention window (DESIGN:183, "e.g. 7 days") and lazy TTL
381 purge (DESIGN:31).
382- Serve the tracker's ML-KEM public bundle to finders so they can seal reports (DESIGN:153–155).
383- Abuse / rate-limit policy (DESIGN:183).
384
385**Accepted privacy weakening:** unlike Option B, the shipped scheme lets the **server link a
386rotating id → tracker** (DESIGN:47). This is deliberate and documented, not a defect.
387
388- **OQ-13** — The tracker firmware has no role in the server contract, and nothing in the firmware
389 scope depends on it. Included here only because the task asked; the firmware-side requirement is
390 simply "emit the right 17 bytes".
391
392---
393
394## 6. UWB / FiRa
395
396The tracker is the FiRa **controlee + responder**; the phone is **controller + initiator**
397(DESIGN:48,84–89,190; HW:190–192). This section is derived from the Qorvo SDK headers and the two
398vendor reference applications: the CLI FiRa app (`C:\qorvo\Src\Apps\Src\fira\*`) and, more
399relevantly, **QANI** — Qorvo's own BLE-provisioned accessory responder
400(`C:\qorvo\Projects\FreeRTOS\QANI\Common\src\fira\fira_niq.c`), which is the closest existing
401analogue to what this tracker is.
402
403### 6.1 Required initialisation order — stack bring-up
404
405`fira_uwb_mcps_init()` is the vendor's canonical bring-up and the order is not negotiable
406(`C:\qorvo\Src\Apps\Src\fira\fira_dw3000.c:21–49`):
407
408```
4091. qplatform_init() /* MUST be first */
4102. l1_config_init(&l1_config_platform_ops)
4113. llhw_init()
4124. uwbmac_init(&uwbmac_ctx)
413```
414
415`qplatform.h:19` states the rule for step 1: *"It should be called prior to any other init of the
416UWB stack."* Teardown is the exact reverse (`fira_dw3000.c:42–47,51–56`):
417`llhw_deinit() → l1_config_deinit() → qplatform_deinit()`, with `uwbmac_exit()` last
418(`fira_app.c:932–936`).
419
420What each step actually does, and why the order is forced:
421
422- **`qplatform_init()`** (`C:\qorvo\Libs\uwb-stack\libs\qplatform\qm33_qhal_common\src\qplatform.c:241–267`):
423 disables the UWB IRQ, pulses `RSTn`, opens and configures the SPI **at the slow rate**
424 (*"At cold start, SPI communication rate cannot be higher than 7 Mhz"*, `qplatform.c:211–212`),
425 installs the IRQ-pin callback, then calls `dwt_probe()` which selects the driver by device ID
426 from the list `{ dw3000_driver, dw3720_driver }` (`qplatform.c:61–68,260–266`). `CONFIG_DW3000`
427 MUST be defined or the `dw3000_driver` is not in the list at all, and `qplatform.c:50–52` is a
428 hard `#error` if neither `CONFIG_DW3000` nor `CONFIG_DW3720` is set.
429- **`l1_config_init()`** must come after `qplatform_init()` because loading calibration reads the
430 DW3xxx OTP over SPI (see §6.2), which requires a probed device.
431- **`llhw_init()`** must come after `l1_config_init()` because it consumes the L1 configuration.
432- **`uwbmac_init()`** last.
433
434**RSTn is open-drain.** `qplatform_uwb_reset()` drives the pin **low**, then reconfigures it as
435**input** — it never drives it high (`qplatform.c:278–285`). HW:117 says the same
436("open-drain reset (don't drive high)"). A devicetree/GPIO configuration that actively drives
437`RSTn` high will damage or hang the DW3110.
438
439### 6.2 L1 config / calibration is mandatory, not optional
440
441**TRAP-4.** This is the single most likely cause of "phone transmits, gets RX timeouts" that is
442invisible in a code review, because nothing fails: the stack initialises cleanly and the session
443goes ACTIVE.
444
445`l1_config_init()` takes a `struct l1_config_platform_ops` whose only member is
446`reset_to_default` (`C:\qorvo\Libs\uwb-stack\config_manager\plugins\l1_config\include\l1_config.h:20–28`).
447In volatile mode (`CONFIG_L1_CONFIG_VOLATILE`) `l1_config_load()` **always** calls
448`l1_config_reset_to_default()`
449(`C:\qorvo\Libs\uwb-stack\config_manager\plugins\l1_config\src\l1_config.c:723–726`), which loads
450generic defaults and then calls `platform_ops.reset_to_default()` if — and only if — one was
451registered (`l1_config.c:653–654`). Pass `NULL` ops, or ops with a null hook, and the radio comes
452up with **generic, uncalibrated** RF settings.
453
454The vendor's DWM3001CDK hook does all of the following
455(`C:\qorvo\Src\Boards\Src\DWM3001CDK\platform_l1_config.c:57–150`):
456
457| Step | Detail | Cite |
458|---|---|---|
459| Read OTP revision, sanity-check platform ID is `DW3000` or `DW3001C` | rejects unknown silicon | `:67–75` |
460| **Antenna path 0 = TX on RF port 1** | `configure_antenna_path(0, TRANSCEIVER_TX, 1)` | `:77–78` |
461| **Antenna path 1 = RX-A on RF port 1** | `configure_antenna_path(1, TRANSCEIVER_RXA, 1)` | `:80–81` |
462| Channel-5 antenna delay from OTP `0x1A`, with a DW3001C cal-rev-1 workaround overriding it to `0x3FEE3FEE` | ToF accuracy | `:29–31,83–96` |
463| Channel-9 antenna delay from OTP `0x1C` | ToF accuracy | `:98–102` |
464| TX power for ch 5 / ch 9 from OTP `0x11` / `0x13`, converted to a **TX power index** via `llhw_convert_tx_power_to_index()` | link budget | `:104–119`, `helper_platform_l1_config.c:50–82` |
465| **XTAL trim** from OTP `0x1E` (masked `0x7F`), applied only if non-zero | carrier frequency offset | `:121–127` |
466| `pg_count` for both channels from OTP `0x18`, stored on the TX antenna path | pulse shaping | `:129–140` |
467| `ant_set0.tx_power_control = 1` (adaptive TX power) | | `:142–143` |
468
469Note the split: `tx_ant_delay = otp & 0xFFFF` goes to **ant_path 0** and
470`rx_ant_delay = (otp >> 16) & 0xFFFF` goes to **ant_path 1**
471(`platform_l1_config.c:43–55`). Getting that backwards produces a constant range bias.
472
473Two of these are plausible root causes of one-way RX failure specifically:
474
475- **Missing antenna-path configuration** means the driver has no TX/RX port assignment at all.
476- **Missing XTAL trim** leaves a clock offset large enough that the peer's receiver may fail to
477 acquire. The QANI sample log shows the pg_count path being exercised at runtime
478 (`"Run calcbandwidthadj for pg_count 178: pg_delay 53"`,
479 `C:\qorvo\Projects\FreeRTOS\QANI\README.md`), i.e. these values are genuinely used, not decorative.
480
481The tracker firmware MUST provide a `reset_to_default` hook equivalent to
482`platform_l1_config.c`, and it MUST run after `dwt_probe()` (which is why the order in §6.1
483matters) because `qotp_read()` talks to the DW3110 over SPI.
484
485- **OQ-14** — Whether the tracker should use volatile or persistent L1 config is not addressed by
486 any source. Persistent mode adds a `CONFIG_SECURE_PARTITIONS_UWB_L1_CONFIG_SIZE` flash partition
487 and version-mismatch handling (`l1_config.c:690–711`); volatile mode re-reads OTP every boot,
488 which is simpler and always correct. Volatile appears preferable, but this is inference.
489
490### 6.3 The application MUST supply the MAC crypto primitives
491
492**TRAP-5.** The prebuilt uwbstack calls out to `mcps_crypto_*` symbols that the **application**
493must define. The public header only declares two of them (`mcps_crypto_init` / `mcps_crypto_deinit`,
494`C:\qorvo\Libs\uwbstack_libs\delivery\full\Release\include\uwbstack_bundle\mcps_crypto_platform.h`),
495but the vendor's implementation shows the full surface
496(`C:\qorvo\Src\UWB\mcps_crypto.c:16–123`):
497
498```
499mcps_crypto_init / _deinit / _reinit
500mcps_crypto_get_random
501mcps_crypto_cmac_aes_128_digest mcps_crypto_cmac_aes_256_digest
502mcps_crypto_aead_aes_ccm_star_128_create / _destroy
503mcps_crypto_aead_aes_ccm_star_128_encrypt / _encrypt_inout
504mcps_crypto_aead_aes_ccm_star_128_decrypt / _decrypt_inout
505mcps_crypto_aes_ecb_128_create_encrypt / _create_decrypt / _encrypt_decrypt / _destroy
506```
507
508`AES-CMAC-128` is what FiRa uses to derive the STS from the vUpper64. If any of these are stubbed
509out, return errors, or are wired to a different AES mode, the STS the tracker generates will not
510match the phone's, and the symptom is exactly the reported one: the phone transmits, the tracker
511either never decodes the poll or replies with an STS the phone rejects, and the phone reports
512**RX timeouts**. The Qorvo enum even has dedicated status codes for this —
513`QUWBS_FBS_STATUS_RANGING_RX_PHY_STS_FAILED` and `..._RX_TIMEOUT`
514(`C:\qorvo\Src\Apps\Src\fira\fira_app.c:556,565`) — so if the tracker's own notifications are
515being logged, they will distinguish "never heard anything" from "heard it, STS wrong".
516
517The tracker firmware MUST implement all of these, and they MUST be correct AES-CMAC/CCM*/ECB, not
518placeholders. `mcps_crypto_get_random` MUST be a real RNG.
519
520- **OQ-15** — No source states whether these may be backed by PSA Crypto on Zephyr the way the
521 epoch HMAC is (PLAN:42). Since PSA offers AES-CMAC and AES-CCM, that should work, but the
522 interaction with the BLE stack's own PSA usage (`BT_GATT_CACHING` selects
523 `PSA_WANT_ALG_CMAC`, `C:\ncs\v3.4.0\zephyr\subsys\bluetooth\host\Kconfig.gatt`) — in particular
524 whether PSA calls are safe from the DW3xxx ISR context described in §6.4 — is undocumented and is
525 a real concern.
526
527### 6.4 Where the MAC event loop is pumped, and why it matters
528
529`qplatform_init()` installs `qplatform_uwb_spi_irq_handler` as the DW3xxx IRQ-pin GPIO callback
530(`qplatform.c:220–225`), and that handler is:
531
532```c
533static void qplatform_uwb_spi_irq_handler(void *arg)
534{
535 while (qplatform_uwb_read_irq_pin_value())
536 dwt_isr();
537}
538```
539(`qplatform.c:153–157`)
540
541So **the entire DW3xxx interrupt service routine — and therefore all MAC frame reception,
542transmission scheduling and FiRa region processing — runs from the GPIO interrupt callback**, and
543it loops until the IRQ line deasserts. On Zephyr, `qgpio_pin_irq_configure()` installs this via
544`gpio_add_callback_dt()` / `gpio_pin_interrupt_configure_dt()`
545(`C:\qorvo\Libs\uwb-stack\libs\qhal\src\zephyr\qgpio.c:280–297`), i.e. as an ordinary Zephyr GPIO
546callback, which runs in **interrupt context**.
547
548Corroborating this model, `uwbmac.h` warns for report callbacks: *"In embedded application, the
549callback might be called from MAC context, large treatments should be deferred"*
550(`C:\qorvo\Libs\uwbstack_libs\delivery\full\Release\include\uwbstack_bundle\uwbmac\uwbmac.h:262–263`),
551and for the data ops: *"This callback must return quickly and it must not reenter the MAC"*
552(`uwbmac.h:150–162`).
553
554**TRAP-6 (the most likely cause of RX timeouts on a BLE+UWB device).** FiRa DS-TWR is
555time-slotted: the responder must transmit inside a 2 ms slot at a precise offset from the poll it
556just received. If the DW3xxx GPIO ISR is delayed or preempted long enough, the response misses its
557slot and the **controller** — the phone — reports an RX timeout, while the tracker looks healthy.
558On nRF with a BLE link running, MPSL/the SoftDevice Controller owns the highest interrupt
559priorities for RADIO/TIMER0/RTC0, so BLE activity will preempt the UWB ISR. The vendor's own
560FreeRTOS projects place the UWB SPI IRQ at priority 3 and GPIOTE at priority 6
561(`C:\qorvo\Projects\FreeRTOS\QANI\DWM3001CDK\ProjectDefinition\uwb_stack_llhw.cmake:9,55`) —
562i.e. deliberately high, above the general-purpose peripherals.
563
564Therefore the tracker firmware SHOULD:
565
566- give the DW3110 IRQ GPIO a high interrupt priority, above ordinary application work, and MUST
567 NOT do heavy work (logging, NVS writes, crypto over the BLE link, GATT notifications) inside the
568 ISR path or in anything that can block it;
569- consider suppressing BLE activity during a ranging session — or at minimum verify that BLE
570 connection events do not overlap ranging rounds. The system is running two radios, and DESIGN:51
571 only addresses their *RF* separation, not their *timing* contention.
572- **OQ-16** — No source specifies whether BLE should be quiesced during ranging. The design
573 requires the GATT link to be usable to *start* a find (DESIGN:203–204) but says nothing about
574 whether it should stay connected during it.
575
576Two further unknowns about the event loop:
577
578- **OQ-17** — `qplatform_init()` **disables** the UWB interrupt (`qplatform.c:245–247`) and
579 `qplatform_uwb_interrupt_enable()` is **never called anywhere in the visible SDK source** — it is
580 declared in `qplatform.h:46` and defined in `qplatform.c:159–169`, and no caller exists in
581 `Src/`, `Projects/`, or the open parts of `Libs/uwb-stack/`. It is presumably called from inside
582 the closed-source `llhw`. **If it is not, the tracker will never see a single DW3110 interrupt,
583 which is a complete and exact explanation of "phone transmits, gets RX timeouts".** This is the
584 first thing to check on hardware: probe the IRQ line, or call
585 `qplatform_uwb_interrupt_enable()` after `llhw_init()` and see whether behaviour changes.
586- **OQ-18** — `uwbmac_poll_events(ctx, timeout_us)` exists but is documented as *"only available
587 if you passed a NULL @event_loop_ops to uwbmac_init()"* (`uwbmac.h:323–340`), and
588 `uwbmac_init()` in this delivery takes only a context pointer (`uwbmac.h:291`); no
589 `event_loop_ops` symbol exists anywhere in the public headers. `uwbmac.h:286–288` says *"Some
590 flavors of uwbmac have their own init method in their dedicated headers"*. So the embedded
591 flavour appears to run its own internal context and the application pumps nothing — but neither
592 vendor sample calls `uwbmac_poll_events()`, and no document states this positively. If the
593 implementation is calling `uwbmac_poll_events()` from a thread, or *not* calling it when it
594 should, that is worth checking.
595
596Separately: **on Zephyr the `qtimer` HAL is entirely stubbed out.**
597`C:\qorvo\Libs\uwb-stack\libs\qhal\src\zephyr\qtimer.c` returns `NULL` from `qtimer_init()` and
598`QERR_ENOTSUP` from `qtimer_start/stop/read`. The idle timer that `qplatform_get_idle_timer_config()`
599advertises (32768 Hz, 24-bit, an RTC instance per
600`C:\qorvo\Libs\uwb-stack\libs\qhal\src\nrfx\qtimer.c:16,50–55`) therefore does not exist under
601Zephyr. **OQ-20**: whether `llhw` tolerates a NULL idle timer, or whether low-power/deferred
602scheduling silently breaks, is undocumented. Note also that the Zephyr `qplatform` variant
603`#error`s unless a devicetree node labelled **`dw35720`** exists
604(`C:\qorvo\Libs\uwb-stack\libs\qplatform\qm33_qhal_zephyr\src\qplatform.c:16–18`) — the Zephyr path
605was developed for the QM33/DW3572, not the DW3110, which is a reason to treat Zephyr support here
606as unproven.
607
608### 6.5 Required initialisation order — per-session bring-up
609
610Both vendor apps use the same sequence
611(`C:\qorvo\Src\Apps\Src\fira\fira_app.c:386–491`; `fira_niq.c:103–174,344–369`):
612
613```
614 5. uwbmac_set_short_addr(ctx, own_short_addr) /* MAC-layer HW address filter */
615 5b.[QANI only] uwbmac_set_promiscuous_mode(ctx, true) /* disables HW filtering */
616 6. fira_helper_open(&fira_ctx, ctx, ntf_cb, "endless", 0, user_data)
617 7. fira_helper_set_scheduler(&fira_ctx) /* MUST be while MAC is stopped */
618 8. fira_prepare_measurement_sequence(ctx, &session, is_report_required)
619 9. fira_helper_init_session(&fira_ctx, session_id,
620 QUWBS_FBS_SESSION_TYPE_RANGING_NO_IN_BAND_DATA, &rsp)
621 session_handle = rsp.session_handle
62210. fira_set_session_parameters(&fira_ctx, session_handle, &session)
62311. [controller only] fira_helper_add_controlee(...) /* NOT for the tracker */
62412. uwbmac_start(ctx) /* MUST precede step 13 */
62513. fira_helper_start_session(&fira_ctx, session_handle)
626```
627
628Hard constraints, each with a citation:
629
630- `fira_helper_open()` *"must be called first"* among the helper calls, and
631 `fira_helper_close()` must be called at the end; the helper owns the uwbmac channel, so the
632 application MUST NOT call `uwbmac_channel_create` / `uwbmac_channel_release`
633 (`fira_helper.h:1439–1457`).
634- `fira_helper_set_scheduler()` *"must be called while the UWB MAC is stopped"*
635 (`fira_helper.h:1479–1487`). It must therefore precede `uwbmac_start()`.
636- `fira_prepare_measurement_sequence()` calls `uwbmac_get_device_info()`
637 (`common_fira.c:150–157`), so it needs an initialised uwbmac; and it *mutates
638 `session.result_report_config`* (`common_fira.c:170–196`), so it MUST run **before**
639 `fira_set_session_parameters()` pushes that field, not after.
640- `fira_helper_init_session()` *"must be called first to create and initialize the fira session"*
641 and returns a **`session_handle` in `rsp.session_handle`** (`fira_helper.h:1500–1512`,
642 `fira_app.c:439–445`).
643- `uwbmac_start()` before `fira_helper_start_session()` (`fira_app.c:471–491`,
644 `fira_niq.c:355–367`).
645
646**TRAP-7. `session_id` and `session_handle` are different values.** Every
647`fira_helper_set_session_*` call, and `start`/`stop`/`deinit`, take the **handle** returned by
648`init_session`, not the session ID (`fira_app.c:439–453`, `fira_helper.h:1510–1546`). Passing the
649session ID where a handle is expected is a natural mistake, will be accepted by the compiler, and
650will make every parameter set silently target nothing.
651
652**Teardown order (as the vendor does it, which is surprising):** `uwbmac_stop()` is called
653**before** `fira_helper_stop_session()`, then `deinit_session`, `fira_helper_close`,
654`fira_uwb_mcps_deinit`, and finally `uwbmac_exit` (`fira_app.c:493–528,932–936`;
655`fira_niq.c:375–403`). `fira_helper_deinit_session()` returning `QERR_EBUSY` is documented as
656**success**, meaning an active session was deinited (`fira_helper.h:1536–1546`) — treating it as
657an error is wrong.
658
659**OQ-21** — QANI calls `fira_uwb_mcps_init()` *before* the SoftDevice/BLE task is created, with
660the comment *"To handle calibration and flash transactions before softdevice is up"*
661(`fira_niq.c:420–426`). That is an ordering constraint between UWB stack init and BLE stack init
662on nRF5+SoftDevice. Whether the equivalent constraint exists on Zephyr (where flash access is
663mediated differently) is undocumented. Given that this tracker's BLE must be up long before any
664find happens, the two cannot be ordered the vendor's way, and the consequences are unknown. **This
665is a structural difference between this design and the only vendor reference for a
666BLE-provisioned responder.**
667
668### 6.6 What the phone sends per find
669
670`…2f03…` carries exactly 8 bytes (HW:179–181, DESIGN:96–97):
671
672```
673offset size field
674 0 2 phoneAddr the controller's 2-byte UWB short address
675 2 4 sessionId uint32, big-endian
676 6 1 channel
677 7 1 preamble preamble code index
678```
679
680Everything else is either derived (§7) or must be pre-agreed as a constant (§6.7). The rationale
681for keeping this minimal is explicit: the GATT link is unbonded, so a stranger nearby could
682otherwise write their own STS key and range against someone else's tracker (DESIGN:92–97,
683HW:181–184).
684
685- **OQ-22** — `phoneAddr` byte order is **not specified**. `sessionId` is explicitly big-endian
686 (HW:180) but the 2-byte address is not. The Qorvo API takes a `uint16_t short_addr`
687 (`fira_helper.h:243–245`), and the vendor NI glue builds it from a byte array as
688 `AR2U16(x) = ((x[1] << 8) | x[0])` — i.e. **little-endian** (`fira_niq.c:43,186,218,220`),
689 matching the on-air 802.15.4 convention. Meanwhile HW:180 puts the rest of the blob in
690 big-endian. If the phone writes the address big-endian and the tracker reads it little-endian (or
691 vice versa) the addresses will not match, MAC filtering will drop everything, and the phone will
692 report RX timeouts. **This is a concrete, high-probability bug candidate.**
693- **OQ-23** — Nothing specifies whether the tracker should validate `channel` ∈ {5, 9} and
694 `preamble` ∈ {9..12} before use. The stack's own limits are given in §6.7; an out-of-range value
695 would be rejected by the region with `..._ERROR_INVALID_PREAMBLE_CODE_INDEX` /
696 `..._ERROR_INVALID_CHANNEL_...` reason codes (`fira_app.c:651,697`), but only if the tracker
697 surfaces the session-status notification.
698
699### 6.7 Complete FiRa session parameter set for the controlee/responder
700
701Values are the ones a controlee must hold to interoperate with a controller using
702`CONFIG_UNICAST_DS_TWR`. The "Source" column says where the value comes from; the
703"Must match?" column says whether a mismatch between phone and tracker is fatal.
704
705| Parameter (`struct session_parameters`) | Value | Numeric | Source | Must match? |
706|---|---|---|---|---|
707| `device_type` | `QUWBS_FBS_DEVICE_TYPE_CONTROLEE` | **0** | `fira_app.c:68`; `quwbs/fbs/defs.h:496–498` (controller = 1) | role, must be opposite |
708| `device_role` | `QUWBS_FBS_DEVICE_ROLE_RESPONDER` | **0** | `fira_app.c:69`; `defs.h:510–516` | role, must be opposite |
709| `ranging_round_usage` | `DSTWR_DEFERRED` | **2** | `fira_default_params.h`; `fira_region_params.h:147–152` | **exactly** |
710| `sts_config` | `FBS_STS_MODE_STATIC` | **0** | `fbs_region_params.h:397–403`; not pushed by `fira_set_session_parameters` → relies on the default | **exactly** |
711| `multi_node_mode` | `FIRA_MULTI_NODE_MODE_UNICAST` | **0** | `fira_default_params.h`; `fira_region_params.h:176–185` | **exactly** |
712| `schedule_mode` | `FIRA_SCHEDULE_MODE_TIME_SCHEDULED` | **1** | `fira_app.c:83`; `fira_region_params.h:240–247` | **exactly** |
713| `rframe_config` | `FIRA_RFRAME_CONFIG_SP3` | **3** | `fira_default_params.h`; `fira_region_params.h:261–265` | **exactly** |
714| `sfd_id` | `FIRA_SFD_ID_2` (4z SFD) | **2** | `fira_default_params.h`; `fira_region_params.h:305–309`; BPRF allows only 0 or 2 (`fira_helper.h:348–357`) | **exactly** |
715| `prf_mode` | `FIRA_PRF_MODE_BPRF` | **0** | `fira_helper.h:467–478`; only BPRF is supported (`fira_app.c:151–153`) | **exactly** |
716| `phr_data_rate` | 850 kbit/s | **0** | `fira_helper.h:371–381`; `fira_app.c:87–88` | **exactly** |
717| `psdu_data_rate` | 6.81 Mbps (default) | **0** | `fira_helper.h:358–370`; **not pushed** by `fira_set_session_parameters` | **exactly** |
718| `preamble_duration` | 64 symbols (default) | **1** | `fira_helper.h:336–346`; `fira_niq.c:210` sets it with the comment *"FIX The decryption issue"*; **not pushed** | **exactly** |
719| `sts_length` | 64 symbols (default) | **1** | `fira_helper.h:521–531`; `fira_niq.c:243`; **not pushed** | **exactly** |
720| `number_of_sts_segments` | 1 | **1** | `fira_helper.h:491–505`, documented **[NOT IMPLEMENTED]**; `fira_niq.c:242`; **not pushed** | **exactly** |
721| `channel_number` | 9 (5 also legal) | 9 | `FIRA_DEFAULT_CHANNEL_NUMBER` = 9 (`fira_region_params.h:63–64`); only 5 and 9 accepted (`uwb_translate.c:17–27`) | **from `…2f03…`** |
722| `preamble_code_index` | 10 | 10 | `FIRA_DEFAULT_PREAMBLE_CODE_INDEX` = 10 (`fira_region_params.h:65`); BPRF range documented as **9–12** in this stack (`fira_region_params.h:103–104`, `uwb_translate.c:178–190`) — note `fira_helper.h:319–328` claims 9–24 for BPRF, see OQ-24 | **from `…2f03…`** |
723| `slot_duration_rstu` | 2400 (= 2 ms; 1200 RSTU = 1 ms) | 2400 | **UCI capture** (see §6.7.1); agrees with `fira_default_params.h`; `fira_helper.h:258–261`; CLI rejects < 2400 (`fira_app.c:187–199`) though the capability minimum is 1200 (`fira_region_params.h:85`) | **exactly** |
724| `block_duration_ms` | **120** (`RANGING_DURATION`) | 120 | **UCI capture** (see §6.7.1). *Not* the sample-app default of 200. `fira_helper.h:266–269` | **exactly** |
725| `round_duration_slots` | **6** (`SLOTS_PER_RR`) | 6 | **UCI capture** (see §6.7.1). *Not* the sample-app default of 25. `fira_helper.h:262–265`; range 1–255 (`fira_app.c:215–228`) | **exactly** |
726| `block_stride_length` | 0 | 0 | pushed by `common_fira.c:234`, never set → 0 | **exactly** |
727| `round_hopping` | **true** (`HOPPING_MODE = 1`) | 1 | **UCI capture** (see §6.7.1). *Not* the sample-app default of `false`. `fira_helper.h:274–277`. See **OQ-30** — no Qorvo sample exercises hopping. | **exactly** |
728| `ranging_round_control` | `0x03` | 0x03 | `FIRA_DEFAULT_RANGING_ROUND_CONTROL` = 0x3; `fira_helper_bool_to_ranging_round_control(true,false)` (`fira_helper.h:2003–2010`) | **exactly**, see OQ-25 |
729| `result_report_config` | bit0 (ToF) set; azimuth/elevation/FoM **cleared** for a non-AoA chip | 0x01 | `FIRA_DEFAULT_RESULT_REPORT_CONFIG` = 0x1; `fira_helper.h:2439–2448`; `common_fira.c:189–196` clears the AoA bits when AoA is unsupported | **exactly** |
730| `report_rssi` | optional | — | pushed by `common_fira.c:240` | local only |
731| `enable_diagnostics` | optional (diagnostics are extremely useful for this bug) | — | `fira_helper.h:511–520`; `common_fira.c:239,254` | local only |
732| `short_addr` | tracker's own derived 2-byte UWB address (§7) | — | `fira_helper.h:243–245`; `common_fira.c:242–244` | **must equal what the phone uses as peer address** |
733| `destination_short_address[0]` | the **phone's** address, from `…2f03…` | — | `fira_app.c:65–66`; `common_fira.c:246–248` | **must equal the phone's own address** |
734| `n_destination_short_address` | **1** | 1 | `fira_app.c:65` — controlee sets 1, controller sets 0 | yes |
735| `n_controlees` | **0** | 0 | `fira_app.c:70` — controlee adds no controlees | yes |
736| `vupper64[8]` | derived STS key (§7), **byte order per §6.8** | — | `fira_helper.h:382–397`; `common_fira.c:236` | **exactly** |
737| `time0_ns` | 0 | 0 | `fira_niq.c:181–183` sets 0 with a comment that NI's ms-based init time does not map onto the stack's absolute UWB-domain time | see OQ-19 |
738| `meas_seq` | 1 step, `FIRA_MEASUREMENT_TYPE_RANGE`, `n_measurements = 1`, all antenna sets `0xff` | — | `common_fira.c:180–188` (the `AOA_NOT_SUPPORTED` branch, which is what a DW3110 takes) | local, but required |
739| `key_rotation`, `key_rotation_rate`, `sub_session_id` | unused with static STS | 0 | `fira_helper.h:398–418` — these apply to Dynamic/Provisioned STS only | n/a |
740
741#### 6.7.1 Provenance of the timing values, and a correction
742
743**Corrected 2026-08-22 after `compare` supplied a UCI capture.** The first revision of this table
744listed `block_duration_ms` = 200, `round_duration_slots` = 25 and `round_hopping` = false, sourced
745from `C:\qorvo\Src\Apps\Src\fira\Inc\fira_default_params.h`. **Those numbers were wrong as
746requirements.** They are the Qorvo *sample application's* defaults, and this document had no
747business presenting them as the values the tracker must hold.
748
749The authoritative values come from a capture of the **`SESSION_SET_APP_CONFIG` the Android
750controller actually sends**:
751
752| UCI parameter | Value | → `session_parameters` field |
753|---|---|---|
754| `SLOT_DURATION` | 2400 RSTU | `slot_duration_rstu` = 2400 |
755| `RANGING_DURATION` | 120 ms | `block_duration_ms` = 120 |
756| `SLOTS_PER_RR` | 6 | `round_duration_slots` = 6 |
757| `HOPPING_MODE` | 1 | `round_hopping` = **true** |
758
759A capture of what the peer programs is strictly better evidence than any documentary inference, and
760it directly closes item 2 of §8 for these four fields. Sanity check: 6 slots × 2400 RSTU = 12 ms of
761ranging round inside a 120 ms block, which is consistent.
762
763**The methodological error is worth recording, because it is the same class of mistake the rest of
764this document warns about.** The table conflated two separate claims in one row: *"this field must
765match exactly on both sides"* (true, and the important point) and *"its value is N"* (which for
766these four fields was only ever a sample-app default). The "Source" column named
767`fira_default_params.h` honestly, but the "Must match?" column said **exactly** next to a number
768that nothing had established. Where the Source column for a value in this table names only a Qorvo
769`FIRA_DEFAULT_*` macro or a vendor sample app, **read it as "the Qorvo side will do this unless told
770otherwise", not as "Android does this"** — the two coincide for the spec-derived PHY fields
771(channel 9 / preamble 10 are labelled UCI-spec defaults at `fira_region_params.h:63–65`) but plainly
772did not coincide for the timing fields.
773
774- **OQ-30** — **`round_hopping = true` is a path no Qorvo sample application exercises.**
775 `FIRA_DEFAULT_ROUND_HOPPING` is `false`, and the CLI only enables it via an explicit `-HOP`
776 argument (`fira_app.c:281–285`). More pointedly, QANI's `round_duration_slots` computation carries
777 the comment *"+1 slot to satisfy corner case when the # of RR is exact the same as the # of slots
778 in TWR. **This is fine because hopping is disabled in the NI protocol**"*
779 (`fira_niq.c:206`) — i.e. the vendor explicitly relies on hopping being off in the one reference
780 that resembles this product. With Android enabling hopping, that assumption does not hold, and
781 whether this stack's controlee-side hop-sequence derivation is correct against Android is
782 unvalidated by any vendor code. If ranging fails *intermittently* or only after the first few
783 blocks rather than never, this is where to look.
784
785**TRAP-8. `session_parameters` MUST be zero-initialised.** `fira_set_session_parameters()`
786(`common_fira.c:208–259`) pushes 25 fields including `prf_mode`, `phr_data_rate`, `sfd_id`,
787`schedule_mode` and `block_stride_length`, and `fira_set_default_params()` (`fira_app.c:49–99`)
788does **not** assign several of them — it relies on the struct living in a zero-initialised static
789(`.rconfig`) section (`driver_app_config.c`, `fira_niq.c:101`). A stack-allocated
790`struct session_parameters` without a `memset` will push garbage for `prf_mode`,
791`block_stride_length`, `priority`, `mac_address_mode`, `link_layer_mode` and more, and the failures
792will be timing/PHY-level rather than a clean error return.
793
794**Fields that `fira_set_session_parameters()` does NOT push**, and which therefore keep the FiRa
795region's internal defaults regardless of what you put in the struct (`common_fira.c:220–256`):
796`sts_config`, `preamble_duration`, `psdu_data_rate`, `sts_length`, `number_of_sts_segments`,
797`mac_address_mode`, `priority`, `link_layer_mode`, `mac_fcs_type`, `time0_ns`,
798`max_number_of_measurements`, `max_rr_retry`, `termination_count`, `key_rotation*`,
799`sub_session_id`, `session_info_ntf_config` and the proximity/AoA-bound fields.
800
801This creates a genuine oddity: **QANI sets `preamble_duration`, `sts_length` and
802`number_of_sts_segments` in the struct and then calls the same `fira_set_session_parameters()`
803that never transmits them** (`fira_niq.c:210,242–243` vs `common_fira.c:220–256`). The
804*"FIX The decryption issue"* comment on `preamble_duration` therefore documents a fix that, on the
805face of the code, cannot be taking effect through this path. **OQ-26**: either there is another
806setter path, or the region default already equals 64 symbols and the assignment is vestigial. If
807the phone ever selects a 32-symbol preamble, this matters.
808
809**TRAP-9. `sts_config` for static STS is `0`, and one of the vendor's own doc comments says
810`0x01`.** `struct session_parameters.sts_config` documents *"0x00: Static STS (default)"*
811(`fira_helper.h:216–229`) and `enum fbs_sts_mode` has `FBS_STS_MODE_STATIC = 0`
812(`fbs_region_params.h:397–403`). But `fira_helper_set_session_sts_config()` documents
813*"0x01: Static STS (default). 0x02: Dynamic STS. 0x08: Provisioned STS"*
814(`fira_helper.h:2036–2050`) — those are **capability bitmask** values mislabelled as parameter
815values. Calling `fira_helper_set_session_sts_config(ctx, h, 0x01)` in the belief that static STS is
816`0x01` selects **Dynamic STS**, guaranteeing an STS mismatch and RX failures. The safe course is
817what both vendor apps do: **never call this setter at all** and leave `sts_config` at its
818zero-initialised default (`common_fira.c:220–256` omits it).
819
820**Address filtering.** `uwbmac_set_short_addr()` sets the **MAC-layer hardware address filter**
821and is a *separate* call from `fira_helper_set_session_short_address()`; both vendor apps make
822both calls (`fira_app.c:413–414` + `common_fira.c:242–244`; `fira_niq.c:128` + same).
823`uwbmac.h:558–567` notes *"HW Filtering is disabled if promiscuous mode is enabled"*.
824**TRAP-10:** if the firmware sets only the *session* short address and neither
825`uwbmac_set_short_addr()` nor promiscuous mode, the DW3110's hardware filter will discard the
826phone's poll frames before the MAC ever sees them — the tracker never responds and the phone
827reports RX timeouts, with no error on the tracker side. QANI additionally enables promiscuous mode
828(`uwbmac_set_promiscuous_mode(ctx, true)`, `fira_niq.c:125–126`) — note the code comment there says
829*"Unset promiscuous to accept only filtered frames"* while passing `true`, i.e. the comment is
830wrong and filtering is in fact **disabled**. Enabling promiscuous mode is the more forgiving option
831for an accessory and is what the only BLE-provisioned vendor reference does.
832
833**Responder slot index.** There is **no responder-slot-index parameter in this API.** Grepping
834`fira_helper.h` finds `slot_index` only as a diagnostic *output* — *"In case of error, slot index
835where the error was detected"* (`fira_helper.h:838–843`). For `MULTI_NODE_MODE_UNICAST` there is
836exactly one responder, so its slot is implicit in the DS-TWR round structure and no configuration
837is needed. **OQ-27**: for one-to-many the ordering would come from the controller's controlee list
838(`fira_app.c:457–466`), but that is not this configuration.
839
840- **OQ-24** — The BPRF preamble-code range is stated inconsistently *within the same SDK*:
841 `fira_helper.h:319–328` says "9-24: BPRF", while `fira_region_params.h:103–104` says
842 `FIRA_PCODE_BPRF_MIN 9` / `FIRA_PCODE_BPRF_MAX 12` with the explicit comment *"Doesn't match
843 with MCPS802154_LLHW_BPRF_MAX"*, and `uwb_translate.c:178–190` accepts only 9–12. **Treat 9–12 as
844 the real limit.** If the phone selects a preamble index above 12, this stack will reject it.
845- **OQ-25** — `ranging_round_control` bit semantics are documented inconsistently.
846 `fira_helper.h:287–293` says b1 = *"Control Message is sent in band(1) or not (0, not
847 supported)"* and b2 = *"Control Message is sent separately(0) or piggybacked to RIM(1)"*, but
848 `fira_helper_bool_to_ranging_round_control(result_report_phase, skip_ranging_control_phase)`
849 unconditionally sets b1 and maps its second argument to b2 as *"skip ranging control phase"*
850 (`fira_helper.h:1996–2010`). `FIRA_DEFAULT_RANGING_ROUND_CONTROL` is `0x3` with the comment
851 *"Result report phase, skip ranging control phase"* — which contradicts `0x3` (b2 clear). The
852 value `0x03` is what both vendor apps end up with; whether it means what the comment says is
853 unresolved, and it must match the phone.
854- **OQ-19** — Nothing states whether the responder must be started before the initiator, or what
855 `time0_ns` / UWB initiation time the tracker should use. `fira_niq.c:181–183` sets `time0_ns = 0`
856 and notes the NI protocol's ms-based init time does not map onto the stack's absolute
857 UWB-domain time. In QANI the accessory starts its session on the *"configure and start"* BLE
858 message and the iPhone starts after (`Projects/FreeRTOS/QANI/README.md`), so responder-first is
859 the vendor's ordering — but the phone side of this design has no equivalent handshake defined
860 (see OQ-7), so the tracker may well be started *after* the phone has already begun polling,
861 which would produce exactly the reported symptom for the first several blocks. **This is a
862 first-order suspect and it is a design gap, not just an implementation gap.**
863
864### 6.8 vUpper64 composition and byte order
865
866Static STS is keyed by the 8-byte **vUpper64**, which the struct exposes as a union
867(`fira_helper.h:382–397`):
868
869```c
870union {
871 struct {
872 uint8_t static_sts_iv[FIRA_STATIC_STS_IV_SIZE]; /* 6 */
873 uint8_t vendor_id[FIRA_VENDOR_ID_SIZE]; /* 2 */
874 };
875 uint8_t vupper64[FIRA_VUPPER64_SIZE]; /* 8 */
876};
877```
878
879So **in this struct's layout, `vupper64[0..5]` is the STATIC_STS_IV and `vupper64[6..7]` is the
880VENDOR_ID** — confirmed by the vendor's own printer, which formats `v[0]..v[5]` as `STATIC_STS_IV`
881and `v[6],v[7]` as `VENDOR_ID` (`common_fira.c:122–124`).
882
883**TRAP-11 — the byte-order trap.** Qorvo's NI accessory glue fills the array **fully reversed**
884relative to the `VendorId || StaticStsIv` concatenation used out of band
885(`fira_niq.c:228–235`):
886
887```c
888vupper64[7] = Vendor_ID[0]; vupper64[6] = Vendor_ID[1];
889vupper64[5] = Static_STS_IV[0]; vupper64[4] = Static_STS_IV[1];
890vupper64[3] = Static_STS_IV[2]; vupper64[2] = Static_STS_IV[3];
891vupper64[1] = Static_STS_IV[4]; vupper64[0] = Static_STS_IV[5];
892```
893
894Meanwhile PLAN:28 specifies the tracker's key as an 8-byte HKDF output, chosen because *"8 bytes
895is exactly what `setSessionKeyInfo` takes … and under FiRa that is `[2B VendorID][6B
896STATIC_STS_IV]`"*. If that 8-byte blob is `memcpy`'d straight into `vupper64`, the resulting STS
897will **not** match the phone's, because the phone's stack interprets the same 8 bytes in the
898opposite order. The observable symptom is precisely one-way RX failure: frames are transmitted with
899a scrambled timestamp sequence the peer cannot correlate, so the peer times out, and the tracker's
900own diagnostics (if enabled) would show `RX_PHY_STS_FAILED` or `RX_TIMEOUT`
901(`fira_app.c:556,565`).
902
903The correct handling is: treat the 8-byte derived value as `[2B VendorID][6B STATIC_STS_IV]`, then
904lay it into the Qorvo struct so that `static_sts_iv` and `vendor_id` land in their documented
905positions with the byte order the vendor's NI glue uses. **OQ-28**: I cannot cite an authoritative
906statement of which of the two orderings is the one Android uses, because I found no citable
907documentation for `setSessionKeyInfo`'s byte layout (see §8). Whichever it is, **this is a single
908byte-order decision that fully determines whether ranging works, and it must be settled by
909experiment (try both) rather than by reasoning.** It is my leading candidate for the reported bug
910alongside OQ-17 and OQ-19.
911
912Note also that `fira_helper_set_session_key()` takes a **128- or 256-bit** key
913(`fira_helper.h:3595–3605`) and is for Dynamic/Provisioned STS. An 8-byte value is *not* a session
914key here — it is the vUpper64. Passing the derived 8 bytes to `fira_helper_set_session_key()` would
915be wrong on two counts (wrong API, illegal length).
916
917### 6.9 DWM3001CDK hardware wiring for the DW3110
918
919From the vendor's own DWM3001CDK project definition
920(`C:\qorvo\Projects\FreeRTOS\QANI\DWM3001CDK\ProjectDefinition\uwb_stack_llhw.cmake:5–24`):
921
922| Signal | nRF52833 pin |
923|---|---|
924| SPI instance | SPIM**3** |
925| SCK | P0.03 |
926| MOSI | P0.08 |
927| MISO | P0.29 (with MISO pull configured — `NRFX_SPIM_MISO_PULL_CFG=1`, `:34`) |
928| CS | P1.06 |
929| WAKEUP | P1.19 |
930| IRQ | P1.02 |
931| RSTn | P0.25 |
932
933Interrupt priorities the vendor chose: UWB SPI IRQ **3**, GPIOTE **6**, SPIM default **7**
934(`:9,48,55`). SPI must start slow (`CONFIG_SPI_UWB_SLOW_RATE_FREQ`, default 4 MHz —
935`qplatform_internal.h:14–15`) and only move to `CONFIG_SPI_UWB_FAST_RATE_FREQ` after cold start
936(`qplatform.c:176–190,211–212`).
937
938Note this pinout differs entirely from HW §4, which is the custom nRF52840 board, not the dev kit
939(HW:5–12). **Do not use HW §4's pin map for the DWM3001CDK.**
940
941Under Zephyr, the DW3xxx must appear in devicetree as a node labelled **`dw35720`** on an SPI bus,
942with `rstn-gpios` and `irq-gpios` properties, or `qplatform.c` fails to compile
943(`C:\qorvo\Libs\uwb-stack\libs\qplatform\qm33_qhal_zephyr\src\qplatform.c:16–28`). The Zephyr
944variant defines **no WAKEUP pin** (compare the non-Zephyr variant's `CONFIG_DWT_WU_GPIO_*`,
945`uwb_stack_llhw.cmake:18–19`). **OQ-29**: how the DW3110 is woken from deep sleep under the Zephyr
946platform layer is undocumented; `dwt_probe_interf.wakeup_device_with_io = qplatform_uwb_wakeup` →
947`qpwr_uwb_wakeup()` (`qplatform.c:236–239,258`) and the qpwr implementation for QM33 is at
948`Libs\uwb-stack\libs\qhal\src\qm33\qpwr.c`, which I did not trace.
949
950---
951
952## 7. Key derivation
953
954Two values are **derived on both sides** from the 32-byte bind-time `beaconSecret` and are never
955transmitted over the air, because the GATT link is unbonded and anything on it could come from a
956stranger nearby (DESIGN:92–97, HW:181–187, PLAN:26–31):
957
958```
959stsKey = HKDF-SHA256(beaconSecret,
960 info = "com.vayunmathur.findfamily/uwb-sts" || u32_be(sessionId))[0..8]
961uwbAddr = HKDF-SHA256(beaconSecret,
962 info = "com.vayunmathur.findfamily/uwb-addr")[0..2]
963```
964
965With, per HW:186–187:
966
967- **salt = 32 zero bytes**;
968- HKDF = RFC 5869 extract-then-expand over HMAC-SHA256 (PLAN:31);
969- reserved addresses `0x0000` and `0xFFFF` have their **low byte set to `0x01`**.
970
971Mixing `sessionId` into the STS derivation gives every find a distinct IV (PLAN:28). The
972`sessionId` is 4 bytes big-endian, matching its wire format on `…2f03…` (HW:180).
973
974The firmware MUST produce byte-identical output to the Kotlin implementation; PLAN:42 requires
975PSA Crypto for this, and PLAN:82 requires it be *"byte-identical to `TrackerUwbKeys.kt`"*, with
976fixed test vectors in `TrackerUwbKeysTest.kt` (HW:187–188, PLAN:124).
977
978### 7.1 What both sides must agree on
979
980| Item | Agreement mechanism |
981|---|---|
982| `beaconSecret` | Written once at bind time over GATT (§4); the root of everything. |
983| `sessionId` | Sent per find on `…2f03…` (§6.6); feeds the STS derivation. |
984| STS key / vUpper64 | Derived independently from `(secret, sessionId)`. **Byte order into the Qorvo struct is unresolved — OQ-28.** |
985| Tracker UWB short address | Derived independently from `secret`. The phone uses it as `peerAddress`; the tracker uses it as both its session `short_addr` **and** its `uwbmac_set_short_addr()` MAC filter address. |
986| Phone UWB short address | Sent per find on `…2f03…`. **Byte order unspecified — OQ-22.** |
987| Channel, preamble | Sent per find on `…2f03…`. |
988| Everything in the §6.7 table marked "exactly" | **Hard-coded constants on both sides.** Nothing negotiates them. |
989
990### 7.2 Negotiated vs. must-match-exactly
991
992This is the crux of FiRa OOB interop and worth stating baldly:
993
994**Nothing in a static-STS unicast DS-TWR session is negotiated over the UWB link.** There is no
995capability exchange, no parameter negotiation, and (in this configuration) no in-band control
996message that would let the controller reconfigure the controlee's PHY or timing. The only things
997that flow at run time are the ranging frames themselves. Consequently:
998
999- **Carried out of band per find (3 values):** phone short address, session ID, channel, preamble
1000 — four fields in eight bytes (§6.6).
1001- **Derived out of band (2 values):** STS key/vUpper64, tracker short address (§7).
1002- **Everything else must be identical by construction** — `ranging_round_usage`, `sts_config`,
1003 `multi_node_mode`, `schedule_mode`, `rframe_config`, `sfd_id`, `prf_mode`, `phr_data_rate`,
1004 `psdu_data_rate`, `preamble_duration`, `sts_length`, `number_of_sts_segments`,
1005 `slot_duration_rstu`, `block_duration_ms`, `round_duration_slots`, `round_hopping`,
1006 `block_stride_length`, `ranging_round_control`, `result_report_config`.
1007
1008A mismatch in **any** of the 19 fields in that last group produces the same symptom — the peer
1009transmits and times out — with no diagnostic distinguishing which one. That is why the §6.7 table
1010enumerates them all with citations rather than only the interesting ones, and why enabling the
1011tracker's session-status and diagnostics notifications (`fira_helper.h:511–520`,
1012`common_fira.c:239,254`, `fira_app.c:583–728` for the reason-code strings) is worth doing before
1013guessing: the region emits specific reason codes such as
1014`..._ERROR_INVALID_STS_CONFIG`, `..._ERROR_INVALID_RFRAME_CONFIG`,
1015`..._ERROR_SLOT_LENGTH_NOT_SUPPORTED`, `..._ERROR_INSUFFICIENT_SLOTS_PER_RR`,
1016`..._ERROR_INVALID_RANGING_DURATION` and `..._ERROR_INVALID_PREAMBLE_CODE_INDEX`
1017(`fira_app.c:627–660`).
1018
1019---
1020
1021## 8. Android-side requirements I could NOT source
1022
1023The task asked for the Android `CONFIG_UNICAST_DS_TWR` parameter set. **I was unable to obtain
1024authoritative documentation for it**, and I am deliberately not reconstructing it from memory.
1025
1026> **Partially superseded 2026-08-22.** `compare` supplied a capture of Android's actual
1027> `SESSION_SET_APP_CONFIG`, which resolves the four timing fields (`SLOT_DURATION` 2400,
1028> `RANGING_DURATION` 120, `SLOTS_PER_RR` 6, `HOPPING_MODE` 1) — see §6.7.1, where the table has been
1029> corrected. `compare` also reports having cross-checked all 19 must-match fields against both sides
1030> and found them in agreement, which **rules out a parameter mismatch as the cause of the RX
1031> timeouts**; §12 has been reordered accordingly. The items below that the capture does not cover
1032> remain open, and a capture of one phone/one Android version is not the same as documentation of
1033> what the API guarantees.
1034
1035Specifically, I could not cite:
1036
10371. What FiRa session parameters `androidx.core.uwb.RangingParameters.CONFIG_UNICAST_DS_TWR` /
1038 `android.ranging`'s `UwbRangingParams.CONFIG_UNICAST_DS_TWR` (FiRa "Config ID 1") actually
1039 implies for ranging round usage, STS config, multi-node mode, rframe config, schedule mode,
1040 round hopping, or ranging round control. *(The capture shows what one device sent; it does not
1041 tell us which of these the config ID pins versus which are AOSP defaults that could change.)*
10422. AOSP's `FiraOpenSessionParams` defaults for `SLOT_DURATION_RSTU`, `RANGING_INTERVAL_MS`,
1043 `SLOTS_PER_RANGING_ROUND`, `SFD_ID`, PHR/PSDU data rate, preamble duration, STS length, number
1044 of STS segments, or MAC address mode. *(First three now observed — §6.7.1. The rest are still
1045 uncited; note `compare` observes that `phr_data_rate` is assigned the wrong enum
1046 (`FIRA_PRF_MODE_BPRF`) but that this is cosmetic, since it equals 0, which equals
1047 `FIRA_PHR_DATA_RATE_850K`, which is what Android defaults to.)*
10483. The byte layout and byte order of `setSessionKeyInfo(byte[8])` for STATIC STS, and how it maps
1049 onto vUpper64. (This is **OQ-28**, the highest-value unknown in this document. `compare`
1050 independently confirms TRAP-11 and ranks it as a top blocker.)
10514. Byte order of `androidx.core.uwb.UwbAddress`'s 2-byte short address (**OQ-22**).
10525. Whether the Android controller sends any in-band control message conveying slot assignment, or
1053 whether Android exposes a responder slot index (**OQ-27**).
10546. Whether Android requires the responder to be started first, and any `UWB_INITIATION_TIME`
1055 requirement (**OQ-19**).
10567. Whether Android's GATT client auto-promotes over-MTU writes to long writes (**OQ-10**).
10578. Android `ScanFilter` matching semantics for 128-bit service data, and confirmation that
1058 `setLegacy(false)` is required for extended advertisements. (DESIGN:204 and PLAN:72 assert the
1059 latter; I have no independent citation.)
10609. Android address-type handling on reconnect (**OQ-5**).
1061
1062**What I did:** searched Meta's internal knowledge base (wikis, Google Docs, Workplace posts,
1063diffs, tasks) four times with different framings; the only UWB-adjacent internal document is a
1064hardware feasibility proposal with no API content. No Android SDK is installed on this machine
1065(`%LOCALAPPDATA%\Android\Sdk` does not exist) and no `androidx.core.uwb` or `android.ranging`
1066artifact is present in the Gradle cache.
1067
1068**Where the authoritative answers live:** the FiRa Consortium UCI Generic Technical Specification
1069(which `fira_region_params.h:98–102` cites by name — *"v2.0.0_0.9r2, Section 8.2 Device
1070Configuration Parameters"* — and which `fira_region_params.h:36–38` cites as *"UCI spec
1071v2.0.0_0.9r11::Table 46"*), AOSP `packages/modules/Uwb`, and the `androidx.core.uwb` reference
1072docs. The §6.7 table is the **Qorvo-side** requirement set; it needs to be cross-checked field by
1073field against whatever Android actually programs, and any disagreement is a bug.
1074
1075A useful shortcut: the defaults in the §6.7 table (channel 9, preamble 10, slot 2400 RSTU, block
1076200 ms, 25 slots/round, SP3, SFD 2, DS-TWR deferred, unicast, static STS, no hopping) are the
1077Qorvo/FiRa *spec* defaults, not arbitrary Qorvo choices —
1078`fira_region_params.h:63–65` labels channel 9 / preamble 10 as *"Default channel and preamble code
1079in UCI spec v2.0.0"*. They are therefore a reasonable prior for what Android will pick, but a prior
1080is not a citation.
1081
1082---
1083
1084## 9. Index of OPEN QUESTIONS
1085
1086| # | Question | § |
1087|---|---|---|
1088| OQ-1 | Beacon and pairing advertising intervals are unspecified. | 1.5 |
1089| OQ-2 | Whether the beacon should be motion-gated. | 1.5 |
1090| OQ-3 | What a provisioned tracker advertises after a long-press back into pairing mode. | 1.5 |
1091| OQ-4 | Rotating epoch IDs vs. a stable random-static BLE address — the link-layer identifier defeats the payload-level privacy goal. | 2.1 |
1092| OQ-5 | Android address-type handling when reconnecting by stored address; no source mentions address type at all. | 2.2 |
1093| OQ-6 | Store the BLE address vs. re-scan for the beacon before a find. | 2.2 |
1094| OQ-7 | `…2f03…` notify semantics: what is notified, when, with what payload. | 3.1 |
1095| OQ-8 | GATT characteristic permissions (encryption/authentication) are never stated. | 3.1 |
1096| OQ-9 | Behaviour on re-provisioning an already-bound tracker; no unbind protocol exists despite the anti-theft claim. | 3.1 |
1097| OQ-10 | Whether Android auto-promotes over-MTU writes to long writes. | 3.2 |
1098| OQ-11 | Whether to beacon at all when the time base was lost. | 4.2 |
1099| OQ-12 | Battery-percent byte units, and what the DWM3001CDK should report with no divider. | 4.2 |
1100| OQ-13 | (informational) Firmware has no stake in the server contract. | 5.3 |
1101| OQ-14 | Volatile vs. persistent L1 config. | 6.2 |
1102| OQ-15 | Whether `mcps_crypto_*` may be PSA-backed, and whether PSA is safe from the DW3xxx ISR context. | 6.3 |
1103| OQ-16 | Whether BLE should be quiesced during a ranging session. | 6.4 |
1104| **OQ-17** | **`qplatform_uwb_interrupt_enable()` has no visible caller. If nothing enables the DW3110 IRQ, the tracker sees no interrupts at all.** | 6.4 |
1105| OQ-18 | Whether the application must pump `uwbmac_poll_events()` in this delivery. | 6.4 |
1106| **OQ-19** | **Responder-vs-initiator start order and UWB initiation time; the design has no start handshake, so the tracker may start after the phone is already polling.** | 6.7 |
1107| OQ-20 | Zephyr `qtimer` is stubbed; effect of a missing idle timer on `llhw` is unknown. | 6.4 |
1108| OQ-21 | Vendor requires UWB stack init before the BLE stack; this design cannot honour that. | 6.5 |
1109| **OQ-22** | **`phoneAddr` byte order on `…2f03…` is unspecified; the rest of the blob is big-endian but the Qorvo/802.15.4 convention is little-endian.** | 6.6 |
1110| OQ-23 | Whether the tracker validates channel/preamble from `…2f03…`. | 6.6 |
1111| OQ-24 | BPRF preamble range: 9–24 vs 9–12, contradictory within the SDK. Treat 9–12 as real. | 6.7 |
1112| OQ-25 | `ranging_round_control` bit semantics are self-contradictory in the SDK. | 6.7 |
1113| OQ-26 | QANI sets `preamble_duration`/`sts_length`/`sts_segments` that `fira_set_session_parameters()` never pushes. | 6.7 |
1114| OQ-27 | Responder slot index does not exist in this API; not needed for unicast. | 6.7 |
1115| **OQ-28** | **vUpper64 byte order between the derived 8-byte key and the Qorvo struct. Single most likely root cause. Must be settled by trying both orderings.** | 6.8 |
1116| OQ-29 | DW3110 deep-sleep wake path under the Zephyr platform layer. | 6.9 |
1117| OQ-30 | `round_hopping = true` (which Android uses) is exercised by no Qorvo sample, and QANI explicitly relies on hopping being **off**. | 6.7.1 |
1118
1119---
1120
1121## 10. Index of TRAPs — where a natural implementation goes wrong
1122
1123| # | Trap | § |
1124|---|---|---|
1125| TRAP-1 | Android `getRemoteDevice(String)` assumes a public address; the tracker advertises random static. | 2.2 |
1126| TRAP-2 | 48-byte GATT write is impossible at Zephyr defaults: `BT_L2CAP_TX_MTU` = 23 and `BT_ATT_PREPARE_COUNT` = 0 disables long writes. | 3.2 |
1127| TRAP-3 | Re-persisting the provisioning timestamp rather than `provision_time + elapsed` silently drifts out of the owner's search window. | 4.2 |
1128| TRAP-4 | Omitting the `l1_config_platform_ops.reset_to_default` OTP hook leaves the radio uncalibrated (no antenna paths, no XTAL trim, no TX power index) with **no error anywhere**. | 6.2 |
1129| TRAP-5 | The ~16 `mcps_crypto_*` primitives are application-supplied; stubs or wrong AES modes produce STS mismatch, i.e. RX timeouts. | 6.3 |
1130| TRAP-6 | The whole DW3xxx ISR and MAC run in GPIO interrupt context; BLE preemption can push the responder's TX out of its 2 ms slot. | 6.4 |
1131| TRAP-7 | `session_id` ≠ `session_handle`; every setter takes the handle from `init_session`'s response. | 6.5 |
1132| TRAP-8 | `struct session_parameters` must be zero-initialised; the vendor relies on static zero-init for ~8 fields it never assigns. | 6.7 |
1133| TRAP-9 | Static STS is `sts_config = 0`; one vendor doc comment says `0x01`, which actually selects **Dynamic** STS. Do not call that setter. | 6.7 |
1134| TRAP-10 | Setting only the *session* short address, without `uwbmac_set_short_addr()` or promiscuous mode, leaves the hardware address filter discarding the phone's polls. | 6.7 |
1135| TRAP-11 | vUpper64 is laid out **reversed** by Qorvo's NI glue relative to `VendorId‖StaticStsIv`; a straight `memcpy` of the derived 8 bytes yields a mismatched STS. | 6.8 |
1136
1137---
1138
1139## 11. Contradictions found in the project's own documents
1140
1141Recorded because they are latent bug sources, not because they need resolving here.
1142
11431. **Who chooses the STS key.** DESIGN:84–89 says the phone *"picks the session params … and hands
1144 them to the tracker"*, and PLAN:12 flags that DESIGN previously said this explicitly included
1145 the STS key. DESIGN:92–97 and HW:181–187 both say the STS key is **derived, not sent**. The
1146 derived reading is the correct one; DESIGN:84–89's "the phone picks the params" must be read as
1147 excluding the STS key and the tracker's UWB address.
11482. **Which crowd-finding scheme shipped.** DESIGN §1 (line 47) and §5.1–5.4 describe rotating
1149 per-epoch EC keys ("Option B"); DESIGN:150–156 says that is **not** what shipped and the
1150 rotating-hash + ML-KEM scheme in §5.5 is. §5 of this document follows the shipped scheme.
1151 PLAN:12 records this same contradiction as unresolved.
11523. **DESIGN §6 says the per-find handoff carries "only channel/slot"** (DESIGN:216–219) while
1153 HW:179–181 defines it as `[2B phoneAddr][4B sessionId][1B channel][1B preamble]`. HW is more
1154 specific and consistent with DESIGN:96–97; follow HW.
11554. **HW §4's pin map is for the wrong board.** HW §1–§4 specifies a bare nRF52840 custom board;
1156 the bench target is the DWM3001CDK (nRF52833), and HW:5–12 says so explicitly. The DW3110 pin
1157 assignments that actually apply are in §6.9 of this document, taken from Qorvo's own
1158 DWM3001CDK project definition. Using HW §4's table would wire SPI to the wrong pins entirely.
11595. **DESIGN:36–38 and PLAN:23,46 say the UWB firmware is staged behind `CONFIG_FF_TRACKER_UWB`
1160 (default `n`) and "never compiled"** because the licensed Qorvo driver was unavailable. The SDK
1161 is now present at `C:\qorvo`, so that premise no longer holds, but no document has been updated
1162 to say what the flag's state should now be, or whether the staged code was ever compiled before
1163 it was first run against hardware. PLAN:139 is explicit that UWB ranging was **not verifiable**
1164 at the time of writing and that success would not be claimed on the basis of compiling.
1165
1166---
1167
1168## 12. Suggested order of investigation for the reported bug
1169
1170The reported symptom is: **the phone transmits and gets RX timeouts.** That means the phone's
1171receiver never gets a valid, correlatable response in the expected slot. Ordered by
1172(probability × cheapness to check):
1173
11741. **Is the tracker seeing DW3110 interrupts at all?** OQ-17 / TRAP-6. Check whether anything calls
1175 `qplatform_uwb_interrupt_enable()` after `llhw_init()`. If not, nothing downstream can work.
1176 Cheapest possible check and a complete explanation of the symptom.
11772. **Enable the tracker's own notifications before guessing.** `fira_helper_open`'s notification
1178 callback delivers `FIRA_HELPER_CB_TYPE_SESSION_STATUS_NTF` (state + reason code) and
1179 `..._TWR_RANGE_NTF` (per-measurement status). The reason-code and status strings in
1180 `fira_app.c:546–728` distinguish "never heard anything" (`RX_TIMEOUT`) from "heard it, STS wrong"
1181 (`RX_PHY_STS_FAILED`) from "parameter rejected" (`ERROR_INVALID_STS_CONFIG`,
1182 `ERROR_INVALID_RFRAME_CONFIG`, `ERROR_SLOT_LENGTH_NOT_SUPPORTED`, …). This single step collapses
1183 most of the search space and should precede any parameter fiddling.
11843. **Address filtering.** TRAP-10 / OQ-22. Verify `uwbmac_set_short_addr()` is called with the
1185 derived address, and try `uwbmac_set_promiscuous_mode(ctx, true)` as the vendor's BLE-provisioned
1186 reference does. Independently, try both byte orders for `phoneAddr` from `…2f03…`.
11874. **vUpper64 byte order.** TRAP-11 / OQ-28. Try both orderings. Two builds, one experiment.
11885. **L1 config / OTP calibration.** TRAP-4. Verify a `reset_to_default` hook exists, runs after
1189 `dwt_probe()`, and configures antenna paths, antenna delays, TX power index, XTAL trim and
1190 pg_count. Missing XTAL trim in particular can prevent the peer from acquiring.
11916. **`mcps_crypto_*` completeness.** TRAP-5. Confirm all ~16 symbols are real AES-CMAC/CCM*/ECB.
11927. **Start order.** OQ-19. Confirm the tracker's session reaches `ACTIVE` before the phone starts
1193 polling, and add whatever handshake OQ-7 is missing if it does not.
11948. **Zero-initialisation of `session_parameters`.** TRAP-8.
11959. **Field-by-field diff of the §6.7 table against what the phone programs.** `compare` reports
1196 having done this against a UCI capture and found all 19 must-match fields in agreement, so
1197 **this is ruled out** — keep it on the list only to re-verify after any parameter change. It was
1198 also the step that caught a real error in §6.7's own timing values (see §6.7.1).
119910. **`round_hopping` behaviour.** OQ-30. Android enables hopping; no Qorvo sample does, and QANI's
1200 code comments explicitly assume it is off. Suspect this specifically if ranging fails
1201 intermittently, or works for the first blocks and then stops, rather than never working.
120211. **Timing contention with BLE.** TRAP-6 / OQ-16. Last, because it is the hardest to change, but
1203 if ranging works intermittently or only with BLE disconnected, this is the answer.