wmbus: fix format-A length formula for L=10 (mod 16); host tests under ASan
This commit is contained in:
+19
-3
@@ -26,10 +26,26 @@ int wmbus_frame_total_len(wmbus_frame_fmt_t fmt, uint8_t lfield)
|
||||
int total;
|
||||
switch (fmt) {
|
||||
case WMBUS_FRAME_A:
|
||||
// L counts C,M,A,CI,data without CRCs. Block 1 holds 9 payload
|
||||
// bytes; every further block holds up to 16, each with 2 CRC bytes.
|
||||
// L counts C,M,A,CI,data and excludes every CRC byte. Block 1
|
||||
// carries the L-field plus C,M,A (10 bytes) with its own CRC, so 9
|
||||
// L-counted bytes. The remaining (L - 9) bytes are split into
|
||||
// blocks of at most 16, each followed by 2 CRC bytes.
|
||||
//
|
||||
// rtl-wmbus uses `2 * ((L - 10 + 15)/16 + 1)`, i.e. floor((L+5)/16)+1
|
||||
// CRC pairs. That differs from the decomposition above by one pair
|
||||
// whenever L = 10 (mod 16), where it would have to place 17 bytes in
|
||||
// a 16-byte block. wmbusmeters' trimCRCsFrameFormatA walks greedy
|
||||
// 16-byte blocks and accepts a final block of 1..16 bytes, which
|
||||
// matches the form used here.
|
||||
//
|
||||
// Both forms agree on every VALID length observed at this site
|
||||
// (L = 54, 57, 62, 67, 87, 95, 98, 102). No valid L = 10 (mod 16)
|
||||
// frame was ever captured, so this is an internal-consistency fix
|
||||
// found by firmware/test/test_wmbus.c, not a fix for an observed
|
||||
// interoperability failure: with the old formula such a frame would
|
||||
// have been computed 2 bytes short and always failed CRC.
|
||||
if (lfield < 9) return -1;
|
||||
total = 1 + lfield + 2 * (((lfield - 10 + 15) / 16) + 1);
|
||||
total = 1 + lfield + 2 * (1 + ((lfield - 9 + 15) / 16));
|
||||
break;
|
||||
case WMBUS_FRAME_B:
|
||||
// L counts everything after itself including CRC bytes.
|
||||
|
||||
Reference in New Issue
Block a user