Commit Graph
115 Commits
Author SHA1 Message Date
catarrh 083924c976 Add context-aware decoding for GET RESPONSE and TERMINAL RESPONSE
decode.py:
- decode_cat: TERMINAL RESPONSE (0x14) now extracts the proactive
  command type from its echoed Command Details (tag 81) — no history
  lookup needed since TR carries its own type
- decode_message gains prev param; GET RESPONSE (0xC0) resolves
  'response_for' from the previous command when its SW1 was 0x61,
  else None (orphaned)
- decode_sniff_msg threads prev through

database.py:
- _row_to_message accepts prev; new _decode_rows tracks previous-TPDU
  context in sequence; get_messages/get_messages_after seed context
  from the message before the window/cursor

tests: TR cat_command + GET RESPONSE context/orphaned cases (49 total)
2026-08-12 19:41:57 +03:00
catarrh 2a58fec0a3 Fix dropped change flags + FIDI parsing
- capture.py: DirectSniffer/GsmtapListener yield (type, data, flags),
  CaptureManager passes flags to insert_message (change flags were
  previously dropped, leaving every change row with flags=0)
- protocol.py: add _parse_fidi (1-byte value) — FIDI was mis-mapped to
  _parse_change (4-byte flags), so FIDI messages were silently dropped
- database.py: pass flags into decode_sniff_msg
- decode.py: decode_change(flags) reads flags directly; decode_sniff_msg
  gains flags parameter; change messages no longer require non-empty data
- tests: fix FIDI test, add change/fidi decode tests (43 total)
2026-08-12 19:25:14 +03:00
catarrh 4097bb864e Remove accidentally committed decode-errors.log; add to .gitignore 2026-08-12 18:27:07 +03:00
catarrh 11d0f29b6a Add CAT (TS 102 223) command decoding + fix AUTHENTICATE naming
- CAT_COMMAND_TYPES: complete Type of Command table from TS 102 223 §9.4
- ENVELOPE_TYPES: D1-D7 envelope tags
- parse_tlv(): minimal BER-TLV parser
- decode_cat(): FETCH → proactive command name (via D0→81 type byte);
  ENVELOPE → envelope type name
- AUTHENTICATE (0x88/0x89) unified to 'AUTHENTICATE' (no suffix)
- decoded dict gains 'cat_command' field for FETCH/ENVELOPE
- tests/test_decode.py: 14 new tests (TLV, naming, CAT, tables)
2026-08-12 18:26:58 +03:00
catarrh 41b5c0218e Defensive: try/except around decode in _row_to_message
Decode errors now log to stderr instead of crashing the entire
API response. This prevents a single malformed message from hiding
all subsequent messages in the same query.
2026-08-12 17:49:05 +03:00
catarrh e211dd91bc Add decode for change, fidi, atr, pps message types
decode_sniff_msg() dispatches to type-specific decoders:
- change: 4-byte flags bitmask → card insert/eject/reset/timeout
- fidi: 1-byte Fi/Di index → decoded values
- atr/pps: raw hex value
database.py now decodes all message types, not just tpdu.
2026-08-12 17:46:03 +03:00
catarrh 7ada4345b8 Add server-side APDU decoder (decode.py)
Pure Python, no dependencies. Decodes raw TPDU bytes into
structured JSON: CLA bitfield, INS->name via APDU_SPEC table,
P1/P2 field breakdown, body extraction, SW name lookup.
~40 command types, 40+ SW codes, known FID notes.

database.py: _row_to_message() calls decode_message() for tpdu
messages, adding 'decoded' field to API responses.

Decoding happens at query time, not storage time — no schema
migration, all past sessions get decode retroactively.
2026-08-12 17:21:25 +03:00
catarrh 4313f308b8 Add server-start.sh startup script
Pre-flight USB permission check only runs for --capture direct mode.
Env vars PORT, DB, CAPTURE, GSMTAP_PORT set defaults. CLI flags override.
2026-08-12 16:11:16 +03:00
catarrh 17eeda27f3 Merge simtrace-analyser-server into simtrace2_pysniff.server
Add simtrace2-pysniff-server CLI — HTTP API for simtrace-analyser PWA.
Two capture modes: GSMTAP UDP listener (compatible with simtrace2-sniff)
or direct SIMtrace2 hardware capture. SQLite storage with sessions +
messages tables. REST API with CORS.

server/ sub-package: database.py, capture.py, server.py, __main__.py

README updated with server usage section.
pyproject.toml: simtrace2-pysniff-server script entry added.
2026-08-12 15:59:51 +03:00
catarrh a130b97cce Add GsmtapReceiver — receive GSMTAP-SIM over UDP
UDP socket on port 4729, parses GSMTAP header, validates
GSMTAP_TYPE_SIM, returns (sub_type, data). Compatible with
simtrace2-sniff and pySim's GsmtapApduSource.
2026-08-12 12:31:52 +03:00
catarrh f8e9cb1018 SIGHUP: ignore only when in background (stdin not a tty)
Use sys.stdin.isatty() to auto-detect: foreground sessions still
respond to SIGHUP (terminal close kills the process as expected),
background/piped processes ignore it and survive.
2026-08-11 01:02:07 +03:00
catarrh fb5c1fbf6a Ignore SIGHUP — survive terminal closure in background
__main__.py: add signal.SIGHUP → SIG_IGN before setting up
SIGINT/SIGTERM handlers. Sniffer no longer dies when the terminal
closes or the shell session ends.

README: add Background / Daemon section with nohup examples.
2026-08-11 00:37:41 +03:00
catarrh ad8d661caa README: add Prerequisites, separate Install/Running sections
Split Quick Start into Prerequisites (Python/PyUSB/libusb/hardware),
Install (clone + pip), and Running (startup script vs Python module).
Startup script section includes env var override examples.
Added dependency table note — PCAP/GSMTAP/hex dump use only stdlib.
2026-08-10 23:55:34 +03:00
catarrh ec129c4463 Add --format option: timestamp and atr-time TPDU output modes
dump.py: tpdu_timestamp_prefix(), tpdu_atr_time_prefix(),
  format_message() accepts tpdu_prefix parameter,
  FileDumper supports fmt + ATR time tracking

__main__.py: --format/-f flag (hex|timestamp|atr-time),
  atr_time_start tracking in message loop

sniff-start.sh: pass through --format/-f and FORMAT env var
2026-08-10 23:53:38 +03:00
catarrh 73b0277ef7 Initial commit: simtrace2-pysniff v0.1.0
Python-based SIMtrace2 sniffer — drop-in replacement for simtrace2-sniff.
Single dependency (pyusb), auto-reconnect, GSMTAP/PCAP output, library API.

Modules:
  protocol.py — SIMtrace2 USB sniffing protocol parser
  device.py   — USB discovery + SniffSession with exponential backoff reconnect
  gsmtap.py   — GSMTAP UDP sender for Wireshark
  pcap.py     — PCAP file writer (LINKTYPE_GSMTAP)
  dump.py     — hex dump formatters + file output
  __main__.py — CLI entry point

Startup script sniff-start.sh handles udev permission checks and shows
install instructions. udev rule uses TAG+=uaccess (systemd-logind ACL).
2026-08-10 23:17:04 +03:00