ccid.py should not stop when an error occurs

This commit is contained in:
Christina Quast
2015-03-10 17:58:54 +01:00
parent 32a90ac660
commit dba7b16b98

View File

@@ -1,4 +1,5 @@
import sys import sys
import traceback
from pySim.commands import SimCardCommands from pySim.commands import SimCardCommands
from pySim.utils import h2b, swap_nibbles, rpad, dec_imsi, dec_iccid from pySim.utils import h2b, swap_nibbles, rpad, dec_imsi, dec_iccid
@@ -19,55 +20,74 @@ def pySim_read():
print("Reading ...") print("Reading ...")
# EF.ICCID # EF.ICCID
(res, sw) = scc.read_binary(['3f00', '2fe2']) try:
if sw == '9000': (res, sw) = scc.read_binary(['3f00', '2fe2'])
print("ICCID: %s" % (dec_iccid(res),)) if sw == '9000':
else: print("ICCID: %s" % (dec_iccid(res),))
print("ICCID: Can't read, response code = %s" % (sw,)) else:
print("ICCID: Can't read, response code = %s" % (sw,))
except:
print("Unexpected error:", sys.exc_info()[0])
print(traceback.format_exc())
# EF.IMSI # EF.IMSI
(res, sw) = scc.read_binary(['3f00', '7f20', '6f07']) try:
if sw == '9000': (res, sw) = scc.read_binary(['3f00', '7f20', '6f07'])
print("IMSI: %s" % (dec_imsi(res),)) if sw == '9000':
else: print("IMSI: %s" % (dec_imsi(res),))
print("IMSI: Can't read, response code = %s" % (sw,)) else:
print("IMSI: Can't read, response code = %s" % (sw,))
except:
print("Unexpected error:", sys.exc_info()[0])
print(traceback.format_exc())
# EF.SMSP # EF.SMSP
(res, sw) = scc.read_record(['3f00', '7f10', '6f42'], 1) try:
if sw == '9000': (res, sw) = scc.read_record(['3f00', '7f10', '6f42'], 1)
print("SMSP: %s" % (res,)) if sw == '9000':
else: print("SMSP: %s" % (res,))
print("SMSP: Can't read, response code = %s" % (sw,)) else:
print("SMSP: Can't read, response code = %s" % (sw,))
except:
print("Unexpected error:", sys.exc_info()[0])
print(traceback.format_exc())
# EF.HPLMN # EF.HPLMN
# (res, sw) = scc.read_binary(['3f00', '7f20', '6f30']) try:
# if sw == '9000': (res, sw) = scc.read_binary(['3f00', '7f20', '6f30'])
# print("HPLMN: %s" % (res)) if sw == '9000':
# print("HPLMN: %s" % (dec_hplmn(res),)) print("HPLMN: %s" % (res))
# else: print("HPLMN: %s" % (dec_hplmn(res),))
# print("HPLMN: Can't read, response code = %s" % (sw,)) else:
# FIXME print("HPLMN: Can't read, response code = %s" % (sw,))
except:
print("Unexpected error:", sys.exc_info()[0])
print(traceback.format_exc())
# EF.ACC # EF.ACC
(res, sw) = scc.read_binary(['3f00', '7f20', '6f78']) try:
if sw == '9000': (res, sw) = scc.read_binary(['3f00', '7f20', '6f78'])
print("ACC: %s" % (res,)) if sw == '9000':
else: print("ACC: %s" % (res,))
print("ACC: Can't read, response code = %s" % (sw,)) else:
print("ACC: Can't read, response code = %s" % (sw,))
except:
print("Unexpected error:", sys.exc_info()[0])
print(traceback.format_exc())
# EF.MSISDN # EF.MSISDN
try: try:
# print(scc.record_size(['3f00', '7f10', '6f40'])) # print(scc.record_size(['3f00', '7f10', '6f40']))
(res, sw) = scc.read_record(['3f00', '7f10', '6f40'], 1) (res, sw) = scc.read_record(['3f00', '7f10', '6f40'], 1)
if sw == '9000': if sw == '9000':
if res[1] != 'f': if res[1] != 'f':
print("MSISDN: %s" % (res,)) print("MSISDN: %s" % (res,))
else:
print("MSISDN: Not available")
else: else:
print("MSISDN: Can't read, response code = %s" % (sw,)) print("MSISDN: Not available")
else:
print("MSISDN: Can't read, response code = %s" % (sw,))
except: except:
prin#t("MSISDN: Can't read. Probably not existing file") print("MSISDN: Can't read. Probably not existing file, error: ", sys.exc_info()[0])
print(traceback.format_exc())
# Done for this card and maybe for everything ?
print("Done !\n") print("Done !\n")