mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-25 06:48:33 +03:00
pySim.transport: Also trace card reset events in ApduTracer
Change-Id: Ia46b65124520eb2b8015dfa3f0a135b497668b92
This commit is contained in:
@@ -65,7 +65,7 @@ class DummySimLink(LinkBase):
|
|||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def reset_card(self):
|
def _reset_card(self):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def get_atr(self):
|
def get_atr(self):
|
||||||
|
|||||||
@@ -40,12 +40,18 @@ class ApduTracer:
|
|||||||
def trace_response(self, cmd, sw, resp):
|
def trace_response(self, cmd, sw, resp):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def trace_reset(self):
|
||||||
|
pass
|
||||||
|
|
||||||
class StdoutApduTracer(ApduTracer):
|
class StdoutApduTracer(ApduTracer):
|
||||||
"""Minimalistic APDU tracer, printing commands to stdout."""
|
"""Minimalistic APDU tracer, printing commands to stdout."""
|
||||||
def trace_response(self, cmd, sw, resp):
|
def trace_response(self, cmd, sw, resp):
|
||||||
print("-> %s %s" % (cmd[:10], cmd[10:]))
|
print("-> %s %s" % (cmd[:10], cmd[10:]))
|
||||||
print("<- %s: %s" % (sw, resp))
|
print("<- %s: %s" % (sw, resp))
|
||||||
|
|
||||||
|
def trace_reset(self):
|
||||||
|
print("-- RESET")
|
||||||
|
|
||||||
class ProactiveHandler(abc.ABC):
|
class ProactiveHandler(abc.ABC):
|
||||||
"""Abstract base class representing the interface of some code that handles
|
"""Abstract base class representing the interface of some code that handles
|
||||||
the proactive commands, as returned by the card in responses to the FETCH
|
the proactive commands, as returned by the card in responses to the FETCH
|
||||||
@@ -117,9 +123,16 @@ class LinkBase(abc.ABC):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
|
def _reset_card(self):
|
||||||
|
"""Resets the card (power down/up)
|
||||||
|
"""
|
||||||
|
|
||||||
def reset_card(self):
|
def reset_card(self):
|
||||||
"""Resets the card (power down/up)
|
"""Resets the card (power down/up)
|
||||||
"""
|
"""
|
||||||
|
if self.apdu_tracer:
|
||||||
|
self.apdu_tracer.trace_reset()
|
||||||
|
return self._reset_card()
|
||||||
|
|
||||||
def send_apdu_raw(self, pdu: Hexstr) -> ResTuple:
|
def send_apdu_raw(self, pdu: Hexstr) -> ResTuple:
|
||||||
"""Sends an APDU with minimal processing
|
"""Sends an APDU with minimal processing
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class CalypsoSimLink(LinkBase):
|
|||||||
rsp = self.sock.recv(exp_len)
|
rsp = self.sock.recv(exp_len)
|
||||||
return rsp
|
return rsp
|
||||||
|
|
||||||
def reset_card(self):
|
def _reset_card(self):
|
||||||
# Request FULL reset
|
# Request FULL reset
|
||||||
req_msg = L1CTLMessageReset()
|
req_msg = L1CTLMessageReset()
|
||||||
self.sock.send(req_msg.gen_msg())
|
self.sock.send(req_msg.gen_msg())
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ class ModemATCommandLink(LinkBase):
|
|||||||
return
|
return
|
||||||
raise ReaderError('Interface \'%s\' does not respond to \'AT\' command' % self._device)
|
raise ReaderError('Interface \'%s\' does not respond to \'AT\' command' % self._device)
|
||||||
|
|
||||||
def reset_card(self):
|
def _reset_card(self):
|
||||||
# Reset the modem, just to be sure
|
# Reset the modem, just to be sure
|
||||||
if self.send_at_cmd('ATZ') != [b'OK']:
|
if self.send_at_cmd('ATZ') != [b'OK']:
|
||||||
raise ReaderError('Failed to reset the modem')
|
raise ReaderError('Failed to reset the modem')
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class PcscSimLink(LinkBase):
|
|||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
self._con.disconnect()
|
self._con.disconnect()
|
||||||
|
|
||||||
def reset_card(self):
|
def _reset_card(self):
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
self.connect()
|
self.connect()
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -101,15 +101,15 @@ class SerialSimLink(LinkBase):
|
|||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
pass # Nothing to do really ...
|
pass # Nothing to do really ...
|
||||||
|
|
||||||
def reset_card(self):
|
def _reset_card(self):
|
||||||
rv = self._reset_card()
|
rv = self.__reset_card()
|
||||||
if rv == 0:
|
if rv == 0:
|
||||||
raise NoCardError()
|
raise NoCardError()
|
||||||
if rv < 0:
|
if rv < 0:
|
||||||
raise ProtocolError()
|
raise ProtocolError()
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
def _reset_card(self):
|
def __reset_card(self):
|
||||||
self._atr = None
|
self._atr = None
|
||||||
rst_meth_map = {
|
rst_meth_map = {
|
||||||
'rts': self._sl.setRTS,
|
'rts': self._sl.setRTS,
|
||||||
|
|||||||
Reference in New Issue
Block a user