diff --git a/card/ICC.py b/card/ICC.py index 9a0d7ec..f6ba844 100644 --- a/card/ICC.py +++ b/card/ICC.py @@ -35,6 +35,7 @@ import re # smartcard python modules from pyscard from smartcard.CardType import AnyCardType +from smartcard.CardType import ATRCardType from smartcard.CardRequest import CardRequest from smartcard.CardConnection import CardConnection from smartcard.ATR import ATR @@ -141,7 +142,7 @@ class ISO7816(object): 0xAB : 'Security Attribute expanded', } - def __init__(self, CLA=0x00): + def __init__(self, atr=None, CLA=0x00): """ connect smartcard and defines class CLA code for communication uses "pyscard" library services @@ -149,7 +150,10 @@ class ISO7816(object): creates self.CLA attribute with CLA code and self.coms attribute with associated "apdu_stack" instance """ - cardtype = AnyCardType() + if (atr): + cardtype = ATRCardType(atr) + else: + cardtype = AnyCardType() cardrequest = CardRequest(timeout=1, cardType=cardtype) self.cardservice = cardrequest.waitforcard() self.cardservice.connection.connect() diff --git a/card/SIM.py b/card/SIM.py index 2e6c9c7..ad81dae 100644 --- a/card/SIM.py +++ b/card/SIM.py @@ -100,12 +100,12 @@ class SIM(ISO7816): use self.dbg = 1 or more to print live debugging information """ - def __init__(self): + def __init__(self, atr = None): """ initialize like an ISO7816-4 card with CLA=0xA0 can also be used for USIM working in SIM mode, """ - ISO7816.__init__(self, CLA=0xA0) + ISO7816.__init__(self, atr, CLA=0xA0) if self.dbg >= 2: log(3, '(SIM.__init__) type definition: %s' % type(self)) diff --git a/card/USIM.py b/card/USIM.py index ce1a62e..fd554af 100644 --- a/card/USIM.py +++ b/card/USIM.py @@ -177,7 +177,7 @@ class USIM(UICC): use self.dbg = 1 or more to print live debugging information """ - def __init__(self): + def __init__(self, atr = None): """ initializes like an ISO7816-4 card with CLA=0x00 and checks available AID (Application ID) read from EF_DIR @@ -185,7 +185,7 @@ class USIM(UICC): initializes on the MF """ # initialize like a UICC - ISO7816.__init__(self, CLA=0x00) + ISO7816.__init__(self, atr, CLA=0x00) self.AID = [] if self.dbg >= 2: diff --git a/simcard.py b/simcard.py index 6f83c44..4d8b7fe 100644 --- a/simcard.py +++ b/simcard.py @@ -85,7 +85,7 @@ class Simcard(): # Constructor: Create a new simcard object def __init__(self, cardtype = GSM_USIM, atr = None): if cardtype == GSM_USIM: - self.card = USIM() + self.card = USIM(atr) self.usim = True # Detect ISIM / USIM applications