From 4c69cebae1a7c4a7827fba97ae445812676762dc Mon Sep 17 00:00:00 2001 From: MartinWho2 Date: Mon, 7 Jul 2025 15:52:53 +0900 Subject: [PATCH 1/4] fix for CAGInfo and ExtCAGInfo to make it follow release 19 of spec --- pycrate_mobile/TS24501_IE.py | 124 ++++++++++++++++++++++++++++++----- 1 file changed, 109 insertions(+), 15 deletions(-) diff --git a/pycrate_mobile/TS24501_IE.py b/pycrate_mobile/TS24501_IE.py index b9120ba..eec27d4 100644 --- a/pycrate_mobile/TS24501_IE.py +++ b/pycrate_mobile/TS24501_IE.py @@ -1601,17 +1601,22 @@ class CAGInfo(Envelope): _GEN = ( Uint8('Len'), PLMN(), + Uint('spare', bl=7, rep=REPR_HEX), + Uint('CAGOnly', val=0, bl=1, dic={ + 0: 'UE allowed to access 5GS via non-CAG cells', + 1: 'UE not allowed to access 5GS via non-CAG cells'}), Array('CAGIDList', GEN=Uint32('CAGID', rep=REPR_HEX)) ) - + def __init__(self, *args, **kwargs): Envelope.__init__(self, *args, **kwargs) - self[0].set_valauto(lambda: 3 + self[2].get_len()) - self[2].set_blauto(lambda: (self[0].get_val()-3)<<3) - + self[0].set_valauto(lambda: 4 + self[4].get_len()) + self[4].set_blauto(lambda: (self[0].get_val() - 4) << 3) + def decode(self): return { 'PLMN' : self['PLMN'].decode(), + 'CAGOnly' : self['CAGOnly'].get_val(), 'CAGIDList' : self['CAGIDList'].get_val() } @@ -2747,27 +2752,116 @@ class RegistrationWaitRange(Envelope): # TS 24.501, 9.11.3.86 #------------------------------------------------------------------------------# +# Needed here to avoid circular imports +class _RouteSelectDescCompTimeWin(Envelope): + _GEN = ( + Envelope('StartTime', GEN=( + Uint32('Second'), + Uint32('Fraction') + )), + Envelope('StopTime', GEN=( + Uint32('Second'), + Uint32('Fraction') + )) + ) + def decode(self): + return { + 'StartTime' : {'Second':self[0][0].get_val(), 'Fraction':self[0][1].get_val()}, + 'StopTime' : {'Second':self[1][0].get_val(), 'Fraction':self[1][1].get_val()} + } + + +class CAGIDAdditionalInfo(Envelope): + _GEN = ( + Uint16('Len'), + Uint32('CAGID', rep=REPR_HEX), + Uint('spare', bl=1), + Uint('SVII', bl=6, dic={ + 0b000000: "Spare validity information is absent", + 0b111111: "Spare validity information is present" + }), + Uint('TVII', bl=1, dic={ + 0: "Time validity information field is absent", + 1: "Time validity information field is present" + }), + Uint8('TimePeriodCnt'), + Sequence('TimePeriods', GEN=_RouteSelectDescCompTimeWin()) + ) + + def __init__(self, *args, **kwargs): + Envelope.__init__(self, *args, **kwargs) + self[0].set_valauto(lambda: 6 + 16 * self[5].get_val()) + self[5].set_valauto(lambda: self[6].get_num()) + self[6].set_numauto(lambda: self[5].get_val()) + self[6].set_transauto(lambda: not self[4]) + + def decode(self): + return { + 'Len': self[0].get_val(), + 'CAGID': self[1].get_val(), + 'SVII': self[3].get_val(), + 'TVII': self[4].get_val(), + 'TimePeriodCnt': self[5].get_val(), + 'TimePeriods' : [x.decode() for x in self['TimePeriods']] + } + + +class CAGAdditionalInfoList(Envelope): + _GEN = ( + Uint16('Len'), + Sequence('CAGIDAdditionalInfos', GEN=CAGIDAdditionalInfo()) + ) + + def __init__(self, *args, **kwargs): + Envelope.__init__(self, *args, **kwargs) + self[0].set_valauto(lambda: self[1].get_len()) + def decode(self): + 12 + return {'Len': self['Len'].get_val(), + 'CAGIDAdditionalInfos': [x.decode() for x in self[1]]} + class ExtCAGInfo(Envelope): _GEN = ( - Uint8('Len'), + Uint16('Len'), PLMN(), - Uint('spare', bl=7, rep=REPR_HEX), + Uint('spare', bl=4, rep=REPR_HEX), + Uint('CAILI', val=0, bl=1, dic={ + 0: "CAG-ID with additional information list field is absent", + 1: "CAG-ID with additional information list field is present" + }), + Uint('LCI', val=0, bl=1, dic={ + 0: "Length of CAG-ID without additional information list field is absent", + 1: "Length of CAG-ID without additional information list field is present" + }), + Uint('spare', bl=1, rep=REPR_HEX), Uint('CAGOnly', val=0, bl=1, dic={ - 0 : 'UE allowed to access 5GS via non-CAG cells', - 1 : 'UE not allowed to access 5GS via non-CAG cells'}), - Array('CAGIDList', GEN=Uint32('CAGID', rep=REPR_HEX)) - ) - + 0: 'UE allowed to access 5GS via non-CAG cells', + 1: 'UE not allowed to access 5GS via non-CAG cells'}), + Uint16('LenCAGIDListWithout'), + Array('CAGIDList', GEN=Uint32('CAGID', rep=REPR_HEX)), + CAGAdditionalInfoList() + ) + def __init__(self, *args, **kwargs): Envelope.__init__(self, *args, **kwargs) - self[0].set_valauto(lambda: 4 + self[4].get_len()) - self[4].set_blauto(lambda: (self[0].get_val()-4)<<3) - + self[0].set_valauto(lambda: 4 + + (2 if self[4].get_val() else 0) + + self[8].get_len() + + self[9].get_len()) + self[4].set_blauto(lambda: (self[0].get_val() - 4) << 3) + self[7].set_transauto(lambda: not self[4].get_val()) + self[7].set_valauto(lambda: self[8].get_len()) + self[8].set_numauto(lambda: self[7].get_val()) + self[9].set_transauto(lambda: not self[3].get_val()) + def decode(self): return { 'PLMN' : self['PLMN'].decode(), + 'CAILI' : self['CAILI'].get_val(), + 'LCI' : self['LCI'].get_val(), 'CAGOnly' : self['CAGOnly'].get_val(), - 'CAGIDList' : self['CAGIDList'].get_val() + 'CAGIDList' : [cag.decode() for cag in self['CAGIDList']], + 'CAGAdditionalInfoList': self['CAGAdditionalInfoList'].decode() } From 8ca11c507ed7a96f8a8d623be1ac15090ea3296b Mon Sep 17 00:00:00 2001 From: MartinWho2 Date: Mon, 7 Jul 2025 15:57:33 +0900 Subject: [PATCH 2/4] remove incorrect set_blauto from previous version --- pycrate_mobile/TS24501_IE.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pycrate_mobile/TS24501_IE.py b/pycrate_mobile/TS24501_IE.py index eec27d4..3b0e908 100644 --- a/pycrate_mobile/TS24501_IE.py +++ b/pycrate_mobile/TS24501_IE.py @@ -2848,7 +2848,6 @@ def __init__(self, *args, **kwargs): (2 if self[4].get_val() else 0) + self[8].get_len() + self[9].get_len()) - self[4].set_blauto(lambda: (self[0].get_val() - 4) << 3) self[7].set_transauto(lambda: not self[4].get_val()) self[7].set_valauto(lambda: self[8].get_len()) self[8].set_numauto(lambda: self[7].get_val()) From 4ea44fb8532e00f2a3470450d9718a177f807222 Mon Sep 17 00:00:00 2001 From: MartinWho2 Date: Sat, 12 Jul 2025 16:29:43 +0900 Subject: [PATCH 3/4] Modified Nas KSI dict to include valid ones as well --- pycrate_mobile/TS24301_IE.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pycrate_mobile/TS24301_IE.py b/pycrate_mobile/TS24301_IE.py index 065d6e3..c2a9d82 100644 --- a/pycrate_mobile/TS24301_IE.py +++ b/pycrate_mobile/TS24301_IE.py @@ -588,11 +588,12 @@ class EPSUpdateType(Envelope): # NAS key set identifier # TS 24.301, 9.9.3.21 #------------------------------------------------------------------------------# - +_NAS_KSI_str = 'Key set identifier' +_NAS_KSI_dic = {i:_NAS_KSI_str for i in range(6)} | {7:'no key available'} class NAS_KSI(Envelope): _GEN = ( Uint('TSC', bl=1, dic={0:'native security context', 1:'mapped security context'}), - Uint('Value', bl=3, dic={7:'no key available'}) + Uint('Value', bl=3, dic=_NAS_KSI_dic) ) From 35f064d5880651ecf1f807a34125d4b64bdde6b2 Mon Sep 17 00:00:00 2001 From: MartinWho2 Date: Sat, 12 Jul 2025 16:31:04 +0900 Subject: [PATCH 4/4] Revert "Modified Nas KSI dict to include valid ones as well" This reverts commit 4ea44fb8532e00f2a3470450d9718a177f807222. --- pycrate_mobile/TS24301_IE.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pycrate_mobile/TS24301_IE.py b/pycrate_mobile/TS24301_IE.py index c2a9d82..065d6e3 100644 --- a/pycrate_mobile/TS24301_IE.py +++ b/pycrate_mobile/TS24301_IE.py @@ -588,12 +588,11 @@ class EPSUpdateType(Envelope): # NAS key set identifier # TS 24.301, 9.9.3.21 #------------------------------------------------------------------------------# -_NAS_KSI_str = 'Key set identifier' -_NAS_KSI_dic = {i:_NAS_KSI_str for i in range(6)} | {7:'no key available'} + class NAS_KSI(Envelope): _GEN = ( Uint('TSC', bl=1, dic={0:'native security context', 1:'mapped security context'}), - Uint('Value', bl=3, dic=_NAS_KSI_dic) + Uint('Value', bl=3, dic={7:'no key available'}) )