From a01e87da773cae60039342e8112e0a26b53990be Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 19 Sep 2024 08:38:20 +0200 Subject: [PATCH] split pySim.profile.euicc from pySim.euicc Change-Id: I2b922622669a2b5ad496ea22fa67656a44096f4a --- pySim/app.py | 2 +- pySim/euicc.py | 41 ----------------------------- pySim/profile/euicc.py | 58 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 42 deletions(-) create mode 100644 pySim/profile/euicc.py diff --git a/pySim/app.py b/pySim/app.py index 4391234a..dfa8abab 100644 --- a/pySim/app.py +++ b/pySim/app.py @@ -40,7 +40,7 @@ import pySim.ts_31_103 import pySim.ts_31_104 import pySim.ara_m import pySim.global_platform -import pySim.euicc +import pySim.profile.euicc def init_card(sl: LinkBase, skip_card_init: bool = False) -> Tuple[RuntimeState, SimCardBase]: """ diff --git a/pySim/euicc.py b/pySim/euicc.py index 3cd52f39..8c9dd6dd 100644 --- a/pySim/euicc.py +++ b/pySim/euicc.py @@ -34,7 +34,6 @@ from osmocom.construct import * from pySim.exceptions import SwMatchError from pySim.utils import Hexstr, SwHexstr, SwMatchstr from pySim.commands import SimCardCommands -from pySim.profile.ts_102_221 import CardProfileUICC import pySim.global_platform # SGP.02 Section 2.2.2 @@ -557,43 +556,3 @@ class CardApplicationECASD(pySim.global_platform.CardApplicationSD): @with_default_category('Application-Specific Commands') class AddlShellCommands(CommandSet): pass - -class CardProfileEuiccSGP32(CardProfileUICC): - ORDER = 5 - - def __init__(self): - super().__init__(name='IoT eUICC (SGP.32)') - - @classmethod - def _try_match_card(cls, scc: SimCardCommands) -> None: - # try a command only supported by SGP.32 - scc.cla_byte = "00" - scc.select_adf(AID_ISD_R) - CardApplicationISDR.store_data_tlv(scc, GetCertsReq(), GetCertsResp) - -class CardProfileEuiccSGP22(CardProfileUICC): - ORDER = 6 - - def __init__(self): - super().__init__(name='Consumer eUICC (SGP.22)') - - @classmethod - def _try_match_card(cls, scc: SimCardCommands) -> None: - # try to read EID from ISD-R - scc.cla_byte = "00" - scc.select_adf(AID_ISD_R) - eid = CardApplicationISDR.get_eid(scc) - # TODO: Store EID identity? - -class CardProfileEuiccSGP02(CardProfileUICC): - ORDER = 7 - - def __init__(self): - super().__init__(name='M2M eUICC (SGP.02)') - - @classmethod - def _try_match_card(cls, scc: SimCardCommands) -> None: - scc.cla_byte = "00" - scc.select_adf(AID_ECASD) - scc.get_data(0x5a) - # TODO: Store EID identity? diff --git a/pySim/profile/euicc.py b/pySim/profile/euicc.py new file mode 100644 index 00000000..01ad2db0 --- /dev/null +++ b/pySim/profile/euicc.py @@ -0,0 +1,58 @@ +# Copyright (C) 2023 Harald Welte +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from pySim.profile.ts_102_221 import CardProfileUICC +from pySim.commands import SimCardCommands +from pySim.euicc import CardApplicationISDR, AID_ISD_R, AID_ECASD, GetCertsReq, GetCertsResp + +class CardProfileEuiccSGP32(CardProfileUICC): + ORDER = 5 + + def __init__(self): + super().__init__(name='IoT eUICC (SGP.32)') + + @classmethod + def _try_match_card(cls, scc: SimCardCommands) -> None: + # try a command only supported by SGP.32 + scc.cla_byte = "00" + scc.select_adf(AID_ISD_R) + CardApplicationISDR.store_data_tlv(scc, GetCertsReq(), GetCertsResp) + +class CardProfileEuiccSGP22(CardProfileUICC): + ORDER = 6 + + def __init__(self): + super().__init__(name='Consumer eUICC (SGP.22)') + + @classmethod + def _try_match_card(cls, scc: SimCardCommands) -> None: + # try to read EID from ISD-R + scc.cla_byte = "00" + scc.select_adf(AID_ISD_R) + eid = CardApplicationISDR.get_eid(scc) + # TODO: Store EID identity? + +class CardProfileEuiccSGP02(CardProfileUICC): + ORDER = 7 + + def __init__(self): + super().__init__(name='M2M eUICC (SGP.02)') + + @classmethod + def _try_match_card(cls, scc: SimCardCommands) -> None: + scc.cla_byte = "00" + scc.select_adf(AID_ECASD) + scc.get_data(0x5a) + # TODO: Store EID identity?