1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
|
/* $OpenBSD: print-gtp.c,v 1.7 2015/01/16 06:40:21 deraadt Exp $ */
/*
* Copyright (c) 2009, 2010 Joel Sing <jsing@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Decoder for the GPRS Trunking Protocol (GTP).
*
* This work has been kindly sponsored by SystemNet (www.systemnet.no).
*
* GTPv0 standards are available from the ETSI website:
*
* http://pda.etsi.org/pda/
*
* GTPv1 standards are available from the 3GPP website:
*
* http://www.3gpp.org/specifications
*
* The following standards have been referenced to create this decoder:
*
* ETSI GSM 09.60 - GPRS Tunnelling Protocol (GTPv0)
* ETSI GSM 12.15 - GPRS Charging (GTPv0')
*
* 3GPP TS 23.003 - Numbering, addressing and identification
* 3GPP TS 24.008 - Core network protocols
* 3GPP TS 29.002 - Mobile Application Part (MAP) specification
* 3GPP TS 29.060 - GPRS Tunnelling Protocol (GTPv1-C/GTPv1-U)
* 3GPP TS 32.295 - Charging Data Record (CDR) transfer (GTPv1')
*/
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "addrtoname.h"
#include "interface.h"
#include "gtp.h"
void gtp_print(register const u_char *, u_int, u_short, u_short);
void gtp_decode_ie(register const u_char *, u_short, int);
void gtp_print_tbcd(register const u_char *, u_int);
void gtp_print_user_address(register const u_char *, u_int);
void gtp_print_apn(register const u_char *, u_int);
void gtp_print_str(const char **, u_int);
void gtp_v0_print(const u_char *, u_int, u_short, u_short);
void gtp_v0_print_prime(register const u_char *);
int gtp_v0_print_tv(register const u_char *, u_int);
int gtp_v0_print_tlv(register const u_char *, u_int);
void gtp_v1_print(const u_char *, u_int, u_short, u_short);
void gtp_v1_print_ctrl(register const u_char *, u_int, struct gtp_v1_hdr *);
void gtp_v1_print_user(register const u_char *, u_int, struct gtp_v1_hdr *);
void gtp_v1_print_prime(register const u_char *, struct gtp_v1_prime_hdr *);
int gtp_v1_print_tv(register const u_char *, u_int);
int gtp_v1_print_tlv(register const u_char *, u_int);
/* GTPv0 message types. */
static struct tok gtp_v0_msgtype[] = {
{ 1, "Echo Request" },
{ 2, "Echo Response" },
{ 3, "Version Not Supported" },
{ 4, "Node Alive Request" },
{ 5, "Node Alive Response" },
{ 6, "Redirection Request" },
{ 7, "Redirection Response" },
{ 16, "Create PDP Context Request" },
{ 17, "Create PDP Context Response" },
{ 18, "Update PDP Context Request" },
{ 19, "Update PDP Context Response" },
{ 20, "Delete PDP Context Request" },
{ 21, "Delete PDP Context Response" },
{ 22, "Create AA PDP Context Request" },
{ 23, "Create AA PDP Context Response" },
{ 24, "Delete AA PDP Context Request" },
{ 25, "Delete AA PDP Context Response" },
{ 26, "Error Indication" },
{ 27, "PDU Notification Request" },
{ 28, "PDU Notification Response" },
{ 29, "PDU Notification Reject Request" },
{ 30, "PDU Notification Reject Response" },
{ 32, "Send Routeing Information Request" },
{ 33, "Send Routeing Information Response" },
{ 34, "Failure Report Request" },
{ 35, "Failure Report Response" },
{ 36, "MS GPRS Present Request" },
{ 37, "MS GPRS Present Response" },
{ 48, "Identification Request" },
{ 49, "Identification Response" },
{ 50, "SGSN Context Request" },
{ 51, "SGSN Context Response" },
{ 52, "SGSN Context Acknowledge" },
{ 240, "Data Record Transfer Request" },
{ 241, "Data Record Transfer Response" },
{ 255, "T-PDU" },
{ 0, NULL }
};
/* GTPv0 causes. */
static struct tok gtp_v0_cause[] = {
{ 0, "Request IMSI" },
{ 1, "Request IMEI" },
{ 2, "Request IMSI and IMEI" },
{ 3, "No identity needed" },
{ 4, "MS refuses" },
{ 5, "MS is not GPRS responding" },
{ 128, "Request accepted" },
{ 192, "Non-existent" },
{ 193, "Invalid message format" },
{ 194, "IMSI not known" },
{ 195, "MS is GPRS detached" },
{ 196, "MS is not GPRS responding" },
{ 197, "MS refuses" },
{ 198, "Version not supported" },
{ 199, "No resources available" },
{ 200, "Service not supported" },
{ 201, "Mandatory IE incorrect" },
{ 202, "Mandatory IE missing" },
{ 203, "Optional IE incorrect" },
{ 204, "System failure" },
{ 205, "Roaming restriction" },
{ 206, "P-TMSI signature mismatch" },
{ 207, "GPRS connection suspended" },
{ 208, "Authentication failure" },
{ 209, "User authentication failed" },
{ 0, NULL }
};
/* GTPv1 message types. */
static struct tok gtp_v1_msgtype[] = {
{ 1, "Echo Request" },
{ 2, "Echo Response" },
{ 3, "Version Not Supported" },
{ 4, "Node Alive Request" },
{ 5, "Node Alive Response" },
{ 6, "Redirection Request" },
{ 7, "Redirection Response" },
{ 16, "Create PDP Context Request" },
{ 17, "Create PDP Context Response" },
{ 18, "Update PDP Context Request" },
{ 19, "Update PDP Context Response" },
{ 20, "Delete PDP Context Request" },
{ 21, "Delete PDP Context Response" },
{ 22, "Initiate PDP Context Activiation Request" },
{ 23, "Initiate PDP Context Activiation Response" },
{ 26, "Error Indication" },
{ 27, "PDU Notification Request" },
{ 28, "PDU Notification Response" },
{ 29, "PDU Notification Reject Request" },
{ 30, "PDU Notification Reject Response" },
{ 31, "Supported Extension Headers Notification" },
{ 32, "Send Routeing Information for GPRS Request" },
{ 33, "Send Routeing Information for GPRS Response" },
{ 34, "Failure Report Request" },
{ 35, "Failure Report Response" },
{ 36, "Note MS GPRS Present Request" },
{ 37, "Note MS GPRS Present Response" },
{ 48, "Identification Request" },
{ 49, "Identification Response" },
{ 50, "SGSN Context Request" },
{ 51, "SGSN Context Response" },
{ 52, "SGSN Context Acknowledge" },
{ 53, "Forward Relocation Request" },
{ 54, "Forward Relocation Response" },
{ 55, "Forward Relocation Complete" },
{ 56, "Relocation Cancel Request" },
{ 57, "Relocation Cancel Response" },
{ 58, "Forward SRNS Context" },
{ 59, "Forward Relocation Complete Acknowledge" },
{ 60, "Forward SRNS Context Acknowledge" },
{ 70, "RAN Information Relay" },
{ 96, "MBMS Notification Request" },
{ 97, "MBMS Notification Response" },
{ 98, "MBMS Notification Reject Request" },
{ 99, "MBMS Notification Reject Response" },
{ 100, "Create MBMS Context Request" },
{ 101, "Create MBMS Context Response" },
{ 102, "Update MBMS Context Request" },
{ 103, "Update MBMS Context Response" },
{ 104, "Delete MBMS Context Request" },
{ 105, "Delete MBMS Context Response" },
{ 112, "MBMS Registration Request" },
{ 113, "MBMS Registration Response" },
{ 114, "MBMS De-Registration Request" },
{ 115, "MBMS De-Registration Response" },
{ 116, "MBMS Session Start Request" },
{ 117, "MBMS Session Start Response" },
{ 118, "MBMS Session Stop Request" },
{ 119, "MBMS Session Stop Response" },
{ 120, "MBMS Session Update Request" },
{ 121, "MBMS Session Update Response" },
{ 128, "MBMS Info Change Notification Request" },
{ 129, "MBMS Info Change Notification Response" },
{ 240, "Data Record Transfer Request" },
{ 241, "Data Record Transfer Response" },
{ 255, "G-PDU" },
{ 0, NULL }
};
/* GTPv1 Causes. */
static struct tok gtp_v1_cause[] = {
/* GTPv1-C. */
{ 0, "Request IMSI" },
{ 1, "Request IMEI" },
{ 2, "Request IMSI and IMEI" },
{ 3, "No identity needed" },
{ 4, "MS refuses" },
{ 5, "MS is not GPRS responding" },
{ 128, "Request accepted" },
{ 192, "Non-existent" },
{ 193, "Invalid message format" },
{ 194, "IMSI not known" },
{ 195, "MS is GPRS detached" },
{ 196, "MS is not GPRS responding" },
{ 197, "MS refuses" },
{ 198, "Version not supported" },
{ 199, "No resources available" },
{ 200, "Service not supported" },
{ 201, "Mandatory IE incorrect" },
{ 202, "Mandatory IE missing" },
{ 203, "Optional IE incorrect" },
{ 204, "System failure" },
{ 205, "Roaming restriction" },
{ 206, "P-TMSI signature mismatch" },
{ 207, "GPRS connection suspended" },
{ 208, "Authentication failure" },
{ 209, "User authentication failed" },
{ 210, "Context not found" },
{ 211, "All dynamic PDP addresses are occupied" },
{ 212, "No memory is available" },
{ 213, "Relocation failure" },
{ 214, "Unknown mandatory extension header" },
{ 215, "Semantic error in the TFT operation" },
{ 216, "Syntactic error in the TFT operation" },
{ 217, "Semantic errors in packet filter(s)" },
{ 218, "Syntactic errors in packet filter(s)" },
{ 219, "Missing or unknown APN" },
{ 220, "Unknown PDP address or PDP type" },
{ 221, "PDP context without TFT already activated" },
{ 222, "APN access denied - no subscription" },
{ 223, "APN restriction type incompatibility with currently "
"active PDP contexts" },
{ 224, "MS MBMS capabilities insufficient" },
{ 225, "Invalid correlation-ID" },
{ 226, "MBMS bearer context superseded" },
/* GTP'v1. */
{ 59, "System failure" },
{ 60, "The transmit buffers are becoming full" },
{ 61, "The receive buffers are becoming full" },
{ 62, "Another node is about to go down" },
{ 63, "This node is about to go down" },
{ 177, "CDR decoding error" },
{ 252, "Request related to possibly duplicated packets already "
"fulfilled" },
{ 253, "Request already fulfilled" },
{ 254, "Sequence numbers of released/cancelled packets IE incorrect" },
{ 255, "Request not fulfilled" },
{ 0, NULL }
};
static int gtp_proto = -1;
void
gtp_print(register const u_char *cp, u_int length, u_short sport, u_short dport)
{
int version;
/* Decode GTP version. */
TCHECK(cp[0]);
version = cp[0] >> GTP_VERSION_SHIFT;
if (version == GTP_VERSION_0)
gtp_v0_print(cp, length, sport, dport);
else if (version == GTP_VERSION_1)
gtp_v1_print(cp, length, sport, dport);
else
printf(" GTP (version %i)", version);
return;
trunc:
printf(" [|GTP]");
}
/*
* Decode and print information elements from message. The actual work is
* handled in the appropriate Tag/Value (TV) or Tag/Length/Value (TLV)
* decoding routine.
*/
void
gtp_decode_ie(register const u_char *cp, u_short version, int len)
{
int val, ielen, iecount = 0;
if (len <= 0)
return;
printf(" {");
while (len > 0) {
iecount++;
if (iecount > 1)
printf(" ");
TCHECK(cp[0]);
val = (u_int)cp[0];
cp++;
printf("[");
switch (version) {
case GTP_VERSION_0:
if ((val & GTPV0_IE_TYPE_MASK) == 0)
ielen = gtp_v0_print_tv(cp, val);
else
ielen = gtp_v0_print_tlv(cp, val);
break;
case GTP_VERSION_1:
if ((val & GTPV1_IE_TYPE_MASK) == 0)
ielen = gtp_v1_print_tv(cp, val);
else
ielen = gtp_v1_print_tlv(cp, val);
break;
default:
/* Version not supported... */
ielen = -1;
break;
}
printf("]");
if (ielen < 0)
goto trunc;
len -= ielen;
cp += ielen - 1;
}
if (iecount > 0)
printf("}");
return;
trunc:
printf(" [|%s]", tok2str(gtp_type, "GTP", gtp_proto));
}
/*
* Decode and print telephony binary coded decimal.
*/
void
gtp_print_tbcd(register const u_char *cp, u_int len)
{
u_int8_t *data, bcd;
int i;
data = (u_int8_t *)cp;
for (i = 0; i < len; i++) {
bcd = *data & 0xf;
if (bcd != 0xf)
printf("%u", bcd);
bcd = *data >> 4;
if (bcd != 0xf)
printf("%u", bcd);
data++;
}
}
/*
* Decode and print an end user address. Format is detailed in
* GSM 09.60 section 7.9.18 and 3GPP 29.060 section 7.7.27.
*/
void
gtp_print_user_address(register const u_char *cp, u_int len)
{
u_int8_t org, type;
if (len < 2)
return;
org = (u_int8_t)cp[0] & 0xf;
type = (u_int8_t)cp[1];
cp += 2;
if (org == 0x0 && type == 0x1)
printf(": PPP");
else if (org == 0x1 && type == 0x21) {
if (len == 6)
printf(": %s", ipaddr_string(cp));
else
printf(": IPv4");
#ifdef INET6
} else if (org == 0x1 && type == 0x57) {
if (len == 18)
printf(": %s", ip6addr_string(cp));
else
printf(": IPv6");
#endif
} else
printf(" (org 0x%x, type 0x%x)", org, type);
}
/*
* Decode and print an Access Point Name. Format is detailed in
* 3GPP 24.008 section 10.5.6.1 and 3GPP 23.003 section 9.1.
*/
void
gtp_print_apn(register const u_char *cp, u_int len)
{
u_char label[100];
u_int8_t llen;
if (len < 1 || len > 100)
return;
while (len > 0) {
llen = (u_int8_t)cp[0];
if (llen > 99)
return;
bcopy(cp + 1, label, llen);
label[llen] = '\0';
printf("%s", label);
cp += llen + 1;
len -= llen + 1;
if (len > 0)
printf(".");
}
}
/* Print string from array. */
void
gtp_print_str(const char **strs, u_int index)
{
if (index >= (sizeof(*strs) / sizeof(*strs[0])))
printf(": %u", index);
else if (strs[index] != NULL)
printf(": %s", strs[index]);
}
/*
* Decoding routines for GTP version 0.
*/
void
gtp_v0_print(const u_char *cp, u_int length, u_short sport, u_short dport)
{
struct gtp_v0_hdr *gh = (struct gtp_v0_hdr *)cp;
int len, version;
u_int64_t tid;
gtp_proto = GTP_V0_PROTO;
/* Check if this is GTP prime. */
TCHECK(gh->flags);
if ((gh->flags & GTPV0_HDR_PROTO_TYPE) == 0) {
gtp_proto = GTP_V0_PRIME_PROTO;
gtp_v0_print_prime(cp);
return;
}
/* Print GTP header. */
TCHECK(*gh);
cp += sizeof(struct gtp_v0_hdr);
len = ntohs(gh->length);
bcopy(&gh->tid, &tid, sizeof(tid));
printf(" GTPv0 (len %u, seqno %u, flow %u, N-PDU %u, tid 0x%llx) ",
ntohs(gh->length), ntohs(gh->seqno), ntohs(gh->flow),
ntohs(gh->npduno), betoh64(tid));
/* Decode GTP message. */
printf("%s", tok2str(gtp_v0_msgtype, "Message Type %u", gh->msgtype));
if (!vflag)
return;
if (gh->msgtype == GTPV0_T_PDU) {
TCHECK(cp[0]);
version = cp[0] >> 4;
printf(" { ");
if (version == 4)
ip_print(cp, len);
#ifdef INET6
else if (version == 6)
ip6_print(cp, len);
#endif
else
printf("Unknown IP version %u", version);
printf(" }");
} else
gtp_decode_ie(cp, GTP_VERSION_0, len);
return;
trunc:
printf(" [|%s]", tok2str(gtp_type, "GTP", gtp_proto));
}
void
gtp_v0_print_prime(register const u_char *cp)
{
struct gtp_v0_prime_hdr *gph = (struct gtp_v0_prime_hdr *)cp;
int len;
/* Decode GTP prime header. */
TCHECK(*gph);
cp += sizeof(*gph);
len = ntohs(gph->length);
printf(" GTPv0' (len %u, seq %u) ", len, ntohs(gph->seqno));
/* Decode GTP message. */
printf("%s", tok2str(gtp_v0_msgtype, "Message Type %u", gph->msgtype));
if (vflag)
gtp_decode_ie(cp, GTP_VERSION_0, len);
return;
trunc:
printf(" [|%s]", tok2str(gtp_type, "GTP", gtp_proto));
}
int
gtp_v0_print_tv(register const u_char *cp, u_int value)
{
u_int32_t *dpl;
u_int16_t *dps;
u_int8_t data;
int ielen = -1;
switch (value) {
case GTPV0_TV_CAUSE:
/* 09.60 7.9.1 - Cause. */
TCHECK(cp[0]);
data = (u_int8_t)cp[0];
ielen = GTPV0_TV_CAUSE_LENGTH;
printf("Cause: %s", tok2str(gtp_v0_cause, "#%u", data));
break;
case GTPV0_TV_IMSI:
/* 09.60 7.9.2 - International Mobile Subscriber Identity. */
TCHECK2(cp[0], GTPV0_TV_IMSI_LENGTH - 1);
printf("IMSI ");
gtp_print_tbcd(cp, GTPV0_TV_IMSI_LENGTH - 1);
ielen = GTPV0_TV_IMSI_LENGTH;
break;
case GTPV0_TV_RAI:
/* 09.60 7.9.3 - Routing Area Identity (RAI). */
TCHECK2(cp[0], GTPV0_TV_RAI_LENGTH - 1);
printf("RAI: MCC ");
data = cp[1] | 0xf0;
gtp_print_tbcd(cp, 1);
gtp_print_tbcd(&data, 1);
printf(", MNC ");
data = (cp[1] >> 4) | 0xf0;
gtp_print_tbcd(cp + 2, 1);
gtp_print_tbcd(&data, 1);
printf(", LAC 0x%x%x", cp[3], cp[4]);
printf(", RAC 0x%x", cp[5]);
ielen = GTPV0_TV_RAI_LENGTH;
break;
case GTPV0_TV_TLLI:
/* 09.60 7.9.4 - Temporary Logical Link Identity (TLLI). */
TCHECK2(cp[0], GTPV0_TV_TLLI_LENGTH - 1);
dpl = (u_int32_t *)cp;
printf("TLLI 0x%x", ntohl(*dpl));
ielen = GTPV0_TV_TLLI_LENGTH;
break;
case GTPV0_TV_PTMSI:
/* 09.60 7.9.5 - Packet TMSI (P-TMSI). */
TCHECK2(cp[0], GTPV0_TV_PTMSI_LENGTH - 1);
dpl = (u_int32_t *)cp;
printf("P-TMSI 0x%x", ntohl(*dpl));
ielen = GTPV0_TV_PTMSI_LENGTH;
break;
case GTPV0_TV_QOS:
/* 09.60 7.9.6 - Quality of Service (QoS) Profile. */
TCHECK2(cp[0], GTPV0_TV_QOS_LENGTH - 1);
printf("QoS Profile"); /* XXX */
ielen = GTPV0_TV_QOS_LENGTH;
break;
case GTPV0_TV_REORDER:
/* 09.60 7.9.7 - Reordering Required. */
TCHECK2(cp[0], GTPV0_TV_REORDER_LENGTH - 1);
printf("Reordering Required: ");
if (cp[0] & 0x1)
printf("yes");
else
printf("no");
ielen = GTPV0_TV_REORDER_LENGTH;
break;
case GTPV0_TV_AUTH_TRIPLET:
/* 09.60 7.9.8 - Authentication Triplet. */
TCHECK2(cp[0], GTPV0_TV_AUTH_TRIPLET_LENGTH - 1);
printf("Authentication"); /* XXX */
ielen = GTPV0_TV_AUTH_TRIPLET_LENGTH;
break;
case GTPV0_TV_MAP_CAUSE:
/* 09.60 7.9.9 - MAP Cause. */
TCHECK2(cp[0], GTPV0_TV_MAP_CAUSE_LENGTH - 1);
printf("MAP Cause: %u", cp[0]);
ielen = GTPV0_TV_MAP_CAUSE_LENGTH;
break;
case GTPV0_TV_PTMSI_SIGNATURE:
/* 09.60 7.9.10 - P-TMSI Signature. */
/* Signature defined in GSM 04.08. */
TCHECK2(cp[0], GTPV0_TV_PTMSI_SIGNATURE_LENGTH - 1);
printf("PTMSI Signature: 0x%x%x%x", cp[0], cp[1], cp[2]);
ielen = GTPV0_TV_PTMSI_SIGNATURE_LENGTH;
break;
case GTPV0_TV_MS_VALIDATED:
/* 09.60 7.9.11 - MS Validated. */
TCHECK2(cp[0], GTPV0_TV_MS_VALIDATED_LENGTH - 1);
printf("MS Validated");
if (cp[0] & 0x1)
printf("yes");
else
printf("no");
ielen = GTPV0_TV_MS_VALIDATED_LENGTH;
break;
case GTPV0_TV_RECOVERY:
/* 09.60 7.9.12 - Recovery. */
TCHECK2(cp[0], GTPV0_TV_RECOVERY_LENGTH - 1);
printf("Recovery: Restart counter %u", cp[0]);
ielen = GTPV0_TV_RECOVERY_LENGTH;
break;
case GTPV0_TV_SELECTION_MODE:
/* 09.60 7.9.13 - Selection Mode. */
TCHECK2(cp[0], GTPV0_TV_SELECTION_MODE_LENGTH - 1);
printf("Selection Mode"); /* XXX */
ielen = GTPV0_TV_SELECTION_MODE_LENGTH;
break;
case GTPV0_TV_FLOW_LABEL_DATA_I:
/* 09.60 7.9.14 - Flow Label Data I. */
TCHECK2(cp[0], GTPV0_TV_FLOW_LABEL_DATA_I_LENGTH - 1);
dps = (u_int16_t *)cp;
printf("Flow Label Data I: %u", ntohs(*dps));
ielen = GTPV0_TV_FLOW_LABEL_DATA_I_LENGTH;
break;
case GTPV0_TV_FLOW_LABEL_SIGNALLING:
/* 09.60 7.9.15 - Flow Label Signalling. */
TCHECK2(cp[0], GTPV0_TV_FLOW_LABEL_SIGNALLING_LENGTH - 1);
dps = (u_int16_t *)cp;
printf("Flow Label Signalling: %u", ntohs(*dps));
ielen = GTPV0_TV_FLOW_LABEL_SIGNALLING_LENGTH;
break;
case GTPV0_TV_FLOW_LABEL_DATA_II:
/* 09.60 7.9.16 - Flow Label Data II. */
TCHECK2(cp[0], GTPV0_TV_FLOW_LABEL_DATA_II_LENGTH - 1);
data = cp[0] & 0xf;
dps = (u_int16_t *)(cp + 1);
printf("Flow Label Data II: %u, NSAPI %u", ntohs(*dps), data);
ielen = GTPV0_TV_FLOW_LABEL_DATA_II_LENGTH;
break;
case GTPV0_TV_PACKET_XFER_CMD:
/* 12.15 7.3.4.5.3 - Packet Transfer Command. */
TCHECK2(cp[0], GTPV0_TV_PACKET_XFER_CMD_LENGTH - 1);
printf("Packet Transfer Command");
gtp_print_str(gtp_packet_xfer_cmd, cp[0]);
ielen = GTPV0_TV_PACKET_XFER_CMD_LENGTH;
break;
case GTPV0_TV_CHARGING_ID:
/* 09.60 7.9.17 - Charging ID. */
TCHECK2(cp[0], GTPV0_TV_CHARGING_ID_LENGTH - 1);
dps = (u_int16_t *)cp;
printf("Charging ID: %u", ntohs(*dps));
ielen = GTPV0_TV_CHARGING_ID_LENGTH;
break;
default:
printf("TV %u", value);
}
trunc:
return ielen;
}
int
gtp_v0_print_tlv(register const u_char *cp, u_int value)
{
u_int8_t data;
u_int16_t *lenp, *seqno, len;
int ielen = -1;
/* Get length of IE. */
TCHECK2(cp[0], 2);
lenp = (u_int16_t *)cp;
cp += 2;
len = ntohs(*lenp);
TCHECK2(cp[0], len);
ielen = sizeof(data) + sizeof(len) + len;
switch (value) {
case GTPV0_TLV_END_USER_ADDRESS:
/* 09.60 7.9.18 - End User Address. */
printf("End User Address");
gtp_print_user_address(cp, len);
break;
case GTPV0_TLV_MM_CONTEXT:
/* 09.60 7.9.19 - MM Context. */
printf("MM Context"); /* XXX */
break;
case GTPV0_TLV_PDP_CONTEXT:
/* 09.60 7.9.20 - PDP Context. */
printf("PDP Context"); /* XXX */
break;
case GTPV0_TLV_ACCESS_POINT_NAME:
/* 09.60 7.9.21 - Access Point Name. */
printf("AP Name: ");
gtp_print_apn(cp, len);
break;
case GTPV0_TLV_PROTOCOL_CONFIG_OPTIONS:
/* 09.60 7.9.22 - Protocol Configuration Options. */
printf("Protocol Configuration Options"); /* XXX */
break;
case GTPV0_TLV_GSN_ADDRESS:
/* 09.60 7.9.23 - GSN Address. */
printf("GSN Address");
if (len == 4)
printf(": %s", ipaddr_string(cp));
#ifdef INET6
else if (len == 16)
printf(": %s", ip6addr_string(cp));
#endif
break;
case GTPV0_TLV_MS_ISDN:
/* 09.60 7.9.24 - MS International PSTN/ISDN Number. */
printf("MSISDN ");
data = (u_int8_t)cp[0]; /* XXX - Number type. */
gtp_print_tbcd(cp + 1, len - 1);
break;
case GTPV0_TLV_CHARGING_GATEWAY_ADDRESS:
/* 09.60 7.9.25 - Charging Gateway Address. */
printf("Charging Gateway");
if (len == 4)
printf(": %s", ipaddr_string(cp));
break;
case GTPV0_TLV_DATA_RECORD_PACKET:
/* 12.15 7.3.4.5.4 - Data Record Packet. */
printf("Data Record: Records %u, Format %u, Format Version %u",
cp[0], cp[1], ntohs(*(u_int16_t *)(cp + 2)));
break;
case GTPV0_TLV_REQUESTS_RESPONDED:
/* 12.15 7.3.4.6 - Requests Responded. */
printf("Requests Responded:");
seqno = (u_int16_t *)cp;
while (len > 0) {
printf(" %u", ntohs(*seqno));
seqno++;
len -= sizeof(*seqno);
}
break;
case GTPV0_TLV_RECOMMENDED_NODE:
/* 12.15 7.3.4.3 - Address of Recommended Node. */
printf("Recommended Node");
if (len == 4)
printf(": %s", ipaddr_string(cp));
#ifdef INET6
else if (len == 16)
printf(": %s", ip6addr_string(cp));
#endif
break;
case GTPV0_TLV_PRIVATE_EXTENSION:
printf("Private Extension");
break;
default:
printf("TLV %u (len %u)", value, len);
}
return ielen;
trunc:
return -1;
}
/*
* Decoding for GTP version 1, which consists of GTPv1-C, GTPv1-U and GTPv1'.
*/
void
gtp_v1_print(const u_char *cp, u_int length, u_short sport, u_short dport)
{
struct gtp_v1_hdr *gh = (struct gtp_v1_hdr *)cp;
struct gtp_v1_hdr_ext *ghe = 0;
int nexthdr, hlen;
u_char *p = (u_char *)cp;
TCHECK(gh->flags);
if ((gh->flags & GTPV1_HDR_PROTO_TYPE) == 0) {
gtp_proto = GTP_V1_PRIME_PROTO;
printf(" GTPv1'");
gtp_v1_print_prime(p, (struct gtp_v1_prime_hdr *)gh);
return;
}
if (dport == GTPV1_C_PORT || sport == GTPV1_C_PORT) {
gtp_proto = GTP_V1_CTRL_PROTO;
printf(" GTPv1-C");
} else if (dport == GTPV1_U_PORT || sport == GTPV1_U_PORT) {
gtp_proto = GTP_V1_USER_PROTO;
printf(" GTPv1-U");
} else if (dport == GTPV1_PRIME_PORT || sport == GTPV1_PRIME_PORT) {
gtp_proto = GTP_V1_PRIME_PROTO;
printf(" GTPv1'");
}
/* Decode GTP header. */
TCHECK(*gh);
p += sizeof(struct gtp_v1_hdr);
printf(" (teid %u, len %u)", ntohl(gh->teid), ntohs(gh->length));
if (gh->flags & GTPV1_HDR_EXT) {
ghe = (struct gtp_v1_hdr_ext *)cp;
TCHECK(*ghe);
p += sizeof(struct gtp_v1_hdr_ext) - sizeof(struct gtp_v1_hdr);
}
if (gh->flags & GTPV1_HDR_SN_FLAG)
printf(" [seq %u]", ntohs(ghe->seqno));
if (gh->flags & GTPV1_HDR_NPDU_FLAG)
printf(" [N-PDU %u]", ghe->npduno);
if (gh->flags & GTPV1_HDR_EH_FLAG) {
/* Process next header... */
nexthdr = ghe->nexthdr;
while (nexthdr != GTPV1_EH_NONE) {
/* Header length is a 4 octet multiplier. */
hlen = (int)p[0] * 4;
TCHECK2(p[0], hlen);
switch (nexthdr) {
case GTPV1_EH_MBMS_SUPPORT:
printf(" [MBMS Support]");
break;
case GTPV1_EH_MSI_CHANGE_RPT:
printf(" [MS Info Change Reporting]");
break;
case GTPV1_EH_PDCP_PDU_NO:
printf(" [PDCP PDU %u]",
ntohs(*(u_int16_t *)(p + 1)));
break;
case GTPV1_EH_SUSPEND_REQUEST:
printf(" [Suspend Request]");
break;
case GTPV1_EH_SUSPEND_RESPONSE:
printf(" [Suspend Response]");
break;
default:
printf(" [Unknown Header %u]", nexthdr);
}
p += hlen - 1;
nexthdr = (int)p[0];
p++;
}
}
hlen = p - cp;
if (dport == GTPV1_C_PORT || sport == GTPV1_C_PORT)
gtp_v1_print_ctrl(p, hlen, gh);
else if (dport == GTPV1_U_PORT || sport == GTPV1_U_PORT)
gtp_v1_print_user(p, hlen, gh);
return;
trunc:
printf(" [|%s]", tok2str(gtp_type, "GTP", gtp_proto));
}
void
gtp_v1_print_ctrl(register const u_char *cp, u_int hlen, struct gtp_v1_hdr *gh)
{
int len;
/* Decode GTP control message. */
printf(" %s", tok2str(gtp_v1_msgtype, "Message Type %u", gh->msgtype));
len = ntohs(gh->length) - hlen + sizeof(*gh);
if (vflag)
gtp_decode_ie(cp, GTP_VERSION_1, len);
}
void
gtp_v1_print_user(register const u_char *cp, u_int hlen, struct gtp_v1_hdr *gh)
{
int len, version;
/* Decode GTP user message. */
printf(" %s", tok2str(gtp_v1_msgtype, "Message Type %u", gh->msgtype));
if (!vflag)
return;
len = ntohs(gh->length) - hlen + sizeof(*gh);
if (gh->msgtype == GTPV1_G_PDU) {
TCHECK(cp[0]);
version = cp[0] >> 4;
printf(" { ");
if (version == 4)
ip_print(cp, len);
#ifdef INET6
else if (version == 6)
ip6_print(cp, len);
#endif
else
printf("Unknown IP version %u", version);
printf(" }");
} else
gtp_decode_ie(cp, GTP_VERSION_1, len);
return;
trunc:
printf(" [|%s]", tok2str(gtp_type, "GTP", gtp_proto));
}
void
gtp_v1_print_prime(register const u_char *cp, struct gtp_v1_prime_hdr *gph)
{
int len;
/* Decode GTP prime header. */
TCHECK(*gph);
cp += sizeof(struct gtp_v1_prime_hdr);
len = ntohs(gph->length);
printf(" (len %u, seq %u) ", len, ntohs(gph->seqno));
/* Decode GTP message. */
printf("%s", tok2str(gtp_v1_msgtype, "Message Type %u", gph->msgtype));
if (vflag)
gtp_decode_ie(cp, GTP_VERSION_1, len);
return;
trunc:
printf(" [|%s]", tok2str(gtp_type, "GTP", gtp_proto));
}
int
gtp_v1_print_tv(register const u_char *cp, u_int value)
{
u_int32_t *dpl;
u_int16_t *dps;
u_int8_t data;
int ielen = -1;
switch (value) {
case GTPV1_TV_CAUSE:
/* 29.060 - 7.7.1 Cause. */
TCHECK(cp[0]);
data = (u_int8_t)cp[0];
ielen = GTPV1_TV_CAUSE_LENGTH;
printf("Cause: %s", tok2str(gtp_v1_cause, "#%u", data));
break;
case GTPV1_TV_IMSI:
/* 29.060 7.7.2 - International Mobile Subscriber Identity. */
TCHECK2(cp[0], GTPV1_TV_IMSI_LENGTH - 1);
printf("IMSI ");
gtp_print_tbcd(cp, GTPV1_TV_IMSI_LENGTH - 1);
ielen = GTPV1_TV_IMSI_LENGTH;
break;
case GTPV1_TV_RAI:
/* 29.060 7.7.3 - Routing Area Identity (RAI). */
TCHECK2(cp[0], GTPV1_TV_RAI_LENGTH - 1);
printf("RAI: MCC ");
data = cp[1] | 0xf0;
gtp_print_tbcd(cp, 1);
gtp_print_tbcd(&data, 1);
printf(", MNC ");
data = (cp[1] >> 4) | 0xf0;
gtp_print_tbcd(cp + 2, 1);
gtp_print_tbcd(&data, 1);
printf(", LAC 0x%x%x", cp[3], cp[4]);
printf(", RAC 0x%x", cp[5]);
ielen = GTPV1_TV_RAI_LENGTH;
break;
case GTPV1_TV_TLLI:
/* 29.060 7.7.4 - Temporary Logical Link Identity (TLLI). */
TCHECK2(cp[0], GTPV1_TV_TLLI_LENGTH - 1);
dpl = (u_int32_t *)cp;
printf("TLLI 0x%x", ntohl(*dpl));
ielen = GTPV1_TV_TLLI_LENGTH;
break;
case GTPV1_TV_PTMSI:
/* 29.060 7.7.5 - Packet TMSI (P-TMSI). */
TCHECK2(cp[0], GTPV1_TV_PTMSI_LENGTH - 1);
dpl = (u_int32_t *)cp;
printf("P-TMSI 0x%x", ntohl(*dpl));
ielen = GTPV1_TV_PTMSI_LENGTH;
break;
case GTPV1_TV_REORDER:
/* 29.060 7.7.6 - Reordering Required. */
TCHECK2(cp[0], GTPV1_TV_REORDER_LENGTH - 1);
printf("Reordering Required: ");
if (cp[0] & 0x1)
printf("yes");
else
printf("no");
ielen = GTPV1_TV_REORDER_LENGTH;
break;
case GTPV1_TV_AUTH:
/* 29.060 7.7.7 - Authentication Triplet. */
TCHECK2(cp[0], GTPV1_TV_AUTH_LENGTH - 1);
dpl = (u_int32_t *)cp;
printf("Auth: RAND 0x%x%x%x%x, SRES 0x%x, Kc 0x%x%x",
ntohl(dpl[0]), ntohl(dpl[1]), ntohl(dpl[2]), ntohl(dpl[3]),
ntohl(dpl[4]), ntohl(dpl[5]), ntohl(dpl[6]));
ielen = GTPV1_TV_AUTH_LENGTH;
break;
case GTPV1_TV_MAP_CAUSE:
/* 29.060 7.7.8 - MAP Cause. */
/* Cause defined in 3GPP TS 29.002. */
TCHECK2(cp[0], GTPV1_TV_MAP_CAUSE_LENGTH - 1);
printf("Map Cause: %u", cp[0]);
ielen = GTPV1_TV_MAP_CAUSE_LENGTH;
break;
case GTPV1_TV_PTMSI_SIGNATURE:
/* 29.060 7.7.9 - P-TMSI Signature. */
/* Signature defined in 3GPP TS 24.008. */
TCHECK2(cp[0], GTPV1_TV_PTMSI_SIGNATURE_LENGTH - 1);
printf("PTMSI Signature: 0x%x%x%x", cp[0], cp[1], cp[2]);
ielen = GTPV1_TV_PTMSI_SIGNATURE_LENGTH;
break;
case GTPV1_TV_MS_VALIDATED:
/* 29.060 7.7.10 - MS Validated. */
TCHECK2(cp[0], GTPV1_TV_MS_VALIDATED_LENGTH - 1);
printf("MS Validated: ");
if (cp[0] & 0x1)
printf("yes");
else
printf("no");
ielen = GTPV1_TV_MS_VALIDATED_LENGTH;
break;
case GTPV1_TV_RECOVERY:
/* 29.060 7.7.11 - Recovery. */
TCHECK2(cp[0], GTPV1_TV_RECOVERY_LENGTH - 1);
printf("Recovery: Restart counter %u", cp[0]);
ielen = GTPV1_TV_RECOVERY_LENGTH;
break;
case GTPV1_TV_SELECTION_MODE:
/* 29.060 7.7.12 - Selection Mode. */
TCHECK2(cp[0], GTPV1_TV_SELECTION_MODE_LENGTH - 1);
data = (u_int8_t)cp[0];
printf("Selection Mode: %u", data & 0x2);
ielen = GTPV1_TV_SELECTION_MODE_LENGTH;
break;
case GTPV1_TV_TEID_DATA_I:
/* 29.060 7.7.13 - Tunnel Endpoint Identifier Data I. */
TCHECK2(cp[0], GTPV1_TV_TEID_DATA_I_LENGTH - 1);
dpl = (u_int32_t *)cp;
printf("TEI Data I: %u", ntohl(*dpl));
ielen = GTPV1_TV_TEID_DATA_I_LENGTH;
break;
case GTPV1_TV_TEID_CTRL:
/* 29.060 7.7.14 - Tunnel Endpoint Identifier Control Plane. */
TCHECK2(cp[0], GTPV1_TV_TEID_CTRL_LENGTH - 1);
dpl = (u_int32_t *)cp;
printf("TEI Control Plane: %u", ntohl(*dpl));
ielen = GTPV1_TV_TEID_CTRL_LENGTH;
break;
case GTPV1_TV_TEID_DATA_II:
/* 29.060 7.7.15 - Tunnel Endpoint Identifier Data II. */
TCHECK2(cp[0], GTPV1_TV_TEID_DATA_II_LENGTH - 1);
data = cp[0] & 0xf;
dpl = (u_int32_t *)(cp + 1);
printf("TEI Data II: %u, NSAPI %u", ntohl(*dpl), data);
ielen = GTPV1_TV_TEID_DATA_II_LENGTH;
break;
case GTPV1_TV_TEARDOWN:
/* 29.060 7.7.16 - Teardown Indicator. */
TCHECK2(cp[0], GTPV1_TV_TEARDOWN_LENGTH - 1);
printf("Teardown: ");
if (cp[0] & 0x1)
printf("yes");
else
printf("no");
ielen = GTPV1_TV_TEARDOWN_LENGTH;
break;
case GTPV1_TV_NSAPI:
/* 29.060 7.7.17 - NSAPI. */
TCHECK2(cp[0], GTPV1_TV_NSAPI_LENGTH - 1);
data = (u_int8_t)cp[0];
printf("NSAPI %u", data & 0xf);
ielen = GTPV1_TV_NSAPI_LENGTH;
break;
case GTPV1_TV_RANAP:
/* 29.060 7.7.18 - RANAP Cause. */
TCHECK2(cp[0], GTPV1_TV_RANAP_LENGTH - 1);
printf("RANAP Cause: %u", cp[0]);
ielen = GTPV1_TV_RANAP_LENGTH;
break;
case GTPV1_TV_RAB_CONTEXT:
/* 29.060 7.7.19 - RAB Context. */
TCHECK2(cp[0], GTPV1_TV_RAB_CONTEXT_LENGTH - 1);
data = cp[0] & 0xf;
dps = (u_int16_t *)(cp + 1);
printf("RAB Context: NSAPI %u, DL GTP-U Seq No %u,"
"UL GTP-U Seq No %u, DL PDCP Seq No %u, UL PDCP Seq No %u",
data, ntohs(dps[0]), ntohs(dps[1]), ntohs(dps[2]),
ntohs(dps[3]));
ielen = GTPV1_TV_RAB_CONTEXT_LENGTH;
break;
case GTPV1_TV_RADIO_PRIORITY_SMS:
/* 29.060 7.7.20 - Radio Priority SMS. */
TCHECK2(cp[0], GTPV1_TV_RADIO_PRI_SMS_LENGTH - 1);
printf("Radio Priority SMS: %u", cp[0] & 0x7);
ielen = GTPV1_TV_RADIO_PRI_SMS_LENGTH;
break;
case GTPV1_TV_RADIO_PRIORITY:
/* 29.060 7.7.21 - Radio Priority. */
TCHECK2(cp[0], GTPV1_TV_RADIO_PRI_LENGTH - 1);
data = cp[0] >> 4;
printf("Radio Priority: %u, NSAPI %u", cp[0] & 0x7, data);
ielen = GTPV1_TV_RADIO_PRI_LENGTH;
break;
case GTPV1_TV_PACKET_FLOW_ID:
/* 29.060 7.7.22 - Packet Flow ID. */
TCHECK2(cp[0], GTPV1_TV_PACKET_FLOW_ID_LENGTH - 1);
printf("Packet Flow ID: %u, NSAPI %u", cp[1], cp[0] & 0xf);
ielen = GTPV1_TV_PACKET_FLOW_ID_LENGTH;
break;
case GTPV1_TV_CHARGING:
/* 29.060 7.7.23 - Charging Characteristics. */
/* Charging defined in 3GPP TS 32.298. */
TCHECK2(cp[0], GTPV1_TV_CHARGING_LENGTH - 1);
printf("Charging Characteristics"); /* XXX */
ielen = GTPV1_TV_CHARGING_LENGTH;
break;
case GTPV1_TV_TRACE_REFERENCE:
/* 29.060 7.7.24 - Trace Reference. */
TCHECK2(cp[0], GTPV1_TV_TRACE_REFERENCE_LENGTH - 1);
dps = (u_int16_t *)cp;
printf("Trace Reference: %u", ntohs(*dps));
ielen = GTPV1_TV_TRACE_REFERENCE_LENGTH;
break;
case GTPV1_TV_TRACE_TYPE:
/* 29.060 7.7.25 - Trace Type. */
/* Trace type defined in GSM 12.08. */
TCHECK2(cp[0], GTPV1_TV_TRACE_TYPE_LENGTH - 1);
dps = (u_int16_t *)cp;
printf("Trace Type: %u", ntohs(*dps));
ielen = GTPV1_TV_TRACE_TYPE_LENGTH;
break;
case GTPV1_TV_MSNRR:
/* 29.060 7.7.26 - MS Not Reachable Reason. */
/* Reason defined in 3GPP TS 23.040. */
TCHECK2(cp[0], GTPV1_TV_MSNRR_LENGTH - 1);
printf("MS NRR: %u", cp[0]);
ielen = GTPV1_TV_MSNRR_LENGTH;
break;
case GTPV1_TV_PACKET_XFER_CMD:
/* 32.295 6.2.4.5.2 - Packet Transfer Command. */
TCHECK2(cp[0], GTPV1_TV_PACKET_XFER_CMD_LENGTH - 1);
printf("Packet Transfer Command");
gtp_print_str(gtp_packet_xfer_cmd, cp[0]);
ielen = GTPV1_TV_PACKET_XFER_CMD_LENGTH;
break;
case GTPV1_TV_CHARGING_ID:
/* 29.060 7.7.26 - Charging ID. */
TCHECK2(cp[0], GTPV1_TV_CHARGING_ID_LENGTH - 1);
dpl = (u_int32_t *)cp;
printf("Charging ID: %u", ntohl(*dpl));
ielen = GTPV1_TV_CHARGING_ID_LENGTH;
break;
default:
printf("TV %u", value);
}
trunc:
return ielen;
}
int
gtp_v1_print_tlv(register const u_char *cp, u_int value)
{
u_int8_t data;
u_int16_t *lenp, *seqno, len;
int ielen = -1;
/* Get length of IE. */
TCHECK2(cp[0], 2);
lenp = (u_int16_t *)cp;
cp += 2;
len = ntohs(*lenp);
TCHECK2(cp[0], len);
ielen = sizeof(data) + sizeof(len) + len;
switch (value) {
case GTPV1_TLV_END_USER_ADDRESS:
/* 3GPP 29.060 - 7.7.27 End User Address. */
printf("End User Address");
gtp_print_user_address(cp, len);
break;
case GTPV1_TLV_MM_CONTEXT:
/* 29.060 7.7.28 - MM Context. */
printf("MM Context"); /* XXX */
break;
case GTPV1_TLV_PDP_CONTEXT:
/* 29.260 7.7.29 - PDP Context. */
printf("PDP Context"); /* XXX */
break;
case GTPV1_TLV_ACCESS_POINT_NAME:
/* 29.060 7.7.30 - Access Point Name. */
printf("AP Name: ");
gtp_print_apn(cp, len);
break;
case GTPV1_TLV_PROTOCOL_CONFIG_OPTIONS:
/* 29.060 7.7.31 - Protocol Configuration Options. */
/* Defined in 3GPP TS 24.008. */
printf("Config Options"); /* XXX */
break;
case GTPV1_TLV_GSN_ADDRESS:
/* 29.060 7.7.32 - GSN Address. */
/* Defined in 3GPP TS 23.003. */
printf("GSN Address");
if (len == 4)
printf(": %s", ipaddr_string(cp));
#ifdef INET6
else if (len == 16)
printf(": %s", ip6addr_string(cp));
#endif
break;
case GTPV1_TLV_MSISDN:
/* 29.060 7.7.33 - MS International PSTN/ISDN Number. */
printf("MSISDN ");
data = (u_int8_t)cp[0]; /* XXX - Number type. */
gtp_print_tbcd(cp + 1, len - 1);
break;
case GTPV1_TLV_QOS_PROFILE:
/* 29.060 7.7.34 - QoS Profile. */
/* QoS profile defined in 3GPP TS 24.008 10.5.6.5. */
printf("QoS Profile: ");
data = (u_int8_t)cp[0];
printf("Delay Class %u, ", (data >> 3) & 0x7);
printf("Reliability Class %u", data & 0x7);
if (vflag > 1) {
printf(", ");
data = (u_int8_t)cp[1];
printf("Precedence Class %u", data & 0x7);
/* XXX - Decode more QoS fields. */
}
break;
case GTPV1_TLV_AUTHENTICATION:
/* 29.060 7.7.35 - Authentication. */
printf("Authentication"); /* XXX */
break;
case GTPV1_TLV_TRAFFIC_FLOW:
/* 29.060 7.7.36 - Traffic Flow Template. */
printf("Traffic Flow Template"); /* XXX */
break;
case GTPV1_TLV_TARGET_IDENTIFICATION:
/* 29.060 7.7.37 - Target Identification. */
printf("Target ID"); /* XXX */
break;
case GTPV1_TLV_UTRAN_CONTAINER:
/* 29.060 7.7.38 - UTRAN Transparent Container. */
printf("UTRAN Container"); /* XXX */
break;
case GTPV1_TLV_RAB_SETUP_INFORMATION:
/* 29.060 7.7.39 - RAB Setup Information. */
printf("RAB Setup"); /* XXX */
break;
case GTPV1_TLV_EXT_HEADER_TYPE_LIST:
/* 29.060 7.7.40 - Extension Header Type List. */
printf("Extension Header List"); /* XXX */
break;
case GTPV1_TLV_TRIGGER_ID:
/* 29.060 7.7.41 - Trigger ID. */
printf("Trigger ID"); /* XXX */
break;
case GTPV1_TLV_OMC_IDENTITY:
/* 29.060 7.7.42 - OMC Identity. */
printf("OMC Identity"); /* XXX */
break;
case GTPV1_TLV_RAN_CONTAINER:
/* 29.060 7.7.43 - RAN Transparent Container. */
printf("RAN Container"); /* XXX */
break;
case GTPV1_TLV_PDP_CONTEXT_PRIORITIZATION:
/* 29.060 7.7.45 - PDP Context Prioritization. */
printf("PDP Context Prioritization"); /* XXX */
break;
case GTPV1_TLV_ADDITIONAL_RAB_SETUP_INFO:
/* 29.060 7.7.45A - Additional RAB Setup Information. */
printf("Additional RAB Setup"); /* XXX */
break;
case GTPV1_TLV_SGSN_NUMBER:
/* 29.060 7.7.47 - SGSN Number. */
printf("SGSN Number"); /* XXX */
break;
case GTPV1_TLV_COMMON_FLAGS:
/* 29.060 7.7.48 - Common Flags. */
printf("Common Flags"); /* XXX */
break;
case GTPV1_TLV_APN_RESTRICTION:
/* 29.060 7.7.49 - APN Restriction. */
data = (u_int8_t)cp[0];
printf("APN Restriction: %u", data);
break;
case GTPV1_TLV_RADIO_PRIORITY_LCS:
/* 29.060 7.7.25B - Radio Priority LCS. */
printf("Radio Priority LCS: %u", cp[0] & 0x7);
break;
case GTPV1_TLV_RAT_TYPE:
/* 29.060 7.7.50 - RAT Type. */
printf("RAT");
gtp_print_str(gtp_rat_type, cp[0]);
break;
case GTPV1_TLV_USER_LOCATION_INFO:
/* 29.060 7.7.51 - User Location Information. */
printf("ULI"); /* XXX */
break;
case GTPV1_TLV_MS_TIME_ZONE:
/* 29.060 7.7.52 - MS Time Zone. */
printf("MSTZ"); /* XXX */
break;
case GTPV1_TLV_IMEI_SV:
/* 29.060 7.7.53 - IMEI(SV). */
printf("IMEI(SV) ");
gtp_print_tbcd(cp, len);
break;
case GTPV1_TLV_CAMEL_CHARGING_CONTAINER:
/* 29.060 7.7.54 - CAMEL Charging Information Container. */
printf("CAMEL Charging"); /* XXX */
break;
case GTPV1_TLV_MBMS_UE_CONTEXT:
/* 29.060 7.7.55 - MBMS UE Context. */
printf("MBMS UE Context"); /* XXX */
break;
case GTPV1_TLV_TMGI:
/* 29.060 7.7.56 - Temporary Mobile Group Identity. */
printf("TMGI"); /* XXX */
break;
case GTPV1_TLV_RIM_ROUTING_ADDRESS:
/* 29.060 7.7.57 - RIM Routing Address. */
printf("RIM Routing Address"); /* XXX */
break;
case GTPV1_TLV_MBMS_PROTOCOL_CONFIG_OPTIONS:
/* 29.060 7.7.58 - MBMS Protocol Configuration Options. */
printf("MBMS Protocol Config Options"); /* XXX */
break;
case GTPV1_TLV_MBMS_SERVICE_AREA:
/* 29.060 7.7.60 - MBMS Service Area. */
printf("MBMS Service Area"); /* XXX */
break;
case GTPV1_TLV_SOURCE_RNC_PDCP_CONTEXT_INFO:
/* 29.060 7.7.61 - Source RNC PDCP Context Information. */
printf("Source RNC PDCP Context"); /* XXX */
break;
case GTPV1_TLV_ADDITIONAL_TRACE_INFO:
/* 29.060 7.7.62 - Additional Trace Information. */
printf("Additional Trace Info"); /* XXX */
break;
case GTPV1_TLV_HOP_COUNTER:
/* 29.060 7.7.63 - Hop Counter. */
printf("Hop Counter: %u", cp[0]);
break;
case GTPV1_TLV_SELECTED_PLMN_ID:
/* 29.060 7.7.64 - Selected PLMN ID. */
printf("Selected PLMN ID"); /* XXX */
break;
case GTPV1_TLV_MBMS_SESSION_IDENTIFIER:
/* 29.060 7.7.65 - MBMS Session Identifier. */
printf("MBMS Session ID: %u", cp[0]);
break;
case GTPV1_TLV_MBMS_2G_3G_INDICATOR:
/* 29.060 7.7.66 - MBMS 2G/3G Indicator. */
printf("MBMS 2G/3G Indicator");
gtp_print_str(mbms_2g3g_indicator, cp[0]);
break;
case GTPV1_TLV_ENHANCED_NSAPI:
/* 29.060 7.7.67 - Enhanced NSAPI. */
printf("Enhanced NSAPI"); /* XXX */
break;
case GTPV1_TLV_MBMS_SESSION_DURATION:
/* 29.060 7.7.59 - MBMS Session Duration. */
printf("MBMS Session Duration"); /* XXX */
break;
case GTPV1_TLV_ADDITIONAL_MBMS_TRACE_INFO:
/* 29.060 7.7.68 - Additional MBMS Trace Info. */
printf("Additional MBMS Trace Info"); /* XXX */
break;
case GTPV1_TLV_MBMS_SESSION_REPITITION_NO:
/* 29.060 7.7.69 - MBMS Session Repetition Number. */
printf("MBMS Session Repetition No: %u", cp[0]);
break;
case GTPV1_TLV_MBMS_TIME_TO_DATA_TRANSFER:
/* 29.060 7.7.70 - MBMS Time to Data Transfer. */
printf("MBMS Time to Data Transfer: %u", cp[0]);
break;
case GTPV1_TLV_PS_HANDOVER_REQUEST_CONTEXT:
/* 29.060 7.7.71 - PS Handover Request Context (Void). */
break;
case GTPV1_TLV_BSS_CONTAINER:
/* 29.060 7.7.72 - BSS Container. */
printf("BSS Container"); /* XXX */
break;
case GTPV1_TLV_CELL_IDENTIFICATION:
/* 29.060 7.7.73 - Cell Identification. */
printf("Cell Identification"); /* XXX */
break;
case GTPV1_TLV_PDU_NUMBERS:
/* 29.060 7.7.74 - PDU Numbers. */
printf("PDU Numbers"); /* XXX */
break;
case GTPV1_TLV_BSSGP_CAUSE:
/* 29.060 7.7.75 - BSSGP Cause. */
printf("BSSGP Cause: %u", cp[0]);
break;
case GTPV1_TLV_REQUIRED_MBMS_BEARER_CAP:
/* 29.060 7.7.76 - Required MBMS Bearer Cap. */
printf("Required MBMS Bearer Cap"); /* XXX */
break;
case GTPV1_TLV_RIM_ROUTING_ADDRESS_DISC:
/* 29.060 7.7.77 - RIM Routing Address Discriminator. */
printf("RIM Routing Address Discriminator: %u", cp[0] & 0xf);
break;
case GTPV1_TLV_LIST_OF_SETUP_PFCS:
/* 29.060 7.7.78 - List of Setup PFCs. */
printf("List of Setup PFCs"); /* XXX */
break;
case GTPV1_TLV_PS_HANDOVER_XID_PARAMETERS:
/* 29.060 7.7.79 - PS Handover XID Parameters. */
printf("PS Handover XID Parameters"); /* XXX */
break;
case GTPV1_TLV_MS_INFO_CHANGE_REPORTING:
/* 29.060 7.7.80 - MS Info Change Reporting. */
printf("MS Info Change Reporting");
gtp_print_str(ms_info_change_rpt, cp[0]);
break;
case GTPV1_TLV_DIRECT_TUNNEL_FLAGS:
/* 29.060 7.7.81 - Direct Tunnel Flags. */
printf("Direct Tunnel Flags"); /* XXX */
break;
case GTPV1_TLV_CORRELATION_ID:
/* 29.060 7.7.82 - Correlation ID. */
printf("Correlation ID"); /* XXX */
break;
case GTPV1_TLV_BEARER_CONTROL_MODE:
/* 29.060 7.7.83 - Bearer Control Mode. */
printf("Bearer Control Mode"); /* XXX */
break;
case GTPV1_TLV_MBMS_FLOW_IDENTIFIER:
/* 29.060 7.7.84 - MBMS Flow Identifier. */
printf("MBMS Flow Identifier"); /* XXX */
break;
case GTPV1_TLV_RELEASED_PACKETS:
/* 32.295 6.2.4.5.4 - Sequence Numbers of Released Packets. */
printf("Released Packets:");
seqno = (u_int16_t *)cp;
while (len > 0) {
printf(" %u", ntohs(*seqno));
seqno++;
len -= sizeof(*seqno);
}
break;
case GTPV1_TLV_CANCELLED_PACKETS:
/* 32.295 6.2.4.5.5 - Sequence Numbers of Cancelled Packets. */
printf("Cancelled Packets:");
seqno = (u_int16_t *)cp;
while (len > 0) {
printf(" %u", ntohs(*seqno));
seqno++;
len -= sizeof(*seqno);
}
break;
case GTPV1_TLV_CHARGING_GATEWAY_ADDRESS:
/* 29.060 7.7.44 - Charging Gateway Address. */
printf("Charging Gateway");
if (len == 4)
printf(": %s", ipaddr_string(cp));
#ifdef INET6
else if (len == 16)
printf(": %s", ip6addr_string(cp));
#endif
break;
case GTPV1_TLV_DATA_RECORD_PACKET:
/* 32.295 6.2.4.5.3 - Data Record Packet. */
printf("Data Record: Records %u, Format %u, Format Version %u",
cp[0], cp[1], ntohs(*(u_int16_t *)(cp + 2)));
break;
case GTPV1_TLV_REQUESTS_RESPONDED:
/* 32.295 6.2.4.6 - Requests Responded. */
printf("Requests Responded:");
seqno = (u_int16_t *)cp;
while (len > 0) {
printf(" %u", ntohs(*seqno));
seqno++;
len -= sizeof(*seqno);
}
break;
case GTPV1_TLV_ADDRESS_OF_RECOMMENDED_NODE:
/* 32.295 6.2.4.3 - Address of Recommended Node. */
printf("Address of Recommended Node");
if (len == 4)
printf(": %s", ipaddr_string(cp));
#ifdef INET6
else if (len == 16)
printf(": %s", ip6addr_string(cp));
#endif
break;
case GTPV1_TLV_PRIVATE_EXTENSION:
/* 29.060 7.7.46 - Private Extension. */
printf("Private Extension");
break;
default:
printf("TLV %u (len %u)", value, len);
}
return ielen;
trunc:
return -1;
}
|