laforge has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/33670
)
Change subject: GlobalPlatform ADF.SD: Add command line reference + error message
......................................................................
GlobalPlatform ADF.SD: Add command line reference + error message
The get_data shell command didn't have any interactive help / syntax,
and no meaningful error message in case an unknown data object name
was specified by the user. Let's fix that.
Change-Id: I09faaf5d45118635cf832c8c513033aede1427e5
---
M docs/shell.rst
M pySim/global_platform.py
2 files changed, 30 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/70/33670/1
diff --git a/docs/shell.rst b/docs/shell.rst
index ef08fcf..73b988a 100644
--- a/docs/shell.rst
+++ b/docs/shell.rst
@@ -795,8 +795,9 @@
get_data
~~~~~~~~
-Performs the GET DATA command as specified by GlobalPlatform.
-
+.. argparse::
+ :module: pySim.global_platform
+ :func: ADF_SD.AddlShellCommands.get_data_parser
cmd2 settable parameters
------------------------
diff --git a/pySim/global_platform.py b/pySim/global_platform.py
index baae234..ea8b70d 100644
--- a/pySim/global_platform.py
+++ b/pySim/global_platform.py
@@ -223,9 +223,21 @@
def __init__(self):
super().__init__()
+ get_data_parser = argparse.ArgumentParser()
+ get_data_parser.add_argument('data_object_name', type=str,
+ help='Name of the data object to be retrieved from the card')
+
+ @cmd2.with_argparser(get_data_parser)
def do_get_data(self, opts):
- tlv_cls_name = opts.arg_list[0]
- tlv_cls = DataCollection().members_by_name[tlv_cls_name]
+ """Perform the GlobalPlatform GET DATA command in order to
obtain some card-specific data."""
+ tlv_cls_name = opts.data_object_name
+ try:
+ tlv_cls = DataCollection().members_by_name[tlv_cls_name]
+ except KeyError:
+ do_names = [camel_to_snake(str(x.__name__)) for x in
DataCollection.possible_nested]
+ self._cmd.poutput('Unknown data object "%s", available
options: %s' % (tlv_cls_name,
+
do_names))
+ return
(data, sw) = self._cmd.card._scc.get_data(cla=0x80, tag=tlv_cls.tag)
ie = tlv_cls()
ie.from_tlv(h2b(data))
--
To view, visit
https://gerrit.osmocom.org/c/pysim/+/33670
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I09faaf5d45118635cf832c8c513033aede1427e5
Gerrit-Change-Number: 33670
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange