From 8c41655e18624d19586bb5b557a6ae28948f6beb 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: Mon, 31 Aug 2026 22:49:52 +0300 Subject: [PATCH] v1.9.23: auto-detect PC/SC reader with retry on startup __main__.py: - Probe smartcard.System.readers() before init_reader when no reader was explicitly specified - Retry 3 times with 2s delay to handle late pcscd startup and USB enumeration delays start.sh: - Also match pcscd.bin process name (some distros) - Wait 1s for pcscd if not running yet --- frontend/index.html | 2 +- pysim_otaman_server/__main__.py | 17 +++++++++++++++++ pysim_otaman_server/server.py | 2 +- start.sh | 12 ++++++++---- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/frontend/index.html b/frontend/index.html index ff620f1..81f3d13 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -18,7 +18,7 @@
-

OTAMan SIM OTA with a Human Face v1.9.22

+

OTAMan SIM OTA with a Human Face v1.9.23

github diff --git a/pysim_otaman_server/__main__.py b/pysim_otaman_server/__main__.py index 3b74068..31f6e44 100644 --- a/pysim_otaman_server/__main__.py +++ b/pysim_otaman_server/__main__.py @@ -56,6 +56,23 @@ def main(): rs = None sim_menu = None event_list = None + # Auto-detect PC/SC reader if none was explicitly specified. + # Handles late pcscd startup and USB enumeration delays. + if opts.pcsc_dev is None and opts.pcsc_regex is None: + try: + from smartcard.System import readers + for attempt in range(3): + r = readers() + if r: + sys.stderr.write('INIT: PC/SC reader detected: %s\n' % r[0]) + opts.pcsc_dev = 0 + break + if attempt < 2: + sys.stderr.write('INIT: no PC/SC readers found, retrying in 2s...\n') + time.sleep(2) + except Exception: + pass # smartcard module not available or pcscd unreachable + try: kwargs = {} if opts.apdu_trace: diff --git a/pysim_otaman_server/server.py b/pysim_otaman_server/server.py index e86f545..67d5271 100644 --- a/pysim_otaman_server/server.py +++ b/pysim_otaman_server/server.py @@ -18,7 +18,7 @@ from osmocom.construct import GsmOrUcs2Adapter from osmocom.tlv import BER_TLV_IE -VERSION = '1.9.22' +VERSION = '1.9.23' MAX_ENVELOPE_SEGMENTS = 5 # max SMS segments for outgoing C-APDU in ENVELOPE diff --git a/start.sh b/start.sh index cf49306..74f7212 100755 --- a/start.sh +++ b/start.sh @@ -10,10 +10,14 @@ VENV_DIR="$SCRIPT_DIR/.venv" # Auto-detect reader READER_ARGS="" -if command -v pcscd > /dev/null 2>&1 && pgrep -x pcscd > /dev/null 2>&1; then - READER_ARGS="-p 0" -elif [ -e /dev/ttyUSB0 ]; then - READER_ARGS="-d /dev/ttyUSB0" +if command -v pcscd > /dev/null 2>&1; then + # Give pcscd a moment if it's not running yet (USB enumeration delay) + if ! pgrep -x pcscd > /dev/null 2>&1 && ! pgrep -x pcscd.bin > /dev/null 2>&1; then + sleep 1 + fi + if pgrep -x pcscd > /dev/null 2>&1 || pgrep -x pcscd.bin > /dev/null 2>&1; then + READER_ARGS="-p 0" + fi fi SERVER=""