dexter has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/28162 )
Change subject: pySim-shell: catch exceptions from walk() while exporting
......................................................................
pySim-shell: catch exceptions from walk() while exporting
When we run the exporter we also get an error summary at the end.
However, if walk() throws an eception this stops the exporter
immediately and we won't get the summpary. Lets catch exceptions from
walk as well so that we are able to end gracefully.
Change-Id: I3edc250ef2a84550c5b821a72e207e4d685790a5
---
M pySim-shell.py
1 file changed, 12 insertions(+), 5 deletions(-)
Approvals:
dexter: Verified
laforge: Looks good to me, approved
diff --git a/pySim-shell.py b/pySim-shell.py
index 0ed4b7c..f498dea 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -648,10 +648,17 @@
context = {'ERR': 0, 'COUNT': 0, 'BAD': [],
'DF_SKIP': 0, 'DF_SKIP_REASON': []}
kwargs_export = {'as_json': opts.json}
+ exception_str_add = ""
+
if opts.filename:
self.export_ef(opts.filename, context, **kwargs_export)
else:
- self.walk(0, self.export_ef, None, context, **kwargs_export)
+ try:
+ self.walk(0, self.export_ef, None, context, **kwargs_export)
+ except Exception as e:
+ print("# Stopping early here due to exception: " + str(e))
+ print("#")
+ exception_str_add = ", also had to stop early due to exception:" + str(e)
self._cmd.poutput(boxed_heading_str("Export summary"))
@@ -666,14 +673,14 @@
self._cmd.poutput("# " + b)
if context['ERR'] and context['DF_SKIP']:
- raise RuntimeError("unable to export %i elementary file(s) and %i dedicated file(s)" % (
- context['ERR'], context['DF_SKIP']))
+ raise RuntimeError("unable to export %i elementary file(s) and %i dedicated file(s)%s" % (
+ context['ERR'], context['DF_SKIP'], exception_str_add))
elif context['ERR']:
raise RuntimeError(
- "unable to export %i elementary file(s)" % context['ERR'])
+ "unable to export %i elementary file(s)%s" % (context['ERR'], exception_str_add))
elif context['DF_SKIP']:
raise RuntimeError(
- "unable to export %i dedicated files(s)" % context['ERR'])
+ "unable to export %i dedicated files(s)%s" % (context['ERR'], exception_str_add))
def do_reset(self, opts):
"""Reset the Card."""
4 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28162
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I3edc250ef2a84550c5b821a72e207e4d685790a5
Gerrit-Change-Number: 28162
Gerrit-PatchSet: 5
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged
dexter has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/28160 )
Change subject: pySim-shell: extend walk() so that we can also have an action of ADF or DF
......................................................................
pySim-shell: extend walk() so that we can also have an action of ADF or DF
The walk() method that we use to traverse the whole file system tree is
currently only able to execute action callbacks on EFs. Lets add a
mechanism that allows us to have a second callback that is executed when
we hit a DF or ADF.
Change-Id: Iabcd78552a14a2d3f8f31273dda7731e1f640cdb
---
M pySim-shell.py
1 file changed, 15 insertions(+), 9 deletions(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/pySim-shell.py b/pySim-shell.py
index 95dc707..0ed4b7c 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -483,12 +483,18 @@
self._cmd.poutput(directory_str)
self._cmd.poutput("%d files" % len(selectables))
- def walk(self, indent=0, action=None, context=None, **kwargs):
+ def walk(self, indent=0, action_ef=None, action_df=None, context=None, **kwargs):
"""Recursively walk through the file system, starting at the currently selected DF"""
+
+ if isinstance(self._cmd.rs.selected_file, CardDF):
+ if action_df:
+ action_df(context, opts)
+
files = self._cmd.rs.selected_file.get_selectables(
flags=['FNAMES', 'ANAMES'])
for f in files:
- if not action:
+ # special case: When no action is performed, just output a directory
+ if not action_ef and not action_df:
output_str = " " * indent + str(f) + (" " * 250)
output_str = output_str[0:25]
if isinstance(files[f], CardADF):
@@ -515,12 +521,12 @@
# If the DF was skipped, we never have entered the directory
# below, so we must not move up.
if skip_df == False:
- self.walk(indent + 1, action, context, **kwargs)
+ self.walk(indent + 1, action_ef, action_df, context, **kwargs)
fcp_dec = self._cmd.rs.select("..", self._cmd)
- elif action:
+ elif action_ef:
df_before_action = self._cmd.rs.selected_file
- action(f, context, **kwargs)
+ action_ef(f, context, **kwargs)
# When walking through the file system tree the action must not
# always restore the currently selected file to the file that
# was selected before executing the action() callback.
@@ -532,8 +538,8 @@
"""Display a filesystem-tree with all selectable files"""
self.walk()
- def export(self, filename, context, as_json):
- """ Select and export a single file """
+ def export_ef(self, filename, context, as_json):
+ """ Select and export a single elementary file (EF) """
context['COUNT'] += 1
df = self._cmd.rs.selected_file
@@ -643,9 +649,9 @@
'DF_SKIP': 0, 'DF_SKIP_REASON': []}
kwargs_export = {'as_json': opts.json}
if opts.filename:
- self.export(opts.filename, context, **kwargs_export)
+ self.export_ef(opts.filename, context, **kwargs_export)
else:
- self.walk(0, self.export, context, **kwargs_export)
+ self.walk(0, self.export_ef, None, context, **kwargs_export)
self._cmd.poutput(boxed_heading_str("Export summary"))
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28160
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Iabcd78552a14a2d3f8f31273dda7731e1f640cdb
Gerrit-Change-Number: 28160
Gerrit-PatchSet: 6
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged
Attention is currently required from: neels, fixeria, pespin.
Hello Jenkins Builder, neels, laforge, pespin,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/28220
to look at the new patch set (#2).
Change subject: BSC_Tests: fix a race condition in TC_imm_ass_pre_[ts,chan]_ack
......................................................................
BSC_Tests: fix a race condition in TC_imm_ass_pre_[ts,chan]_ack
These test cases sporadically fail on Jenkins and 9/10 times on my
machine. The problem appears to be that we are sending both the
RSL CHANnel ReQuireD and the VTY command simultaneously, and the
later may be handled earlier than the former by osmo-bsc.
Ensure that the RSL message is handled first by sending the VTY
command after we have received the RSL CHANnel ACTivation message.
Change-Id: I38cd31041741b69eb15098a089b4d4b6b918ffd4
---
M bsc/BSC_Tests.ttcn
1 file changed, 6 insertions(+), 6 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/20/28220/2
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/28220
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I38cd31041741b69eb15098a089b4d4b6b918ffd4
Gerrit-Change-Number: 28220
Gerrit-PatchSet: 2
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newpatchset
dexter has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/28163 )
Change subject: pySim-shell: make APDU command available on the lowest level
......................................................................
pySim-shell: make APDU command available on the lowest level
The apdu command is used to communicate with the card on the lowest
possible level. Lets make it available even before a card profile (rs)
is avalable. This is especially useful when the card has no files on it,
in this situation pySim-shell will not be able to assign a profile to
the card at all. We can then use the apdu command to equip the card with
the most basic files and start over.
Change-Id: I601b8f17bd6af41dcbf7bbb53c75903dd46beee7
---
M pySim-shell.py
1 file changed, 21 insertions(+), 15 deletions(-)
Approvals:
laforge: Looks good to me, approved
fixeria: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/pySim-shell.py b/pySim-shell.py
index 7ec77d3..7fa9d81 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -91,7 +91,7 @@
profile = CardProfile.pick(scc)
if profile is None:
print("Unsupported card type!")
- return None, None
+ return None, card
print("Info: Card is of type: %s" % str(profile))
@@ -224,7 +224,10 @@
not self.numeric_path)
self.prompt = 'pySIM-shell (%s)> ' % ('/'.join(path_list))
else:
- self.prompt = 'pySIM-shell (no card)> '
+ if self.card:
+ self.prompt = 'pySIM-shell (no card profile)> '
+ else:
+ self.prompt = 'pySIM-shell (no card)> '
@cmd2.with_category(CUSTOM_CATEGORY)
def do_intro(self, _):
@@ -241,6 +244,21 @@
rs, card = init_card(sl)
self.equip(card, rs)
+ apdu_cmd_parser = argparse.ArgumentParser()
+ apdu_cmd_parser.add_argument('APDU', type=str, help='APDU as hex string')
+
+ @cmd2.with_argparser(apdu_cmd_parser)
+ def do_apdu(self, opts):
+ """Send a raw APDU to the card, and print SW + Response.
+ DANGEROUS: pySim-shell will not know any card state changes, and
+ not continue to work as expected if you e.g. select a different
+ file."""
+ data, sw = self.card._scc._tp.send_apdu(opts.APDU)
+ if data:
+ self.poutput("SW: %s, RESP: %s" % (sw, data))
+ else:
+ self.poutput("SW: %s" % sw)
+
class InterceptStderr(list):
def __init__(self):
self._stderr_backup = sys.stderr
@@ -683,18 +701,6 @@
else:
raise ValueError("error: cannot authenticate, no adm-pin!")
- apdu_cmd_parser = argparse.ArgumentParser()
- apdu_cmd_parser.add_argument('APDU', type=str, help='APDU as hex string')
-
- @cmd2.with_argparser(apdu_cmd_parser)
- def do_apdu(self, opts):
- """Send a raw APDU to the card, and print SW + Response.
- DANGEROUS: pySim-shell will not know any card state changes, and
- not continue to work as expected if you e.g. select a different
- file."""
- data, sw = self._cmd.card._scc._tp.send_apdu(opts.APDU)
- self._cmd.poutput("SW: %s %s, RESP: %s" % (sw, self._cmd.rs.interpret_sw(sw), data))
-
@with_default_category('ISO7816 Commands')
class Iso7816Commands(CommandSet):
@@ -940,7 +946,7 @@
" it should also be noted that some readers may behave strangely when no card")
print(" is inserted.)")
print("")
- app = PysimApp(None, None, sl, ch, opts.script)
+ app = PysimApp(card, None, sl, ch, opts.script)
# If the user supplies an ADM PIN at via commandline args authenticate
# immediately so that the user does not have to use the shell commands
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28163
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I601b8f17bd6af41dcbf7bbb53c75903dd46beee7
Gerrit-Change-Number: 28163
Gerrit-PatchSet: 4
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged
Attention is currently required from: fixeria, dexter.
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/28185 )
Change subject: ts_102_221: The BTLV IEs FILE SIZE and TOTAL FILE SIZE have a min length
......................................................................
Patch Set 7: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28185
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ief113ce8fe3bcae2c9fb2ff4138df9ccf98d26ff
Gerrit-Change-Number: 28185
Gerrit-PatchSet: 7
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Attention: dexter <pmaier(a)sysmocom.de>
Gerrit-Comment-Date: Fri, 03 Jun 2022 07:37:03 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: dexter.
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/28163 )
Change subject: pySim-shell: make APDU command available on the lowest level
......................................................................
Patch Set 3: Code-Review+2
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28163
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I601b8f17bd6af41dcbf7bbb53c75903dd46beee7
Gerrit-Change-Number: 28163
Gerrit-PatchSet: 3
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: dexter <pmaier(a)sysmocom.de>
Gerrit-Comment-Date: Fri, 03 Jun 2022 07:36:20 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment