Skip to content

Commit 32211b4

Browse files
APCO, PrivateExtension & ULI-Timestamp IE (#2761)
* APCO IE; PrivateExtension IE * Add tests for APCO * Add ULI TImestamp * Fix flake8 error * fix flake8 error-2 * Change extension and timestamp to lowercase * Update gtp_v2.uts * Fix apco test
1 parent c03d8d4 commit 32211b4

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

scapy/contrib/gtp_v2.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@
240240
136: "FQDN",
241241
145: "UCI",
242242
161: "Max MBR/APN-AMBR (MMBR)",
243+
163: "Additional Protocol Configuration Options",
244+
170: "ULI Timestamp",
243245
172: "RAN/NAS Cause",
244246
197: "Extended Protocol Configuration Options",
245247
202: "UP Function Selection Indication Flags",
@@ -444,6 +446,16 @@ class IE_ULI(gtp.IE_Base):
444446
]
445447

446448

449+
class IE_ULI_Timestamp(gtp.IE_Base):
450+
name = "IE ULI Timestamp"
451+
fields_desc = [
452+
ByteEnumField("ietype", 170, IEType),
453+
ShortField("length", None),
454+
BitField("CR_flag", 0, 4),
455+
BitField("instance", 0, 4),
456+
XIntField("timestamp", 0)]
457+
458+
447459
# 3GPP TS 29.274 v12.12.0 section 8.22
448460
INTERFACE_TYPES = {
449461
0: "S1-U eNodeB GTP-U interface",
@@ -1291,6 +1303,19 @@ class IE_EPCO(gtp.IE_Base):
12911303
length_from=lambda pkt: pkt.length - 1)]
12921304

12931305

1306+
class IE_APCO(gtp.IE_Base):
1307+
name = "IE Additional Protocol Configuration Options"
1308+
fields_desc = [ByteEnumField("ietype", 163, IEType),
1309+
ShortField("length", None),
1310+
BitField("CR_flag", 0, 4),
1311+
BitField("instance", 0, 4),
1312+
BitField("extension", 0, 1),
1313+
BitField("SPARE", 0, 4),
1314+
BitField("PPP", 0, 3),
1315+
PacketListField("Protocols", None, PCO_protocol_dispatcher,
1316+
length_from=lambda pkt: pkt.length - 1)]
1317+
1318+
12941319
class IE_PAA(gtp.IE_Base):
12951320
name = "IE PAA"
12961321
fields_desc = [ByteEnumField("ietype", 79, IEType),
@@ -1454,10 +1479,8 @@ class IE_PrivateExtension(gtp.IE_Base):
14541479
BitField("SPARE", 0, 4),
14551480
BitField("instance", 0, 4),
14561481
ShortEnumField("enterprisenum", None, IANA_ENTERPRISE_NUMBERS),
1457-
]
1458-
1459-
def extract_padding(self, s):
1460-
return s[:self.length], ''
1482+
StrLenField("proprietaryvalue", "",
1483+
length_from=lambda x: x.length - 2)]
14611484

14621485

14631486
ietypecls = {1: IE_IMSI,
@@ -1493,6 +1516,8 @@ def extract_padding(self, s):
14931516
136: IE_FQDN,
14941517
145: IE_UCI,
14951518
161: IE_MMBR,
1519+
163: IE_APCO,
1520+
170: IE_ULI_Timestamp,
14961521
172: IE_Ran_Nas_Cause,
14971522
197: IE_EPCO,
14981523
202: IE_UPF_SelInd_Flags,

test/contrib/gtp_v2.uts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ ie.Protocols[0].type == 27
175175
ie = IE_EPCO(Protocols=[PCO_S_Nssai(type=27, length=0)], ietype=197, length=4, CR_flag=0, instance=0, Extension=1, SPARE=0, PPP=0)
176176
ie.Extension == 1 and ie.ietype == 197 and ie.Protocols[0].type == 27 and ie.Protocols[0].length == 0
177177

178+
= IE_APCO, dissection
179+
h = "d89ef3da40e2fa163e956dce0800450000360001000040115d650a0f0f3d01020304084b084b00220000482000160000000100000100a3000a0080000c00001200000d00"
180+
gtp = Ether(hex_bytes(h))
181+
ie = gtp.IE_list[0]
182+
ie.Protocols[0].type == 12 and ie.Protocols[1].type == 18 and ie.Protocols[2].type == 13
183+
184+
= IE_APCO, basic instantiation
185+
ie = IE_APCO(Protocols=[PCO_P_CSCF_IPv4_Address_Request(address=None, type=12, length=0),PCO_P_CSCF_Re_selection_Support(type=18, length=0),PCO_DNS_Server_IPv4(address=None, type=13, length=0)], ietype=163, length=10, CR_flag=0, instance=0, extension=1, SPARE=0, PPP=0)
186+
ie.extension == 1 and ie.ietype == 163 and ie.length == 10 and ie.Protocols[0].type == 12 and ie.Protocols[1].type == 18 and ie.Protocols[2].type == 13
187+
178188
= IE_MMContext_EPS, dissection
179189
h = "d89ef3da40e2fa163e956dce08004500007f0001000040114bbd0a0a0f3d0a0f0b5b084b084b006b5a234883005f0000180f76d163006b0046008800910000020000021890aa80be385102083701a2907066f8bd9f2a28b717671c71c71c71c71c71c70100003d090002625a00028040000812345678900000000000000000006d000900880005000470677731"
180190
gtp = Ether(hex_bytes(h))
@@ -440,10 +450,16 @@ gtp = Ether(hex_bytes(h))
440450
isinstance(gtp.IE_list[0], IE_NotImplementedTLV)
441451
isinstance(gtp.IE_list[0].payload, NoPayload)
442452

443-
= IE_PrivateExtension
444-
h = "5001003500303900ff0031002b79deadbeef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef12345678"
445-
gtp = GTPHeader(hex_bytes(h))
446-
gtp.show2()
447-
(ie,) = gtp.IE_list
448-
ie.enterprisenum == 11129
449-
bytes_hex(ie.payload) == b"deadbeef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef12345678"
453+
= IE_PrivateExtension, dissection
454+
h = "d89ef3da40e2fa163e956dce08004500005b0001000040115d400a0f0f3d01020304084b084b00470000482000620000000100000100ff0015000137020046462d46462d46462d46462d46462d4646ff00160001370100000100000000000000000000000000000000"
455+
gtp = Ether(hex_bytes(h))
456+
ie1 = gtp.IE_list[0]
457+
ie2 = gtp.IE_list[1]
458+
ie1.enterprisenum == 311 and bytes_hex(ie1.proprietaryvalue) == b'020046462d46462d46462d46462d46462d4646'
459+
ie2.enterprisenum == 311 and bytes_hex(ie2.proprietaryvalue) == b'0100000100000000000000000000000000000000'
460+
461+
= IE_PrivateExtension, basic instantiation
462+
ie1 = IE_PrivateExtension(ietype=255, length=21, SPARE=0, instance=0, enterprisenum=311, proprietaryvalue=hex_bytes('020046462d46462d46462d46462d46462d4646'))
463+
ie2 = IE_PrivateExtension(ietype=255, length=22, SPARE=0, instance=0, enterprisenum=311, proprietaryvalue=hex_bytes('0100000100000000000000000000000000000000'))
464+
ie1.enterprisenum == 311 and bytes_hex(ie1.proprietaryvalue) == b'020046462d46462d46462d46462d46462d4646'
465+
ie2.enterprisenum == 311 and bytes_hex(ie2.proprietaryvalue) == b'0100000100000000000000000000000000000000'

0 commit comments

Comments
 (0)