mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-28 16:28:33 +03:00
ts_102221: Add "resume_uicc" command
We've had a "suspend_uicc" command since commit
ec95053249 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 required to power-cycle the card
between SUSPEND and RESUME, see TS 102 221 Section 11.1.22.3.2
Change-Id: I3322fde74f680e77954e1d3e18a32ef5662759f2
This commit is contained in:
@@ -217,6 +217,20 @@ including the electrical power down.
|
|||||||
:module: pySim.ts_102_221
|
:module: pySim.ts_102_221
|
||||||
:func: CardProfileUICC.AddlShellCommands.suspend_uicc_parser
|
: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
|
pySim commands
|
||||||
|
|||||||
@@ -631,6 +631,13 @@ class SimCardCommands:
|
|||||||
resume_token = data[4:]
|
resume_token = data[4:]
|
||||||
return (negotiated_duration_secs, resume_token, sw)
|
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)
|
||||||
|
|
||||||
def get_data(self, tag: int, cla: int = 0x00):
|
def get_data(self, tag: int, cla: int = 0x00):
|
||||||
data, sw = self._tp.send_apdu('%02xca%04x00' % (cla, tag))
|
data, sw = self._tp.send_apdu('%02xca%04x00' % (cla, tag))
|
||||||
return (data, sw)
|
return (data, sw)
|
||||||
|
|||||||
@@ -864,12 +864,22 @@ class CardProfileUICC(CardProfile):
|
|||||||
# not ISO7816-4 but TS 102 221
|
# not ISO7816-4 but TS 102 221
|
||||||
@cmd2.with_argparser(suspend_uicc_parser)
|
@cmd2.with_argparser(suspend_uicc_parser)
|
||||||
def do_suspend_uicc(self, opts):
|
def do_suspend_uicc(self, opts):
|
||||||
"""Perform the SUSPEND UICC command. Only supported on some UICC."""
|
"""Perform the SUSPEND UICC command. Only supported on some UICC (check EF.UMPC)."""
|
||||||
(duration, token, sw) = self._cmd.card._scc.suspend_uicc(min_len_secs=opts.min_duration_secs,
|
(duration, token, sw) = self._cmd.card._scc.suspend_uicc(min_len_secs=opts.min_duration_secs,
|
||||||
max_len_secs=opts.max_duration_secs)
|
max_len_secs=opts.max_duration_secs)
|
||||||
self._cmd.poutput(
|
self._cmd.poutput(
|
||||||
'Negotiated Duration: %u secs, Token: %s, SW: %s' % (duration, token, sw))
|
'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. Also: A power-cycle
|
||||||
|
of the card is required between SUSPEND and RESUME, and only very few non-RESUME
|
||||||
|
commands are permitted between SUSPEND and RESUME. See TS 102 221 Section 11.1.22."""
|
||||||
|
self._cmd.card._scc.resume_uicc(opts.token)
|
||||||
|
|
||||||
|
|
||||||
class CardProfileUICCSIM(CardProfileUICC):
|
class CardProfileUICCSIM(CardProfileUICC):
|
||||||
"""Same as above, but including 2G SIM support"""
|
"""Same as above, but including 2G SIM support"""
|
||||||
|
|||||||
Reference in New Issue
Block a user