blob: c7f2a456c7f262093a0ab2b7524968fee12793b9 [file] [log] [blame]
Pau Espin Pedrol4669b612023-10-23 17:43:14 +02001module DIAMETER_ts29_273_Templates {
2
3/* (C) 2023 by sysmocom s.f.m.c. GmbH <info@sysmocom.de
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 * Templates for AVPs and messages for TS 29.273
12 */
13
14import from General_Types all;
15import from DIAMETER_Types all;
16import from DIAMETER_Templates all;
Pau Espin Pedrol73996732023-10-23 18:16:21 +020017import from DIAMETER_rfc5447_Templates all;
Pau Espin Pedrol5154e352024-03-05 13:23:40 +010018import from DIAMETER_ts29_272_Templates all;
Pau Espin Pedrol4669b612023-10-23 17:43:14 +020019import from Osmocom_Types all;
20import from Misc_Helpers all;
21
22/* 3GPP TS 29.273 Section 8.2 */
23const uint32_t c_DIAMETER_3GPP_SWx_AID := 16777265;
24/* 3GPP TS 29.273 Section 9 */
25const uint32_t c_DIAMETER_3GPP_S6b_AID := 16777272;
26
Pau Espin Pedrol73996732023-10-23 18:16:21 +020027/* 5.2.3.3 MIP6-Feature-Vector bits */
28const uint64_t DIA_TS29_373_MIP6_Feature_Vector_PMIP6_SUPPORTED := hex2int('0000010000000000'H);
29const uint64_t DIA_TS29_373_MIP6_Feature_Vector_ASSIGN_LOCAL_IP := hex2int('0000080000000000'H);
30const uint64_t DIA_TS29_373_MIP6_Feature_Vector_MIP4_SUPPORTED := hex2int('0000100000000000'H);
31const uint64_t DIA_TS29_373_MIP6_Feature_Vector_OPTIMIZED_IDLE_MODE_MOBILITY := hex2int('0000200000000000'H);
32const uint64_t DIA_TS29_373_MIP6_Feature_Vector_GTPv2_SUPPORTED := hex2int('0000400000000000'H);
33
Pau Espin Pedrol4669b612023-10-23 17:43:14 +020034/*******************************
35 * SWx 3GPP TS 29.273 section 8
36 *******************************/
37
38/* SIP-Auth-Data-Item , 3GPP TS 29.273 8.2.3.9 */
39template (present) GenericAVP tr_AVP_3GPP_SIPAuthDataItem(template (present) uint32_t num := ?) := {
40 avp := {
41 avp_header := tr_DIA_Hdr_3GPP(c_AVP_Code_CxDx_3GPP_SIP_Auth_Data_Item),
42 avp_data := {
43 avp_CxDx_3GPP_SIP_Auth_Data_Item := superset(
44 //tr_AVP_3GPP_SIPItemNumber(num), /* Optional */
45 tr_AVP_3GPP_SIPAuthScheme(?)//, /* Optional */
46 //tr_AVP_3GPP_SIPAuthenticate(?), /* Optional */
47 //tr_AVP_3GPP_SIPAuthorization(?), /* Optional */
48 //tr_AVP_3GPP_SIPAuthContext(?), /* Optional */
49 //tr_AVP_3GPP_ConfidentialityKey(?), /* Optional */
50 //tr_AVP_3GPP_IntegrityKey(?) /* Optional */
51 /* TODO:
52 [ SIP-Digest-Authenticate ]
53 [ Framed-IP-Address ]
54 [ Framed-IPv6-Prefix ]
55 [ Framed-Interface-Id ]
56 [ Line-Identifier ]
57 *[AVP]
58 */
59 )
60 }
61 }
62}
63template (value) GenericAVP ts_AVP_3GPP_SIPAuthDataItem(uint32_t num, OCT16 rand, OCT16 ik, OCT16 ck, OCT16 autn, OCT14 auts) := {
64 avp := {
65 avp_header := ts_DIA_Hdr_3GPP(c_AVP_Code_CxDx_3GPP_SIP_Auth_Data_Item),
66 avp_data := {
67 avp_CxDx_3GPP_SIP_Auth_Data_Item := {
68 ts_AVP_3GPP_SIPItemNumber(num),
69 ts_AVP_3GPP_SIPAuthScheme(char2oct("Digest-AKAv1-MD5")),
70 ts_AVP_3GPP_SIPAuthenticate(rand & autn),
71 ts_AVP_3GPP_SIPAuthorization(rand & auts),
72 ts_AVP_3GPP_SIPAuthContext(char2oct("foobar")),
73 ts_AVP_3GPP_ConfidentialityKey(ck),
74 ts_AVP_3GPP_IntegrityKey(ik)
75 /* TODO:
76 [ SIP-Digest-Authenticate ]
77 [ Framed-IP-Address ]
78 [ Framed-IPv6-Prefix ]
79 [ Framed-Interface-Id ]
80 [ Line-Identifier ]
81 *[AVP]
82 */
83 }
84 }
85 }
86}
87
88/* Multimedia-Auth-Request, 3GPP TS 29.273 8.2.2.1 Authentication Procedure */
89template (present) PDU_DIAMETER
90tr_DIA_SWx_MAR(template (present) hexstring imsi := ?,
91 template (present) octetstring sess_id := ?,
92 template (present) charstring orig_host := ?,
93 template (present) charstring orig_realm := ?,
94 template (present) charstring dest_realm := ?,
95 template (present) UINT32 hbh_id := ?,
96 template (present) UINT32 ete_id := ?) :=
97 tr_DIAMETER(flags := '1???????'B,
98 cmd_code := Multimedia_Auth,
99 app_id := int2oct(c_DIAMETER_3GPP_SWx_AID, 4),
100 hbh_id := hbh_id, ete_id := ete_id,
101 avps := superset(
102 tr_AVP_SessionId(sess_id),
103 tr_AVP_VendorSpecAppId(?, ?),
104 tr_AVP_AuthSessionState(NO_STATE_MAINTAINED),
105 tr_AVP_OriginHost(orig_host),
106 tr_AVP_OriginRealm(orig_realm),
107 tr_AVP_DestinationRealm(dest_realm),
108 tr_AVP_UserNameImsi(imsi),
109 tr_AVP_3GPP_SIPAuthDataItem(?),
110 tr_AVP_3GPP_SIPNumAuthDataItems(?)
111 ));
112
113/* Multimedia-Auth-Answer, 3GPP TS 29.273 8.2.2.1 Authentication Procedure */
114template (value) PDU_DIAMETER
115ts_DIA_SWx_MAA(template (value) hexstring imsi,
116 template (value) GenericAVP sip_auth_data_item,
117 template (value) uint32_t vendor_app_id := c_DIAMETER_3GPP_SWx_AID,
118 template (value) octetstring sess_id := c_def_sess_id,
119 template (value) charstring orig_host := "hss.localdomain",
120 template (value) charstring orig_realm := "localdomain",
121 template (value) UINT32 hbh_id := '00000000'O,
122 template (value) UINT32 ete_id := '00000000'O) :=
123 ts_DIAMETER(flags := '01000000'B,
124 cmd_code := Multimedia_Auth,
125 app_id := int2oct(c_DIAMETER_3GPP_SWx_AID, 4),
126 hbh_id := hbh_id,
127 ete_id := ete_id,
128 avps := {
129 ts_AVP_SessionId(sess_id),
130 ts_AVP_VendorSpecAppId(vendor_id_3GPP, valueof(vendor_app_id)),
131 ts_AVP_ResultCode(DIAMETER_SUCCESS),
132 ts_AVP_AuthSessionState(NO_STATE_MAINTAINED),
133 ts_AVP_OriginHost(orig_host),
134 ts_AVP_OriginRealm(orig_realm),
135 ts_AVP_UserNameImsi(valueof(imsi)),
136 sip_auth_data_item,
137 ts_AVP_3GPP_SIPNumAuthDataItems(1)
138 });
139
140/* Server-Assignment-Request,
141 * 3GPP TS 29.273 8.1.2.2.2 UE/PDN Registration/DeRegistration Notification
142 * 3GPP TS 29.273 8.2.2.3 Non-3GPP IP Access Registration Procedure */
143template (present) PDU_DIAMETER
144tr_DIA_SWx_SAR(template (present) hexstring imsi := ?,
145 template (present) octetstring sess_id := ?,
146 template (present) charstring orig_host := ?,
147 template (present) charstring orig_realm := ?,
148 template (present) charstring dest_realm := ?,
149 template (present) UINT32 hbh_id := ?,
150 template (present) UINT32 ete_id := ?,
151 template (present) CxDx_3GPP_Server_Assignment_Type server_ass_type := ?,
152 template (present) charstring service_selection := ?) :=
153 tr_DIAMETER(flags := '1???????'B,
154 cmd_code := Server_Assignment,
155 app_id := int2oct(c_DIAMETER_3GPP_SWx_AID, 4),
156 hbh_id := hbh_id, ete_id := ete_id,
157 avps := superset(
158 tr_AVP_SessionId(sess_id),
159 tr_AVP_VendorSpecAppId(?, ?),
160 tr_AVP_AuthSessionState(NO_STATE_MAINTAINED),
161 tr_AVP_OriginHost(orig_host),
162 tr_AVP_OriginRealm(orig_realm),
163 tr_AVP_DestinationRealm(dest_realm),
164 tr_AVP_UserNameImsi(imsi),
165 tr_AVP_3GPP_ServerAssignmentType(server_ass_type),
166 tr_AVP_ServiceSelection(service_selection)
167 ));
168
169/* Server-Assignment-Answer,
170 * 3GPP TS 29.273 8.1.2.2.2 UE/PDN Registration/DeRegistration Notification
171 * 3GPP TS 29.273 8.2.2.3 Non-3GPP IP Access Registration Procedure */
172template (value) PDU_DIAMETER
173ts_DIA_SWx_SAA(template (value) hexstring imsi,
174 template (value) uint32_t vendor_app_id := c_DIAMETER_3GPP_SWx_AID,
175 template (value) octetstring sess_id := c_def_sess_id,
176 template (value) charstring orig_host := "hss.localdomain",
177 template (value) charstring orig_realm := "localdomain",
178 template (value) UINT32 hbh_id := '00000000'O,
179 template (value) UINT32 ete_id := '00000000'O) :=
180 ts_DIAMETER(flags := '01000000'B,
181 cmd_code := Server_Assignment,
182 app_id := int2oct(c_DIAMETER_3GPP_SWx_AID, 4),
183 hbh_id := hbh_id,
184 ete_id := ete_id,
185 avps := {
186 ts_AVP_SessionId(sess_id),
187 ts_AVP_VendorSpecAppId(vendor_id_3GPP, valueof(vendor_app_id)),
188 ts_AVP_ResultCode(DIAMETER_SUCCESS),
189 ts_AVP_AuthSessionState(NO_STATE_MAINTAINED),
190 ts_AVP_OriginHost(orig_host),
191 ts_AVP_OriginRealm(orig_realm),
192 ts_AVP_UserNameImsi(valueof(imsi))
193 /* TODO:
194 * [ Non-3GPP-User-Data ]
195 * [ 3GPP-AAA-Server-Name ]
196 * [ OC-Supported-Features ]
197 * [ OC-OLR ] ]
198 * *[ Load ]
199 * *[ Supported-Features ]
200 */
201 });
202
203/*******************************
204 * S6b 3GPP TS 29.273 section 9
205 *******************************/
206
207 /* TS 29.273 9.2.2.5.1 AA-Request (AAR) */
Pau Espin Pedrol518e24b2024-02-23 17:45:08 +0100208template (present) PDU_DIAMETER
209tr_DIA_S6b_AAR(template (present) charstring username_nai := ?,
210 template (present) MIPv6_NONE_MIP6_Feature_Vector mip6_feat_vec := ?,
211 template (present) charstring apn := ?,
212 template (present) octetstring sess_id := ?,
213 template (present) charstring orig_host := ?,
214 template (present) charstring orig_realm := ?,
215 template (present) charstring dest_realm := ?,
216 template (present) UINT32 hbh_id := ?,
217 template (present) UINT32 ete_id := ?) :=
218 tr_DIAMETER(flags := '1???????'B,
219 cmd_code := Authorize_Authenticate,
220 app_id := int2oct(c_DIAMETER_3GPP_S6b_AID, 4),
221 hbh_id := hbh_id,
222 ete_id := ete_id,
223 avps := superset(
224 tr_AVP_SessionId(sess_id),
225 /* Optional: DRMP, */
226 tr_AVP_AuthAppId(int2oct(c_DIAMETER_3GPP_S6b_AID, 4)),
227 tr_AVP_OriginHost(orig_host),
228 tr_AVP_OriginRealm(orig_realm),
229 tr_AVP_DestinationRealm(dest_realm),
230 tr_AVP_AuthRequestType(AUTHORIZE_ONLY),
231 tr_AVP_UserName(char2oct_tmpl_present(username_nai)),
232 tr_AVP_MIP6FeatureVector(mip6_feat_vec),
233 tr_AVP_ServiceSelection(apn)
234 /* TODO: Lots other optional */
235 ));
236
Pau Espin Pedrol4669b612023-10-23 17:43:14 +0200237template (value) PDU_DIAMETER
Pau Espin Pedrol8586b262024-02-09 18:12:21 +0100238ts_DIA_S6b_AAR(template (value) charstring username_nai,
Pau Espin Pedrol73996732023-10-23 18:16:21 +0200239 template (value) MIPv6_NONE_MIP6_Feature_Vector mip6_feat_vec,
Pau Espin Pedrol2c2e1872023-10-23 18:31:03 +0200240 template (value) charstring apn,
Pau Espin Pedrol4669b612023-10-23 17:43:14 +0200241 template (value) octetstring sess_id := c_def_sess_id,
242 template (value) charstring orig_host := "pgw.localdomain",
243 template (value) charstring orig_realm := "localdomain",
244 template (value) charstring dest_realm := "localdomain",
245 template (value) UINT32 hbh_id := '00000000'O,
246 template (value) UINT32 ete_id := '00000000'O) :=
247 ts_DIAMETER(flags := '11000000'B,
248 cmd_code := Authorize_Authenticate,
249 app_id := int2oct(c_DIAMETER_3GPP_S6b_AID, 4),
250 hbh_id := hbh_id,
251 ete_id := ete_id,
252 avps := {
253 ts_AVP_SessionId(sess_id),
254 /* Optional: DRMP, */
255 ts_AVP_AuthAppId(int2oct(c_DIAMETER_3GPP_S6b_AID, 4)),
256 ts_AVP_OriginHost(orig_host),
257 ts_AVP_OriginRealm(orig_realm),
258 ts_AVP_DestinationRealm(dest_realm),
259 ts_AVP_AuthRequestType(AUTHORIZE_ONLY),
Pau Espin Pedrol8586b262024-02-09 18:12:21 +0100260 ts_AVP_UserName(char2oct(valueof(username_nai))),
Pau Espin Pedrol2c2e1872023-10-23 18:31:03 +0200261 ts_AVP_MIP6FeatureVector(mip6_feat_vec),
262 ts_AVP_ServiceSelection(valueof(apn))
Pau Espin Pedrol4669b612023-10-23 17:43:14 +0200263 /* TODO: Lots other optional */
264 });
265
266/* TS 29.273 9.2.2.2.2 AA-Answer (AAA) */
267template (present) PDU_DIAMETER
268tr_DIA_S6b_AAA(template (present) octetstring sess_id := ?,
269 template (present) charstring orig_host := ?,
270 template (present) charstring orig_realm := ?,
271 template (present) charstring dest_realm := ?,
272 template (present) UINT32 hbh_id := ?,
273 template (present) UINT32 ete_id := ?,
274 template (present) CxDx_3GPP_Server_Assignment_Type server_ass_type := ?,
275 template (present) charstring service_selection := ?) :=
276 tr_DIAMETER(flags := '0???????'B,
277 cmd_code := Authorize_Authenticate,
278 app_id := int2oct(c_DIAMETER_3GPP_S6b_AID, 4),
279 hbh_id := hbh_id, ete_id := ete_id,
280 avps := superset(
281 tr_AVP_SessionId(sess_id),
282 /* Optional: DRMP, */
283 tr_AVP_AuthAppId(int2oct(c_DIAMETER_3GPP_S6b_AID, 4)),
284 tr_AVP_AuthRequestType(AUTHORIZE_ONLY),
285 tr_AVP_ResultCode(DIAMETER_SUCCESS),
286 tr_AVP_OriginHost(orig_host),
287 tr_AVP_OriginRealm(orig_realm)
288 ));
289
Pau Espin Pedrol518e24b2024-02-23 17:45:08 +0100290template (value) PDU_DIAMETER
291ts_DIA_S6b_AAA(template (value) octetstring sess_id := c_def_sess_id,
292 template (value) charstring orig_host := "aaa.localdomain",
293 template (value) charstring orig_realm := "localdomain",
294 template (value) charstring dest_realm := "localdomain",
295 template (value) UINT32 hbh_id := '00000000'O,
296 template (value) UINT32 ete_id := '00000000'O) :=
297 ts_DIAMETER(flags := '01000000'B,
298 cmd_code := Authorize_Authenticate,
299 app_id := int2oct(c_DIAMETER_3GPP_S6b_AID, 4),
300 hbh_id := hbh_id, ete_id := ete_id,
301 avps := {
302 ts_AVP_SessionId(sess_id),
303 /* Optional: DRMP, */
304 ts_AVP_AuthAppId(int2oct(c_DIAMETER_3GPP_S6b_AID, 4)),
305 ts_AVP_AuthRequestType(AUTHORIZE_ONLY),
306 ts_AVP_ResultCode(DIAMETER_SUCCESS),
307 ts_AVP_OriginHost(orig_host),
308 ts_AVP_OriginRealm(orig_realm)
309 });
310
Pau Espin Pedrol4944a5c2024-01-24 17:23:01 +0100311 /* TS 29.273 9.2.2.3.1 Session-Termination-Request (STR) Command,
312 * Table 9.1.2.3.1/1: S6b Session Termination Request (STR), based on RFC 6733 8.4.1 */
313template (value) PDU_DIAMETER
314ts_DIA_S6b_STR(template (value) hexstring imsi,
315 template (value) BASE_NONE_Termination_Cause term_cause := DIAMETER_LOGOUT,
316 template (value) octetstring sess_id := c_def_sess_id,
317 template (value) charstring orig_host := "pgw.localdomain",
318 template (value) charstring orig_realm := "localdomain",
319 template (value) charstring dest_realm := "localdomain",
320 template (value) UINT32 hbh_id := '00000000'O,
321 template (value) UINT32 ete_id := '00000000'O) :=
322 ts_DIAMETER(flags := '11000000'B,
323 cmd_code := Session_Termination,
324 app_id := int2oct(c_DIAMETER_3GPP_S6b_AID, 4),
325 hbh_id := hbh_id,
326 ete_id := ete_id,
327 avps := {
328 ts_AVP_SessionId(sess_id),
329 /* Optional: DRMP */
330 ts_AVP_AuthAppId(int2oct(c_DIAMETER_3GPP_S6b_AID, 4)),
331 ts_AVP_OriginHost(orig_host),
332 ts_AVP_OriginRealm(orig_realm),
333 ts_AVP_DestinationRealm(dest_realm),
334 ts_AVP_TerminationCause(term_cause),
335 ts_AVP_UserNameImsi(valueof(imsi))
336 /* Optional: OC-Supported-Features */
337 });
338
339/* TS 29.273 9.2.2.3.2 Session-Termination-Answer (STA) Command,
340 * Table 9.1.2.3.1/2: S6b Session Termination Answer (STA), based on RFC 6733 8.4.2 */
341template (present) PDU_DIAMETER
342tr_DIA_S6b_STA(template (present) DIAMETER_Resultcode res_code := ?,
343 template (present) octetstring sess_id := ?,
344 template (present) charstring orig_host := ?,
345 template (present) charstring orig_realm := ?,
346 template (present) charstring dest_realm := ?,
347 template (present) UINT32 hbh_id := ?,
348 template (present) UINT32 ete_id := ?) :=
349 tr_DIAMETER(flags := '0???????'B,
350 cmd_code := Session_Termination,
351 app_id := int2oct(c_DIAMETER_3GPP_S6b_AID, 4),
352 hbh_id := hbh_id, ete_id := ete_id,
353 avps := superset(
354 tr_AVP_SessionId(sess_id),
355 /* Optional: DRMP */
356 tr_AVP_ResultCode(res_code),
357 tr_AVP_OriginHost(orig_host),
358 tr_AVP_OriginRealm(orig_realm)
359 /* Lots other Optional */
360 ));
361
Pau Espin Pedrol4669b612023-10-23 17:43:14 +0200362}