Change in pysim[master]: utils: catch exceptions during reader initalitation

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

dexter gerrit-no-reply at lists.osmocom.org
Mon Feb 22 15:24:20 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/23028 )


Change subject: utils: catch exceptions during reader initalitation
......................................................................

utils: catch exceptions during reader initalitation

Failed reader initializations happen frome time to time, mostly because
of messed up commandline arguments. This results in ugly crashes very
often. Lets control this a bit by catching the exception string and
print it.

Change-Id: I313017355da01bbef7c3d3f1899555aadb509319
---
M pySim-prog.py
M pySim-read.py
M pySim/utils.py
3 files changed, 25 insertions(+), 17 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/28/23028/1

diff --git a/pySim-prog.py b/pySim-prog.py
index cf503d0..e9b0433 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -720,6 +720,8 @@
 
 	# Init card reader driver
 	sl = init_reader(opts)
+	if (sl == None):
+		exit(1)
 
 	# Create command layer
 	scc = SimCardCommands(transport=sl)
diff --git a/pySim-read.py b/pySim-read.py
index f901260..6aebda3 100755
--- a/pySim-read.py
+++ b/pySim-read.py
@@ -82,6 +82,8 @@
 
 	# Init card reader driver
 	sl = init_reader(opts)
+	if (sel == None):
+		exit(1)
 
 	# Create command layer
 	scc = SimCardCommands(transport=sl)
diff --git a/pySim/utils.py b/pySim/utils.py
index c150184..67bfa74 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -607,24 +607,28 @@
 	"""
 	Init card reader driver
 	"""
-	if opts.pcsc_dev is not None:
-		print("Using PC/SC reader interface")
-		from pySim.transport.pcsc import PcscSimLink
-		sl = PcscSimLink(opts.pcsc_dev)
-	elif opts.osmocon_sock is not None:
-		print("Using Calypso-based (OsmocomBB) reader interface")
-		from pySim.transport.calypso import CalypsoSimLink
-		sl = CalypsoSimLink(sock_path=opts.osmocon_sock)
-	elif opts.modem_dev is not None:
-		print("Using modem for Generic SIM Access (3GPP TS 27.007)")
-		from pySim.transport.modem_atcmd import ModemATCommandLink
-		sl = ModemATCommandLink(device=opts.modem_dev, baudrate=opts.modem_baud)
-	else: # Serial reader is default
-		print("Using serial reader interface")
-		from pySim.transport.serial import SerialSimLink
-		sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate)
+	try:
+		if opts.pcsc_dev is not None:
+			print("Using PC/SC reader interface")
+			from pySim.transport.pcsc import PcscSimLink
+			sl = PcscSimLink(opts.pcsc_dev)
+		elif opts.osmocon_sock is not None:
+			print("Using Calypso-based (OsmocomBB) reader interface")
+			from pySim.transport.calypso import CalypsoSimLink
+			sl = CalypsoSimLink(sock_path=opts.osmocon_sock)
+		elif opts.modem_dev is not None:
+			print("Using modem for Generic SIM Access (3GPP TS 27.007)")
+			from pySim.transport.modem_atcmd import ModemATCommandLink
+			sl = ModemATCommandLink(device=opts.modem_dev, baudrate=opts.modem_baud)
+		else: # Serial reader is default
+			print("Using serial reader interface")
+			from pySim.transport.serial import SerialSimLink
+			sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate)
+		return sl
+	except Exception as e:
+		print("Card reader initialization failed with exception:\n" + str(e))
+		return None
 
-	return sl
 
 def enc_ePDGSelection(hexstr, mcc, mnc, epdg_priority='0001', epdg_fqdn_format='00'):
 	"""

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/23028
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I313017355da01bbef7c3d3f1899555aadb509319
Gerrit-Change-Number: 23028
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210222/c6bdb7c3/attachment.htm>


More information about the gerrit-log mailing list