Surface GSMTAP BAD_FCS desync flag end-to-end

sigrok-iso7816-stream sets GSMTAP_FLAG_BAD_FCS (0x01) in the GSMTAP
header `res` byte on desynced TPDUs (mis-framed exchanges kept for
forensics). Propagate that flag through the whole pipeline so such
packets are explicitly surfaced instead of decoding as garbage:

- gsmtap.py: GSMTAP_FLAG_BAD_FCS const; GsmtapReceiver.read_packet()
  now returns (sub_type, data, flags) from the res byte.
- server/capture.py: GsmtapListener forwards the flags to the DB.
- pcap.py: _parse_gsmtap_hdr/_scan_gsmtap/extract_gsmtap and
  parse_pcap/parse_pcapng now yield a (ts, type, payload, flags)
  tuple, so the flag survives a PCAP/PCAPNG round-trip.
- server/server.py: PCAP import stores the flags.
- server/decode.py: gsmtap_flag_names() maps bit 0x01 to
  'bad FCS (desynced)'; merged into decoded errors for tpdu/atr/pps
  and rst/vcc, so the frontend ⚠ badge + Errors row flag the entry.

User-visible: desynced TPDUs show a ⚠ "bad FCS (desynced)" marker
in the trace and detail views. Tests: +4 (decode BAD_FCS markers,
PCAP flag round-trip); existing tests updated for the new tuple
arities. Version 1.22.0, SW cache simtrace-analyser-v32.
This commit is contained in:
catarrh committed 2026-08-26 18:08:25 +03:00
1 parent 7eaf7e9b53
commit 66094a0114
13 files changed
+90 -35

No files matched your search

+2 -2
View File
@@ -34,10 +34,10 @@ class GsmtapListener:
def iter_messages(self):
while self._running:
sub_type, data = self._receiver.read_packet()
sub_type, data, flags = self._receiver.read_packet()
if sub_type is None:
continue
yield gsmtap_msg_type(sub_type), data, 0
yield gsmtap_msg_type(sub_type), data, flags
class DirectSniffer:
+21 -4
View File
@@ -4030,6 +4030,19 @@ def decode_data_flags(flags):
return names or None
def gsmtap_flag_names(flags):
"""Decode the GSMTAP header ``res`` per-packet flag bits into a list of
human-readable names (or None).
GSMTAP_FLAG_BAD_FCS is set by the sigrok-iso7816-stream decoder on a
desynced TPDU (mis-framed exchange / implausible status word).
"""
names = []
if flags & 0x01:
names.append('bad FCS (desynced)')
return names or None
def decode_fidi(raw_data):
"""Decode a SIMtrace2 sniff_fidi payload (1-byte Fi/Di)."""
if len(raw_data) < 1:
@@ -4274,27 +4287,31 @@ def decode_sniff_msg(raw_data, msg_type, flags=0, prev=None):
if msg_type == 'tpdu' and raw_data:
result = decode_message(raw_data, prev=prev)
if result is not None:
errs = decode_data_flags(flags)
errs = (decode_data_flags(flags) or []) + (gsmtap_flag_names(flags) or [])
if errs:
result['errors'] = errs
return result
if msg_type == 'change':
return decode_change(flags)
if msg_type in ('rst', 'vcc'):
return decode_line_event(raw_data, msg_type)
result = decode_line_event(raw_data, msg_type)
errs = gsmtap_flag_names(flags)
if errs:
result['errors'] = errs
return result
if msg_type == 'fidi' and raw_data:
return decode_fidi(raw_data)
if msg_type == 'atr':
result = _decode_atr(raw_data)
if result is not None:
errs = decode_data_flags(flags)
errs = (decode_data_flags(flags) or []) + (gsmtap_flag_names(flags) or [])
if errs:
result['errors'] = errs
return result
if msg_type == 'pps':
result = _decode_pps(raw_data)
if result is not None:
errs = decode_data_flags(flags)
errs = (decode_data_flags(flags) or []) + (gsmtap_flag_names(flags) or [])
if errs:
result['errors'] = errs
return result
+2 -2
View File
@@ -331,9 +331,9 @@ class RequestHandler(BaseHTTPRequestHandler):
first_ts = packets[0][0]
last_ts = packets[-1][0]
rows = []
for ts, msg_type, payload in packets:
for ts, msg_type, payload, flags in packets:
elapsed = round(ts - first_ts, 6) if ts is not None else 0.0
rows.append((max(0.0, elapsed), msg_type, payload, 0))
rows.append((max(0.0, elapsed), msg_type, payload, flags))
self.db.insert_messages(session_id, rows)
# Use the packet timestamps as the session window when they are real
# (classic pcap / pcapng EPB). pcapng SPB-only files have synthetic