This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Alexander Chemeris gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/5717 Add methods to get ATR for a card or a link. Implemented for both serial and PCSC readers. Change-Id: Ic12e4b115d24a8b7e483a5603dd6cec90ad289cc --- M pySim/commands.py M pySim/transport/pcsc.py M pySim/transport/serial.py 3 files changed, 19 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/17/5717/1 diff --git a/pySim/commands.py b/pySim/commands.py index 777dd24..eba915c 100644 --- a/pySim/commands.py +++ b/pySim/commands.py @@ -31,6 +31,9 @@ self._cla_byte = "a0" self.sel_ctrl = "0000" + def get_atr(self): + return self._tp.get_atr() + @property def cla_byte(self): return self._cla_byte diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py index dc040c5..47c4185 100644 --- a/pySim/transport/pcsc.py +++ b/pySim/transport/pcsc.py @@ -56,6 +56,9 @@ except NoCardException: raise NoCardError() + def get_atr(self): + return self._con.getATR() + def disconnect(self): self._con.disconnect() diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py index 825c458..c0b5b54 100644 --- a/pySim/transport/serial.py +++ b/pySim/transport/serial.py @@ -46,6 +46,7 @@ ) self._rst_pin = rst self._debug = debug + self._atr = None def __del__(self): self._sl.close() @@ -90,6 +91,9 @@ def connect(self): self.reset_card() + + def get_atr(self): + return self._atr def disconnect(self): pass # Nothing to do really ... @@ -102,6 +106,7 @@ raise ProtocolError() def _reset_card(self): + self._atr = None rst_meth_map = { 'rts': self._sl.setRTS, 'dtr': self._sl.setDTR, @@ -133,18 +138,24 @@ return -1 t0 = ord(b) self._dbg_print("T0: 0x%x" % t0) + self._atr = [0x3b, ord(b)] for i in range(4): if t0 & (0x10 << i): - self._dbg_print("T%si = %x" % (chr(ord('A')+i), ord(self._rx_byte()))) + b = self._rx_byte() + self._atr.apend(ord(b)) + self._dbg_print("T%si = %x" % (chr(ord('A')+i), ord(b))) for i in range(0, t0 & 0xf): - self._dbg_print("Historical = %x" % ord(self._rx_byte())) + b = self._rx_byte() + self._atr.apend(ord(b)) + self._dbg_print("Historical = %x" % ord(b)) while True: x = self._rx_byte() if not x: break + self._atr.apend(ord(x)) self._dbg_print("Extra: %x" % ord(x)) return 1 -- To view, visit https://gerrit.osmocom.org/5717 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic12e4b115d24a8b7e483a5603dd6cec90ad289cc Gerrit-PatchSet: 1 Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Owner: Alexander Chemeris <Alexander.Chemeris at gmail.com>