laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38049?usp=email )
Change subject: pySim-shell: Detect different eUICC types and print during start-up ......................................................................
pySim-shell: Detect different eUICC types and print during start-up
Change-Id: I54ea4ce663693f3951040dcc8a16bf532bf99c02 --- M pySim/cdma_ruim.py M pySim/euicc.py M pySim/ts_102_221.py M pySim/ts_51_011.py 4 files changed, 70 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/49/38049/1
diff --git a/pySim/cdma_ruim.py b/pySim/cdma_ruim.py index 96ff1a4..287a3d9 100644 --- a/pySim/cdma_ruim.py +++ b/pySim/cdma_ruim.py @@ -179,7 +179,7 @@ class CardProfileRUIM(CardProfile): '''R-UIM card profile as per 3GPP2 C.S0023-D'''
- ORDER = 2 + ORDER = 20
def __init__(self): super().__init__('R-UIM', desc='CDMA R-UIM Card', cla="a0", diff --git a/pySim/euicc.py b/pySim/euicc.py index c7b59d9..98ae1af 100644 --- a/pySim/euicc.py +++ b/pySim/euicc.py @@ -31,8 +31,10 @@ from osmocom.tlv import * from osmocom.construct import *
+from pySim.exceptions import SwMatchError from pySim.utils import Hexstr, SwHexstr, SwMatchstr from pySim.commands import SimCardCommands +from pySim.ts_102_221 import CardProfileUICC import pySim.global_platform
# SGP.02 Section 2.2.2 @@ -555,3 +557,68 @@ @with_default_category('Application-Specific Commands') class AddlShellCommands(CommandSet): pass + +def match_helper(scc, fn) -> bool: + # try to read EID from ISD-R + try: + cla_backup = scc.cla_byte + fn(scc) + return True + except SwMatchError: + return False + finally: + scc.cla_byte = cla_backup + scc.reset_card() + +class CardProfileEuiccSGP32(CardProfileUICC): + ORDER = 5 + + def __init__(self): + super().__init__(name='IoT eUICC (SGP.32)') + + @staticmethod + def _match_with_card(scc: SimCardCommands) -> bool: + # try a command only supported by SGP.32 + scc.cla_byte = "80" + scc.select_adf(AID_ISD_R) + gc = CardApplicationISDR.store_data_tlv(scc, GetCertsReq(), GetCertsResp) + + @staticmethod + def match_with_card(scc: SimCardCommands) -> bool: + return match_helper(scc, CardProfileEuiccSGP32._match_with_card) + +class CardProfileEuiccSGP22(CardProfileUICC): + ORDER = 6 + + def __init__(self): + super().__init__(name='Consumer eUICC (SGP.22)') + + + @staticmethod + def _match_with_card(scc: SimCardCommands) -> bool: + # try to read EID from ISD-R + scc.cla_byte = "80" + scc.select_adf(AID_ISD_R) + eid = CardApplicationISDR.get_eid(scc) + # TODO: Store EID identity? + + @staticmethod + def match_with_card(scc: SimCardCommands) -> bool: + return match_helper(scc, CardProfileEuiccSGP22._match_with_card) + +class CardProfileEuiccSGP02(CardProfileUICC): + ORDER = 7 + + def __init__(self): + super().__init__(name='M2M eUICC (SGP.02)') + + @staticmethod + def _match_with_card(scc: SimCardCommands) -> bool: + scc.cla_byte = "00" + scc.select_adf(AID_ECASD) + scc.get_data(0x5a) + # TODO: Store EID identity? + + @staticmethod + def match_with_card(scc: SimCardCommands) -> bool: + return match_helper(scc, CardProfileEuiccSGP02._match_with_card) diff --git a/pySim/ts_102_221.py b/pySim/ts_102_221.py index aba28cd..c2e7697 100644 --- a/pySim/ts_102_221.py +++ b/pySim/ts_102_221.py @@ -787,7 +787,7 @@
class CardProfileUICC(CardProfile):
- ORDER = 1 + ORDER = 10
def __init__(self, name='UICC'): files = [ diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py index c6720fe..8982ad4 100644 --- a/pySim/ts_51_011.py +++ b/pySim/ts_51_011.py @@ -1087,7 +1087,7 @@
class CardProfileSIM(CardProfile):
- ORDER = 3 + ORDER = 30
def __init__(self): sw = {