Decode sigrok-iso7816-stream RST/VCC line events (GSMTAP 0x10/0x11)

Support the sigrok-iso7816-stream decoder (FX2 logic-analyzer passive
SIM sniffer, github.com/anttro/sigrok_iso7816_stream) which streams
GSMTAP-SIM on UDP 4729 and adds two custom sub-types for line events.

- gsmtap.py: GSMTAP_SIM_RST_EVENT (0x10) / GSMTAP_SIM_VCC_EVENT (0x11).
- capture.py: gsmtap_msg_type() maps 0x10→'rst', 0x11→'vcc' (shared by
  the listener and tests); pcap.py _SUB_TYPE_NAMES gains the same
  entries so PCAP re-imports of these captures preserve the events.
- decode.py: decode_line_event() decodes [direction, level, reserved]
  into reset asserted/de-asserted or power applied/removed + level;
  routed through decode_sniff_msg.
- database.py: reset-assert and power-removal invalidate the per-channel
  file selection (card-level transition); de-assert / power-on are
  markers only.
- frontend: RST/VCC labels (RESET ASSERTED / VCC OFF, …), a detail-view
  branch (Event + Level + raw), and list styling (.apdu-type.rst/.vcc).

README notes the custom sub-type compatibility. Tests: +8 (line-event
vectors, sniff routing, subtype + PCAP round-trip mappings) — 359
total. Version 1.21.0, SW cache simtrace-analyser-v31.
This commit is contained in:
catarrh committed 2026-08-26 17:29:36 +03:00
1 parent 3e21d093d9
commit 7eaf7e9b53
13 files changed
+165 -11

No files matched your search

+16 -3
View File
@@ -3,7 +3,21 @@
import time
import threading
from ..gsmtap import GsmtapReceiver, GSMTAP_SIM_ATR, GSMTAP_SIM_APDU
from ..gsmtap import (GsmtapReceiver, GSMTAP_SIM_ATR,
GSMTAP_SIM_RST_EVENT, GSMTAP_SIM_VCC_EVENT)
def gsmtap_msg_type(sub_type):
"""Map a GSMTAP-SIM sub_type to a stored message type.
Custom sigrok-iso7816-stream line events (0x10/0x11) become 'rst'/'vcc';
everything except ATR defaults to 'tpdu'.
"""
return {
GSMTAP_SIM_ATR: 'atr',
GSMTAP_SIM_RST_EVENT: 'rst',
GSMTAP_SIM_VCC_EVENT: 'vcc',
}.get(sub_type, 'tpdu')
class GsmtapListener:
@@ -23,8 +37,7 @@ class GsmtapListener:
sub_type, data = self._receiver.read_packet()
if sub_type is None:
continue
msg_type = 'atr' if sub_type == GSMTAP_SIM_ATR else 'tpdu'
yield msg_type, data, 0
yield gsmtap_msg_type(sub_type), data, 0
class DirectSniffer:
+11
View File
@@ -377,5 +377,16 @@ class Database:
if msg['flags'] & (CHANGE_FLAG_CARD_INSERT | CHANGE_FLAG_CARD_EJECT |
CHANGE_FLAG_RESET_ASSERT | CHANGE_FLAG_RESET_DEASSERT):
states = {}
elif msg['type'] in ('rst', 'vcc'):
# sigrok-iso7816-stream line events: a reset assert or power
# removal destroys the card's selection state. De-assert /
# power-on are markers only (the following ATR resets state).
data = row[4] if len(row) > 4 and row[4] else b''
if msg['type'] == 'rst':
if data and data[0] == 1: # asserted
states = {}
else: # vcc
if data and data[0] == 0: # power removed
states = {}
msgs.append(msg)
return msgs
+22
View File
@@ -4002,6 +4002,26 @@ def decode_change(flags):
}
def decode_line_event(raw_data, kind):
"""Decode a sigrok-iso7816-stream RST/VCC line event (GSMTAP sub_type
0x10/0x11): payload [direction, level, reserved].
direction — RST: 1 = asserted (high→low), 0 = de-asserted (low→high);
VCC: 1 = power applied (low→high), 0 = removed (high→low).
level — resulting line level: 0 = low, 1 = high.
"""
result = {'type': kind}
if raw_data and len(raw_data) >= 2:
direction, level = raw_data[0], raw_data[1]
if kind == 'rst':
result['event'] = 'reset asserted' if direction else 'reset de-asserted'
else:
result['event'] = 'power applied' if direction else 'power removed'
result['level'] = 'high' if level else 'low'
result['raw'] = raw_data.hex().upper()
return result
def decode_data_flags(flags):
"""Decode SIMtrace2 sniff_data error flags into a list of names (or None)."""
if not flags:
@@ -4260,6 +4280,8 @@ def decode_sniff_msg(raw_data, msg_type, flags=0, prev=None):
return result
if msg_type == 'change':
return decode_change(flags)
if msg_type in ('rst', 'vcc'):
return decode_line_event(raw_data, msg_type)
if msg_type == 'fidi' and raw_data:
return decode_fidi(raw_data)
if msg_type == 'atr':