mirror of https://gerrit.osmocom.org/pysim
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
This commit is contained in:
parent
bdf3d3597b
commit
c8caec2933
|
@ -720,6 +720,8 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
# Init card reader driver
|
# Init card reader driver
|
||||||
sl = init_reader(opts)
|
sl = init_reader(opts)
|
||||||
|
if sl is None:
|
||||||
|
exit(1)
|
||||||
|
|
||||||
# Create command layer
|
# Create command layer
|
||||||
scc = SimCardCommands(transport=sl)
|
scc = SimCardCommands(transport=sl)
|
||||||
|
|
|
@ -82,6 +82,8 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
# Init card reader driver
|
# Init card reader driver
|
||||||
sl = init_reader(opts)
|
sl = init_reader(opts)
|
||||||
|
if sl is None:
|
||||||
|
exit(1)
|
||||||
|
|
||||||
# Create command layer
|
# Create command layer
|
||||||
scc = SimCardCommands(transport=sl)
|
scc = SimCardCommands(transport=sl)
|
||||||
|
|
|
@ -607,24 +607,28 @@ def init_reader(opts):
|
||||||
"""
|
"""
|
||||||
Init card reader driver
|
Init card reader driver
|
||||||
"""
|
"""
|
||||||
if opts.pcsc_dev is not None:
|
try:
|
||||||
print("Using PC/SC reader interface")
|
if opts.pcsc_dev is not None:
|
||||||
from pySim.transport.pcsc import PcscSimLink
|
print("Using PC/SC reader interface")
|
||||||
sl = PcscSimLink(opts.pcsc_dev)
|
from pySim.transport.pcsc import PcscSimLink
|
||||||
elif opts.osmocon_sock is not None:
|
sl = PcscSimLink(opts.pcsc_dev)
|
||||||
print("Using Calypso-based (OsmocomBB) reader interface")
|
elif opts.osmocon_sock is not None:
|
||||||
from pySim.transport.calypso import CalypsoSimLink
|
print("Using Calypso-based (OsmocomBB) reader interface")
|
||||||
sl = CalypsoSimLink(sock_path=opts.osmocon_sock)
|
from pySim.transport.calypso import CalypsoSimLink
|
||||||
elif opts.modem_dev is not None:
|
sl = CalypsoSimLink(sock_path=opts.osmocon_sock)
|
||||||
print("Using modem for Generic SIM Access (3GPP TS 27.007)")
|
elif opts.modem_dev is not None:
|
||||||
from pySim.transport.modem_atcmd import ModemATCommandLink
|
print("Using modem for Generic SIM Access (3GPP TS 27.007)")
|
||||||
sl = ModemATCommandLink(device=opts.modem_dev, baudrate=opts.modem_baud)
|
from pySim.transport.modem_atcmd import ModemATCommandLink
|
||||||
else: # Serial reader is default
|
sl = ModemATCommandLink(device=opts.modem_dev, baudrate=opts.modem_baud)
|
||||||
print("Using serial reader interface")
|
else: # Serial reader is default
|
||||||
from pySim.transport.serial import SerialSimLink
|
print("Using serial reader interface")
|
||||||
sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate)
|
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'):
|
def enc_ePDGSelection(hexstr, mcc, mnc, epdg_priority='0001', epdg_fqdn_format='00'):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue