Change in pysim[master]: ts_31_102: Start using pySim.tlv to implement more DF.5GS files

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Sat May 29 20:42:29 UTC 2021


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/24455 )


Change subject: ts_31_102: Start using pySim.tlv to implement more DF.5GS files
......................................................................

ts_31_102: Start using pySim.tlv to implement more DF.5GS files

Change-Id: I8ef2d8c24530d13929282e1a1d2138d319b894c6
---
M pySim/ts_31_102.py
1 file changed, 76 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/55/24455/1

diff --git a/pySim/ts_31_102.py b/pySim/ts_31_102.py
index ae255f1..6d30f23 100644
--- a/pySim/ts_31_102.py
+++ b/pySim/ts_31_102.py
@@ -278,8 +278,9 @@
 
 from struct import unpack, pack
 from construct import *
-from pySim.construct import LV, HexAdapter, BcdAdapter, BitsRFU
+from pySim.construct import *
 from pySim.filesystem import *
+from pySim.tlv import *
 from pySim.ts_102_221 import EF_ARR
 from pySim.ts_51_011 import EF_IMSI, EF_xPLMNwAcT, EF_SPN, EF_CBMI, EF_ACC, EF_PLMNsel, EF_AD
 from pySim.ts_51_011 import EF_CBMID, EF_CBMIR, EF_ADN, EF_SMS, EF_MSISDN, EF_SMSP, EF_SMSS
@@ -289,6 +290,77 @@
 
 import pySim.ts_102_221
 
+# 3GPP TS 31.102 Section 4.4.11.4 (EF_5GS3GPPNSC)
+class EF_5GS3GPPNSC(LinFixedEF):
+    class NgKSI(BER_TLV_IE, tag=0x80):
+        _construct = Int8ub
+
+    class K_AMF(BER_TLV_IE, tag=0x81):
+        _construct = HexAdapter(Bytes(32))
+
+    class UplinkNASCount(BER_TLV_IE, tag=0x82):
+        _construct = Int32ub
+
+    class DownlinkNASCount(BER_TLV_IE, tag=0x83):
+        _construct = Int32ub
+
+    class IdsOfSelectedNasAlgos(BER_TLV_IE, tag=0x84):
+        # 3GPP TS 24.501 Section 9.11.3.34
+        _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble)
+
+    class IdsOfSelectedEpsAlgos(BER_TLV_IE, tag=0x85):
+        # 3GPP TS 24.301 Section 9.9.3.23
+        _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble)
+
+    class FiveGSNasSecurityContext(BER_TLV_IE, tag=0xA0,
+            nested=[NgKSI, K_AMF, UplinkNASCount, DownlinkNASCount, IdsOfSelectedNasAlgos,
+                    IdsOfSelectedEpsAlgos]):
+        pass
+
+    def __init__(self, fid="4f03", sfid=0x03, name='EF.5GS3GPPNSC', rec_len={57, None},
+        desc='5GS 3GPP Access NAS Security Context'):
+        super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len)
+        self._tlv = EF_5GS3GPPNSC.FiveGSNasSecurityContext()
+
+# 3GPP TS 31.102 Section 4.4.11.6
+class EF_5GAUTHKEYS(TransparentEF):
+    class K_AUSF(BER_TLV_IE, tag=0x80):
+        _construct = HexAdapter(GreedyBytes)
+
+    class K_SEAF(BER_TLV_IE, tag=0x81):
+        _construct = HexAdapter(GreedyBytes)
+
+    class FiveGAuthKeys(TLV_IE_Collection, nested=[K_AUSF, K_SEAF]):
+        pass
+
+    def __init__(self, fid='4f05', sfid=0x05, name='EF.5GAUTHKEYS', size={68, None},
+            desc='5G authentication keys'):
+        super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
+        self._tlv = EF_5GAUTHKEYS.FiveGAuthKeys()
+
+# 3GPP TS 31.102 Section 4.4.11.8
+class ProtSchemeIdList(BER_TLV_IE, tag=0xa0):
+    # FIXME: 3GPP TS 24.501 Protection Scheme Identifier
+    # repeated sequence of (id, index) tuples
+    _construct = GreedyRange(Struct('id'/Enum(Byte, null=0, A=1, B=2), 'index'/Int8ub))
+
+class HomeNetPubKeyId(BER_TLV_IE, tag=0x80):
+    # 3GPP TS 24.501 / 3GPP TS 23.003
+    _construct = Int8ub
+
+class HomeNetPubKey(BER_TLV_IE, tag=0x81):
+    # FIXME: RFC 5480
+    _construct = HexAdapter(GreedyBytes)
+
+class HomeNetPubKeyList(BER_TLV_IE, tag=0xa1,
+        nested=[HomeNetPubKeyId, HomeNetPubKey]):
+    pass
+
+# 3GPP TS 31.102 Section 4.4.11.6
+class SUCI_CalcInfo(TLV_IE_Collection, nested=[ProtSchemeIdList,HomeNetPubKeyList]):
+    pass
+
+
 # TS 31.102 4.4.11.8
 class EF_SUCI_Calc_Info(TransparentEF):
     def __init__(self, fid="4f07", sfid=0x07, name='EF.SUCI_Calc_Info', size={2, None},
@@ -705,9 +777,9 @@
           # I'm looking at 31.102 R16.6
           EF_5GS3GPPLOCI(),
           EF_5GS3GPPLOCI('4f02', 0x02, 'EF.5GSN3GPPLOCI', '5GS non-3GPP location information'),
-          LinFixedEF('4F03', 0x03, 'EF.5GS3GPPNSC', '5GS 3GPP Access NAS Security Context', rec_len={57,None}),
-          LinFixedEF('4F04', 0x04, 'EF.5GSN3GPPNSC', '5GS non-3GPP Access NAS Security Context', rec_len={57,None}),
-          TransparentEF('4F05', 0x05, 'EF.5GAUTHKEYS', '5G authentication keys', size={68, None}),
+          EF_5GS3GPPNSC(),
+          EF_5GS3GPPNSC('4f04', 0x04, 'EF.5GSN3GPPNSC', '5GS non-3GPP Access NAS Security Context'),
+          EF_5GAUTHKEYS(),
           EF_UAC_AIC(),
           EF_SUCI_Calc_Info(),
           EF_OPL5G(),

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/24455
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I8ef2d8c24530d13929282e1a1d2138d319b894c6
Gerrit-Change-Number: 24455
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210529/dc143ee6/attachment.htm>


More information about the gerrit-log mailing list