laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/33210 ) Change subject: ts_102221: Add "resume_uicc" command ...................................................................... ts_102221: Add "resume_uicc" command We've had a "suspend_uicc" command since commit ec95053249bc7f9308ca1f659d8ef6ac97a6e393 in 2021, but didn't yet have the corresponding "resume" pair. Note that you cannot really execute this in a reasonable way from within pySim, as it is issuing other commands than those permitted between SUSPEND and RESUME by TS 102 221 Section 11.1.22.3.2 Change-Id: I3322fde74f680e77954e1d3e18a32ef5662759f2 --- M docs/shell.rst M pySim/commands.py M pySim/ts_102_221.py 3 files changed, 47 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/10/33210/1 diff --git a/docs/shell.rst b/docs/shell.rst index 8f85246..cce790a 100644 --- a/docs/shell.rst +++ b/docs/shell.rst @@ -217,6 +217,20 @@ :module: pySim.ts_102_221 :func: CardProfileUICC.AddlShellCommands.suspend_uicc_parser +resume_uicc +~~~~~~~~~~~ +This command allows you to perform the SUSPEND UICC command for the RESUME operation on the card. + +Suspend/Resume is a relatively recent power-saving addition to the UICC specifications, allowing for +suspend/resume while maintaining state, as opposed to a full power-off (deactivate) and power-on +(activate) of the card. + +The pySim command just sends that SUSPEND UICC (RESUME) command and doesn't perform the full related +sequence including the electrical power down. + +.. argparse:: + :module: pySim.ts_102_221 + :func: CardProfileUICC.AddlShellCommands.resume_uicc_parser pySim commands diff --git a/pySim/commands.py b/pySim/commands.py index 6acdb2e..424ed0d 100644 --- a/pySim/commands.py +++ b/pySim/commands.py @@ -631,6 +631,14 @@ resume_token = data[4:] return (negotiated_duration_secs, resume_token, sw) + # ETSI TS 102 221 11.1.22 + def resume_uicc(self, token: str): + """Send SUSPEND UICC (resume) to the card.""" + if len(h2b(token)) != 8: + raise ValueError("Token must be 8 bytes long") + data, sw = self._tp.send_apdu_checksw('8076010008' + token) + negotiated_duration_secs = decode_duration(data[:4]) + def get_data(self, tag: int, cla: int = 0x00): data, sw = self._tp.send_apdu('%02xca%04x00' % (cla, tag)) return (data, sw) diff --git a/pySim/ts_102_221.py b/pySim/ts_102_221.py index bade9cf..19b63fe 100644 --- a/pySim/ts_102_221.py +++ b/pySim/ts_102_221.py @@ -870,6 +870,14 @@ self._cmd.poutput( 'Negotiated Duration: %u secs, Token: %s, SW: %s' % (duration, token, sw)) + resume_uicc_parser = argparse.ArgumentParser() + resume_uicc_parser.add_argument('token', type=str, help='Token provided during SUSPEND') + + @cmd2.with_argparser(resume_uicc_parser) + def do_resume_uicc(self, opts): + """Perform the REUSME UICC operation. Only supported on some UICC.""" + self._cmd.card._scc.resume_uicc(opts.token) + class CardProfileUICCSIM(CardProfileUICC): """Same as above, but including 2G SIM support""" -- To view, visit https://gerrit.osmocom.org/c/pysim/+/33210 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I3322fde74f680e77954e1d3e18a32ef5662759f2 Gerrit-Change-Number: 33210 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge@osmocom.org> Gerrit-MessageType: newchange