mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-25 06:48:33 +03:00
fileystem: fix ADF selection
When the ADF is selected, then this is done by the AID. At the moment only the first 7 bytes of the AID are used to select the ADF. sysmo-isim-sja2 tolerates this, but sysmo-usim-sjs1 does not. The Cards class already has methods to deal with this problem. The method select_adf_by_aid takes an ADF name and completes the AID from an internal list. This can be extended to support partial hexadecimal AIDs as well. Change-Id: If99b143ae5ff42a889c52e8023084692e709e1b1 Related: OS#4963
This commit is contained in:
committed by
Harald Welte
parent
ad073e834a
commit
cba6dbce9a
@@ -251,7 +251,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# Check whether we have th AID of USIM, if so select it by its AID
|
# Check whether we have th AID of USIM, if so select it by its AID
|
||||||
# EF.UST - File Id in ADF USIM : 6f38
|
# EF.UST - File Id in ADF USIM : 6f38
|
||||||
if '9000' == card.select_adf_by_aid():
|
data, sw = card.select_adf_by_aid(adf="usim")
|
||||||
|
if sw == '9000':
|
||||||
# Select USIM profile
|
# Select USIM profile
|
||||||
usim_card = UsimCard(scc)
|
usim_card = UsimCard(scc)
|
||||||
|
|
||||||
@@ -300,7 +301,8 @@ if __name__ == '__main__':
|
|||||||
print("ePDGSelection: Can't read file -- " + str(e))
|
print("ePDGSelection: Can't read file -- " + str(e))
|
||||||
|
|
||||||
# Select ISIM application by its AID
|
# Select ISIM application by its AID
|
||||||
if '9000' == card.select_adf_by_aid(adf="isim"):
|
data, sw = card.select_adf_by_aid(adf="isim")
|
||||||
|
if sw == '9000':
|
||||||
# Select USIM profile
|
# Select USIM profile
|
||||||
isim_card = IsimCard(scc)
|
isim_card = IsimCard(scc)
|
||||||
|
|
||||||
@@ -352,7 +354,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# Check whether we have th AID of ISIM, if so select it by its AID
|
# Check whether we have th AID of ISIM, if so select it by its AID
|
||||||
# EF.IST - File Id in ADF ISIM : 6f07
|
# EF.IST - File Id in ADF ISIM : 6f07
|
||||||
if '9000' == card.select_adf_by_aid(adf="isim"):
|
data, sw = card.select_adf_by_aid(adf="isim")
|
||||||
|
if sw == '9000':
|
||||||
# EF.IST
|
# EF.IST
|
||||||
(res, sw) = card.read_binary('6f07')
|
(res, sw) = card.read_binary('6f07')
|
||||||
if sw == '9000':
|
if sw == '9000':
|
||||||
|
|||||||
@@ -224,21 +224,21 @@ class Card(object):
|
|||||||
|
|
||||||
# Select ADF.U/ISIM in the Card using its full AID
|
# Select ADF.U/ISIM in the Card using its full AID
|
||||||
def select_adf_by_aid(self, adf="usim"):
|
def select_adf_by_aid(self, adf="usim"):
|
||||||
# Check for valid ADF name
|
# Find full AID by partial AID:
|
||||||
if adf not in ["usim", "isim"]:
|
if is_hex(adf):
|
||||||
return None
|
for aid in self._aids:
|
||||||
|
if len(aid) >= len(adf) and adf == aid[0:len(adf)]:
|
||||||
# First (known) halves of the U/ISIM AID
|
return self._scc.select_adf(aid)
|
||||||
aid_map = {}
|
# Find full AID by application name:
|
||||||
aid_map["usim"] = "a0000000871002"
|
elif adf in ["usim", "isim"]:
|
||||||
aid_map["isim"] = "a0000000871004"
|
# First (known) halves of the U/ISIM AID
|
||||||
|
aid_map = {}
|
||||||
for aid in self._aids:
|
aid_map["usim"] = "a0000000871002"
|
||||||
if aid_map[adf] in aid:
|
aid_map["isim"] = "a0000000871004"
|
||||||
(res, sw) = self._scc.select_adf(aid)
|
for aid in self._aids:
|
||||||
return sw
|
if aid_map[adf] in aid:
|
||||||
|
return self._scc.select_adf(aid)
|
||||||
return None
|
return (None, None)
|
||||||
|
|
||||||
# Erase the contents of a file
|
# Erase the contents of a file
|
||||||
def erase_binary(self, ef):
|
def erase_binary(self, ef):
|
||||||
@@ -1335,7 +1335,8 @@ class SysmoISIMSJA2(UsimCard, IsimCard):
|
|||||||
self._scc.update_binary('6f20', p['opc'], 17)
|
self._scc.update_binary('6f20', p['opc'], 17)
|
||||||
|
|
||||||
# update EF-USIM_AUTH_KEY in ADF.ISIM
|
# update EF-USIM_AUTH_KEY in ADF.ISIM
|
||||||
if '9000' == self.select_adf_by_aid(adf="isim"):
|
data, sw = self.select_adf_by_aid(adf="isim")
|
||||||
|
if sw == '9000':
|
||||||
if p.get('ki'):
|
if p.get('ki'):
|
||||||
self._scc.update_binary('af20', p['ki'], 1)
|
self._scc.update_binary('af20', p['ki'], 1)
|
||||||
if p.get('opc'):
|
if p.get('opc'):
|
||||||
@@ -1382,7 +1383,8 @@ class SysmoISIMSJA2(UsimCard, IsimCard):
|
|||||||
if sw != '9000':
|
if sw != '9000':
|
||||||
print("Programming IMPU failed with code %s"%sw)
|
print("Programming IMPU failed with code %s"%sw)
|
||||||
|
|
||||||
if '9000' == self.select_adf_by_aid():
|
data, sw = self.select_adf_by_aid(adf="usim")
|
||||||
|
if sw == '9000':
|
||||||
# update EF-USIM_AUTH_KEY in ADF.USIM
|
# update EF-USIM_AUTH_KEY in ADF.USIM
|
||||||
if p.get('ki'):
|
if p.get('ki'):
|
||||||
self._scc.update_binary('af20', p['ki'], 1)
|
self._scc.update_binary('af20', p['ki'], 1)
|
||||||
|
|||||||
@@ -665,7 +665,7 @@ class RuntimeState(object):
|
|||||||
f = sels[name]
|
f = sels[name]
|
||||||
try:
|
try:
|
||||||
if isinstance(f, CardADF):
|
if isinstance(f, CardADF):
|
||||||
(data, sw) = self.card._scc.select_adf(f.aid)
|
(data, sw) = self.card.select_adf_by_aid(f.aid)
|
||||||
else:
|
else:
|
||||||
(data, sw) = self.card._scc.select_file(f.fid)
|
(data, sw) = self.card._scc.select_file(f.fid)
|
||||||
self.selected_file = f
|
self.selected_file = f
|
||||||
|
|||||||
Reference in New Issue
Block a user