dexter has uploaded this change for review.

View Change

pySim-shell: add new commandline option "--pure"

by default pySim-shell does all kinds of probing and file selection
on startup. This is to determine the card type and to find a suitable
card profile. However, in case the card is non yet provisioned this
probing may cause a error messages and even might upset the cards
internal state. So let's have a commandline option thrugh which we
can instruct pySim-shell to skip any initialization and to give us
a prompt immediately, so that we can enter custom APDUs

Related: OS#6367
Change-Id: I1d8a57de201fe7ad7cbcbc6f72969ea8521e821d
---
M pySim-shell.py
M pySim/app.py
M pySim/cards.py
3 files changed, 12 insertions(+), 3 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/08/38608/1
diff --git a/pySim-shell.py b/pySim-shell.py
index 413d3f7..7e59cdf 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -1060,6 +1060,8 @@
help="Use automatic card handling machine")
global_group.add_argument("--noprompt", help="Run in non interactive mode",
action='store_true', default=False)
+global_group.add_argument("--pure", help="Skip all card/profile initialization",
+ action='store_true', default=False)

adm_group = global_group.add_mutually_exclusive_group()
adm_group.add_argument('-a', '--pin-adm', metavar='PIN_ADM1', dest='pin_adm', default=None,
@@ -1105,7 +1107,7 @@
# is no card in the reader or the card is unresponsive. PysimApp is
# able to tolerate and recover from that.
try:
- rs, card = init_card(sl)
+ rs, card = init_card(sl, opts.pure)
app = PysimApp(card, rs, sl, ch)
except:
startup_errors = True
diff --git a/pySim/app.py b/pySim/app.py
index 5a93f98..d8087aa 100644
--- a/pySim/app.py
+++ b/pySim/app.py
@@ -19,7 +19,7 @@
from pySim.transport import LinkBase
from pySim.commands import SimCardCommands
from pySim.filesystem import CardModel, CardApplication
-from pySim.cards import card_detect, SimCardBase, UiccCardBase
+from pySim.cards import card_detect, SimCardBase, UiccCardBase, CardBase
from pySim.runtime import RuntimeState
from pySim.profile import CardProfile
from pySim.cdma_ruim import CardProfileRUIM
@@ -42,7 +42,7 @@
import pySim.global_platform
import pySim.euicc

-def init_card(sl: LinkBase) -> Tuple[RuntimeState, SimCardBase]:
+def init_card(sl: LinkBase, pure: bool = False) -> Tuple[RuntimeState, SimCardBase]:
"""
Detect card in reader and setup card profile and runtime state. This
function must be called at least once on startup. The card and runtime
@@ -57,6 +57,12 @@
print("Waiting for card...")
sl.wait_for_card(3)

+ # The user may opt to skip all card initialization. In this case only the
+ # most basic card profile is selected. This mode is suitable for blank
+ # cards that need card O/S initialization using APDU scripts first.
+ if pure:
+ return None, CardBase(scc)
+
generic_card = False
card = card_detect(scc)
if card is None:
diff --git a/pySim/cards.py b/pySim/cards.py
index b7958f4..b0d8312 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -168,6 +168,7 @@
return (None, None)

def card_detect(scc: SimCardCommands) -> Optional[CardBase]:
+
# UICC always has higher preference, as a UICC might also contain a SIM application
uicc = UiccCardBase(scc)
if uicc.probe():

To view, visit change 38608. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I1d8a57de201fe7ad7cbcbc6f72969ea8521e821d
Gerrit-Change-Number: 38608
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier@sysmocom.de>