mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-24 14:28:32 +03:00
python3 conversion: fix tabs and spaces inconsistency
Without that fix we have:
$ python3 pySim-read.py
File "pySim-read.py", line 135
try:
^
TabError: inconsistent use of tabs and spaces in indentation
The following command was used to do the conversion:
sed 's# #\t#g' -i $(find -name "*.py")
Then the remaining spaces spotted during the review were
addressed manually.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Change-Id: I83f76a8e9b6e36098f16552a0135a8c22dde545f
This commit is contained in:
@@ -130,7 +130,7 @@ def parse_options():
|
|||||||
)
|
)
|
||||||
parser.add_option("--acc", dest="acc",
|
parser.add_option("--acc", dest="acc",
|
||||||
help="Set ACC bits (Access Control Code). not all card types are supported",
|
help="Set ACC bits (Access Control Code). not all card types are supported",
|
||||||
)
|
)
|
||||||
parser.add_option("--read-imsi", dest="read_imsi", action="store_true",
|
parser.add_option("--read-imsi", dest="read_imsi", action="store_true",
|
||||||
help="Read the IMSI from the CARD", default=False
|
help="Read the IMSI from the CARD", default=False
|
||||||
)
|
)
|
||||||
@@ -176,8 +176,8 @@ def parse_options():
|
|||||||
print kls.name
|
print kls.name
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if options.probe:
|
if options.probe:
|
||||||
return options
|
return options
|
||||||
|
|
||||||
if options.source == 'csv':
|
if options.source == 'csv':
|
||||||
if (options.imsi is None) and (options.batch_mode is False) and (options.read_imsi is False) and (options.read_iccid is False):
|
if (options.imsi is None) and (options.batch_mode is False) and (options.read_imsi is False) and (options.read_iccid is False):
|
||||||
@@ -287,7 +287,7 @@ def gen_parameters(opts):
|
|||||||
iccid = (
|
iccid = (
|
||||||
'89' + # Common prefix (telecom)
|
'89' + # Common prefix (telecom)
|
||||||
cc_digits + # Country Code on 2/3 digits
|
cc_digits + # Country Code on 2/3 digits
|
||||||
plmn_digits # MCC/MNC on 5/6 digits
|
plmn_digits # MCC/MNC on 5/6 digits
|
||||||
)
|
)
|
||||||
|
|
||||||
ml = 18 - len(iccid)
|
ml = 18 - len(iccid)
|
||||||
@@ -399,14 +399,14 @@ def gen_parameters(opts):
|
|||||||
else:
|
else:
|
||||||
raise ValueError("PIN-ADM needs to be <=8 digits (ascii)")
|
raise ValueError("PIN-ADM needs to be <=8 digits (ascii)")
|
||||||
|
|
||||||
if opts.pin_adm_hex is not None:
|
if opts.pin_adm_hex is not None:
|
||||||
if len(opts.pin_adm_hex) == 16:
|
if len(opts.pin_adm_hex) == 16:
|
||||||
pin_adm = opts.pin_adm_hex
|
pin_adm = opts.pin_adm_hex
|
||||||
# Ensure that it's hex-encoded
|
# Ensure that it's hex-encoded
|
||||||
try:
|
try:
|
||||||
try_encode = h2b(pin_adm)
|
try_encode = h2b(pin_adm)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError("PIN-ADM needs to be hex encoded using this option")
|
raise ValueError("PIN-ADM needs to be hex encoded using this option")
|
||||||
else:
|
else:
|
||||||
raise ValueError("PIN-ADM needs to be exactly 16 digits (hex encoded)")
|
raise ValueError("PIN-ADM needs to be exactly 16 digits (hex encoded)")
|
||||||
|
|
||||||
@@ -462,8 +462,8 @@ def _read_params_csv(opts, iccid=None, imsi=None):
|
|||||||
cr.fieldnames = [ field.lower() for field in cr.fieldnames ]
|
cr.fieldnames = [ field.lower() for field in cr.fieldnames ]
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
if not 'iccid' in cr.fieldnames:
|
if not 'iccid' in cr.fieldnames:
|
||||||
raise Exception("CSV file in wrong format!")
|
raise Exception("CSV file in wrong format!")
|
||||||
for row in cr:
|
for row in cr:
|
||||||
if opts.num is not None and opts.read_iccid is False and opts.read_imsi is False:
|
if opts.num is not None and opts.read_iccid is False and opts.read_imsi is False:
|
||||||
if opts.num == i:
|
if opts.num == i:
|
||||||
@@ -726,7 +726,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
if opts.card_handler:
|
if opts.card_handler:
|
||||||
card_handler = card_handler_auto(sl, opts.card_handler)
|
card_handler = card_handler_auto(sl, opts.card_handler)
|
||||||
else:
|
else:
|
||||||
card_handler = card_handler(sl)
|
card_handler = card_handler(sl)
|
||||||
|
|
||||||
# Iterate
|
# Iterate
|
||||||
@@ -762,4 +762,3 @@ if __name__ == '__main__':
|
|||||||
sys.exit(rc)
|
sys.exit(rc)
|
||||||
|
|
||||||
first = False
|
first = False
|
||||||
|
|
||||||
|
|||||||
@@ -123,41 +123,41 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# EF.PLMNsel
|
# EF.PLMNsel
|
||||||
try:
|
try:
|
||||||
(res, sw) = scc.read_binary(EF['PLMNsel'])
|
(res, sw) = scc.read_binary(EF['PLMNsel'])
|
||||||
if sw == '9000':
|
if sw == '9000':
|
||||||
print("PLMNsel: %s" % (res))
|
print("PLMNsel: %s" % (res))
|
||||||
else:
|
else:
|
||||||
print("PLMNsel: Can't read, response code = %s" % (sw,))
|
print("PLMNsel: Can't read, response code = %s" % (sw,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "HPLMNAcT: Can't read file -- " + str(e)
|
print "HPLMNAcT: Can't read file -- " + str(e)
|
||||||
|
|
||||||
# EF.PLMNwAcT
|
# EF.PLMNwAcT
|
||||||
try:
|
try:
|
||||||
(res, sw) = scc.read_binary(EF['PLMNwAcT'])
|
(res, sw) = scc.read_binary(EF['PLMNwAcT'])
|
||||||
if sw == '9000':
|
if sw == '9000':
|
||||||
print("PLMNwAcT:\n%s" % (format_xplmn_w_act(res)))
|
print("PLMNwAcT:\n%s" % (format_xplmn_w_act(res)))
|
||||||
else:
|
else:
|
||||||
print("PLMNwAcT: Can't read, response code = %s" % (sw,))
|
print("PLMNwAcT: Can't read, response code = %s" % (sw,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "PLMNwAcT: Can't read file -- " + str(e)
|
print "PLMNwAcT: Can't read file -- " + str(e)
|
||||||
|
|
||||||
# EF.OPLMNwAcT
|
# EF.OPLMNwAcT
|
||||||
try:
|
try:
|
||||||
(res, sw) = scc.read_binary(EF['OPLMNwAcT'])
|
(res, sw) = scc.read_binary(EF['OPLMNwAcT'])
|
||||||
if sw == '9000':
|
if sw == '9000':
|
||||||
print("OPLMNwAcT:\n%s" % (format_xplmn_w_act(res)))
|
print("OPLMNwAcT:\n%s" % (format_xplmn_w_act(res)))
|
||||||
else:
|
else:
|
||||||
print("OPLMNwAcT: Can't read, response code = %s" % (sw,))
|
print("OPLMNwAcT: Can't read, response code = %s" % (sw,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "OPLMNwAcT: Can't read file -- " + str(e)
|
print "OPLMNwAcT: Can't read file -- " + str(e)
|
||||||
|
|
||||||
# EF.HPLMNAcT
|
# EF.HPLMNAcT
|
||||||
try:
|
try:
|
||||||
(res, sw) = scc.read_binary(EF['HPLMNAcT'])
|
(res, sw) = scc.read_binary(EF['HPLMNAcT'])
|
||||||
if sw == '9000':
|
if sw == '9000':
|
||||||
print("HPLMNAcT:\n%s" % (format_xplmn_w_act(res)))
|
print("HPLMNAcT:\n%s" % (format_xplmn_w_act(res)))
|
||||||
else:
|
else:
|
||||||
print("HPLMNAcT: Can't read, response code = %s" % (sw,))
|
print("HPLMNAcT: Can't read, response code = %s" % (sw,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "HPLMNAcT: Can't read file -- " + str(e)
|
print "HPLMNAcT: Can't read file -- " + str(e)
|
||||||
|
|
||||||
|
|||||||
100
pySim/cards.py
100
pySim/cards.py
@@ -85,11 +85,11 @@ class Card(object):
|
|||||||
|
|
||||||
def update_oplmn_act(self, mcc, mnc, access_tech='FFFF'):
|
def update_oplmn_act(self, mcc, mnc, access_tech='FFFF'):
|
||||||
"""
|
"""
|
||||||
See note in update_hplmn_act()
|
See note in update_hplmn_act()
|
||||||
"""
|
"""
|
||||||
# get size and write EF.OPLMNwAcT
|
# get size and write EF.OPLMNwAcT
|
||||||
data = self._scc.read_binary(EF['OPLMNwAcT'], length=None, offset=0)
|
data = self._scc.read_binary(EF['OPLMNwAcT'], length=None, offset=0)
|
||||||
size = len(data[0])/2
|
size = len(data[0])/2
|
||||||
hplmn = enc_plmn(mcc, mnc)
|
hplmn = enc_plmn(mcc, mnc)
|
||||||
content = hplmn + access_tech
|
content = hplmn + access_tech
|
||||||
data, sw = self._scc.update_binary(EF['OPLMNwAcT'], content + 'ffffff0000' * (size/5-1))
|
data, sw = self._scc.update_binary(EF['OPLMNwAcT'], content + 'ffffff0000' * (size/5-1))
|
||||||
@@ -97,19 +97,19 @@ class Card(object):
|
|||||||
|
|
||||||
def update_plmn_act(self, mcc, mnc, access_tech='FFFF'):
|
def update_plmn_act(self, mcc, mnc, access_tech='FFFF'):
|
||||||
"""
|
"""
|
||||||
See note in update_hplmn_act()
|
See note in update_hplmn_act()
|
||||||
"""
|
"""
|
||||||
# get size and write EF.PLMNwAcT
|
# get size and write EF.PLMNwAcT
|
||||||
data = self._scc.read_binary(EF['PLMNwAcT'], length=None, offset=0)
|
data = self._scc.read_binary(EF['PLMNwAcT'], length=None, offset=0)
|
||||||
size = len(data[0])/2
|
size = len(data[0])/2
|
||||||
hplmn = enc_plmn(mcc, mnc)
|
hplmn = enc_plmn(mcc, mnc)
|
||||||
content = hplmn + access_tech
|
content = hplmn + access_tech
|
||||||
data, sw = self._scc.update_binary(EF['PLMNwAcT'], content + 'ffffff0000' * (size/5-1))
|
data, sw = self._scc.update_binary(EF['PLMNwAcT'], content + 'ffffff0000' * (size/5-1))
|
||||||
return sw
|
return sw
|
||||||
|
|
||||||
def update_plmnsel(self, mcc, mnc):
|
def update_plmnsel(self, mcc, mnc):
|
||||||
data = self._scc.read_binary(EF['PLMNsel'], length=None, offset=0)
|
data = self._scc.read_binary(EF['PLMNsel'], length=None, offset=0)
|
||||||
size = len(data[0])/2
|
size = len(data[0])/2
|
||||||
hplmn = enc_plmn(mcc, mnc)
|
hplmn = enc_plmn(mcc, mnc)
|
||||||
data, sw = self._scc.update_binary(EF['PLMNsel'], hplmn + 'ff' * (size-3))
|
data, sw = self._scc.update_binary(EF['PLMNsel'], hplmn + 'ff' * (size-3))
|
||||||
return sw
|
return sw
|
||||||
@@ -119,16 +119,16 @@ class Card(object):
|
|||||||
return sw
|
return sw
|
||||||
|
|
||||||
def update_ad(self, mnc):
|
def update_ad(self, mnc):
|
||||||
#See also: 3GPP TS 31.102, chapter 4.2.18
|
#See also: 3GPP TS 31.102, chapter 4.2.18
|
||||||
mnclen = len(str(mnc))
|
mnclen = len(str(mnc))
|
||||||
if mnclen == 1:
|
if mnclen == 1:
|
||||||
mnclen = 2
|
mnclen = 2
|
||||||
if mnclen > 3:
|
if mnclen > 3:
|
||||||
raise RuntimeError('unable to calculate proper mnclen')
|
raise RuntimeError('unable to calculate proper mnclen')
|
||||||
|
|
||||||
data = self._scc.read_binary(EF['AD'], length=None, offset=0)
|
data = self._scc.read_binary(EF['AD'], length=None, offset=0)
|
||||||
size = len(data[0])/2
|
size = len(data[0])/2
|
||||||
content = data[0][0:6] + "%02X" % mnclen
|
content = data[0][0:6] + "%02X" % mnclen
|
||||||
data, sw = self._scc.update_binary(EF['AD'], content)
|
data, sw = self._scc.update_binary(EF['AD'], content)
|
||||||
return sw
|
return sw
|
||||||
|
|
||||||
@@ -394,7 +394,7 @@ class GrcardSim(Card):
|
|||||||
data, sw = self._scc.update_binary('6f78', lpad(p['acc'], 4))
|
data, sw = self._scc.update_binary('6f78', lpad(p['acc'], 4))
|
||||||
|
|
||||||
# EF.SMSP
|
# EF.SMSP
|
||||||
if p.get('smsp'):
|
if p.get('smsp'):
|
||||||
r = self._scc.select_file(['3f00', '7f10', '6f42'])
|
r = self._scc.select_file(['3f00', '7f10', '6f42'])
|
||||||
data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 80))
|
data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 80))
|
||||||
|
|
||||||
@@ -426,7 +426,7 @@ class SysmoSIMgr1(GrcardSim):
|
|||||||
"""
|
"""
|
||||||
name = 'sysmosim-gr1'
|
name = 'sysmosim-gr1'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def autodetect(kls, scc):
|
def autodetect(kls, scc):
|
||||||
try:
|
try:
|
||||||
# Look for ATR
|
# Look for ATR
|
||||||
@@ -536,7 +536,7 @@ class SysmoSIMgr2(Card):
|
|||||||
r = self._scc.select_file(['3f00', '7f10'])
|
r = self._scc.select_file(['3f00', '7f10'])
|
||||||
|
|
||||||
# write EF.SMSP
|
# write EF.SMSP
|
||||||
if p.get('smsp'):
|
if p.get('smsp'):
|
||||||
data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 80))
|
data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 80))
|
||||||
|
|
||||||
def erase(self):
|
def erase(self):
|
||||||
@@ -592,25 +592,25 @@ class SysmoUSIMSJS1(Card):
|
|||||||
data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
|
data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
|
||||||
|
|
||||||
# EF.PLMNsel
|
# EF.PLMNsel
|
||||||
if p.get('mcc') and p.get('mnc'):
|
if p.get('mcc') and p.get('mnc'):
|
||||||
sw = self.update_plmnsel(p['mcc'], p['mnc'])
|
sw = self.update_plmnsel(p['mcc'], p['mnc'])
|
||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
print("Programming PLMNsel failed with code %s"%sw)
|
print("Programming PLMNsel failed with code %s"%sw)
|
||||||
|
|
||||||
# EF.PLMNwAcT
|
# EF.PLMNwAcT
|
||||||
if p.get('mcc') and p.get('mnc'):
|
if p.get('mcc') and p.get('mnc'):
|
||||||
sw = self.update_plmn_act(p['mcc'], p['mnc'])
|
sw = self.update_plmn_act(p['mcc'], p['mnc'])
|
||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
print("Programming PLMNwAcT failed with code %s"%sw)
|
print("Programming PLMNwAcT failed with code %s"%sw)
|
||||||
|
|
||||||
# EF.OPLMNwAcT
|
# EF.OPLMNwAcT
|
||||||
if p.get('mcc') and p.get('mnc'):
|
if p.get('mcc') and p.get('mnc'):
|
||||||
sw = self.update_oplmn_act(p['mcc'], p['mnc'])
|
sw = self.update_oplmn_act(p['mcc'], p['mnc'])
|
||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
print("Programming OPLMNwAcT failed with code %s"%sw)
|
print("Programming OPLMNwAcT failed with code %s"%sw)
|
||||||
|
|
||||||
# EF.AD
|
# EF.AD
|
||||||
if p.get('mcc') and p.get('mnc'):
|
if p.get('mcc') and p.get('mnc'):
|
||||||
sw = self.update_ad(p['mnc'])
|
sw = self.update_ad(p['mnc'])
|
||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
print("Programming AD failed with code %s"%sw)
|
print("Programming AD failed with code %s"%sw)
|
||||||
@@ -848,28 +848,28 @@ class WavemobileSim(Card):
|
|||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
raise RuntimeError('Failed to authenticate with ADM key %s'%(p['pin_adm'],))
|
raise RuntimeError('Failed to authenticate with ADM key %s'%(p['pin_adm'],))
|
||||||
|
|
||||||
# EF.ICCID
|
# EF.ICCID
|
||||||
# TODO: Add programming of the ICCID
|
# TODO: Add programming of the ICCID
|
||||||
if p.get('iccid'):
|
if p.get('iccid'):
|
||||||
print("Warning: Programming of the ICCID is not implemented for this type of card.")
|
print("Warning: Programming of the ICCID is not implemented for this type of card.")
|
||||||
|
|
||||||
# KI (Presumably a propritary file)
|
# KI (Presumably a propritary file)
|
||||||
# TODO: Add programming of KI
|
# TODO: Add programming of KI
|
||||||
if p.get('ki'):
|
if p.get('ki'):
|
||||||
print("Warning: Programming of the KI is not implemented for this type of card.")
|
print("Warning: Programming of the KI is not implemented for this type of card.")
|
||||||
|
|
||||||
# OPc (Presumably a propritary file)
|
# OPc (Presumably a propritary file)
|
||||||
# TODO: Add programming of OPc
|
# TODO: Add programming of OPc
|
||||||
if p.get('opc'):
|
if p.get('opc'):
|
||||||
print("Warning: Programming of the OPc is not implemented for this type of card.")
|
print("Warning: Programming of the OPc is not implemented for this type of card.")
|
||||||
|
|
||||||
# EF.SMSP
|
# EF.SMSP
|
||||||
if p.get('smsp'):
|
if p.get('smsp'):
|
||||||
sw = self.update_smsp(p['smsp'])
|
sw = self.update_smsp(p['smsp'])
|
||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
print("Programming SMSP failed with code %s"%sw)
|
print("Programming SMSP failed with code %s"%sw)
|
||||||
|
|
||||||
# EF.IMSI
|
# EF.IMSI
|
||||||
if p.get('imsi'):
|
if p.get('imsi'):
|
||||||
sw = self.update_imsi(p['imsi'])
|
sw = self.update_imsi(p['imsi'])
|
||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
@@ -882,30 +882,30 @@ class WavemobileSim(Card):
|
|||||||
print("Programming ACC failed with code %s"%sw)
|
print("Programming ACC failed with code %s"%sw)
|
||||||
|
|
||||||
# EF.PLMNsel
|
# EF.PLMNsel
|
||||||
if p.get('mcc') and p.get('mnc'):
|
if p.get('mcc') and p.get('mnc'):
|
||||||
sw = self.update_plmnsel(p['mcc'], p['mnc'])
|
sw = self.update_plmnsel(p['mcc'], p['mnc'])
|
||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
print("Programming PLMNsel failed with code %s"%sw)
|
print("Programming PLMNsel failed with code %s"%sw)
|
||||||
|
|
||||||
# EF.PLMNwAcT
|
# EF.PLMNwAcT
|
||||||
if p.get('mcc') and p.get('mnc'):
|
if p.get('mcc') and p.get('mnc'):
|
||||||
sw = self.update_plmn_act(p['mcc'], p['mnc'])
|
sw = self.update_plmn_act(p['mcc'], p['mnc'])
|
||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
print("Programming PLMNwAcT failed with code %s"%sw)
|
print("Programming PLMNwAcT failed with code %s"%sw)
|
||||||
|
|
||||||
# EF.OPLMNwAcT
|
# EF.OPLMNwAcT
|
||||||
if p.get('mcc') and p.get('mnc'):
|
if p.get('mcc') and p.get('mnc'):
|
||||||
sw = self.update_oplmn_act(p['mcc'], p['mnc'])
|
sw = self.update_oplmn_act(p['mcc'], p['mnc'])
|
||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
print("Programming OPLMNwAcT failed with code %s"%sw)
|
print("Programming OPLMNwAcT failed with code %s"%sw)
|
||||||
|
|
||||||
# EF.AD
|
# EF.AD
|
||||||
if p.get('mcc') and p.get('mnc'):
|
if p.get('mcc') and p.get('mnc'):
|
||||||
sw = self.update_ad(p['mnc'])
|
sw = self.update_ad(p['mnc'])
|
||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
print("Programming AD failed with code %s"%sw)
|
print("Programming AD failed with code %s"%sw)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def erase(self):
|
def erase(self):
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class SimCardCommands(object):
|
|||||||
def __get_len_from_tlv(self, fcp):
|
def __get_len_from_tlv(self, fcp):
|
||||||
# see also: ETSI TS 102 221, chapter 11.1.1.3.1 Response for MF,
|
# see also: ETSI TS 102 221, chapter 11.1.1.3.1 Response for MF,
|
||||||
# DF or ADF
|
# DF or ADF
|
||||||
from pytlv.TLV import TLV
|
from pytlv.TLV import TLV
|
||||||
tlvparser = TLV(['82', '83', '84', 'a5', '8a', '8b', '8c', '80', 'ab', 'c6', '81', '88'])
|
tlvparser = TLV(['82', '83', '84', 'a5', '8a', '8b', '8c', '80', 'ab', 'c6', '81', '88'])
|
||||||
|
|
||||||
# pytlv is case sensitive!
|
# pytlv is case sensitive!
|
||||||
@@ -62,24 +62,24 @@ class SimCardCommands(object):
|
|||||||
|
|
||||||
return int(tlv_parsed['80'], 16)
|
return int(tlv_parsed['80'], 16)
|
||||||
|
|
||||||
# Tell the length of a record by the card response
|
# Tell the length of a record by the card response
|
||||||
# USIMs respond with an FCP template, which is different
|
# USIMs respond with an FCP template, which is different
|
||||||
# from what SIMs responds. See also:
|
# from what SIMs responds. See also:
|
||||||
# USIM: ETSI TS 102 221, chapter 11.1.1.3 Response Data
|
# USIM: ETSI TS 102 221, chapter 11.1.1.3 Response Data
|
||||||
# SIM: GSM 11.11, chapter 9.2.1 SELECT
|
# SIM: GSM 11.11, chapter 9.2.1 SELECT
|
||||||
def __record_len(self, r):
|
def __record_len(self, r):
|
||||||
if self.sel_ctrl == "0004":
|
if self.sel_ctrl == "0004":
|
||||||
return self.__get_len_from_tlv(r[-1])
|
return self.__get_len_from_tlv(r[-1])
|
||||||
else:
|
else:
|
||||||
return int(r[-1][28:30], 16)
|
return int(r[-1][28:30], 16)
|
||||||
|
|
||||||
# Tell the length of a binary file. See also comment
|
# Tell the length of a binary file. See also comment
|
||||||
# above.
|
# above.
|
||||||
def __len(self, r):
|
def __len(self, r):
|
||||||
if self.sel_ctrl == "0004":
|
if self.sel_ctrl == "0004":
|
||||||
return self.__get_len_from_tlv(r[-1])
|
return self.__get_len_from_tlv(r[-1])
|
||||||
else:
|
else:
|
||||||
return int(r[-1][4:8], 16)
|
return int(r[-1][4:8], 16)
|
||||||
|
|
||||||
def get_atr(self):
|
def get_atr(self):
|
||||||
return self._tp.get_atr()
|
return self._tp.get_atr()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class LinkBase(object):
|
|||||||
|
|
||||||
timeout : Maximum wait time (None=no timeout)
|
timeout : Maximum wait time (None=no timeout)
|
||||||
newcardonly : Should we wait for a new card, or an already
|
newcardonly : Should we wait for a new card, or an already
|
||||||
inserted one ?
|
inserted one ?
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -52,8 +52,8 @@ class LinkBase(object):
|
|||||||
|
|
||||||
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
|
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
|
||||||
return : tuple(data, sw), where
|
return : tuple(data, sw), where
|
||||||
data : string (in hex) of returned data (ex. "074F4EFFFF")
|
data : string (in hex) of returned data (ex. "074F4EFFFF")
|
||||||
sw : string (in hex) of status word (ex. "9000")
|
sw : string (in hex) of status word (ex. "9000")
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -62,8 +62,8 @@ class LinkBase(object):
|
|||||||
|
|
||||||
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
|
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
|
||||||
return : tuple(data, sw), where
|
return : tuple(data, sw), where
|
||||||
data : string (in hex) of returned data (ex. "074F4EFFFF")
|
data : string (in hex) of returned data (ex. "074F4EFFFF")
|
||||||
sw : string (in hex) of status word (ex. "9000")
|
sw : string (in hex) of status word (ex. "9000")
|
||||||
"""
|
"""
|
||||||
data, sw = self.send_apdu_raw(pdu)
|
data, sw = self.send_apdu_raw(pdu)
|
||||||
|
|
||||||
@@ -84,15 +84,15 @@ class LinkBase(object):
|
|||||||
|
|
||||||
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
|
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
|
||||||
sw : string of 4 hexadecimal characters (ex. "9000"). The
|
sw : string of 4 hexadecimal characters (ex. "9000"). The
|
||||||
user may mask out certain digits using a '?' to add some
|
user may mask out certain digits using a '?' to add some
|
||||||
ambiguity if needed.
|
ambiguity if needed.
|
||||||
return : tuple(data, sw), where
|
return : tuple(data, sw), where
|
||||||
data : string (in hex) of returned data (ex. "074F4EFFFF")
|
data : string (in hex) of returned data (ex. "074F4EFFFF")
|
||||||
sw : string (in hex) of status word (ex. "9000")
|
sw : string (in hex) of status word (ex. "9000")
|
||||||
"""
|
"""
|
||||||
rv = self.send_apdu(pdu)
|
rv = self.send_apdu(pdu)
|
||||||
|
|
||||||
# Create a masked version of the returned status word
|
# Create a masked version of the returned status word
|
||||||
sw_masked = ""
|
sw_masked = ""
|
||||||
for i in range(0, 4):
|
for i in range(0, 4):
|
||||||
if sw.lower()[i] == '?':
|
if sw.lower()[i] == '?':
|
||||||
|
|||||||
Reference in New Issue
Block a user