From a42ee6f99d1cb1e8b3f4c58379291224c0ce4309 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Wed, 16 Aug 2023 10:44:57 +0200 Subject: [PATCH] cards: get rid of method read_iccid The method read_iccid in class CardBase should be put back to legacy/cards.py. The reason for this is that it falls in the same category like read_imsi, read_ki, etc. We should not use those old methods in future programs since we have a more modern infrastructure (lchan) now. Also pySim-shell.py is the only caller of this method now. It is not used in any other place. Related: RT#67094 Change-Id: Ied3ae6fd107992abcc1b5ea3edb0eb4bdcd2f892 --- pySim-shell.py | 7 +++++-- pySim/cards.py | 10 +--------- pySim/legacy/cards.py | 7 +++++++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pySim-shell.py b/pySim-shell.py index 2727a5b8..af7dbca3 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -52,7 +52,7 @@ from pySim.commands import SimCardCommands from pySim.transport import init_reader, ApduTracer, argparse_add_reader_args, ProactiveHandler from pySim.cards import card_detect, SimCardBase, UiccCardBase from pySim.utils import h2b, b2h, i2h, swap_nibbles, rpad, JsonEncoder, bertlv_parse_one, sw_match -from pySim.utils import sanitize_pin_adm, tabulate_str_list, boxed_heading_str, Hexstr +from pySim.utils import sanitize_pin_adm, tabulate_str_list, boxed_heading_str, Hexstr, dec_iccid from pySim.card_handler import CardHandler, CardHandlerAuto from pySim.filesystem import CardDF, CardADF, CardModel, CardApplication @@ -240,7 +240,10 @@ class PysimApp(Cmd2Compat): self.register_command_set(Iso7816Commands()) self.register_command_set(Ts102222Commands()) self.register_command_set(PySimCommands()) - self.iccid, sw = self.card.read_iccid() + + self.lchan.select('MF/EF.ICCID', self) + self.iccid = dec_iccid(self.lchan.read_binary()[0]) + self.lchan.select('MF', self) rc = True else: diff --git a/pySim/cards.py b/pySim/cards.py index c87c488f..b1adcf22 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -23,7 +23,7 @@ # from typing import Optional, Dict, Tuple -from pySim.ts_102_221 import EF_DIR, EF_ICCID +from pySim.ts_102_221 import EF_DIR from pySim.ts_51_011 import DF_GSM from pySim.transport import LinkBase import abc @@ -69,14 +69,6 @@ class CardBase: # callers having to do hasattr('read_aids') ahead of every call. return [] - def read_iccid(self) -> Tuple[Optional[Hexstr], SwHexstr]: - ef_iccid = EF_ICCID() - (res, sw) = self._scc.read_binary(ef_iccid.fid) - if sw == '9000': - return (dec_iccid(res), sw) - else: - return (None, sw) - class SimCardBase(CardBase): """Here we only add methods for commands specified in TS 51.011, without diff --git a/pySim/legacy/cards.py b/pySim/legacy/cards.py index e64b5c32..496ce780 100644 --- a/pySim/legacy/cards.py +++ b/pySim/legacy/cards.py @@ -59,6 +59,13 @@ class SimCard(SimCardBase): (res, sw) = self._scc.verify_chv(self._adm_chv_num, key) return sw + def read_iccid(self): + (res, sw) = self._scc.read_binary(EF['ICCID']) + if sw == '9000': + return (dec_iccid(res), sw) + else: + return (None, sw) + def update_iccid(self, iccid): data, sw = self._scc.update_binary(EF['ICCID'], enc_iccid(iccid)) return sw