aboutsummaryrefslogtreecommitdiffstats
path: root/src/libosmo-pfcp/gen__pfcp_ies_auto.c
blob: 0dfb43c0669f07adb49f6dea1574d952ceb81dd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/* Tool to generate C source code of structs and IE arrays for de- and encoding PFCP messages. */
/*
 * (C) 2021-2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
 * All Rights Reserved.
 *
 * Author: Neels Janosch Hofmeyr <nhofmeyr@sysmocom.de>
 *
 * SPDX-License-Identifier: GPL-2.0+
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdbool.h>
#include <stdio.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/talloc.h>
#include <osmocom/gtlv/gtlv_gen.h>

#define O OSMO_GTLV_GEN_O
#define M OSMO_GTLV_GEN_M
#define O_MULTI OSMO_GTLV_GEN_O_MULTI
#define M_MULTI OSMO_GTLV_GEN_M_MULTI
#define ALL_FROM_NAME osmo_gtlv_gen_ie_auto

#define Ms(MEMB_NAME) M(MEMB_NAME, #MEMB_NAME)
#define Os(MEMB_NAME) O(MEMB_NAME, #MEMB_NAME)
#define O_MULTIs(N, MEMB_NAME) O_MULTI(N, MEMB_NAME, #MEMB_NAME)
#define M_MULTIs(N, M, MEMB_NAME) M_MULTI(N, M, MEMB_NAME, #MEMB_NAME)

static const struct osmo_gtlv_gen_ie recovery_time_stamp = {
	"uint32_t",
	.dec_enc = "32be",
	.spec_ref = "7.4.2",
};

static const struct osmo_gtlv_gen_ie cause = {
	"enum osmo_pfcp_cause",
	.spec_ref = "8.2.1",
};

static const struct osmo_gtlv_gen_ie offending_ie = {
	.decoded_type = "enum osmo_pfcp_iei",
	.spec_ref = "8.2.22",
};

static const struct osmo_gtlv_gen_ie f_seid = {
	.tag_name = "f_seid",
	.spec_ref = "8.2.37",
};

static const struct osmo_gtlv_gen_ie pdr_id = {
	.decoded_type = "uint16_t",
	.dec_enc = "16be",
	.spec_ref = "8.2.36",
};

static const struct osmo_gtlv_gen_ie precedence = {
	.decoded_type = "uint32_t",
	.dec_enc = "32be",
	.spec_ref = "8.2.11",
};

static const struct osmo_gtlv_gen_ie source_iface = {
	.decoded_type = "enum osmo_pfcp_source_iface",
	.spec_ref = "8.2.2",
};

static const struct osmo_gtlv_gen_ie f_teid = {
	.tag_name = "f_teid",
	.spec_ref = "8.2.3",
};

static const struct osmo_gtlv_gen_ie traffic_endpoint_id = {
	.tag_name = "traffic_endpoint_id",
	.decoded_type = "uint8_t",
	.dec_enc = "8",
	.spec_ref = "8.2.92",
};

static const struct osmo_gtlv_gen_ie iface_type = {
	.decoded_type = "enum osmo_pfcp_3gpp_iface_type",
	.tag_name = "3gpp_iface_type",
	.spec_ref = "8.2.118",
};

static const struct osmo_gtlv_gen_ie_o ies_in_pdi[] = {
	Ms(source_iface),
	O(f_teid, "local_f_teid"),
	O(ALL_FROM_NAME, "ue_ip_address"),
	Os(traffic_endpoint_id),
	O(iface_type, "source_iface_type"),
	{}
};

static const struct osmo_gtlv_gen_ie pdi = {
	.nested_ies = ies_in_pdi,
	.spec_ref = "7.5.2.2-2",
};

static const struct osmo_gtlv_gen_ie far_id = {
	.decoded_type = "uint32_t",
	.dec_enc = "32be",
	.spec_ref = "8.2.74",
};

static const struct osmo_gtlv_gen_ie_o ies_in_create_pdr[] = {
	Ms(pdr_id),
	Ms(precedence),
	Ms(pdi),
	O(ALL_FROM_NAME, "outer_header_removal"),
	Os(far_id),
	O(ALL_FROM_NAME, "activate_predefined_rules"),
	{}
};

static const struct osmo_gtlv_gen_ie create_pdr = {
	.nested_ies = ies_in_create_pdr,
	.spec_ref = "7.5.2.2",
};

static const struct osmo_gtlv_gen_ie_o ies_in_created_pdr[] = {
	Ms(pdr_id),
	O(f_teid, "local_f_teid"),
	{}
};

static const struct osmo_gtlv_gen_ie created_pdr = {
	.nested_ies = ies_in_created_pdr,
	.spec_ref = "7.5.3.2",
};

static const struct osmo_gtlv_gen_ie_o ies_in_upd_pdr[] = {
	Ms(pdr_id),
	O(ALL_FROM_NAME, "outer_header_removal"),
	Os(pdi),
	Os(far_id),
	O(ALL_FROM_NAME, "activate_predefined_rules"),
	{}
};

static const struct osmo_gtlv_gen_ie upd_pdr = {
	.nested_ies = ies_in_upd_pdr,
	.spec_ref = "7.5.4.2",
};

static const struct osmo_gtlv_gen_ie_o ies_in_updated_pdr[] = {
	Ms(pdr_id),
	O(f_teid, "local_f_teid"),
	{}
};

static const struct osmo_gtlv_gen_ie updated_pdr = {
	.nested_ies = ies_in_updated_pdr,
	.spec_ref = "7.5.9.3",
};

static const struct osmo_gtlv_gen_ie_o ies_in_remove_pdr[] = {
	Ms(pdr_id),
	{}
};

static const struct osmo_gtlv_gen_ie remove_pdr = {
	.nested_ies = ies_in_remove_pdr,
	.spec_ref = "7.5.4.6",
};

static const struct osmo_gtlv_gen_ie destination_iface = {
	.decoded_type = "enum osmo_pfcp_dest_iface",
	.dec_enc = "dest_iface",
	.spec_ref = "8.2.24",
};

static const struct osmo_gtlv_gen_ie_o ies_in_forw_params[] = {
	Ms(destination_iface),
	O(ALL_FROM_NAME, "network_inst"),
	O(ALL_FROM_NAME, "outer_header_creation"),
	O(traffic_endpoint_id, "linked_te_id"),
	O(iface_type, "destination_iface_type"),
	{}
};

static const struct osmo_gtlv_gen_ie forw_params = {
	.nested_ies = ies_in_forw_params,
	.spec_ref = "7.5.2.3-2",
};

static const struct osmo_gtlv_gen_ie_o ies_in_upd_forw_params[] = {
	Os(destination_iface),
	O(ALL_FROM_NAME, "network_inst"),
	O(ALL_FROM_NAME, "outer_header_creation"),
	O(traffic_endpoint_id, "linked_te_id"),
	O(iface_type, "destination_iface_type"),
	{}
};

static const struct osmo_gtlv_gen_ie upd_forw_params = {
	.nested_ies = ies_in_upd_forw_params,
	.spec_ref = "7.5.4.3-2",
};

static const struct osmo_gtlv_gen_ie_o ies_in_create_far[] = {
	Ms(far_id),
	M(ALL_FROM_NAME, "apply_action"),
	Os(forw_params),
	{}
};

static const struct osmo_gtlv_gen_ie create_far = {
	.nested_ies = ies_in_create_far,
	.spec_ref = "7.5.2.3",
};

static const struct osmo_gtlv_gen_ie_o ies_in_remove_far[] = {
	Ms(far_id),
	{}
};

static const struct osmo_gtlv_gen_ie remove_far = {
	.nested_ies = ies_in_remove_far,
	.spec_ref = "7.5.4.6",
};

static const struct osmo_gtlv_gen_ie_o ies_in_upd_far[] = {
	Ms(far_id),
	O(ALL_FROM_NAME, "apply_action"),
	Os(upd_forw_params),
	{}
};

static const struct osmo_gtlv_gen_ie upd_far = {
	.nested_ies = ies_in_upd_far,
	.spec_ref = "7.5.4.3",
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_heartbeat_req[] = {
	Ms(recovery_time_stamp),
	{}
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_heartbeat_resp[] = {
	Ms(recovery_time_stamp),
	{}
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_assoc_setup_req[] = {
	M(ALL_FROM_NAME, "node_id"),
	Ms(recovery_time_stamp),
	O(ALL_FROM_NAME, "up_function_features"),
	O(ALL_FROM_NAME, "cp_function_features"),
	{}
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_assoc_setup_resp[] = {
	M(ALL_FROM_NAME, "node_id"),
	Ms(cause),
	Ms(recovery_time_stamp),
	O(ALL_FROM_NAME, "up_function_features"),
	O(ALL_FROM_NAME, "cp_function_features"),
	{}
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_assoc_release_req[] = {
	M(ALL_FROM_NAME, "node_id"),
	{}
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_assoc_release_resp[] = {
	M(ALL_FROM_NAME, "node_id"),
	Ms(cause),
	{}
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_session_est_req[] = {
	M(ALL_FROM_NAME, "node_id"),
	O(f_seid, "cp_f_seid"),
	M_MULTIs(32, 1, create_pdr),
	M_MULTI(32, 1, create_far, "create_far"),
	{}
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_session_est_resp[] = {
	M(ALL_FROM_NAME, "node_id"),
	Ms(cause),
	Os(offending_ie),
	O(f_seid, "up_f_seid"),
	O_MULTIs(32, created_pdr),
	{}
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_session_mod_req[] = {
	O(f_seid, "cp_f_seid"),
	O_MULTIs(32, remove_pdr),
	O_MULTIs(32, remove_far),
	O_MULTIs(32, create_pdr),
	O_MULTIs(32, create_far),
	O_MULTIs(32, upd_pdr),
	O_MULTIs(32, upd_far),
	{}
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_session_mod_resp[] = {
	Ms(cause),
	Os(offending_ie),
	O_MULTIs(32, created_pdr),
	O_MULTIs(32, updated_pdr),
	{}
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_session_del_req[] = {
	/* no IEs */
	{}
};

static const struct osmo_gtlv_gen_ie_o ies_in_msg_session_del_resp[] = {
	Ms(cause),
	{}
};

#define MSG(NAME) { #NAME, ies_in_msg_##NAME }
static const struct osmo_gtlv_gen_msg pfcp_msg_defs[] = {
	MSG(heartbeat_req),
	MSG(heartbeat_resp),
	MSG(assoc_setup_req),
	MSG(assoc_setup_resp),
	MSG(assoc_release_req),
	MSG(assoc_release_resp),
	MSG(session_est_req),
	MSG(session_est_resp),
	MSG(session_mod_req),
	MSG(session_mod_resp),
	MSG(session_del_req),
	MSG(session_del_resp),
	{}
};

int main(int argc, const char **argv)
{
	struct osmo_gtlv_gen_cfg cfg = {
		.proto_name = "osmo_pfcp",
		.spec_ref_prefix = "3GPP TS 29.244 ",
		.message_type_enum = "enum osmo_pfcp_message_type",
		.message_type_prefix = "OSMO_PFCP_MSGT_",
		.tag_enum = "enum osmo_pfcp_iei",
		.tag_prefix = "OSMO_PFCP_IEI_",
		.decoded_type_prefix = "struct osmo_pfcp_ie_",
		.h_header = "#include <osmocom/pfcp/pfcp_ies_custom.h>",
		.c_header = "#include <osmocom/pfcp/pfcp_ies_auto.h>",
		.msg_defs = pfcp_msg_defs,
		.add_enc_to_str = true,
	};
	return osmo_gtlv_gen_main(&cfg, argc, argv);
}