From fdcf3c570248a43fd9f773a7189dfbb450a4fe7a Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 11 Jul 2023 08:52:39 +0200 Subject: [PATCH] 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 --- docs/shell.rst | 5 +++-- pySim/global_platform.py | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/shell.rst b/docs/shell.rst index ef08fcf1..73b988ae 100644 --- a/docs/shell.rst +++ b/docs/shell.rst @@ -795,8 +795,9 @@ projects like GlobalPlatformPro meanwhile. 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 baae2345..ea8b70df 100644 --- a/pySim/global_platform.py +++ b/pySim/global_platform.py @@ -223,9 +223,21 @@ class ADF_SD(CardADF): 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))