diff options
author | Harald Welte <laforge@osmocom.org> | 2021-04-03 11:52:37 +0200 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2021-04-04 10:53:36 +0200 |
commit | 6e0458dda661f653380bfee8cf715412e8124f7c (patch) | |
tree | d393bd8ce9143c8db9746272f2e102dc5bc953ab /pySim/transport/__init__.py | |
parent | 9d0f1f0cd5473a52387fdc4be3f61de185200aaa (diff) |
Move init_reader() from utils.py to transport/__init__.py
This avoids a circular dependency when introducing type annotations.
Change-Id: I168597ac14497fb188a15cb632f32452128bc1c6
Diffstat (limited to 'pySim/transport/__init__.py')
-rw-r--r-- | pySim/transport/__init__.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py index f946af8..24d7521 100644 --- a/pySim/transport/__init__.py +++ b/pySim/transport/__init__.py @@ -3,6 +3,8 @@ """ pySim: PCSC reader transport link base """ +from typing import Optional + from pySim.exceptions import * from pySim.utils import sw_match @@ -103,3 +105,30 @@ class LinkBase(object): if not sw_match(rv[1], sw): raise SwMatchError(rv[1], sw.lower()) return rv + +def init_reader(opts) -> Optional[LinkBase]: + """ + Init card reader driver + """ + sl = None # type : :Optional[LinkBase] + 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 |