Skip to content

Commit dc177e9

Browse files
committed
add routine for selecting ISIM and normalize AID handling
1 parent 65f813c commit dc177e9

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

card/USIM.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ def __init__(self, reader=''):
186186
"""
187187
# initialize like a UICC
188188
ISO7816.__init__(self, CLA=0x00, reader=reader)
189-
self.AID = []
189+
self.AID = []
190+
self.AID_GP = {}
191+
self.AID_USIM = None
192+
self.AID_ISIM = None
190193
#
191194
if self.dbg >= 2:
192195
log(3, '(UICC.__init__) type definition: %s' % type(self))
@@ -195,20 +198,48 @@ def __init__(self, reader=''):
195198
self.SELECT_ADF_USIM()
196199

197200
def SELECT_ADF_USIM(self):
201+
"""
202+
selects the USIM AID
203+
204+
returns True if the USIM AID exists, False otherwise
205+
may print an error in case the USIM AID selection fails
206+
"""
198207
# USIM selection from AID
199-
if self.dbg:
200-
log(3, '(USIM.__init__) UICC AID found:')
201208
self.get_AID()
202209
for aid in self.AID:
203210
if tuple(aid[0:5]) == (0xA0, 0x00, 0x00, 0x00, 0x87) \
204211
and tuple(aid[5:7]) == (0x10, 0x02) :
205212
usim = self.select(addr=aid, type='aid')
206213
if usim is None and self.dbg:
207-
log(2, '(USIM.__init__) USIM AID selection failed')
208-
if usim is not None:
209-
self.USIM_AID = aid
214+
log(2, '(USIM.SELECT_ADF_USIM) USIM AID selection failed')
215+
elif usim is not None:
216+
self.AID_USIM = aid
210217
if self.dbg >= 2:
211-
log(3, '(USIM.__init__) USIM AID selection succeeded\n')
218+
log(3, '(USIM.SELECT_ADF_USIM) USIM AID selection succeeded\n')
219+
return True
220+
return False
221+
222+
def SELECT_ADF_ISIM(self):
223+
"""
224+
selects the ISIM AID
225+
226+
returns True if the ISIM AID exists, False otherwise
227+
may print an error in case the ISIM AID selection fails
228+
"""
229+
# ISIM selection from AID
230+
self.get_AID()
231+
for aid in self.AID:
232+
if tuple(aid[0:5]) == (0xA0, 0x00, 0x00, 0x00, 0x87) \
233+
and tuple(aid[5:7]) == (0x10, 0x04) :
234+
isim = self.select(addr=aid, type='aid')
235+
if isim is None and self.dbg:
236+
log(2, '(ISIM.SELECT_ADF_ISIM) ISIM AID selection failed')
237+
elif isim is not None:
238+
self.AID_ISIM = aid
239+
if self.dbg >= 3:
240+
log(3, '(ISIM.SELECT_ADF_ISIM) ISIM AID selection succeeded\n')
241+
return True
242+
return False
212243

213244
@staticmethod
214245
def sw_status(sw1, sw2):
@@ -560,11 +591,11 @@ def explore_fs(self, filename='usim_fs.txt', depth=2):
560591
write information on existing DF and file in the output file
561592
"""
562593
usimfs_entries = USIM_app_FS.keys()
563-
self.explore_DF([], self.AID.index(self.USIM_AID)+1, depth)
594+
self.explore_DF([], self.AID.index(self.AID_USIM) + 1, depth)
564595

565596
fd = open(filename, 'w')
566-
fd.write('\n### AID %s ###\n' % self.USIM_AID)
567-
f = self.select_by_aid( self.AID.index(self.USIM_AID)+1 )
597+
fd.write('\n### AID %s ###\n' % self.AID_USIM)
598+
f = self.select_by_aid( self.AID.index(self.AID_USIM) + 1 )
568599
write_dict(f, fd)
569600
fd.write('\n')
570601
#

0 commit comments

Comments
 (0)