laforge submitted this change.
pySim.apdu.ts_102_222: APDU decoding for administrative commands
Change-Id: I77c97221da19e1a67d96f7cfb69785baefc675c0
---
A pySim/apdu/ts_102_222.py
M pySim/apdu_source/gsmtap.py
M pySim/apdu_source/pyshark_gsmtap.py
M pySim/apdu_source/tca_loader_log.py
4 files changed, 75 insertions(+), 3 deletions(-)
diff --git a/pySim/apdu/ts_102_222.py b/pySim/apdu/ts_102_222.py
new file mode 100644
index 0000000..fde16a8
--- /dev/null
+++ b/pySim/apdu/ts_102_222.py
@@ -0,0 +1,60 @@
+# coding=utf-8
+"""APDU definitions/decoders of ETSI TS 102 222.
+
+(C) 2022-2024 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
+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 <http://www.gnu.org/licenses/>.
+"""
+
+import logging
+
+from construct import Struct
+
+from pySim.construct import *
+from pySim.apdu import ApduCommand, ApduCommandSet
+from pySim.ts_102_221 import FcpTemplate
+
+logger = logging.getLogger(__name__)
+
+# TS 102 222 Section 6.3
+class CreateFile(ApduCommand, n='CREATE FILE', ins=0xE0, cla=['0X', '4X', 'EX']):
+ _apdu_case = 3
+ _tlv = FcpTemplate
+
+# TS 102 222 Section 6.4
+class DeleteFile(ApduCommand, n='DELETE FILE', ins=0xE4, cla=['0X', '4X']):
+ _apdu_case = 3
+ _construct = Struct('file_id'/Bytes(2))
+
+# TS 102 222 Section 6.7
+class TerminateDF(ApduCommand, n='TERMINATE DF', ins=0xE6, cla=['0X', '4X']):
+ _apdu_case = 1
+
+# TS 102 222 Section 6.8
+class TerminateEF(ApduCommand, n='TERMINATE EF', ins=0xE8, cla=['0X', '4X']):
+ _apdu_case = 1
+
+# TS 102 222 Section 6.9
+class TerminateCardUsage(ApduCommand, n='TERMINATE CARD USAGE', ins=0xFE, cla=['0X', '4X']):
+ _apdu_case = 1
+
+# TS 102 222 Section 6.10
+class ResizeFile(ApduCommand, n='RESIZE FILE', ins=0xD4, cla=['8X', 'CX', 'EX']):
+ _apdu_case = 3
+ _construct_p1 = Enum(Byte, mode_0=0, mode_1=1)
+ _tlv = FcpTemplate
+
+
+ApduCommands = ApduCommandSet('TS 102 222', cmds=[CreateFile, DeleteFile, TerminateDF,
+ TerminateEF, TerminateCardUsage, ResizeFile])
diff --git a/pySim/apdu_source/gsmtap.py b/pySim/apdu_source/gsmtap.py
index bcfb66d..bc2f4f8 100644
--- a/pySim/apdu_source/gsmtap.py
+++ b/pySim/apdu_source/gsmtap.py
@@ -19,12 +19,13 @@
from pySim.gsmtap import GsmtapSource
from pySim.apdu.ts_102_221 import ApduCommands as UiccApduCommands
+from pySim.apdu.ts_102_222 import ApduCommands as UiccAdmApduCommands
from pySim.apdu.ts_31_102 import ApduCommands as UsimApduCommands
from pySim.apdu.global_platform import ApduCommands as GpApduCommands
from . import ApduSource, PacketType, CardReset
-ApduCommands = UiccApduCommands + UsimApduCommands + GpApduCommands
+ApduCommands = UiccApduCommands + UiccAdmApduCommands + UsimApduCommands + GpApduCommands
class GsmtapApduSource(ApduSource):
"""ApduSource for handling GSMTAP-SIM messages received via UDP, such as
diff --git a/pySim/apdu_source/pyshark_gsmtap.py b/pySim/apdu_source/pyshark_gsmtap.py
index 83745e9..af53ec8 100644
--- a/pySim/apdu_source/pyshark_gsmtap.py
+++ b/pySim/apdu_source/pyshark_gsmtap.py
@@ -24,12 +24,13 @@
from pySim.gsmtap import GsmtapMessage
from pySim.apdu.ts_102_221 import ApduCommands as UiccApduCommands
+from pySim.apdu.ts_102_222 import ApduCommands as UiccAdmApduCommands
from pySim.apdu.ts_31_102 import ApduCommands as UsimApduCommands
from pySim.apdu.global_platform import ApduCommands as GpApduCommands
from . import ApduSource, PacketType, CardReset
-ApduCommands = UiccApduCommands + UsimApduCommands + GpApduCommands
+ApduCommands = UiccApduCommands + UiccAdmApduCommands + UsimApduCommands + GpApduCommands
logger = logging.getLogger(__name__)
diff --git a/pySim/apdu_source/tca_loader_log.py b/pySim/apdu_source/tca_loader_log.py
index 6efc605..c7827e7 100644
--- a/pySim/apdu_source/tca_loader_log.py
+++ b/pySim/apdu_source/tca_loader_log.py
@@ -20,12 +20,13 @@
from pySim.gsmtap import GsmtapSource
from pySim.apdu.ts_102_221 import ApduCommands as UiccApduCommands
+from pySim.apdu.ts_102_222 import ApduCommands as UiccAdmApduCommands
from pySim.apdu.ts_31_102 import ApduCommands as UsimApduCommands
from pySim.apdu.global_platform import ApduCommands as GpApduCommands
from . import ApduSource, PacketType, CardReset
-ApduCommands = UiccApduCommands + UsimApduCommands + GpApduCommands
+ApduCommands = UiccApduCommands + UiccAdmApduCommands + UsimApduCommands + GpApduCommands
class TcaLoaderLogApduSource(ApduSource):
"""ApduSource for reading log files created by TCALoader."""
To view, visit change 37533. To unsubscribe, or for help writing mail filters, visit settings.