Browse Source

card: re-add capability to find USIM cards by ATR

de31d9f88b removes the ability to select
USIM cards by specifiying their ATR. This feature is needed to
properly distinguish symo-usim-sjs1 and sysmo-isim-sja2 from other
cards.
master
Philipp Maier 1 year ago
parent
commit
a767cec4d0
  1. 8
      card/ICC.py
  2. 4
      card/SIM.py
  3. 4
      card/USIM.py
  4. 2
      simcard.py

8
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()

4
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))

4
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:

2
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

Loading…
Cancel
Save