diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py index 923787b6..c176f8aa 100644 --- a/pySim/transport/__init__.py +++ b/pySim/transport/__init__.py @@ -28,7 +28,8 @@ from pySim.utils import sw_match class LinkBase(object): """Base class for link/transport to card.""" - sw_interpreter = None + def __init__(self, sw_interpreter=None): + self.sw_interpreter = sw_interpreter def set_sw_interpreter(self, interp): """Set an (optional) status word interpreter.""" @@ -112,7 +113,7 @@ class LinkBase(object): raise SwMatchError(rv[1], sw.lower(), self.sw_interpreter) return rv -def init_reader(opts) -> Optional[LinkBase]: +def init_reader(opts, **kwargs) -> Optional[LinkBase]: """ Init card reader driver """ @@ -121,19 +122,19 @@ def init_reader(opts) -> Optional[LinkBase]: if opts.pcsc_dev is not None: print("Using PC/SC reader interface") from pySim.transport.pcsc import PcscSimLink - sl = PcscSimLink(opts.pcsc_dev) + sl = PcscSimLink(opts.pcsc_dev, **kwargs) 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) + sl = CalypsoSimLink(sock_path=opts.osmocon_sock, **kwargs) 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) + sl = ModemATCommandLink(device=opts.modem_dev, baudrate=opts.modem_baud, **kwargs) else: # Serial reader is default print("Using serial reader interface") from pySim.transport.serial import SerialSimLink - sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate) + sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate, **kwargs) return sl except Exception as e: print("Card reader initialization failed with exception:\n" + str(e)) diff --git a/pySim/transport/calypso.py b/pySim/transport/calypso.py index 3c223e64..b55a089a 100644 --- a/pySim/transport/calypso.py +++ b/pySim/transport/calypso.py @@ -71,7 +71,8 @@ class L1CTLMessageSIM(L1CTLMessage): class CalypsoSimLink(LinkBase): """Transport Link for Calypso based phones.""" - def __init__(self, sock_path:str = "/tmp/osmocom_l2"): + def __init__(self, sock_path:str = "/tmp/osmocom_l2", **kwargs): + super().__init__(**kwargs) # Make sure that a given socket path exists if not os.path.exists(sock_path): raise ReaderError("There is no such ('%s') UNIX socket" % sock_path) diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py index f5a0f238..ecf463cc 100644 --- a/pySim/transport/modem_atcmd.py +++ b/pySim/transport/modem_atcmd.py @@ -29,7 +29,8 @@ from pySim.exceptions import * class ModemATCommandLink(LinkBase): """Transport Link for 3GPP TS 27.007 compliant modems.""" - def __init__(self, device:str='/dev/ttyUSB0', baudrate:int=115200): + def __init__(self, device:str='/dev/ttyUSB0', baudrate:int=115200, **kwargs): + super().__init__(**kwargs) self._sl = serial.Serial(device, baudrate, timeout=5) self._device = device self._atr = None diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py index 2433e792..73a99e8b 100644 --- a/pySim/transport/pcsc.py +++ b/pySim/transport/pcsc.py @@ -30,7 +30,8 @@ from pySim.utils import h2i, i2h class PcscSimLink(LinkBase): """ pySim: PCSC reader transport link.""" - def __init__(self, reader_number:int=0): + def __init__(self, reader_number:int=0, **kwargs): + super().__init__(**kwargs) r = readers() self._reader = r[reader_number] self._con = self._reader.createConnection() diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py index 22788a90..4f2b28f5 100644 --- a/pySim/transport/serial.py +++ b/pySim/transport/serial.py @@ -29,7 +29,8 @@ class SerialSimLink(LinkBase): """ pySim: Transport Link for serial (RS232) based readers included with simcard""" def __init__(self, device:str='/dev/ttyUSB0', baudrate:int=9600, rst:str='-rts', - debug:bool=False): + debug:bool=False, **kwargs): + super().__init__(**kwargs) if not os.path.exists(device): raise ValueError("device file %s does not exist -- abort" % device) self._sl = serial.Serial(