Add repeater protocol and device firmware features

This commit is contained in:
Lars Nolden
2026-09-21 12:30:50 +02:00
parent 73d3ddf00c
commit a11a4b3b89
41 changed files with 7791 additions and 228 deletions
+34 -1
View File
@@ -1,4 +1,4 @@
// Wireless M-Bus C-mode frame helpers (EN 13757-4).
// Wireless M-Bus C/T-mode frame helpers (EN 13757-4).
#pragma once
#include <stdint.h>
@@ -28,6 +28,13 @@ bool wmbus_check_crc(wmbus_frame_fmt_t fmt, const uint8_t *frame, int total_len)
// CRC-16 EN 13757 (poly 0x3D65, init 0, complemented result).
uint16_t wmbus_crc16(const uint8_t *data, size_t len);
// Mark an eligible OMS uplink as repeated in place, repairing its block CRC.
// Caller must first validate all CRCs. Supports ELL 8C/8E or a direct short/
// long uplink TPL header in security mode 0/5. ELL takes precedence.
// Returns false, leaving frame unchanged, for unsupported/malformed headers,
// non-SND_NR/SND_IR C-fields, H=1 or R=1. No payload decryption is performed.
bool wmbus_mark_repeated(wmbus_frame_fmt_t fmt, uint8_t *frame, int total_len);
// Build a valid C-mode format A test frame with our test manufacturer/ID.
// Returns total frame length written to out (>= 12), or -1 if payload_len
// does not fit. out[0] = L-field.
@@ -36,3 +43,29 @@ int wmbus_build_test_frame(uint8_t *out, size_t maxlen, uint8_t access_nr,
// 32-bit FNV-1a hash used to correlate RX/TX events in the logs.
uint32_t wmbus_hash(const uint8_t *data, size_t len);
// ---- T-mode "3 of 6" codec (EN 13757-4) -------------------------------
// Chips travel MSB-first: the first received chip is bit 7 of coded[0].
// T1 shares the 0x543D access code with C-mode; after it, T1 sends coded
// data directly (no mode bytes). Tables verified against rtl-wmbus
// t1_c1_packet_decoder.h (HIGH/LOW_NIBBLE_3OUTOF6).
// Coded on-air byte count for a decoded byte count: ceil(total * 12 / 8).
int wmbus_3of6_coded_len(int total_len);
// Decode total_len bytes (2 * total_len six-bit codes) from coded[].
// Invalid codes decode as 0x0 nibbles so the CRC can still judge the
// frame. Returns the number of invalid codes (0 = clean), or -1 if
// coded_len holds fewer than total_len * 12 bits.
int wmbus_3of6_decode(const uint8_t *coded, size_t coded_len,
uint8_t *out, int total_len);
// Decode only the first byte (the T1 L-field). Returns 0..255, or -1 if
// either 6-bit code is invalid or fewer than 2 bytes are available.
int wmbus_3of6_first_byte(const uint8_t *coded, size_t coded_len);
// Encode total_len bytes into 3-of-6 chips, padding the final partial
// byte with 01 postamble chips. Returns coded byte count, or -1 if it
// does not fit maxlen.
int wmbus_3of6_encode(const uint8_t *data, int total_len,
uint8_t *coded, size_t maxlen);