mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-16 18:38:32 +03:00
pySim-shell: add new commandline option "--skip-card-init"
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
This commit is contained in:
@@ -1060,6 +1060,8 @@ global_group.add_argument("--card_handler", dest="card_handler_config", metavar=
|
|||||||
help="Use automatic card handling machine")
|
help="Use automatic card handling machine")
|
||||||
global_group.add_argument("--noprompt", help="Run in non interactive mode",
|
global_group.add_argument("--noprompt", help="Run in non interactive mode",
|
||||||
action='store_true', default=False)
|
action='store_true', default=False)
|
||||||
|
global_group.add_argument("--skip-card-init", help="Skip all card/profile initialization",
|
||||||
|
action='store_true', default=False)
|
||||||
|
|
||||||
adm_group = global_group.add_mutually_exclusive_group()
|
adm_group = global_group.add_mutually_exclusive_group()
|
||||||
adm_group.add_argument('-a', '--pin-adm', metavar='PIN_ADM1', dest='pin_adm', default=None,
|
adm_group.add_argument('-a', '--pin-adm', metavar='PIN_ADM1', dest='pin_adm', default=None,
|
||||||
@@ -1105,7 +1107,7 @@ if __name__ == '__main__':
|
|||||||
# is no card in the reader or the card is unresponsive. PysimApp is
|
# is no card in the reader or the card is unresponsive. PysimApp is
|
||||||
# able to tolerate and recover from that.
|
# able to tolerate and recover from that.
|
||||||
try:
|
try:
|
||||||
rs, card = init_card(sl)
|
rs, card = init_card(sl, opts.skip_card_init)
|
||||||
app = PysimApp(card, rs, sl, ch)
|
app = PysimApp(card, rs, sl, ch)
|
||||||
except:
|
except:
|
||||||
startup_errors = True
|
startup_errors = True
|
||||||
|
|||||||
10
pySim/app.py
10
pySim/app.py
@@ -19,7 +19,7 @@ from typing import Tuple
|
|||||||
from pySim.transport import LinkBase
|
from pySim.transport import LinkBase
|
||||||
from pySim.commands import SimCardCommands
|
from pySim.commands import SimCardCommands
|
||||||
from pySim.filesystem import CardModel, CardApplication
|
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.runtime import RuntimeState
|
||||||
from pySim.profile import CardProfile
|
from pySim.profile import CardProfile
|
||||||
from pySim.cdma_ruim import CardProfileRUIM
|
from pySim.cdma_ruim import CardProfileRUIM
|
||||||
@@ -42,7 +42,7 @@ import pySim.ara_m
|
|||||||
import pySim.global_platform
|
import pySim.global_platform
|
||||||
import pySim.euicc
|
import pySim.euicc
|
||||||
|
|
||||||
def init_card(sl: LinkBase) -> Tuple[RuntimeState, SimCardBase]:
|
def init_card(sl: LinkBase, skip_card_init: bool = False) -> Tuple[RuntimeState, SimCardBase]:
|
||||||
"""
|
"""
|
||||||
Detect card in reader and setup card profile and runtime state. This
|
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
|
function must be called at least once on startup. The card and runtime
|
||||||
@@ -57,6 +57,12 @@ def init_card(sl: LinkBase) -> Tuple[RuntimeState, SimCardBase]:
|
|||||||
print("Waiting for card...")
|
print("Waiting for card...")
|
||||||
sl.wait_for_card(3)
|
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 skip_card_init:
|
||||||
|
return None, CardBase(scc)
|
||||||
|
|
||||||
generic_card = False
|
generic_card = False
|
||||||
card = card_detect(scc)
|
card = card_detect(scc)
|
||||||
if card is None:
|
if card is None:
|
||||||
|
|||||||
@@ -228,7 +228,8 @@ class UnittestUtils(unittest.TestCase):
|
|||||||
def runPySimShell(self, cardname:str, script:str,
|
def runPySimShell(self, cardname:str, script:str,
|
||||||
add_adm:bool = False,
|
add_adm:bool = False,
|
||||||
add_csv:bool = False,
|
add_csv:bool = False,
|
||||||
no_exceptions = False):
|
no_exceptions = False,
|
||||||
|
skip_card_init = False):
|
||||||
|
|
||||||
""" execute pySimShell.py. Each testcase should run pySim-shell at least once. The working directlry is the
|
""" execute pySimShell.py. Each testcase should run pySim-shell at least once. The working directlry is the
|
||||||
testcase directory.
|
testcase directory.
|
||||||
@@ -261,6 +262,8 @@ class UnittestUtils(unittest.TestCase):
|
|||||||
if add_csv:
|
if add_csv:
|
||||||
adm1 = self.cards[cardname]['adm1']
|
adm1 = self.cards[cardname]['adm1']
|
||||||
cmdline += " --csv " + self.top_dir + CARD_DATA_CSV
|
cmdline += " --csv " + self.top_dir + CARD_DATA_CSV
|
||||||
|
if skip_card_init:
|
||||||
|
cmdline += " --skip-card-init"
|
||||||
|
|
||||||
# Execute commandline
|
# Execute commandline
|
||||||
cmdline += " > " + logfile_name + " 2>&1"
|
cmdline += " > " + logfile_name + " 2>&1"
|
||||||
|
|||||||
Reference in New Issue
Block a user