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:
1 parent
3e21d093d9
commit
7eaf7e9b53
13 files changed
+165
-11
No files matched your search
@@ -113,6 +113,14 @@ simtrace2-pysniff-server --capture direct
|
||||
simtrace2-pysniff-server --capture disabled
|
||||
```
|
||||
|
||||
The GSMTAP listener also accepts the **sigrok-iso7816-stream** decoder
|
||||
(https://github.com/anttro/sigrok_iso7816_stream) — an FX2-logic-analyzer
|
||||
passive SIM sniffer that emits the same GSMTAP-SIM format on UDP 4729. Its
|
||||
custom sub-types for RST/VCC line events (`0x10`/`0x11`, added for
|
||||
compatibility with that project) are decoded as `RESET ASSERTED/DE-ASSERTED`
|
||||
and `VCC ON/OFF` timeline markers, and a reset-assert or power-removal
|
||||
correctly invalidates the file-selection tracking.
|
||||
|
||||
Server options:
|
||||
|
||||
```
|
||||
|
||||
+29
-2
@@ -124,6 +124,8 @@ body { font: 14px/1.5 system-ui, sans-serif; background: var(--bg); color: var(-
|
||||
.apdu-type { color: var(--text); font-weight: 600; min-width: 150px; }
|
||||
.apdu-type.atr { color: var(--green); }
|
||||
.apdu-type.pps { color: var(--yellow); }
|
||||
.apdu-type.rst { color: var(--warn); }
|
||||
.apdu-type.vcc { color: var(--accent); }
|
||||
.apdu-type.cat-proactive { font-weight: 700; color: var(--proactive); }
|
||||
.apdu-type.cat-tr { font-weight: 700; color: var(--tr); }
|
||||
.apdu-type.cat-envelope { color: var(--envelope); }
|
||||
@@ -412,6 +414,13 @@ const INS_NAMES = {
|
||||
};
|
||||
|
||||
// ──────────────────── UI Helpers ────────────────────
|
||||
function line_event_label(msg) {
|
||||
const d = msg.decoded;
|
||||
if (msg.type === 'rst') return d && d.event ? 'RESET ' + (d.event === 'reset asserted' ? 'ASSERTED' : 'DE-ASSERTED') : 'RESET';
|
||||
if (msg.type === 'vcc') return d && d.event ? 'VCC ' + (d.event === 'power applied' ? 'ON' : 'OFF') : 'VCC';
|
||||
return null;
|
||||
}
|
||||
|
||||
function ins_label(msg) {
|
||||
if (msg.decoded && msg.decoded.cat_command) return msg.decoded.cat_command;
|
||||
if (msg.decoded && msg.decoded.ins_name) return msg.decoded.ins_name;
|
||||
@@ -420,6 +429,8 @@ function ins_label(msg) {
|
||||
if (msg.type === 'change') return 'STATE CHANGE';
|
||||
if (msg.type === 'fidi') return 'FIDI';
|
||||
if (msg.type === 'gap') return 'CAPTURE GAP';
|
||||
const le = line_event_label(msg);
|
||||
if (le) return le;
|
||||
const d = msg.data;
|
||||
if (d && d.length >= 2) {
|
||||
const ins = d.slice(2, 4);
|
||||
@@ -434,6 +445,8 @@ function _fallback_label(msg) {
|
||||
if (msg.type === 'change') return 'STATE CHANGE';
|
||||
if (msg.type === 'fidi') return 'FIDI';
|
||||
if (msg.type === 'gap') return 'CAPTURE GAP';
|
||||
const le = line_event_label(msg);
|
||||
if (le) return le;
|
||||
const data = msg.data;
|
||||
if (data && data.length >= 2) {
|
||||
const ins = data.slice(2, 4);
|
||||
@@ -1504,6 +1517,19 @@ function showDetail(msg, entry) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (decoded.type === 'rst' || decoded.type === 'vcc') {
|
||||
const evName = decoded.event || (decoded.type === 'rst' ? 'reset event' : 'power event');
|
||||
d.innerHTML = `<div class="detail-header"><strong>${ins_label(msg)}</strong><span style="color:var(--text-muted)">${detail_time_html(msg)}</span></div>
|
||||
<div class="detail-body">
|
||||
<table>
|
||||
<tr><td class="label">Event</td><td class="value">${evName}</td></tr>
|
||||
<tr><td class="label">Level</td><td class="value">${decoded.level || '?'}</td></tr>
|
||||
${decoded.raw ? `<tr><td class="label">Raw</td><td class="hex">${decoded.raw}</td></tr>` : ''}
|
||||
</table>
|
||||
</div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
if (decoded.type === 'fidi') {
|
||||
d.innerHTML = `<div class="detail-header"><strong>Fi/Di Change</strong><span style="color:var(--text-muted)">${detail_time_html(msg)}</span></div>
|
||||
<div class="detail-body">
|
||||
@@ -1951,7 +1977,8 @@ function renderMessages(skipScroll) {
|
||||
}
|
||||
const label = ins_label(m);
|
||||
const cat = command_cat(_ins_hex(m));
|
||||
const typeCls = (m.type === 'atr' ? 'atr' : m.type === 'pps' ? 'pps' : '') +
|
||||
const typeCls = (m.type === 'atr' ? 'atr' : m.type === 'pps' ? 'pps'
|
||||
: m.type === 'rst' ? 'rst' : m.type === 'vcc' ? 'vcc' : '') +
|
||||
(cat ? ' cat-' + cat : '');
|
||||
const errs = error_names(m);
|
||||
const errBadge = errs ? `<span class="apdu-err" title="${errs.join(', ')}">⚠</span>` : '';
|
||||
@@ -2484,7 +2511,7 @@ function onFilterChange() {
|
||||
}
|
||||
|
||||
// ──────────────────── Versioning ────────────────────
|
||||
const PWA_VERSION = '1.20.2';
|
||||
const PWA_VERSION = '1.21.0';
|
||||
const MIN_SERVER_VERSION = '1.0.0';
|
||||
|
||||
function parseVersion(v) {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
const CACHE = 'simtrace-analyser-v30';
|
||||
const CACHE = 'simtrace-analyser-v31';
|
||||
|
||||
const PRECACHE = [
|
||||
'index.html',
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.backends._legacy:_Backend"
|
||||
|
||||
[project]
|
||||
name = "simtrace2-pysniff"
|
||||
version = "1.20.2"
|
||||
version = "1.21.0"
|
||||
description = "Python-based sniffing tool for SIMtrace2 hardware (SIM card communication sniffer)"
|
||||
readme = {file = "README.md", content-type = "text/markdown"}
|
||||
license = {text = "GPL-2.0-or-later"}
|
||||
|
||||
@@ -6,7 +6,7 @@ from .gsmtap import GsmtapSender, GsmtapReceiver
|
||||
from .pcap import PcapWriter
|
||||
from .dump import FileDumper, format_message
|
||||
|
||||
__version__ = '1.20.2'
|
||||
__version__ = '1.21.0'
|
||||
__all__ = [
|
||||
'SniffSession',
|
||||
'DeviceDisconnected',
|
||||
|
||||
@@ -14,6 +14,10 @@ GSMTAP_SIM_APDU = 0x00
|
||||
GSMTAP_SIM_ATR = 0x01
|
||||
GSMTAP_SIM_PPS_REQ = 0x02
|
||||
GSMTAP_SIM_PPS_RSP = 0x03
|
||||
# Custom sub-types from the sigrok-iso7816-stream decoder
|
||||
# (github.com/anttro/sigrok_iso7816_stream): line-level events.
|
||||
GSMTAP_SIM_RST_EVENT = 0x10
|
||||
GSMTAP_SIM_VCC_EVENT = 0x11
|
||||
|
||||
GSMTAP_UDP_PORT = 4729
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ GSMTAP_SIM_APDU = 0x00
|
||||
GSMTAP_SIM_ATR = 0x01
|
||||
GSMTAP_SIM_PPS_REQ = 0x02
|
||||
GSMTAP_SIM_PPS_RSP = 0x03
|
||||
GSMTAP_SIM_RST_EVENT = 0x10 # sigrok-iso7816-stream custom sub-type
|
||||
GSMTAP_SIM_VCC_EVENT = 0x11 # sigrok-iso7816-stream custom sub-type
|
||||
_GSMTAP_HDR_FMT = '!BBBBHBBIBBBB'
|
||||
_GSMTAP_HDR_SIZE = struct.calcsize(_GSMTAP_HDR_FMT) # 16 bytes
|
||||
|
||||
@@ -48,6 +50,8 @@ _SUB_TYPE_NAMES = {
|
||||
GSMTAP_SIM_ATR: 'atr',
|
||||
GSMTAP_SIM_PPS_REQ: 'pps',
|
||||
GSMTAP_SIM_PPS_RSP: 'pps',
|
||||
GSMTAP_SIM_RST_EVENT: 'rst',
|
||||
GSMTAP_SIM_VCC_EVENT: 'vcc',
|
||||
}
|
||||
|
||||
# pcapng block types
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
@@ -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':
|
||||
|
||||
+12
-1
@@ -4,10 +4,21 @@ import os
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from simtrace2_pysniff.server.capture import CaptureManager
|
||||
from simtrace2_pysniff.server.capture import CaptureManager, gsmtap_msg_type
|
||||
from simtrace2_pysniff.server.database import Database
|
||||
|
||||
|
||||
class TestGsmtapSubtypeMapping(unittest.TestCase):
|
||||
def test_custom_line_event_subtypes(self):
|
||||
self.assertEqual(gsmtap_msg_type(0x10), 'rst')
|
||||
self.assertEqual(gsmtap_msg_type(0x11), 'vcc')
|
||||
|
||||
def test_standard_subtypes(self):
|
||||
self.assertEqual(gsmtap_msg_type(0x00), 'tpdu')
|
||||
self.assertEqual(gsmtap_msg_type(0x01), 'atr')
|
||||
self.assertEqual(gsmtap_msg_type(0x02), 'tpdu') # PPS combined
|
||||
|
||||
|
||||
class _FakeBackend:
|
||||
def __init__(self, messages=()):
|
||||
self._messages = list(messages)
|
||||
|
||||
@@ -2307,5 +2307,44 @@ class TestClaDecode(unittest.TestCase):
|
||||
self.assertEqual(r['interclass'], 'ETSI-defined (SIM/GSM)')
|
||||
|
||||
|
||||
class TestLineEvents(unittest.TestCase):
|
||||
"""sigrok-iso7816-stream RST/VCC line events (GSMTAP 0x10/0x11)."""
|
||||
|
||||
def _dec(self, kind, payload):
|
||||
from simtrace2_pysniff.server.decode import decode_line_event
|
||||
return decode_line_event(bytes.fromhex(payload), kind)
|
||||
|
||||
def test_rst_asserted(self):
|
||||
r = self._dec('rst', '010000')
|
||||
self.assertEqual(r['type'], 'rst')
|
||||
self.assertEqual(r['event'], 'reset asserted')
|
||||
self.assertEqual(r['level'], 'low')
|
||||
|
||||
def test_rst_deasserted(self):
|
||||
r = self._dec('rst', '000100')
|
||||
self.assertEqual(r['event'], 'reset de-asserted')
|
||||
self.assertEqual(r['level'], 'high')
|
||||
|
||||
def test_vcc_on(self):
|
||||
r = self._dec('vcc', '010100')
|
||||
self.assertEqual(r['event'], 'power applied')
|
||||
self.assertEqual(r['level'], 'high')
|
||||
|
||||
def test_vcc_off(self):
|
||||
r = self._dec('vcc', '000000')
|
||||
self.assertEqual(r['event'], 'power removed')
|
||||
self.assertEqual(r['level'], 'low')
|
||||
|
||||
def test_sniff_routing(self):
|
||||
from simtrace2_pysniff.server.decode import decode_sniff_msg
|
||||
self.assertEqual(decode_sniff_msg(b'\x01\x00\x00', 'rst')['type'], 'rst')
|
||||
self.assertEqual(decode_sniff_msg(b'\x00\x01\x00', 'vcc')['type'], 'vcc')
|
||||
|
||||
def test_short_payload(self):
|
||||
r = self._dec('rst', '01')
|
||||
self.assertEqual(r['type'], 'rst')
|
||||
self.assertNotIn('event', r)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -9,7 +9,9 @@ from simtrace2_pysniff.pcap import (
|
||||
build_pcap, parse_pcap, parse_pcapng, wrap_gsmtap, extract_gsmtap,
|
||||
LINKTYPE_ETHERNET,
|
||||
)
|
||||
from simtrace2_pysniff.gsmtap import build_gsmtap_packet, GSMTAP_SIM_ATR, GSMTAP_SIM_APDU
|
||||
from simtrace2_pysniff.gsmtap import (build_gsmtap_packet, GSMTAP_SIM_ATR,
|
||||
GSMTAP_SIM_APDU, GSMTAP_SIM_RST_EVENT,
|
||||
GSMTAP_SIM_VCC_EVENT)
|
||||
|
||||
|
||||
def _gsmtap_hdr(sub_type):
|
||||
@@ -54,6 +56,19 @@ class TestParsePcap(unittest.TestCase):
|
||||
(2.5, 'tpdu', b'\x80\xf2\x00\x00\x00'),
|
||||
])
|
||||
|
||||
def test_roundtrip_line_events(self):
|
||||
# sigrok-iso7816-stream custom sub-types survive a PCAP round-trip.
|
||||
packets = [
|
||||
(_gsmtap_hdr(GSMTAP_SIM_RST_EVENT), b'\x01\x00\x00', 1.0),
|
||||
(_gsmtap_hdr(GSMTAP_SIM_VCC_EVENT), b'\x00\x00\x00', 1.5),
|
||||
]
|
||||
data = build_pcap(packets)
|
||||
parsed = [(round(ts, 1), t, payload) for ts, t, payload in parse_pcap(data)]
|
||||
self.assertEqual(parsed, [
|
||||
(1.0, 'rst', b'\x01\x00\x00'),
|
||||
(1.5, 'vcc', b'\x00\x00\x00'),
|
||||
])
|
||||
|
||||
def test_no_gsmtap(self):
|
||||
# A packet that is not GSMTAP-SIM yields nothing.
|
||||
frame = wrap_gsmtap(b'\x03' + b'\x00' * 15) # type=3, not SIM
|
||||
@@ -197,7 +212,7 @@ class TestImportEndpoint(unittest.TestCase):
|
||||
class TestVersion(unittest.TestCase):
|
||||
def test_package_version(self):
|
||||
from simtrace2_pysniff import __version__
|
||||
self.assertEqual(__version__, '1.20.2')
|
||||
self.assertEqual(__version__, '1.21.0')
|
||||
|
||||
def test_status_includes_version(self):
|
||||
import os
|
||||
|
||||
Reference in new issue
Block a user