From 79acb3773f247e67b38b9cb05b3292c0d71e0c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=A2=D1=80=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Wed, 26 Aug 2026 22:11:29 +0300 Subject: [PATCH] Address code-review nits for BAD_FCS support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - decode.py: use the GSMTAP_FLAG_BAD_FCS constant instead of a literal 0x01 in gsmtap_flag_names() (import from ..gsmtap); no behavior change. - tests: add a DB round-trip test (insert_message with BAD_FCS flag → get_messages → decoded.errors) covering the end-to-end path, not just the direct decode_sniff_msg call. --- simtrace2_pysniff/server/decode.py | 4 +++- tests/test_decode.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/simtrace2_pysniff/server/decode.py b/simtrace2_pysniff/server/decode.py index 9614f97..bd6bd05 100644 --- a/simtrace2_pysniff/server/decode.py +++ b/simtrace2_pysniff/server/decode.py @@ -4,6 +4,8 @@ Pure Python, no dependencies. Decodes raw TPDU bytes captured by the SIMtrace2 sniffer into structured dicts for the PWA to display. """ +from ..gsmtap import GSMTAP_FLAG_BAD_FCS + # ──────────────────── Status Word names ──────────────────── SW_NAMES = { @@ -4038,7 +4040,7 @@ def gsmtap_flag_names(flags): desynced TPDU (mis-framed exchange / implausible status word). """ names = [] - if flags & 0x01: + if flags & GSMTAP_FLAG_BAD_FCS: names.append('bad FCS (desynced)') return names or None diff --git a/tests/test_decode.py b/tests/test_decode.py index a657ce3..f32a2b0 100644 --- a/tests/test_decode.py +++ b/tests/test_decode.py @@ -1204,6 +1204,20 @@ class TestFileDecoders(unittest.TestCase): class TestSelectionTracking(unittest.TestCase): + def test_bad_fcs_roundtrip(self): + # GSMTAP BAD_FCS flag stored via insert_message must surface as a + # decode error in the DB → frontend path (not just the direct call). + import tempfile + from simtrace2_pysniff.server.database import Database + from simtrace2_pysniff.gsmtap import GSMTAP_FLAG_BAD_FCS + with tempfile.NamedTemporaryFile(suffix='.db') as tmp: + db = Database(tmp.name) + sid = db.create_session('capture') + db.insert_message(sid, 0.1, 'tpdu', bytes.fromhex('80f2000000'), + GSMTAP_FLAG_BAD_FCS) + msgs = db.get_messages(sid) + self.assertIn('bad FCS (desynced)', msgs[0]['decoded']['errors']) + def test_select_then_read(self): import tempfile from simtrace2_pysniff.server.database import Database