Coverage Report

Created: 2025-07-11 06:44

/src/open5gs/lib/nas/eps/ies.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * The MIT License
3
 *
4
 * Copyright (C) 2019-2023 by Sukchan Lee <acetcom@gmail.com>
5
 *
6
 * This file is part of Open5GS.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining
9
 * a copy of this software and associated documentation files (the
10
 * "Software"), to deal in the Software without restriction, including
11
 * without limitation the rights to use, copy, modify, merge, publish,
12
 * distribute, sublicense, and/or sell copies of the Software, and to
13
 * permit persons to whom the Software is furnished to do so, subject to
14
 * the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be
17
 * included in all copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
 */
27
28
/*******************************************************************************
29
 * This file had been created by nas-message.py script v0.1.0
30
 * Please do not modify this file but regenerate it via script.
31
 * Created on: 2024-12-11 21:08:02.462921 by acetcom
32
 * from 24301-h90.docx
33
 ******************************************************************************/
34
35
#include "ogs-nas-eps.h"
36
37
int ogs_nas_eps_encode_optional_type(ogs_pkbuf_t *pkbuf, uint8_t type)
38
0
{
39
0
    int size = sizeof(uint8_t);
40
41
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
42
0
    memcpy(pkbuf->data - size, &type, size);
43
44
0
    return size;
45
0
}
46
/* 9.9.2.0 Additional information
47
 * O TLV 3-n */
48
int ogs_nas_eps_decode_additional_information(ogs_nas_additional_information_t *additional_information, ogs_pkbuf_t *pkbuf)
49
471
{
50
471
    int size = 0;
51
471
    ogs_nas_additional_information_t *source = NULL;
52
53
471
    if (pkbuf->len < 1) {
54
6
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
55
6
       return -1;
56
6
    }
57
58
465
    source = (ogs_nas_additional_information_t *)pkbuf->data;
59
60
465
    additional_information->length = source->length;
61
465
    size = additional_information->length + sizeof(additional_information->length);
62
63
465
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
64
1
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
65
1
       return -1;
66
1
    }
67
68
464
    if (sizeof(*additional_information) < size) return -1;
69
464
    memcpy(additional_information, pkbuf->data - size, size);
70
71
464
    ogs_trace("  ADDITIONAL_INFORMATION - ");
72
464
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
73
74
464
    return size;
75
464
}
76
77
int ogs_nas_eps_encode_additional_information(ogs_pkbuf_t *pkbuf, ogs_nas_additional_information_t *additional_information)
78
0
{
79
0
    int size = additional_information->length + sizeof(additional_information->length);
80
0
    ogs_nas_additional_information_t target;
81
82
0
    memcpy(&target, additional_information, sizeof(ogs_nas_additional_information_t));
83
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
84
0
    memcpy(pkbuf->data - size, &target, size);
85
86
0
    ogs_trace("  ADDITIONAL_INFORMATION - ");
87
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
88
89
0
    return size;
90
0
}
91
92
/* 9.9.2.0A Device properties
93
 * O TV 1 */
94
int ogs_nas_eps_decode_device_properties(ogs_nas_device_properties_t *device_properties, ogs_pkbuf_t *pkbuf)
95
2.63k
{
96
2.63k
    int size = sizeof(ogs_nas_device_properties_t);
97
98
2.63k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
99
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
100
0
       return -1;
101
0
    }
102
103
2.63k
    memcpy(device_properties, pkbuf->data - size, size);
104
105
2.63k
    ogs_trace("  DEVICE_PROPERTIES - ");
106
2.63k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
107
108
2.63k
    return size;
109
2.63k
}
110
111
int ogs_nas_eps_encode_device_properties(ogs_pkbuf_t *pkbuf, ogs_nas_device_properties_t *device_properties)
112
0
{
113
0
    int size = sizeof(ogs_nas_device_properties_t);
114
115
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
116
0
    memcpy(pkbuf->data - size, device_properties, size);
117
118
0
    ogs_trace("  DEVICE_PROPERTIES - ");
119
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
120
121
0
    return size;
122
0
}
123
124
/* 9.9.2.1 EPS bearer context status
125
 * O TLV 4 */
126
int ogs_nas_eps_decode_eps_bearer_context_status(ogs_nas_eps_bearer_context_status_t *eps_bearer_context_status, ogs_pkbuf_t *pkbuf)
127
866
{
128
866
    int size = 0;
129
866
    ogs_nas_eps_bearer_context_status_t *source = NULL;
130
131
866
    if (pkbuf->len < 1) {
132
9
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
133
9
       return -1;
134
9
    }
135
136
857
    source = (ogs_nas_eps_bearer_context_status_t *)pkbuf->data;
137
138
857
    eps_bearer_context_status->length = source->length;
139
857
    size = eps_bearer_context_status->length + sizeof(eps_bearer_context_status->length);
140
141
857
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
142
2
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
143
2
       return -1;
144
2
    }
145
146
855
    if (sizeof(*eps_bearer_context_status) < size) return -1;
147
853
    memcpy(eps_bearer_context_status, pkbuf->data - size, size);
148
149
853
    ogs_trace("  EPS_BEARER_CONTEXT_STATUS - ");
150
853
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
151
152
853
    return size;
153
855
}
154
155
int ogs_nas_eps_encode_eps_bearer_context_status(ogs_pkbuf_t *pkbuf, ogs_nas_eps_bearer_context_status_t *eps_bearer_context_status)
156
0
{
157
0
    int size = eps_bearer_context_status->length + sizeof(eps_bearer_context_status->length);
158
0
    ogs_nas_eps_bearer_context_status_t target;
159
160
0
    memcpy(&target, eps_bearer_context_status, sizeof(ogs_nas_eps_bearer_context_status_t));
161
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
162
0
    memcpy(pkbuf->data - size, &target, size);
163
164
0
    ogs_trace("  EPS_BEARER_CONTEXT_STATUS - ");
165
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
166
167
0
    return size;
168
0
}
169
170
/* 9.9.2.10 Supported Codec List
171
 * O TLV 5-n */
172
int ogs_nas_eps_decode_supported_codec_list(ogs_nas_supported_codec_list_t *supported_codec_list, ogs_pkbuf_t *pkbuf)
173
560
{
174
560
    int size = 0;
175
560
    ogs_nas_supported_codec_list_t *source = NULL;
176
177
560
    if (pkbuf->len < 1) {
178
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
179
7
       return -1;
180
7
    }
181
182
553
    source = (ogs_nas_supported_codec_list_t *)pkbuf->data;
183
184
553
    supported_codec_list->length = source->length;
185
553
    size = supported_codec_list->length + sizeof(supported_codec_list->length);
186
187
553
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
188
4
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
189
4
       return -1;
190
4
    }
191
192
549
    if (sizeof(*supported_codec_list) < size) return -1;
193
548
    memcpy(supported_codec_list, pkbuf->data - size, size);
194
195
548
    ogs_trace("  SUPPORTED_CODEC_LIST - ");
196
548
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
197
198
548
    return size;
199
549
}
200
201
int ogs_nas_eps_encode_supported_codec_list(ogs_pkbuf_t *pkbuf, ogs_nas_supported_codec_list_t *supported_codec_list)
202
0
{
203
0
    int size = supported_codec_list->length + sizeof(supported_codec_list->length);
204
0
    ogs_nas_supported_codec_list_t target;
205
206
0
    memcpy(&target, supported_codec_list, sizeof(ogs_nas_supported_codec_list_t));
207
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
208
0
    memcpy(pkbuf->data - size, &target, size);
209
210
0
    ogs_trace("  SUPPORTED_CODEC_LIST - ");
211
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
212
213
0
    return size;
214
0
}
215
216
/* 9.9.2.2 Location area identification
217
 * O TV 6 */
218
int ogs_nas_eps_decode_location_area_identification(ogs_nas_location_area_identification_t *location_area_identification, ogs_pkbuf_t *pkbuf)
219
1.34k
{
220
1.34k
    int size = sizeof(ogs_nas_location_area_identification_t);
221
222
1.34k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
223
11
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
224
11
       return -1;
225
11
    }
226
227
1.33k
    memcpy(location_area_identification, pkbuf->data - size, size);
228
229
1.33k
    location_area_identification->lac = be16toh(location_area_identification->lac);
230
231
1.33k
    ogs_trace("  LOCATION_AREA_IDENTIFICATION - ");
232
1.33k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
233
234
1.33k
    return size;
235
1.34k
}
236
237
int ogs_nas_eps_encode_location_area_identification(ogs_pkbuf_t *pkbuf, ogs_nas_location_area_identification_t *location_area_identification)
238
0
{
239
0
    int size = sizeof(ogs_nas_location_area_identification_t);
240
0
    ogs_nas_location_area_identification_t target;
241
242
0
    memcpy(&target, location_area_identification, size);
243
0
    target.lac = htobe16(location_area_identification->lac);
244
245
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
246
0
    memcpy(pkbuf->data - size, &target, size);
247
248
0
    ogs_trace("  LOCATION_AREA_IDENTIFICATION - ");
249
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
250
251
0
    return size;
252
0
}
253
254
/* 9.9.2.3 Mobile identity
255
 * O TLV 7-10 */
256
int ogs_nas_eps_decode_mobile_identity(ogs_nas_mobile_identity_t *mobile_identity, ogs_pkbuf_t *pkbuf)
257
1.12k
{
258
1.12k
    int size = 0;
259
1.12k
    ogs_nas_mobile_identity_t *source = NULL;
260
261
1.12k
    if (pkbuf->len < 1) {
262
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
263
7
       return -1;
264
7
    }
265
266
1.11k
    source = (ogs_nas_mobile_identity_t *)pkbuf->data;
267
268
1.11k
    mobile_identity->length = source->length;
269
1.11k
    size = mobile_identity->length + sizeof(mobile_identity->length);
270
271
1.11k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
272
8
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
273
8
       return -1;
274
8
    }
275
276
1.10k
    if (sizeof(*mobile_identity) < size) return -1;
277
1.10k
    memcpy(mobile_identity, pkbuf->data - size, size);
278
279
1.10k
    if (mobile_identity->tmsi.type == OGS_NAS_MOBILE_IDENTITY_TMSI) {
280
199
        mobile_identity->tmsi.tmsi = be32toh(mobile_identity->tmsi.tmsi);
281
199
    }
282
283
1.10k
    ogs_trace("  MOBILE_IDENTITY - ");
284
1.10k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
285
286
1.10k
    return size;
287
1.10k
}
288
289
int ogs_nas_eps_encode_mobile_identity(ogs_pkbuf_t *pkbuf, ogs_nas_mobile_identity_t *mobile_identity)
290
0
{
291
0
    int size = mobile_identity->length + sizeof(mobile_identity->length);
292
0
    ogs_nas_mobile_identity_t target;
293
294
0
    memcpy(&target, mobile_identity, sizeof(ogs_nas_mobile_identity_t));
295
0
    if (mobile_identity->tmsi.type == OGS_NAS_MOBILE_IDENTITY_TMSI) {
296
0
        target.tmsi.tmsi = htobe32(mobile_identity->tmsi.tmsi);
297
0
        target.tmsi.spare = 0xf;
298
0
    }
299
300
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
301
0
    memcpy(pkbuf->data - size, &target, size);
302
303
0
    ogs_trace("  MOBILE_IDENTITY - ");
304
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
305
306
0
    return size;
307
0
}
308
309
/* 9.9.2.4 Mobile station classmark 2
310
 * O TLV 5 */
311
int ogs_nas_eps_decode_mobile_station_classmark_2(ogs_nas_mobile_station_classmark_2_t *mobile_station_classmark_2, ogs_pkbuf_t *pkbuf)
312
546
{
313
546
    int size = 0;
314
546
    ogs_nas_mobile_station_classmark_2_t *source = NULL;
315
316
546
    if (pkbuf->len < 1) {
317
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
318
7
       return -1;
319
7
    }
320
321
539
    source = (ogs_nas_mobile_station_classmark_2_t *)pkbuf->data;
322
323
539
    mobile_station_classmark_2->length = source->length;
324
539
    size = mobile_station_classmark_2->length + sizeof(mobile_station_classmark_2->length);
325
326
539
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
327
6
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
328
6
       return -1;
329
6
    }
330
331
533
    if (sizeof(*mobile_station_classmark_2) < size) return -1;
332
528
    memcpy(mobile_station_classmark_2, pkbuf->data - size, size);
333
334
528
    ogs_trace("  MOBILE_STATION_CLASSMARK_2 - ");
335
528
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
336
337
528
    return size;
338
533
}
339
340
int ogs_nas_eps_encode_mobile_station_classmark_2(ogs_pkbuf_t *pkbuf, ogs_nas_mobile_station_classmark_2_t *mobile_station_classmark_2)
341
0
{
342
0
    int size = mobile_station_classmark_2->length + sizeof(mobile_station_classmark_2->length);
343
0
    ogs_nas_mobile_station_classmark_2_t target;
344
345
0
    memcpy(&target, mobile_station_classmark_2, sizeof(ogs_nas_mobile_station_classmark_2_t));
346
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
347
0
    memcpy(pkbuf->data - size, &target, size);
348
349
0
    ogs_trace("  MOBILE_STATION_CLASSMARK_2 - ");
350
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
351
352
0
    return size;
353
0
}
354
355
/* 9.9.2.5 Mobile station classmark 3
356
 * O TLV 2-34 */
357
int ogs_nas_eps_decode_mobile_station_classmark_3(ogs_nas_mobile_station_classmark_3_t *mobile_station_classmark_3, ogs_pkbuf_t *pkbuf)
358
488
{
359
488
    int size = 0;
360
488
    ogs_nas_mobile_station_classmark_3_t *source = NULL;
361
362
488
    if (pkbuf->len < 1) {
363
6
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
364
6
       return -1;
365
6
    }
366
367
482
    source = (ogs_nas_mobile_station_classmark_3_t *)pkbuf->data;
368
369
482
    mobile_station_classmark_3->length = source->length;
370
482
    size = mobile_station_classmark_3->length + sizeof(mobile_station_classmark_3->length);
371
372
482
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
373
1
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
374
1
       return -1;
375
1
    }
376
377
481
    if (sizeof(*mobile_station_classmark_3) < size) return -1;
378
480
    memcpy(mobile_station_classmark_3, pkbuf->data - size, size);
379
380
480
    ogs_trace("  MOBILE_STATION_CLASSMARK_3 - ");
381
480
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
382
383
480
    return size;
384
481
}
385
386
int ogs_nas_eps_encode_mobile_station_classmark_3(ogs_pkbuf_t *pkbuf, ogs_nas_mobile_station_classmark_3_t *mobile_station_classmark_3)
387
0
{
388
0
    int size = mobile_station_classmark_3->length + sizeof(mobile_station_classmark_3->length);
389
0
    ogs_nas_mobile_station_classmark_3_t target;
390
391
0
    memcpy(&target, mobile_station_classmark_3, sizeof(ogs_nas_mobile_station_classmark_3_t));
392
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
393
0
    memcpy(pkbuf->data - size, &target, size);
394
395
0
    ogs_trace("  MOBILE_STATION_CLASSMARK_3 - ");
396
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
397
398
0
    return size;
399
0
}
400
401
/* 9.9.2.8 PLMN list
402
 * O TLV 5-47 */
403
int ogs_nas_eps_decode_plmn_list(ogs_nas_plmn_list_t *plmn_list, ogs_pkbuf_t *pkbuf)
404
589
{
405
589
    int size = 0;
406
589
    ogs_nas_plmn_list_t *source = NULL;
407
408
589
    if (pkbuf->len < 1) {
409
8
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
410
8
       return -1;
411
8
    }
412
413
581
    source = (ogs_nas_plmn_list_t *)pkbuf->data;
414
415
581
    plmn_list->length = source->length;
416
581
    size = plmn_list->length + sizeof(plmn_list->length);
417
418
581
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
419
1
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
420
1
       return -1;
421
1
    }
422
423
580
    if (sizeof(*plmn_list) < size) return -1;
424
579
    memcpy(plmn_list, pkbuf->data - size, size);
425
426
579
    ogs_trace("  PLMN_LIST - ");
427
579
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
428
429
579
    return size;
430
580
}
431
432
int ogs_nas_eps_encode_plmn_list(ogs_pkbuf_t *pkbuf, ogs_nas_plmn_list_t *plmn_list)
433
0
{
434
0
    int size = plmn_list->length + sizeof(plmn_list->length);
435
0
    ogs_nas_plmn_list_t target;
436
437
0
    memcpy(&target, plmn_list, sizeof(ogs_nas_plmn_list_t));
438
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
439
0
    memcpy(pkbuf->data - size, &target, size);
440
441
0
    ogs_trace("  PLMN_LIST - ");
442
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
443
444
0
    return size;
445
0
}
446
447
/* 9.9.3.0A Additional update result
448
 * O TV 1 */
449
int ogs_nas_eps_decode_additional_update_result(ogs_nas_additional_update_result_t *additional_update_result, ogs_pkbuf_t *pkbuf)
450
6.58k
{
451
6.58k
    int size = sizeof(ogs_nas_additional_update_result_t);
452
453
6.58k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
454
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
455
0
       return -1;
456
0
    }
457
458
6.58k
    memcpy(additional_update_result, pkbuf->data - size, size);
459
460
6.58k
    ogs_trace("  ADDITIONAL_UPDATE_RESULT - ");
461
6.58k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
462
463
6.58k
    return size;
464
6.58k
}
465
466
int ogs_nas_eps_encode_additional_update_result(ogs_pkbuf_t *pkbuf, ogs_nas_additional_update_result_t *additional_update_result)
467
0
{
468
0
    int size = sizeof(ogs_nas_additional_update_result_t);
469
470
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
471
0
    memcpy(pkbuf->data - size, additional_update_result, size);
472
473
0
    ogs_trace("  ADDITIONAL_UPDATE_RESULT - ");
474
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
475
476
0
    return size;
477
0
}
478
479
/* 9.9.3.0B Additional update type
480
 * O TV 1 */
481
int ogs_nas_eps_decode_additional_update_type(ogs_nas_additional_update_type_t *additional_update_type, ogs_pkbuf_t *pkbuf)
482
8.16k
{
483
8.16k
    int size = sizeof(ogs_nas_additional_update_type_t);
484
485
8.16k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
486
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
487
0
       return -1;
488
0
    }
489
490
8.16k
    memcpy(additional_update_type, pkbuf->data - size, size);
491
492
8.16k
    ogs_trace("  ADDITIONAL_UPDATE_TYPE - ");
493
8.16k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
494
495
8.16k
    return size;
496
8.16k
}
497
498
int ogs_nas_eps_encode_additional_update_type(ogs_pkbuf_t *pkbuf, ogs_nas_additional_update_type_t *additional_update_type)
499
0
{
500
0
    int size = sizeof(ogs_nas_additional_update_type_t);
501
502
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
503
0
    memcpy(pkbuf->data - size, additional_update_type, size);
504
505
0
    ogs_trace("  ADDITIONAL_UPDATE_TYPE - ");
506
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
507
508
0
    return size;
509
0
}
510
511
/* 9.9.3.1 Authentication failure parameter
512
 * O TLV 16 */
513
int ogs_nas_eps_decode_authentication_failure_parameter(ogs_nas_authentication_failure_parameter_t *authentication_failure_parameter, ogs_pkbuf_t *pkbuf)
514
430
{
515
430
    int size = 0;
516
430
    ogs_nas_authentication_failure_parameter_t *source = NULL;
517
518
430
    if (pkbuf->len < 1) {
519
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
520
7
       return -1;
521
7
    }
522
523
423
    source = (ogs_nas_authentication_failure_parameter_t *)pkbuf->data;
524
525
423
    authentication_failure_parameter->length = source->length;
526
423
    size = authentication_failure_parameter->length + sizeof(authentication_failure_parameter->length);
527
528
423
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
529
1
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
530
1
       return -1;
531
1
    }
532
533
422
    if (sizeof(*authentication_failure_parameter) < size) return -1;
534
420
    memcpy(authentication_failure_parameter, pkbuf->data - size, size);
535
536
420
    ogs_trace("  AUTHENTICATION_FAILURE_PARAMETER - ");
537
420
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
538
539
420
    return size;
540
422
}
541
542
int ogs_nas_eps_encode_authentication_failure_parameter(ogs_pkbuf_t *pkbuf, ogs_nas_authentication_failure_parameter_t *authentication_failure_parameter)
543
0
{
544
0
    int size = authentication_failure_parameter->length + sizeof(authentication_failure_parameter->length);
545
0
    ogs_nas_authentication_failure_parameter_t target;
546
547
0
    memcpy(&target, authentication_failure_parameter, sizeof(ogs_nas_authentication_failure_parameter_t));
548
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
549
0
    memcpy(pkbuf->data - size, &target, size);
550
551
0
    ogs_trace("  AUTHENTICATION_FAILURE_PARAMETER - ");
552
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
553
554
0
    return size;
555
0
}
556
557
/* 9.9.3.10 EPS attach result
558
 * M V 1/2 */
559
int ogs_nas_eps_decode_eps_attach_result(ogs_nas_eps_attach_result_t *eps_attach_result, ogs_pkbuf_t *pkbuf)
560
368
{
561
368
    int size = sizeof(ogs_nas_eps_attach_result_t);
562
563
368
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
564
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
565
0
       return -1;
566
0
    }
567
568
368
    memcpy(eps_attach_result, pkbuf->data - size, size);
569
570
368
    ogs_trace("  EPS_ATTACH_RESULT - ");
571
368
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
572
573
368
    return size;
574
368
}
575
576
int ogs_nas_eps_encode_eps_attach_result(ogs_pkbuf_t *pkbuf, ogs_nas_eps_attach_result_t *eps_attach_result)
577
0
{
578
0
    int size = sizeof(ogs_nas_eps_attach_result_t);
579
0
    ogs_nas_eps_attach_result_t target;
580
581
0
    memcpy(&target, eps_attach_result, size);
582
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
583
0
    memcpy(pkbuf->data - size, &target, size);
584
585
0
    ogs_trace("  EPS_ATTACH_RESULT - ");
586
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
587
588
0
    return size;
589
0
}
590
591
/* 9.9.3.11 EPS attach type
592
 * M V 1/2 */
593
int ogs_nas_eps_decode_eps_attach_type(ogs_nas_eps_attach_type_t *eps_attach_type, ogs_pkbuf_t *pkbuf)
594
362
{
595
362
    int size = sizeof(ogs_nas_eps_attach_type_t);
596
597
362
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
598
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
599
0
       return -1;
600
0
    }
601
602
362
    memcpy(eps_attach_type, pkbuf->data - size, size);
603
604
362
    ogs_trace("  EPS_ATTACH_TYPE - ");
605
362
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
606
607
362
    return size;
608
362
}
609
610
int ogs_nas_eps_encode_eps_attach_type(ogs_pkbuf_t *pkbuf, ogs_nas_eps_attach_type_t *eps_attach_type)
611
0
{
612
0
    int size = sizeof(ogs_nas_eps_attach_type_t);
613
0
    ogs_nas_eps_attach_type_t target;
614
615
0
    memcpy(&target, eps_attach_type, size);
616
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
617
0
    memcpy(pkbuf->data - size, &target, size);
618
619
0
    ogs_trace("  EPS_ATTACH_TYPE - ");
620
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
621
622
0
    return size;
623
0
}
624
625
/* 9.9.3.12 EPS mobile identity
626
 * M LV 5-12 */
627
int ogs_nas_eps_decode_eps_mobile_identity(ogs_nas_eps_mobile_identity_t *eps_mobile_identity, ogs_pkbuf_t *pkbuf)
628
2.77k
{
629
2.77k
    int size = 0;
630
2.77k
    ogs_nas_eps_mobile_identity_t *source = NULL;
631
632
2.77k
    if (pkbuf->len < 1) {
633
9
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
634
9
       return -1;
635
9
    }
636
637
2.76k
    source = (ogs_nas_eps_mobile_identity_t *)pkbuf->data;
638
639
2.76k
    eps_mobile_identity->length = source->length;
640
2.76k
    size = eps_mobile_identity->length + sizeof(eps_mobile_identity->length);
641
642
2.76k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
643
9
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
644
9
       return -1;
645
9
    }
646
647
2.75k
    if (sizeof(*eps_mobile_identity) < size) return -1;
648
2.75k
    memcpy(eps_mobile_identity, pkbuf->data - size, size);
649
650
2.75k
    if (eps_mobile_identity->guti.type == OGS_NAS_EPS_MOBILE_IDENTITY_GUTI) {
651
355
        eps_mobile_identity->guti.mme_gid = be16toh(eps_mobile_identity->guti.mme_gid);
652
355
        eps_mobile_identity->guti.m_tmsi = be32toh(eps_mobile_identity->guti.m_tmsi);
653
355
    }
654
655
2.75k
    ogs_trace("  EPS_MOBILE_IDENTITY - ");
656
2.75k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
657
658
2.75k
    return size;
659
2.75k
}
660
661
int ogs_nas_eps_encode_eps_mobile_identity(ogs_pkbuf_t *pkbuf, ogs_nas_eps_mobile_identity_t *eps_mobile_identity)
662
0
{
663
0
    int size = eps_mobile_identity->length + sizeof(eps_mobile_identity->length);
664
0
    ogs_nas_eps_mobile_identity_t target;
665
666
0
    memcpy(&target, eps_mobile_identity, sizeof(ogs_nas_eps_mobile_identity_t));
667
0
    if (target.guti.type == OGS_NAS_EPS_MOBILE_IDENTITY_GUTI) {
668
0
        target.guti.spare = 0xf;
669
0
        target.guti.mme_gid = htobe16(eps_mobile_identity->guti.mme_gid);
670
0
        target.guti.m_tmsi = htobe32(eps_mobile_identity->guti.m_tmsi);
671
0
    }
672
673
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
674
0
    memcpy(pkbuf->data - size, &target, size);
675
676
0
    ogs_trace("  EPS_MOBILE_IDENTITY - ");
677
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
678
679
0
    return size;
680
0
}
681
682
/* 9.9.3.12A EPS network feature support
683
 * O TLV 3-4 */
684
int ogs_nas_eps_decode_eps_network_feature_support(ogs_nas_eps_network_feature_support_t *eps_network_feature_support, ogs_pkbuf_t *pkbuf)
685
725
{
686
725
    int size = 0;
687
725
    ogs_nas_eps_network_feature_support_t *source = NULL;
688
689
725
    if (pkbuf->len < 1) {
690
8
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
691
8
       return -1;
692
8
    }
693
694
717
    source = (ogs_nas_eps_network_feature_support_t *)pkbuf->data;
695
696
717
    eps_network_feature_support->length = source->length;
697
717
    size = eps_network_feature_support->length + sizeof(eps_network_feature_support->length);
698
699
717
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
700
9
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
701
9
       return -1;
702
9
    }
703
704
708
    if (sizeof(*eps_network_feature_support) < size) return -1;
705
705
    memcpy(eps_network_feature_support, pkbuf->data - size, size);
706
707
705
    ogs_trace("  EPS_NETWORK_FEATURE_SUPPORT - ");
708
705
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
709
710
705
    return size;
711
708
}
712
713
int ogs_nas_eps_encode_eps_network_feature_support(ogs_pkbuf_t *pkbuf, ogs_nas_eps_network_feature_support_t *eps_network_feature_support)
714
0
{
715
0
    int size = eps_network_feature_support->length + sizeof(eps_network_feature_support->length);
716
0
    ogs_nas_eps_network_feature_support_t target;
717
718
0
    memcpy(&target, eps_network_feature_support, sizeof(ogs_nas_eps_network_feature_support_t));
719
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
720
0
    memcpy(pkbuf->data - size, &target, size);
721
722
0
    ogs_trace("  EPS_NETWORK_FEATURE_SUPPORT - ");
723
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
724
725
0
    return size;
726
0
}
727
728
/* 9.9.3.13 EPS update result
729
 * M V 1/2 */
730
int ogs_nas_eps_decode_eps_update_result(ogs_nas_eps_update_result_t *eps_update_result, ogs_pkbuf_t *pkbuf)
731
705
{
732
705
    int size = sizeof(ogs_nas_eps_update_result_t);
733
734
705
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
735
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
736
0
       return -1;
737
0
    }
738
739
705
    memcpy(eps_update_result, pkbuf->data - size, size);
740
741
705
    ogs_trace("  EPS_UPDATE_RESULT - ");
742
705
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
743
744
705
    return size;
745
705
}
746
747
int ogs_nas_eps_encode_eps_update_result(ogs_pkbuf_t *pkbuf, ogs_nas_eps_update_result_t *eps_update_result)
748
0
{
749
0
    int size = sizeof(ogs_nas_eps_update_result_t);
750
0
    ogs_nas_eps_update_result_t target;
751
752
0
    memcpy(&target, eps_update_result, size);
753
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
754
0
    memcpy(pkbuf->data - size, &target, size);
755
756
0
    ogs_trace("  EPS_UPDATE_RESULT - ");
757
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
758
759
0
    return size;
760
0
}
761
762
/* 9.9.3.14 EPS update type
763
 * M V 1/2 */
764
int ogs_nas_eps_decode_eps_update_type(ogs_nas_eps_update_type_t *eps_update_type, ogs_pkbuf_t *pkbuf)
765
683
{
766
683
    int size = sizeof(ogs_nas_eps_update_type_t);
767
768
683
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
769
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
770
0
       return -1;
771
0
    }
772
773
683
    memcpy(eps_update_type, pkbuf->data - size, size);
774
775
683
    ogs_trace("  EPS_UPDATE_TYPE - ");
776
683
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
777
778
683
    return size;
779
683
}
780
781
int ogs_nas_eps_encode_eps_update_type(ogs_pkbuf_t *pkbuf, ogs_nas_eps_update_type_t *eps_update_type)
782
0
{
783
0
    int size = sizeof(ogs_nas_eps_update_type_t);
784
0
    ogs_nas_eps_update_type_t target;
785
786
0
    memcpy(&target, eps_update_type, size);
787
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
788
0
    memcpy(pkbuf->data - size, &target, size);
789
790
0
    ogs_trace("  EPS_UPDATE_TYPE - ");
791
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
792
793
0
    return size;
794
0
}
795
796
/* 9.9.3.15 ESM message container
797
 * M LV-E 5-n */
798
int ogs_nas_eps_decode_esm_message_container(ogs_nas_esm_message_container_t *esm_message_container, ogs_pkbuf_t *pkbuf)
799
1.07k
{
800
1.07k
    int size = 0;
801
1.07k
    ogs_nas_esm_message_container_t *source = NULL;
802
803
1.07k
    if (pkbuf->len < 2) {
804
19
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
805
19
       return -1;
806
19
    }
807
808
1.05k
    source = (ogs_nas_esm_message_container_t *)pkbuf->data;
809
810
1.05k
    esm_message_container->length = be16toh(source->length);
811
1.05k
    size = esm_message_container->length + sizeof(esm_message_container->length);
812
813
1.05k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
814
15
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
815
15
       return -1;
816
15
    }
817
818
1.04k
    esm_message_container->buffer = pkbuf->data - size + sizeof(esm_message_container->length);
819
820
1.04k
    ogs_trace("  ESM_MESSAGE_CONTAINER - ");
821
1.04k
    ogs_log_hexdump(OGS_LOG_TRACE, (void*)esm_message_container->buffer, esm_message_container->length);
822
823
1.04k
    return size;
824
1.05k
}
825
826
int ogs_nas_eps_encode_esm_message_container(ogs_pkbuf_t *pkbuf, ogs_nas_esm_message_container_t *esm_message_container)
827
0
{
828
0
    int size = 0;
829
0
    int target;
830
831
0
    ogs_assert(esm_message_container);
832
0
    ogs_assert(esm_message_container->buffer);
833
834
0
    size = sizeof(esm_message_container->length);
835
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
836
0
    target = htobe16(esm_message_container->length);
837
0
    memcpy(pkbuf->data - size, &target, size);
838
839
0
    size = esm_message_container->length;
840
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
841
0
    memcpy(pkbuf->data - size, esm_message_container->buffer, size);
842
843
0
    ogs_trace("  ESM_MESSAGE_CONTAINER - ");
844
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
845
846
0
    return esm_message_container->length + sizeof(esm_message_container->length);
847
0
}
848
849
/* 9.9.3.16 GPRS timer
850
 * M V 1 */
851
int ogs_nas_eps_decode_gprs_timer(ogs_nas_gprs_timer_t *gprs_timer, ogs_pkbuf_t *pkbuf)
852
2.30k
{
853
2.30k
    int size = sizeof(ogs_nas_gprs_timer_t);
854
855
2.30k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
856
12
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
857
12
       return -1;
858
12
    }
859
860
2.29k
    memcpy(gprs_timer, pkbuf->data - size, size);
861
862
2.29k
    ogs_trace("  GPRS_TIMER - ");
863
2.29k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
864
865
2.29k
    return size;
866
2.30k
}
867
868
int ogs_nas_eps_encode_gprs_timer(ogs_pkbuf_t *pkbuf, ogs_nas_gprs_timer_t *gprs_timer)
869
0
{
870
0
    int size = sizeof(ogs_nas_gprs_timer_t);
871
0
    ogs_nas_gprs_timer_t target;
872
873
0
    memcpy(&target, gprs_timer, size);
874
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
875
0
    memcpy(pkbuf->data - size, &target, size);
876
877
0
    ogs_trace("  GPRS_TIMER - ");
878
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
879
880
0
    return size;
881
0
}
882
883
/* 9.9.3.16A GPRS timer 2
884
 * O TLV 3 */
885
int ogs_nas_eps_decode_gprs_timer_2(ogs_nas_gprs_timer_2_t *gprs_timer_2, ogs_pkbuf_t *pkbuf)
886
2.68k
{
887
2.68k
    int size = 0;
888
2.68k
    ogs_nas_gprs_timer_2_t *source = NULL;
889
890
2.68k
    if (pkbuf->len < 1) {
891
12
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
892
12
       return -1;
893
12
    }
894
895
2.67k
    source = (ogs_nas_gprs_timer_2_t *)pkbuf->data;
896
897
2.67k
    gprs_timer_2->length = source->length;
898
2.67k
    size = gprs_timer_2->length + sizeof(gprs_timer_2->length);
899
900
2.67k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
901
11
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
902
11
       return -1;
903
11
    }
904
905
2.66k
    if (sizeof(*gprs_timer_2) < size) return -1;
906
2.66k
    memcpy(gprs_timer_2, pkbuf->data - size, size);
907
908
2.66k
    ogs_trace("  GPRS_TIMER_2 - ");
909
2.66k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
910
911
2.66k
    return size;
912
2.66k
}
913
914
int ogs_nas_eps_encode_gprs_timer_2(ogs_pkbuf_t *pkbuf, ogs_nas_gprs_timer_2_t *gprs_timer_2)
915
0
{
916
0
    int size = gprs_timer_2->length + sizeof(gprs_timer_2->length);
917
0
    ogs_nas_gprs_timer_2_t target;
918
919
0
    memcpy(&target, gprs_timer_2, sizeof(ogs_nas_gprs_timer_2_t));
920
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
921
0
    memcpy(pkbuf->data - size, &target, size);
922
923
0
    ogs_trace("  GPRS_TIMER_2 - ");
924
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
925
926
0
    return size;
927
0
}
928
929
/* 9.9.3.16B GPRS timer 3
930
 * O TLV 3 */
931
int ogs_nas_eps_decode_gprs_timer_3(ogs_nas_gprs_timer_3_t *gprs_timer_3, ogs_pkbuf_t *pkbuf)
932
2.21k
{
933
2.21k
    int size = 0;
934
2.21k
    ogs_nas_gprs_timer_3_t *source = NULL;
935
936
2.21k
    if (pkbuf->len < 1) {
937
10
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
938
10
       return -1;
939
10
    }
940
941
2.20k
    source = (ogs_nas_gprs_timer_3_t *)pkbuf->data;
942
943
2.20k
    gprs_timer_3->length = source->length;
944
2.20k
    size = gprs_timer_3->length + sizeof(gprs_timer_3->length);
945
946
2.20k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
947
8
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
948
8
       return -1;
949
8
    }
950
951
2.19k
    if (sizeof(*gprs_timer_3) < size) return -1;
952
2.18k
    memcpy(gprs_timer_3, pkbuf->data - size, size);
953
954
2.18k
    ogs_trace("  GPRS_TIMER_3 - ");
955
2.18k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
956
957
2.18k
    return size;
958
2.19k
}
959
960
int ogs_nas_eps_encode_gprs_timer_3(ogs_pkbuf_t *pkbuf, ogs_nas_gprs_timer_3_t *gprs_timer_3)
961
0
{
962
0
    int size = gprs_timer_3->length + sizeof(gprs_timer_3->length);
963
0
    ogs_nas_gprs_timer_3_t target;
964
965
0
    memcpy(&target, gprs_timer_3, sizeof(ogs_nas_gprs_timer_3_t));
966
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
967
0
    memcpy(pkbuf->data - size, &target, size);
968
969
0
    ogs_trace("  GPRS_TIMER_3 - ");
970
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
971
972
0
    return size;
973
0
}
974
975
/* 9.9.3.17 Identity type 2
976
 * M V 1/2 */
977
int ogs_nas_eps_decode_identity_type_2(ogs_nas_identity_type_2_t *identity_type_2, ogs_pkbuf_t *pkbuf)
978
8
{
979
8
    int size = sizeof(ogs_nas_identity_type_2_t);
980
981
8
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
982
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
983
0
       return -1;
984
0
    }
985
986
8
    memcpy(identity_type_2, pkbuf->data - size, size);
987
988
8
    ogs_trace("  IDENTITY_TYPE_2 - ");
989
8
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
990
991
8
    return size;
992
8
}
993
994
int ogs_nas_eps_encode_identity_type_2(ogs_pkbuf_t *pkbuf, ogs_nas_identity_type_2_t *identity_type_2)
995
0
{
996
0
    int size = sizeof(ogs_nas_identity_type_2_t);
997
0
    ogs_nas_identity_type_2_t target;
998
999
0
    memcpy(&target, identity_type_2, size);
1000
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1001
0
    memcpy(pkbuf->data - size, &target, size);
1002
1003
0
    ogs_trace("  IDENTITY_TYPE_2 - ");
1004
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1005
1006
0
    return size;
1007
0
}
1008
1009
/* 9.9.3.18 IMEISV request
1010
 * O TV 1 */
1011
int ogs_nas_eps_decode_imeisv_request(ogs_nas_imeisv_request_t *imeisv_request, ogs_pkbuf_t *pkbuf)
1012
439
{
1013
439
    int size = sizeof(ogs_nas_imeisv_request_t);
1014
1015
439
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1016
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1017
0
       return -1;
1018
0
    }
1019
1020
439
    memcpy(imeisv_request, pkbuf->data - size, size);
1021
1022
439
    ogs_trace("  IMEISV_REQUEST - ");
1023
439
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1024
1025
439
    return size;
1026
439
}
1027
1028
int ogs_nas_eps_encode_imeisv_request(ogs_pkbuf_t *pkbuf, ogs_nas_imeisv_request_t *imeisv_request)
1029
0
{
1030
0
    int size = sizeof(ogs_nas_imeisv_request_t);
1031
1032
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1033
0
    memcpy(pkbuf->data - size, imeisv_request, size);
1034
1035
0
    ogs_trace("  IMEISV_REQUEST - ");
1036
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1037
1038
0
    return size;
1039
0
}
1040
1041
/* 9.9.3.19 KSI and sequence number
1042
 * M V 1 */
1043
int ogs_nas_eps_decode_ksi_and_sequence_number(ogs_nas_ksi_and_sequence_number_t *ksi_and_sequence_number, ogs_pkbuf_t *pkbuf)
1044
3
{
1045
3
    int size = sizeof(ogs_nas_ksi_and_sequence_number_t);
1046
1047
3
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1048
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1049
0
       return -1;
1050
0
    }
1051
1052
3
    memcpy(ksi_and_sequence_number, pkbuf->data - size, size);
1053
1054
3
    ogs_trace("  KSI_AND_SEQUENCE_NUMBER - ");
1055
3
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1056
1057
3
    return size;
1058
3
}
1059
1060
int ogs_nas_eps_encode_ksi_and_sequence_number(ogs_pkbuf_t *pkbuf, ogs_nas_ksi_and_sequence_number_t *ksi_and_sequence_number)
1061
0
{
1062
0
    int size = sizeof(ogs_nas_ksi_and_sequence_number_t);
1063
0
    ogs_nas_ksi_and_sequence_number_t target;
1064
1065
0
    memcpy(&target, ksi_and_sequence_number, size);
1066
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1067
0
    memcpy(pkbuf->data - size, &target, size);
1068
1069
0
    ogs_trace("  KSI_AND_SEQUENCE_NUMBER - ");
1070
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1071
1072
0
    return size;
1073
0
}
1074
1075
/* 9.9.3.2 Authentication parameter AUTN
1076
 * M LV 17 */
1077
int ogs_nas_eps_decode_authentication_parameter_autn(ogs_nas_authentication_parameter_autn_t *authentication_parameter_autn, ogs_pkbuf_t *pkbuf)
1078
14
{
1079
14
    int size = 0;
1080
14
    ogs_nas_authentication_parameter_autn_t *source = NULL;
1081
1082
14
    if (pkbuf->len < 1) {
1083
1
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
1084
1
       return -1;
1085
1
    }
1086
1087
13
    source = (ogs_nas_authentication_parameter_autn_t *)pkbuf->data;
1088
1089
13
    authentication_parameter_autn->length = source->length;
1090
13
    size = authentication_parameter_autn->length + sizeof(authentication_parameter_autn->length);
1091
1092
13
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1093
1
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1094
1
       return -1;
1095
1
    }
1096
1097
12
    if (sizeof(*authentication_parameter_autn) < size) return -1;
1098
11
    memcpy(authentication_parameter_autn, pkbuf->data - size, size);
1099
1100
11
    ogs_trace("  AUTHENTICATION_PARAMETER_AUTN - ");
1101
11
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1102
1103
11
    return size;
1104
12
}
1105
1106
int ogs_nas_eps_encode_authentication_parameter_autn(ogs_pkbuf_t *pkbuf, ogs_nas_authentication_parameter_autn_t *authentication_parameter_autn)
1107
0
{
1108
0
    int size = authentication_parameter_autn->length + sizeof(authentication_parameter_autn->length);
1109
0
    ogs_nas_authentication_parameter_autn_t target;
1110
1111
0
    memcpy(&target, authentication_parameter_autn, sizeof(ogs_nas_authentication_parameter_autn_t));
1112
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1113
0
    memcpy(pkbuf->data - size, &target, size);
1114
1115
0
    ogs_trace("  AUTHENTICATION_PARAMETER_AUTN - ");
1116
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1117
1118
0
    return size;
1119
0
}
1120
1121
/* 9.9.3.20 MS network capability
1122
 * O TLV 4-10 */
1123
int ogs_nas_eps_decode_ms_network_capability(ogs_nas_ms_network_capability_t *ms_network_capability, ogs_pkbuf_t *pkbuf)
1124
648
{
1125
648
    int size = 0;
1126
648
    ogs_nas_ms_network_capability_t *source = NULL;
1127
1128
648
    if (pkbuf->len < 1) {
1129
5
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
1130
5
       return -1;
1131
5
    }
1132
1133
643
    source = (ogs_nas_ms_network_capability_t *)pkbuf->data;
1134
1135
643
    ms_network_capability->length = source->length;
1136
643
    size = ms_network_capability->length + sizeof(ms_network_capability->length);
1137
1138
643
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1139
8
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1140
8
       return -1;
1141
8
    }
1142
1143
635
    if (sizeof(*ms_network_capability) < size) return -1;
1144
632
    memcpy(ms_network_capability, pkbuf->data - size, size);
1145
1146
632
    ogs_trace("  MS_NETWORK_CAPABILITY - ");
1147
632
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1148
1149
632
    return size;
1150
635
}
1151
1152
int ogs_nas_eps_encode_ms_network_capability(ogs_pkbuf_t *pkbuf, ogs_nas_ms_network_capability_t *ms_network_capability)
1153
0
{
1154
0
    int size = ms_network_capability->length + sizeof(ms_network_capability->length);
1155
0
    ogs_nas_ms_network_capability_t target;
1156
1157
0
    memcpy(&target, ms_network_capability, sizeof(ogs_nas_ms_network_capability_t));
1158
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1159
0
    memcpy(pkbuf->data - size, &target, size);
1160
1161
0
    ogs_trace("  MS_NETWORK_CAPABILITY - ");
1162
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1163
1164
0
    return size;
1165
0
}
1166
1167
/* 9.9.3.20A MS network feature support
1168
 * O TV 1 */
1169
int ogs_nas_eps_decode_ms_network_feature_support(ogs_nas_ms_network_feature_support_t *ms_network_feature_support, ogs_pkbuf_t *pkbuf)
1170
1.98k
{
1171
1.98k
    int size = sizeof(ogs_nas_ms_network_feature_support_t);
1172
1173
1.98k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1174
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1175
0
       return -1;
1176
0
    }
1177
1178
1.98k
    memcpy(ms_network_feature_support, pkbuf->data - size, size);
1179
1180
1.98k
    ogs_trace("  MS_NETWORK_FEATURE_SUPPORT - ");
1181
1.98k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1182
1183
1.98k
    return size;
1184
1.98k
}
1185
1186
int ogs_nas_eps_encode_ms_network_feature_support(ogs_pkbuf_t *pkbuf, ogs_nas_ms_network_feature_support_t *ms_network_feature_support)
1187
0
{
1188
0
    int size = sizeof(ogs_nas_ms_network_feature_support_t);
1189
1190
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1191
0
    memcpy(pkbuf->data - size, ms_network_feature_support, size);
1192
1193
0
    ogs_trace("  MS_NETWORK_FEATURE_SUPPORT - ");
1194
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1195
1196
0
    return size;
1197
0
}
1198
1199
/* 9.9.3.21 key set identifier
1200
 * O TV 1 */
1201
int ogs_nas_eps_decode_key_set_identifier(ogs_nas_key_set_identifier_t *key_set_identifier, ogs_pkbuf_t *pkbuf)
1202
1.86k
{
1203
1.86k
    int size = sizeof(ogs_nas_key_set_identifier_t);
1204
1205
1.86k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1206
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1207
0
       return -1;
1208
0
    }
1209
1210
1.86k
    memcpy(key_set_identifier, pkbuf->data - size, size);
1211
1212
1.86k
    ogs_trace("  KEY_SET_IDENTIFIER - ");
1213
1.86k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1214
1215
1.86k
    return size;
1216
1.86k
}
1217
1218
int ogs_nas_eps_encode_key_set_identifier(ogs_pkbuf_t *pkbuf, ogs_nas_key_set_identifier_t *key_set_identifier)
1219
0
{
1220
0
    int size = sizeof(ogs_nas_key_set_identifier_t);
1221
1222
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1223
0
    memcpy(pkbuf->data - size, key_set_identifier, size);
1224
1225
0
    ogs_trace("  KEY_SET_IDENTIFIER - ");
1226
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1227
1228
0
    return size;
1229
0
}
1230
1231
/* 9.9.3.22 EPS message container
1232
 * M LV 3-252 */
1233
int ogs_nas_eps_decode_eps_message_container(ogs_nas_eps_message_container_t *eps_message_container, ogs_pkbuf_t *pkbuf)
1234
52
{
1235
52
    int size = 0;
1236
52
    ogs_nas_eps_message_container_t *source = NULL;
1237
1238
52
    if (pkbuf->len < 1) {
1239
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
1240
0
       return -1;
1241
0
    }
1242
1243
52
    source = (ogs_nas_eps_message_container_t *)pkbuf->data;
1244
1245
52
    eps_message_container->length = source->length;
1246
52
    size = eps_message_container->length + sizeof(eps_message_container->length);
1247
1248
52
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1249
6
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1250
6
       return -1;
1251
6
    }
1252
1253
46
    if (sizeof(*eps_message_container) < size) return -1;
1254
44
    memcpy(eps_message_container, pkbuf->data - size, size);
1255
1256
44
    ogs_trace("  EPS_MESSAGE_CONTAINER - ");
1257
44
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1258
1259
44
    return size;
1260
46
}
1261
1262
int ogs_nas_eps_encode_eps_message_container(ogs_pkbuf_t *pkbuf, ogs_nas_eps_message_container_t *eps_message_container)
1263
0
{
1264
0
    int size = eps_message_container->length + sizeof(eps_message_container->length);
1265
0
    ogs_nas_eps_message_container_t target;
1266
1267
0
    memcpy(&target, eps_message_container, sizeof(ogs_nas_eps_message_container_t));
1268
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1269
0
    memcpy(pkbuf->data - size, &target, size);
1270
1271
0
    ogs_trace("  EPS_MESSAGE_CONTAINER - ");
1272
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1273
1274
0
    return size;
1275
0
}
1276
1277
/* 9.9.3.23 security algorithms
1278
 * M V 1 */
1279
int ogs_nas_eps_decode_security_algorithms(ogs_nas_security_algorithms_t *security_algorithms, ogs_pkbuf_t *pkbuf)
1280
118
{
1281
118
    int size = sizeof(ogs_nas_security_algorithms_t);
1282
1283
118
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1284
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1285
0
       return -1;
1286
0
    }
1287
1288
118
    memcpy(security_algorithms, pkbuf->data - size, size);
1289
1290
118
    ogs_trace("  SECURITY_ALGORITHMS - ");
1291
118
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1292
1293
118
    return size;
1294
118
}
1295
1296
int ogs_nas_eps_encode_security_algorithms(ogs_pkbuf_t *pkbuf, ogs_nas_security_algorithms_t *security_algorithms)
1297
0
{
1298
0
    int size = sizeof(ogs_nas_security_algorithms_t);
1299
0
    ogs_nas_security_algorithms_t target;
1300
1301
0
    memcpy(&target, security_algorithms, size);
1302
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1303
0
    memcpy(pkbuf->data - size, &target, size);
1304
1305
0
    ogs_trace("  SECURITY_ALGORITHMS - ");
1306
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1307
1308
0
    return size;
1309
0
}
1310
1311
/* 9.9.3.24 Network name
1312
 * O TLV 3-n */
1313
int ogs_nas_eps_decode_network_name(ogs_nas_network_name_t *network_name, ogs_pkbuf_t *pkbuf)
1314
767
{
1315
767
    int size = 0;
1316
767
    ogs_nas_network_name_t *source = NULL;
1317
1318
767
    if (pkbuf->len < 1) {
1319
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
1320
7
       return -1;
1321
7
    }
1322
1323
760
    source = (ogs_nas_network_name_t *)pkbuf->data;
1324
1325
760
    network_name->length = source->length;
1326
760
    size = network_name->length + sizeof(network_name->length);
1327
1328
760
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1329
2
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1330
2
       return -1;
1331
2
    }
1332
1333
758
    if (sizeof(*network_name) < size) return -1;
1334
758
    memcpy(network_name, pkbuf->data - size, size);
1335
1336
758
    ogs_trace("  NETWORK_NAME - ");
1337
758
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1338
1339
758
    return size;
1340
758
}
1341
1342
int ogs_nas_eps_encode_network_name(ogs_pkbuf_t *pkbuf, ogs_nas_network_name_t *network_name)
1343
0
{
1344
0
    int size = network_name->length + sizeof(network_name->length);
1345
0
    ogs_nas_network_name_t target;
1346
1347
0
    memcpy(&target, network_name, sizeof(ogs_nas_network_name_t));
1348
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1349
0
    memcpy(pkbuf->data - size, &target, size);
1350
1351
0
    ogs_trace("  NETWORK_NAME - ");
1352
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1353
1354
0
    return size;
1355
0
}
1356
1357
/* 9.9.3.24A Network resource identifier container
1358
 * O TLV 4 */
1359
int ogs_nas_eps_decode_network_resource_identifier_container(ogs_nas_network_resource_identifier_container_t *network_resource_identifier_container, ogs_pkbuf_t *pkbuf)
1360
499
{
1361
499
    int size = 0;
1362
499
    ogs_nas_network_resource_identifier_container_t *source = NULL;
1363
1364
499
    if (pkbuf->len < 1) {
1365
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
1366
7
       return -1;
1367
7
    }
1368
1369
492
    source = (ogs_nas_network_resource_identifier_container_t *)pkbuf->data;
1370
1371
492
    network_resource_identifier_container->length = source->length;
1372
492
    size = network_resource_identifier_container->length + sizeof(network_resource_identifier_container->length);
1373
1374
492
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1375
1
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1376
1
       return -1;
1377
1
    }
1378
1379
491
    if (sizeof(*network_resource_identifier_container) < size) return -1;
1380
489
    memcpy(network_resource_identifier_container, pkbuf->data - size, size);
1381
1382
489
    ogs_trace("  NETWORK_RESOURCE_IDENTIFIER_CONTAINER - ");
1383
489
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1384
1385
489
    return size;
1386
491
}
1387
1388
int ogs_nas_eps_encode_network_resource_identifier_container(ogs_pkbuf_t *pkbuf, ogs_nas_network_resource_identifier_container_t *network_resource_identifier_container)
1389
0
{
1390
0
    int size = network_resource_identifier_container->length + sizeof(network_resource_identifier_container->length);
1391
0
    ogs_nas_network_resource_identifier_container_t target;
1392
1393
0
    memcpy(&target, network_resource_identifier_container, sizeof(ogs_nas_network_resource_identifier_container_t));
1394
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1395
0
    memcpy(pkbuf->data - size, &target, size);
1396
1397
0
    ogs_trace("  NETWORK_RESOURCE_IDENTIFIER_CONTAINER - ");
1398
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1399
1400
0
    return size;
1401
0
}
1402
1403
/* 9.9.3.25 Nonce
1404
 * O TV 5 */
1405
int ogs_nas_eps_decode_nonce(ogs_nas_nonce_t *nonce, ogs_pkbuf_t *pkbuf)
1406
824
{
1407
824
    int size = sizeof(ogs_nas_nonce_t);
1408
1409
824
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1410
10
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1411
10
       return -1;
1412
10
    }
1413
1414
814
    memcpy(nonce, pkbuf->data - size, size);
1415
1416
814
    *nonce = be32toh(*nonce);
1417
1418
814
    ogs_trace("  NONCE - ");
1419
814
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1420
1421
814
    return size;
1422
824
}
1423
1424
int ogs_nas_eps_encode_nonce(ogs_pkbuf_t *pkbuf, ogs_nas_nonce_t *nonce)
1425
0
{
1426
0
    int size = sizeof(ogs_nas_nonce_t);
1427
0
    ogs_nas_nonce_t target;
1428
1429
0
    memcpy(&target, nonce, size);
1430
0
    target = htobe32(*nonce);
1431
1432
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1433
0
    memcpy(pkbuf->data - size, &target, size);
1434
1435
0
    ogs_trace("  NONCE - ");
1436
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1437
1438
0
    return size;
1439
0
}
1440
1441
/* 9.9.3.25A Paging identity
1442
 * M V 1 */
1443
int ogs_nas_eps_decode_paging_identity(ogs_nas_paging_identity_t *paging_identity, ogs_pkbuf_t *pkbuf)
1444
138
{
1445
138
    int size = sizeof(ogs_nas_paging_identity_t);
1446
1447
138
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1448
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1449
0
       return -1;
1450
0
    }
1451
1452
138
    memcpy(paging_identity, pkbuf->data - size, size);
1453
1454
138
    ogs_trace("  PAGING_IDENTITY - ");
1455
138
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1456
1457
138
    return size;
1458
138
}
1459
1460
int ogs_nas_eps_encode_paging_identity(ogs_pkbuf_t *pkbuf, ogs_nas_paging_identity_t *paging_identity)
1461
0
{
1462
0
    int size = sizeof(ogs_nas_paging_identity_t);
1463
0
    ogs_nas_paging_identity_t target;
1464
1465
0
    memcpy(&target, paging_identity, size);
1466
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1467
0
    memcpy(pkbuf->data - size, &target, size);
1468
1469
0
    ogs_trace("  PAGING_IDENTITY - ");
1470
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1471
1472
0
    return size;
1473
0
}
1474
1475
/* 9.9.3.26 P-TMSI signature
1476
 * O TV 4 */
1477
int ogs_nas_eps_decode_p_tmsi_signature(ogs_nas_p_tmsi_signature_t *p_tmsi_signature, ogs_pkbuf_t *pkbuf)
1478
1.00k
{
1479
1.00k
    int size = 3;
1480
1481
1.00k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1482
10
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1483
10
       return -1;
1484
10
    }
1485
1486
994
    memcpy(p_tmsi_signature, pkbuf->data - size, size);
1487
1488
994
    *p_tmsi_signature = htobe32(*p_tmsi_signature);
1489
1490
994
    ogs_trace("  P_TMSI_SIGNATURE - ");
1491
994
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1492
1493
994
    return size;
1494
1.00k
}
1495
1496
int ogs_nas_eps_encode_p_tmsi_signature(ogs_pkbuf_t *pkbuf, ogs_nas_p_tmsi_signature_t *p_tmsi_signature)
1497
0
{
1498
0
    int size = 3;
1499
0
    ogs_nas_p_tmsi_signature_t target;
1500
1501
0
    memcpy(&target, p_tmsi_signature, size);
1502
0
    *p_tmsi_signature = be32toh(*p_tmsi_signature);
1503
1504
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1505
0
    memcpy(pkbuf->data - size, &target, size);
1506
1507
0
    ogs_trace("  P_TMSI_SIGNATURE - ");
1508
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1509
1510
0
    return size;
1511
0
}
1512
1513
/* 9.9.3.26A Extended EMM cause
1514
 * O TV 1 */
1515
int ogs_nas_eps_decode_extended_emm_cause(ogs_nas_extended_emm_cause_t *extended_emm_cause, ogs_pkbuf_t *pkbuf)
1516
1.34k
{
1517
1.34k
    int size = sizeof(ogs_nas_extended_emm_cause_t);
1518
1519
1.34k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1520
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1521
0
       return -1;
1522
0
    }
1523
1524
1.34k
    memcpy(extended_emm_cause, pkbuf->data - size, size);
1525
1526
1.34k
    ogs_trace("  EXTENDED_EMM_CAUSE - ");
1527
1.34k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1528
1529
1.34k
    return size;
1530
1.34k
}
1531
1532
int ogs_nas_eps_encode_extended_emm_cause(ogs_pkbuf_t *pkbuf, ogs_nas_extended_emm_cause_t *extended_emm_cause)
1533
0
{
1534
0
    int size = sizeof(ogs_nas_extended_emm_cause_t);
1535
1536
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1537
0
    memcpy(pkbuf->data - size, extended_emm_cause, size);
1538
1539
0
    ogs_trace("  EXTENDED_EMM_CAUSE - ");
1540
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1541
1542
0
    return size;
1543
0
}
1544
1545
/* 9.9.3.27 Service type
1546
 * M V 1/2 */
1547
int ogs_nas_eps_decode_service_type(ogs_nas_service_type_t *service_type, ogs_pkbuf_t *pkbuf)
1548
98
{
1549
98
    int size = sizeof(ogs_nas_service_type_t);
1550
1551
98
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1552
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1553
0
       return -1;
1554
0
    }
1555
1556
98
    memcpy(service_type, pkbuf->data - size, size);
1557
1558
98
    ogs_trace("  SERVICE_TYPE - ");
1559
98
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1560
1561
98
    return size;
1562
98
}
1563
1564
int ogs_nas_eps_encode_service_type(ogs_pkbuf_t *pkbuf, ogs_nas_service_type_t *service_type)
1565
0
{
1566
0
    int size = sizeof(ogs_nas_service_type_t);
1567
0
    ogs_nas_service_type_t target;
1568
1569
0
    memcpy(&target, service_type, size);
1570
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1571
0
    memcpy(pkbuf->data - size, &target, size);
1572
1573
0
    ogs_trace("  SERVICE_TYPE - ");
1574
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1575
1576
0
    return size;
1577
0
}
1578
1579
/* 9.9.3.28 Short MAC
1580
 * M V 2 */
1581
int ogs_nas_eps_decode_short_mac(ogs_nas_short_mac_t *short_mac, ogs_pkbuf_t *pkbuf)
1582
3
{
1583
3
    int size = sizeof(ogs_nas_short_mac_t);
1584
1585
3
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1586
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1587
0
       return -1;
1588
0
    }
1589
1590
3
    memcpy(short_mac, pkbuf->data - size, size);
1591
1592
3
    *short_mac = be16toh(*short_mac);
1593
1594
3
    ogs_trace("  SHORT_MAC - ");
1595
3
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1596
1597
3
    return size;
1598
3
}
1599
1600
int ogs_nas_eps_encode_short_mac(ogs_pkbuf_t *pkbuf, ogs_nas_short_mac_t *short_mac)
1601
0
{
1602
0
    int size = sizeof(ogs_nas_short_mac_t);
1603
0
    ogs_nas_short_mac_t target;
1604
1605
0
    memcpy(&target, short_mac, size);
1606
0
    target = htobe16(*short_mac);
1607
1608
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1609
0
    memcpy(pkbuf->data - size, &target, size);
1610
1611
0
    ogs_trace("  SHORT_MAC - ");
1612
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1613
1614
0
    return size;
1615
0
}
1616
1617
/* 9.9.3.29 Time zone
1618
 * O TV 2 */
1619
int ogs_nas_eps_decode_time_zone(ogs_nas_time_zone_t *time_zone, ogs_pkbuf_t *pkbuf)
1620
382
{
1621
382
    int size = sizeof(ogs_nas_time_zone_t);
1622
1623
382
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1624
6
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1625
6
       return -1;
1626
6
    }
1627
1628
376
    memcpy(time_zone, pkbuf->data - size, size);
1629
1630
376
    ogs_trace("  TIME_ZONE - ");
1631
376
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1632
1633
376
    return size;
1634
382
}
1635
1636
int ogs_nas_eps_encode_time_zone(ogs_pkbuf_t *pkbuf, ogs_nas_time_zone_t *time_zone)
1637
0
{
1638
0
    int size = sizeof(ogs_nas_time_zone_t);
1639
0
    ogs_nas_time_zone_t target;
1640
1641
0
    memcpy(&target, time_zone, size);
1642
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1643
0
    memcpy(pkbuf->data - size, &target, size);
1644
1645
0
    ogs_trace("  TIME_ZONE - ");
1646
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1647
1648
0
    return size;
1649
0
}
1650
1651
/* 9.9.3.3 Authentication parameter RAND
1652
 * M V 16 */
1653
int ogs_nas_eps_decode_authentication_parameter_rand(ogs_nas_authentication_parameter_rand_t *authentication_parameter_rand, ogs_pkbuf_t *pkbuf)
1654
22
{
1655
22
    int size = sizeof(ogs_nas_authentication_parameter_rand_t);
1656
1657
22
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1658
8
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1659
8
       return -1;
1660
8
    }
1661
1662
14
    memcpy(authentication_parameter_rand, pkbuf->data - size, size);
1663
1664
14
    ogs_trace("  AUTHENTICATION_PARAMETER_RAND - ");
1665
14
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1666
1667
14
    return size;
1668
22
}
1669
1670
int ogs_nas_eps_encode_authentication_parameter_rand(ogs_pkbuf_t *pkbuf, ogs_nas_authentication_parameter_rand_t *authentication_parameter_rand)
1671
0
{
1672
0
    int size = sizeof(ogs_nas_authentication_parameter_rand_t);
1673
0
    ogs_nas_authentication_parameter_rand_t target;
1674
1675
0
    memcpy(&target, authentication_parameter_rand, size);
1676
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1677
0
    memcpy(pkbuf->data - size, &target, size);
1678
1679
0
    ogs_trace("  AUTHENTICATION_PARAMETER_RAND - ");
1680
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1681
1682
0
    return size;
1683
0
}
1684
1685
/* 9.9.3.30 Time zone and time
1686
 * O TV 8 */
1687
int ogs_nas_eps_decode_time_zone_and_time(ogs_nas_time_zone_and_time_t *time_zone_and_time, ogs_pkbuf_t *pkbuf)
1688
344
{
1689
344
    int size = sizeof(ogs_nas_time_zone_and_time_t);
1690
1691
344
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1692
13
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1693
13
       return -1;
1694
13
    }
1695
1696
331
    memcpy(time_zone_and_time, pkbuf->data - size, size);
1697
1698
331
    ogs_trace("  TIME_ZONE_AND_TIME - ");
1699
331
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1700
1701
331
    return size;
1702
344
}
1703
1704
int ogs_nas_eps_encode_time_zone_and_time(ogs_pkbuf_t *pkbuf, ogs_nas_time_zone_and_time_t *time_zone_and_time)
1705
0
{
1706
0
    int size = sizeof(ogs_nas_time_zone_and_time_t);
1707
0
    ogs_nas_time_zone_and_time_t target;
1708
1709
0
    memcpy(&target, time_zone_and_time, size);
1710
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1711
0
    memcpy(pkbuf->data - size, &target, size);
1712
1713
0
    ogs_trace("  TIME_ZONE_AND_TIME - ");
1714
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1715
1716
0
    return size;
1717
0
}
1718
1719
/* 9.9.3.31 TMSI status
1720
 * O TV 1 */
1721
int ogs_nas_eps_decode_tmsi_status(ogs_nas_tmsi_status_t *tmsi_status, ogs_pkbuf_t *pkbuf)
1722
2.14k
{
1723
2.14k
    int size = sizeof(ogs_nas_tmsi_status_t);
1724
1725
2.14k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1726
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1727
0
       return -1;
1728
0
    }
1729
1730
2.14k
    memcpy(tmsi_status, pkbuf->data - size, size);
1731
1732
2.14k
    ogs_trace("  TMSI_STATUS - ");
1733
2.14k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1734
1735
2.14k
    return size;
1736
2.14k
}
1737
1738
int ogs_nas_eps_encode_tmsi_status(ogs_pkbuf_t *pkbuf, ogs_nas_tmsi_status_t *tmsi_status)
1739
0
{
1740
0
    int size = sizeof(ogs_nas_tmsi_status_t);
1741
1742
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1743
0
    memcpy(pkbuf->data - size, tmsi_status, size);
1744
1745
0
    ogs_trace("  TMSI_STATUS - ");
1746
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1747
1748
0
    return size;
1749
0
}
1750
1751
/* 9.9.3.32 Tracking area identity
1752
 * O TV 6 */
1753
int ogs_nas_eps_decode_tracking_area_identity(ogs_nas_tracking_area_identity_t *tracking_area_identity, ogs_pkbuf_t *pkbuf)
1754
607
{
1755
607
    int size = sizeof(ogs_nas_tracking_area_identity_t);
1756
1757
607
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1758
7
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1759
7
       return -1;
1760
7
    }
1761
1762
600
    memcpy(tracking_area_identity, pkbuf->data - size, size);
1763
1764
600
    tracking_area_identity->tac = be16toh(tracking_area_identity->tac);
1765
1766
600
    ogs_trace("  TRACKING_AREA_IDENTITY - ");
1767
600
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1768
1769
600
    return size;
1770
607
}
1771
1772
int ogs_nas_eps_encode_tracking_area_identity(ogs_pkbuf_t *pkbuf, ogs_nas_tracking_area_identity_t *tracking_area_identity)
1773
0
{
1774
0
    int size = sizeof(ogs_nas_tracking_area_identity_t);
1775
0
    ogs_nas_tracking_area_identity_t target;
1776
1777
0
    memcpy(&target, tracking_area_identity, size);
1778
0
    target.tac = htobe16(tracking_area_identity->tac);
1779
1780
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1781
0
    memcpy(pkbuf->data - size, &target, size);
1782
1783
0
    ogs_trace("  TRACKING_AREA_IDENTITY - ");
1784
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1785
1786
0
    return size;
1787
0
}
1788
1789
/* 9.9.3.33 Tracking area identity list
1790
 * M LV 7-97 */
1791
int ogs_nas_eps_decode_tracking_area_identity_list(ogs_nas_tracking_area_identity_list_t *tracking_area_identity_list, ogs_pkbuf_t *pkbuf)
1792
3.50k
{
1793
3.50k
    int size = 0;
1794
3.50k
    ogs_nas_tracking_area_identity_list_t *source = NULL;
1795
1796
3.50k
    if (pkbuf->len < 1) {
1797
11
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
1798
11
       return -1;
1799
11
    }
1800
1801
3.49k
    source = (ogs_nas_tracking_area_identity_list_t *)pkbuf->data;
1802
1803
3.49k
    tracking_area_identity_list->length = source->length;
1804
3.49k
    size = tracking_area_identity_list->length + sizeof(tracking_area_identity_list->length);
1805
1806
3.49k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1807
12
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1808
12
       return -1;
1809
12
    }
1810
1811
3.48k
    if (sizeof(*tracking_area_identity_list) < size) return -1;
1812
3.48k
    memcpy(tracking_area_identity_list, pkbuf->data - size, size);
1813
1814
3.48k
    ogs_trace("  TRACKING_AREA_IDENTITY_LIST - ");
1815
3.48k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1816
1817
3.48k
    return size;
1818
3.48k
}
1819
1820
int ogs_nas_eps_encode_tracking_area_identity_list(ogs_pkbuf_t *pkbuf, ogs_nas_tracking_area_identity_list_t *tracking_area_identity_list)
1821
0
{
1822
0
    int size = tracking_area_identity_list->length + sizeof(tracking_area_identity_list->length);
1823
0
    ogs_nas_tracking_area_identity_list_t target;
1824
1825
0
    memcpy(&target, tracking_area_identity_list, sizeof(ogs_nas_tracking_area_identity_list_t));
1826
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1827
0
    memcpy(pkbuf->data - size, &target, size);
1828
1829
0
    ogs_trace("  TRACKING_AREA_IDENTITY_LIST - ");
1830
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1831
1832
0
    return size;
1833
0
}
1834
1835
/* 9.9.3.34 UE network capability
1836
 * M LV 3-14 */
1837
int ogs_nas_eps_decode_ue_network_capability(ogs_nas_ue_network_capability_t *ue_network_capability, ogs_pkbuf_t *pkbuf)
1838
752
{
1839
752
    int size = 0;
1840
752
    ogs_nas_ue_network_capability_t *source = NULL;
1841
1842
752
    if (pkbuf->len < 1) {
1843
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
1844
7
       return -1;
1845
7
    }
1846
1847
745
    source = (ogs_nas_ue_network_capability_t *)pkbuf->data;
1848
1849
745
    ue_network_capability->length = source->length;
1850
745
    size = ue_network_capability->length + sizeof(ue_network_capability->length);
1851
1852
745
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1853
9
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1854
9
       return -1;
1855
9
    }
1856
1857
736
    if (sizeof(*ue_network_capability) < size) return -1;
1858
732
    memcpy(ue_network_capability, pkbuf->data - size, size);
1859
1860
732
    ogs_trace("  UE_NETWORK_CAPABILITY - ");
1861
732
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1862
1863
732
    return size;
1864
736
}
1865
1866
int ogs_nas_eps_encode_ue_network_capability(ogs_pkbuf_t *pkbuf, ogs_nas_ue_network_capability_t *ue_network_capability)
1867
0
{
1868
0
    int size = ue_network_capability->length + sizeof(ue_network_capability->length);
1869
0
    ogs_nas_ue_network_capability_t target;
1870
1871
0
    memcpy(&target, ue_network_capability, sizeof(ogs_nas_ue_network_capability_t));
1872
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1873
0
    memcpy(pkbuf->data - size, &target, size);
1874
1875
0
    ogs_trace("  UE_NETWORK_CAPABILITY - ");
1876
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1877
1878
0
    return size;
1879
0
}
1880
1881
/* 9.9.3.35 UE radio capability information update needed
1882
 * O TV 1 */
1883
int ogs_nas_eps_decode_ue_radio_capability_information_update_needed(ogs_nas_ue_radio_capability_information_update_needed_t *ue_radio_capability_information_update_needed, ogs_pkbuf_t *pkbuf)
1884
1.43k
{
1885
1.43k
    int size = sizeof(ogs_nas_ue_radio_capability_information_update_needed_t);
1886
1887
1.43k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1888
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1889
0
       return -1;
1890
0
    }
1891
1892
1.43k
    memcpy(ue_radio_capability_information_update_needed, pkbuf->data - size, size);
1893
1894
1.43k
    ogs_trace("  UE_RADIO_CAPABILITY_INFORMATION_UPDATE_NEEDED - ");
1895
1.43k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1896
1897
1.43k
    return size;
1898
1.43k
}
1899
1900
int ogs_nas_eps_encode_ue_radio_capability_information_update_needed(ogs_pkbuf_t *pkbuf, ogs_nas_ue_radio_capability_information_update_needed_t *ue_radio_capability_information_update_needed)
1901
0
{
1902
0
    int size = sizeof(ogs_nas_ue_radio_capability_information_update_needed_t);
1903
1904
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1905
0
    memcpy(pkbuf->data - size, ue_radio_capability_information_update_needed, size);
1906
1907
0
    ogs_trace("  UE_RADIO_CAPABILITY_INFORMATION_UPDATE_NEEDED - ");
1908
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1909
1910
0
    return size;
1911
0
}
1912
1913
/* 9.9.3.36 UE security capability
1914
 * M LV 3-6 */
1915
int ogs_nas_eps_decode_ue_security_capability(ogs_nas_ue_security_capability_t *ue_security_capability, ogs_pkbuf_t *pkbuf)
1916
118
{
1917
118
    int size = 0;
1918
118
    ogs_nas_ue_security_capability_t *source = NULL;
1919
1920
118
    if (pkbuf->len < 1) {
1921
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
1922
0
       return -1;
1923
0
    }
1924
1925
118
    source = (ogs_nas_ue_security_capability_t *)pkbuf->data;
1926
1927
118
    ue_security_capability->length = source->length;
1928
118
    size = ue_security_capability->length + sizeof(ue_security_capability->length);
1929
1930
118
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1931
5
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1932
5
       return -1;
1933
5
    }
1934
1935
113
    if (sizeof(*ue_security_capability) < size) return -1;
1936
112
    memcpy(ue_security_capability, pkbuf->data - size, size);
1937
1938
112
    ogs_trace("  UE_SECURITY_CAPABILITY - ");
1939
112
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1940
1941
112
    return size;
1942
113
}
1943
1944
int ogs_nas_eps_encode_ue_security_capability(ogs_pkbuf_t *pkbuf, ogs_nas_ue_security_capability_t *ue_security_capability)
1945
0
{
1946
0
    int size = ue_security_capability->length + sizeof(ue_security_capability->length);
1947
0
    ogs_nas_ue_security_capability_t target;
1948
1949
0
    memcpy(&target, ue_security_capability, sizeof(ogs_nas_ue_security_capability_t));
1950
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1951
0
    memcpy(pkbuf->data - size, &target, size);
1952
1953
0
    ogs_trace("  UE_SECURITY_CAPABILITY - ");
1954
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1955
1956
0
    return size;
1957
0
}
1958
1959
/* 9.9.3.37 Emergency number list
1960
 * O TLV 5-50 */
1961
int ogs_nas_eps_decode_emergency_number_list(ogs_nas_emergency_number_list_t *emergency_number_list, ogs_pkbuf_t *pkbuf)
1962
640
{
1963
640
    int size = 0;
1964
640
    ogs_nas_emergency_number_list_t *source = NULL;
1965
1966
640
    if (pkbuf->len < 1) {
1967
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
1968
7
       return -1;
1969
7
    }
1970
1971
633
    source = (ogs_nas_emergency_number_list_t *)pkbuf->data;
1972
1973
633
    emergency_number_list->length = source->length;
1974
633
    size = emergency_number_list->length + sizeof(emergency_number_list->length);
1975
1976
633
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
1977
16
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
1978
16
       return -1;
1979
16
    }
1980
1981
617
    if (sizeof(*emergency_number_list) < size) return -1;
1982
616
    memcpy(emergency_number_list, pkbuf->data - size, size);
1983
1984
616
    ogs_trace("  EMERGENCY_NUMBER_LIST - ");
1985
616
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
1986
1987
616
    return size;
1988
617
}
1989
1990
int ogs_nas_eps_encode_emergency_number_list(ogs_pkbuf_t *pkbuf, ogs_nas_emergency_number_list_t *emergency_number_list)
1991
0
{
1992
0
    int size = emergency_number_list->length + sizeof(emergency_number_list->length);
1993
0
    ogs_nas_emergency_number_list_t target;
1994
1995
0
    memcpy(&target, emergency_number_list, sizeof(ogs_nas_emergency_number_list_t));
1996
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
1997
0
    memcpy(pkbuf->data - size, &target, size);
1998
1999
0
    ogs_trace("  EMERGENCY_NUMBER_LIST - ");
2000
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2001
2002
0
    return size;
2003
0
}
2004
2005
/* 9.9.3.37A Extended emergency number list
2006
 * O TLV-E 7-65538 */
2007
int ogs_nas_eps_decode_extended_emergency_number_list(ogs_nas_extended_emergency_number_list_t *extended_emergency_number_list, ogs_pkbuf_t *pkbuf)
2008
524
{
2009
524
    int size = 0;
2010
524
    ogs_nas_extended_emergency_number_list_t *source = NULL;
2011
2012
524
    if (pkbuf->len < 2) {
2013
9
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2014
9
       return -1;
2015
9
    }
2016
2017
515
    source = (ogs_nas_extended_emergency_number_list_t *)pkbuf->data;
2018
2019
515
    extended_emergency_number_list->length = be16toh(source->length);
2020
515
    size = extended_emergency_number_list->length + sizeof(extended_emergency_number_list->length);
2021
2022
515
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2023
14
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2024
14
       return -1;
2025
14
    }
2026
2027
501
    extended_emergency_number_list->buffer = pkbuf->data - size + sizeof(extended_emergency_number_list->length);
2028
2029
501
    ogs_trace("  EXTENDED_EMERGENCY_NUMBER_LIST - ");
2030
501
    ogs_log_hexdump(OGS_LOG_TRACE, (void*)extended_emergency_number_list->buffer, extended_emergency_number_list->length);
2031
2032
501
    return size;
2033
515
}
2034
2035
int ogs_nas_eps_encode_extended_emergency_number_list(ogs_pkbuf_t *pkbuf, ogs_nas_extended_emergency_number_list_t *extended_emergency_number_list)
2036
0
{
2037
0
    int size = 0;
2038
0
    int target;
2039
2040
0
    ogs_assert(extended_emergency_number_list);
2041
0
    ogs_assert(extended_emergency_number_list->buffer);
2042
2043
0
    size = sizeof(extended_emergency_number_list->length);
2044
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2045
0
    target = htobe16(extended_emergency_number_list->length);
2046
0
    memcpy(pkbuf->data - size, &target, size);
2047
2048
0
    size = extended_emergency_number_list->length;
2049
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2050
0
    memcpy(pkbuf->data - size, extended_emergency_number_list->buffer, size);
2051
2052
0
    ogs_trace("  EXTENDED_EMERGENCY_NUMBER_LIST - ");
2053
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2054
2055
0
    return extended_emergency_number_list->length + sizeof(extended_emergency_number_list->length);
2056
0
}
2057
2058
/* 9.9.3.38 CLI
2059
 * O TLV 3-14 */
2060
int ogs_nas_eps_decode_cli(ogs_nas_cli_t *cli, ogs_pkbuf_t *pkbuf)
2061
421
{
2062
421
    int size = 0;
2063
421
    ogs_nas_cli_t *source = NULL;
2064
2065
421
    if (pkbuf->len < 1) {
2066
8
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2067
8
       return -1;
2068
8
    }
2069
2070
413
    source = (ogs_nas_cli_t *)pkbuf->data;
2071
2072
413
    cli->length = source->length;
2073
413
    size = cli->length + sizeof(cli->length);
2074
2075
413
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2076
5
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2077
5
       return -1;
2078
5
    }
2079
2080
408
    if (sizeof(*cli) < size) return -1;
2081
407
    memcpy(cli, pkbuf->data - size, size);
2082
2083
407
    ogs_trace("  CLI - ");
2084
407
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2085
2086
407
    return size;
2087
408
}
2088
2089
int ogs_nas_eps_encode_cli(ogs_pkbuf_t *pkbuf, ogs_nas_cli_t *cli)
2090
0
{
2091
0
    int size = cli->length + sizeof(cli->length);
2092
0
    ogs_nas_cli_t target;
2093
2094
0
    memcpy(&target, cli, sizeof(ogs_nas_cli_t));
2095
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2096
0
    memcpy(pkbuf->data - size, &target, size);
2097
2098
0
    ogs_trace("  CLI - ");
2099
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2100
2101
0
    return size;
2102
0
}
2103
2104
/* 9.9.3.39 SS Code
2105
 * O TV 2 */
2106
int ogs_nas_eps_decode_ss_code(ogs_nas_ss_code_t *ss_code, ogs_pkbuf_t *pkbuf)
2107
317
{
2108
317
    int size = sizeof(ogs_nas_ss_code_t);
2109
2110
317
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2111
6
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2112
6
       return -1;
2113
6
    }
2114
2115
311
    memcpy(ss_code, pkbuf->data - size, size);
2116
2117
311
    ogs_trace("  SS_CODE - ");
2118
311
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2119
2120
311
    return size;
2121
317
}
2122
2123
int ogs_nas_eps_encode_ss_code(ogs_pkbuf_t *pkbuf, ogs_nas_ss_code_t *ss_code)
2124
0
{
2125
0
    int size = sizeof(ogs_nas_ss_code_t);
2126
0
    ogs_nas_ss_code_t target;
2127
2128
0
    memcpy(&target, ss_code, size);
2129
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2130
0
    memcpy(pkbuf->data - size, &target, size);
2131
2132
0
    ogs_trace("  SS_CODE - ");
2133
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2134
2135
0
    return size;
2136
0
}
2137
2138
/* 9.9.3.4 Authentication response parameter
2139
 * M LV 5-17 */
2140
int ogs_nas_eps_decode_authentication_response_parameter(ogs_nas_authentication_response_parameter_t *authentication_response_parameter, ogs_pkbuf_t *pkbuf)
2141
34
{
2142
34
    int size = 0;
2143
34
    ogs_nas_authentication_response_parameter_t *source = NULL;
2144
2145
34
    if (pkbuf->len < 1) {
2146
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2147
0
       return -1;
2148
0
    }
2149
2150
34
    source = (ogs_nas_authentication_response_parameter_t *)pkbuf->data;
2151
2152
34
    authentication_response_parameter->length = source->length;
2153
34
    size = authentication_response_parameter->length + sizeof(authentication_response_parameter->length);
2154
2155
34
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2156
7
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2157
7
       return -1;
2158
7
    }
2159
2160
27
    if (sizeof(*authentication_response_parameter) < size) return -1;
2161
25
    memcpy(authentication_response_parameter, pkbuf->data - size, size);
2162
2163
25
    ogs_trace("  AUTHENTICATION_RESPONSE_PARAMETER - ");
2164
25
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2165
2166
25
    return size;
2167
27
}
2168
2169
int ogs_nas_eps_encode_authentication_response_parameter(ogs_pkbuf_t *pkbuf, ogs_nas_authentication_response_parameter_t *authentication_response_parameter)
2170
0
{
2171
0
    int size = authentication_response_parameter->length + sizeof(authentication_response_parameter->length);
2172
0
    ogs_nas_authentication_response_parameter_t target;
2173
2174
0
    memcpy(&target, authentication_response_parameter, sizeof(ogs_nas_authentication_response_parameter_t));
2175
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2176
0
    memcpy(pkbuf->data - size, &target, size);
2177
2178
0
    ogs_trace("  AUTHENTICATION_RESPONSE_PARAMETER - ");
2179
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2180
2181
0
    return size;
2182
0
}
2183
2184
/* 9.9.3.40 LCS indicator
2185
 * O TV 2 */
2186
int ogs_nas_eps_decode_lcs_indicator(ogs_nas_lcs_indicator_t *lcs_indicator, ogs_pkbuf_t *pkbuf)
2187
469
{
2188
469
    int size = sizeof(ogs_nas_lcs_indicator_t);
2189
2190
469
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2191
8
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2192
8
       return -1;
2193
8
    }
2194
2195
461
    memcpy(lcs_indicator, pkbuf->data - size, size);
2196
2197
461
    ogs_trace("  LCS_INDICATOR - ");
2198
461
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2199
2200
461
    return size;
2201
469
}
2202
2203
int ogs_nas_eps_encode_lcs_indicator(ogs_pkbuf_t *pkbuf, ogs_nas_lcs_indicator_t *lcs_indicator)
2204
0
{
2205
0
    int size = sizeof(ogs_nas_lcs_indicator_t);
2206
0
    ogs_nas_lcs_indicator_t target;
2207
2208
0
    memcpy(&target, lcs_indicator, size);
2209
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2210
0
    memcpy(pkbuf->data - size, &target, size);
2211
2212
0
    ogs_trace("  LCS_INDICATOR - ");
2213
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2214
2215
0
    return size;
2216
0
}
2217
2218
/* 9.9.3.41 LCS client identity
2219
 * O TLV 3-257 */
2220
int ogs_nas_eps_decode_lcs_client_identity(ogs_nas_lcs_client_identity_t *lcs_client_identity, ogs_pkbuf_t *pkbuf)
2221
409
{
2222
409
    int size = 0;
2223
409
    ogs_nas_lcs_client_identity_t *source = NULL;
2224
2225
409
    if (pkbuf->len < 1) {
2226
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2227
7
       return -1;
2228
7
    }
2229
2230
402
    source = (ogs_nas_lcs_client_identity_t *)pkbuf->data;
2231
2232
402
    lcs_client_identity->length = source->length;
2233
402
    size = lcs_client_identity->length + sizeof(lcs_client_identity->length);
2234
2235
402
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2236
7
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2237
7
       return -1;
2238
7
    }
2239
2240
395
    if (sizeof(*lcs_client_identity) < size) return -1;
2241
395
    memcpy(lcs_client_identity, pkbuf->data - size, size);
2242
2243
395
    ogs_trace("  LCS_CLIENT_IDENTITY - ");
2244
395
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2245
2246
395
    return size;
2247
395
}
2248
2249
int ogs_nas_eps_encode_lcs_client_identity(ogs_pkbuf_t *pkbuf, ogs_nas_lcs_client_identity_t *lcs_client_identity)
2250
0
{
2251
0
    int size = lcs_client_identity->length + sizeof(lcs_client_identity->length);
2252
0
    ogs_nas_lcs_client_identity_t target;
2253
2254
0
    memcpy(&target, lcs_client_identity, sizeof(ogs_nas_lcs_client_identity_t));
2255
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2256
0
    memcpy(pkbuf->data - size, &target, size);
2257
2258
0
    ogs_trace("  LCS_CLIENT_IDENTITY - ");
2259
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2260
2261
0
    return size;
2262
0
}
2263
2264
/* 9.9.3.42 Generic message container type
2265
 * M V 1 */
2266
int ogs_nas_eps_decode_generic_message_container_type(ogs_nas_generic_message_container_type_t *generic_message_container_type, ogs_pkbuf_t *pkbuf)
2267
145
{
2268
145
    int size = sizeof(ogs_nas_generic_message_container_type_t);
2269
2270
145
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2271
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2272
0
       return -1;
2273
0
    }
2274
2275
145
    memcpy(generic_message_container_type, pkbuf->data - size, size);
2276
2277
145
    ogs_trace("  GENERIC_MESSAGE_CONTAINER_TYPE - ");
2278
145
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2279
2280
145
    return size;
2281
145
}
2282
2283
int ogs_nas_eps_encode_generic_message_container_type(ogs_pkbuf_t *pkbuf, ogs_nas_generic_message_container_type_t *generic_message_container_type)
2284
0
{
2285
0
    int size = sizeof(ogs_nas_generic_message_container_type_t);
2286
0
    ogs_nas_generic_message_container_type_t target;
2287
2288
0
    memcpy(&target, generic_message_container_type, size);
2289
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2290
0
    memcpy(pkbuf->data - size, &target, size);
2291
2292
0
    ogs_trace("  GENERIC_MESSAGE_CONTAINER_TYPE - ");
2293
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2294
2295
0
    return size;
2296
0
}
2297
2298
/* 9.9.3.43 Generic message container
2299
 * M LV-E 3-n */
2300
int ogs_nas_eps_decode_generic_message_container(ogs_nas_generic_message_container_t *generic_message_container, ogs_pkbuf_t *pkbuf)
2301
145
{
2302
145
    int size = 0;
2303
145
    ogs_nas_generic_message_container_t *source = NULL;
2304
2305
145
    if (pkbuf->len < 2) {
2306
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2307
0
       return -1;
2308
0
    }
2309
2310
145
    source = (ogs_nas_generic_message_container_t *)pkbuf->data;
2311
2312
145
    generic_message_container->length = be16toh(source->length);
2313
145
    size = generic_message_container->length + sizeof(generic_message_container->length);
2314
2315
145
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2316
14
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2317
14
       return -1;
2318
14
    }
2319
2320
131
    generic_message_container->buffer = pkbuf->data - size + sizeof(generic_message_container->length);
2321
2322
131
    ogs_trace("  GENERIC_MESSAGE_CONTAINER - ");
2323
131
    ogs_log_hexdump(OGS_LOG_TRACE, (void*)generic_message_container->buffer, generic_message_container->length);
2324
2325
131
    return size;
2326
145
}
2327
2328
int ogs_nas_eps_encode_generic_message_container(ogs_pkbuf_t *pkbuf, ogs_nas_generic_message_container_t *generic_message_container)
2329
0
{
2330
0
    int size = 0;
2331
0
    int target;
2332
2333
0
    ogs_assert(generic_message_container);
2334
0
    ogs_assert(generic_message_container->buffer);
2335
2336
0
    size = sizeof(generic_message_container->length);
2337
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2338
0
    target = htobe16(generic_message_container->length);
2339
0
    memcpy(pkbuf->data - size, &target, size);
2340
2341
0
    size = generic_message_container->length;
2342
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2343
0
    memcpy(pkbuf->data - size, generic_message_container->buffer, size);
2344
2345
0
    ogs_trace("  GENERIC_MESSAGE_CONTAINER - ");
2346
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2347
2348
0
    return generic_message_container->length + sizeof(generic_message_container->length);
2349
0
}
2350
2351
/* 9.9.3.44 Voice domain preference and UE usage setting
2352
 * O TLV 3 */
2353
int ogs_nas_eps_decode_voice_domain_preference_and_ue_usage_setting(ogs_nas_voice_domain_preference_and_ue_usage_setting_t *voice_domain_preference_and_ue_usage_setting, ogs_pkbuf_t *pkbuf)
2354
557
{
2355
557
    int size = 0;
2356
557
    ogs_nas_voice_domain_preference_and_ue_usage_setting_t *source = NULL;
2357
2358
557
    if (pkbuf->len < 1) {
2359
6
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2360
6
       return -1;
2361
6
    }
2362
2363
551
    source = (ogs_nas_voice_domain_preference_and_ue_usage_setting_t *)pkbuf->data;
2364
2365
551
    voice_domain_preference_and_ue_usage_setting->length = source->length;
2366
551
    size = voice_domain_preference_and_ue_usage_setting->length + sizeof(voice_domain_preference_and_ue_usage_setting->length);
2367
2368
551
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2369
1
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2370
1
       return -1;
2371
1
    }
2372
2373
550
    if (sizeof(*voice_domain_preference_and_ue_usage_setting) < size) return -1;
2374
549
    memcpy(voice_domain_preference_and_ue_usage_setting, pkbuf->data - size, size);
2375
2376
549
    ogs_trace("  VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING - ");
2377
549
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2378
2379
549
    return size;
2380
550
}
2381
2382
int ogs_nas_eps_encode_voice_domain_preference_and_ue_usage_setting(ogs_pkbuf_t *pkbuf, ogs_nas_voice_domain_preference_and_ue_usage_setting_t *voice_domain_preference_and_ue_usage_setting)
2383
0
{
2384
0
    int size = voice_domain_preference_and_ue_usage_setting->length + sizeof(voice_domain_preference_and_ue_usage_setting->length);
2385
0
    ogs_nas_voice_domain_preference_and_ue_usage_setting_t target;
2386
2387
0
    memcpy(&target, voice_domain_preference_and_ue_usage_setting, sizeof(ogs_nas_voice_domain_preference_and_ue_usage_setting_t));
2388
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2389
0
    memcpy(pkbuf->data - size, &target, size);
2390
2391
0
    ogs_trace("  VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING - ");
2392
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2393
2394
0
    return size;
2395
0
}
2396
2397
/* 9.9.3.45 GUTI type
2398
 * O TV 1 */
2399
int ogs_nas_eps_decode_guti_type(ogs_nas_guti_type_t *guti_type, ogs_pkbuf_t *pkbuf)
2400
2.23k
{
2401
2.23k
    int size = sizeof(ogs_nas_guti_type_t);
2402
2403
2.23k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2404
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2405
0
       return -1;
2406
0
    }
2407
2408
2.23k
    memcpy(guti_type, pkbuf->data - size, size);
2409
2410
2.23k
    ogs_trace("  GUTI_TYPE - ");
2411
2.23k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2412
2413
2.23k
    return size;
2414
2.23k
}
2415
2416
int ogs_nas_eps_encode_guti_type(ogs_pkbuf_t *pkbuf, ogs_nas_guti_type_t *guti_type)
2417
0
{
2418
0
    int size = sizeof(ogs_nas_guti_type_t);
2419
2420
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2421
0
    memcpy(pkbuf->data - size, guti_type, size);
2422
2423
0
    ogs_trace("  GUTI_TYPE - ");
2424
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2425
2426
0
    return size;
2427
0
}
2428
2429
/* 9.9.3.46 Extended DRX parameters
2430
 * O TLV 3 */
2431
int ogs_nas_eps_decode_extended_drx_parameters(ogs_nas_extended_drx_parameters_t *extended_drx_parameters, ogs_pkbuf_t *pkbuf)
2432
1.01k
{
2433
1.01k
    int size = 0;
2434
1.01k
    ogs_nas_extended_drx_parameters_t *source = NULL;
2435
2436
1.01k
    if (pkbuf->len < 1) {
2437
8
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2438
8
       return -1;
2439
8
    }
2440
2441
1.00k
    source = (ogs_nas_extended_drx_parameters_t *)pkbuf->data;
2442
2443
1.00k
    extended_drx_parameters->length = source->length;
2444
1.00k
    size = extended_drx_parameters->length + sizeof(extended_drx_parameters->length);
2445
2446
1.00k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2447
5
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2448
5
       return -1;
2449
5
    }
2450
2451
997
    if (sizeof(*extended_drx_parameters) < size) return -1;
2452
995
    memcpy(extended_drx_parameters, pkbuf->data - size, size);
2453
2454
995
    ogs_trace("  EXTENDED_DRX_PARAMETERS - ");
2455
995
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2456
2457
995
    return size;
2458
997
}
2459
2460
int ogs_nas_eps_encode_extended_drx_parameters(ogs_pkbuf_t *pkbuf, ogs_nas_extended_drx_parameters_t *extended_drx_parameters)
2461
0
{
2462
0
    int size = extended_drx_parameters->length + sizeof(extended_drx_parameters->length);
2463
0
    ogs_nas_extended_drx_parameters_t target;
2464
2465
0
    memcpy(&target, extended_drx_parameters, sizeof(ogs_nas_extended_drx_parameters_t));
2466
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2467
0
    memcpy(pkbuf->data - size, &target, size);
2468
2469
0
    ogs_trace("  EXTENDED_DRX_PARAMETERS - ");
2470
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2471
2472
0
    return size;
2473
0
}
2474
2475
/* 9.9.3.48 DCN-ID
2476
 * O TLV 4 */
2477
int ogs_nas_eps_decode_dcn_id(ogs_nas_dcn_id_t *dcn_id, ogs_pkbuf_t *pkbuf)
2478
750
{
2479
750
    int size = 0;
2480
750
    ogs_nas_dcn_id_t *source = NULL;
2481
2482
750
    if (pkbuf->len < 1) {
2483
8
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2484
8
       return -1;
2485
8
    }
2486
2487
742
    source = (ogs_nas_dcn_id_t *)pkbuf->data;
2488
2489
742
    dcn_id->length = source->length;
2490
742
    size = dcn_id->length + sizeof(dcn_id->length);
2491
2492
742
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2493
4
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2494
4
       return -1;
2495
4
    }
2496
2497
738
    if (sizeof(*dcn_id) < size) return -1;
2498
737
    memcpy(dcn_id, pkbuf->data - size, size);
2499
2500
737
    ogs_trace("  DCN_ID - ");
2501
737
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2502
2503
737
    return size;
2504
738
}
2505
2506
int ogs_nas_eps_encode_dcn_id(ogs_pkbuf_t *pkbuf, ogs_nas_dcn_id_t *dcn_id)
2507
0
{
2508
0
    int size = dcn_id->length + sizeof(dcn_id->length);
2509
0
    ogs_nas_dcn_id_t target;
2510
2511
0
    memcpy(&target, dcn_id, sizeof(ogs_nas_dcn_id_t));
2512
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2513
0
    memcpy(pkbuf->data - size, &target, size);
2514
2515
0
    ogs_trace("  DCN_ID - ");
2516
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2517
2518
0
    return size;
2519
0
}
2520
2521
/* 9.9.3.49 Non-3GPP NW provided policies
2522
 * O TV 1 */
2523
int ogs_nas_eps_decode_non__nw_provided_policies(ogs_nas_non__nw_provided_policies_t *non__nw_provided_policies, ogs_pkbuf_t *pkbuf)
2524
2.16k
{
2525
2.16k
    int size = sizeof(ogs_nas_non__nw_provided_policies_t);
2526
2527
2.16k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2528
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2529
0
       return -1;
2530
0
    }
2531
2532
2.16k
    memcpy(non__nw_provided_policies, pkbuf->data - size, size);
2533
2534
2.16k
    ogs_trace("  NON__NW_PROVIDED_POLICIES - ");
2535
2.16k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2536
2537
2.16k
    return size;
2538
2.16k
}
2539
2540
int ogs_nas_eps_encode_non__nw_provided_policies(ogs_pkbuf_t *pkbuf, ogs_nas_non__nw_provided_policies_t *non__nw_provided_policies)
2541
0
{
2542
0
    int size = sizeof(ogs_nas_non__nw_provided_policies_t);
2543
2544
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2545
0
    memcpy(pkbuf->data - size, non__nw_provided_policies, size);
2546
2547
0
    ogs_trace("  NON__NW_PROVIDED_POLICIES - ");
2548
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2549
2550
0
    return size;
2551
0
}
2552
2553
/* 9.9.3.4B SMS services status
2554
 * O TV 1 */
2555
int ogs_nas_eps_decode_sms_services_status(ogs_nas_sms_services_status_t *sms_services_status, ogs_pkbuf_t *pkbuf)
2556
1.88k
{
2557
1.88k
    int size = sizeof(ogs_nas_sms_services_status_t);
2558
2559
1.88k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2560
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2561
0
       return -1;
2562
0
    }
2563
2564
1.88k
    memcpy(sms_services_status, pkbuf->data - size, size);
2565
2566
1.88k
    ogs_trace("  SMS_SERVICES_STATUS - ");
2567
1.88k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2568
2569
1.88k
    return size;
2570
1.88k
}
2571
2572
int ogs_nas_eps_encode_sms_services_status(ogs_pkbuf_t *pkbuf, ogs_nas_sms_services_status_t *sms_services_status)
2573
0
{
2574
0
    int size = sizeof(ogs_nas_sms_services_status_t);
2575
2576
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2577
0
    memcpy(pkbuf->data - size, sms_services_status, size);
2578
2579
0
    ogs_trace("  SMS_SERVICES_STATUS - ");
2580
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2581
2582
0
    return size;
2583
0
}
2584
2585
/* 9.9.3.4a Ciphering key sequence number
2586
 * O TV 1 */
2587
int ogs_nas_eps_decode_ciphering_key_sequence_number(ogs_nas_ciphering_key_sequence_number_t *ciphering_key_sequence_number, ogs_pkbuf_t *pkbuf)
2588
1.90k
{
2589
1.90k
    int size = sizeof(ogs_nas_ciphering_key_sequence_number_t);
2590
2591
1.90k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2592
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2593
0
       return -1;
2594
0
    }
2595
2596
1.90k
    memcpy(ciphering_key_sequence_number, pkbuf->data - size, size);
2597
2598
1.90k
    ogs_trace("  CIPHERING_KEY_SEQUENCE_NUMBER - ");
2599
1.90k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2600
2601
1.90k
    return size;
2602
1.90k
}
2603
2604
int ogs_nas_eps_encode_ciphering_key_sequence_number(ogs_pkbuf_t *pkbuf, ogs_nas_ciphering_key_sequence_number_t *ciphering_key_sequence_number)
2605
0
{
2606
0
    int size = sizeof(ogs_nas_ciphering_key_sequence_number_t);
2607
2608
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2609
0
    memcpy(pkbuf->data - size, ciphering_key_sequence_number, size);
2610
2611
0
    ogs_trace("  CIPHERING_KEY_SEQUENCE_NUMBER - ");
2612
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2613
2614
0
    return size;
2615
0
}
2616
2617
/* 9.9.3.5 CSFB response
2618
 * C TV 1 */
2619
int ogs_nas_eps_decode_csfb_response(ogs_nas_csfb_response_t *csfb_response, ogs_pkbuf_t *pkbuf)
2620
517
{
2621
517
    int size = sizeof(ogs_nas_csfb_response_t);
2622
2623
517
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2624
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2625
0
       return -1;
2626
0
    }
2627
2628
517
    memcpy(csfb_response, pkbuf->data - size, size);
2629
2630
517
    ogs_trace("  CSFB_RESPONSE - ");
2631
517
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2632
2633
517
    return size;
2634
517
}
2635
2636
int ogs_nas_eps_encode_csfb_response(ogs_pkbuf_t *pkbuf, ogs_nas_csfb_response_t *csfb_response)
2637
0
{
2638
0
    int size = sizeof(ogs_nas_csfb_response_t);
2639
2640
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2641
0
    memcpy(pkbuf->data - size, csfb_response, size);
2642
2643
0
    ogs_trace("  CSFB_RESPONSE - ");
2644
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2645
2646
0
    return size;
2647
0
}
2648
2649
/* 9.9.3.50 HashMME
2650
 * O TLV 10 */
2651
int ogs_nas_eps_decode_hashmme(ogs_nas_hashmme_t *hashmme, ogs_pkbuf_t *pkbuf)
2652
379
{
2653
379
    int size = 0;
2654
379
    ogs_nas_hashmme_t *source = NULL;
2655
2656
379
    if (pkbuf->len < 1) {
2657
6
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2658
6
       return -1;
2659
6
    }
2660
2661
373
    source = (ogs_nas_hashmme_t *)pkbuf->data;
2662
2663
373
    hashmme->length = source->length;
2664
373
    size = hashmme->length + sizeof(hashmme->length);
2665
2666
373
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2667
2
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2668
2
       return -1;
2669
2
    }
2670
2671
371
    if (sizeof(*hashmme) < size) return -1;
2672
370
    memcpy(hashmme, pkbuf->data - size, size);
2673
2674
370
    ogs_trace("  HASHMME - ");
2675
370
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2676
2677
370
    return size;
2678
371
}
2679
2680
int ogs_nas_eps_encode_hashmme(ogs_pkbuf_t *pkbuf, ogs_nas_hashmme_t *hashmme)
2681
0
{
2682
0
    int size = hashmme->length + sizeof(hashmme->length);
2683
0
    ogs_nas_hashmme_t target;
2684
2685
0
    memcpy(&target, hashmme, sizeof(ogs_nas_hashmme_t));
2686
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2687
0
    memcpy(pkbuf->data - size, &target, size);
2688
2689
0
    ogs_trace("  HASHMME - ");
2690
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2691
2692
0
    return size;
2693
0
}
2694
2695
/* 9.9.3.51 Replayed NAS message container
2696
 * O TLV-E 3-n */
2697
int ogs_nas_eps_decode_replayed_nas_message_container(ogs_nas_replayed_nas_message_container_t *replayed_nas_message_container, ogs_pkbuf_t *pkbuf)
2698
376
{
2699
376
    int size = 0;
2700
376
    ogs_nas_replayed_nas_message_container_t *source = NULL;
2701
2702
376
    if (pkbuf->len < 2) {
2703
9
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2704
9
       return -1;
2705
9
    }
2706
2707
367
    source = (ogs_nas_replayed_nas_message_container_t *)pkbuf->data;
2708
2709
367
    replayed_nas_message_container->length = be16toh(source->length);
2710
367
    size = replayed_nas_message_container->length + sizeof(replayed_nas_message_container->length);
2711
2712
367
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2713
14
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2714
14
       return -1;
2715
14
    }
2716
2717
353
    replayed_nas_message_container->buffer = pkbuf->data - size + sizeof(replayed_nas_message_container->length);
2718
2719
353
    ogs_trace("  REPLAYED_NAS_MESSAGE_CONTAINER - ");
2720
353
    ogs_log_hexdump(OGS_LOG_TRACE, (void*)replayed_nas_message_container->buffer, replayed_nas_message_container->length);
2721
2722
353
    return size;
2723
367
}
2724
2725
int ogs_nas_eps_encode_replayed_nas_message_container(ogs_pkbuf_t *pkbuf, ogs_nas_replayed_nas_message_container_t *replayed_nas_message_container)
2726
0
{
2727
0
    int size = 0;
2728
0
    int target;
2729
2730
0
    ogs_assert(replayed_nas_message_container);
2731
0
    ogs_assert(replayed_nas_message_container->buffer);
2732
2733
0
    size = sizeof(replayed_nas_message_container->length);
2734
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2735
0
    target = htobe16(replayed_nas_message_container->length);
2736
0
    memcpy(pkbuf->data - size, &target, size);
2737
2738
0
    size = replayed_nas_message_container->length;
2739
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2740
0
    memcpy(pkbuf->data - size, replayed_nas_message_container->buffer, size);
2741
2742
0
    ogs_trace("  REPLAYED_NAS_MESSAGE_CONTAINER - ");
2743
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2744
2745
0
    return replayed_nas_message_container->length + sizeof(replayed_nas_message_container->length);
2746
0
}
2747
2748
/* 9.9.3.52 Network policy
2749
 * O TV 1 */
2750
int ogs_nas_eps_decode_network_policy(ogs_nas_network_policy_t *network_policy, ogs_pkbuf_t *pkbuf)
2751
2.05k
{
2752
2.05k
    int size = sizeof(ogs_nas_network_policy_t);
2753
2754
2.05k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2755
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2756
0
       return -1;
2757
0
    }
2758
2759
2.05k
    memcpy(network_policy, pkbuf->data - size, size);
2760
2761
2.05k
    ogs_trace("  NETWORK_POLICY - ");
2762
2.05k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2763
2764
2.05k
    return size;
2765
2.05k
}
2766
2767
int ogs_nas_eps_encode_network_policy(ogs_pkbuf_t *pkbuf, ogs_nas_network_policy_t *network_policy)
2768
0
{
2769
0
    int size = sizeof(ogs_nas_network_policy_t);
2770
2771
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2772
0
    memcpy(pkbuf->data - size, network_policy, size);
2773
2774
0
    ogs_trace("  NETWORK_POLICY - ");
2775
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2776
2777
0
    return size;
2778
0
}
2779
2780
/* 9.9.3.53 UE additional security capability
2781
 * O TLV 6 */
2782
int ogs_nas_eps_decode_ue_additional_security_capability(ogs_nas_ue_additional_security_capability_t *ue_additional_security_capability, ogs_pkbuf_t *pkbuf)
2783
780
{
2784
780
    int size = 0;
2785
780
    ogs_nas_ue_additional_security_capability_t *source = NULL;
2786
2787
780
    if (pkbuf->len < 1) {
2788
8
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2789
8
       return -1;
2790
8
    }
2791
2792
772
    source = (ogs_nas_ue_additional_security_capability_t *)pkbuf->data;
2793
2794
772
    ue_additional_security_capability->length = source->length;
2795
772
    size = ue_additional_security_capability->length + sizeof(ue_additional_security_capability->length);
2796
2797
772
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2798
8
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2799
8
       return -1;
2800
8
    }
2801
2802
764
    if (sizeof(*ue_additional_security_capability) < size) return -1;
2803
762
    memcpy(ue_additional_security_capability, pkbuf->data - size, size);
2804
2805
762
    ogs_trace("  UE_ADDITIONAL_SECURITY_CAPABILITY - ");
2806
762
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2807
2808
762
    return size;
2809
764
}
2810
2811
int ogs_nas_eps_encode_ue_additional_security_capability(ogs_pkbuf_t *pkbuf, ogs_nas_ue_additional_security_capability_t *ue_additional_security_capability)
2812
0
{
2813
0
    int size = ue_additional_security_capability->length + sizeof(ue_additional_security_capability->length);
2814
0
    ogs_nas_ue_additional_security_capability_t target;
2815
2816
0
    memcpy(&target, ue_additional_security_capability, sizeof(ogs_nas_ue_additional_security_capability_t));
2817
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2818
0
    memcpy(pkbuf->data - size, &target, size);
2819
2820
0
    ogs_trace("  UE_ADDITIONAL_SECURITY_CAPABILITY - ");
2821
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2822
2823
0
    return size;
2824
0
}
2825
2826
/* 9.9.3.54 UE status
2827
 * O TLV 3 */
2828
int ogs_nas_eps_decode_ue_status(ogs_nas_ue_status_t *ue_status, ogs_pkbuf_t *pkbuf)
2829
540
{
2830
540
    int size = 0;
2831
540
    ogs_nas_ue_status_t *source = NULL;
2832
2833
540
    if (pkbuf->len < 1) {
2834
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2835
7
       return -1;
2836
7
    }
2837
2838
533
    source = (ogs_nas_ue_status_t *)pkbuf->data;
2839
2840
533
    ue_status->length = source->length;
2841
533
    size = ue_status->length + sizeof(ue_status->length);
2842
2843
533
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2844
5
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2845
5
       return -1;
2846
5
    }
2847
2848
528
    if (sizeof(*ue_status) < size) return -1;
2849
523
    memcpy(ue_status, pkbuf->data - size, size);
2850
2851
523
    ogs_trace("  UE_STATUS - ");
2852
523
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2853
2854
523
    return size;
2855
528
}
2856
2857
int ogs_nas_eps_encode_ue_status(ogs_pkbuf_t *pkbuf, ogs_nas_ue_status_t *ue_status)
2858
0
{
2859
0
    int size = ue_status->length + sizeof(ue_status->length);
2860
0
    ogs_nas_ue_status_t target;
2861
2862
0
    memcpy(&target, ue_status, sizeof(ogs_nas_ue_status_t));
2863
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2864
0
    memcpy(pkbuf->data - size, &target, size);
2865
2866
0
    ogs_trace("  UE_STATUS - ");
2867
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2868
2869
0
    return size;
2870
0
}
2871
2872
/* 9.9.3.55 Additional information requested
2873
 * O TV 2 */
2874
int ogs_nas_eps_decode_additional_information_requested(ogs_nas_additional_information_requested_t *additional_information_requested, ogs_pkbuf_t *pkbuf)
2875
649
{
2876
649
    int size = sizeof(ogs_nas_additional_information_requested_t);
2877
2878
649
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2879
9
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2880
9
       return -1;
2881
9
    }
2882
2883
640
    memcpy(additional_information_requested, pkbuf->data - size, size);
2884
2885
640
    ogs_trace("  ADDITIONAL_INFORMATION_REQUESTED - ");
2886
640
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2887
2888
640
    return size;
2889
649
}
2890
2891
int ogs_nas_eps_encode_additional_information_requested(ogs_pkbuf_t *pkbuf, ogs_nas_additional_information_requested_t *additional_information_requested)
2892
0
{
2893
0
    int size = sizeof(ogs_nas_additional_information_requested_t);
2894
0
    ogs_nas_additional_information_requested_t target;
2895
2896
0
    memcpy(&target, additional_information_requested, size);
2897
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2898
0
    memcpy(pkbuf->data - size, &target, size);
2899
2900
0
    ogs_trace("  ADDITIONAL_INFORMATION_REQUESTED - ");
2901
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2902
2903
0
    return size;
2904
0
}
2905
2906
/* 9.9.3.56 Ciphering key data
2907
 * O TLV-E 35-2291 */
2908
int ogs_nas_eps_decode_ciphering_key_data(ogs_nas_ciphering_key_data_t *ciphering_key_data, ogs_pkbuf_t *pkbuf)
2909
599
{
2910
599
    int size = 0;
2911
599
    ogs_nas_ciphering_key_data_t *source = NULL;
2912
2913
599
    if (pkbuf->len < 2) {
2914
9
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2915
9
       return -1;
2916
9
    }
2917
2918
590
    source = (ogs_nas_ciphering_key_data_t *)pkbuf->data;
2919
2920
590
    ciphering_key_data->length = be16toh(source->length);
2921
590
    size = ciphering_key_data->length + sizeof(ciphering_key_data->length);
2922
2923
590
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2924
11
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2925
11
       return -1;
2926
11
    }
2927
2928
579
    ciphering_key_data->buffer = pkbuf->data - size + sizeof(ciphering_key_data->length);
2929
2930
579
    ogs_trace("  CIPHERING_KEY_DATA - ");
2931
579
    ogs_log_hexdump(OGS_LOG_TRACE, (void*)ciphering_key_data->buffer, ciphering_key_data->length);
2932
2933
579
    return size;
2934
590
}
2935
2936
int ogs_nas_eps_encode_ciphering_key_data(ogs_pkbuf_t *pkbuf, ogs_nas_ciphering_key_data_t *ciphering_key_data)
2937
0
{
2938
0
    int size = 0;
2939
0
    int target;
2940
2941
0
    ogs_assert(ciphering_key_data);
2942
0
    ogs_assert(ciphering_key_data->buffer);
2943
2944
0
    size = sizeof(ciphering_key_data->length);
2945
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2946
0
    target = htobe16(ciphering_key_data->length);
2947
0
    memcpy(pkbuf->data - size, &target, size);
2948
2949
0
    size = ciphering_key_data->length;
2950
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2951
0
    memcpy(pkbuf->data - size, ciphering_key_data->buffer, size);
2952
2953
0
    ogs_trace("  CIPHERING_KEY_DATA - ");
2954
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2955
2956
0
    return ciphering_key_data->length + sizeof(ciphering_key_data->length);
2957
0
}
2958
2959
/* 9.9.3.57 N1 UE network capability
2960
 * O TLV 3-15 */
2961
int ogs_nas_eps_decode_n1_ue_network_capability(ogs_nas_n1_ue_network_capability_t *n1_ue_network_capability, ogs_pkbuf_t *pkbuf)
2962
660
{
2963
660
    int size = 0;
2964
660
    ogs_nas_n1_ue_network_capability_t *source = NULL;
2965
2966
660
    if (pkbuf->len < 1) {
2967
8
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
2968
8
       return -1;
2969
8
    }
2970
2971
652
    source = (ogs_nas_n1_ue_network_capability_t *)pkbuf->data;
2972
2973
652
    n1_ue_network_capability->length = source->length;
2974
652
    size = n1_ue_network_capability->length + sizeof(n1_ue_network_capability->length);
2975
2976
652
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
2977
3
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
2978
3
       return -1;
2979
3
    }
2980
2981
649
    if (sizeof(*n1_ue_network_capability) < size) return -1;
2982
646
    memcpy(n1_ue_network_capability, pkbuf->data - size, size);
2983
2984
646
    ogs_trace("  N1_UE_NETWORK_CAPABILITY - ");
2985
646
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
2986
2987
646
    return size;
2988
649
}
2989
2990
int ogs_nas_eps_encode_n1_ue_network_capability(ogs_pkbuf_t *pkbuf, ogs_nas_n1_ue_network_capability_t *n1_ue_network_capability)
2991
0
{
2992
0
    int size = n1_ue_network_capability->length + sizeof(n1_ue_network_capability->length);
2993
0
    ogs_nas_n1_ue_network_capability_t target;
2994
2995
0
    memcpy(&target, n1_ue_network_capability, sizeof(ogs_nas_n1_ue_network_capability_t));
2996
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
2997
0
    memcpy(pkbuf->data - size, &target, size);
2998
2999
0
    ogs_trace("  N1_UE_NETWORK_CAPABILITY - ");
3000
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3001
3002
0
    return size;
3003
0
}
3004
3005
/* 9.9.3.58 UE radio capability ID availability
3006
 * O TLV 3 */
3007
int ogs_nas_eps_decode_ue_radio_capability_id_availability(ogs_nas_ue_radio_capability_id_availability_t *ue_radio_capability_id_availability, ogs_pkbuf_t *pkbuf)
3008
488
{
3009
488
    int size = 0;
3010
488
    ogs_nas_ue_radio_capability_id_availability_t *source = NULL;
3011
3012
488
    if (pkbuf->len < 1) {
3013
8
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3014
8
       return -1;
3015
8
    }
3016
3017
480
    source = (ogs_nas_ue_radio_capability_id_availability_t *)pkbuf->data;
3018
3019
480
    ue_radio_capability_id_availability->length = source->length;
3020
480
    size = ue_radio_capability_id_availability->length + sizeof(ue_radio_capability_id_availability->length);
3021
3022
480
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3023
1
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3024
1
       return -1;
3025
1
    }
3026
3027
479
    if (sizeof(*ue_radio_capability_id_availability) < size) return -1;
3028
477
    memcpy(ue_radio_capability_id_availability, pkbuf->data - size, size);
3029
3030
477
    ogs_trace("  UE_RADIO_CAPABILITY_ID_AVAILABILITY - ");
3031
477
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3032
3033
477
    return size;
3034
479
}
3035
3036
int ogs_nas_eps_encode_ue_radio_capability_id_availability(ogs_pkbuf_t *pkbuf, ogs_nas_ue_radio_capability_id_availability_t *ue_radio_capability_id_availability)
3037
0
{
3038
0
    int size = ue_radio_capability_id_availability->length + sizeof(ue_radio_capability_id_availability->length);
3039
0
    ogs_nas_ue_radio_capability_id_availability_t target;
3040
3041
0
    memcpy(&target, ue_radio_capability_id_availability, sizeof(ogs_nas_ue_radio_capability_id_availability_t));
3042
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3043
0
    memcpy(pkbuf->data - size, &target, size);
3044
3045
0
    ogs_trace("  UE_RADIO_CAPABILITY_ID_AVAILABILITY - ");
3046
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3047
3048
0
    return size;
3049
0
}
3050
3051
/* 9.9.3.59 UE radio capability ID request
3052
 * O TLV 3 */
3053
int ogs_nas_eps_decode_ue_radio_capability_id_request(ogs_nas_ue_radio_capability_id_request_t *ue_radio_capability_id_request, ogs_pkbuf_t *pkbuf)
3054
357
{
3055
357
    int size = 0;
3056
357
    ogs_nas_ue_radio_capability_id_request_t *source = NULL;
3057
3058
357
    if (pkbuf->len < 1) {
3059
6
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3060
6
       return -1;
3061
6
    }
3062
3063
351
    source = (ogs_nas_ue_radio_capability_id_request_t *)pkbuf->data;
3064
3065
351
    ue_radio_capability_id_request->length = source->length;
3066
351
    size = ue_radio_capability_id_request->length + sizeof(ue_radio_capability_id_request->length);
3067
3068
351
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3069
1
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3070
1
       return -1;
3071
1
    }
3072
3073
350
    if (sizeof(*ue_radio_capability_id_request) < size) return -1;
3074
349
    memcpy(ue_radio_capability_id_request, pkbuf->data - size, size);
3075
3076
349
    ogs_trace("  UE_RADIO_CAPABILITY_ID_REQUEST - ");
3077
349
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3078
3079
349
    return size;
3080
350
}
3081
3082
int ogs_nas_eps_encode_ue_radio_capability_id_request(ogs_pkbuf_t *pkbuf, ogs_nas_ue_radio_capability_id_request_t *ue_radio_capability_id_request)
3083
0
{
3084
0
    int size = ue_radio_capability_id_request->length + sizeof(ue_radio_capability_id_request->length);
3085
0
    ogs_nas_ue_radio_capability_id_request_t target;
3086
3087
0
    memcpy(&target, ue_radio_capability_id_request, sizeof(ogs_nas_ue_radio_capability_id_request_t));
3088
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3089
0
    memcpy(pkbuf->data - size, &target, size);
3090
3091
0
    ogs_trace("  UE_RADIO_CAPABILITY_ID_REQUEST - ");
3092
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3093
3094
0
    return size;
3095
0
}
3096
3097
/* 9.9.3.6 Daylight saving time
3098
 * O TLV 3 */
3099
int ogs_nas_eps_decode_daylight_saving_time(ogs_nas_daylight_saving_time_t *daylight_saving_time, ogs_pkbuf_t *pkbuf)
3100
575
{
3101
575
    int size = 0;
3102
575
    ogs_nas_daylight_saving_time_t *source = NULL;
3103
3104
575
    if (pkbuf->len < 1) {
3105
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3106
7
       return -1;
3107
7
    }
3108
3109
568
    source = (ogs_nas_daylight_saving_time_t *)pkbuf->data;
3110
3111
568
    daylight_saving_time->length = source->length;
3112
568
    size = daylight_saving_time->length + sizeof(daylight_saving_time->length);
3113
3114
568
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3115
3
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3116
3
       return -1;
3117
3
    }
3118
3119
565
    if (sizeof(*daylight_saving_time) < size) return -1;
3120
563
    memcpy(daylight_saving_time, pkbuf->data - size, size);
3121
3122
563
    ogs_trace("  DAYLIGHT_SAVING_TIME - ");
3123
563
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3124
3125
563
    return size;
3126
565
}
3127
3128
int ogs_nas_eps_encode_daylight_saving_time(ogs_pkbuf_t *pkbuf, ogs_nas_daylight_saving_time_t *daylight_saving_time)
3129
0
{
3130
0
    int size = daylight_saving_time->length + sizeof(daylight_saving_time->length);
3131
0
    ogs_nas_daylight_saving_time_t target;
3132
3133
0
    memcpy(&target, daylight_saving_time, sizeof(ogs_nas_daylight_saving_time_t));
3134
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3135
0
    memcpy(pkbuf->data - size, &target, size);
3136
3137
0
    ogs_trace("  DAYLIGHT_SAVING_TIME - ");
3138
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3139
3140
0
    return size;
3141
0
}
3142
3143
/* 9.9.3.60 UE radio capability ID
3144
 * O TLV 3-n */
3145
int ogs_nas_eps_decode_ue_radio_capability_id(ogs_nas_ue_radio_capability_id_t *ue_radio_capability_id, ogs_pkbuf_t *pkbuf)
3146
974
{
3147
974
    int size = 0;
3148
974
    ogs_nas_ue_radio_capability_id_t *source = NULL;
3149
3150
974
    if (pkbuf->len < 1) {
3151
6
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3152
6
       return -1;
3153
6
    }
3154
3155
968
    source = (ogs_nas_ue_radio_capability_id_t *)pkbuf->data;
3156
3157
968
    ue_radio_capability_id->length = source->length;
3158
968
    size = ue_radio_capability_id->length + sizeof(ue_radio_capability_id->length);
3159
3160
968
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3161
9
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3162
9
       return -1;
3163
9
    }
3164
3165
959
    if (sizeof(*ue_radio_capability_id) < size) return -1;
3166
959
    memcpy(ue_radio_capability_id, pkbuf->data - size, size);
3167
3168
959
    ogs_trace("  UE_RADIO_CAPABILITY_ID - ");
3169
959
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3170
3171
959
    return size;
3172
959
}
3173
3174
int ogs_nas_eps_encode_ue_radio_capability_id(ogs_pkbuf_t *pkbuf, ogs_nas_ue_radio_capability_id_t *ue_radio_capability_id)
3175
0
{
3176
0
    int size = ue_radio_capability_id->length + sizeof(ue_radio_capability_id->length);
3177
0
    ogs_nas_ue_radio_capability_id_t target;
3178
3179
0
    memcpy(&target, ue_radio_capability_id, sizeof(ogs_nas_ue_radio_capability_id_t));
3180
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3181
0
    memcpy(pkbuf->data - size, &target, size);
3182
3183
0
    ogs_trace("  UE_RADIO_CAPABILITY_ID - ");
3184
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3185
3186
0
    return size;
3187
0
}
3188
3189
/* 9.9.3.61 UE radio capability ID deletion indication
3190
 * O TV 1 */
3191
int ogs_nas_eps_decode_ue_radio_capability_id_deletion_indication(ogs_nas_ue_radio_capability_id_deletion_indication_t *ue_radio_capability_id_deletion_indication, ogs_pkbuf_t *pkbuf)
3192
2.26k
{
3193
2.26k
    int size = sizeof(ogs_nas_ue_radio_capability_id_deletion_indication_t);
3194
3195
2.26k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3196
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3197
0
       return -1;
3198
0
    }
3199
3200
2.26k
    memcpy(ue_radio_capability_id_deletion_indication, pkbuf->data - size, size);
3201
3202
2.26k
    ogs_trace("  UE_RADIO_CAPABILITY_ID_DELETION_INDICATION - ");
3203
2.26k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3204
3205
2.26k
    return size;
3206
2.26k
}
3207
3208
int ogs_nas_eps_encode_ue_radio_capability_id_deletion_indication(ogs_pkbuf_t *pkbuf, ogs_nas_ue_radio_capability_id_deletion_indication_t *ue_radio_capability_id_deletion_indication)
3209
0
{
3210
0
    int size = sizeof(ogs_nas_ue_radio_capability_id_deletion_indication_t);
3211
3212
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3213
0
    memcpy(pkbuf->data - size, ue_radio_capability_id_deletion_indication, size);
3214
3215
0
    ogs_trace("  UE_RADIO_CAPABILITY_ID_DELETION_INDICATION - ");
3216
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3217
3218
0
    return size;
3219
0
}
3220
3221
/* 9.9.3.62 WUS assistance information
3222
 * O TLV 3-n */
3223
int ogs_nas_eps_decode_wus_assistance_information(ogs_nas_wus_assistance_information_t *wus_assistance_information, ogs_pkbuf_t *pkbuf)
3224
973
{
3225
973
    int size = 0;
3226
973
    ogs_nas_wus_assistance_information_t *source = NULL;
3227
3228
973
    if (pkbuf->len < 1) {
3229
6
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3230
6
       return -1;
3231
6
    }
3232
3233
967
    source = (ogs_nas_wus_assistance_information_t *)pkbuf->data;
3234
3235
967
    wus_assistance_information->length = source->length;
3236
967
    size = wus_assistance_information->length + sizeof(wus_assistance_information->length);
3237
3238
967
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3239
5
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3240
5
       return -1;
3241
5
    }
3242
3243
962
    if (sizeof(*wus_assistance_information) < size) return -1;
3244
962
    memcpy(wus_assistance_information, pkbuf->data - size, size);
3245
3246
962
    ogs_trace("  WUS_ASSISTANCE_INFORMATION - ");
3247
962
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3248
3249
962
    return size;
3250
962
}
3251
3252
int ogs_nas_eps_encode_wus_assistance_information(ogs_pkbuf_t *pkbuf, ogs_nas_wus_assistance_information_t *wus_assistance_information)
3253
0
{
3254
0
    int size = wus_assistance_information->length + sizeof(wus_assistance_information->length);
3255
0
    ogs_nas_wus_assistance_information_t target;
3256
3257
0
    memcpy(&target, wus_assistance_information, sizeof(ogs_nas_wus_assistance_information_t));
3258
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3259
0
    memcpy(pkbuf->data - size, &target, size);
3260
3261
0
    ogs_trace("  WUS_ASSISTANCE_INFORMATION - ");
3262
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3263
3264
0
    return size;
3265
0
}
3266
3267
/* 9.9.3.63 NB-S1 DRX parameter
3268
 * O TLV 3 */
3269
int ogs_nas_eps_decode_nb_s1_drx_parameter(ogs_nas_nb_s1_drx_parameter_t *nb_s1_drx_parameter, ogs_pkbuf_t *pkbuf)
3270
1.07k
{
3271
1.07k
    int size = 0;
3272
1.07k
    ogs_nas_nb_s1_drx_parameter_t *source = NULL;
3273
3274
1.07k
    if (pkbuf->len < 1) {
3275
9
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3276
9
       return -1;
3277
9
    }
3278
3279
1.06k
    source = (ogs_nas_nb_s1_drx_parameter_t *)pkbuf->data;
3280
3281
1.06k
    nb_s1_drx_parameter->length = source->length;
3282
1.06k
    size = nb_s1_drx_parameter->length + sizeof(nb_s1_drx_parameter->length);
3283
3284
1.06k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3285
3
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3286
3
       return -1;
3287
3
    }
3288
3289
1.05k
    if (sizeof(*nb_s1_drx_parameter) < size) return -1;
3290
1.05k
    memcpy(nb_s1_drx_parameter, pkbuf->data - size, size);
3291
3292
1.05k
    ogs_trace("  NB_S1_DRX_PARAMETER - ");
3293
1.05k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3294
3295
1.05k
    return size;
3296
1.05k
}
3297
3298
int ogs_nas_eps_encode_nb_s1_drx_parameter(ogs_pkbuf_t *pkbuf, ogs_nas_nb_s1_drx_parameter_t *nb_s1_drx_parameter)
3299
0
{
3300
0
    int size = nb_s1_drx_parameter->length + sizeof(nb_s1_drx_parameter->length);
3301
0
    ogs_nas_nb_s1_drx_parameter_t target;
3302
3303
0
    memcpy(&target, nb_s1_drx_parameter, sizeof(ogs_nas_nb_s1_drx_parameter_t));
3304
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3305
0
    memcpy(pkbuf->data - size, &target, size);
3306
3307
0
    ogs_trace("  NB_S1_DRX_PARAMETER - ");
3308
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3309
3310
0
    return size;
3311
0
}
3312
3313
/* 9.9.3.64 IMSI offset
3314
 * O TLV 4 */
3315
int ogs_nas_eps_decode_imsi_offset(ogs_nas_imsi_offset_t *imsi_offset, ogs_pkbuf_t *pkbuf)
3316
939
{
3317
939
    int size = 0;
3318
939
    ogs_nas_imsi_offset_t *source = NULL;
3319
3320
939
    if (pkbuf->len < 1) {
3321
6
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3322
6
       return -1;
3323
6
    }
3324
3325
933
    source = (ogs_nas_imsi_offset_t *)pkbuf->data;
3326
3327
933
    imsi_offset->length = source->length;
3328
933
    size = imsi_offset->length + sizeof(imsi_offset->length);
3329
3330
933
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3331
3
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3332
3
       return -1;
3333
3
    }
3334
3335
930
    if (sizeof(*imsi_offset) < size) return -1;
3336
929
    memcpy(imsi_offset, pkbuf->data - size, size);
3337
3338
929
    ogs_trace("  IMSI_OFFSET - ");
3339
929
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3340
3341
929
    return size;
3342
930
}
3343
3344
int ogs_nas_eps_encode_imsi_offset(ogs_pkbuf_t *pkbuf, ogs_nas_imsi_offset_t *imsi_offset)
3345
0
{
3346
0
    int size = imsi_offset->length + sizeof(imsi_offset->length);
3347
0
    ogs_nas_imsi_offset_t target;
3348
3349
0
    memcpy(&target, imsi_offset, sizeof(ogs_nas_imsi_offset_t));
3350
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3351
0
    memcpy(pkbuf->data - size, &target, size);
3352
3353
0
    ogs_trace("  IMSI_OFFSET - ");
3354
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3355
3356
0
    return size;
3357
0
}
3358
3359
/* 9.9.3.65 UE request type
3360
 * O TLV 3 */
3361
int ogs_nas_eps_decode_ue_request_type(ogs_nas_ue_request_type_t *ue_request_type, ogs_pkbuf_t *pkbuf)
3362
613
{
3363
613
    int size = 0;
3364
613
    ogs_nas_ue_request_type_t *source = NULL;
3365
3366
613
    if (pkbuf->len < 1) {
3367
8
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3368
8
       return -1;
3369
8
    }
3370
3371
605
    source = (ogs_nas_ue_request_type_t *)pkbuf->data;
3372
3373
605
    ue_request_type->length = source->length;
3374
605
    size = ue_request_type->length + sizeof(ue_request_type->length);
3375
3376
605
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3377
1
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3378
1
       return -1;
3379
1
    }
3380
3381
604
    if (sizeof(*ue_request_type) < size) return -1;
3382
603
    memcpy(ue_request_type, pkbuf->data - size, size);
3383
3384
603
    ogs_trace("  UE_REQUEST_TYPE - ");
3385
603
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3386
3387
603
    return size;
3388
604
}
3389
3390
int ogs_nas_eps_encode_ue_request_type(ogs_pkbuf_t *pkbuf, ogs_nas_ue_request_type_t *ue_request_type)
3391
0
{
3392
0
    int size = ue_request_type->length + sizeof(ue_request_type->length);
3393
0
    ogs_nas_ue_request_type_t target;
3394
3395
0
    memcpy(&target, ue_request_type, sizeof(ogs_nas_ue_request_type_t));
3396
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3397
0
    memcpy(pkbuf->data - size, &target, size);
3398
3399
0
    ogs_trace("  UE_REQUEST_TYPE - ");
3400
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3401
3402
0
    return size;
3403
0
}
3404
3405
/* 9.9.3.66 Paging restriction
3406
 * O TLV 3-5 */
3407
int ogs_nas_eps_decode_paging_restriction(ogs_nas_paging_restriction_t *paging_restriction, ogs_pkbuf_t *pkbuf)
3408
635
{
3409
635
    int size = 0;
3410
635
    ogs_nas_paging_restriction_t *source = NULL;
3411
3412
635
    if (pkbuf->len < 1) {
3413
7
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3414
7
       return -1;
3415
7
    }
3416
3417
628
    source = (ogs_nas_paging_restriction_t *)pkbuf->data;
3418
3419
628
    paging_restriction->length = source->length;
3420
628
    size = paging_restriction->length + sizeof(paging_restriction->length);
3421
3422
628
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3423
1
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3424
1
       return -1;
3425
1
    }
3426
3427
627
    if (sizeof(*paging_restriction) < size) return -1;
3428
626
    memcpy(paging_restriction, pkbuf->data - size, size);
3429
3430
626
    ogs_trace("  PAGING_RESTRICTION - ");
3431
626
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3432
3433
626
    return size;
3434
627
}
3435
3436
int ogs_nas_eps_encode_paging_restriction(ogs_pkbuf_t *pkbuf, ogs_nas_paging_restriction_t *paging_restriction)
3437
0
{
3438
0
    int size = paging_restriction->length + sizeof(paging_restriction->length);
3439
0
    ogs_nas_paging_restriction_t target;
3440
3441
0
    memcpy(&target, paging_restriction, sizeof(ogs_nas_paging_restriction_t));
3442
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3443
0
    memcpy(pkbuf->data - size, &target, size);
3444
3445
0
    ogs_trace("  PAGING_RESTRICTION - ");
3446
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3447
3448
0
    return size;
3449
0
}
3450
3451
/* 9.9.3.67 EPS additional request result
3452
 * O TLV 3 */
3453
int ogs_nas_eps_decode_eps_additional_request_result(ogs_nas_eps_additional_request_result_t *eps_additional_request_result, ogs_pkbuf_t *pkbuf)
3454
398
{
3455
398
    int size = 0;
3456
398
    ogs_nas_eps_additional_request_result_t *source = NULL;
3457
3458
398
    if (pkbuf->len < 1) {
3459
8
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3460
8
       return -1;
3461
8
    }
3462
3463
390
    source = (ogs_nas_eps_additional_request_result_t *)pkbuf->data;
3464
3465
390
    eps_additional_request_result->length = source->length;
3466
390
    size = eps_additional_request_result->length + sizeof(eps_additional_request_result->length);
3467
3468
390
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3469
2
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3470
2
       return -1;
3471
2
    }
3472
3473
388
    if (sizeof(*eps_additional_request_result) < size) return -1;
3474
387
    memcpy(eps_additional_request_result, pkbuf->data - size, size);
3475
3476
387
    ogs_trace("  EPS_ADDITIONAL_REQUEST_RESULT - ");
3477
387
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3478
3479
387
    return size;
3480
388
}
3481
3482
int ogs_nas_eps_encode_eps_additional_request_result(ogs_pkbuf_t *pkbuf, ogs_nas_eps_additional_request_result_t *eps_additional_request_result)
3483
0
{
3484
0
    int size = eps_additional_request_result->length + sizeof(eps_additional_request_result->length);
3485
0
    ogs_nas_eps_additional_request_result_t target;
3486
3487
0
    memcpy(&target, eps_additional_request_result, sizeof(ogs_nas_eps_additional_request_result_t));
3488
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3489
0
    memcpy(pkbuf->data - size, &target, size);
3490
3491
0
    ogs_trace("  EPS_ADDITIONAL_REQUEST_RESULT - ");
3492
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3493
3494
0
    return size;
3495
0
}
3496
3497
/* 9.9.3.7 Detach type
3498
 * M V 1/2 */
3499
int ogs_nas_eps_decode_detach_type(ogs_nas_detach_type_t *detach_type, ogs_pkbuf_t *pkbuf)
3500
7
{
3501
7
    int size = sizeof(ogs_nas_detach_type_t);
3502
3503
7
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3504
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3505
0
       return -1;
3506
0
    }
3507
3508
7
    memcpy(detach_type, pkbuf->data - size, size);
3509
3510
7
    ogs_trace("  DETACH_TYPE - ");
3511
7
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3512
3513
7
    return size;
3514
7
}
3515
3516
int ogs_nas_eps_encode_detach_type(ogs_pkbuf_t *pkbuf, ogs_nas_detach_type_t *detach_type)
3517
0
{
3518
0
    int size = sizeof(ogs_nas_detach_type_t);
3519
0
    ogs_nas_detach_type_t target;
3520
3521
0
    memcpy(&target, detach_type, size);
3522
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3523
0
    memcpy(pkbuf->data - size, &target, size);
3524
3525
0
    ogs_trace("  DETACH_TYPE - ");
3526
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3527
3528
0
    return size;
3529
0
}
3530
3531
/* 9.9.3.8 DRX parameter
3532
 * O TV 3 */
3533
int ogs_nas_eps_decode_drx_parameter(ogs_nas_drx_parameter_t *drx_parameter, ogs_pkbuf_t *pkbuf)
3534
513
{
3535
513
    int size = sizeof(ogs_nas_drx_parameter_t);
3536
3537
513
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3538
9
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3539
9
       return -1;
3540
9
    }
3541
3542
504
    memcpy(drx_parameter, pkbuf->data - size, size);
3543
3544
504
    ogs_trace("  DRX_PARAMETER - ");
3545
504
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3546
3547
504
    return size;
3548
513
}
3549
3550
int ogs_nas_eps_encode_drx_parameter(ogs_pkbuf_t *pkbuf, ogs_nas_drx_parameter_t *drx_parameter)
3551
0
{
3552
0
    int size = sizeof(ogs_nas_drx_parameter_t);
3553
0
    ogs_nas_drx_parameter_t target;
3554
3555
0
    memcpy(&target, drx_parameter, size);
3556
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3557
0
    memcpy(pkbuf->data - size, &target, size);
3558
3559
0
    ogs_trace("  DRX_PARAMETER - ");
3560
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3561
3562
0
    return size;
3563
0
}
3564
3565
/* 9.9.3.9 EMM cause
3566
 * O TV 2 */
3567
int ogs_nas_eps_decode_emm_cause(ogs_nas_emm_cause_t *emm_cause, ogs_pkbuf_t *pkbuf)
3568
1.05k
{
3569
1.05k
    int size = sizeof(ogs_nas_emm_cause_t);
3570
3571
1.05k
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3572
7
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3573
7
       return -1;
3574
7
    }
3575
3576
1.04k
    memcpy(emm_cause, pkbuf->data - size, size);
3577
3578
1.04k
    ogs_trace("  EMM_CAUSE - ");
3579
1.04k
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3580
3581
1.04k
    return size;
3582
1.05k
}
3583
3584
int ogs_nas_eps_encode_emm_cause(ogs_pkbuf_t *pkbuf, ogs_nas_emm_cause_t *emm_cause)
3585
0
{
3586
0
    int size = sizeof(ogs_nas_emm_cause_t);
3587
0
    ogs_nas_emm_cause_t target;
3588
3589
0
    memcpy(&target, emm_cause, size);
3590
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3591
0
    memcpy(pkbuf->data - size, &target, size);
3592
3593
0
    ogs_trace("  EMM_CAUSE - ");
3594
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3595
3596
0
    return size;
3597
0
}
3598
3599
/* 9.9.4.1 Access point name
3600
 * M LV 2-101 */
3601
int ogs_nas_eps_decode_access_point_name(ogs_nas_access_point_name_t *access_point_name, ogs_pkbuf_t *pkbuf)
3602
0
{
3603
0
    int size = 0;
3604
0
    ogs_nas_access_point_name_t *source = NULL;
3605
3606
0
    if (pkbuf->len < 1) {
3607
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3608
0
       return -1;
3609
0
    }
3610
3611
0
    source = (ogs_nas_access_point_name_t *)pkbuf->data;
3612
3613
0
    access_point_name->length = source->length;
3614
0
    size = access_point_name->length + sizeof(access_point_name->length);
3615
3616
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3617
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3618
0
       return -1;
3619
0
    }
3620
3621
0
    if (sizeof(*access_point_name) < size) return -1;
3622
0
    memcpy(access_point_name, pkbuf->data - size, size);
3623
3624
0
    {
3625
0
        char apn[OGS_MAX_APN_LEN+1];
3626
0
        access_point_name->length = ogs_fqdn_parse(apn, access_point_name->apn, ogs_min(access_point_name->length, OGS_MAX_APN_LEN));
3627
0
        if (access_point_name->length > 0) {
3628
0
            ogs_cpystrn(access_point_name->apn, apn, ogs_min(access_point_name->length, OGS_MAX_APN_LEN)+1);
3629
0
        } else {
3630
0
            ogs_error("UE not APN setting");
3631
0
        }
3632
0
    }
3633
3634
0
    ogs_trace("  ACCESS_POINT_NAME - ");
3635
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3636
3637
0
    return size;
3638
0
}
3639
3640
int ogs_nas_eps_encode_access_point_name(ogs_pkbuf_t *pkbuf, ogs_nas_access_point_name_t *access_point_name)
3641
0
{
3642
0
    int size = access_point_name->length + sizeof(access_point_name->length);
3643
0
    ogs_nas_access_point_name_t target;
3644
3645
0
    memcpy(&target, access_point_name, sizeof(ogs_nas_access_point_name_t));
3646
0
    target.length = ogs_fqdn_build(target.apn, access_point_name->apn, access_point_name->length);
3647
0
    size = target.length + sizeof(target.length);
3648
3649
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3650
0
    memcpy(pkbuf->data - size, &target, size);
3651
3652
0
    ogs_trace("  ACCESS_POINT_NAME - ");
3653
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3654
3655
0
    return size;
3656
0
}
3657
3658
/* 9.9.4.11 Protocol configuration options
3659
 * O TLV 3-253 */
3660
int ogs_nas_eps_decode_protocol_configuration_options(ogs_nas_protocol_configuration_options_t *protocol_configuration_options, ogs_pkbuf_t *pkbuf)
3661
0
{
3662
0
    int size = 0;
3663
0
    ogs_nas_protocol_configuration_options_t *source = NULL;
3664
3665
0
    if (pkbuf->len < 1) {
3666
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3667
0
       return -1;
3668
0
    }
3669
3670
0
    source = (ogs_nas_protocol_configuration_options_t *)pkbuf->data;
3671
3672
0
    protocol_configuration_options->length = source->length;
3673
0
    size = protocol_configuration_options->length + sizeof(protocol_configuration_options->length);
3674
3675
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3676
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3677
0
       return -1;
3678
0
    }
3679
3680
0
    if (sizeof(*protocol_configuration_options) < size) return -1;
3681
0
    memcpy(protocol_configuration_options, pkbuf->data - size, size);
3682
3683
0
    ogs_trace("  PROTOCOL_CONFIGURATION_OPTIONS - ");
3684
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3685
3686
0
    return size;
3687
0
}
3688
3689
int ogs_nas_eps_encode_protocol_configuration_options(ogs_pkbuf_t *pkbuf, ogs_nas_protocol_configuration_options_t *protocol_configuration_options)
3690
0
{
3691
0
    int size = protocol_configuration_options->length + sizeof(protocol_configuration_options->length);
3692
0
    ogs_nas_protocol_configuration_options_t target;
3693
3694
0
    memcpy(&target, protocol_configuration_options, sizeof(ogs_nas_protocol_configuration_options_t));
3695
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3696
0
    memcpy(pkbuf->data - size, &target, size);
3697
3698
0
    ogs_trace("  PROTOCOL_CONFIGURATION_OPTIONS - ");
3699
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3700
3701
0
    return size;
3702
0
}
3703
3704
/* 9.9.4.12 Quality of service
3705
 * O TLV 14-22 */
3706
int ogs_nas_eps_decode_quality_of_service(ogs_nas_quality_of_service_t *quality_of_service, ogs_pkbuf_t *pkbuf)
3707
0
{
3708
0
    int size = 0;
3709
0
    ogs_nas_quality_of_service_t *source = NULL;
3710
3711
0
    if (pkbuf->len < 1) {
3712
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3713
0
       return -1;
3714
0
    }
3715
3716
0
    source = (ogs_nas_quality_of_service_t *)pkbuf->data;
3717
3718
0
    quality_of_service->length = source->length;
3719
0
    size = quality_of_service->length + sizeof(quality_of_service->length);
3720
3721
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3722
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3723
0
       return -1;
3724
0
    }
3725
3726
0
    if (sizeof(*quality_of_service) < size) return -1;
3727
0
    memcpy(quality_of_service, pkbuf->data - size, size);
3728
3729
0
    ogs_trace("  QUALITY_OF_SERVICE - ");
3730
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3731
3732
0
    return size;
3733
0
}
3734
3735
int ogs_nas_eps_encode_quality_of_service(ogs_pkbuf_t *pkbuf, ogs_nas_quality_of_service_t *quality_of_service)
3736
0
{
3737
0
    int size = quality_of_service->length + sizeof(quality_of_service->length);
3738
0
    ogs_nas_quality_of_service_t target;
3739
3740
0
    memcpy(&target, quality_of_service, sizeof(ogs_nas_quality_of_service_t));
3741
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3742
0
    memcpy(pkbuf->data - size, &target, size);
3743
3744
0
    ogs_trace("  QUALITY_OF_SERVICE - ");
3745
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3746
3747
0
    return size;
3748
0
}
3749
3750
/* 9.9.4.13 Radio priority
3751
 * O TV 1 */
3752
int ogs_nas_eps_decode_radio_priority(ogs_nas_radio_priority_t *radio_priority, ogs_pkbuf_t *pkbuf)
3753
0
{
3754
0
    int size = sizeof(ogs_nas_radio_priority_t);
3755
3756
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3757
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3758
0
       return -1;
3759
0
    }
3760
3761
0
    memcpy(radio_priority, pkbuf->data - size, size);
3762
3763
0
    ogs_trace("  RADIO_PRIORITY - ");
3764
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3765
3766
0
    return size;
3767
0
}
3768
3769
int ogs_nas_eps_encode_radio_priority(ogs_pkbuf_t *pkbuf, ogs_nas_radio_priority_t *radio_priority)
3770
0
{
3771
0
    int size = sizeof(ogs_nas_radio_priority_t);
3772
3773
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3774
0
    memcpy(pkbuf->data - size, radio_priority, size);
3775
3776
0
    ogs_trace("  RADIO_PRIORITY - ");
3777
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3778
3779
0
    return size;
3780
0
}
3781
3782
/* 9.9.4.13A Re-attempt indicator
3783
 * O TLV 3 */
3784
int ogs_nas_eps_decode_re_attempt_indicator(ogs_nas_re_attempt_indicator_t *re_attempt_indicator, ogs_pkbuf_t *pkbuf)
3785
0
{
3786
0
    int size = 0;
3787
0
    ogs_nas_re_attempt_indicator_t *source = NULL;
3788
3789
0
    if (pkbuf->len < 1) {
3790
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3791
0
       return -1;
3792
0
    }
3793
3794
0
    source = (ogs_nas_re_attempt_indicator_t *)pkbuf->data;
3795
3796
0
    re_attempt_indicator->length = source->length;
3797
0
    size = re_attempt_indicator->length + sizeof(re_attempt_indicator->length);
3798
3799
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3800
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3801
0
       return -1;
3802
0
    }
3803
3804
0
    if (sizeof(*re_attempt_indicator) < size) return -1;
3805
0
    memcpy(re_attempt_indicator, pkbuf->data - size, size);
3806
3807
0
    ogs_trace("  RE_ATTEMPT_INDICATOR - ");
3808
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3809
3810
0
    return size;
3811
0
}
3812
3813
int ogs_nas_eps_encode_re_attempt_indicator(ogs_pkbuf_t *pkbuf, ogs_nas_re_attempt_indicator_t *re_attempt_indicator)
3814
0
{
3815
0
    int size = re_attempt_indicator->length + sizeof(re_attempt_indicator->length);
3816
0
    ogs_nas_re_attempt_indicator_t target;
3817
3818
0
    memcpy(&target, re_attempt_indicator, sizeof(ogs_nas_re_attempt_indicator_t));
3819
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3820
0
    memcpy(pkbuf->data - size, &target, size);
3821
3822
0
    ogs_trace("  RE_ATTEMPT_INDICATOR - ");
3823
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3824
3825
0
    return size;
3826
0
}
3827
3828
/* 9.9.4.14 Request type
3829
 * M V 1/2 */
3830
int ogs_nas_eps_decode_request_type(ogs_nas_request_type_t *request_type, ogs_pkbuf_t *pkbuf)
3831
0
{
3832
0
    int size = sizeof(ogs_nas_request_type_t);
3833
3834
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3835
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3836
0
       return -1;
3837
0
    }
3838
3839
0
    memcpy(request_type, pkbuf->data - size, size);
3840
3841
0
    ogs_trace("  REQUEST_TYPE - ");
3842
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3843
3844
0
    return size;
3845
0
}
3846
3847
int ogs_nas_eps_encode_request_type(ogs_pkbuf_t *pkbuf, ogs_nas_request_type_t *request_type)
3848
0
{
3849
0
    int size = sizeof(ogs_nas_request_type_t);
3850
0
    ogs_nas_request_type_t target;
3851
3852
0
    memcpy(&target, request_type, size);
3853
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3854
0
    memcpy(pkbuf->data - size, &target, size);
3855
3856
0
    ogs_trace("  REQUEST_TYPE - ");
3857
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3858
3859
0
    return size;
3860
0
}
3861
3862
/* 9.9.4.15 Traffic flow aggregate description
3863
 * M LV 2-256 */
3864
int ogs_nas_eps_decode_traffic_flow_aggregate_description(ogs_nas_traffic_flow_aggregate_description_t *traffic_flow_aggregate_description, ogs_pkbuf_t *pkbuf)
3865
0
{
3866
0
    int size = 0;
3867
0
    ogs_nas_traffic_flow_aggregate_description_t *source = NULL;
3868
3869
0
    if (pkbuf->len < 1) {
3870
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3871
0
       return -1;
3872
0
    }
3873
3874
0
    source = (ogs_nas_traffic_flow_aggregate_description_t *)pkbuf->data;
3875
3876
0
    traffic_flow_aggregate_description->length = source->length;
3877
0
    size = traffic_flow_aggregate_description->length + sizeof(traffic_flow_aggregate_description->length);
3878
3879
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3880
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3881
0
       return -1;
3882
0
    }
3883
3884
0
    if (sizeof(*traffic_flow_aggregate_description) < size) return -1;
3885
0
    memcpy(traffic_flow_aggregate_description, pkbuf->data - size, size);
3886
3887
0
    ogs_trace("  TRAFFIC_FLOW_AGGREGATE_DESCRIPTION - ");
3888
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3889
3890
0
    return size;
3891
0
}
3892
3893
int ogs_nas_eps_encode_traffic_flow_aggregate_description(ogs_pkbuf_t *pkbuf, ogs_nas_traffic_flow_aggregate_description_t *traffic_flow_aggregate_description)
3894
0
{
3895
0
    int size = traffic_flow_aggregate_description->length + sizeof(traffic_flow_aggregate_description->length);
3896
0
    ogs_nas_traffic_flow_aggregate_description_t target;
3897
3898
0
    memcpy(&target, traffic_flow_aggregate_description, sizeof(ogs_nas_traffic_flow_aggregate_description_t));
3899
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3900
0
    memcpy(pkbuf->data - size, &target, size);
3901
3902
0
    ogs_trace("  TRAFFIC_FLOW_AGGREGATE_DESCRIPTION - ");
3903
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3904
3905
0
    return size;
3906
0
}
3907
3908
/* 9.9.4.16 Traffic flow template
3909
 * M LV 2-256 */
3910
int ogs_nas_eps_decode_traffic_flow_template(ogs_nas_traffic_flow_template_t *traffic_flow_template, ogs_pkbuf_t *pkbuf)
3911
0
{
3912
0
    int size = 0;
3913
0
    ogs_nas_traffic_flow_template_t *source = NULL;
3914
3915
0
    if (pkbuf->len < 1) {
3916
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3917
0
       return -1;
3918
0
    }
3919
3920
0
    source = (ogs_nas_traffic_flow_template_t *)pkbuf->data;
3921
3922
0
    traffic_flow_template->length = source->length;
3923
0
    size = traffic_flow_template->length + sizeof(traffic_flow_template->length);
3924
3925
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3926
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3927
0
       return -1;
3928
0
    }
3929
3930
0
    if (sizeof(*traffic_flow_template) < size) return -1;
3931
0
    memcpy(traffic_flow_template, pkbuf->data - size, size);
3932
3933
0
    ogs_trace("  TRAFFIC_FLOW_TEMPLATE - ");
3934
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3935
3936
0
    return size;
3937
0
}
3938
3939
int ogs_nas_eps_encode_traffic_flow_template(ogs_pkbuf_t *pkbuf, ogs_nas_traffic_flow_template_t *traffic_flow_template)
3940
0
{
3941
0
    int size = traffic_flow_template->length + sizeof(traffic_flow_template->length);
3942
0
    ogs_nas_traffic_flow_template_t target;
3943
3944
0
    memcpy(&target, traffic_flow_template, sizeof(ogs_nas_traffic_flow_template_t));
3945
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3946
0
    memcpy(pkbuf->data - size, &target, size);
3947
3948
0
    ogs_trace("  TRAFFIC_FLOW_TEMPLATE - ");
3949
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3950
3951
0
    return size;
3952
0
}
3953
3954
/* 9.9.4.17 Transaction identifier
3955
 * O TLV 3-4 */
3956
int ogs_nas_eps_decode_transaction_identifier(ogs_nas_transaction_identifier_t *transaction_identifier, ogs_pkbuf_t *pkbuf)
3957
0
{
3958
0
    int size = 0;
3959
0
    ogs_nas_transaction_identifier_t *source = NULL;
3960
3961
0
    if (pkbuf->len < 1) {
3962
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
3963
0
       return -1;
3964
0
    }
3965
3966
0
    source = (ogs_nas_transaction_identifier_t *)pkbuf->data;
3967
3968
0
    transaction_identifier->length = source->length;
3969
0
    size = transaction_identifier->length + sizeof(transaction_identifier->length);
3970
3971
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
3972
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
3973
0
       return -1;
3974
0
    }
3975
3976
0
    if (sizeof(*transaction_identifier) < size) return -1;
3977
0
    memcpy(transaction_identifier, pkbuf->data - size, size);
3978
3979
0
    ogs_trace("  TRANSACTION_IDENTIFIER - ");
3980
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3981
3982
0
    return size;
3983
0
}
3984
3985
int ogs_nas_eps_encode_transaction_identifier(ogs_pkbuf_t *pkbuf, ogs_nas_transaction_identifier_t *transaction_identifier)
3986
0
{
3987
0
    int size = transaction_identifier->length + sizeof(transaction_identifier->length);
3988
0
    ogs_nas_transaction_identifier_t target;
3989
3990
0
    memcpy(&target, transaction_identifier, sizeof(ogs_nas_transaction_identifier_t));
3991
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
3992
0
    memcpy(pkbuf->data - size, &target, size);
3993
3994
0
    ogs_trace("  TRANSACTION_IDENTIFIER - ");
3995
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
3996
3997
0
    return size;
3998
0
}
3999
4000
/* 9.9.4.18 WLAN offload acceptability
4001
 * O TV 1 */
4002
int ogs_nas_eps_decode_wlan_offload_acceptability(ogs_nas_wlan_offload_acceptability_t *wlan_offload_acceptability, ogs_pkbuf_t *pkbuf)
4003
0
{
4004
0
    int size = sizeof(ogs_nas_wlan_offload_acceptability_t);
4005
4006
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4007
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4008
0
       return -1;
4009
0
    }
4010
4011
0
    memcpy(wlan_offload_acceptability, pkbuf->data - size, size);
4012
4013
0
    ogs_trace("  WLAN_OFFLOAD_ACCEPTABILITY - ");
4014
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4015
4016
0
    return size;
4017
0
}
4018
4019
int ogs_nas_eps_encode_wlan_offload_acceptability(ogs_pkbuf_t *pkbuf, ogs_nas_wlan_offload_acceptability_t *wlan_offload_acceptability)
4020
0
{
4021
0
    int size = sizeof(ogs_nas_wlan_offload_acceptability_t);
4022
4023
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4024
0
    memcpy(pkbuf->data - size, wlan_offload_acceptability, size);
4025
4026
0
    ogs_trace("  WLAN_OFFLOAD_ACCEPTABILITY - ");
4027
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4028
4029
0
    return size;
4030
0
}
4031
4032
/* 9.9.4.19 NBIFOM container
4033
 * O TLV 3-257 */
4034
int ogs_nas_eps_decode_nbifom_container(ogs_nas_nbifom_container_t *nbifom_container, ogs_pkbuf_t *pkbuf)
4035
0
{
4036
0
    int size = 0;
4037
0
    ogs_nas_nbifom_container_t *source = NULL;
4038
4039
0
    if (pkbuf->len < 1) {
4040
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
4041
0
       return -1;
4042
0
    }
4043
4044
0
    source = (ogs_nas_nbifom_container_t *)pkbuf->data;
4045
4046
0
    nbifom_container->length = source->length;
4047
0
    size = nbifom_container->length + sizeof(nbifom_container->length);
4048
4049
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4050
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4051
0
       return -1;
4052
0
    }
4053
4054
0
    if (sizeof(*nbifom_container) < size) return -1;
4055
0
    memcpy(nbifom_container, pkbuf->data - size, size);
4056
4057
0
    ogs_trace("  NBIFOM_CONTAINER - ");
4058
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4059
4060
0
    return size;
4061
0
}
4062
4063
int ogs_nas_eps_encode_nbifom_container(ogs_pkbuf_t *pkbuf, ogs_nas_nbifom_container_t *nbifom_container)
4064
0
{
4065
0
    int size = nbifom_container->length + sizeof(nbifom_container->length);
4066
0
    ogs_nas_nbifom_container_t target;
4067
4068
0
    memcpy(&target, nbifom_container, sizeof(ogs_nas_nbifom_container_t));
4069
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4070
0
    memcpy(pkbuf->data - size, &target, size);
4071
4072
0
    ogs_trace("  NBIFOM_CONTAINER - ");
4073
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4074
4075
0
    return size;
4076
0
}
4077
4078
/* 9.9.4.2 APN aggregate maximum bit rate
4079
 * O TLV 4-8 */
4080
int ogs_nas_eps_decode_apn_aggregate_maximum_bit_rate(ogs_nas_apn_aggregate_maximum_bit_rate_t *apn_aggregate_maximum_bit_rate, ogs_pkbuf_t *pkbuf)
4081
0
{
4082
0
    int size = 0;
4083
0
    ogs_nas_apn_aggregate_maximum_bit_rate_t *source = NULL;
4084
4085
0
    if (pkbuf->len < 1) {
4086
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
4087
0
       return -1;
4088
0
    }
4089
4090
0
    source = (ogs_nas_apn_aggregate_maximum_bit_rate_t *)pkbuf->data;
4091
4092
0
    apn_aggregate_maximum_bit_rate->length = source->length;
4093
0
    size = apn_aggregate_maximum_bit_rate->length + sizeof(apn_aggregate_maximum_bit_rate->length);
4094
4095
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4096
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4097
0
       return -1;
4098
0
    }
4099
4100
0
    if (sizeof(*apn_aggregate_maximum_bit_rate) < size) return -1;
4101
0
    memcpy(apn_aggregate_maximum_bit_rate, pkbuf->data - size, size);
4102
4103
0
    ogs_trace("  APN_AGGREGATE_MAXIMUM_BIT_RATE - ");
4104
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4105
4106
0
    return size;
4107
0
}
4108
4109
int ogs_nas_eps_encode_apn_aggregate_maximum_bit_rate(ogs_pkbuf_t *pkbuf, ogs_nas_apn_aggregate_maximum_bit_rate_t *apn_aggregate_maximum_bit_rate)
4110
0
{
4111
0
    int size = apn_aggregate_maximum_bit_rate->length + sizeof(apn_aggregate_maximum_bit_rate->length);
4112
0
    ogs_nas_apn_aggregate_maximum_bit_rate_t target;
4113
4114
0
    memcpy(&target, apn_aggregate_maximum_bit_rate, sizeof(ogs_nas_apn_aggregate_maximum_bit_rate_t));
4115
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4116
0
    memcpy(pkbuf->data - size, &target, size);
4117
4118
0
    ogs_trace("  APN_AGGREGATE_MAXIMUM_BIT_RATE - ");
4119
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4120
4121
0
    return size;
4122
0
}
4123
4124
/* 9.9.4.22 Header compression configuration
4125
 * O TLV 5-257 */
4126
int ogs_nas_eps_decode_header_compression_configuration(ogs_nas_header_compression_configuration_t *header_compression_configuration, ogs_pkbuf_t *pkbuf)
4127
0
{
4128
0
    int size = 0;
4129
0
    ogs_nas_header_compression_configuration_t *source = NULL;
4130
4131
0
    if (pkbuf->len < 1) {
4132
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
4133
0
       return -1;
4134
0
    }
4135
4136
0
    source = (ogs_nas_header_compression_configuration_t *)pkbuf->data;
4137
4138
0
    header_compression_configuration->length = source->length;
4139
0
    size = header_compression_configuration->length + sizeof(header_compression_configuration->length);
4140
4141
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4142
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4143
0
       return -1;
4144
0
    }
4145
4146
0
    if (sizeof(*header_compression_configuration) < size) return -1;
4147
0
    memcpy(header_compression_configuration, pkbuf->data - size, size);
4148
4149
0
    header_compression_configuration->max_cid = be16toh(header_compression_configuration->max_cid);
4150
4151
0
    ogs_trace("  HEADER_COMPRESSION_CONFIGURATION - ");
4152
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4153
4154
0
    return size;
4155
0
}
4156
4157
int ogs_nas_eps_encode_header_compression_configuration(ogs_pkbuf_t *pkbuf, ogs_nas_header_compression_configuration_t *header_compression_configuration)
4158
0
{
4159
0
    int size = header_compression_configuration->length + sizeof(header_compression_configuration->length);
4160
0
    ogs_nas_header_compression_configuration_t target;
4161
4162
0
    memcpy(&target, header_compression_configuration, sizeof(ogs_nas_header_compression_configuration_t));
4163
0
    target.max_cid = htobe16(header_compression_configuration->max_cid);
4164
4165
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4166
0
    memcpy(pkbuf->data - size, &target, size);
4167
4168
0
    ogs_trace("  HEADER_COMPRESSION_CONFIGURATION - ");
4169
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4170
4171
0
    return size;
4172
0
}
4173
4174
/* 9.9.4.23 Control plane only indication
4175
 * O TV 1 */
4176
int ogs_nas_eps_decode_control_plane_only_indication(ogs_nas_control_plane_only_indication_t *control_plane_only_indication, ogs_pkbuf_t *pkbuf)
4177
0
{
4178
0
    int size = sizeof(ogs_nas_control_plane_only_indication_t);
4179
4180
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4181
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4182
0
       return -1;
4183
0
    }
4184
4185
0
    memcpy(control_plane_only_indication, pkbuf->data - size, size);
4186
4187
0
    ogs_trace("  CONTROL_PLANE_ONLY_INDICATION - ");
4188
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4189
4190
0
    return size;
4191
0
}
4192
4193
int ogs_nas_eps_encode_control_plane_only_indication(ogs_pkbuf_t *pkbuf, ogs_nas_control_plane_only_indication_t *control_plane_only_indication)
4194
0
{
4195
0
    int size = sizeof(ogs_nas_control_plane_only_indication_t);
4196
4197
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4198
0
    memcpy(pkbuf->data - size, control_plane_only_indication, size);
4199
4200
0
    ogs_trace("  CONTROL_PLANE_ONLY_INDICATION - ");
4201
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4202
4203
0
    return size;
4204
0
}
4205
4206
/* 9.9.4.26 Extended protocol configuration options
4207
 * O TLV-E 4-65538 */
4208
int ogs_nas_eps_decode_extended_protocol_configuration_options(ogs_nas_extended_protocol_configuration_options_t *extended_protocol_configuration_options, ogs_pkbuf_t *pkbuf)
4209
0
{
4210
0
    int size = 0;
4211
0
    ogs_nas_extended_protocol_configuration_options_t *source = NULL;
4212
4213
0
    if (pkbuf->len < 2) {
4214
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
4215
0
       return -1;
4216
0
    }
4217
4218
0
    source = (ogs_nas_extended_protocol_configuration_options_t *)pkbuf->data;
4219
4220
0
    extended_protocol_configuration_options->length = be16toh(source->length);
4221
0
    size = extended_protocol_configuration_options->length + sizeof(extended_protocol_configuration_options->length);
4222
4223
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4224
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4225
0
       return -1;
4226
0
    }
4227
4228
0
    extended_protocol_configuration_options->buffer = pkbuf->data - size + sizeof(extended_protocol_configuration_options->length);
4229
4230
0
    ogs_trace("  EXTENDED_PROTOCOL_CONFIGURATION_OPTIONS - ");
4231
0
    ogs_log_hexdump(OGS_LOG_TRACE, (void*)extended_protocol_configuration_options->buffer, extended_protocol_configuration_options->length);
4232
4233
0
    return size;
4234
0
}
4235
4236
int ogs_nas_eps_encode_extended_protocol_configuration_options(ogs_pkbuf_t *pkbuf, ogs_nas_extended_protocol_configuration_options_t *extended_protocol_configuration_options)
4237
0
{
4238
0
    int size = 0;
4239
0
    int target;
4240
4241
0
    ogs_assert(extended_protocol_configuration_options);
4242
0
    ogs_assert(extended_protocol_configuration_options->buffer);
4243
4244
0
    size = sizeof(extended_protocol_configuration_options->length);
4245
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4246
0
    target = htobe16(extended_protocol_configuration_options->length);
4247
0
    memcpy(pkbuf->data - size, &target, size);
4248
4249
0
    size = extended_protocol_configuration_options->length;
4250
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4251
0
    memcpy(pkbuf->data - size, extended_protocol_configuration_options->buffer, size);
4252
4253
0
    ogs_trace("  EXTENDED_PROTOCOL_CONFIGURATION_OPTIONS - ");
4254
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4255
4256
0
    return extended_protocol_configuration_options->length + sizeof(extended_protocol_configuration_options->length);
4257
0
}
4258
4259
/* 9.9.4.27 Header compression configuration status
4260
 * O TLV 4 */
4261
int ogs_nas_eps_decode_header_compression_configuration_status(ogs_nas_header_compression_configuration_status_t *header_compression_configuration_status, ogs_pkbuf_t *pkbuf)
4262
499
{
4263
499
    int size = 0;
4264
499
    ogs_nas_header_compression_configuration_status_t *source = NULL;
4265
4266
499
    if (pkbuf->len < 1) {
4267
6
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
4268
6
       return -1;
4269
6
    }
4270
4271
493
    source = (ogs_nas_header_compression_configuration_status_t *)pkbuf->data;
4272
4273
493
    header_compression_configuration_status->length = source->length;
4274
493
    size = header_compression_configuration_status->length + sizeof(header_compression_configuration_status->length);
4275
4276
493
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4277
7
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4278
7
       return -1;
4279
7
    }
4280
4281
486
    if (sizeof(*header_compression_configuration_status) < size) return -1;
4282
485
    memcpy(header_compression_configuration_status, pkbuf->data - size, size);
4283
4284
485
    ogs_trace("  HEADER_COMPRESSION_CONFIGURATION_STATUS - ");
4285
485
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4286
4287
485
    return size;
4288
486
}
4289
4290
int ogs_nas_eps_encode_header_compression_configuration_status(ogs_pkbuf_t *pkbuf, ogs_nas_header_compression_configuration_status_t *header_compression_configuration_status)
4291
0
{
4292
0
    int size = header_compression_configuration_status->length + sizeof(header_compression_configuration_status->length);
4293
0
    ogs_nas_header_compression_configuration_status_t target;
4294
4295
0
    memcpy(&target, header_compression_configuration_status, sizeof(ogs_nas_header_compression_configuration_status_t));
4296
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4297
0
    memcpy(pkbuf->data - size, &target, size);
4298
4299
0
    ogs_trace("  HEADER_COMPRESSION_CONFIGURATION_STATUS - ");
4300
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4301
4302
0
    return size;
4303
0
}
4304
4305
/* 9.9.4.28 Serving PLMN rate control
4306
 * O TLV 4 */
4307
int ogs_nas_eps_decode_serving_plmn_rate_control(ogs_nas_serving_plmn_rate_control_t *serving_plmn_rate_control, ogs_pkbuf_t *pkbuf)
4308
0
{
4309
0
    int size = 0;
4310
0
    ogs_nas_serving_plmn_rate_control_t *source = NULL;
4311
4312
0
    if (pkbuf->len < 1) {
4313
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
4314
0
       return -1;
4315
0
    }
4316
4317
0
    source = (ogs_nas_serving_plmn_rate_control_t *)pkbuf->data;
4318
4319
0
    serving_plmn_rate_control->length = source->length;
4320
0
    size = serving_plmn_rate_control->length + sizeof(serving_plmn_rate_control->length);
4321
4322
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4323
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4324
0
       return -1;
4325
0
    }
4326
4327
0
    if (sizeof(*serving_plmn_rate_control) < size) return -1;
4328
0
    memcpy(serving_plmn_rate_control, pkbuf->data - size, size);
4329
4330
0
    ogs_trace("  SERVING_PLMN_RATE_CONTROL - ");
4331
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4332
4333
0
    return size;
4334
0
}
4335
4336
int ogs_nas_eps_encode_serving_plmn_rate_control(ogs_pkbuf_t *pkbuf, ogs_nas_serving_plmn_rate_control_t *serving_plmn_rate_control)
4337
0
{
4338
0
    int size = serving_plmn_rate_control->length + sizeof(serving_plmn_rate_control->length);
4339
0
    ogs_nas_serving_plmn_rate_control_t target;
4340
4341
0
    memcpy(&target, serving_plmn_rate_control, sizeof(ogs_nas_serving_plmn_rate_control_t));
4342
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4343
0
    memcpy(pkbuf->data - size, &target, size);
4344
4345
0
    ogs_trace("  SERVING_PLMN_RATE_CONTROL - ");
4346
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4347
4348
0
    return size;
4349
0
}
4350
4351
/* 9.9.4.29 Extended APN aggregate maximum bit rate
4352
 * O TLV 8 */
4353
int ogs_nas_eps_decode_extended_apn_aggregate_maximum_bit_rate(ogs_nas_extended_apn_aggregate_maximum_bit_rate_t *extended_apn_aggregate_maximum_bit_rate, ogs_pkbuf_t *pkbuf)
4354
0
{
4355
0
    int size = 0;
4356
0
    ogs_nas_extended_apn_aggregate_maximum_bit_rate_t *source = NULL;
4357
4358
0
    if (pkbuf->len < 1) {
4359
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
4360
0
       return -1;
4361
0
    }
4362
4363
0
    source = (ogs_nas_extended_apn_aggregate_maximum_bit_rate_t *)pkbuf->data;
4364
4365
0
    extended_apn_aggregate_maximum_bit_rate->length = source->length;
4366
0
    size = extended_apn_aggregate_maximum_bit_rate->length + sizeof(extended_apn_aggregate_maximum_bit_rate->length);
4367
4368
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4369
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4370
0
       return -1;
4371
0
    }
4372
4373
0
    if (sizeof(*extended_apn_aggregate_maximum_bit_rate) < size) return -1;
4374
0
    memcpy(extended_apn_aggregate_maximum_bit_rate, pkbuf->data - size, size);
4375
4376
0
    ogs_trace("  EXTENDED_APN_AGGREGATE_MAXIMUM_BIT_RATE - ");
4377
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4378
4379
0
    return size;
4380
0
}
4381
4382
int ogs_nas_eps_encode_extended_apn_aggregate_maximum_bit_rate(ogs_pkbuf_t *pkbuf, ogs_nas_extended_apn_aggregate_maximum_bit_rate_t *extended_apn_aggregate_maximum_bit_rate)
4383
0
{
4384
0
    int size = extended_apn_aggregate_maximum_bit_rate->length + sizeof(extended_apn_aggregate_maximum_bit_rate->length);
4385
0
    ogs_nas_extended_apn_aggregate_maximum_bit_rate_t target;
4386
4387
0
    memcpy(&target, extended_apn_aggregate_maximum_bit_rate, sizeof(ogs_nas_extended_apn_aggregate_maximum_bit_rate_t));
4388
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4389
0
    memcpy(pkbuf->data - size, &target, size);
4390
4391
0
    ogs_trace("  EXTENDED_APN_AGGREGATE_MAXIMUM_BIT_RATE - ");
4392
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4393
4394
0
    return size;
4395
0
}
4396
4397
/* 9.9.4.2A Connectivity type
4398
 * O TV 1 */
4399
int ogs_nas_eps_decode_connectivity_type(ogs_nas_connectivity_type_t *connectivity_type, ogs_pkbuf_t *pkbuf)
4400
0
{
4401
0
    int size = sizeof(ogs_nas_connectivity_type_t);
4402
4403
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4404
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4405
0
       return -1;
4406
0
    }
4407
4408
0
    memcpy(connectivity_type, pkbuf->data - size, size);
4409
4410
0
    ogs_trace("  CONNECTIVITY_TYPE - ");
4411
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4412
4413
0
    return size;
4414
0
}
4415
4416
int ogs_nas_eps_encode_connectivity_type(ogs_pkbuf_t *pkbuf, ogs_nas_connectivity_type_t *connectivity_type)
4417
0
{
4418
0
    int size = sizeof(ogs_nas_connectivity_type_t);
4419
4420
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4421
0
    memcpy(pkbuf->data - size, connectivity_type, size);
4422
4423
0
    ogs_trace("  CONNECTIVITY_TYPE - ");
4424
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4425
4426
0
    return size;
4427
0
}
4428
4429
/* 9.9.4.3 EPS quality of service
4430
 * M LV 2-14 */
4431
int ogs_nas_eps_decode_eps_quality_of_service(ogs_nas_eps_quality_of_service_t *eps_quality_of_service, ogs_pkbuf_t *pkbuf)
4432
0
{
4433
0
    int size = 0;
4434
0
    ogs_nas_eps_quality_of_service_t *source = NULL;
4435
4436
0
    if (pkbuf->len < 1) {
4437
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
4438
0
       return -1;
4439
0
    }
4440
4441
0
    source = (ogs_nas_eps_quality_of_service_t *)pkbuf->data;
4442
4443
0
    eps_quality_of_service->length = source->length;
4444
0
    size = eps_quality_of_service->length + sizeof(eps_quality_of_service->length);
4445
4446
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4447
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4448
0
       return -1;
4449
0
    }
4450
4451
0
    if (sizeof(*eps_quality_of_service) < size) return -1;
4452
0
    memcpy(eps_quality_of_service, pkbuf->data - size, size);
4453
4454
0
    ogs_trace("  EPS_QUALITY_OF_SERVICE - ");
4455
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4456
4457
0
    return size;
4458
0
}
4459
4460
int ogs_nas_eps_encode_eps_quality_of_service(ogs_pkbuf_t *pkbuf, ogs_nas_eps_quality_of_service_t *eps_quality_of_service)
4461
0
{
4462
0
    int size = eps_quality_of_service->length + sizeof(eps_quality_of_service->length);
4463
0
    ogs_nas_eps_quality_of_service_t target;
4464
4465
0
    memcpy(&target, eps_quality_of_service, sizeof(ogs_nas_eps_quality_of_service_t));
4466
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4467
0
    memcpy(pkbuf->data - size, &target, size);
4468
4469
0
    ogs_trace("  EPS_QUALITY_OF_SERVICE - ");
4470
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4471
4472
0
    return size;
4473
0
}
4474
4475
/* 9.9.4.30 Extended quality of service
4476
 * O TLV 12 */
4477
int ogs_nas_eps_decode_extended_quality_of_service(ogs_nas_extended_quality_of_service_t *extended_quality_of_service, ogs_pkbuf_t *pkbuf)
4478
0
{
4479
0
    int size = 0;
4480
0
    ogs_nas_extended_quality_of_service_t *source = NULL;
4481
4482
0
    if (pkbuf->len < 1) {
4483
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
4484
0
       return -1;
4485
0
    }
4486
4487
0
    source = (ogs_nas_extended_quality_of_service_t *)pkbuf->data;
4488
4489
0
    extended_quality_of_service->length = source->length;
4490
0
    size = extended_quality_of_service->length + sizeof(extended_quality_of_service->length);
4491
4492
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4493
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4494
0
       return -1;
4495
0
    }
4496
4497
0
    if (sizeof(*extended_quality_of_service) < size) return -1;
4498
0
    memcpy(extended_quality_of_service, pkbuf->data - size, size);
4499
4500
0
    ogs_trace("  EXTENDED_QUALITY_OF_SERVICE - ");
4501
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4502
4503
0
    return size;
4504
0
}
4505
4506
int ogs_nas_eps_encode_extended_quality_of_service(ogs_pkbuf_t *pkbuf, ogs_nas_extended_quality_of_service_t *extended_quality_of_service)
4507
0
{
4508
0
    int size = extended_quality_of_service->length + sizeof(extended_quality_of_service->length);
4509
0
    ogs_nas_extended_quality_of_service_t target;
4510
4511
0
    memcpy(&target, extended_quality_of_service, sizeof(ogs_nas_extended_quality_of_service_t));
4512
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4513
0
    memcpy(pkbuf->data - size, &target, size);
4514
4515
0
    ogs_trace("  EXTENDED_QUALITY_OF_SERVICE - ");
4516
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4517
4518
0
    return size;
4519
0
}
4520
4521
/* 9.9.4.4 ESM cause
4522
 * O TV 2 */
4523
int ogs_nas_eps_decode_esm_cause(ogs_nas_esm_cause_t *esm_cause, ogs_pkbuf_t *pkbuf)
4524
0
{
4525
0
    int size = sizeof(ogs_nas_esm_cause_t);
4526
4527
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4528
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4529
0
       return -1;
4530
0
    }
4531
4532
0
    memcpy(esm_cause, pkbuf->data - size, size);
4533
4534
0
    ogs_trace("  ESM_CAUSE - ");
4535
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4536
4537
0
    return size;
4538
0
}
4539
4540
int ogs_nas_eps_encode_esm_cause(ogs_pkbuf_t *pkbuf, ogs_nas_esm_cause_t *esm_cause)
4541
0
{
4542
0
    int size = sizeof(ogs_nas_esm_cause_t);
4543
0
    ogs_nas_esm_cause_t target;
4544
4545
0
    memcpy(&target, esm_cause, size);
4546
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4547
0
    memcpy(pkbuf->data - size, &target, size);
4548
4549
0
    ogs_trace("  ESM_CAUSE - ");
4550
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4551
4552
0
    return size;
4553
0
}
4554
4555
/* 9.9.4.5 ESM information transfer flag
4556
 * O TV 1 */
4557
int ogs_nas_eps_decode_esm_information_transfer_flag(ogs_nas_esm_information_transfer_flag_t *esm_information_transfer_flag, ogs_pkbuf_t *pkbuf)
4558
0
{
4559
0
    int size = sizeof(ogs_nas_esm_information_transfer_flag_t);
4560
4561
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4562
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4563
0
       return -1;
4564
0
    }
4565
4566
0
    memcpy(esm_information_transfer_flag, pkbuf->data - size, size);
4567
4568
0
    ogs_trace("  ESM_INFORMATION_TRANSFER_FLAG - ");
4569
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4570
4571
0
    return size;
4572
0
}
4573
4574
int ogs_nas_eps_encode_esm_information_transfer_flag(ogs_pkbuf_t *pkbuf, ogs_nas_esm_information_transfer_flag_t *esm_information_transfer_flag)
4575
0
{
4576
0
    int size = sizeof(ogs_nas_esm_information_transfer_flag_t);
4577
4578
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4579
0
    memcpy(pkbuf->data - size, esm_information_transfer_flag, size);
4580
4581
0
    ogs_trace("  ESM_INFORMATION_TRANSFER_FLAG - ");
4582
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4583
4584
0
    return size;
4585
0
}
4586
4587
/* 9.9.4.6 Linked EPS bearer identity
4588
 * M V 1/2 */
4589
int ogs_nas_eps_decode_linked_eps_bearer_identity(ogs_nas_linked_eps_bearer_identity_t *linked_eps_bearer_identity, ogs_pkbuf_t *pkbuf)
4590
0
{
4591
0
    int size = sizeof(ogs_nas_linked_eps_bearer_identity_t);
4592
4593
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4594
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4595
0
       return -1;
4596
0
    }
4597
4598
0
    memcpy(linked_eps_bearer_identity, pkbuf->data - size, size);
4599
4600
0
    ogs_trace("  LINKED_EPS_BEARER_IDENTITY - ");
4601
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4602
4603
0
    return size;
4604
0
}
4605
4606
int ogs_nas_eps_encode_linked_eps_bearer_identity(ogs_pkbuf_t *pkbuf, ogs_nas_linked_eps_bearer_identity_t *linked_eps_bearer_identity)
4607
0
{
4608
0
    int size = sizeof(ogs_nas_linked_eps_bearer_identity_t);
4609
0
    ogs_nas_linked_eps_bearer_identity_t target;
4610
4611
0
    memcpy(&target, linked_eps_bearer_identity, size);
4612
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4613
0
    memcpy(pkbuf->data - size, &target, size);
4614
4615
0
    ogs_trace("  LINKED_EPS_BEARER_IDENTITY - ");
4616
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4617
4618
0
    return size;
4619
0
}
4620
4621
/* 9.9.4.7 LLC service access point identifier
4622
 * O TV 2 */
4623
int ogs_nas_eps_decode_llc_service_access_point_identifier(ogs_nas_llc_service_access_point_identifier_t *llc_service_access_point_identifier, ogs_pkbuf_t *pkbuf)
4624
0
{
4625
0
    int size = sizeof(ogs_nas_llc_service_access_point_identifier_t);
4626
4627
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4628
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4629
0
       return -1;
4630
0
    }
4631
4632
0
    memcpy(llc_service_access_point_identifier, pkbuf->data - size, size);
4633
4634
0
    ogs_trace("  LLC_SERVICE_ACCESS_POINT_IDENTIFIER - ");
4635
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4636
4637
0
    return size;
4638
0
}
4639
4640
int ogs_nas_eps_encode_llc_service_access_point_identifier(ogs_pkbuf_t *pkbuf, ogs_nas_llc_service_access_point_identifier_t *llc_service_access_point_identifier)
4641
0
{
4642
0
    int size = sizeof(ogs_nas_llc_service_access_point_identifier_t);
4643
0
    ogs_nas_llc_service_access_point_identifier_t target;
4644
4645
0
    memcpy(&target, llc_service_access_point_identifier, size);
4646
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4647
0
    memcpy(pkbuf->data - size, &target, size);
4648
4649
0
    ogs_trace("  LLC_SERVICE_ACCESS_POINT_IDENTIFIER - ");
4650
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4651
4652
0
    return size;
4653
0
}
4654
4655
/* 9.9.4.8 Packet flow Identifier
4656
 * O TLV 3 */
4657
int ogs_nas_eps_decode_packet_flow_identifier(ogs_nas_packet_flow_identifier_t *packet_flow_identifier, ogs_pkbuf_t *pkbuf)
4658
0
{
4659
0
    int size = 0;
4660
0
    ogs_nas_packet_flow_identifier_t *source = NULL;
4661
4662
0
    if (pkbuf->len < 1) {
4663
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
4664
0
       return -1;
4665
0
    }
4666
4667
0
    source = (ogs_nas_packet_flow_identifier_t *)pkbuf->data;
4668
4669
0
    packet_flow_identifier->length = source->length;
4670
0
    size = packet_flow_identifier->length + sizeof(packet_flow_identifier->length);
4671
4672
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4673
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4674
0
       return -1;
4675
0
    }
4676
4677
0
    if (sizeof(*packet_flow_identifier) < size) return -1;
4678
0
    memcpy(packet_flow_identifier, pkbuf->data - size, size);
4679
4680
0
    ogs_trace("  PACKET_FLOW_IDENTIFIER - ");
4681
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4682
4683
0
    return size;
4684
0
}
4685
4686
int ogs_nas_eps_encode_packet_flow_identifier(ogs_pkbuf_t *pkbuf, ogs_nas_packet_flow_identifier_t *packet_flow_identifier)
4687
0
{
4688
0
    int size = packet_flow_identifier->length + sizeof(packet_flow_identifier->length);
4689
0
    ogs_nas_packet_flow_identifier_t target;
4690
4691
0
    memcpy(&target, packet_flow_identifier, sizeof(ogs_nas_packet_flow_identifier_t));
4692
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4693
0
    memcpy(pkbuf->data - size, &target, size);
4694
4695
0
    ogs_trace("  PACKET_FLOW_IDENTIFIER - ");
4696
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4697
4698
0
    return size;
4699
0
}
4700
4701
/* 9.9.4.9 PDN address
4702
 * M LV 6-14 */
4703
int ogs_nas_eps_decode_pdn_address(ogs_nas_pdn_address_t *pdn_address, ogs_pkbuf_t *pkbuf)
4704
0
{
4705
0
    int size = 0;
4706
0
    ogs_nas_pdn_address_t *source = NULL;
4707
4708
0
    if (pkbuf->len < 1) {
4709
0
       ogs_error("Not enough pkbuf [len:%d]", pkbuf->len);
4710
0
       return -1;
4711
0
    }
4712
4713
0
    source = (ogs_nas_pdn_address_t *)pkbuf->data;
4714
4715
0
    pdn_address->length = source->length;
4716
0
    size = pdn_address->length + sizeof(pdn_address->length);
4717
4718
0
    if (ogs_pkbuf_pull(pkbuf, size) == NULL) {
4719
0
       ogs_error("ogs_pkbuf_pull() failed [size:%d]", (int)size);
4720
0
       return -1;
4721
0
    }
4722
4723
0
    if (sizeof(*pdn_address) < size) return -1;
4724
0
    memcpy(pdn_address, pkbuf->data - size, size);
4725
4726
0
    ogs_trace("  PDN_ADDRESS - ");
4727
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4728
4729
0
    return size;
4730
0
}
4731
4732
int ogs_nas_eps_encode_pdn_address(ogs_pkbuf_t *pkbuf, ogs_nas_pdn_address_t *pdn_address)
4733
0
{
4734
0
    int size = pdn_address->length + sizeof(pdn_address->length);
4735
0
    ogs_nas_pdn_address_t target;
4736
4737
0
    memcpy(&target, pdn_address, sizeof(ogs_nas_pdn_address_t));
4738
0
    ogs_assert(ogs_pkbuf_pull(pkbuf, size));
4739
0
    memcpy(pkbuf->data - size, &target, size);
4740
4741
0
    ogs_trace("  PDN_ADDRESS - ");
4742
0
    ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);
4743
4744
0
    return size;
4745
0
}
4746