#!/usr/bin/env bash # Independent semantic check of a transmitted frame using wmbusmeters. # # rtl-wmbus proves the PHY/framing is demodulable and the CRCs are right. # wmbusmeters is a separate implementation with its own link-layer parser, # so agreeing with it shows the frame is a structurally valid Wireless M-Bus # telegram (manufacturer, ID, version, device type, CI field) and not merely # something that happens to satisfy a CRC. # # Usage: verify_frame_semantics.sh COOKED_HEX [OUTFILE] # Exit 0 if wmbusmeters parsed the link layer, 1 otherwise. set -euo pipefail HEX=$1 OUT=${2:-/dev/stdout} if ! command -v wmbusmeters >/dev/null 2>&1; then echo "wmbusmeters not on PATH; skipping semantic cross-check" > "$OUT" exit 0 fi ANALYSIS=$(wmbusmeters --analyze "$HEX" 2>&1 || true) echo "$ANALYSIS" > "$OUT" # Require the link-layer fields to have been recognised. for field in "dll-mfct" "dll-id" "dll-version" "dll-type" "tpl-ci-field"; do if ! grep -q "$field" <<< "$ANALYSIS"; then echo "MISSING: $field" >> "$OUT" exit 1 fi done exit 0