filesystem: define class byte and select control bytes in profile

The class byte and the select control bytes are different for SIM cards
and UICC cards. Lets define those parameters in the card profile, so
that we always get the correct parameters depending on which profile we
use.

Change-Id: I2d175e28bd748a4871b1373273b3a9be9ae8c4d0
Related: OS#5274
This commit is contained in:
Philipp Maier 2021-11-08 15:45:10 +01:00
parent 4e2e1d9fd3
commit 51cad0d234
3 changed files with 11 additions and 3 deletions

View File

@ -1065,6 +1065,11 @@ class RuntimeState(object):
self.card = card self.card = card
self.selected_file = self.mf # type: CardDF self.selected_file = self.mf # type: CardDF
self.profile = profile self.profile = profile
# make sure the class and selection control bytes, which are specified
# by the card profile are used
self.card.set_apdu_parameter(cla=self.profile.cla, sel_ctrl=self.profile.sel_ctrl)
# add application ADFs + MF-files from profile # add application ADFs + MF-files from profile
apps = self._match_applications() apps = self._match_applications()
for a in apps: for a in apps:
@ -1450,6 +1455,8 @@ class CardProfile(object):
applications : List of CardApplications present on card applications : List of CardApplications present on card
sw : List of status word definitions sw : List of status word definitions
shell_cmdsets : List of cmd2 shell command sets of profile-specific commands shell_cmdsets : List of cmd2 shell command sets of profile-specific commands
cla : class byte that should be used with cards of this profile
sel_ctrl : selection control bytes class byte that should be used with cards of this profile
""" """
self.name = name self.name = name
self.desc = kw.get("desc", None) self.desc = kw.get("desc", None)
@ -1457,6 +1464,8 @@ class CardProfile(object):
self.sw = kw.get("sw", []) self.sw = kw.get("sw", [])
self.applications = kw.get("applications", []) self.applications = kw.get("applications", [])
self.shell_cmdsets = kw.get("shell_cmdsets", []) self.shell_cmdsets = kw.get("shell_cmdsets", [])
self.cla = kw.get("cla", "00")
self.sel_ctrl = kw.get("sel_ctrl", "0004")
def __str__(self): def __str__(self):
return self.name return self.name

View File

@ -683,7 +683,7 @@ class CardProfileUICC(CardProfile):
}, },
} }
super().__init__('UICC', desc='ETSI TS 102 221', files_in_mf=files, sw=sw) super().__init__('UICC', desc='ETSI TS 102 221', cla="00", sel_ctrl="0004", files_in_mf=files, sw=sw)
def decode_select_response(self, data_hex:str) -> Any: def decode_select_response(self, data_hex:str) -> Any:
return decode_select_response(data_hex) return decode_select_response(data_hex)

View File

@ -976,7 +976,6 @@ def _decode_select_response(resp_hex):
class CardProfileSIM(CardProfile): class CardProfileSIM(CardProfile):
def __init__(self): def __init__(self):
super().__init__('SIM', desc='GSM SIM Card', files_in_mf=[DF_TELECOM(), DF_GSM()]) super().__init__('SIM', desc='GSM SIM Card', cla="a0", sel_ctrl="0000", files_in_mf=[DF_TELECOM(), DF_GSM()])
def decode_select_response(self, data_hex:str) -> Any: def decode_select_response(self, data_hex:str) -> Any:
return _decode_select_response(data_hex) return _decode_select_response(data_hex)