wmbus: fix format-A length formula for L=10 (mod 16); host tests under ASan

This commit is contained in:
Lars Nolden
2026-09-01 11:28:14 +02:00
parent c835c62172
commit 6bdcb2acad
6 changed files with 302 additions and 3 deletions
+17
View File
@@ -124,6 +124,23 @@
every heartbeat (`config_intact`), and recovery levels only report success
when both the mode and the configuration verify.
## CONFIRMED (frame layer, host tests)
- `firmware/test/run_tests.sh` validates the frame layer against real
captured meter frames under AddressSanitizer: CRCs of third-party frames
verify, every single-bit flip in them is detected, the builder's own
frames validate for all buildable L, and 200k adversarial length/buffer
combinations produce no out-of-bounds access.
- The tests found a real internal inconsistency: the format-A length formula
copied from rtl-wmbus disagrees with the greedy 16-byte block walk used
for CRC validation whenever L = 10 (mod 16). Fixed to
`1 + L + 2*(1 + ceil((L-9)/16))`, which matches wmbusmeters' trimming.
Both forms agree on every valid length observed here, and no valid
L = 10 (mod 16) frame was ever captured -- the 10 candidates in the logs
all fail their length-independent block-1 CRC, i.e. they are corrupted
receptions. So this is a latent-correctness fix, not a measured
improvement (docs/OPEN_QUESTIONS.md).
## NEEDS TESTING
- Narrower RX bandwidth (156 kHz) vs current 234.3 kHz on weak meters.
+15
View File
@@ -24,3 +24,18 @@
(thermal suspected). The `rtl_test -t` theory was DISPROVEN.
- Can the SX1262 RX be stopped early (poll GetRxBufferStatus after
SyncWordValid) to remove the ~12 ms fixed-capture tail?
## Standards detail needing an authoritative answer
- Format A frame length for `L = 10 (mod 16)`. Two mature open-source
implementations disagree in this corner:
- rtl-wmbus computes `1 + L + 2*((L-10+15)/16 + 1)` CRC pairs, which for
L = 10, 26, 42, ... requires a 17-byte block;
- wmbusmeters does not predict the length at all; it walks greedy 16-byte
blocks and accepts a final block of 1..16 bytes.
This firmware follows the wmbusmeters decomposition
(`1 + L + 2*(1 + ceil((L-9)/16))`) because it is self-consistent with the
CRC walk actually used. No valid frame with such an L was ever captured
at this site, so the question is unresolved empirically -- it needs the
EN 13757-4 text, or a meter that emits one. Until then, a real meter using
those lengths is an interoperability risk worth a targeted test.