blob: 23b0053ba3f3024b5e21046182c8ceb9a80922bb [file] [log] [blame]
Harald Welte0f7d03a2019-07-16 19:43:32 +09001module GTPv2_Templates {
2
3/* (C) 2019 by Harald Welte <laforge@gnumonks.org>
4 * All rights reserved.
5 *
6 * Released under the terms of GNU General Public License, Version 2 or
7 * (at your option) any later version.
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11
12import from General_Types all;
13import from Osmocom_Types all;
14import from GTPv2_Types all;
15
16private function fs_GTP2C_t_bit(template (omit) OCT4 teid) return BIT1 {
17 if (istemplatekind(teid, "omit")) {
18 return '0'B;
19 } else {
20 return '1'B;
21 }
22}
23
24private function fs_GTP2C_p_bit(template (omit) PDU_GTPCv2 piggyback) return BIT1 {
25 if (istemplatekind(piggyback, "omit")) {
26 return '0'B;
27 } else {
28 return '1'B;
29 }
30}
31
32template (present) PDU_GTPCv2 tr_PDU_GTP2C(template OCT4 teid := ?,
33 template (present) GTPCv2_PDUs pdus := ?,
34 template PDU_GTPCv2 piggyback := omit) := {
35 spare := '000'B,
36 t_Bit := ?,
37 p_Bit := ?,
38 version := '010'B,
39 messageType := ?,
40 lengthf := ?,
41 tEID := teid,
42 sequenceNumber := ?,
43 spare3 := '00'O,
44 gtpcv2_pdu := pdus,
45 piggybackPDU_GTPCv2 := piggyback
46}
47
48
49/* 8.3 */
50template (value) IMSI ts_GTP2C_Imsi(template (value) hexstring imsi) := {
51 elementIdentifier := '01'O,
52 lengthIndicator := 0, /* overwritten */
53 instance := '0000'B,
54 spare := '0000'B,
55 iMSI_Value := imsi
56}
57template (present) IMSI tr_GTP2C_Imsi(template (present) hexstring imsi) := {
58 elementIdentifier := '01'O,
59 lengthIndicator := ?,
60 instance := ?,
61 spare := '0000'B,
62 iMSI_Value := imsi
63}
64
65/* 8.4-1 */
66/*
67type enumerated GTP2C_Cause {
68 Local_Detach (2),
69 Complete_Detach (3),
70 RAT_changed_from_3GPP_to_Non_3GPP (4),
71 ISR_deactivation (5),
72 Error_Ind_from_RNC_eNB_SGSN_MME (5),
73 IMSI_Detach_Only (7),
74 Reactivation_Required (8),
75}
76*/
77
78const integer c_GTP2C_Cause_LocalDetach := 1;
79
80/* 8.4 */
81template (value) Cause ts_GTP2C_Cause(template (value) OCT1 cause,
82 template (value) BIT1 cs) := {
83 elementIdentifier := '02'O,
84 lengthIndicator := 0, /* overwritten */
85 instance := '0000'B,
86 spare := '0000'B,
87 causeValue := cause,
88 cS := cs,
89 bCE := '0'B,
90 pCE := '0'B,
91 spare2 := '00000'B,
92 typeOfOffendingIE := omit,
93 lengthIndicator2 := omit,
94 instanceOfOffendingIE := omit,
95 spare3 := omit
96}
97template (present) Cause tr_GTP2C_Cause(template (present) OCT1 cause) := {
98 elementIdentifier := '02'O,
99 lengthIndicator := ?,
100 instance := ?,
101 spare := '0000'B,
102 causeValue := cause,
103 cS := ?,
104 bCE := ?,
105 pCE := ?,
106 spare2 := '00000'B,
107 typeOfOffendingIE := *,
108 lengthIndicator2 := *,
109 instanceOfOffendingIE := *,
110 spare3 := *
111}
112
113/* 8.5 */
114template (value) AccessPointName ts_GTP2C_APN(template (value) octetstring apn) := {
115 elementIdentifier := '48'O,
116 lengthIndicator := 0, /* overwritten */
117 instance := '0000'B,
118 spare := '0000'B,
119 aPN_Value := apn
120}
121template (present) AccessPointName tr_GTP2C_APN(template (present) octetstring apn) := {
122 elementIdentifier := '48'O,
123 lengthIndicator := ?,
124 instance := ?,
125 spare := '0000'B,
126 aPN_Value := apn
127}
128
129/* 8.14 */
130template (value) PDN_AddressAllocation
131ts_GTP2C_PdnAddrAlloc(template (value) BIT3 pdn_type,
132 template (value) PDN_Address_and_Prefix addr_pfx) := {
133 elementIdentifier := '4F'O,
134 lengthIndicator := 0, /* overwritten */
135 instance := '0000'B,
136 spare := '0000'B,
137 pDN_Type := pdn_type,
138 spare2 := '00000'B,
139 pDN_Address_and_Prefix := addr_pfx
140}
141template (present) PDN_AddressAllocation
142tr_GTP2C_PdnAddrAlloc(template (present) BIT3 pdn_type,
143 template (present) PDN_Address_and_Prefix addr_pfx) := {
144 elementIdentifier := '4F'O,
145 lengthIndicator := ?,
146 instance := ?,
147 spare := '0000'B,
148 pDN_Type := pdn_type,
149 spare2 := '00000'B,
150 pDN_Address_and_Prefix := addr_pfx
151}
152template (value) PDN_AddressAllocation
153ts_GTP2C_PdnAddrAlloc_v4(template (value) OCT4 addr) :=
154 ts_GTP2C_PdnAddrAlloc('001'B, {iPv4_Address:=addr});
155template (present) PDN_AddressAllocation
156tr_GTP2C_PdnAddrAlloc_v4(template (present) OCT4 addr) :=
157 ts_GTP2C_PdnAddrAlloc('001'B, {iPv4_Address:=addr});
158
159/* 8.17 */
160template (value) RAT_Type ts_GTP2C_RatType(template (value) integer rat) := {
161 elementIdentifier := '53'O,
162 lengthIndicator := 0, /* overwritten */
163 instance := '0000'B,
164 spare := '0000'B,
165 rAT_TypeValue := rat,
166 additionalOctets := omit
167}
168template (present) RAT_Type tr_GTP2C_RatType(template (present) integer rat) := {
169 elementIdentifier := '53'O,
170 lengthIndicator := ?,
171 instance := ?,
172 spare := '0000'B,
173 rAT_TypeValue := rat,
174 additionalOctets := *
175}
176
177
178/* 8.22 */
179private function f_bit4oct(template (omit) octetstring os) return BIT1
180{
181 if (istemplatekind(os, "omit")) {
182 return '0'B;
183 } else {
184 return '1'B;
185 }
186}
187template (value) FullyQualifiedTEID
188ts_GTP2C_FTEID(integer if_type, OCT4 teid, template (omit) OCT4 v4_addr := omit,
189 template (omit) OCT16 v6_addr := omit) := {
190 elementIdentifier := '57'O,
191 lengthIndicator := 0, /* overwritten */
192 instance := '0000'B,
193 spare := '0000'B,
194 interfaceType := if_type,
195 v6_Flag := f_bit4oct(v4_addr),
196 v4_Flag := f_bit4oct(v6_addr),
197 tEID_GRE_Key := teid,
198 iPv4_Address := v4_addr,
199 iPv6_Address := v6_addr,
200 additionalOctets := omit
201}
202template (present) FullyQualifiedTEID
203tr_GTP2C_FTEID(template (present) integer if_type, template (present) OCT4 teid,
204 template OCT4 v4_addr := omit,
205 template OCT16 v6_addr := omit) := {
206 elementIdentifier := '57'O,
207 lengthIndicator := ?,
208 instance := ?,
209 spare := '0000'B,
210 interfaceType := if_type,
211 v6_Flag := ?,
212 v4_Flag := ?,
213 tEID_GRE_Key := teid,
214 iPv4_Address := v4_addr,
215 iPv6_Address := v6_addr,
216 additionalOctets := omit
217}
218
219
220
221template (value) PDU_GTPCv2 ts_PDU_GTP2C(template (omit) OCT4 teid, template (value) OCT3 seq,
222 template (value) OCT1 msg_type,
223 template (value) GTPCv2_PDUs pdus,
224 template (omit) PDU_GTPCv2 piggyback := omit) := {
225 spare := '000'B,
226 t_Bit := fs_GTP2C_t_bit(teid),
227 p_Bit := fs_GTP2C_p_bit(piggyback),
228 version := '010'B,
229 messageType := msg_type,
230 lengthf := 0, /* overwritten */
231 tEID := teid,
232 sequenceNumber := seq,
233 spare3 := '00'O,
234 gtpcv2_pdu := pdus,
235 piggybackPDU_GTPCv2 := piggyback
236}
237
238
239template (present) PDU_GTPCv2
240tr_GTP2C_CreateSessionReq(template (present) hexstring imsi) := tr_PDU_GTP2C('00000000'O, {
241 createSessionRequest := {
242 iMSI := tr_GTP2C_Imsi(imsi),
243 mSISDN := *,
244 mEI := *,
245 userLocationInfo := ?,
246 servingNetwork := ?,
247 rAT_Type := tr_GTP2C_RatType(6),
248 indication := *,
249 fullyQualifiedTEID := ?,
250 accessPointName := tr_GTP2C_APN('012a'O), // '*'
251 selectionMode := ?,
252 pDN_Type := ?,
253 pDN_AddressAllocation := ?,
254 maxAPN_Restriction := ?,
255 ambr := *,
256 linkedEPS_Bearer_ID := omit,
257 trustedWLANModeIndication := omit,
258 protocolConfigOptions := omit,
259 bearerContextGrouped := ?,
260 traceInformation := *,
261 recovery := omit,
262 csid := omit,
263 uE_TimeZone := ?,
264 user_CSG_Information := omit,
265 chargingCharacteristics := ?,
266 lDN := omit,
267 signallingPriorityIndication := *,
268 iP_Addr := omit,
269 portNumber := omit,
270 aPCO := omit,
271 trustedWLANAccessNetworkIdentifier := omit,
272 cNOperatorSelectionEntity := omit,
273 presenceReportingAreaInformation := omit,
274 overloadControlInformationGrouped := omit,
275 originationTimeStamp := *,
276 maximumWaitTime := *,
277 wLANLocationTimestamp := omit,
278 nBIFOMContainer := omit,
279 remoteUEContextGrouped := *,
280 nodeIdentifier := *,
281 extendedProtocolConfigOptions := omit,
282 servingPLMNRateControl := omit,
283 counter := omit,
284 privateExtension := omit
285 }});
286
287template (value) PDU_GTPCv2
288ts_GTP2C_CreateSessionResp(template (value) FullyQualifiedTEID_List fteids,
289 template (value) PDN_AddressAllocation addr) :=
290ts_PDU_GTP2C('00000000'O, '000000'O, '20'O, {
291 createSessionResponse := {
292 cause := ts_GTP2C_Cause(int2oct(16, 1), '0'B),
293 changeReportingAction := omit,
294 cSG_InformationReportingAction := omit,
295 heNBInformationReporting := omit,
296 fullyQualifiedTEID := fteids,
297 pDN_AddressAllocation := addr,
298 aPN_Restriction := omit,
299 ambr := omit,
300 linkedEPS_Bearer_ID := omit,
301 protocolConfigOptions := omit,
302 bearerContextGrouped := omit,
303 recovery := omit,
304 chargingGatewayName := omit,
305 chargingGatewayAddress := omit,
306 csid := omit,
307 lDN := omit,
308 pGW_Back_OffTime := omit,
309 aPCO := omit,
310 trustedWLANIPv4Parameters := omit,
311 indicationFlags := omit,
312 presenceReportingAreaAction := omit,
313 loadControlInformationGrouped := omit,
314 overloadControlInformationGrouped := omit,
315 nBIFOMContainer := omit,
316 pDNConnectionChargingID := omit,
317 extendedProtocolConfigOptions := omit,
318 privateExtension := omit
319 }});
320
321
322
323}