<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/24455">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">ts_31_102: Start using pySim.tlv to implement more DF.5GS files<br><br>Change-Id: I8ef2d8c24530d13929282e1a1d2138d319b894c6<br>---<br>M pySim/ts_31_102.py<br>1 file changed, 81 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim/ts_31_102.py b/pySim/ts_31_102.py</span><br><span>index ae255f1..78307a4 100644</span><br><span>--- a/pySim/ts_31_102.py</span><br><span>+++ b/pySim/ts_31_102.py</span><br><span>@@ -1,5 +1,9 @@</span><br><span> # -*- coding: utf-8 -*-</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+# without this, pylint will fail when inner classes are used</span><br><span style="color: hsl(120, 100%, 40%);">+# within the 'nested' kwarg of our TlvMeta metaclass on python 3.7 :(</span><br><span style="color: hsl(120, 100%, 40%);">+# pylint: disable=undefined-variable</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> """</span><br><span> Various constants from 3GPP TS 31.102 V16.6.0</span><br><span> """</span><br><span>@@ -278,8 +282,9 @@</span><br><span> </span><br><span> from struct import unpack, pack</span><br><span> from construct import *</span><br><span style="color: hsl(0, 100%, 40%);">-from pySim.construct import LV, HexAdapter, BcdAdapter, BitsRFU</span><br><span style="color: hsl(120, 100%, 40%);">+from pySim.construct import *</span><br><span> from pySim.filesystem import *</span><br><span style="color: hsl(120, 100%, 40%);">+from pySim.tlv import *</span><br><span> from pySim.ts_102_221 import EF_ARR</span><br><span> from pySim.ts_51_011 import EF_IMSI, EF_xPLMNwAcT, EF_SPN, EF_CBMI, EF_ACC, EF_PLMNsel, EF_AD</span><br><span> from pySim.ts_51_011 import EF_CBMID, EF_CBMIR, EF_ADN, EF_SMS, EF_MSISDN, EF_SMSP, EF_SMSS</span><br><span>@@ -289,6 +294,78 @@</span><br><span> </span><br><span> import pySim.ts_102_221</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+# 3GPP TS 31.102 Section 4.4.11.4 (EF_5GS3GPPNSC)</span><br><span style="color: hsl(120, 100%, 40%);">+class EF_5GS3GPPNSC(LinFixedEF):</span><br><span style="color: hsl(120, 100%, 40%);">+    class NgKSI(BER_TLV_IE, tag=0x80):</span><br><span style="color: hsl(120, 100%, 40%);">+        _construct = Int8ub</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    class K_AMF(BER_TLV_IE, tag=0x81):</span><br><span style="color: hsl(120, 100%, 40%);">+        _construct = HexAdapter(Bytes(32))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    class UplinkNASCount(BER_TLV_IE, tag=0x82):</span><br><span style="color: hsl(120, 100%, 40%);">+        _construct = Int32ub</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    class DownlinkNASCount(BER_TLV_IE, tag=0x83):</span><br><span style="color: hsl(120, 100%, 40%);">+        _construct = Int32ub</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    class IdsOfSelectedNasAlgos(BER_TLV_IE, tag=0x84):</span><br><span style="color: hsl(120, 100%, 40%);">+        # 3GPP TS 24.501 Section 9.11.3.34</span><br><span style="color: hsl(120, 100%, 40%);">+        _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    class IdsOfSelectedEpsAlgos(BER_TLV_IE, tag=0x85):</span><br><span style="color: hsl(120, 100%, 40%);">+        # 3GPP TS 24.301 Section 9.9.3.23</span><br><span style="color: hsl(120, 100%, 40%);">+        _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    class FiveGSNasSecurityContext(BER_TLV_IE, tag=0xA0,</span><br><span style="color: hsl(120, 100%, 40%);">+            nested=[NgKSI, K_AMF, UplinkNASCount,</span><br><span style="color: hsl(120, 100%, 40%);">+                    DownlinkNASCount, IdsOfSelectedNasAlgos,</span><br><span style="color: hsl(120, 100%, 40%);">+                    IdsOfSelectedEpsAlgos]):</span><br><span style="color: hsl(120, 100%, 40%);">+        pass</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self, fid="4f03", sfid=0x03, name='EF.5GS3GPPNSC', rec_len={57, None},</span><br><span style="color: hsl(120, 100%, 40%);">+        desc='5GS 3GPP Access NAS Security Context'):</span><br><span style="color: hsl(120, 100%, 40%);">+        super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len)</span><br><span style="color: hsl(120, 100%, 40%);">+        self._tlv = EF_5GS3GPPNSC.FiveGSNasSecurityContext()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# 3GPP TS 31.102 Section 4.4.11.6</span><br><span style="color: hsl(120, 100%, 40%);">+class EF_5GAUTHKEYS(TransparentEF):</span><br><span style="color: hsl(120, 100%, 40%);">+    class K_AUSF(BER_TLV_IE, tag=0x80):</span><br><span style="color: hsl(120, 100%, 40%);">+        _construct = HexAdapter(GreedyBytes)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    class K_SEAF(BER_TLV_IE, tag=0x81):</span><br><span style="color: hsl(120, 100%, 40%);">+        _construct = HexAdapter(GreedyBytes)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    class FiveGAuthKeys(TLV_IE_Collection, nested=[K_AUSF, K_SEAF]):</span><br><span style="color: hsl(120, 100%, 40%);">+        pass</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self, fid='4f05', sfid=0x05, name='EF.5GAUTHKEYS', size={68, None},</span><br><span style="color: hsl(120, 100%, 40%);">+            desc='5G authentication keys'):</span><br><span style="color: hsl(120, 100%, 40%);">+        super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)</span><br><span style="color: hsl(120, 100%, 40%);">+        self._tlv = EF_5GAUTHKEYS.FiveGAuthKeys()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# 3GPP TS 31.102 Section 4.4.11.8</span><br><span style="color: hsl(120, 100%, 40%);">+class ProtSchemeIdList(BER_TLV_IE, tag=0xa0):</span><br><span style="color: hsl(120, 100%, 40%);">+    # FIXME: 3GPP TS 24.501 Protection Scheme Identifier</span><br><span style="color: hsl(120, 100%, 40%);">+    # repeated sequence of (id, index) tuples</span><br><span style="color: hsl(120, 100%, 40%);">+    _construct = GreedyRange(Struct('id'/Enum(Byte, null=0, A=1, B=2), 'index'/Int8ub))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+class HomeNetPubKeyId(BER_TLV_IE, tag=0x80):</span><br><span style="color: hsl(120, 100%, 40%);">+    # 3GPP TS 24.501 / 3GPP TS 23.003</span><br><span style="color: hsl(120, 100%, 40%);">+    _construct = Int8ub</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+class HomeNetPubKey(BER_TLV_IE, tag=0x81):</span><br><span style="color: hsl(120, 100%, 40%);">+    # FIXME: RFC 5480</span><br><span style="color: hsl(120, 100%, 40%);">+    _construct = HexAdapter(GreedyBytes)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+class HomeNetPubKeyList(BER_TLV_IE, tag=0xa1,</span><br><span style="color: hsl(120, 100%, 40%);">+        nested=[HomeNetPubKeyId, HomeNetPubKey]):</span><br><span style="color: hsl(120, 100%, 40%);">+    pass</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# 3GPP TS 31.102 Section 4.4.11.6</span><br><span style="color: hsl(120, 100%, 40%);">+class SUCI_CalcInfo(TLV_IE_Collection, nested=[ProtSchemeIdList,HomeNetPubKeyList]):</span><br><span style="color: hsl(120, 100%, 40%);">+    pass</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> # TS 31.102 4.4.11.8</span><br><span> class EF_SUCI_Calc_Info(TransparentEF):</span><br><span>     def __init__(self, fid="4f07", sfid=0x07, name='EF.SUCI_Calc_Info', size={2, None},</span><br><span>@@ -705,9 +782,9 @@</span><br><span>           # I'm looking at 31.102 R16.6</span><br><span>           EF_5GS3GPPLOCI(),</span><br><span>           EF_5GS3GPPLOCI('4f02', 0x02, 'EF.5GSN3GPPLOCI', '5GS non-3GPP location information'),</span><br><span style="color: hsl(0, 100%, 40%);">-          LinFixedEF('4F03', 0x03, 'EF.5GS3GPPNSC', '5GS 3GPP Access NAS Security Context', rec_len={57,None}),</span><br><span style="color: hsl(0, 100%, 40%);">-          LinFixedEF('4F04', 0x04, 'EF.5GSN3GPPNSC', '5GS non-3GPP Access NAS Security Context', rec_len={57,None}),</span><br><span style="color: hsl(0, 100%, 40%);">-          TransparentEF('4F05', 0x05, 'EF.5GAUTHKEYS', '5G authentication keys', size={68, None}),</span><br><span style="color: hsl(120, 100%, 40%);">+          EF_5GS3GPPNSC(),</span><br><span style="color: hsl(120, 100%, 40%);">+          EF_5GS3GPPNSC('4f04', 0x04, 'EF.5GSN3GPPNSC', '5GS non-3GPP Access NAS Security Context'),</span><br><span style="color: hsl(120, 100%, 40%);">+          EF_5GAUTHKEYS(),</span><br><span>           EF_UAC_AIC(),</span><br><span>           EF_SUCI_Calc_Info(),</span><br><span>           EF_OPL5G(),</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/24455">change 24455</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/pysim/+/24455"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I8ef2d8c24530d13929282e1a1d2138d319b894c6 </div>
<div style="display:none"> Gerrit-Change-Number: 24455 </div>
<div style="display:none"> Gerrit-PatchSet: 8 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>