forked from public/pysim
transport: Pass arbitrary kwargs to base-class constructor
Change-Id: I3cd5ba87cf53409ea97196d5789ed28eef072c68
This commit is contained in:
@@ -28,7 +28,8 @@ from pySim.utils import sw_match
|
|||||||
class LinkBase(object):
|
class LinkBase(object):
|
||||||
"""Base class for link/transport to card."""
|
"""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):
|
def set_sw_interpreter(self, interp):
|
||||||
"""Set an (optional) status word interpreter."""
|
"""Set an (optional) status word interpreter."""
|
||||||
@@ -112,7 +113,7 @@ class LinkBase(object):
|
|||||||
raise SwMatchError(rv[1], sw.lower(), self.sw_interpreter)
|
raise SwMatchError(rv[1], sw.lower(), self.sw_interpreter)
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
def init_reader(opts) -> Optional[LinkBase]:
|
def init_reader(opts, **kwargs) -> Optional[LinkBase]:
|
||||||
"""
|
"""
|
||||||
Init card reader driver
|
Init card reader driver
|
||||||
"""
|
"""
|
||||||
@@ -121,19 +122,19 @@ def init_reader(opts) -> Optional[LinkBase]:
|
|||||||
if opts.pcsc_dev is not None:
|
if opts.pcsc_dev is not None:
|
||||||
print("Using PC/SC reader interface")
|
print("Using PC/SC reader interface")
|
||||||
from pySim.transport.pcsc import PcscSimLink
|
from pySim.transport.pcsc import PcscSimLink
|
||||||
sl = PcscSimLink(opts.pcsc_dev)
|
sl = PcscSimLink(opts.pcsc_dev, **kwargs)
|
||||||
elif opts.osmocon_sock is not None:
|
elif opts.osmocon_sock is not None:
|
||||||
print("Using Calypso-based (OsmocomBB) reader interface")
|
print("Using Calypso-based (OsmocomBB) reader interface")
|
||||||
from pySim.transport.calypso import CalypsoSimLink
|
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:
|
elif opts.modem_dev is not None:
|
||||||
print("Using modem for Generic SIM Access (3GPP TS 27.007)")
|
print("Using modem for Generic SIM Access (3GPP TS 27.007)")
|
||||||
from pySim.transport.modem_atcmd import ModemATCommandLink
|
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
|
else: # Serial reader is default
|
||||||
print("Using serial reader interface")
|
print("Using serial reader interface")
|
||||||
from pySim.transport.serial import SerialSimLink
|
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
|
return sl
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Card reader initialization failed with exception:\n" + str(e))
|
print("Card reader initialization failed with exception:\n" + str(e))
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ class L1CTLMessageSIM(L1CTLMessage):
|
|||||||
class CalypsoSimLink(LinkBase):
|
class CalypsoSimLink(LinkBase):
|
||||||
"""Transport Link for Calypso based phones."""
|
"""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
|
# Make sure that a given socket path exists
|
||||||
if not os.path.exists(sock_path):
|
if not os.path.exists(sock_path):
|
||||||
raise ReaderError("There is no such ('%s') UNIX socket" % sock_path)
|
raise ReaderError("There is no such ('%s') UNIX socket" % sock_path)
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ from pySim.exceptions import *
|
|||||||
|
|
||||||
class ModemATCommandLink(LinkBase):
|
class ModemATCommandLink(LinkBase):
|
||||||
"""Transport Link for 3GPP TS 27.007 compliant modems."""
|
"""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._sl = serial.Serial(device, baudrate, timeout=5)
|
||||||
self._device = device
|
self._device = device
|
||||||
self._atr = None
|
self._atr = None
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ from pySim.utils import h2i, i2h
|
|||||||
class PcscSimLink(LinkBase):
|
class PcscSimLink(LinkBase):
|
||||||
""" pySim: PCSC reader transport link."""
|
""" 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()
|
r = readers()
|
||||||
self._reader = r[reader_number]
|
self._reader = r[reader_number]
|
||||||
self._con = self._reader.createConnection()
|
self._con = self._reader.createConnection()
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ class SerialSimLink(LinkBase):
|
|||||||
""" pySim: Transport Link for serial (RS232) based readers included with simcard"""
|
""" pySim: Transport Link for serial (RS232) based readers included with simcard"""
|
||||||
|
|
||||||
def __init__(self, device:str='/dev/ttyUSB0', baudrate:int=9600, rst:str='-rts',
|
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):
|
if not os.path.exists(device):
|
||||||
raise ValueError("device file %s does not exist -- abort" % device)
|
raise ValueError("device file %s does not exist -- abort" % device)
|
||||||
self._sl = serial.Serial(
|
self._sl = serial.Serial(
|
||||||
|
|||||||
Reference in New Issue
Block a user