cards.py: support ATR-based detection of sysmoISIM-SJA5

The cards are 99% software-compatible to the SJA2, so let's just
derive the SJA5 class from the SJA2

Change-Id: I706631baaf447c49904277886bc9a3f6ba3f5532
diff --git a/pySim/cards.py b/pySim/cards.py
index b48a80c..d5cd676 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -1656,11 +1656,38 @@
 
         return
 
+class SysmoISIMSJA5(SysmoISIMSJA2):
+    """
+    sysmocom sysmoISIM-SJA5
+    """
+
+    name = 'sysmoISIM-SJA5'
+
+    @classmethod
+    def autodetect(kls, scc):
+        try:
+            # Try card model #1 (9FJ)
+            atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 35 75 30 35 02 51 CC"
+            if scc.get_atr() == toBytes(atr):
+                return kls(scc)
+            # Try card model #2 (SLM17)
+            atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 35 75 30 35 02 65 F8"
+            if scc.get_atr() == toBytes(atr):
+                return kls(scc)
+            # Try card model #3 (9FV)
+            atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 35 75 30 35 02 59 C4"
+            if scc.get_atr() == toBytes(atr):
+                return kls(scc)
+        except:
+            return None
+        return None
+
 
 # In order for autodetection ...
 _cards_classes = [FakeMagicSim, SuperSim, MagicSim, GrcardSim,
                   SysmoSIMgr1, SysmoSIMgr2, SysmoUSIMgr1, SysmoUSIMSJS1,
-                  FairwavesSIM, OpenCellsSim, WavemobileSim, SysmoISIMSJA2]
+                  FairwavesSIM, OpenCellsSim, WavemobileSim, SysmoISIMSJA2,
+                  SysmoISIMSJA5]
 
 
 def card_detect(ctype, scc):
diff --git a/pySim/sysmocom_sja2.py b/pySim/sysmocom_sja2.py
index 4967701..e32943f 100644
--- a/pySim/sysmocom_sja2.py
+++ b/pySim/sysmocom_sja2.py
@@ -1,7 +1,7 @@
 # coding=utf-8
-"""Utilities / Functions related to sysmocom SJA2 cards
+"""Utilities / Functions related to sysmocom SJA2/SJA5 cards
 
-(C) 2021 by Harald Welte <laforge@osmocom.org>
+(C) 2021-2023 by Harald Welte <laforge@osmocom.org>
 
 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
@@ -258,3 +258,34 @@
                 EF_USIM_SQN(name='EF.ISIM_SQN'),
             ]
             isim_adf.add_files(files_adf_isim)
+
+class SysmocomSJA5(CardModel):
+    _atrs = ["3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 35 75 30 35 02 51 CC",
+             "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 35 75 30 35 02 65 F8",
+             "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 35 75 30 35 02 59 C4"]
+
+    @classmethod
+    def add_files(cls, rs: RuntimeState):
+        """Add sysmocom SJA2 specific files to given RuntimeState."""
+        rs.mf.add_file(DF_SYSTEM())
+        # optional USIM application
+        if 'a0000000871002' in rs.mf.applications:
+            usim_adf = rs.mf.applications['a0000000871002']
+            files_adf_usim = [
+                EF_USIM_AUTH_KEY(),
+                EF_USIM_AUTH_KEY_2G(),
+                EF_GBA_SK(),
+                EF_GBA_REC_LIST(),
+                EF_GBA_INT_KEY(),
+                EF_USIM_SQN(),
+            ]
+            usim_adf.add_files(files_adf_usim)
+        # optional ISIM application
+        if 'a0000000871004' in rs.mf.applications:
+            isim_adf = rs.mf.applications['a0000000871004']
+            files_adf_isim = [
+                EF_USIM_AUTH_KEY(name='EF.ISIM_AUTH_KEY'),
+                EF_USIM_AUTH_KEY_2G(name='EF.ISIM_AUTH_KEY_2G'),
+                EF_USIM_SQN(name='EF.ISIM_SQN'),
+            ]
+            isim_adf.add_files(files_adf_isim)