pySim/transport add support for T=1 protocol and fix APDU/TPDU layer conflicts

ETSI TS 102 221, section 7.3 specifies that UICCs (and eUICCs) may support two
different transport protocols: T=0 or T=1 or both. The spec also says that the
terminal must support both protocols.

This patch adds the necessary functionality to support the T=1 protocol
alongside the T=0 protocol. However, this also means that we have to sharpen
the lines between APDUs and TPDUs.

As this patch also touches the low level interface to readers it was also
manually tested with a classic serial reader. Calypso and AT command readers
were not tested.

Change-Id: I8b56d7804a2b4c392f43f8540e0b6e70001a8970
Related: OS#6367
This commit is contained in:
Philipp Maier
2024-10-28 17:28:43 +01:00
parent f951c56449
commit 852eff54df
25 changed files with 606 additions and 144 deletions

View File

@@ -24,7 +24,7 @@ import argparse
from typing import Optional
from osmocom.utils import h2b, b2h, Hexstr
from pySim.transport import LinkBase
from pySim.transport import LinkBaseTpdu
from pySim.exceptions import ReaderError, ProtocolError
from pySim.utils import ResTuple
@@ -70,12 +70,12 @@ class L1CTLMessageSIM(L1CTLMessage):
L1CTL_SIM_REQ = 0x16
L1CTL_SIM_CONF = 0x17
def __init__(self, pdu):
def __init__(self, tpdu):
super().__init__(self.L1CTL_SIM_REQ)
self.data += pdu
self.data += tpdu
class CalypsoSimLink(LinkBase):
class CalypsoSimLink(LinkBaseTpdu):
"""Transport Link for Calypso based phones."""
name = 'Calypso-based (OsmocomBB) reader'
@@ -129,10 +129,10 @@ class CalypsoSimLink(LinkBase):
def wait_for_card(self, timeout: Optional[int] = None, newcardonly: bool = False):
pass # Nothing to do really ...
def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple:
def send_tpdu(self, tpdu: Hexstr) -> ResTuple:
# Request FULL reset
req_msg = L1CTLMessageSIM(h2b(pdu))
# Request sending of TPDU
req_msg = L1CTLMessageSIM(h2b(tpdu))
self.sock.send(req_msg.gen_msg())
# Read message length first