aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-01-21 16:06:50 +0100
committerHarald Welte <laforge@osmocom.org>2021-01-21 16:11:39 +0100
commitd49d0668dcfa69f830fd085b332e2153e4841c7b (patch)
tree78378d6a1c939034c1a8b4a9a7c194f2b9902461
parent14b2e2c9dbd826116cb5aab8d12981c1bf6c96f1 (diff)
commands.py: rename select_file() to select_path()
In reality, the function is not a simple avstraction around the SELECT command, but it iterates over a list/path and selects at each element. Change-Id: I63e01155de4ae47aeed8500708c0eb6580c7b8d1
-rw-r--r--pySim/cards.py54
-rw-r--r--pySim/commands.py20
2 files changed, 37 insertions, 37 deletions
diff --git a/pySim/cards.py b/pySim/cards.py
index 1d6cddb..ff2b1c1 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -45,7 +45,7 @@ class Card(object):
return
def file_exists(self, fid):
- res_arr = self._scc.try_select_file(fid)
+ res_arr = self._scc.try_select_path(fid)
for res in res_arr:
if res[1] != '9000':
return False
@@ -478,7 +478,7 @@ class _MagicSimBase(Card):
"""
f = self._files['name']
- r = self._scc.select_file(['3f00', '7f4d', f[0]])
+ r = self._scc.select_path(['3f00', '7f4d', f[0]])
rec_len = int(r[-1][28:30], 16)
tlen = int(r[-1][4:8],16)
rec_cnt = (tlen / rec_len) - 1
@@ -490,7 +490,7 @@ class _MagicSimBase(Card):
def program(self, p):
# Go to dir
- self._scc.select_file(['3f00', '7f4d'])
+ self._scc.select_path(['3f00', '7f4d'])
# Home PLMN in PLMN_Sel format
hplmn = enc_plmn(p['mcc'], p['mnc'])
@@ -534,7 +534,7 @@ class _MagicSimBase(Card):
# FIXME
# Write PLMN_Sel forcefully as well
- r = self._scc.select_file(['3f00', '7f20', '6f30'])
+ r = self._scc.select_path(['3f00', '7f20', '6f30'])
tl = int(r[-1][4:8], 16)
hplmn = enc_plmn(p['mcc'], p['mnc'])
@@ -608,7 +608,7 @@ class FakeMagicSim(Card):
and entry size
"""
- r = self._scc.select_file(['3f00', '000c'])
+ r = self._scc.select_path(['3f00', '000c'])
rec_len = int(r[-1][28:30], 16)
tlen = int(r[-1][4:8],16)
rec_cnt = (tlen / rec_len) - 1
@@ -620,7 +620,7 @@ class FakeMagicSim(Card):
def program(self, p):
# Home PLMN
- r = self._scc.select_file(['3f00', '7f20', '6f30'])
+ r = self._scc.select_path(['3f00', '7f20', '6f30'])
tl = int(r[-1][4:8], 16)
hplmn = enc_plmn(p['mcc'], p['mnc'])
@@ -675,11 +675,11 @@ class GrcardSim(Card):
self._scc.verify_chv(5, pin)
# EF.ICCID
- r = self._scc.select_file(['3f00', '2fe2'])
+ r = self._scc.select_path(['3f00', '2fe2'])
data, sw = self._scc.update_binary('2fe2', enc_iccid(p['iccid']))
# EF.IMSI
- r = self._scc.select_file(['3f00', '7f20', '6f07'])
+ r = self._scc.select_path(['3f00', '7f20', '6f07'])
data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
# EF.ACC
@@ -688,7 +688,7 @@ class GrcardSim(Card):
# EF.SMSP
if p.get('smsp'):
- r = self._scc.select_file(['3f00', '7f10', '6f42'])
+ r = self._scc.select_path(['3f00', '7f10', '6f42'])
data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 80))
# Set the Ki using proprietary command
@@ -696,13 +696,13 @@ class GrcardSim(Card):
data, sw = self._scc._tp.send_apdu(pdu)
# EF.HPLMN
- r = self._scc.select_file(['3f00', '7f20', '6f30'])
+ r = self._scc.select_path(['3f00', '7f20', '6f30'])
size = int(r[-1][4:8], 16)
hplmn = enc_plmn(p['mcc'], p['mnc'])
self._scc.update_binary('6f30', hplmn + 'ff' * (size-3))
# EF.SPN (Service Provider Name)
- r = self._scc.select_file(['3f00', '7f20', '6f30'])
+ r = self._scc.select_path(['3f00', '7f20', '6f30'])
size = int(r[-1][4:8], 16)
# FIXME
@@ -773,7 +773,7 @@ class SysmoSIMgr2(Card):
def program(self, p):
# select MF
- r = self._scc.select_file(['3f00'])
+ r = self._scc.select_path(['3f00'])
# authenticate as SUPER ADM using default key
self._scc.verify_chv(0x0b, h2b("3838383838383838"))
@@ -799,7 +799,7 @@ class SysmoSIMgr2(Card):
data, sw = self._scc.update_binary('2fe2', enc_iccid(p['iccid']))
# select DF_GSM
- r = self._scc.select_file(['7f20'])
+ r = self._scc.select_path(['7f20'])
# write EF.IMSI
data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
@@ -809,7 +809,7 @@ class SysmoSIMgr2(Card):
data, sw = self._scc.update_binary('6f78', lpad(p['acc'], 4))
# get size and write EF.HPLMN
- r = self._scc.select_file(['6f30'])
+ r = self._scc.select_path(['6f30'])
size = int(r[-1][4:8], 16)
hplmn = enc_plmn(p['mcc'], p['mnc'])
self._scc.update_binary('6f30', hplmn + 'ff' * (size-3))
@@ -821,7 +821,7 @@ class SysmoSIMgr2(Card):
data, sw = self._scc.update_binary('0001', p['ki'], 3)
# select DF_TELECOM
- r = self._scc.select_file(['3f00', '7f10'])
+ r = self._scc.select_path(['3f00', '7f10'])
# write EF.SMSP
if p.get('smsp'):
@@ -863,13 +863,13 @@ class SysmoUSIMSJS1(UsimCard):
self.verify_adm(h2b(p['pin_adm']))
# select MF
- r = self._scc.select_file(['3f00'])
+ r = self._scc.select_path(['3f00'])
# write EF.ICCID
data, sw = self._scc.update_binary('2fe2', enc_iccid(p['iccid']))
# select DF_GSM
- r = self._scc.select_file(['7f20'])
+ r = self._scc.select_path(['7f20'])
# set Ki in proprietary file
data, sw = self._scc.update_binary('00FF', p['ki'])
@@ -922,7 +922,7 @@ class SysmoUSIMSJS1(UsimCard):
# EF.SMSP
if p.get('smsp'):
- r = self._scc.select_file(['3f00', '7f10'])
+ r = self._scc.select_path(['3f00', '7f10'])
data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 104), force_len=True)
# EF.MSISDN
@@ -933,7 +933,7 @@ class SysmoUSIMSJS1(UsimCard):
msisdn = enc_msisdn(p['msisdn'])
data = 'ff' * 20 + msisdn + 'ff' * 2
- r = self._scc.select_file(['3f00', '7f10'])
+ r = self._scc.select_path(['3f00', '7f10'])
data, sw = self._scc.update_record('6F40', 1, data, force_len=True)
@@ -1107,12 +1107,12 @@ class OpenCellsSim(Card):
self._scc.verify_chv(0x0A, h2b(p['pin_adm']))
# select MF
- r = self._scc.select_file(['3f00'])
+ r = self._scc.select_path(['3f00'])
# write EF.ICCID
data, sw = self._scc.update_binary('2fe2', enc_iccid(p['iccid']))
- r = self._scc.select_file(['7ff0'])
+ r = self._scc.select_path(['7ff0'])
# set Ki in proprietary file
data, sw = self._scc.update_binary('FF02', p['ki'])
@@ -1121,7 +1121,7 @@ class OpenCellsSim(Card):
data, sw = self._scc.update_binary('FF01', p['opc'])
# select DF_GSM
- r = self._scc.select_file(['7f20'])
+ r = self._scc.select_path(['7f20'])
# write EF.IMSI
data, sw = self._scc.update_binary('6f07', enc_imsi(p['imsi']))
@@ -1270,7 +1270,7 @@ class SysmoISIMSJA2(UsimCard, IsimCard):
print("Warning: Programming of the ICCID is not implemented for this type of card.")
# select DF_GSM
- self._scc.select_file(['7f20'])
+ self._scc.select_path(['7f20'])
# write EF.IMSI
if p.get('imsi'):
@@ -1308,7 +1308,7 @@ class SysmoISIMSJA2(UsimCard, IsimCard):
# EF.SMSP
if p.get('smsp'):
- r = self._scc.select_file(['3f00', '7f10'])
+ r = self._scc.select_path(['3f00', '7f10'])
data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 104), force_len=True)
# EF.MSISDN
@@ -1319,7 +1319,7 @@ class SysmoISIMSJA2(UsimCard, IsimCard):
msisdn = enc_msisdn(p['msisdn'])
content = 'ff' * 20 + msisdn + 'ff' * 2
- r = self._scc.select_file(['3f00', '7f10'])
+ r = self._scc.select_path(['3f00', '7f10'])
data, sw = self._scc.update_record('6F40', 1, content, force_len=True)
# EF.ACC
@@ -1333,8 +1333,8 @@ class SysmoISIMSJA2(UsimCard, IsimCard):
# update EF-SIM_AUTH_KEY (and EF-USIM_AUTH_KEY_2G, which is
# hard linked to EF-USIM_AUTH_KEY)
- self._scc.select_file(['3f00'])
- self._scc.select_file(['a515'])
+ self._scc.select_path(['3f00'])
+ self._scc.select_path(['a515'])
if p.get('ki'):
self._scc.update_binary('6f20', p['ki'], 1)
if p.get('opc'):
diff --git a/pySim/commands.py b/pySim/commands.py
index 7b8ebec..6c253d1 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -100,7 +100,7 @@ class SimCardCommands(object):
def sel_ctrl(self, value):
self._sel_ctrl = value
- def try_select_file(self, dir_list):
+ def try_select_path(self, dir_list):
rv = []
if type(dir_list) is not list:
dir_list = [dir_list]
@@ -111,7 +111,7 @@ class SimCardCommands(object):
return rv
return rv
- def select_file(self, dir_list):
+ def select_path(self, dir_list):
rv = []
if type(dir_list) is not list:
dir_list = [dir_list]
@@ -125,7 +125,7 @@ class SimCardCommands(object):
return self._tp.send_apdu_checksw(self.cla_byte + "a4" + "0404" + aidlen + aid)
def read_binary(self, ef, length=None, offset=0):
- r = self.select_file(ef)
+ r = self.select_path(ef)
if len(r[-1]) == 0:
return (None, None)
if length is None:
@@ -143,7 +143,7 @@ class SimCardCommands(object):
return total_data, sw
def update_binary(self, ef, data, offset=0, verify=False):
- self.select_file(ef)
+ self.select_path(ef)
pdu = self.cla_byte + 'd6%04x%02x' % (offset, len(data) // 2) + data
res = self._tp.send_apdu_checksw(pdu)
if verify:
@@ -156,13 +156,13 @@ class SimCardCommands(object):
raise ValueError('Binary verification failed (expected %s, got %s)' % (data.lower(), res[0].lower()))
def read_record(self, ef, rec_no):
- r = self.select_file(ef)
+ r = self.select_path(ef)
rec_length = self.__record_len(r)
pdu = self.cla_byte + 'b2%02x04%02x' % (rec_no, rec_length)
return self._tp.send_apdu(pdu)
def update_record(self, ef, rec_no, data, force_len=False, verify=False):
- r = self.select_file(ef)
+ r = self.select_path(ef)
if not force_len:
rec_length = self.__record_len(r)
if (len(data) // 2 != rec_length):
@@ -181,21 +181,21 @@ class SimCardCommands(object):
raise ValueError('Record verification failed (expected %s, got %s)' % (data.lower(), res[0].lower()))
def record_size(self, ef):
- r = self.select_file(ef)
+ r = self.select_path(ef)
return self.__record_len(r)
def record_count(self, ef):
- r = self.select_file(ef)
+ r = self.select_path(ef)
return self.__len(r) // self.__record_len(r)
def binary_size(self, ef):
- r = self.select_file(ef)
+ r = self.select_path(ef)
return self.__len(r)
def run_gsm(self, rand):
if len(rand) != 32:
raise ValueError('Invalid rand')
- self.select_file(['3f00', '7f20'])
+ self.select_path(['3f00', '7f20'])
return self._tp.send_apdu(self.cla_byte + '88000010' + rand)
def reset_card(self):