aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-someip.c
blob: 8c2e6c8f5581007ff9066e5c9015ea9a2ec7ccce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
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
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
/* packet-someip.c
 * SOME/IP dissector.
 * By Dr. Lars Voelker <lars.voelker@technica-engineering.de> / <lars.voelker@bmw.de>
 * Copyright 2012-2024 Dr. Lars Voelker
 * Copyright 2019      Ana Pantar
 * Copyright 2019      Guenter Ebermann
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include <config.h>

#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/expert.h>
#include <epan/to_str.h>
#include <epan/uat.h>
#include "packet-tcp.h"
#include <epan/reassemble.h>
#include <epan/addr_resolv.h>
#include <epan/stats_tree.h>

#include "packet-udp.h"
#include "packet-dtls.h"
#include "packet-someip.h"
#include "packet-tls.h"

/*
 * Dissector for SOME/IP, SOME/IP-TP, and SOME/IP Payloads.
 *
 * See
 *     http://www.some-ip.com
 *
 *
 * This dissector also supports the experimental WTLV or TLV extension,
 * which is not part of the original SOME/IP.
 * This add-on feature uses a so-called WireType, which is basically
 * a type of a length field and an ID to each parameter. Since the
 * WireType is not really a type, we should avoid TLV as name for this.
 * Only use this, if you know what you are doing since this changes the
 * serialization methodology of SOME/IP in a incompatible way and might
 * break the dissection of your messages.
 */

#define SOMEIP_NAME                             "SOME/IP"
#define SOMEIP_NAME_LONG                        "SOME/IP Protocol"
#define SOMEIP_NAME_FILTER                      "someip"
#define SOMEIP_NAME_PREFIX                      "someip.payload"

#define SOMEIP_NAME_LONG_MULTIPLE               "SOME/IP Protocol (Multiple Payloads)"
#define SOMEIP_NAME_LONG_BROKEN                 "SOME/IP: Incomplete headers!"
#define SOMEIP_NAME_LONG_TOO_SHORT              "SOME/IP: Incomplete SOME/IP payload!"

 /*** Configuration ***/
#define DATAFILE_SOMEIP_SERVICES                "SOMEIP_service_identifiers"
#define DATAFILE_SOMEIP_METHODS                 "SOMEIP_method_event_identifiers"
#define DATAFILE_SOMEIP_EVENTGROUPS             "SOMEIP_eventgroup_identifiers"
#define DATAFILE_SOMEIP_CLIENTS                 "SOMEIP_client_identifiers"

#define DATAFILE_SOMEIP_PARAMETERS              "SOMEIP_parameter_list"
#define DATAFILE_SOMEIP_BASE_TYPES              "SOMEIP_parameter_base_types"
#define DATAFILE_SOMEIP_ARRAYS                  "SOMEIP_parameter_arrays"
#define DATAFILE_SOMEIP_STRINGS                 "SOMEIP_parameter_strings"
#define DATAFILE_SOMEIP_TYPEDEFS                "SOMEIP_parameter_typedefs"
#define DATAFILE_SOMEIP_STRUCTS                 "SOMEIP_parameter_structs"
#define DATAFILE_SOMEIP_UNIONS                  "SOMEIP_parameter_unions"
#define DATAFILE_SOMEIP_ENUMS                   "SOMEIP_parameter_enums"

#define SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_UNKNOWN      0
#define SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_BASE_TYPE    1
#define SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_STRING       2
#define SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_ARRAY        3
#define SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_STRUCT       4
#define SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_UNION        5
#define SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_TYPEDEF      6
#define SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_ENUM         7

/*** SOME/IP ***/
#define SOMEIP_HDR_LEN                          16
#define SOMEIP_HDR_PART1_LEN                    8
#define SOMEIP_HDR_PART2_LEN_INCL_TP            12
#define SOMEIP_TP_HDR_LEN                       4
#define SOMEIP_PROTOCOL_VERSION                 1

/* Message Types */
#define SOMEIP_MSGTYPE_REQUEST                  0x00
#define SOMEIP_MSGTYPE_REQUEST_NO_RESPONSE      0x01
#define SOMEIP_MSGTYPE_NOTIFICATION             0x02
#define SOMEIP_MSGTYPE_RESPONSE                 0x80
#define SOMEIP_MSGTYPE_ERROR                    0x81

#define SOMEIP_MSGTYPE_ACK_MASK                 0x40
#define SOMEIP_MSGTYPE_TP_MASK                  0x20
#define SOMEIP_MSGTYPE_FLAGS_MASK               0x60
#define SOMEIP_MSGTYPE_NO_FLAGS_MASK            0x9f
#define SOMEIP_MSGTYPE_TP_STRING                "SOME/IP-TP segment"
#define SOMEIP_MSGTYPE_ACK_STRING               "ACK"

/* SOME/IP-TP */
#define SOMEIP_TP_OFFSET_MASK                   0xfffffff0
#define SOMEIP_TP_OFFSET_MASK_FLAGS             0x0000000f
#define SOMEIP_TP_OFFSET_MASK_RESERVED          0x0000000e
#define SOMEIP_TP_OFFSET_MASK_MORE_SEGMENTS     0x00000001

/* Return Codes */
#define SOMEIP_RETCODE_OK                       0x00
#define SOMEIP_RETCODE_NOT_OK                   0x01
#define SOMEIP_RETCODE_UNKNOWN_SERVICE          0x02
#define SOMEIP_RETCODE_UNKNOWN_METHOD           0x03
#define SOMEIP_RETCODE_NOT_READY                0x04
#define SOMEIP_RETCODE_NOT_REACHABLE            0x05
#define SOMEIP_RETCODE_TIMEOUT                  0x06
#define SOMEIP_RETCODE_WRONG_PROTO_VER          0x07
#define SOMEIP_RETCODE_WRONG_INTERFACE_VER      0x08
#define SOMEIP_RETCODE_MALFORMED_MSG            0x09
#define SOMEIP_RETCODE_WRONG_MESSAGE_TYPE       0x0a

/* SOME/IP WTLV (experimental "WTLV" extension) */
#define SOMEIP_WTLV_MASK_RES                     0x8000
#define SOMEIP_WTLV_MASK_WIRE_TYPE               0x7000
#define SOMEIP_WTLV_MASK_DATA_ID                 0x0fff

/* ID wireshark identifies the dissector by */
static int proto_someip;

static dissector_handle_t someip_handle_udp = NULL;
static dissector_handle_t someip_handle_tcp = NULL;
static dissector_handle_t dtls_handle = NULL;

/* header field */
static int hf_someip_messageid;
static int hf_someip_serviceid;
static int hf_someip_servicename;
static int hf_someip_methodid;
static int hf_someip_methodname;
static int hf_someip_length;
static int hf_someip_clientid;
static int hf_someip_clientname;
static int hf_someip_sessionid;
static int hf_someip_protover;
static int hf_someip_interface_ver;
static int hf_someip_messagetype;
static int hf_someip_messagetype_ack_flag;
static int hf_someip_messagetype_tp_flag;
static int hf_someip_returncode;

static int hf_someip_tp;
static int hf_someip_tp_offset;
static int hf_someip_tp_offset_encoded;
static int hf_someip_tp_flags;
static int hf_someip_tp_reserved;
static int hf_someip_tp_more_segments;

static int hf_someip_payload;

/* protocol tree items */
static gint ett_someip;
static gint ett_someip_msgtype;
static gint ett_someip_tp;

/* dissector handling */
static dissector_table_t someip_dissector_table = NULL;

/* message reassembly for SOME/IP-TP */
static int hf_someip_tp_fragments;
static int hf_someip_tp_fragment;
static int hf_someip_tp_fragment_overlap;
static int hf_someip_tp_fragment_overlap_conflicts;
static int hf_someip_tp_fragment_multiple_tails;
static int hf_someip_tp_fragment_too_long_fragment;
static int hf_someip_tp_fragment_error;
static int hf_someip_tp_fragment_count;
static int hf_someip_tp_reassembled_in;
static int hf_someip_tp_reassembled_length;
static int hf_someip_tp_reassembled_data;

static int hf_payload_unparsed;
static int hf_payload_length_field_8bit;
static int hf_payload_length_field_16bit;
static int hf_payload_length_field_32bit;
static int hf_payload_type_field_8bit;
static int hf_payload_type_field_16bit;
static int hf_payload_type_field_32bit;
static int hf_payload_str_base;
static int hf_payload_str_string;
static int hf_payload_str_struct;
static int hf_payload_str_array;
static int hf_payload_str_union;

static int hf_payload_wtlv_tag;
static int hf_payload_wtlv_tag_res;
static int hf_payload_wtlv_tag_wire_type;
static int hf_payload_wtlv_tag_data_id;

static hf_register_info* dynamic_hf_param                               = NULL;
static guint dynamic_hf_param_size                                      = 0;
static hf_register_info* dynamic_hf_array                               = NULL;
static guint dynamic_hf_array_size                                      = 0;
static hf_register_info* dynamic_hf_struct                              = NULL;
static guint dynamic_hf_struct_size                                     = 0;
static hf_register_info* dynamic_hf_union                               = NULL;
static guint dynamic_hf_union_size                                      = 0;

static gint ett_someip_tp_fragment;
static gint ett_someip_tp_fragments;
static gint ett_someip_payload;
static gint ett_someip_string;
static gint ett_someip_array;
static gint ett_someip_array_dim;
static gint ett_someip_struct;
static gint ett_someip_union;
static gint ett_someip_parameter;
static gint ett_someip_wtlv_tag;

static const fragment_items someip_tp_frag_items = {
    &ett_someip_tp_fragment,
    &ett_someip_tp_fragments,
    &hf_someip_tp_fragments,
    &hf_someip_tp_fragment,
    &hf_someip_tp_fragment_overlap,
    &hf_someip_tp_fragment_overlap_conflicts,
    &hf_someip_tp_fragment_multiple_tails,
    &hf_someip_tp_fragment_too_long_fragment,
    &hf_someip_tp_fragment_error,
    &hf_someip_tp_fragment_count,
    &hf_someip_tp_reassembled_in,
    &hf_someip_tp_reassembled_length,
    &hf_someip_tp_reassembled_data,
    "SOME/IP-TP Segments"
};

static gboolean someip_tp_reassemble = TRUE;
static gboolean someip_deserializer_activated = TRUE;
static gboolean someip_deserializer_wtlv_default = FALSE;
static gboolean someip_detect_dtls = FALSE;

/* SOME/IP Message Types */
static const value_string someip_msg_type[] = {
    {SOMEIP_MSGTYPE_REQUEST,                                            "Request"},
    {SOMEIP_MSGTYPE_REQUEST_NO_RESPONSE,                                "Request no response"},
    {SOMEIP_MSGTYPE_NOTIFICATION,                                       "Notification"},
    {SOMEIP_MSGTYPE_RESPONSE,                                           "Response"},
    {SOMEIP_MSGTYPE_ERROR,                                              "Error"},
    {SOMEIP_MSGTYPE_REQUEST | SOMEIP_MSGTYPE_ACK_MASK,                  "Request Ack"},
    {SOMEIP_MSGTYPE_REQUEST_NO_RESPONSE | SOMEIP_MSGTYPE_ACK_MASK,      "Request no response Ack"},
    {SOMEIP_MSGTYPE_NOTIFICATION | SOMEIP_MSGTYPE_ACK_MASK,             "Notification Ack"},
    {SOMEIP_MSGTYPE_RESPONSE | SOMEIP_MSGTYPE_ACK_MASK,                 "Response Ack"},
    {SOMEIP_MSGTYPE_ERROR | SOMEIP_MSGTYPE_ACK_MASK,                    "Error Ack"},
    {0, NULL}
};

/* SOME/IP Return Code */
static const value_string someip_return_code[] = {
    {SOMEIP_RETCODE_OK,                                                 "Ok"},
    {SOMEIP_RETCODE_NOT_OK,                                             "Not Ok"},
    {SOMEIP_RETCODE_UNKNOWN_SERVICE,                                    "Unknown Service"},
    {SOMEIP_RETCODE_UNKNOWN_METHOD,                                     "Unknown Method/Event"},
    {SOMEIP_RETCODE_NOT_READY,                                          "Not Ready"},
    {SOMEIP_RETCODE_NOT_REACHABLE,                                      "Not Reachable (internal)"},
    {SOMEIP_RETCODE_TIMEOUT,                                            "Timeout (internal)"},
    {SOMEIP_RETCODE_WRONG_PROTO_VER,                                    "Wrong Protocol Version"},
    {SOMEIP_RETCODE_WRONG_INTERFACE_VER,                                "Wrong Interface Version"},
    {SOMEIP_RETCODE_MALFORMED_MSG,                                      "Malformed Message"},
    {SOMEIP_RETCODE_WRONG_MESSAGE_TYPE,                                 "Wrong Message Type"},
    {0, NULL}
};

/*** expert info items ***/
static expert_field ei_someip_unknown_version;
static expert_field ei_someip_message_truncated;
static expert_field ei_someip_incomplete_headers;

static expert_field ei_someip_payload_truncated;
static expert_field ei_someip_payload_malformed;
static expert_field ei_someip_payload_config_error;
static expert_field ei_someip_payload_alignment_error;
static expert_field ei_someip_payload_static_array_min_not_max;
static expert_field ei_someip_payload_dyn_array_not_within_limit;

/*** Data Structure for mapping IDs to Names (Services, Methods, ...) ***/
static GHashTable *data_someip_services                                 = NULL;
static GHashTable *data_someip_methods                                  = NULL;
static GHashTable *data_someip_eventgroups                              = NULL;
static GHashTable *data_someip_clients                                  = NULL;

static GHashTable *data_someip_parameter_list                           = NULL;
static GHashTable *data_someip_parameter_base_type_list                 = NULL;
static GHashTable *data_someip_parameter_strings                        = NULL;
static GHashTable *data_someip_parameter_typedefs                       = NULL;
static GHashTable *data_someip_parameter_arrays                         = NULL;
static GHashTable *data_someip_parameter_structs                        = NULL;
static GHashTable *data_someip_parameter_unions                         = NULL;
static GHashTable *data_someip_parameter_enums                          = NULL;

/*** Taps ***/
static int tap_someip_messages = -1;

/*** Stats ***/
static const gchar *st_str_ip_src = "Source Addresses";
static const gchar *st_str_ip_dst = "Destination Addresses";

static int st_node_ip_src = -1;
static int st_node_ip_dst = -1;

/***********************************************
 ********* Preferences / Configuration *********
 ***********************************************/

typedef struct _someip_payload_parameter_item {
    guint32     pos;
    gchar      *name;
    guint32     data_type;
    guint32     id_ref;
    int        *hf_id;
    gchar      *filter_string;
} someip_payload_parameter_item_t;

#define INIT_SOMEIP_PAYLOAD_PARAMETER_ITEM(NAME) \
    (NAME)->pos = 0; \
    (NAME)->name = NULL; \
    (NAME)->data_type = 0; \
    (NAME)->id_ref = 0; \
    (NAME)->hf_id = NULL; \
    (NAME)->filter_string = NULL;


typedef struct _someip_payload_parameter_base_type_list {
    guint32     id;
    gchar      *name;
    gchar      *data_type;
    gboolean    big_endian;
    guint32     bitlength_base_type;
    guint32     bitlength_encoded_type;
} someip_payload_parameter_base_type_list_t;

#define INIT_COMMON_BASE_TYPE_LIST_ITEM(NAME) \
    (NAME)->id                      = 0; \
    (NAME)->name                    = NULL; \
    (NAME)->data_type               = NULL ; \
    (NAME)->big_endian              = TRUE; \
    (NAME)->bitlength_base_type     = 0; \
    (NAME)->bitlength_encoded_type  = 0;


typedef struct _someip_payload_parameter_string {
    guint32     id;
    gchar      *name;
    gchar      *encoding;
    gboolean    dynamic_length;
    guint32     max_length;
    guint32     length_of_length;   /* default: 32 */
    gboolean    big_endian;
    guint32     pad_to;
} someip_payload_parameter_string_t;

#define INIT_SOMEIP_PAYLOAD_PARAMETER_STRING(NAME) \
    (NAME)->id                  = 0; \
    (NAME)->name                = NULL; \
    (NAME)->encoding            = NULL; \
    (NAME)->dynamic_length      = FALSE; \
    (NAME)->max_length          = 0; \
    (NAME)->length_of_length    = 0; \
    (NAME)->big_endian          = TRUE; \
    (NAME)->pad_to              = 0;


typedef struct _someip_payload_parameter_typedef {
    guint32    id;
    gchar*     name;
    guint32    data_type;
    guint32    id_ref;
} someip_payload_parameter_typedef_t;

#define INIT_SOMEIP_PAYLOAD_PARAMETER_TYPEDEF(NAME) \
    (NAME)->id          = 0; \
    (NAME)->name        = NULL; \
    (NAME)->data_type   = 0; \
    (NAME)->id_ref      = 0;


typedef struct _someip_payload_parameter_struct {
    guint32     id;
    gchar      *struct_name;
    guint32     length_of_length;   /* default: 0 */
    guint32     pad_to;             /* default: 0 */
    gboolean    wtlv_encoding;
    guint32     num_of_items;

    /* array of items */
    someip_payload_parameter_item_t *items;
} someip_payload_parameter_struct_t;

#define INIT_SOMEIP_PAYLOAD_PARAMETER_STRUCT(NAME) \
    (NAME)->id                  = 0; \
    (NAME)->struct_name         = NULL; \
    (NAME)->length_of_length    = 0; \
    (NAME)->pad_to              = 0; \
    (NAME)->wtlv_encoding       = FALSE; \
    (NAME)->num_of_items        = 0;


typedef struct _someip_payload_parameter_enum_item {
    guint64     value;
    gchar      *name;
} someip_payload_parameter_enum_item_t;

#define INIT_SOMEIP_PAYLOAD_PARAMETER_ENUM_ITEM(NAME) \
    (NAME)->value   = 0; \
    (NAME)->name    = NULL;


typedef struct _someip_payload_parameter_enum {
    guint32     id;
    gchar      *name;
    guint32     data_type;
    guint32     id_ref;
    guint32     num_of_items;

    someip_payload_parameter_enum_item_t *items;
} someip_payload_parameter_enum_t;

#define INIT_SOMEIP_PAYLOAD_PARAMETER_ENUM(NAME) \
    (NAME)->id              = 0; \
    (NAME)->name            = NULL; \
    (NAME)->data_type       = 0; \
    (NAME)->id_ref          = 0; \
    (NAME)->num_of_items    = 0; \
    (NAME)->items           = NULL;

typedef struct _someip_parameter_union_item {
    guint32             id;
    gchar              *name;
    guint32             data_type;
    guint32             id_ref;
    int                *hf_id;
    gchar              *filter_string;
} someip_parameter_union_item_t;

typedef struct _someip_parameter_union {
    guint32             id;
    gchar              *name;
    guint32             length_of_length;       /* default: 32 */
    guint32             length_of_type;         /* default: 32 */
    guint32             pad_to;                 /* default: 0 */
    guint32             num_of_items;

    someip_parameter_union_item_t *items;
} someip_parameter_union_t;

typedef struct _someip_parameter_union_uat {
    guint32             id;
    gchar              *name;
    guint32             length_of_length;
    guint32             length_of_type;
    guint32             pad_to;
    guint32             num_of_items;
    guint32             type_id;
    gchar              *type_name;
    guint32             data_type;
    guint32             id_ref;
    gchar              *filter_string;
} someip_parameter_union_uat_t;

typedef struct _someip_parameter_enum_uat {
    guint32             id;
    gchar              *name;
    guint32             data_type;
    guint32             id_ref;
    guint32             num_of_items;
    guint32             value;
    gchar              *value_name;
} someip_parameter_enum_uat_t;

typedef struct _someip_parameter_array_dim {
    guint32             num;
    guint32             lower_limit;
    guint32             upper_limit;
    guint32             length_of_length;
    guint32             pad_to;
} someip_parameter_array_dim_t;

typedef struct _someip_parameter_array {
    guint32             id;
    gchar              *name;
    guint32             data_type;
    guint32             id_ref;
    guint32             num_of_dims;
    int                *hf_id;
    char               *filter_string;

    someip_parameter_array_dim_t *dims;
} someip_parameter_array_t;

typedef struct _someip_parameter_array_uat {
    guint32             id;
    gchar              *name;
    guint32             data_type;
    guint32             id_ref;
    guint32             num_of_dims;
    gchar              *filter_string;

    guint32             num;
    guint32             lower_limit;
    guint32             upper_limit;
    guint32             length_of_length;
    guint32             pad_to;
} someip_parameter_array_uat_t;

typedef struct _someip_parameter_list {
    guint32             service_id;
    guint32             method_id;
    guint32             version;
    guint32             message_type;
    gboolean            wtlv_encoding;

    guint32             num_of_items;

    someip_payload_parameter_item_t *items;
} someip_parameter_list_t;

typedef struct _someip_parameter_list_uat {
    guint32             service_id;
    guint32             method_id;
    guint32             version;
    guint32             message_type;
    gboolean            wtlv_encoding;

    guint32             num_of_params;

    guint32             pos;
    gchar              *name;
    guint32             data_type;
    guint32             id_ref;
    gchar              *filter_string;
} someip_parameter_list_uat_t;

typedef struct _someip_parameter_struct_uat {
    guint32             id;
    gchar              *struct_name;
    guint32             length_of_length;       /* default: 0 */
    guint32             pad_to;                 /* default: 0 */
    gboolean            wtlv_encoding;

    guint32             num_of_items;

    guint32             pos;
    gchar              *name;
    guint32             data_type;
    guint32             id_ref;
    gchar              *filter_string;
} someip_parameter_struct_uat_t;

typedef someip_payload_parameter_base_type_list_t someip_parameter_base_type_list_uat_t;
typedef someip_payload_parameter_string_t someip_parameter_string_uat_t;
typedef someip_payload_parameter_typedef_t someip_parameter_typedef_uat_t;

typedef struct _generic_one_id_string {
    guint   id;
    gchar  *name;
} generic_one_id_string_t;

typedef struct _generic_two_id_string {
    guint   id;
    guint   id2;
    gchar  *name;
} generic_two_id_string_t;

static generic_one_id_string_t *someip_service_ident = NULL;
static guint someip_service_ident_num = 0;

static generic_two_id_string_t *someip_method_ident = NULL;
static guint someip_method_ident_num = 0;

static generic_two_id_string_t *someip_eventgroup_ident = NULL;
static guint someip_eventgroup_ident_num = 0;

static generic_two_id_string_t *someip_client_ident = NULL;
static guint someip_client_ident_num = 0;

static someip_parameter_list_uat_t *someip_parameter_list = NULL;
static guint someip_parameter_list_num = 0;

static someip_parameter_string_uat_t *someip_parameter_strings = NULL;
static guint someip_parameter_strings_num = 0;

static someip_parameter_typedef_uat_t *someip_parameter_typedefs = NULL;
static guint someip_parameter_typedefs_num = 0;

static someip_parameter_array_uat_t *someip_parameter_arrays = NULL;
static guint someip_parameter_arrays_num = 0;

static someip_parameter_struct_uat_t *someip_parameter_structs = NULL;
static guint someip_parameter_structs_num = 0;

static someip_parameter_union_uat_t *someip_parameter_unions = NULL;
static guint someip_parameter_unions_num = 0;

static someip_parameter_enum_uat_t *someip_parameter_enums = NULL;
static guint someip_parameter_enums_num = 0;

static someip_parameter_base_type_list_uat_t *someip_parameter_base_type_list = NULL;
static guint someip_parameter_base_type_list_num = 0;

void proto_register_someip(void);
void proto_reg_handoff_someip(void);

static void update_dynamic_hf_entries_someip_parameter_list(void);
static void update_dynamic_hf_entries_someip_parameter_arrays(void);
static void update_dynamic_hf_entries_someip_parameter_structs(void);
static void update_dynamic_hf_entries_someip_parameter_unions(void);

/* Segmentation support
 * https://gitlab.com/wireshark/wireshark/-/issues/18880
 */
typedef struct _someip_segment_key {
    address src_addr;
    address dst_addr;
    guint32 src_port;
    guint32 dst_port;
    someip_info_t info;
} someip_segment_key;

static guint
someip_segment_hash(gconstpointer k)
{
    const someip_segment_key *key = (const someip_segment_key *)k;
    guint hash_val;

    hash_val = (key->info.service_id << 16 | key->info.method_id) ^
        (key->info.client_id << 16 | key->info.session_id);

    return hash_val;
}

static gint
someip_segment_equal(gconstpointer k1, gconstpointer k2)
{
    const someip_segment_key *key1 = (someip_segment_key *)k1;
    const someip_segment_key *key2 = (someip_segment_key *)k2;

    return (key1->info.session_id == key2->info.session_id) &&
        (key1->info.service_id == key2->info.service_id) &&
        (key1->info.client_id == key2->info.client_id) &&
        (key1->info.method_id == key2->info.method_id) &&
        (key1->info.message_type == key2->info.message_type) &&
        (key1->info.major_version == key2->info.major_version) &&
        (addresses_equal(&key1->src_addr, &key2->src_addr)) &&
        (addresses_equal(&key1->dst_addr, &key2->dst_addr)) &&
        (key1->src_port == key2->src_port) &&
        (key1->dst_port == key2->dst_port);
}

/*
 * Create a fragment key for temporary use; it can point to non-
 * persistent data, and so must only be used to look up and
 * delete entries, not to add them.
 */
static gpointer
someip_segment_temporary_key(const packet_info *pinfo, const guint32 id _U_,
                          const void *data)
{
    const someip_info_t *info = (const someip_info_t *)data;
    someip_segment_key *key = g_slice_new(someip_segment_key);

    /* Do a shallow copy of the addresses. */
    copy_address_shallow(&key->src_addr, &pinfo->src);
    copy_address_shallow(&key->dst_addr, &pinfo->dst);
    key->src_port = pinfo->srcport;
    key->dst_port = pinfo->destport;
    memcpy(&key->info, info, sizeof(someip_info_t));

    return (gpointer)key;
}

/*
 * Create a fragment key for permanent use; it must point to persistent
 * data, so that it can be used to add entries.
 */
static gpointer
someip_segment_persistent_key(const packet_info *pinfo,
                              const guint32 id _U_, const void *data)
{
    const someip_info_t *info = (const someip_info_t *)data;
    someip_segment_key *key = g_slice_new(someip_segment_key);

    /* Do a deep copy of the addresses. */
    copy_address(&key->src_addr, &pinfo->src);
    copy_address(&key->dst_addr, &pinfo->dst);
    key->src_port = pinfo->srcport;
    key->dst_port = pinfo->destport;
    memcpy(&key->info, info, sizeof(someip_info_t));

    return (gpointer)key;
}

static void
someip_segment_free_temporary_key(gpointer ptr)
{
    someip_segment_key *key = (someip_segment_key *)ptr;
    if (key) {
        g_slice_free(someip_segment_key, key);
    }
}
static void
someip_segment_free_persistent_key(gpointer ptr)
{
    someip_segment_key *key = (someip_segment_key *)ptr;
    if (key) {
        /* Free up the copies of the addresses from the old key. */
        free_address(&key->src_addr);
        free_address(&key->dst_addr);

        g_slice_free(someip_segment_key, key);
    }
}

static const reassembly_table_functions
someip_reassembly_table_functions = {
    someip_segment_hash,
    someip_segment_equal,
    someip_segment_temporary_key,
    someip_segment_persistent_key,
    someip_segment_free_temporary_key,
    someip_segment_free_persistent_key
};

static reassembly_table someip_tp_reassembly_table;


/* register a UDP SOME/IP port */
void
register_someip_port_udp(guint32 portnumber) {
    dissector_add_uint("udp.port", portnumber, someip_handle_udp);
}

/* register a TCP SOME/IP port */
void
register_someip_port_tcp(guint32 portnumber) {
    dissector_add_uint("tcp.port", portnumber, someip_handle_tcp);
}

/*** UAT Callbacks and Helpers ***/

static char*
check_filter_string(gchar *filter_string, guint32 id) {
    char   *err = NULL;
    guchar  c;

    c = proto_check_field_name(filter_string);
    if (c) {
        if (c == '.') {
            err = ws_strdup_printf("Filter String contains illegal chars '.' (ID: %i )", id);
        } else if (g_ascii_isprint(c)) {
            err = ws_strdup_printf("Filter String contains illegal chars '%c' (ID: %i)", c, id);
        } else {
            err = ws_strdup_printf("Filter String contains invalid byte \\%03o (ID: %i)", c, id);
        }
    }

    return err;
}

static void
someip_free_key(gpointer key) {
    wmem_free(wmem_epan_scope(), key);
}

static void
simple_free(gpointer data _U_) {
    /* we need to free because of the g_strdup in post_update*/
    g_free(data);
}

/* ID -> Name */
static void *
copy_generic_one_id_string_cb(void *n, const void *o, size_t size _U_) {
    generic_one_id_string_t        *new_rec = (generic_one_id_string_t *)n;
    const generic_one_id_string_t  *old_rec = (const generic_one_id_string_t *)o;

    new_rec->name = g_strdup(old_rec->name);
    new_rec->id   = old_rec->id;
    return new_rec;
}

static bool
update_serviceid(void *r, char **err) {
    generic_one_id_string_t *rec = (generic_one_id_string_t *)r;

    if (rec->id == 0xffff) {
        *err = ws_strdup_printf("Service-ID 0xffff is reserved and cannot be used (ID: %i  Name: %s)", rec->id, rec->name);
        return FALSE;
    }

    if (rec->id > 0xffff) {
        *err = ws_strdup_printf("Service-IDs have to be 16bit (ID: %i  Name: %s)", rec->id, rec->name);
        return FALSE;
    }

    if (rec->name == NULL || rec->name[0] == 0) {
        *err = g_strdup("Name cannot be empty");
        return FALSE;
    }

    return TRUE;
}

static void
free_generic_one_id_string_cb(void*r) {
    generic_one_id_string_t *rec = (generic_one_id_string_t *)r;

    /* freeing result of g_strdup */
    g_free(rec->name);
    rec->name = NULL;
}

static void
post_update_one_id_string_template_cb(generic_one_id_string_t *data, guint data_num, GHashTable *ht) {
    guint   i;
    int    *key = NULL;

    for (i = 0; i < data_num; i++) {
        key = wmem_new(wmem_epan_scope(), int);
        *key = data[i].id;

        g_hash_table_insert(ht, key, g_strdup(data[i].name));
    }
}

/* ID/ID2 -> Name */

static void *
copy_generic_two_id_string_cb(void *n, const void *o, size_t size _U_) {
    generic_two_id_string_t        *new_rec = (generic_two_id_string_t *)n;
    const generic_two_id_string_t  *old_rec = (const generic_two_id_string_t *)o;

    new_rec->name = g_strdup(old_rec->name);
    new_rec->id   = old_rec->id;
    new_rec->id2  = old_rec->id2;
    return new_rec;
}

static bool
update_two_identifier_16bit_check_both(void *r, char **err) {
    generic_two_id_string_t *rec = (generic_two_id_string_t *)r;

    if (rec->id == 0xffff) {
        *err = ws_strdup_printf("Service-ID 0xffff is reserved and cannot be used (ID: %i  Name: %s)", rec->id, rec->name);
        return FALSE;
    }

    if (rec->id > 0xffff) {
        *err = ws_strdup_printf("Service-IDs have to be 16bit (ID: %i  Name: %s)", rec->id, rec->name);
        return FALSE;
    }

    if (rec->id2 == 0xffff) {
        *err = ws_strdup_printf("0xffff is reserved and cannot be used (ID: %i  ID2: %i  Name: %s)", rec->id, rec->id2, rec->name);
        return FALSE;
    }

    if (rec->id2 > 0xffff) {
        *err = ws_strdup_printf("We currently only support 16 bit identifiers (ID: %i  ID2: %i  Name: %s)", rec->id, rec->id2, rec->name);
        return FALSE;
    }

    if (rec->name == NULL || rec->name[0] == 0) {
        *err = g_strdup("Name cannot be empty");
        return FALSE;
    }

    return TRUE;
}

static bool
update_generic_two_identifier_16bit(void *r, char **err) {
    generic_two_id_string_t *rec = (generic_two_id_string_t *)r;

    if (rec->id > 0xffff) {
        *err = ws_strdup_printf("We currently only support 16 bit identifiers (ID: %i  Name: %s)", rec->id, rec->name);
        return FALSE;
    }

    if (rec->id2 > 0xffff) {
        *err = ws_strdup_printf("We currently only support 16 bit identifiers (ID: %i  ID2: %i  Name: %s)", rec->id, rec->id2, rec->name);
        return FALSE;
    }

    if (rec->name == NULL || rec->name[0] == 0) {
        *err = g_strdup("Name cannot be empty");
        return FALSE;
    }

    return TRUE;
}

static void
free_generic_two_id_string_cb(void*r) {
    generic_two_id_string_t *rec = (generic_two_id_string_t *)r;

    /* freeing result of g_strdup */
    g_free(rec->name);
    rec->name = NULL;
}

static void
post_update_generic_two_id_string_template_cb(generic_two_id_string_t *data, guint data_num, GHashTable *ht) {
    guint   i;
    int    *key = NULL;
    guint   tmp;
    guint   tmp2;

    for (i = 0; i < data_num; i++) {
        key = wmem_new(wmem_epan_scope(), int);
        tmp = (data[i].id & 0xffff) << 16;
        tmp2 = (data[i].id2 & 0xffff);

        /* the hash table does not know about uint32, so we use int32 */
        *key = (int)(tmp + tmp2);

        g_hash_table_insert(ht, key, g_strdup(data[i].name));
    }
}

char *
someip_lookup_service_name(guint16 serviceid) {
    guint32 tmp = (guint32)serviceid;

    if (data_someip_services == NULL) {
        return NULL;
    }

    return (char *)g_hash_table_lookup(data_someip_services, &tmp);
}

static char *
someip_lookup_method_name(guint16 serviceid, guint16 methodid) {
    guint32 tmp = (serviceid << 16) + methodid;

    if (data_someip_methods == NULL) {
        return NULL;
    }

    return (char *)g_hash_table_lookup(data_someip_methods, &tmp);
}

char *
someip_lookup_eventgroup_name(guint16 serviceid, guint16 eventgroupid) {
    guint32 tmp = (serviceid << 16) + eventgroupid;

    if (data_someip_eventgroups == NULL) {
        return NULL;
    }

    return (char *)g_hash_table_lookup(data_someip_eventgroups, &tmp);
}

static char *
someip_lookup_client_name(guint16 serviceid, guint16 clientid) {
    guint32 tmp = (serviceid << 16) + clientid;

    if (data_someip_clients == NULL) {
        return NULL;
    }

    return (char *)g_hash_table_lookup(data_someip_clients, &tmp);
}


/*** SOME/IP Services ***/
UAT_HEX_CB_DEF        (someip_service_ident, id,    generic_one_id_string_t)
UAT_CSTRING_CB_DEF    (someip_service_ident, name,  generic_one_id_string_t)

static void
reset_someip_service_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_services) {
        g_hash_table_destroy(data_someip_services);
        data_someip_services = NULL;
    }
}

static void
post_update_someip_service_cb(void) {
    reset_someip_service_cb();

    /* create new hash table */
    data_someip_services = g_hash_table_new_full(g_int_hash, g_int_equal, &someip_free_key, &simple_free);
    post_update_one_id_string_template_cb(someip_service_ident, someip_service_ident_num, data_someip_services);
}


/*** SOME/IP Methods/Events/Fields ***/
UAT_HEX_CB_DEF      (someip_method_ident, id,   generic_two_id_string_t)
UAT_HEX_CB_DEF      (someip_method_ident, id2,  generic_two_id_string_t)
UAT_CSTRING_CB_DEF  (someip_method_ident, name, generic_two_id_string_t)

static void
reset_someip_method_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_methods) {
        g_hash_table_destroy(data_someip_methods);
        data_someip_methods = NULL;
    }
}

static void
post_update_someip_method_cb(void) {
    reset_someip_method_cb();

    /* create new hash table */
    data_someip_methods = g_hash_table_new_full(g_int_hash, g_int_equal, &someip_free_key, &simple_free);
    post_update_generic_two_id_string_template_cb(someip_method_ident, someip_method_ident_num, data_someip_methods);
}


/*** SOME/IP Eventgroups ***/
UAT_HEX_CB_DEF      (someip_eventgroup_ident, id,   generic_two_id_string_t)
UAT_HEX_CB_DEF      (someip_eventgroup_ident, id2,  generic_two_id_string_t)
UAT_CSTRING_CB_DEF  (someip_eventgroup_ident, name, generic_two_id_string_t)

static void
reset_someip_eventgroup_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_eventgroups) {
        g_hash_table_destroy(data_someip_eventgroups);
        data_someip_eventgroups = NULL;
    }
}

static void
post_update_someip_eventgroup_cb(void) {
    reset_someip_eventgroup_cb();

    /* create new hash table */
    data_someip_eventgroups = g_hash_table_new_full(g_int_hash, g_int_equal, &someip_free_key, &simple_free);
    post_update_generic_two_id_string_template_cb(someip_eventgroup_ident, someip_eventgroup_ident_num, data_someip_eventgroups);
}


/*** SOME/IP Clients ***/
UAT_HEX_CB_DEF(someip_client_ident, id, generic_two_id_string_t)
UAT_HEX_CB_DEF(someip_client_ident, id2, generic_two_id_string_t)
UAT_CSTRING_CB_DEF(someip_client_ident, name, generic_two_id_string_t)

static void
reset_someip_client_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_clients) {
        g_hash_table_destroy(data_someip_clients);
        data_someip_clients = NULL;
    }
}

static void
post_update_someip_client_cb(void) {
    reset_someip_client_cb();

    /* create new hash table */
    data_someip_clients = g_hash_table_new_full(g_int_hash, g_int_equal, &someip_free_key, &simple_free);
    post_update_generic_two_id_string_template_cb(someip_client_ident, someip_client_ident_num, data_someip_clients);
}

static void
someip_payload_free_key(gpointer key) {
    wmem_free(wmem_epan_scope(), key);
}

static gint64
someip_parameter_key(guint16 serviceid, guint16 methodid, guint8 version, guint8 msgtype) {
    gint64 tmp1;
    gint64 tmp2;
    gint64 tmp3;
    gint64 tmp4;

    /* key:
        Service-ID [16bit] | Method-ID [16bit] | Version [8bit] | Message-Type [8bit]
    */

    tmp1 = (gint64)(serviceid & 0xffff);
    tmp2 = (gint64)(methodid & 0xffff) << 16;
    tmp3 = (gint64)(version & 0xff) << 32;
    tmp4 = (gint64)(msgtype & 0xff) << 40;

    return (gint64)(tmp1 + tmp2 + tmp3 + tmp4);
}

static someip_parameter_list_t*
get_parameter_config(guint16 serviceid, guint16 methodid, guint8 version, guint8 msgtype) {
    gint64                  *key = NULL;
    someip_parameter_list_t *tmp = NULL;

    if (data_someip_parameter_list == NULL) {
        return NULL;
    }

    key = wmem_new(wmem_epan_scope(), gint64);
    *key = someip_parameter_key(serviceid, methodid, version, msgtype);
    tmp = (someip_parameter_list_t *)g_hash_table_lookup(data_someip_parameter_list, key);
    wmem_free(wmem_epan_scope(), key);

    return tmp;
}

static gpointer
get_generic_config(GHashTable *ht, gint64 id) {
    if (ht == NULL) {
        return NULL;
    }

    return (gpointer)g_hash_table_lookup(ht, &id);
}

static someip_payload_parameter_base_type_list_t*
get_base_type_config(guint32 id) {
    return (someip_payload_parameter_base_type_list_t *)get_generic_config(data_someip_parameter_base_type_list, (gint64)id);
}

static someip_payload_parameter_string_t*
get_string_config(guint32 id) {
    return (someip_payload_parameter_string_t *)get_generic_config(data_someip_parameter_strings, (gint64)id);
}

static someip_payload_parameter_typedef_t*
get_typedef_config(guint32 id) {
    return (someip_payload_parameter_typedef_t *)get_generic_config(data_someip_parameter_typedefs, (gint64)id);
}

static someip_parameter_array_t*
get_array_config(guint32 id) {
    return (someip_parameter_array_t *)get_generic_config(data_someip_parameter_arrays, (gint64)id);
}

static someip_payload_parameter_struct_t*
get_struct_config(guint32 id) {
    return (someip_payload_parameter_struct_t *)get_generic_config(data_someip_parameter_structs, (gint64)id);
}

static someip_parameter_union_t*
get_union_config(guint32 id) {
    return (someip_parameter_union_t *)get_generic_config(data_someip_parameter_unions, (gint64)id);
}

static someip_payload_parameter_enum_t*
get_enum_config(guint32 id) {
    return (someip_payload_parameter_enum_t *)get_generic_config(data_someip_parameter_enums, (gint64)id);
}

UAT_HEX_CB_DEF(someip_parameter_list, service_id, someip_parameter_list_uat_t)
UAT_HEX_CB_DEF(someip_parameter_list, method_id, someip_parameter_list_uat_t)
UAT_DEC_CB_DEF(someip_parameter_list, version, someip_parameter_list_uat_t)
UAT_HEX_CB_DEF(someip_parameter_list, message_type, someip_parameter_list_uat_t)
UAT_BOOL_CB_DEF(someip_parameter_list, wtlv_encoding, someip_parameter_list_uat_t)

UAT_DEC_CB_DEF(someip_parameter_list, num_of_params, someip_parameter_list_uat_t)

UAT_DEC_CB_DEF(someip_parameter_list, pos, someip_parameter_list_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_list, name, someip_parameter_list_uat_t)
UAT_DEC_CB_DEF(someip_parameter_list, data_type, someip_parameter_list_uat_t)
UAT_HEX_CB_DEF(someip_parameter_list, id_ref, someip_parameter_list_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_list, filter_string, someip_parameter_list_uat_t)

static void *
copy_someip_parameter_list_cb(void *n, const void *o, size_t size _U_) {
    someip_parameter_list_uat_t        *new_rec = (someip_parameter_list_uat_t *)n;
    const someip_parameter_list_uat_t  *old_rec = (const someip_parameter_list_uat_t *)o;

    if (old_rec->name) {
        new_rec->name = g_strdup(old_rec->name);
    } else {
        new_rec->name = NULL;
    }

    if (old_rec->filter_string) {
        new_rec->filter_string = g_strdup(old_rec->filter_string);
    } else {
        new_rec->filter_string = NULL;
    }

    new_rec->service_id    = old_rec->service_id;
    new_rec->method_id     = old_rec->method_id;
    new_rec->version       = old_rec->version;
    new_rec->message_type  = old_rec->message_type;
    new_rec->wtlv_encoding = old_rec->wtlv_encoding;
    new_rec->num_of_params = old_rec->num_of_params;
    new_rec->pos           = old_rec->pos;
    new_rec->data_type     = old_rec->data_type;
    new_rec->id_ref        = old_rec->id_ref;

    return new_rec;
}

static bool
update_someip_parameter_list(void *r, char **err) {
    someip_parameter_list_uat_t *rec = (someip_parameter_list_uat_t *)r;
    guchar c;

    if (rec->service_id > 0xffff) {
        *err = ws_strdup_printf("We currently only support 16 bit Service IDs (Service-ID: %i  Name: %s)", rec->service_id, rec->name);
        return FALSE;
    }

    if (rec->method_id > 0xffff) {
        *err = ws_strdup_printf("We currently only support 16 bit Method IDs (Service-ID: %i  Method-ID: %i  Name: %s)", rec->service_id, rec->method_id, rec->name);
        return FALSE;
    }

    if (rec->version > 0xff) {
        *err = ws_strdup_printf("We currently only support 8 bit Version (Service-ID: %i  Method-ID: %i  Version: %d  Name: %s)", rec->service_id, rec->method_id, rec->version, rec->name);
        return FALSE;
    }

    if (rec->message_type > 0xff) {
        *err = ws_strdup_printf("We currently only support 8 bit Message Type (Service-ID: %i  Method-ID: %i  Version: %d  Message Type: %x  Name: %s)", rec->service_id, rec->method_id, rec->version, rec->message_type, rec->name);
        return FALSE;
    }

    if (rec->name == NULL || rec->name[0] == 0) {
        *err = ws_strdup_printf("Name cannot be empty");
        return FALSE;
    }

    if (rec->pos >= rec->num_of_params) {
        *err = ws_strdup_printf("Position >= Number of Parameters");
        return FALSE;
    }

    if (rec->filter_string == NULL || rec->filter_string[0] == 0) {
        *err = ws_strdup_printf("Name cannot be empty");
        return FALSE;
    }

    c = proto_check_field_name(rec->filter_string);
    if (c) {
        if (c == '.') {
            *err = ws_strdup_printf("Filter String contains illegal chars '.' (Service-ID: %i  Method-ID: %i)", rec->service_id, rec->method_id);
        } else if (g_ascii_isprint(c)) {
            *err = ws_strdup_printf("Filter String contains illegal chars '%c' (Service-ID: %i  Method-ID: %i)", c, rec->service_id, rec->method_id);
        } else {
            *err = ws_strdup_printf("Filter String contains invalid byte \\%03o (Service-ID: %i  Method-ID: %i)", c, rec->service_id, rec->method_id);
        }
        return FALSE;
    }

    return TRUE;
}

static void
free_someip_parameter_list_cb(void *r) {
    someip_parameter_list_uat_t *rec = (someip_parameter_list_uat_t *)r;

    if (rec->name) {
        g_free(rec->name);
        rec->name = NULL;
    }

    if (rec->filter_string) {
        g_free(rec->filter_string);
        rec->filter_string = NULL;
    }
}

static void
free_someip_parameter_list(gpointer data) {
    someip_parameter_list_t *list = (someip_parameter_list_t *)data;

    if (list->items != NULL) {
        wmem_free(wmem_epan_scope(), (void *)(list->items));
        list->items = NULL;
    }

    wmem_free(wmem_epan_scope(), (void *)data);
}

static void
post_update_someip_parameter_list_read_in_data(someip_parameter_list_uat_t *data, guint data_num, GHashTable *ht) {
    guint                               i = 0;
    gint64                             *key = NULL;
    someip_parameter_list_t            *list = NULL;
    someip_payload_parameter_item_t    *item = NULL;
    someip_payload_parameter_item_t    *items = NULL;

    if (ht == NULL || data == NULL || data_num == 0) {
        return;
    }

    for (i = 0; i < data_num; i++) {
        /* the hash table does not know about uint64, so we use int64*/
        key = wmem_new(wmem_epan_scope(), gint64);
        *key = someip_parameter_key((guint16)data[i].service_id, (guint16)data[i].method_id, (guint8)data[i].version, (guint8)data[i].message_type);

        list = (someip_parameter_list_t *)g_hash_table_lookup(ht, key);
        if (list == NULL) {

            list = wmem_new(wmem_epan_scope(), someip_parameter_list_t);

            list->service_id    = data[i].service_id;
            list->method_id     = data[i].method_id;
            list->version       = data[i].version;
            list->message_type  = data[i].message_type;
            list->wtlv_encoding = data[i].wtlv_encoding;
            list->num_of_items  = data[i].num_of_params;

            items = (someip_payload_parameter_item_t *)wmem_alloc0_array(wmem_epan_scope(), someip_payload_parameter_item_t, data[i].num_of_params);
            list->items = items;

            /* create new entry ... */
            g_hash_table_insert(ht, key, list);
        } else {
            /* already present, deleting key */
            wmem_free(wmem_epan_scope(), key);
        }

        /* and now we add to item array */
        if (data[i].num_of_params == list->num_of_items && data[i].pos < list->num_of_items) {
            item = &(list->items[data[i].pos]);

            /* we do not care if we overwrite param */
            item->name          = data[i].name;
            item->id_ref        = data[i].id_ref;
            item->pos           = data[i].pos;
            item->data_type     = data[i].data_type;
            item->filter_string = data[i].filter_string;
        }
    }
}

static void
reset_someip_parameter_list_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_parameter_list) {
        g_hash_table_destroy(data_someip_parameter_list);
        data_someip_parameter_list = NULL;
    }
}

static void
post_update_someip_parameter_list_cb(void) {
    reset_someip_parameter_list_cb();

    data_someip_parameter_list = g_hash_table_new_full(g_int64_hash, g_int64_equal, &someip_payload_free_key, &free_someip_parameter_list);
    post_update_someip_parameter_list_read_in_data(someip_parameter_list, someip_parameter_list_num, data_someip_parameter_list);
    update_dynamic_hf_entries_someip_parameter_list();
}

UAT_HEX_CB_DEF(someip_parameter_enums, id, someip_parameter_enum_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_enums, name, someip_parameter_enum_uat_t)
UAT_DEC_CB_DEF(someip_parameter_enums, data_type, someip_parameter_enum_uat_t)
UAT_HEX_CB_DEF(someip_parameter_enums, id_ref, someip_parameter_enum_uat_t)
UAT_DEC_CB_DEF(someip_parameter_enums, num_of_items, someip_parameter_enum_uat_t)

UAT_HEX_CB_DEF(someip_parameter_enums, value, someip_parameter_enum_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_enums, value_name, someip_parameter_enum_uat_t)

static void *
copy_someip_parameter_enum_cb(void *n, const void *o, size_t size _U_) {
    someip_parameter_enum_uat_t        *new_rec = (someip_parameter_enum_uat_t *)n;
    const someip_parameter_enum_uat_t  *old_rec = (const someip_parameter_enum_uat_t *)o;

    new_rec->id = old_rec->id;
    if (old_rec->name) {
        new_rec->name = g_strdup(old_rec->name);
    } else {
        new_rec->name = NULL;
    }
    new_rec->data_type    = old_rec->data_type;
    new_rec->id_ref       = old_rec->id_ref;
    new_rec->num_of_items = old_rec->num_of_items;

    new_rec->value = old_rec->value;
    if (old_rec->value_name) {
        new_rec->value_name = g_strdup(old_rec->value_name);
    } else {
        new_rec->value_name = NULL;
    }

    return new_rec;
}

static bool
update_someip_parameter_enum(void *r, char **err) {
    someip_parameter_enum_uat_t *rec = (someip_parameter_enum_uat_t *)r;

    /* enum name is not used in a filter yet. */

    if (rec->name == NULL || rec->name[0] == 0) {
        *err = ws_strdup_printf("Name cannot be empty (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    if (rec->value_name == NULL || rec->value_name[0] == 0) {
        *err = ws_strdup_printf("Value Name cannot be empty (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    if (rec->num_of_items == 0) {
        *err = ws_strdup_printf("Number_of_Items = 0 (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    if (rec->data_type == SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_ENUM) {
        *err = ws_strdup_printf("An enum cannot reference an enum (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    return TRUE;
}

static void
free_someip_parameter_enum_cb(void*r) {
    someip_parameter_enum_uat_t *rec = (someip_parameter_enum_uat_t *)r;
    if (rec->name) {
        g_free(rec->name);
        rec->name = NULL;
    }

    if (rec->value_name) {
        g_free(rec->value_name);
        rec->value_name = NULL;
    }
}

static void
free_someip_parameter_enum(gpointer data) {
    someip_payload_parameter_enum_t *list = (someip_payload_parameter_enum_t *)data;

    if (list->items != NULL) {
        wmem_free(wmem_epan_scope(), (void *)(list->items));
        list->items = NULL;
    }

    wmem_free(wmem_epan_scope(), (void *)data);
}

static void
post_update_someip_parameter_enum_read_in_data(someip_parameter_enum_uat_t *data, guint data_num, GHashTable *ht) {
    guint                                   i = 0;
    guint                                   j = 0;
    gint64                                 *key = NULL;
    someip_payload_parameter_enum_t        *list = NULL;
    someip_payload_parameter_enum_item_t   *item = NULL;

    if (ht == NULL || data == NULL || data_num == 0) {
        return;
    }

    for (i = 0; i < data_num; i++) {
        key = wmem_new(wmem_epan_scope(), gint64);
        *key = data[i].id;

        list = (someip_payload_parameter_enum_t *)g_hash_table_lookup(ht, key);
        if (list == NULL) {

            list = wmem_new(wmem_epan_scope(), someip_payload_parameter_enum_t);
            INIT_SOMEIP_PAYLOAD_PARAMETER_ENUM(list)

            list->id           = data[i].id;
            list->name         = data[i].name;
            list->data_type    = data[i].data_type;
            list->id_ref       = data[i].id_ref;
            list->num_of_items = data[i].num_of_items;

            list->items = (someip_payload_parameter_enum_item_t *)wmem_alloc0_array(wmem_epan_scope(), someip_payload_parameter_enum_item_t, list->num_of_items);

            /* create new entry ... */
            g_hash_table_insert(ht, key, list);
        } else {
            /* don't need it anymore */
            wmem_free(wmem_epan_scope(), key);
        }

        /* and now we add to item array */
        if (list->num_of_items > 0 && data[i].num_of_items == list->num_of_items) {

            /* find first empty slot */
            for (j = 0; j < list->num_of_items && list->items[j].name != NULL; j++);

            if (j < list->num_of_items) {
                item = &(list->items[j]);
                INIT_SOMEIP_PAYLOAD_PARAMETER_ENUM_ITEM(item)

                /* we do not care if we overwrite param */
                item->value = data[i].value;
                item->name  = data[i].value_name;
            }
        }
    }
}

static void
reset_someip_parameter_enum_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_parameter_enums) {
        g_hash_table_destroy(data_someip_parameter_enums);
        data_someip_parameter_enums = NULL;
    }
}

static void
post_update_someip_parameter_enum_cb(void) {
    reset_someip_parameter_enum_cb();

    data_someip_parameter_enums = g_hash_table_new_full(g_int64_hash, g_int64_equal, &someip_payload_free_key, &free_someip_parameter_enum);
    post_update_someip_parameter_enum_read_in_data(someip_parameter_enums, someip_parameter_enums_num, data_someip_parameter_enums);
}

UAT_HEX_CB_DEF(someip_parameter_arrays, id, someip_parameter_array_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_arrays, name, someip_parameter_array_uat_t)
UAT_DEC_CB_DEF(someip_parameter_arrays, data_type, someip_parameter_array_uat_t)
UAT_HEX_CB_DEF(someip_parameter_arrays, id_ref, someip_parameter_array_uat_t)
UAT_DEC_CB_DEF(someip_parameter_arrays, num_of_dims, someip_parameter_array_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_arrays, filter_string, someip_parameter_array_uat_t)

UAT_DEC_CB_DEF(someip_parameter_arrays, num, someip_parameter_array_uat_t)
UAT_DEC_CB_DEF(someip_parameter_arrays, lower_limit, someip_parameter_array_uat_t)
UAT_DEC_CB_DEF(someip_parameter_arrays, upper_limit, someip_parameter_array_uat_t)
UAT_DEC_CB_DEF(someip_parameter_arrays, length_of_length, someip_parameter_array_uat_t)
UAT_DEC_CB_DEF(someip_parameter_arrays, pad_to, someip_parameter_array_uat_t)

static void *
copy_someip_parameter_array_cb(void *n, const void *o, size_t size _U_) {
    someip_parameter_array_uat_t       *new_rec = (someip_parameter_array_uat_t *)n;
    const someip_parameter_array_uat_t *old_rec = (const someip_parameter_array_uat_t *)o;

    new_rec->id = old_rec->id;
    if (old_rec->name) {
        new_rec->name = g_strdup(old_rec->name);
    } else {
        new_rec->name = NULL;
    }
    new_rec->data_type = old_rec->data_type;
    new_rec->id_ref = old_rec->id_ref;
    new_rec->num_of_dims = old_rec->num_of_dims;
    if (old_rec->filter_string) {
        new_rec->filter_string = g_strdup(old_rec->filter_string);
    } else {
        new_rec->filter_string = NULL;
    }

    new_rec->num              = old_rec->num;
    new_rec->lower_limit      = old_rec->lower_limit;
    new_rec->upper_limit      = old_rec->upper_limit;
    new_rec->length_of_length = old_rec->length_of_length;
    new_rec->pad_to           = old_rec->pad_to;

    return new_rec;
}

static bool
update_someip_parameter_array(void *r, char **err) {
    someip_parameter_array_uat_t *rec = (someip_parameter_array_uat_t *)r;
    char                         *tmp;

    if (rec->name == NULL || rec->name[0] == 0) {
        *err = ws_strdup_printf("Name cannot be empty (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    if (rec->num >= rec->num_of_dims) {
        *err = ws_strdup_printf("Dimension >= Number of Dimensions (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    if (rec->filter_string == NULL || rec->filter_string[0] == 0) {
        *err = ws_strdup_printf("Filter String cannot be empty (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    tmp = check_filter_string(rec->filter_string, rec->id);
    if (tmp != NULL) {
        *err = tmp;
        return FALSE;
    }

    if (rec->data_type == SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_ARRAY && rec->id == rec->id_ref) {
        *err = ws_strdup_printf("An array cannot include itself (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    return TRUE;
}

static void
free_someip_parameter_array_cb(void*r) {
    someip_parameter_array_uat_t *rec = (someip_parameter_array_uat_t *)r;

    if (rec->name) g_free(rec->name);
    rec->name = NULL;

    if (rec->filter_string) g_free(rec->filter_string);
    rec->filter_string = NULL;
}

static void
free_someip_parameter_array(gpointer data) {
    someip_parameter_array_t *list = (someip_parameter_array_t *)data;

    if (list->dims != NULL) {
        wmem_free(wmem_epan_scope(), (void *)(list->dims));
        list->dims = NULL;
    }

    wmem_free(wmem_epan_scope(), (void *)data);
}

static void
post_update_someip_parameter_array_read_in_data(someip_parameter_array_uat_t *data, guint data_num, GHashTable *ht) {
    guint                            i = 0;
    gint64                          *key = NULL;
    someip_parameter_array_t        *list = NULL;
    someip_parameter_array_dim_t    *item = NULL;
    someip_parameter_array_dim_t    *items = NULL;

    if (ht == NULL || data == NULL || data_num == 0) {
        return;
    }

    for (i = 0; i < data_num; i++) {
        key = wmem_new(wmem_epan_scope(), gint64);
        *key = data[i].id;

        list = (someip_parameter_array_t *)g_hash_table_lookup(ht, key);
        if (list == NULL) {

            list = wmem_new(wmem_epan_scope(), someip_parameter_array_t);

            list->id            = data[i].id;
            list->name          = data[i].name;
            list->data_type     = data[i].data_type;
            list->id_ref        = data[i].id_ref;
            list->num_of_dims   = data[i].num_of_dims;
            list->filter_string = data[i].filter_string;

            items = (someip_parameter_array_dim_t *)wmem_alloc0_array(wmem_epan_scope(), someip_parameter_array_dim_t, data[i].num_of_dims);
            list->dims = items;

            /* create new entry ... */
            g_hash_table_insert(ht, key, list);
        }

        /* and now we add to item array */
        if (data[i].num_of_dims == list->num_of_dims && data[i].num < list->num_of_dims) {
            item = &(list->dims[data[i].num]);

            /* we do not care if we overwrite param */
            item->num              = data[i].num;
            item->lower_limit      = data[i].lower_limit;
            item->upper_limit      = data[i].upper_limit;
            item->length_of_length = data[i].length_of_length;
            item->pad_to           = data[i].pad_to;
        }
    }
}

static void
post_update_someip_parameter_array_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_parameter_arrays) {
        g_hash_table_destroy(data_someip_parameter_arrays);
        data_someip_parameter_arrays = NULL;
    }

    data_someip_parameter_arrays = g_hash_table_new_full(g_int64_hash, g_int64_equal, &someip_payload_free_key, &free_someip_parameter_array);
    post_update_someip_parameter_array_read_in_data(someip_parameter_arrays, someip_parameter_arrays_num, data_someip_parameter_arrays);
    update_dynamic_hf_entries_someip_parameter_arrays();
}

static void
reset_someip_parameter_array_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_parameter_arrays) {
        g_hash_table_destroy(data_someip_parameter_arrays);
        data_someip_parameter_arrays = NULL;
    }
}

UAT_HEX_CB_DEF(someip_parameter_structs, id, someip_parameter_struct_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_structs, struct_name, someip_parameter_struct_uat_t)
UAT_DEC_CB_DEF(someip_parameter_structs, length_of_length, someip_parameter_struct_uat_t)
UAT_DEC_CB_DEF(someip_parameter_structs, pad_to, someip_parameter_struct_uat_t)
UAT_BOOL_CB_DEF(someip_parameter_structs, wtlv_encoding, someip_parameter_struct_uat_t)
UAT_DEC_CB_DEF(someip_parameter_structs, num_of_items, someip_parameter_struct_uat_t)

UAT_DEC_CB_DEF(someip_parameter_structs, pos, someip_parameter_struct_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_structs, name, someip_parameter_struct_uat_t)
UAT_DEC_CB_DEF(someip_parameter_structs, data_type, someip_parameter_struct_uat_t)
UAT_HEX_CB_DEF(someip_parameter_structs, id_ref, someip_parameter_struct_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_structs, filter_string, someip_parameter_struct_uat_t)

static void *
copy_someip_parameter_struct_cb(void *n, const void *o, size_t size _U_) {
    someip_parameter_struct_uat_t       *new_rec = (someip_parameter_struct_uat_t *)n;
    const someip_parameter_struct_uat_t *old_rec = (const someip_parameter_struct_uat_t *)o;

    new_rec->id = old_rec->id;

    if (old_rec->struct_name) {
        new_rec->struct_name = g_strdup(old_rec->struct_name);
    } else {
        new_rec->struct_name = NULL;
    }

    new_rec->length_of_length = old_rec->length_of_length;
    new_rec->pad_to           = old_rec->pad_to;
    new_rec->wtlv_encoding    = old_rec->wtlv_encoding;
    new_rec->num_of_items     = old_rec->num_of_items;

    new_rec->pos = old_rec->pos;

    if (old_rec->name) {
        new_rec->name = g_strdup(old_rec->name);
    } else {
        new_rec->name = NULL;
    }

    new_rec->data_type = old_rec->data_type;
    new_rec->id_ref    = old_rec->id_ref;

    if (old_rec->filter_string) {
        new_rec->filter_string = g_strdup(old_rec->filter_string);
    } else {
        new_rec->filter_string = NULL;
    }

    return new_rec;
}

static bool
update_someip_parameter_struct(void *r, char **err) {
    someip_parameter_struct_uat_t *rec = (someip_parameter_struct_uat_t *)r;
    char                          *tmp = NULL;

    if (rec->struct_name == NULL || rec->struct_name[0] == 0) {
        *err = ws_strdup_printf("Struct name cannot be empty (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    if (rec->filter_string == NULL || rec->filter_string[0] == 0) {
        *err = ws_strdup_printf("Struct name cannot be empty (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    tmp = check_filter_string(rec->filter_string, rec->id);
    if (tmp != NULL) {
        *err = tmp;
        return FALSE;
    }

    if (rec->name == NULL || rec->name[0] == 0) {
        *err = ws_strdup_printf("Name cannot be empty (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    if (rec->pos >= rec->num_of_items) {
        *err = ws_strdup_printf("Position >= Number of Parameters (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    if (rec->data_type == SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_STRUCT && rec->id == rec->id_ref) {
        *err = ws_strdup_printf("A struct cannot include itself (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    return TRUE;
}

static void
free_someip_parameter_struct_cb(void *r) {
    someip_parameter_struct_uat_t *rec = (someip_parameter_struct_uat_t *)r;

    if (rec->struct_name) g_free(rec->struct_name);
    rec->struct_name = NULL;

    if (rec->name) g_free(rec->name);
    rec->name = NULL;

    if (rec->filter_string) g_free(rec->filter_string);
    rec->filter_string = NULL;
}

static void
free_someip_parameter_struct(gpointer data) {
    someip_payload_parameter_struct_t *list = (someip_payload_parameter_struct_t *)data;

    if (list->items != NULL) {
        wmem_free(wmem_epan_scope(), (void *)(list->items));
        list->items = NULL;
    }

    wmem_free(wmem_epan_scope(), (void *)data);
}

static void
post_update_someip_parameter_struct_read_in_data(someip_parameter_struct_uat_t *data, guint data_num, GHashTable *ht) {
    guint                               i = 0;
    gint64                             *key = NULL;
    someip_payload_parameter_struct_t  *list = NULL;
    someip_payload_parameter_item_t    *item = NULL;
    someip_payload_parameter_item_t    *items = NULL;

    if (ht == NULL || data == NULL || data_num == 0) {
        return;
    }

    for (i = 0; i < data_num; i++) {
        key = wmem_new(wmem_epan_scope(), gint64);
        *key = data[i].id;

        list = (someip_payload_parameter_struct_t *)g_hash_table_lookup(ht, key);
        if (list == NULL) {
            list = wmem_new(wmem_epan_scope(), someip_payload_parameter_struct_t);
            INIT_SOMEIP_PAYLOAD_PARAMETER_STRUCT(list)

            list->id               = data[i].id;
            list->struct_name      = data[i].struct_name;
            list->length_of_length = data[i].length_of_length;
            list->pad_to           = data[i].pad_to;
            list->wtlv_encoding    = data[i].wtlv_encoding;
            list->num_of_items     = data[i].num_of_items;

            items = (someip_payload_parameter_item_t *)wmem_alloc0_array(wmem_epan_scope(), someip_payload_parameter_item_t, data[i].num_of_items);
            list->items = items;

            /* create new entry ... */
            g_hash_table_insert(ht, key, list);
        }

        /* and now we add to item array */
        if (data[i].num_of_items == list->num_of_items && data[i].pos < list->num_of_items) {
            item = &(list->items[data[i].pos]);
            INIT_SOMEIP_PAYLOAD_PARAMETER_ITEM(item)

            /* we do not care if we overwrite param */
            item->name          = data[i].name;
            item->id_ref        = data[i].id_ref;
            item->pos           = data[i].pos;
            item->data_type     = data[i].data_type;
            item->filter_string = data[i].filter_string;
        }
    }
}

static void
post_update_someip_parameter_struct_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_parameter_structs) {
        g_hash_table_destroy(data_someip_parameter_structs);
        data_someip_parameter_structs = NULL;
    }

    data_someip_parameter_structs = g_hash_table_new_full(g_int64_hash, g_int64_equal, &someip_payload_free_key, &free_someip_parameter_struct);
    post_update_someip_parameter_struct_read_in_data(someip_parameter_structs, someip_parameter_structs_num, data_someip_parameter_structs);
    update_dynamic_hf_entries_someip_parameter_structs();
}

static void
reset_someip_parameter_struct_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_parameter_structs) {
        g_hash_table_destroy(data_someip_parameter_structs);
        data_someip_parameter_structs = NULL;
    }
}

UAT_HEX_CB_DEF(someip_parameter_unions, id, someip_parameter_union_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_unions, name, someip_parameter_union_uat_t)
UAT_DEC_CB_DEF(someip_parameter_unions, length_of_length, someip_parameter_union_uat_t)
UAT_DEC_CB_DEF(someip_parameter_unions, length_of_type, someip_parameter_union_uat_t)
UAT_DEC_CB_DEF(someip_parameter_unions, pad_to, someip_parameter_union_uat_t)

UAT_DEC_CB_DEF(someip_parameter_unions, num_of_items, someip_parameter_union_uat_t)

UAT_DEC_CB_DEF(someip_parameter_unions, type_id, someip_parameter_union_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_unions, type_name, someip_parameter_union_uat_t)
UAT_DEC_CB_DEF(someip_parameter_unions, data_type, someip_parameter_union_uat_t)
UAT_HEX_CB_DEF(someip_parameter_unions, id_ref, someip_parameter_union_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_unions, filter_string, someip_parameter_union_uat_t)

static void *
copy_someip_parameter_union_cb(void *n, const void *o, size_t size _U_) {
    someip_parameter_union_uat_t        *new_rec = (someip_parameter_union_uat_t *)n;
    const someip_parameter_union_uat_t  *old_rec = (const someip_parameter_union_uat_t *)o;

    new_rec->id = old_rec->id;

    if (old_rec->name) {
        new_rec->name = g_strdup(old_rec->name);
    } else {
        new_rec->name = NULL;
    }

    new_rec->length_of_length = old_rec->length_of_length;
    new_rec->length_of_type   = old_rec->length_of_type;
    new_rec->pad_to           = old_rec->pad_to;
    new_rec->num_of_items     = old_rec->num_of_items;
    new_rec->type_id          = old_rec->type_id;

    if (old_rec->type_name) {
        new_rec->type_name = g_strdup(old_rec->type_name);
    } else {
        new_rec->type_name = NULL;
    }

    new_rec->data_type        = old_rec->data_type;
    new_rec->id_ref           = old_rec->id_ref;

    if (old_rec->filter_string) {
        new_rec->filter_string = g_strdup(old_rec->filter_string);
    } else {
        new_rec->filter_string = NULL;
    }

    return new_rec;
}

static bool
update_someip_parameter_union(void *r, char **err) {
    someip_parameter_union_uat_t *rec = (someip_parameter_union_uat_t *)r;
    gchar                        *tmp;

    if (rec->name == NULL || rec->name[0] == 0) {
        *err = ws_strdup_printf("Union name cannot be empty (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    tmp = check_filter_string(rec->filter_string, rec->id);
    if (tmp != NULL) {
        *err = tmp;
        return FALSE;
    }

    if (rec->type_name == NULL || rec->type_name[0] == 0) {
        *err = ws_strdup_printf("Type Name cannot be empty (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    if (rec->data_type == SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_UNION && rec->id == rec->id_ref) {
        *err = ws_strdup_printf("A union cannot include itself (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    return TRUE;
}

static void
free_someip_parameter_union_cb(void*r) {
    someip_parameter_union_uat_t *rec = (someip_parameter_union_uat_t *)r;

    if (rec->name) {
        g_free(rec->name);
        rec->name = NULL;
    }

    if (rec->type_name) {
        g_free(rec->type_name);
        rec->type_name = NULL;
    }

    if (rec->filter_string) {
        g_free(rec->filter_string);
        rec->filter_string = NULL;
    }
}

static void
free_someip_parameter_union(gpointer data) {
    someip_parameter_union_t *list = (someip_parameter_union_t *)data;

    if (list->items != NULL) {
        wmem_free(wmem_epan_scope(), (void *)(list->items));
        list->items = NULL;
    }

    wmem_free(wmem_epan_scope(), (void *)data);
}

static void
post_update_someip_parameter_union_read_in_data(someip_parameter_union_uat_t *data, guint data_num, GHashTable *ht) {
    guint           i = 0;
    guint           j = 0;
    gint64         *key = NULL;
    someip_parameter_union_t       *list = NULL;
    someip_parameter_union_item_t  *item = NULL;

    if (ht == NULL || data == NULL || data_num == 0) {
        return;
    }

    for (i = 0; i < data_num; i++) {
        key = wmem_new(wmem_epan_scope(), gint64);
        *key = data[i].id;

        list = (someip_parameter_union_t *)g_hash_table_lookup(ht, key);
        if (list == NULL) {

            list = wmem_new(wmem_epan_scope(), someip_parameter_union_t);

            list->id               = data[i].id;
            list->name             = data[i].name;
            list->length_of_length = data[i].length_of_length;
            list->length_of_type   = data[i].length_of_type;
            list->pad_to           = data[i].pad_to;
            list->num_of_items     = data[i].num_of_items;

            list->items = (someip_parameter_union_item_t *)wmem_alloc0_array(wmem_epan_scope(), someip_parameter_union_item_t, list->num_of_items);

            /* create new entry ... */
            g_hash_table_insert(ht, key, list);
        } else {
            /* don't need it anymore */
            wmem_free(wmem_epan_scope(), key);
        }

        /* and now we add to item array */
        if (data[i].num_of_items == list->num_of_items) {

            /* find first empty slot */
            for (j = 0; j < list->num_of_items && list->items[j].name != NULL; j++);

            if (j < list->num_of_items) {
                item = &(list->items[j]);

                /* we do not care if we overwrite param */
                item->id            = data[i].type_id;
                item->name          = data[i].type_name;
                item->data_type     = data[i].data_type;
                item->id_ref        = data[i].id_ref;
                item->filter_string = data[i].filter_string;
            }
        }
    }
}

static void
reset_someip_parameter_union_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_parameter_unions) {
        g_hash_table_destroy(data_someip_parameter_unions);
        data_someip_parameter_unions = NULL;
    }
}

static void
post_update_someip_parameter_union_cb(void) {
    reset_someip_parameter_union_cb();

    data_someip_parameter_unions = g_hash_table_new_full(g_int64_hash, g_int64_equal, &someip_payload_free_key, &free_someip_parameter_union);
    post_update_someip_parameter_union_read_in_data(someip_parameter_unions, someip_parameter_unions_num, data_someip_parameter_unions);
    update_dynamic_hf_entries_someip_parameter_unions();
}

UAT_HEX_CB_DEF(someip_parameter_base_type_list, id, someip_parameter_base_type_list_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_base_type_list, name, someip_parameter_base_type_list_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_base_type_list, data_type, someip_parameter_base_type_list_uat_t)
UAT_BOOL_CB_DEF(someip_parameter_base_type_list, big_endian, someip_parameter_base_type_list_uat_t)
UAT_DEC_CB_DEF(someip_parameter_base_type_list, bitlength_base_type, someip_parameter_base_type_list_uat_t)
UAT_DEC_CB_DEF(someip_parameter_base_type_list, bitlength_encoded_type, someip_parameter_base_type_list_uat_t)

static void *
copy_someip_parameter_base_type_list_cb(void *n, const void *o, size_t size _U_) {
    someip_parameter_base_type_list_uat_t       *new_rec = (someip_parameter_base_type_list_uat_t *)n;
    const someip_parameter_base_type_list_uat_t *old_rec = (const someip_parameter_base_type_list_uat_t *)o;

    if (old_rec->name) {
        new_rec->name = g_strdup(old_rec->name);
    } else {
        new_rec->name = NULL;
    }

    if (old_rec->data_type) {
        new_rec->data_type = g_strdup(old_rec->data_type);
    } else {
        new_rec->data_type = NULL;
    }

    new_rec->id                     = old_rec->id;
    new_rec->big_endian             = old_rec->big_endian;
    new_rec->bitlength_base_type    = old_rec->bitlength_base_type;
    new_rec->bitlength_encoded_type = old_rec->bitlength_encoded_type;

    return new_rec;
}

static bool
update_someip_parameter_base_type_list(void *r, char **err) {
    someip_parameter_base_type_list_uat_t *rec = (someip_parameter_base_type_list_uat_t *)r;

    if (rec->name == NULL || rec->name[0] == 0) {
        *err = ws_strdup_printf("Name cannot be empty (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    if (rec->id > 0xffffffff) {
        *err = ws_strdup_printf("We currently only support 32 bit IDs (%i) Name: %s", rec->id, rec->name);
        return FALSE;
    }

    if (rec->bitlength_base_type != 8 && rec->bitlength_base_type != 16 && rec->bitlength_base_type != 32 && rec->bitlength_base_type != 64) {
        *err = ws_strdup_printf("Bit length of base type may only be 8, 16, 32, or 64. Affected item: ID (%i) Name (%s).", rec->id, rec->name);
        return FALSE;
    }

    /* As long as we check that rec->bitlength_base_type equals rec->bitlength_encoded_type, we do not have to check that bitlength_encoded_type is 8, 16, 32, or 64. */

    if (rec->bitlength_base_type != rec->bitlength_encoded_type) {
        *err = ws_strdup_printf("Bit length of encoded type must be equal to bit length of base type. Affected item: ID (%i) Name (%s). Shortened types supported by Signal-PDU dissector.", rec->id, rec->name);
        return FALSE;
    }

    return TRUE;
}

static void
free_someip_parameter_base_type_list_cb(void*r) {
    someip_parameter_base_type_list_uat_t *rec = (someip_parameter_base_type_list_uat_t *)r;

    if (rec->name) {
        g_free(rec->name);
        rec->name = NULL;
    }

    if (rec->data_type) {
        g_free(rec->data_type);
        rec->data_type = NULL;
    }
}

static void
reset_someip_parameter_base_type_list_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_parameter_base_type_list) {
        g_hash_table_destroy(data_someip_parameter_base_type_list);
        data_someip_parameter_base_type_list = NULL;
    }
}

static void
post_update_someip_parameter_base_type_list_cb(void) {
    guint   i;
    gint64 *key = NULL;

    reset_someip_parameter_base_type_list_cb();

    /* we don't need to free the data as long as we don't alloc it first */
    data_someip_parameter_base_type_list = g_hash_table_new_full(g_int64_hash, g_int64_equal, &someip_payload_free_key, NULL);

    if (data_someip_parameter_base_type_list == NULL || someip_parameter_base_type_list == NULL || someip_parameter_base_type_list_num == 0) {
        return;
    }

    if (someip_parameter_base_type_list_num > 0) {
        for (i = 0; i < someip_parameter_base_type_list_num; i++) {
            key = wmem_new(wmem_epan_scope(), gint64);
            *key = someip_parameter_base_type_list[i].id;

            g_hash_table_insert(data_someip_parameter_base_type_list, key, &someip_parameter_base_type_list[i]);
        }
    }
}

UAT_HEX_CB_DEF(someip_parameter_strings, id, someip_parameter_string_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_strings, name, someip_parameter_string_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_strings, encoding, someip_parameter_string_uat_t)
UAT_BOOL_CB_DEF(someip_parameter_strings, dynamic_length, someip_parameter_string_uat_t)
UAT_DEC_CB_DEF(someip_parameter_strings, max_length, someip_parameter_string_uat_t)
UAT_DEC_CB_DEF(someip_parameter_strings, length_of_length, someip_parameter_string_uat_t)
UAT_BOOL_CB_DEF(someip_parameter_strings, big_endian, someip_parameter_string_uat_t)
UAT_DEC_CB_DEF(someip_parameter_strings, pad_to, someip_parameter_string_uat_t)

static void *
copy_someip_parameter_string_list_cb(void *n, const void *o, size_t size _U_) {
    someip_parameter_string_uat_t       *new_rec = (someip_parameter_string_uat_t *)n;
    const someip_parameter_string_uat_t *old_rec = (const someip_parameter_string_uat_t *)o;

    if (old_rec->name) {
        new_rec->name = g_strdup(old_rec->name);
    } else {
        new_rec->name = NULL;
    }

    if (old_rec->encoding) {
        new_rec->encoding = g_strdup(old_rec->encoding);
    } else {
        new_rec->encoding = NULL;
    }

    new_rec->id               = old_rec->id;
    new_rec->dynamic_length   = old_rec->dynamic_length;
    new_rec->max_length       = old_rec->max_length;
    new_rec->length_of_length = old_rec->length_of_length;
    new_rec->big_endian       = old_rec->big_endian;
    new_rec->pad_to           = old_rec->pad_to;

    return new_rec;
}

static bool
update_someip_parameter_string_list(void *r, char **err) {
    someip_parameter_string_uat_t *rec = (someip_parameter_string_uat_t *)r;

    if (rec->name == NULL || rec->name[0] == 0) {
        *err = ws_strdup_printf("Name cannot be empty (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    if (rec->id > 0xffffffff) {
        *err = ws_strdup_printf("We currently only support 32 bit IDs (%i) Name: %s", rec->id, rec->name);
        return FALSE;
    }

    if (rec->max_length > 0xffffffff) {
        *err = ws_strdup_printf("We currently only support 32 bit max_length (%i) Name: %s", rec->max_length, rec->name);
        return FALSE;
    }

    if (rec->length_of_length != 0 && rec->length_of_length != 8 && rec->length_of_length != 16 && rec->length_of_length != 32) {
        *err = ws_strdup_printf("length_of_length can be only 0, 8, 16, or 32 but not %d (IDs: %i Name: %s)", rec->length_of_length, rec->id, rec->name);
        return FALSE;
    }

    return TRUE;
}

static void
free_someip_parameter_string_list_cb(void*r) {
    someip_parameter_string_uat_t *rec = (someip_parameter_string_uat_t *)r;

    if (rec->name) {
        g_free(rec->name);
        rec->name = NULL;
    }

    if (rec->encoding) {
        g_free(rec->encoding);
        rec->encoding = NULL;
    }
}

static void
reset_someip_parameter_string_list_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_parameter_strings) {
        g_hash_table_destroy(data_someip_parameter_strings);
        data_someip_parameter_strings = NULL;
    }
}

static void
post_update_someip_parameter_string_list_cb(void) {
    guint   i;
    gint64 *key = NULL;

    /* destroy old hash table, if it exists */
    if (data_someip_parameter_strings) {
        g_hash_table_destroy(data_someip_parameter_strings);
        data_someip_parameter_strings = NULL;
    }

    /* we don't need to free the data as long as we don't alloc it first */
    data_someip_parameter_strings = g_hash_table_new_full(g_int64_hash, g_int64_equal, &someip_payload_free_key, NULL);

    if (data_someip_parameter_strings == NULL || someip_parameter_strings == NULL || someip_parameter_strings_num == 0) {
        return;
    }

    if (someip_parameter_strings_num > 0) {
        for (i = 0; i < someip_parameter_strings_num; i++) {
            key = wmem_new(wmem_epan_scope(), gint64);
            *key = someip_parameter_strings[i].id;

            g_hash_table_insert(data_someip_parameter_strings, key, &someip_parameter_strings[i]);
        }
    }
}

UAT_HEX_CB_DEF(someip_parameter_typedefs, id, someip_parameter_typedef_uat_t)
UAT_CSTRING_CB_DEF(someip_parameter_typedefs, name, someip_parameter_typedef_uat_t)
UAT_DEC_CB_DEF(someip_parameter_typedefs, data_type, someip_parameter_typedef_uat_t)
UAT_HEX_CB_DEF(someip_parameter_typedefs, id_ref, someip_parameter_typedef_uat_t)

static void *
copy_someip_parameter_typedef_list_cb(void *n, const void *o, size_t size _U_) {
    someip_parameter_typedef_uat_t         *new_rec = (someip_parameter_typedef_uat_t *)n;
    const someip_parameter_typedef_uat_t   *old_rec = (const someip_parameter_typedef_uat_t *)o;

    if (old_rec->name) {
        new_rec->name = g_strdup(old_rec->name);
    } else {
        new_rec->name = NULL;
    }

    new_rec->id = old_rec->id;
    new_rec->data_type = old_rec->data_type;
    new_rec->id_ref = old_rec->id_ref;

    return new_rec;
}

static bool
update_someip_parameter_typedef_list(void *r, char **err) {
    someip_parameter_typedef_uat_t *rec = (someip_parameter_typedef_uat_t *)r;

    if (rec->id > 0xffffffff) {
        *err = ws_strdup_printf("We currently only support 32 bit IDs (%i) Name: %s", rec->id, rec->name);
        return FALSE;
    }

    if (rec->data_type == SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_TYPEDEF && rec->id == rec->id_ref) {
        *err = ws_strdup_printf("A typedef cannot reference itself (ID: 0x%x)!", rec->id);
        return FALSE;
    }

    return TRUE;
}

static void
free_someip_parameter_typedef_list_cb(void*r) {
    someip_parameter_typedef_uat_t *rec = (someip_parameter_typedef_uat_t *)r;

    if (rec->name) {
        g_free(rec->name);
        rec->name = NULL;
    }
}

static void
reset_someip_parameter_typedef_list_cb(void) {
    /* destroy old hash table, if it exists */
    if (data_someip_parameter_typedefs) {
        g_hash_table_destroy(data_someip_parameter_typedefs);
        data_someip_parameter_typedefs = NULL;
    }
}

static void
post_update_someip_parameter_typedef_list_cb(void) {
    guint   i;
    gint64 *key = NULL;

    reset_someip_parameter_typedef_list_cb();

    /* we don't need to free the data as long as we don't alloc it first */
    data_someip_parameter_typedefs = g_hash_table_new_full(g_int64_hash, g_int64_equal, &someip_payload_free_key, NULL);

    if (data_someip_parameter_typedefs == NULL || someip_parameter_typedefs == NULL || someip_parameter_typedefs_num == 0) {
        return;
    }

    if (someip_parameter_typedefs_num > 0) {
        for (i = 0; i < someip_parameter_typedefs_num; i++) {
            /* key: ID [32bit] */
            key = wmem_new(wmem_epan_scope(), gint64);
            *key = someip_parameter_typedefs[i].id;
            g_hash_table_insert(data_someip_parameter_typedefs, key, &someip_parameter_typedefs[i]);
        }
    }
}


static void
deregister_dynamic_hf_data(hf_register_info **hf_array, guint *hf_size) {
    if (*hf_array) {
        /* Unregister all fields used before */
        for (guint i = 0; i < *hf_size; i++) {
            if ((*hf_array)[i].p_id != NULL) {
                proto_deregister_field(proto_someip, *((*hf_array)[i].p_id));
                g_free((*hf_array)[i].p_id);
                (*hf_array)[i].p_id = NULL;
            }
        }
        proto_add_deregistered_data(*hf_array);
        *hf_array = NULL;
        *hf_size = 0;
    }
}

static void
allocate_dynamic_hf_data(hf_register_info **hf_array, guint *hf_size, guint new_size) {
    *hf_array = g_new0(hf_register_info, new_size);
    *hf_size = new_size;
}

typedef struct _param_return_attibutes_t {
    enum ftenum     type;
    int             display_base;
    gchar          *base_type_name;
} param_return_attributes_t;

static param_return_attributes_t
get_param_attributes(guint8 data_type, guint32 id_ref) {
    gint count = 10;

    param_return_attributes_t ret;
    ret.type = FT_NONE;
    ret.display_base = BASE_NONE;
    ret.base_type_name = NULL;

    /* we limit the number of typedef recursion to "count" */
    while (data_type == SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_TYPEDEF && count > 0) {
        someip_payload_parameter_typedef_t *tmp = get_typedef_config(id_ref);
        /* this should not be a typedef since we don't support recursion of typedefs */
        if (tmp != NULL) {
            data_type = tmp->data_type;
            id_ref = tmp->id_ref;
        }
        count--;
    }

    if (data_type == SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_ENUM) {
        someip_payload_parameter_enum_t *tmp = get_enum_config(id_ref);
        /* this can only be a base type ... */
        if (tmp != NULL) {
            data_type = tmp->data_type;
            id_ref = tmp->id_ref;
        }
    }

    if (data_type == SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_STRING) {
        someip_payload_parameter_string_t *tmp = get_string_config(id_ref);
        ret.type = FT_STRING;
        ret.display_base = BASE_NONE;
        if (tmp != NULL) {
            ret.base_type_name = tmp->name;
        }
        return ret;
    }

    if (data_type == SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_BASE_TYPE) {
        someip_payload_parameter_base_type_list_t *tmp = get_base_type_config(id_ref);

        ret.display_base = BASE_DEC;

        if (tmp != NULL) {
            ret.base_type_name = tmp->name;

            if (g_strcmp0(tmp->data_type, "uint8") == 0) {
                ret.type = FT_UINT8;
            } else if (g_strcmp0(tmp->data_type, "uint16") == 0) {
                ret.type = FT_UINT16;
            } else if (g_strcmp0(tmp->data_type, "uint24") == 0) {
                ret.type = FT_UINT24;
            } else if (g_strcmp0(tmp->data_type, "uint32") == 0) {
                ret.type = FT_UINT32;
            } else if (g_strcmp0(tmp->data_type, "uint40") == 0) {
                ret.type = FT_UINT40;
            } else if (g_strcmp0(tmp->data_type, "uint48") == 0) {
                ret.type = FT_UINT48;
            } else if (g_strcmp0(tmp->data_type, "uint56") == 0) {
                ret.type = FT_UINT56;
            } else if (g_strcmp0(tmp->data_type, "uint64") == 0) {
                ret.type = FT_UINT64;
            } else if (g_strcmp0(tmp->data_type, "int8") == 0) {
                ret.type = FT_INT8;
            } else if (g_strcmp0(tmp->data_type, "int16") == 0) {
                ret.type = FT_INT16;
            } else if (g_strcmp0(tmp->data_type, "int24") == 0) {
                ret.type = FT_INT24;
            } else if (g_strcmp0(tmp->data_type, "int32") == 0) {
                ret.type = FT_INT32;
            } else if (g_strcmp0(tmp->data_type, "int40") == 0) {
                ret.type = FT_INT40;
            } else if (g_strcmp0(tmp->data_type, "int48") == 0) {
                ret.type = FT_INT48;
            } else if (g_strcmp0(tmp->data_type, "int56") == 0) {
                ret.type = FT_INT56;
            } else if (g_strcmp0(tmp->data_type, "int64") == 0) {
                ret.type = FT_INT64;
            } else if (g_strcmp0(tmp->data_type, "float32") == 0) {
                ret.type = FT_FLOAT;
                ret.display_base = BASE_NONE;
            } else if (g_strcmp0(tmp->data_type, "float64") == 0) {
                ret.type = FT_DOUBLE;
                ret.display_base = BASE_NONE;
            } else {
                ret.type = FT_NONE;
            }
        } else {
            ret.type = FT_NONE;
        }
    }

    /* all other types are handled or don't need a type! */
    return ret;
}

static gint*
update_dynamic_hf_entry(hf_register_info *hf_array, int pos, guint32 data_type, guint id_ref, char *param_name, char *filter_string) {
    param_return_attributes_t   attribs;
    gint                       *hf_id;

    attribs = get_param_attributes(data_type, id_ref);
    if (hf_array == NULL || attribs.type == FT_NONE) {
        return NULL;
    }

    hf_id = g_new(gint, 1);
    *hf_id = -1;
    hf_array[pos].p_id = hf_id;

    hf_array[pos].hfinfo.strings = NULL;
    hf_array[pos].hfinfo.bitmask = 0;
    hf_array[pos].hfinfo.blurb   = NULL;

    if (attribs.base_type_name == NULL) {
        hf_array[pos].hfinfo.name = g_strdup(param_name);
    } else {
        hf_array[pos].hfinfo.name = ws_strdup_printf("%s [%s]", param_name, attribs.base_type_name);
    }

    hf_array[pos].hfinfo.abbrev = ws_strdup_printf("%s.%s", SOMEIP_NAME_PREFIX, filter_string);
    hf_array[pos].hfinfo.type = attribs.type;
    hf_array[pos].hfinfo.display = attribs.display_base;

    HFILL_INIT(hf_array[pos]);

    return hf_id;
}

static void
update_dynamic_param_hf_entry(gpointer key _U_, gpointer value, gpointer data) {
    guint32                    *pos = (guint32 *)data;
    someip_parameter_list_t    *list = (someip_parameter_list_t *)value;
    guint                       i = 0;

    for (i = 0; i < list->num_of_items ; i++) {
        if (*pos >= dynamic_hf_param_size) {
            return;
        }

        someip_payload_parameter_item_t *item = &(list->items[i]);

        item->hf_id = update_dynamic_hf_entry(dynamic_hf_param, *pos, item->data_type, item->id_ref, item->name, item->filter_string);

        if (item->hf_id != NULL) {
            (*pos)++;
        }
    }
}

static void
update_dynamic_array_hf_entry(gpointer key _U_, gpointer value, gpointer data) {
    guint32                    *pos = (guint32 *)data;
    someip_parameter_array_t   *item = (someip_parameter_array_t *)value;

    if (*pos >= dynamic_hf_array_size) {
        return;
    }

    item->hf_id = update_dynamic_hf_entry(dynamic_hf_array, *pos, item->data_type, item->id_ref, item->name, item->filter_string);

    if (item->hf_id != NULL) {
        (*pos)++;
    }
}

static void
update_dynamic_struct_hf_entry(gpointer key _U_, gpointer value, gpointer data) {
    guint32                            *pos = (guint32 *)data;
    someip_payload_parameter_struct_t  *list = (someip_payload_parameter_struct_t *)value;
    guint                               i = 0;

    for (i = 0; i < list->num_of_items; i++) {
        if (*pos >= dynamic_hf_struct_size) {
            return;
        }
        someip_payload_parameter_item_t *item = &(list->items[i]);

        item->hf_id = update_dynamic_hf_entry(dynamic_hf_struct, *pos, item->data_type, item->id_ref, item->name, item->filter_string);

        if (item->hf_id != NULL) {
            (*pos)++;
        }
    }
}

static void
update_dynamic_union_hf_entry(gpointer key _U_, gpointer value, gpointer data) {
    guint32                    *pos = (guint32 *)data;
    someip_parameter_union_t   *list = (someip_parameter_union_t *)value;
    guint                       i = 0;

    for (i = 0; i < list->num_of_items; i++) {
        if (*pos >= dynamic_hf_union_size) {
            return;
        }

        someip_parameter_union_item_t *item = &(list->items[i]);

        item->hf_id = update_dynamic_hf_entry(dynamic_hf_union, *pos, item->data_type, item->id_ref, item->name, item->filter_string);

        if (item->hf_id != NULL) {
            (*pos)++;
        }
    }
}

static void
update_dynamic_hf_entries_someip_parameter_list(void) {
    if (data_someip_parameter_list != NULL) {
        deregister_dynamic_hf_data(&dynamic_hf_param, &dynamic_hf_param_size);
        allocate_dynamic_hf_data(&dynamic_hf_param, &dynamic_hf_param_size, someip_parameter_list_num);
        guint32 pos = 0;
        g_hash_table_foreach(data_someip_parameter_list, update_dynamic_param_hf_entry, &pos);
        proto_register_field_array(proto_someip, dynamic_hf_param, pos);
    }
}

static void
update_dynamic_hf_entries_someip_parameter_arrays(void) {
    if (data_someip_parameter_arrays != NULL) {
        deregister_dynamic_hf_data(&dynamic_hf_array, &dynamic_hf_array_size);
        allocate_dynamic_hf_data(&dynamic_hf_array, &dynamic_hf_array_size, someip_parameter_arrays_num);
        guint32 pos = 0;
        g_hash_table_foreach(data_someip_parameter_arrays, update_dynamic_array_hf_entry, &pos);
        proto_register_field_array(proto_someip, dynamic_hf_array, pos);
    }
}

static void
update_dynamic_hf_entries_someip_parameter_structs(void) {
    if (data_someip_parameter_structs != NULL) {
        deregister_dynamic_hf_data(&dynamic_hf_struct, &dynamic_hf_struct_size);
        allocate_dynamic_hf_data(&dynamic_hf_struct, &dynamic_hf_struct_size, someip_parameter_structs_num);
        guint32 pos = 0;
        g_hash_table_foreach(data_someip_parameter_structs, update_dynamic_struct_hf_entry, &pos);
        proto_register_field_array(proto_someip, dynamic_hf_struct, pos);
    }
}

static void
update_dynamic_hf_entries_someip_parameter_unions(void) {
    if (data_someip_parameter_unions != NULL) {
        deregister_dynamic_hf_data(&dynamic_hf_union, &dynamic_hf_union_size);
        allocate_dynamic_hf_data(&dynamic_hf_union, &dynamic_hf_union_size, someip_parameter_unions_num);
        guint32 pos = 0;
        g_hash_table_foreach(data_someip_parameter_unions, update_dynamic_union_hf_entry, &pos);
        proto_register_field_array(proto_someip, dynamic_hf_union, pos);
    }
}

static void
expert_someip_payload_truncated(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, gint length) {
    proto_tree_add_expert(tree, pinfo, &ei_someip_payload_truncated, tvb, offset, length);
    col_append_str(pinfo->cinfo, COL_INFO, " [SOME/IP Payload: Truncated payload!]");
}

static void
expert_someip_payload_malformed(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, gint length) {
    proto_tree_add_expert(tree, pinfo, &ei_someip_payload_malformed, tvb, offset, length);
    col_append_str(pinfo->cinfo, COL_INFO, " [SOME/IP Payload: Malformed payload!]");
}

static void
expert_someip_payload_config_error(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, gint length, const char *message) {
    proto_tree_add_expert_format(tree, pinfo, &ei_someip_payload_config_error, tvb, offset, length, "SOME/IP Payload: %s", message);
    col_append_str(pinfo->cinfo, COL_INFO, " [SOME/IP Payload: Config Error]");
}

/*******************************************
 **************** Statistics ***************
 *******************************************/

static void
someip_messages_stats_tree_init(stats_tree *st) {
    st_node_ip_src = stats_tree_create_node(st, st_str_ip_src, 0, STAT_DT_INT, TRUE);
    stat_node_set_flags(st, st_str_ip_src, 0, FALSE, ST_FLG_SORT_TOP);
    st_node_ip_dst = stats_tree_create_node(st, st_str_ip_dst, 0, STAT_DT_INT, TRUE);
}

static tap_packet_status
someip_messages_stats_tree_packet(stats_tree *st, packet_info *pinfo, epan_dissect_t *edt _U_, const void *p, tap_flags_t flags _U_) {
    static gchar tmp_srv_str[128];
    static gchar tmp_meth_str[128];
    static gchar tmp_addr_str[128];
    int tmp;

    DISSECTOR_ASSERT(p);
    const someip_messages_tap_t *data = (const someip_messages_tap_t *)p;

    snprintf(tmp_addr_str, sizeof(tmp_addr_str) - 1, "%s (%s)", address_to_str(pinfo->pool, &pinfo->net_src), address_to_name(&pinfo->net_src));
    tick_stat_node(st, st_str_ip_src, 0, FALSE);
    int src_id = tick_stat_node(st, tmp_addr_str, st_node_ip_src, TRUE);

    snprintf(tmp_addr_str, sizeof(tmp_addr_str) - 1, "%s (%s)", address_to_str(pinfo->pool, &pinfo->net_dst), address_to_name(&pinfo->net_dst));
    tick_stat_node(st, st_str_ip_dst, 0, FALSE);
    int dst_id = tick_stat_node(st, tmp_addr_str, st_node_ip_dst, TRUE);

    char *service_name = someip_lookup_service_name(data->service_id);
    if (service_name == NULL) {
        snprintf(tmp_srv_str, sizeof(tmp_srv_str) - 1, "Service 0x%04x", data->service_id);
    } else {
        snprintf(tmp_srv_str, sizeof(tmp_srv_str) - 1, "Service 0x%04x (%s)", data->service_id, service_name);
    }

    char *method_name = someip_lookup_method_name(data->service_id, data->method_id);
    if (method_name == NULL) {
        snprintf(tmp_meth_str, sizeof(tmp_meth_str) - 1, "Method 0x%04x %s", data->method_id,
            val_to_str(data->message_type, someip_msg_type, "Message-Type: 0x%02x"));
    } else {
        snprintf(tmp_meth_str, sizeof(tmp_meth_str) - 1, "Method 0x%04x (%s) %s", data->method_id, method_name,
            val_to_str(data->message_type, someip_msg_type, "Message-Type: 0x%02x"));
    }

    tmp = tick_stat_node(st, tmp_srv_str, src_id, TRUE);
    tick_stat_node(st, tmp_meth_str, tmp, FALSE);
    tmp = tick_stat_node(st, tmp_srv_str, dst_id, TRUE);
    tick_stat_node(st, tmp_meth_str, tmp, FALSE);

    return TAP_PACKET_REDRAW;
}

/*******************************************
 ******** SOME/IP Payload Dissector ********
 *******************************************/

static int
dissect_someip_payload_parameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset, guint8 data_type, guint32 idref, gchar *name, int *hf_id_ptr, gint wtlv_offset);

static int
dissect_someip_payload_parameters(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset, someip_payload_parameter_item_t *items, guint32 num_of_items, gboolean wtlv);

/* add a flexible size length field, -1 for error*/
static gint64
dissect_someip_payload_length_field(tvbuff_t *tvb, packet_info *pinfo, proto_tree *subtree, gint offset, gint length_of_length_field) {
    proto_item *ti;
    guint32     tmp = 0;

    switch (length_of_length_field) {
    case 8:
        ti = proto_tree_add_item_ret_uint(subtree, hf_payload_length_field_8bit, tvb, offset, length_of_length_field / 8, ENC_NA, &tmp);
        proto_item_set_hidden(ti);
        break;
    case 16:
        ti = proto_tree_add_item_ret_uint(subtree, hf_payload_length_field_16bit, tvb, offset, length_of_length_field / 8, ENC_BIG_ENDIAN, &tmp);
        proto_item_set_hidden(ti);
        break;
    case 32:
        ti = proto_tree_add_item_ret_uint(subtree, hf_payload_length_field_32bit, tvb, offset, length_of_length_field / 8, ENC_BIG_ENDIAN, &tmp);
        proto_item_set_hidden(ti);
        break;
    default:
        proto_tree_add_expert_format(subtree, pinfo, &ei_someip_payload_config_error, tvb, offset, 0,
            "SOME/IP: Payload: length of length field does not make sense: %d bits", length_of_length_field);
        col_append_str(pinfo->cinfo, COL_INFO, " [SOME/IP: Payload Config Error]");
        return -1;
    }

    return (gint64)tmp;
}

/* add a flexible size type field */
static gint64
dissect_someip_payload_type_field(tvbuff_t *tvb, packet_info *pinfo, proto_tree *subtree, gint offset, gint length_of_type_field) {
    proto_item *ti;
    guint32     tmp = 0;

    switch (length_of_type_field) {
    case 8:
        ti = proto_tree_add_item_ret_uint(subtree, hf_payload_type_field_8bit, tvb, offset, length_of_type_field / 8, ENC_NA, &tmp);
        proto_item_set_hidden(ti);
        break;
    case 16:
        ti = proto_tree_add_item_ret_uint(subtree, hf_payload_type_field_16bit, tvb, offset, length_of_type_field / 8, ENC_BIG_ENDIAN, &tmp);
        proto_item_set_hidden(ti);
        break;
    case 32:
        ti = proto_tree_add_item_ret_uint(subtree, hf_payload_type_field_32bit, tvb, offset, length_of_type_field / 8, ENC_BIG_ENDIAN, &tmp);
        proto_item_set_hidden(ti);
        break;
    default:
        proto_tree_add_expert_format(subtree, pinfo, &ei_someip_payload_config_error, tvb, offset, 0,
            "SOME/IP: Payload: length of type field does not make sense: %d bits", length_of_type_field);
        col_append_str(pinfo->cinfo, COL_INFO, " [SOME/IP: Payload Config Error]");
        return -1;
    }

    return (gint64)tmp;
}

static guint32
dissect_someip_payload_add_wtlv_if_needed(tvbuff_t *tvb, packet_info *pinfo _U_, gint offset, proto_item *ti_root, proto_tree *parent_tree) {
    static int * const tag_bitfield[] = {
        &hf_payload_wtlv_tag_res,
        &hf_payload_wtlv_tag_wire_type,
        &hf_payload_wtlv_tag_data_id,
        NULL
    };

    if (offset < 0) {
        return 0;
    }

    proto_tree *tree = parent_tree;
    if (tree == NULL) {
        tree = proto_item_add_subtree(ti_root, ett_someip_parameter);
    }

    guint64 tagdata = 0;
    proto_item *ti = proto_tree_add_bitmask_ret_uint64(tree, tvb, offset, hf_payload_wtlv_tag, ett_someip_wtlv_tag, tag_bitfield, ENC_BIG_ENDIAN, &tagdata);
    proto_item_set_hidden(ti);

    guint wiretype = (guint)((tagdata & SOMEIP_WTLV_MASK_WIRE_TYPE) >> 12);

    switch (wiretype) {
    case 5:
        return 8;
    case 6:
        return 16;
    case 7:
        return 32;
    default:
        return 0;
    }
}

static gint
dissect_someip_payload_base_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, gint offset, guint8 data_type, guint32 id, gchar *name, int *hf_id_ptr, gint wtlv_offset) {
    someip_payload_parameter_base_type_list_t  *base_type = NULL;
    someip_payload_parameter_enum_t            *enum_config = NULL;

    guint32     basetype_id = 0;
    guint32     enum_id = 0;

    gint        param_length = -1;

    proto_item *ti = NULL;

    guint64     value = 0;
    guint32     value32 = 0;
    gboolean    value_set = FALSE;

    guint32     i = 0;
    gchar      *value_name = NULL;

    gboolean    big_endian = TRUE;

    int         hf_id = -1;

    if (hf_id_ptr != NULL) {
        hf_id = *hf_id_ptr;
    }

    switch (data_type) {
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_BASE_TYPE:
        basetype_id = id;
        break;
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_ENUM:
        enum_id = id;
        enum_config = get_enum_config(enum_id);
        if (enum_config == NULL) {
            return 0;
        }
        basetype_id = enum_config->id_ref;
        break;
    default:
        return 0;
    }

    base_type = get_base_type_config(basetype_id);
    if (base_type == NULL) {
        return 0;
    }

    big_endian = base_type->big_endian;
    param_length = (gint)((base_type->bitlength_base_type) / 8);

    if (param_length > tvb_captured_length_remaining(tvb, 0) - offset) {
        return 0;
    }

    if (hf_id > 0) {
        if (strncmp(base_type->data_type, "uint", 4) == 0) {
            if (base_type->bitlength_base_type > 32) {
                ti = proto_tree_add_item_ret_uint64(tree, hf_id, tvb, offset, param_length, big_endian ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN, &value);
            } else {
                ti = proto_tree_add_item_ret_uint(tree, hf_id, tvb, offset, param_length, big_endian ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN, &value32);
                value = (guint64)value32;
            }
            value_set = TRUE;
        } else {
            ti = proto_tree_add_item(tree, hf_id, tvb, offset, param_length, big_endian ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN);
        }
    } else {
        if (name == NULL) {
            ti = proto_tree_add_string_format(tree, hf_payload_str_base, tvb, offset, param_length, base_type->name, "[%s]", base_type->name);
        } else {
            ti = proto_tree_add_string_format(tree, hf_payload_str_base, tvb, offset, param_length, base_type->name, "%s [%s]", name, base_type->name);
        }
    }

    dissect_someip_payload_add_wtlv_if_needed(tvb, pinfo, wtlv_offset, ti, NULL);

    if (enum_config != NULL && value_set == TRUE) {
        for (i = 0; i < enum_config->num_of_items; i++) {
            if (enum_config->items[i].value == value) {
                value_name = enum_config->items[i].name;
                break;
            }
        }
        if (value_name != NULL) {
            proto_item_append_text(ti, " (%s)", value_name);
        }
    }

    return param_length;
}

static int
dissect_someip_payload_string(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset, guint32 id, gchar *name, int *hf_id_ptr, gint wtlv_offset) {
    someip_payload_parameter_string_t *config = NULL;

    guint8     *buf = NULL;
    guint32     i = 0;

    proto_item *ti = NULL;
    proto_tree *subtree = NULL;
    gint64      tmp = 0;
    guint32     length = 0;
    gint        offset_orig = offset;

    guint       str_encoding = 0;
    int         hf_id = hf_payload_str_string;

    if (hf_id_ptr != NULL) {
        hf_id = *hf_id_ptr;
    }

    config = get_string_config(id);

    if (config == NULL) {
        return 0;
    }

    if (wtlv_offset >= 0) {
        ti = proto_tree_add_string_format(tree, hf_id, tvb, wtlv_offset, 0, name, "%s [%s]", name, config->name);
    } else {
        ti = proto_tree_add_string_format(tree, hf_id, tvb, offset, 0, name, "%s [%s]", name, config->name);
    }

    subtree = proto_item_add_subtree(ti, ett_someip_string);
    guint32 length_of_length = dissect_someip_payload_add_wtlv_if_needed(tvb, pinfo, wtlv_offset, ti, NULL);

    /* WTLV length overrides configured length */
    if (config->length_of_length == 0 && length_of_length == 0) {
        length = config->max_length;
    } else {
        if (length_of_length == 0) {
            length_of_length = config->length_of_length;
        }

        if (tvb_captured_length_remaining(tvb, offset) < (gint)(length_of_length >> 3)) {
            expert_someip_payload_malformed(tree, pinfo, tvb, offset, 0);
            return 0;
        }

        tmp = dissect_someip_payload_length_field(tvb, pinfo, subtree, offset, length_of_length);
        if (tmp < 0) {
            /* error */
            return length_of_length / 8;
        }
        length = (guint32)tmp;
        offset += length_of_length / 8;
    }

    if ((guint32)tvb_captured_length_remaining(tvb, offset) < length) {
        expert_someip_payload_malformed(subtree, pinfo, tvb, offset, 0);
        return 0;
    }

    if (strcmp(config->encoding, "utf-8") == 0) {
        str_encoding = ENC_UTF_8 | ENC_NA;
    } else if (strcmp(config->encoding, "utf-16") == 0) {
        str_encoding = ENC_UTF_16 | (config->big_endian ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN);
    } else {
        str_encoding = ENC_ASCII | ENC_NA;
    }

    buf = tvb_get_string_enc(pinfo->pool, tvb, offset, length, str_encoding);

    /* sanitizing buffer */
    if (str_encoding & ENC_ASCII || str_encoding & ENC_UTF_8) {
        for (i = 0; i < length; i++) {
            if (buf[i] > 0x00 && buf[i] < 0x20) {
                buf[i] = 0x20;
            }
        }
    }

    proto_item_append_text(ti, ": %s", buf);
    offset += length;

    proto_item_set_end(ti, tvb, offset);

    return offset - offset_orig;
}

static int
dissect_someip_payload_struct(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset_orig, guint32 id, gchar *name, gint wtlv_offset) {
    someip_payload_parameter_struct_t *config = NULL;

    proto_tree *subtree = NULL;
    proto_item *ti = NULL;
    tvbuff_t   *subtvb = tvb;

    gint64      length = 0;
    gint        offset = offset_orig;

    config = get_struct_config(id);

    if (config == NULL || tree == NULL || tvb == NULL) {
        return 0;
    }

    if (wtlv_offset >= 0) {
        ti = proto_tree_add_string_format(tree, hf_payload_str_struct, tvb, wtlv_offset, 0, config->struct_name, "struct %s [%s]", name, config->struct_name);
    } else {
        ti = proto_tree_add_string_format(tree, hf_payload_str_struct, tvb, offset, 0, config->struct_name, "struct %s [%s]", name, config->struct_name);
    }

    subtree = proto_item_add_subtree(ti, ett_someip_struct);
    guint32 length_of_length = dissect_someip_payload_add_wtlv_if_needed(tvb, pinfo, wtlv_offset, ti, subtree);

    /* WTLV length overrides configured length */
    if (length_of_length == 0) {
        length_of_length = config->length_of_length;
    }

    if (tvb_captured_length_remaining(tvb, 0) < (gint)(length_of_length >> 3)) {
        expert_someip_payload_malformed(tree, pinfo, tvb, offset, 0);
        return 0;
    };

    if (length_of_length != 0) {
        length = dissect_someip_payload_length_field(tvb, pinfo, subtree, offset, length_of_length);
        if (length < 0) {
            /* error */
            return length_of_length / 8;
        }
        offset += length_of_length / 8;
        int endpos = offset_orig + (length_of_length / 8) + (guint32)length;
        proto_item_set_end(ti, tvb, endpos);
        subtvb = tvb_new_subset_length(tvb, 0, endpos);
    }

    offset += dissect_someip_payload_parameters(subtvb, pinfo, subtree, offset, config->items, config->num_of_items, config->wtlv_encoding);

    if (length_of_length == 0) {
        proto_item_set_end(ti, tvb, offset);

        return offset - offset_orig;
    } else {
        return (length_of_length / 8) + (guint32)length;
    }
}

static int
dissect_someip_payload_typedef(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset, guint32 id, gchar *name _U_, int *hf_id, gint wtlv_offset) {
    someip_payload_parameter_typedef_t *config = NULL;

    config = get_typedef_config(id);

    if (config == NULL) {
        return 0;
    }

    /* we basically skip over the typedef for now */
    return dissect_someip_payload_parameter(tvb, pinfo, tree, offset, (guint8)config->data_type, config->id_ref, config->name, hf_id, wtlv_offset);
}

/* returns bytes parsed, length needs to be gint to encode "non-existing" as -1 */
static int
dissect_someip_payload_array_dim_length(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset_orig, gint *length, gint *lower_limit, gint *upper_limit,
    someip_parameter_array_t *config, gint current_dim, guint32 length_of_length) {
    gint    offset = offset_orig;
    gint64  tmp = 0;

    *lower_limit = config->dims[current_dim].lower_limit;
    *upper_limit = config->dims[current_dim].upper_limit;

    /* length needs to be -1, if we do not have a dynamic length array */
    *length = -1;

    if (length_of_length == 0) {
        length_of_length = config->dims[current_dim].length_of_length;
    }
    if (length_of_length > 0) {
        /* we are filling the length with number of bytes we found in the packet */
        tmp = dissect_someip_payload_length_field(tvb, pinfo, tree, offset, length_of_length);
        if (tmp < 0) {
            /* leave *length = -1 */
            return length_of_length/8;
        }
        *length = (gint32)tmp;
        offset += length_of_length/8;
    } else {
        /* without a length field, the number of elements needs be fixed */
        if (config->dims[current_dim].lower_limit != config->dims[current_dim].upper_limit) {
            proto_tree_add_expert_format(tree, pinfo, &ei_someip_payload_static_array_min_not_max, tvb, offset_orig, 0,
                "Static array config with Min!=Max (%d, %d)", config->dims[current_dim].lower_limit, config->dims[current_dim].upper_limit);
            col_append_str(pinfo->cinfo, COL_INFO, " [SOME/IP Payload: Static array config with Min!=Max!]");

            return 0;
        }
    }

    return offset - offset_orig;
}

/* returns bytes parsed, length needs to be gint to encode "non-existing" as -1 */
static gint
dissect_someip_payload_array_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset_orig, gint length, gint lower_limit, gint upper_limit,
    someip_parameter_array_t *config) {
    tvbuff_t   *subtvb = NULL;
    guint32     offset = offset_orig;
    guint32     bytes_parsed = 0;
    guint32     ret = 0;
    gint        count = 0;

    if (length != -1) {
        if (length <= tvb_captured_length_remaining(tvb, offset)) {
            subtvb = tvb_new_subset_length(tvb, offset, length);
            /* created subtvb. so we set offset=0 */
            offset = 0;
        } else {
            expert_someip_payload_truncated(tree, pinfo, tvb, offset, tvb_captured_length_remaining(tvb, offset));
            return tvb_captured_length_remaining(tvb, offset);
        }
    } else {
        subtvb = tvb;
    }

    while ((length == -1 && count < upper_limit) || ((gint)offset < length)) {
        bytes_parsed = dissect_someip_payload_parameter(subtvb, pinfo, tree, offset, (guint8)config->data_type, config->id_ref, config->name, config->hf_id, -1);
        if (bytes_parsed == 0) {
            /* does this make sense? */
            return 1;
        }
        offset += bytes_parsed;
        count++;
    }

    if (count<lower_limit && count>upper_limit) {
        proto_tree_add_expert_format(tree, pinfo, &ei_someip_payload_dyn_array_not_within_limit, tvb, offset_orig, length,
            "Number of items (%d) outside limit %d-%d", count, lower_limit, upper_limit);
        col_append_str(pinfo->cinfo, COL_INFO, " [SOME/IP Payload: Dynamic array does not stay between Min and Max values]");
    }

    if (length != -1) {
        /* we created subtvb first and set offset to 0 */
        ret = offset;
    } else {
        ret = offset - offset_orig;
    }

    return ret;
}

static gint
dissect_someip_payload_array_dim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset_orig, gint length, gint lower_limit, gint upper_limit, someip_parameter_array_t *config, guint current_dim, gchar *name, guint32 length_of_length) {
    proto_item *ti = NULL;
    proto_tree *subtree = NULL;
    gint        sub_length = 0;
    gint        sub_lower_limit = 0;
    gint        sub_upper_limit = 0;
    gint        i = 0;

    gint        sub_offset = 0;
    gint        offset = offset_orig;

    if (config->num_of_dims == current_dim + 1) {
        /* only payload left. :) */
        offset += dissect_someip_payload_array_payload(tvb, pinfo, tree, offset, length, lower_limit, upper_limit, config);
    } else {
        if (length != -1) {
            while (offset < offset_orig + (gint)length) {
                sub_offset = offset;

                ti = proto_tree_add_string_format(tree, hf_payload_str_array, tvb, sub_offset, 0, name, "subarray (dim: %d, limit %d-%d)", current_dim + 1, sub_lower_limit, sub_upper_limit);
                subtree = proto_item_add_subtree(ti, ett_someip_array_dim);

                offset += dissect_someip_payload_array_dim_length(tvb, pinfo, subtree, offset, &sub_length, &sub_lower_limit, &sub_upper_limit, config, current_dim + 1, length_of_length);

                if (tvb_captured_length_remaining(tvb, offset) < (gint)sub_length) {
                    expert_someip_payload_truncated(subtree, pinfo, tvb, offset, tvb_captured_length_remaining(tvb, offset));
                    return 0;
                }

                offset += dissect_someip_payload_array_dim(tvb, pinfo, subtree, offset, sub_length, sub_lower_limit, sub_upper_limit, config, current_dim + 1, name, length_of_length);

                proto_item_set_end(ti, tvb, offset);
            }
        } else {
            /* Multi-dim static array */
            sub_lower_limit = config->dims[current_dim].lower_limit;
            sub_upper_limit = config->dims[current_dim].upper_limit;

            for (i = 0; i < upper_limit; i++) {
                offset += dissect_someip_payload_array_dim(tvb, pinfo, tree, offset, -1, sub_lower_limit, sub_upper_limit, config, current_dim + 1, name, length_of_length);
            }
        }
    }

    return offset - offset_orig;
}

static int
dissect_someip_payload_array(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset_orig, guint32 id, gchar *name, gint wtlv_offset) {
    someip_parameter_array_t *config = NULL;

    proto_tree *subtree;
    proto_item *ti = NULL;

    gint        offset = offset_orig;

    gint        length = 0;
    gint        size_of_length = 0;
    gint        lower_limit = 0;
    gint        upper_limit = 0;

    config = get_array_config(id);

    if (config == NULL) {
        return 0;
    }

    if (config->num_of_dims == 0 || config->dims == NULL) {
        expert_someip_payload_config_error(tree, pinfo, tvb, offset, 0, "Array config has not enough dimensions for this array!");
        return 0;
    }

    ti = proto_tree_add_string_format(tree, hf_payload_str_array, tvb, offset, 0, config->name, "array %s", name);
    subtree = proto_item_add_subtree(ti, ett_someip_array);
    guint32 length_of_length = dissect_someip_payload_add_wtlv_if_needed(tvb, pinfo, wtlv_offset, ti, subtree);

    offset += dissect_someip_payload_array_dim_length(tvb, pinfo, subtree, offset_orig, &length, &lower_limit, &upper_limit, config, 0, length_of_length);
    size_of_length = offset - offset_orig;

    if (length != -1) {
        proto_item_append_text(ti, " (elements limit: %d-%d)", lower_limit, upper_limit);
    } else {
         proto_item_append_text(ti, " (elements limit: %d)", upper_limit);
    }

    offset += dissect_someip_payload_array_dim(tvb, pinfo, subtree, offset, length, lower_limit, upper_limit, config, 0, name, length_of_length);

    proto_item_set_end(ti, tvb, offset);

    if (length >= 0) {
        /* length field present */
        return size_of_length + length;
    } else {
        /* We have no length field, so we return what has been parsed! */
        return offset - offset_orig;
    }
}

static int
dissect_someip_payload_union(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset_orig, guint32 id, gchar *name, gint wtlv_offset) {
    someip_parameter_union_t        *config = NULL;
    someip_parameter_union_item_t   *item = NULL;

    proto_item *ti = NULL;
    proto_tree *subtree = NULL;

    tvbuff_t   *subtvb;
    gint        buf_length = -1;

    gint64      tmp = 0;
    guint32     length = 0;
    guint32     type = 0;

    guint32     i = 0;

    gint        offset = offset_orig;

    config = get_union_config(id);
    buf_length = tvb_captured_length_remaining(tvb, 0);

    if (config == NULL) {
        expert_someip_payload_config_error(tree, pinfo, tvb, offset, 0, "Union ID not configured");
        return 0;
    }

    if (wtlv_offset >= 0) {
        ti = proto_tree_add_string_format(tree, hf_payload_str_union, tvb, wtlv_offset, 0, name, "union %s [%s]", name, config->name);
    } else {
        ti = proto_tree_add_string_format(tree, hf_payload_str_union, tvb, offset_orig, 0, name, "union %s [%s]", name, config->name);
    }

    subtree = proto_item_add_subtree(ti, ett_someip_union);
    guint32 length_of_length = dissect_someip_payload_add_wtlv_if_needed(tvb, pinfo, wtlv_offset, ti, subtree);

    if (length_of_length == 0) {
        length_of_length = config->length_of_length;
    }

    if ((length_of_length + config->length_of_type) / 8 > (guint)buf_length - offset) {
        expert_someip_payload_truncated(tree, pinfo, tvb, offset, tvb_captured_length_remaining(tvb, offset));
        return 0;
    }

    tmp = dissect_someip_payload_length_field(tvb, pinfo, subtree, offset_orig, length_of_length);
    if (tmp == -1) {
        return offset - offset_orig;
    } else {
        length = (guint32)tmp;
    }

    tmp = dissect_someip_payload_type_field(tvb, pinfo, subtree, offset_orig + length_of_length / 8, config->length_of_type);
    if (tmp == -1) {
        return offset - offset_orig;
    } else {
        type = (guint32)tmp;
    }

    offset += (length_of_length + config->length_of_type) / 8;
    proto_item_set_end(ti, tvb, offset + length);

    item = NULL;
    for (i = 0; i < config->num_of_items; i++) {
        if (config->items[i].id == type && config->items[i].name != NULL) {
            item = &(config->items[i]);
        }
    }

    if (item != NULL) {
        subtvb = tvb_new_subset_length(tvb, offset, length);
        dissect_someip_payload_parameter(subtvb, pinfo, subtree, 0, (guint8)item->data_type, item->id_ref, item->name, item->hf_id, -1);
    } else {
        expert_someip_payload_config_error(tree, pinfo, tvb, offset, 0, "Union type not configured");
    }

    return length + (config->length_of_type + length_of_length) / 8;
}

static int
dissect_someip_payload_parameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset, guint8 data_type, guint32 idref, gchar *name, int *hf_id_ptr, gint wtlv_offset) {
    gint bytes_parsed = 0;

    switch (data_type) {
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_TYPEDEF:
        bytes_parsed = dissect_someip_payload_typedef(tvb, pinfo, tree, offset, idref, name, hf_id_ptr, wtlv_offset);
        break;
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_BASE_TYPE:
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_ENUM:
        bytes_parsed = dissect_someip_payload_base_type(tvb, pinfo, tree, offset, data_type, idref, name, hf_id_ptr, wtlv_offset);
        break;
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_STRING:
        bytes_parsed = dissect_someip_payload_string(tvb, pinfo, tree, offset, idref, name, hf_id_ptr, wtlv_offset);
        break;
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_ARRAY:
        bytes_parsed = dissect_someip_payload_array(tvb, pinfo, tree, offset, idref, name, wtlv_offset);
        break;
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_STRUCT:
        bytes_parsed = dissect_someip_payload_struct(tvb, pinfo, tree, offset, idref, name, wtlv_offset);
        break;
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_UNION:
        bytes_parsed = dissect_someip_payload_union(tvb, pinfo, tree, offset, idref, name, wtlv_offset);
        break;
    default:
        proto_tree_add_expert_format(tree, pinfo, &ei_someip_payload_config_error, tvb, offset, 0,
            "SOME/IP: Payload: item->data_type (0x%x) unknown/not implemented yet! name: %s, id_ref: 0x%x",
            data_type, name, idref);
        col_append_str(pinfo->cinfo, COL_INFO, " [SOME/IP: Payload Config Error]");
        break;
    }

    return bytes_parsed;
}

/*
 * returns <0 for errors
 */
static int dissect_someip_payload_peek_length_of_length(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, gint length, someip_payload_parameter_item_t *item) {
    if (item == NULL) {
        return -1;
    }

    guint32 data_type = item->data_type;
    guint32 id_ref    = item->id_ref;

    /* a config error could cause an endless loop, so we limit the number of indirections with loop_limit */
    gint loop_limit = 255;
    while (data_type == SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_TYPEDEF && loop_limit > 0) {
        someip_payload_parameter_typedef_t *tmp = get_typedef_config(id_ref);
        data_type = tmp->data_type;
        id_ref = tmp->id_ref;
        loop_limit--;
    }

    someip_payload_parameter_string_t  *tmp_string_config;
    someip_parameter_array_t           *tmp_array_config;
    someip_payload_parameter_struct_t  *tmp_struct_config;
    someip_parameter_union_t           *tmp_union_config;

    switch (data_type) {
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_STRING:
        tmp_string_config = get_string_config(id_ref);
        if (tmp_string_config == NULL) {
            return -1;
        }

        return tmp_string_config->length_of_length;
        break;

    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_ARRAY:
        tmp_array_config = get_array_config(id_ref);
        if (tmp_array_config == NULL) {
            return -1;
        }

        if (tmp_array_config->num_of_dims < 1 || tmp_array_config->dims == NULL) {
            expert_someip_payload_config_error(tree, pinfo, tvb, offset, length, "array configuration does not support WTLV");
            return -1;
        }

        return tmp_array_config->dims[0].length_of_length;
        break;

    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_STRUCT:
        tmp_struct_config = get_struct_config(id_ref);
        if (tmp_struct_config == NULL) {
            return -1;
        }

        return tmp_struct_config->length_of_length;
        break;

    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_UNION:
        tmp_union_config = get_union_config(id_ref);
        if (tmp_union_config == NULL) {
            return -1;
        }

        return tmp_union_config->length_of_length;
        break;

    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_TYPEDEF:
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_BASE_TYPE:
    case SOMEIP_PAYLOAD_PARAMETER_DATA_TYPE_ENUM:
    default:
        /* This happends only if configuration or message are buggy. */
        return -2;
    }
}

static int
dissect_someip_payload_parameters(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset, someip_payload_parameter_item_t *items, guint32 num_of_items, gboolean wtlv) {
    someip_payload_parameter_item_t *item;

    gint      offset_orig = offset;

    if (items == NULL && !someip_deserializer_wtlv_default) {
        return 0;
    }

    if (wtlv) {
        while (tvb_captured_length_remaining(tvb, offset) >= 2) {
            guint64 tagdata = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
            guint wiretype = (tagdata & SOMEIP_WTLV_MASK_WIRE_TYPE) >> 12;
            guint param_id = tagdata & SOMEIP_WTLV_MASK_DATA_ID;
            offset += 2;

            if (param_id < num_of_items && items != NULL) {
                item = &(items[param_id]);
            } else {
                item = NULL;
            }

            guint param_length = 0;
            switch (wiretype) {

            /* fixed length type with just 1, 2, 4, or 8 byte length */
            case 0:
            case 1:
            case 2:
            case 3:
                param_length = 1 << wiretype;
                break;

            /* var length types like structs, strings, arrays, and unions */
            case 4:
                /* this type is deprecated and should not be used*/

                switch (dissect_someip_payload_peek_length_of_length(tree, pinfo, tvb, offset - 2, 0, item)) {
                case 8:
                    param_length = 1 + tvb_get_guint8(tvb, offset);
                    break;
                case 16:
                    param_length = 2 + tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
                    break;
                case 32:
                    param_length = 4 + tvb_get_guint32(tvb, offset, ENC_BIG_ENDIAN);
                    break;
                default:
                    expert_someip_payload_config_error(tree, pinfo, tvb, offset - 2, 2, "WTLV type 4 but datatype has not an appropriate length field configured");
                    return 8 * (offset - offset_orig);
                }
                break;

            case 5:
                param_length = 1 + tvb_get_guint8(tvb, offset);
                break;
            case 6:
                param_length = 2 + tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
                break;
            case 7:
                param_length = 4 + tvb_get_guint32(tvb, offset, ENC_BIG_ENDIAN);
                break;

            default:
                 /* unsupported Wire Type!*/
                expert_someip_payload_malformed(tree, pinfo, tvb, offset - 2, 2);
                break;
            }

            tvbuff_t *subtvb = tvb_new_subset_length(tvb, offset - 2, param_length + 2);
            if (item != NULL) {
                dissect_someip_payload_parameter(subtvb, pinfo, tree, 2, (guint8)item->data_type, item->id_ref, item->name, item->hf_id, 0);
            } else {
                proto_item *ti = proto_tree_add_item(tree, hf_payload_unparsed, subtvb, 2, param_length, ENC_NA);
                dissect_someip_payload_add_wtlv_if_needed(tvb, pinfo, offset - 2, ti, NULL);
            }
            offset += param_length;
        }
    } else {
        if (items == NULL) {
            return 0;
        }
        guint32 i;
        for (i = 0; i < num_of_items; i++) {
            item = &(items[i]);
            offset += dissect_someip_payload_parameter(tvb, pinfo, tree, offset, (guint8)item->data_type, item->id_ref, item->name, item->hf_id, -1);
        }
    }

    return offset - offset_orig;
}

static void
dissect_someip_payload(tvbuff_t* tvb, packet_info* pinfo, proto_item *ti, guint16 serviceid, guint16 methodid, guint8 version, guint8 msgtype) {
    someip_parameter_list_t* paramlist = NULL;

    gint        length = -1;
    gint        offset = 0;

    proto_tree *tree = NULL;

    length = tvb_captured_length_remaining(tvb, 0);
    tree = proto_item_add_subtree(ti, ett_someip_payload);
    paramlist = get_parameter_config(serviceid, methodid, version, msgtype);

    if (paramlist == NULL) {
        if (someip_deserializer_wtlv_default) {
            offset += dissect_someip_payload_parameters(tvb, pinfo, tree, offset, NULL, 0, TRUE);
        } else {
            return;
        }
    } else {
        offset += dissect_someip_payload_parameters(tvb, pinfo, tree, offset, paramlist->items, paramlist->num_of_items, paramlist->wtlv_encoding);
    }

    if (length > offset) {
        proto_tree_add_item(tree, hf_payload_unparsed, tvb, offset, length - (offset), ENC_NA);
    }
}

/***********************************
 ******** SOME/IP Dissector ********
 ***********************************/

static int
dissect_someip_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
    guint32         offset = 0;
    guint32         someip_messageid = 0;
    guint32         someip_serviceid = 0;
    guint32         someip_methodid = 0;
    guint32         someip_clientid = 0;
    guint32         someip_sessionid = 0;
    guint32         someip_length = 0;
    const gchar    *service_description = NULL;
    const gchar    *method_description = NULL;
    const gchar    *client_description = NULL;
    someip_info_t   someip_data = SOMEIP_INFO_T_INIT;

    guint32         someip_payload_length = 0;
    tvbuff_t       *subtvb = NULL;

    proto_item     *ti = NULL;
    proto_item     *ti_someip = NULL;
    proto_tree     *someip_tree = NULL;
    proto_tree     *msgtype_tree = NULL;

    guint32         protocol_version = 0;
    guint32         version = 0;
    guint32         msgtype = 0;
    gboolean        msgtype_ack = FALSE;
    gboolean        msgtype_tp = FALSE;
    guint32         retcode = 0;
    int             tmp = 0;

    gint            tvb_length = tvb_captured_length_remaining(tvb, offset);

    col_set_str(pinfo->cinfo, COL_PROTOCOL, SOMEIP_NAME);
    col_set_str(pinfo->cinfo, COL_INFO, SOMEIP_NAME_LONG);
    ti_someip = proto_tree_add_item(tree, proto_someip, tvb, offset, -1, ENC_NA);
    someip_tree = proto_item_add_subtree(ti_someip, ett_someip);

    /* we should never get called with less than 8 bytes */
    if (tvb_length < 8) {
        return tvb_length;
    }

    /* Message ID = Service ID + Method ID*/
    someip_messageid = tvb_get_ntohl(tvb, 0);
    ti = proto_tree_add_uint_format_value(someip_tree, hf_someip_messageid, tvb, offset, 4, someip_messageid, "0x%08x", someip_messageid);
    proto_item_set_hidden(ti);

    /* Service ID */
    ti = proto_tree_add_item_ret_uint(someip_tree, hf_someip_serviceid, tvb, offset, 2, ENC_BIG_ENDIAN, &someip_serviceid);
    someip_data.service_id = someip_serviceid;
    service_description = someip_lookup_service_name(someip_serviceid);
    if (service_description != NULL) {
        proto_item_append_text(ti, " (%s)", service_description);
        ti = proto_tree_add_string(someip_tree, hf_someip_servicename, tvb, offset, 2, service_description);
        proto_item_set_generated(ti);
        proto_item_set_hidden(ti);
    }
    offset += 2;

    /* Method ID */
    ti = proto_tree_add_item_ret_uint(someip_tree, hf_someip_methodid, tvb, offset, 2, ENC_BIG_ENDIAN, &someip_methodid);
    someip_data.method_id = someip_methodid;
    method_description = someip_lookup_method_name(someip_serviceid, someip_methodid);
    if (method_description != NULL) {
        proto_item_append_text(ti, " (%s)", method_description);
        ti = proto_tree_add_string(someip_tree, hf_someip_methodname , tvb, offset, 2, method_description);
        proto_item_set_generated(ti);
        proto_item_set_hidden(ti);
    }
    offset += 2;

    /* Length */
    proto_tree_add_item_ret_uint(someip_tree, hf_someip_length, tvb, offset, 4, ENC_BIG_ENDIAN, &someip_length);
    offset += 4;

    /* this checks if value of the header field */
    if (someip_length < 8) {
        expert_add_info_format(pinfo, ti_someip, &ei_someip_incomplete_headers, "%s", "SOME/IP length too short (<8 Bytes)!");
        return tvb_length;
    }

    /* Add some additional info to the Protocol line and the Info Column*/
    if (service_description == NULL) {
        col_add_fstr(pinfo->cinfo, COL_INFO, "%s (Service ID: 0x%04x, Method ID: 0x%04x, Length: %i)",
                     SOMEIP_NAME_LONG, someip_serviceid, someip_methodid, someip_length);
    } else if (method_description == NULL) {
        col_add_fstr(pinfo->cinfo, COL_INFO, "%s (Service ID: 0x%04x (%s), Method ID: 0x%04x, Length: %i)",
                     SOMEIP_NAME_LONG, someip_serviceid, service_description, someip_methodid, someip_length);
    } else {
        col_add_fstr(pinfo->cinfo, COL_INFO, "%s (Service ID: 0x%04x (%s), Method ID: 0x%04x (%s), Length: %i)",
                     SOMEIP_NAME_LONG, someip_serviceid, service_description, someip_methodid, method_description, someip_length);
    }
    proto_item_append_text(ti_someip, " (Service ID: 0x%04x, Method ID: 0x%04x, Length: %i)", someip_serviceid, someip_methodid, someip_length);

    /* check if we have bytes for the rest of the header */
    if (tvb_length < 0 || offset + 8 > (guint32)tvb_length) {
        expert_add_info_format(pinfo, ti_someip, &ei_someip_incomplete_headers, "%s", "SOME/IP not enough buffer bytes for header!");
        return tvb_length;
    }

    /* Client ID */
    ti = proto_tree_add_item_ret_uint(someip_tree, hf_someip_clientid, tvb, offset, 2, ENC_BIG_ENDIAN, &someip_clientid);
    someip_data.client_id = someip_clientid;
    client_description = someip_lookup_client_name(someip_serviceid, someip_clientid);
    if (client_description != NULL) {
        proto_item_append_text(ti, " (%s)", client_description);
        ti = proto_tree_add_string(someip_tree, hf_someip_clientname, tvb, offset, 2, client_description);
        proto_item_set_generated(ti);
        proto_item_set_hidden(ti);
    }
    offset += 2;

    /* Session ID */
    proto_tree_add_item_ret_uint(someip_tree, hf_someip_sessionid, tvb, offset, 2, ENC_BIG_ENDIAN, &someip_sessionid);
    someip_data.session_id = someip_sessionid;
    offset += 2;

    /* Protocol Version*/
    ti = proto_tree_add_item_ret_uint(someip_tree, hf_someip_protover, tvb, offset, 1, ENC_BIG_ENDIAN, &protocol_version);
    if (protocol_version!=SOMEIP_PROTOCOL_VERSION) {
        expert_add_info(pinfo, ti, &ei_someip_unknown_version);
    }
    offset += 1;

    /* Major Version of Service Interface */
    proto_tree_add_item_ret_uint(someip_tree, hf_someip_interface_ver, tvb, offset, 1, ENC_BIG_ENDIAN, &version);
    someip_data.major_version = version;
    offset += 1;

    /* Message Type */
    ti = proto_tree_add_item_ret_uint(someip_tree, hf_someip_messagetype, tvb, offset, 1, ENC_BIG_ENDIAN, &msgtype);
    someip_data.message_type = msgtype;
    msgtype_tree = proto_item_add_subtree(ti, ett_someip_msgtype);
    proto_tree_add_item_ret_boolean(msgtype_tree, hf_someip_messagetype_ack_flag, tvb, offset, 1, ENC_BIG_ENDIAN, &msgtype_ack);
    proto_tree_add_item_ret_boolean(msgtype_tree, hf_someip_messagetype_tp_flag, tvb, offset, 1, ENC_BIG_ENDIAN, &msgtype_tp);

    proto_item_append_text(ti, " (%s)", val_to_str_const((~SOMEIP_MSGTYPE_TP_MASK)&msgtype, someip_msg_type, "Unknown Message Type"));
    if (msgtype_tp) {
        proto_item_append_text(ti, " (%s)", SOMEIP_MSGTYPE_TP_STRING);
    }
    offset += 1;

    /* Return Code */
    ti = proto_tree_add_item_ret_uint(someip_tree, hf_someip_returncode, tvb, offset, 1, ENC_BIG_ENDIAN, &retcode);
    proto_item_append_text(ti, " (%s)", val_to_str_const(retcode, someip_return_code, "Unknown Return Code"));
    offset += 1;

    /* lets figure out what we have for the rest */
    if (((guint32)tvb_length >= (someip_length + 8)) ) {
        someip_payload_length = someip_length - SOMEIP_HDR_PART1_LEN;
    } else {
        someip_payload_length = tvb_length - SOMEIP_HDR_LEN;
        expert_add_info(pinfo, ti_someip, &ei_someip_message_truncated);
    }

    /* Is this a SOME/IP-TP segment? */
    if (msgtype_tp) {
        guint32         tp_offset = 0;
        gboolean        tp_more_segments = FALSE;
        gboolean        update_col_info = TRUE;
        fragment_head  *someip_tp_head = NULL;
        proto_tree     *tp_tree = NULL;

        ti = proto_tree_add_item(someip_tree, hf_someip_tp, tvb, offset, someip_payload_length, ENC_NA);
        tp_tree = proto_item_add_subtree(ti, ett_someip_tp);

        /* Unfortunately, with a bitmask set the value is always shifted and cannot be set directly. */
        proto_tree_add_item_ret_uint(tp_tree, hf_someip_tp_offset_encoded, tvb, offset, 4, ENC_BIG_ENDIAN, &tp_offset);
        tp_offset <<= 4;
        proto_tree_add_item(tp_tree, hf_someip_tp_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item_ret_boolean(tp_tree, hf_someip_tp_more_segments, tvb, offset, 4, ENC_BIG_ENDIAN, &tp_more_segments);
        ti = proto_tree_add_uint(tp_tree, hf_someip_tp_offset, tvb, offset, 4, tp_offset);
        PROTO_ITEM_SET_GENERATED(ti);
        offset += 4;

        proto_tree_add_item(tp_tree, hf_someip_payload, tvb, offset, someip_payload_length - SOMEIP_TP_HDR_LEN, ENC_NA);

        if (someip_tp_reassemble && tvb_bytes_exist(tvb, offset, someip_payload_length - SOMEIP_TP_HDR_LEN)) {
            someip_tp_head = fragment_add_check(&someip_tp_reassembly_table, tvb, offset, pinfo, 0,
                                                &someip_data, tp_offset, someip_payload_length - SOMEIP_TP_HDR_LEN, tp_more_segments);
            subtvb = process_reassembled_data(tvb, offset, pinfo, "Reassembled SOME/IP-TP Segment",
                     someip_tp_head, &someip_tp_frag_items, &update_col_info, someip_tree);
        }
    } else {
        subtvb = tvb_new_subset_length(tvb, SOMEIP_HDR_LEN, someip_payload_length);
    }

    if (subtvb != NULL) {
        /* TAP */
        if (have_tap_listener(tap_someip_messages)) {
            someip_messages_tap_t *stats_data = wmem_alloc(pinfo->pool, sizeof(someip_messages_tap_t));
            stats_data->service_id = (guint16)someip_serviceid;
            stats_data->method_id = (guint16)someip_methodid;
            stats_data->interface_version = (guint8)version;
            stats_data->message_type = (guint8)(~SOMEIP_MSGTYPE_TP_MASK) & msgtype;

            tap_queue_packet(tap_someip_messages, pinfo, stats_data);
        }

        tvb_length = tvb_captured_length_remaining(subtvb, 0);
        if (tvb_length > 0) {
            tmp = dissector_try_uint_new(someip_dissector_table, someip_messageid, subtvb, pinfo, tree, FALSE, &someip_data);

            /* if no subdissector was found, the generic payload dissector takes over. */
            if (tmp==0) {
                ti = proto_tree_add_item(someip_tree, hf_someip_payload, subtvb, 0, tvb_length, ENC_NA);

                if (someip_deserializer_activated) {
                    dissect_someip_payload(subtvb, pinfo, ti, (guint16)someip_serviceid, (guint16)someip_methodid, (guint8)version, (guint8)(~SOMEIP_MSGTYPE_TP_MASK)&msgtype);
                } else {
                    proto_tree* payload_dissection_disabled_info_sub_tree = proto_item_add_subtree(ti, ett_someip_payload);
                    proto_tree_add_text_internal(payload_dissection_disabled_info_sub_tree, subtvb, 0, tvb_length, "Dissection of payload is disabled. It can be enabled via protocol preferences.");
                }
            }
        }
    }

    return SOMEIP_HDR_LEN + someip_payload_length;
}

static guint
get_someip_message_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_) {
    return SOMEIP_HDR_PART1_LEN + (guint)tvb_get_ntohl(tvb, offset + 4);
}

static int
dissect_someip_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) {
    tcp_dissect_pdus(tvb, pinfo, tree, TRUE, SOMEIP_HDR_PART1_LEN, get_someip_message_len, dissect_someip_message, data);
    return tvb_reported_length(tvb);
}

static gboolean
could_this_be_dtls(tvbuff_t *tvb) {
    /* Headers compared
     *
     * Byte | SOME/IP     | DTLS
     * --------------------------------
     * 00   | Service ID  | Content Type
     * 01   | Service ID  | Version
     * 02   | Method ID   | Version
     * 03   | Method ID   | Epoch
     * 04   | Length      | Epoch
     * 05   | Length      | Sequence Counter
     * 06   | Length      | Sequence Counter
     * 07   | Length      | Sequence Counter
     * 08   | Client ID   | Sequence Counter
     * 09   | Client ID   | Sequence Counter
     * 10   | Session ID  | Sequence Counter
     * 11   | Session ID  | Length
     * 12   | SOME/IP Ver | Length
     * 13   | Iface Ver   | ...
     * 14   | Msg Type    | ...
     * 15   | Return Code | ...
     * 16   | ...         | ...
     */
    gint length = tvb_captured_length_remaining(tvb, 0);

    /* DTLS header is 13 bytes. */
    if (length < 13) {
        /* not sure what we have here ... */
        return false;
    }

    guint8 dtls_content_type = tvb_get_guint8(tvb, 0);
    guint16 dtls_version = tvb_get_guint16(tvb, 1, ENC_BIG_ENDIAN);
    guint16 dtls_length = tvb_get_guint16(tvb, 11, ENC_BIG_ENDIAN);

    gboolean dtls_possible = (20 <= dtls_content_type) && (dtls_content_type <= 63) &&
                             (0xfefc <= dtls_version) && (dtls_version <= 0xfeff) &&
                             ((guint32)length == (guint32)dtls_length + 13);

    if (dtls_possible && length < SOMEIP_HDR_LEN) {
        return true;
    }

    guint32 someip_length = tvb_get_guint32(tvb, 4, ENC_BIG_ENDIAN);
    guint8 someip_version = tvb_get_guint8(tvb, 12);

    /* typically this is 1500 bytes or less on UDP but being conservative */
    gboolean someip_possible = (someip_version == 1) && (8 <= someip_length) && (someip_length <= 65535) &&
                               ((guint32)length == someip_length + 8);

    return dtls_possible && !someip_possible;
}

static int
dissect_someip_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) {
    if (someip_detect_dtls && could_this_be_dtls(tvb)) {
        if (!PINFO_FD_VISITED(pinfo)) {
            dissector_add_uint("dtls.port", (guint16)pinfo->destport, someip_handle_udp);
        }

        if (dtls_handle != 0) {
            return call_dissector_with_data(dtls_handle, tvb, pinfo, tree, data);
        }
    }

    return udp_dissect_pdus(tvb, pinfo, tree, SOMEIP_HDR_PART1_LEN, NULL, get_someip_message_len, dissect_someip_message, data);
}

static gboolean
test_someip(packet_info *pinfo _U_, tvbuff_t *tvb, int offset _U_, void *data _U_) {
    if (tvb_captured_length(tvb) < SOMEIP_HDR_LEN) {
        return FALSE;
    }

    if (tvb_get_guint32(tvb, 4, ENC_BIG_ENDIAN) < 8) {
        return FALSE;
    }

    if ((tvb_get_guint8(tvb, 12)) != SOMEIP_PROTOCOL_VERSION) {
        return FALSE;
    }

    if (!try_val_to_str((tvb_get_guint8(tvb, 14) & ~SOMEIP_MSGTYPE_TP_MASK), someip_msg_type)) {
        return FALSE;
    }

    return TRUE;
}

static gboolean
dissect_some_ip_heur_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) {
    if (test_someip(pinfo, tvb, 0, data)) {
        tcp_dissect_pdus(tvb, pinfo, tree, TRUE, SOMEIP_HDR_PART1_LEN, get_someip_message_len, dissect_someip_message, data);
        return TRUE;
    }
    return FALSE;
}

static gboolean
dissect_some_ip_heur_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) {
    return (udp_dissect_pdus(tvb, pinfo, tree, SOMEIP_HDR_PART1_LEN, test_someip, get_someip_message_len, dissect_someip_message, data) != 0);
}

void
proto_register_someip(void) {
    module_t        *someip_module;
    expert_module_t *expert_module_someip;

    uat_t *someip_service_uat;
    uat_t *someip_method_uat;
    uat_t *someip_eventgroup_uat;
    uat_t *someip_client_uat;

    uat_t  *someip_parameter_base_type_list_uat;
    uat_t  *someip_parameter_strings_uat;
    uat_t  *someip_parameter_typedefs_uat;
    uat_t  *someip_parameter_list_uat;
    uat_t  *someip_parameter_arrays_uat;
    uat_t  *someip_parameter_structs_uat;
    uat_t  *someip_parameter_unions_uat;
    uat_t  *someip_parameter_enums_uat;

    /* data fields */
    static hf_register_info hf[] = {
        { &hf_someip_serviceid,
            { "Service ID", "someip.serviceid",
            FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_servicename,
            { "Service Name", "someip.servicename",
            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_methodid,
            { "Method ID", "someip.methodid",
            FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_methodname,
            { "Method Name", "someip.methodname",
            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_messageid,
            { "Message ID", "someip.messageid",
            FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_length,
            { "Length", "someip.length",
            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_clientid,
            { "Client ID", "someip.clientid",
            FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_clientname,
            { "Client Name", "someip.clientname",
            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_sessionid,
            { "Session ID", "someip.sessionid",
            FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_protover,
            { "SOME/IP Version", "someip.protoversion",
            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_interface_ver,
            { "Interface Version", "someip.interfaceversion",
            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_messagetype,
            { "Message Type", "someip.messagetype",
            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_messagetype_ack_flag,
            { "Message Type Ack Flag", "someip.messagetype.ack",
            FT_BOOLEAN, 8, NULL, SOMEIP_MSGTYPE_ACK_MASK, NULL, HFILL }},
        { &hf_someip_messagetype_tp_flag,
            { "Message Type TP Flag", "someip.messagetype.tp",
            FT_BOOLEAN, 8, NULL, SOMEIP_MSGTYPE_TP_MASK, NULL, HFILL }},
        { &hf_someip_returncode,
            { "Return Code", "someip.returncode",
            FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},

        { &hf_someip_payload,
            { "Payload", "someip.payload",
            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},

        { &hf_someip_tp,
            { "SOME/IP-TP", "someip.tp",
            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_tp_offset,
            { "Offset", "someip.tp.offset",
            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
        { &hf_someip_tp_offset_encoded,
            { "Encoded Offset", "someip.tp.offset_encoded",
            FT_UINT32, BASE_HEX, NULL, SOMEIP_TP_OFFSET_MASK, NULL, HFILL }},
        { &hf_someip_tp_flags,
            { "Flags", "someip.tp.flags",
            FT_UINT32, BASE_HEX, NULL, SOMEIP_TP_OFFSET_MASK_FLAGS, NULL, HFILL }},
        { &hf_someip_tp_reserved,
            { "Reserved", "someip.tp.flags.reserved",
            FT_UINT32, BASE_HEX, NULL, SOMEIP_TP_OFFSET_MASK_RESERVED, NULL, HFILL }},
        { &hf_someip_tp_more_segments,
            { "More Segments", "someip.tp.flags.more_segments",
            FT_BOOLEAN, 32, NULL, SOMEIP_TP_OFFSET_MASK_MORE_SEGMENTS, NULL, HFILL }},

        {&hf_someip_tp_fragments,
            {"SOME/IP-TP segments", "someip.tp.fragments",
            FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } },
        {&hf_someip_tp_fragment,
            {"SOME/IP-TP segment", "someip.tp.fragment",
            FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } },
        {&hf_someip_tp_fragment_overlap,
            {"SOME/IP-TP segment overlap", "someip.tp.fragment.overlap",
            FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } },
        {&hf_someip_tp_fragment_overlap_conflicts,
            {"SOME/IP-TP segment overlapping with conflicting data", "someip.tp.fragment.overlap.conflicts",
            FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } },
        {&hf_someip_tp_fragment_multiple_tails,
            {"SOME/IP-TP Message has multiple tail fragments", "someip.tp.fragment.multiple_tails",
            FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } },
        {&hf_someip_tp_fragment_too_long_fragment,
            {"SOME/IP-TP segment too long", "someip.tp.fragment.too_long_fragment",
            FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } },
        {&hf_someip_tp_fragment_error,
            {"SOME/IP-TP Message defragmentation error", "someip.tp.fragment.error",
            FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } },
        {&hf_someip_tp_fragment_count,
            {"SOME/IP-TP segment count", "someip.tp.fragment.count",
            FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL } },
        {&hf_someip_tp_reassembled_in,
            {"Reassembled in", "someip.tp.reassembled.in",
            FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } },
        {&hf_someip_tp_reassembled_length,
            {"Reassembled length", "someip.tp.reassembled.length",
            FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL } },

        {&hf_someip_tp_reassembled_data,
            {"Reassembled data", "someip.tp.reassembled.data",
            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },

        { &hf_payload_unparsed,
            { "Unparsed Payload", "someip.payload.unparsed",
            FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
        { &hf_payload_length_field_8bit,
            { "Length", "someip.payload.length",
            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_payload_length_field_16bit,
            { "Length", "someip.payload.length",
            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_payload_length_field_32bit,
            { "Length", "someip.payload.length",
            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_payload_type_field_8bit,
            { "Type", "someip.payload.type",
            FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_payload_type_field_16bit,
            { "Type", "someip.payload.type",
            FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_payload_type_field_32bit,
            { "Type", "someip.payload.type",
            FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },

        { &hf_payload_str_base, {
            "(base)", "someip.payload.base",
            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_payload_str_string, {
            "(string)", "someip.payload.string",
            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_payload_str_struct, {
            "(struct)", "someip.payload.struct",
            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_payload_str_array, {
            "(array)", "someip.payload.array",
            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_payload_str_union, {
            "(array)", "someip.payload.union",
            FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },

        { &hf_payload_wtlv_tag, {
            "WTLV-TAG", "someip.payload.wtlvtag",
            FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_payload_wtlv_tag_res, {
            "Reserved", "someip.payload.wtlvtag.res",
            FT_UINT16, BASE_DEC, NULL, SOMEIP_WTLV_MASK_RES, NULL, HFILL } },
        { &hf_payload_wtlv_tag_wire_type, {
            "Wire Type", "someip.payload.wtlvtag.wire_type",
            FT_UINT16, BASE_DEC, NULL, SOMEIP_WTLV_MASK_WIRE_TYPE, NULL, HFILL } },
        { &hf_payload_wtlv_tag_data_id, {
            "Data ID", "someip.payload.wtlvtag.data_id",
            FT_UINT16, BASE_DEC, NULL, SOMEIP_WTLV_MASK_DATA_ID, NULL, HFILL } },
    };

    static gint *ett[] = {
        &ett_someip,
        &ett_someip_msgtype,
        &ett_someip_tp,
        &ett_someip_tp_fragment,
        &ett_someip_tp_fragments,

        &ett_someip_payload,
        &ett_someip_string,
        &ett_someip_array,
        &ett_someip_array_dim,
        &ett_someip_struct,
        &ett_someip_union,

        &ett_someip_parameter,
        &ett_someip_wtlv_tag,
    };


    /* UATs for user_data fields */
    static uat_field_t someip_service_uat_fields[] = {
        UAT_FLD_HEX(someip_service_ident, id, "Service ID", "ID of the SOME/IP Service (16bit hex without leading 0x)"),
        UAT_FLD_CSTRING(someip_service_ident, name, "Service Name", "Name of the SOME/IP Service (string)"),
        UAT_END_FIELDS
    };

    static uat_field_t someip_method_uat_fields[] = {
        UAT_FLD_HEX(someip_method_ident, id, "Service ID", "ID of the SOME/IP Service (16bit hex without leading 0x)"),
        UAT_FLD_HEX(someip_method_ident, id2, "Methods ID", "ID of the SOME/IP Method/Event/Notifier (16bit hex without leading 0x)"),
        UAT_FLD_CSTRING(someip_method_ident, name, "Method Name", "Name of the SOME/IP Method/Event/Notifier (string)"),
        UAT_END_FIELDS
    };

    static uat_field_t someip_eventgroup_uat_fields[] = {
        UAT_FLD_HEX(someip_eventgroup_ident, id, "Service ID", "ID of the SOME/IP Service (16bit hex without leading 0x)"),
        UAT_FLD_HEX(someip_eventgroup_ident, id2, "Eventgroup ID", "ID of the SOME/IP Eventgroup (16bit hex without leading 0x)"),
        UAT_FLD_CSTRING(someip_eventgroup_ident, name, "Eventgroup Name", "Name of the SOME/IP Service (string)"),
        UAT_END_FIELDS
    };

    static uat_field_t someip_client_uat_fields[] = {
        UAT_FLD_HEX(someip_client_ident, id, "Service ID", "ID of the SOME/IP Service (16bit hex without leading 0x)"),
        UAT_FLD_HEX(someip_client_ident, id2, "Client ID", "ID of the SOME/IP Client (16bit hex without leading 0x)"),
        UAT_FLD_CSTRING(someip_client_ident, name, "Client Name", "Name of the SOME/IP Client (string)"),
        UAT_END_FIELDS
    };

    static uat_field_t someip_parameter_list_uat_fields[] = {
        UAT_FLD_HEX(someip_parameter_list, service_id,              "Service ID",               "ID of the SOME/IP Service (16bit hex without leading 0x)"),
        UAT_FLD_HEX(someip_parameter_list, method_id,               "Method ID",                "ID of the SOME/IP Method/Event/Notifier (16bit hex without leading 0x)"),
        UAT_FLD_DEC(someip_parameter_list, version,                 "Version",                  "Version of the SOME/IP Service (8bit dec)"),
        UAT_FLD_HEX(someip_parameter_list, message_type,            "Message Type",             "Message Type (8bit hex without leading 0x)"),
        UAT_FLD_BOOL(someip_parameter_list, wtlv_encoding,          "WTLV Extension?",          "SOME/IP is extended by Wiretag-Length-Value encoding for this parameter list (not pure SOME/IP)"),

        UAT_FLD_DEC(someip_parameter_list, num_of_params,           "Number of Parameters",     "Number of Parameters (16bit dec), needs to be larger than greatest Parameter Position/ID"),

        UAT_FLD_DEC(someip_parameter_list, pos,                     "Parameter Position/ID",    "Position or ID of parameter (16bit dec, starting with 0)"),
        UAT_FLD_CSTRING(someip_parameter_list, name,                "Parameter Name",           "Name of parameter (string)"),
        UAT_FLD_DEC(someip_parameter_list, data_type,               "Parameter Type",           "Type of parameter (1: base, 2: string, 3: array, 4: struct, 5: union, 6: typedef, 7: enum)"),
        UAT_FLD_HEX(someip_parameter_list, id_ref,                  "ID Reference",             "ID Reference (32bit hex)"),
        UAT_FLD_CSTRING(someip_parameter_list, filter_string,       "Filter String",            "Unique filter string that will be prepended with someip.payload. (string)"),
        UAT_END_FIELDS
    };

    static uat_field_t someip_parameter_array_uat_fields[] = {
        UAT_FLD_HEX(someip_parameter_arrays, id,                    "ID",                       "ID of SOME/IP array (32bit hex without leading 0x)"),
        UAT_FLD_CSTRING(someip_parameter_arrays, name,              "Array Name",               "Name of array"),
        UAT_FLD_DEC(someip_parameter_arrays, data_type,             "Parameter Type",           "Type of parameter (1: base, 2: string, 3: array, 4: struct, 5: union, 6: typedef, 7: enum)"),
        UAT_FLD_HEX(someip_parameter_arrays, id_ref,                "ID Reference",             "ID Reference (32bit hex)"),
        UAT_FLD_DEC(someip_parameter_arrays, num_of_dims,           "Number of Items",          "Number of Dimensions (16bit dec)"),
        UAT_FLD_CSTRING(someip_parameter_arrays, filter_string,     "Filter String",            "Unique filter string that will be prepended with someip.payload. (string)"),

        UAT_FLD_DEC(someip_parameter_arrays, num,                   "Dimension",                "Dimension (16bit dec, starting with 0)"),
        UAT_FLD_DEC(someip_parameter_arrays, lower_limit,           "Lower Limit",              "Dimension (32bit dec)"),
        UAT_FLD_DEC(someip_parameter_arrays, upper_limit,           "Upper Limit",              "Dimension (32bit dec)"),
        UAT_FLD_DEC(someip_parameter_arrays, length_of_length,      "Length of Length Field",   "Length of the arrays length field in bits (8bit dec)"),
        UAT_FLD_DEC(someip_parameter_arrays, pad_to,                "Pad to",                   "Padding pads to reach alignment (8bit dec)"),
        UAT_END_FIELDS
    };

    static uat_field_t someip_parameter_struct_uat_fields[] = {
        UAT_FLD_HEX(someip_parameter_structs, id,                   "ID",                       "ID of SOME/IP struct (32bit hex without leading 0x)"),
        UAT_FLD_CSTRING(someip_parameter_structs, struct_name,      "Struct Name",              "Name of struct"),
        UAT_FLD_DEC(someip_parameter_structs, length_of_length,     "Length of Length Field",   "Length of the structs length field in bits (8bit dec)"),
        UAT_FLD_DEC(someip_parameter_structs, pad_to,               "Pad to",                   "Padding pads to reach alignment (8bit dec)"),
        UAT_FLD_BOOL(someip_parameter_structs, wtlv_encoding,       "WTLV Extension?",          "SOME/IP is extended by Wiretag-Length-Value encoding for this struct (not pure SOME/IP)"),
        UAT_FLD_DEC(someip_parameter_structs, num_of_items,         "Number of Items",          "Number of Items (16bit dec)"),

        UAT_FLD_DEC(someip_parameter_structs, pos,                  "Parameter Position/ID",    "Position or ID of parameter (16bit dec, starting with 0)"),
        UAT_FLD_CSTRING(someip_parameter_structs, name,             "Parameter Name",           "Name of parameter (string)"),
        UAT_FLD_DEC(someip_parameter_structs, data_type,            "Parameter Type",           "Type of parameter (1: base, 2: string, 3: array, 4: struct, 5: union, 6: typedef, 7: enum)"),
        UAT_FLD_HEX(someip_parameter_structs, id_ref,               "ID Reference",             "ID Reference (32bit hex)"),
        UAT_FLD_CSTRING(someip_parameter_structs, filter_string,    "Filter String",            "Unique filter string that will be prepended with someip.payload. (string)"),
        UAT_END_FIELDS
    };

    static uat_field_t someip_parameter_union_uat_fields[] = {
        UAT_FLD_HEX(someip_parameter_unions, id,                    "ID",                       "ID of SOME/IP union (32bit hex without leading 0x)"),
        UAT_FLD_CSTRING(someip_parameter_unions, name,              "Union Name",               "Name of union"),
        UAT_FLD_DEC(someip_parameter_unions, length_of_length,      "Length of Length Field",   "Length of the unions length field in bits (uint8 dec)"),
        UAT_FLD_DEC(someip_parameter_unions, length_of_type,        "Length of Type Field",     "Length of the unions type field in bits (8bit dec)"),
        UAT_FLD_DEC(someip_parameter_unions, pad_to,                "Pad to",                   "Padding pads to reach alignment (8bit dec)"),

        UAT_FLD_DEC(someip_parameter_unions, num_of_items,          "Number of Items",          "Number of Items (32bit dec)"),

        UAT_FLD_DEC(someip_parameter_unions, type_id,               "Type ID",                  "ID of Type (32bit dec, starting with 0)"),
        UAT_FLD_CSTRING(someip_parameter_unions, type_name,         "Type Name",                "Name of Type (string)"),
        UAT_FLD_DEC(someip_parameter_unions, data_type,             "Data Type",                "Type of payload (1: base, 2: string, 3: array, 4: struct, 5: union, 6: typedef, 7: enum)"),
        UAT_FLD_HEX(someip_parameter_unions, id_ref,                "ID Reference",             "ID Reference (32bit hex)"),
        UAT_FLD_CSTRING(someip_parameter_unions, filter_string,     "Filter String",            "Unique filter string that will be prepended with someip.payload. (string)"),
        UAT_END_FIELDS
    };

    static uat_field_t someip_parameter_enum_uat_fields[] = {
        UAT_FLD_HEX(someip_parameter_enums, id,                     "ID",                       "ID of SOME/IP enum (32bit hex without leading 0x)"),
        UAT_FLD_CSTRING(someip_parameter_enums, name,               "Name",                     "Name of Enumeration (string)"),
        UAT_FLD_DEC(someip_parameter_enums, data_type,              "Parameter Type",           "Type of parameter (1: base, 2: string, 3: array, 4: struct, 5: union, 6: typedef, 7: enum)"),
        UAT_FLD_HEX(someip_parameter_enums, id_ref,                 "ID Reference",             "ID Reference (32bit hex)"),
        UAT_FLD_DEC(someip_parameter_enums, num_of_items,           "Number of Items",          "Number of Items (32bit dec)"),

        UAT_FLD_HEX(someip_parameter_enums, value,                  "Value",                    "Value (64bit uint hex)"),
        UAT_FLD_CSTRING(someip_parameter_enums, value_name,         "Value Name",               "Name (string)"),
        UAT_END_FIELDS
    };

    static uat_field_t someip_parameter_base_type_list_uat_fields[] = {
        UAT_FLD_HEX(someip_parameter_base_type_list, id,                        "ID ",                  "ID  (32bit hex)"),
        UAT_FLD_CSTRING(someip_parameter_base_type_list, name,                  "Name",                 "Name of type (string)"),
        UAT_FLD_CSTRING(someip_parameter_base_type_list, data_type,             "Data Type",            "Data type (string)"),
        UAT_FLD_BOOL(someip_parameter_base_type_list, big_endian,               "Big Endian",           "Encoded Big Endian"),
        UAT_FLD_DEC(someip_parameter_base_type_list, bitlength_base_type,       "Bitlength base type",  "Bitlength base type (uint32 dec)"),
        UAT_FLD_DEC(someip_parameter_base_type_list, bitlength_encoded_type,    "Bitlength enc. type",  "Bitlength encoded type (uint32 dec)"),
        UAT_END_FIELDS
    };

    static uat_field_t someip_parameter_string_list_uat_fields[] = {
        UAT_FLD_HEX(someip_parameter_strings, id,                   "ID ",                  "ID  (32bit hex)"),
        UAT_FLD_CSTRING(someip_parameter_strings, name,             "Name",                 "Name of string (string)"),
        UAT_FLD_CSTRING(someip_parameter_strings, encoding,         "Encoding",             "String Encoding (ascii, utf-8, utf-16)"),
        UAT_FLD_BOOL(someip_parameter_strings, dynamic_length,      "Dynamic Length",       "Dynamic length of string"),
        UAT_FLD_DEC(someip_parameter_strings, max_length,           "Max. Length",          "Maximum length/Length (uint32 dec)"),
        UAT_FLD_DEC(someip_parameter_strings, length_of_length,     "Length of Len Field",  "Length of the length field in bits (uint8 dec)"),
        UAT_FLD_BOOL(someip_parameter_strings, big_endian,          "Big Endian",           "Encoded Big Endian"),
        UAT_FLD_DEC(someip_parameter_strings, pad_to,               "Pad to",               "Padding pads to reach alignment (8bit dec)"),
        UAT_END_FIELDS
    };

    static uat_field_t someip_parameter_typedef_list_uat_fields[] = {
        UAT_FLD_HEX(someip_parameter_typedefs, id,                  "ID ",                  "ID  (32bit hex)"),
        UAT_FLD_CSTRING(someip_parameter_typedefs, name,            "Name",                 "Name of typedef (string)"),
        UAT_FLD_DEC(someip_parameter_typedefs, data_type,           "Data Type",            "Type referenced item (1: base, 2: string, 3: array, 4: struct, 5: union, 6: typedef, 7: enum)"),
        UAT_FLD_HEX(someip_parameter_typedefs, id_ref,              "ID Reference",         "ID Reference (32bit hex)"),
        UAT_END_FIELDS
    };

    static ei_register_info ei[] = {
        { &ei_someip_unknown_version,{ "someip.unknown_protocol_version",
          PI_PROTOCOL, PI_WARN, "SOME/IP Unknown Protocol Version!", EXPFILL } },
        { &ei_someip_message_truncated,{ "someip.message_truncated",
          PI_MALFORMED, PI_ERROR, "SOME/IP Truncated message!", EXPFILL } },
        { &ei_someip_incomplete_headers,{ "someip.incomplete_headers",
          PI_MALFORMED, PI_ERROR, "SOME/IP Incomplete headers or some bytes left over!", EXPFILL } },

        { &ei_someip_payload_truncated, {"someip.payload.expert_truncated",
          PI_MALFORMED, PI_ERROR, "SOME/IP Payload: Truncated payload!", EXPFILL} },
        { &ei_someip_payload_malformed, {"someip.payload.expert_malformed",
          PI_MALFORMED, PI_ERROR, "SOME/IP Payload: Malformed payload!", EXPFILL} },
        { &ei_someip_payload_config_error, {"someip.payload.expert_config_error",
         PI_MALFORMED, PI_ERROR, "SOME/IP Payload: Config Error!", EXPFILL} },
        { &ei_someip_payload_alignment_error, {"someip.payload.expert_alignment_error",
          PI_MALFORMED, PI_ERROR, "SOME/IP Payload: SOME/IP datatype must be align to a byte!", EXPFILL} },
        { &ei_someip_payload_static_array_min_not_max, {"someip.payload.expert_static_array_min_max",
          PI_MALFORMED, PI_ERROR, "SOME/IP Payload: Static array with min!=max!", EXPFILL} },
        { &ei_someip_payload_dyn_array_not_within_limit, {"someip.payload.expert_dyn_array_not_within_limit",
          PI_MALFORMED, PI_WARN, "SOME/IP Payload: Dynamic array does not stay between Min and Max values!", EXPFILL} },
    };

    /* Register Protocol, Handles, Fields, ETTs, Expert Info, Dissector Table, Taps */
    proto_someip = proto_register_protocol(SOMEIP_NAME_LONG, SOMEIP_NAME, SOMEIP_NAME_FILTER);
    someip_handle_udp = register_dissector("someip_udp", dissect_someip_udp, proto_someip);
    someip_handle_tcp = register_dissector("someip_tcp", dissect_someip_tcp, proto_someip);

    proto_register_field_array(proto_someip, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));
    expert_module_someip = expert_register_protocol(proto_someip);
    expert_register_field_array(expert_module_someip, ei, array_length(ei));

    someip_dissector_table = register_dissector_table("someip.messageid", "SOME/IP Message ID", proto_someip, FT_UINT32, BASE_HEX);

    tap_someip_messages = register_tap("someip_messages");

    /* init for SOME/IP-TP */
    reassembly_table_init(&someip_tp_reassembly_table, &someip_reassembly_table_functions);

    /* Register preferences */
    someip_module = prefs_register_protocol(proto_someip, &proto_reg_handoff_someip);

    /* UATs */
    someip_service_uat = uat_new("SOME/IP Services",
        sizeof(generic_one_id_string_t),                   /* record size           */
        DATAFILE_SOMEIP_SERVICES,                          /* filename              */
        TRUE,                                              /* from profile          */
        (void **) &someip_service_ident,                   /* data_ptr              */
        &someip_service_ident_num,                         /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION,                            /* but not fields        */
        NULL,                                              /* help                  */
        copy_generic_one_id_string_cb,                     /* copy callback         */
        update_serviceid,                                  /* update callback       */
        free_generic_one_id_string_cb,                     /* free callback         */
        post_update_someip_service_cb,                     /* post update callback  */
        reset_someip_service_cb,                           /* reset callback        */
        someip_service_uat_fields                          /* UAT field definitions */
    );

    prefs_register_uat_preference(someip_module, "services", "SOME/IP Services",
        "A table to define names of SOME/IP services", someip_service_uat);

    someip_method_uat = uat_new("SOME/IP Methods/Events/Fields",
        sizeof(generic_two_id_string_t),                    /* record size           */
        DATAFILE_SOMEIP_METHODS,                            /* filename              */
        TRUE,                                               /* from profile          */
        (void **) &someip_method_ident,                     /* data_ptr              */
        &someip_method_ident_num,                           /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION,                             /* but not fields        */
        NULL,                                               /* help                  */
        copy_generic_two_id_string_cb,                      /* copy callback         */
        update_two_identifier_16bit_check_both,             /* update callback       */
        free_generic_two_id_string_cb,                      /* free callback         */
        post_update_someip_method_cb,                       /* post update callback  */
        reset_someip_method_cb,                             /* reset callback        */
        someip_method_uat_fields                            /* UAT field definitions */
    );

    prefs_register_uat_preference(someip_module, "methods", "SOME/IP Methods",
        "A table to define names of SOME/IP methods", someip_method_uat);

    someip_eventgroup_uat = uat_new("SOME/IP Eventgroups",
        sizeof(generic_two_id_string_t),                   /* record size           */
        DATAFILE_SOMEIP_EVENTGROUPS,                       /* filename              */
        TRUE,                                              /* from profile          */
        (void **) &someip_eventgroup_ident,                /* data_ptr              */
        &someip_eventgroup_ident_num,                      /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION,                            /* but not fields        */
        NULL,                                              /* help                  */
        copy_generic_two_id_string_cb,                     /* copy callback         */
        update_two_identifier_16bit_check_both,            /* update callback       */
        free_generic_two_id_string_cb,                     /* free callback         */
        post_update_someip_eventgroup_cb,                  /* post update callback  */
        reset_someip_eventgroup_cb,                        /* reset callback        */
        someip_eventgroup_uat_fields                       /* UAT field definitions */
    );

    prefs_register_uat_preference(someip_module, "eventgroups", "SOME/IP Eventgroups",
        "A table to define names of SOME/IP eventgroups", someip_eventgroup_uat);

    someip_client_uat = uat_new("SOME/IP Clients",
        sizeof(generic_two_id_string_t),                   /* record size           */
        DATAFILE_SOMEIP_CLIENTS,                           /* filename              */
        TRUE,                                              /* from profile          */
        (void **)&someip_client_ident,                     /* data_ptr              */
        &someip_client_ident_num,                          /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION,                            /* but not fields        */
        NULL,                                              /* help                  */
        copy_generic_two_id_string_cb,                     /* copy callback         */
        update_generic_two_identifier_16bit,               /* update callback       */
        free_generic_two_id_string_cb,                     /* free callback         */
        post_update_someip_client_cb,                      /* post update callback  */
        reset_someip_client_cb,                            /* reset callback        */
        someip_client_uat_fields                           /* UAT field definitions */
    );

    prefs_register_uat_preference(someip_module, "clients", "SOME/IP Clients",
        "A table to define names of SOME/IP clients", someip_client_uat);

    someip_parameter_list_uat = uat_new("SOME/IP Parameter List",
        sizeof(someip_parameter_list_uat_t),               /* record size           */
        DATAFILE_SOMEIP_PARAMETERS,                        /* filename              */
        TRUE,                                              /* from profile          */
        (void **)&someip_parameter_list,                   /* data_ptr              */
        &someip_parameter_list_num,                        /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION | UAT_AFFECTS_FIELDS,
        NULL,                                              /* help                  */
        copy_someip_parameter_list_cb,                     /* copy callback         */
        update_someip_parameter_list,                      /* update callback       */
        free_someip_parameter_list_cb,                     /* free callback         */
        post_update_someip_parameter_list_cb,              /* post update callback  */
        reset_someip_parameter_list_cb,                    /* reset callback        */
        someip_parameter_list_uat_fields                   /* UAT field definitions */
    );

    prefs_register_bool_preference(someip_module, "reassemble_tp", "Reassemble SOME/IP-TP",
        "Reassemble SOME/IP-TP segments", &someip_tp_reassemble);

    prefs_register_bool_preference(someip_module, "payload_dissector_activated",
        "Dissect Payload",
        "Should the SOME/IP Dissector use the payload dissector?",
        &someip_deserializer_activated);

    prefs_register_bool_preference(someip_module, "detect_dtls_and_hand_off",
        "Try to automatically detect DTLS",
        "Should the SOME/IP Dissector automatically detect DTLS and hand off to it?",
        &someip_detect_dtls);

    prefs_register_bool_preference(someip_module, "payload_dissector_wtlv_default",
        "Try WTLV payload dissection for unconfigured messages (not pure SOME/IP)",
        "Should the SOME/IP Dissector use the payload dissector with the experimental WTLV encoding for unconfigured messages?",
        &someip_deserializer_wtlv_default);

    prefs_register_uat_preference(someip_module, "_someip_parameter_list", "SOME/IP Parameter List",
        "A table to define names of SOME/IP parameters", someip_parameter_list_uat);

    someip_parameter_arrays_uat = uat_new("SOME/IP Parameter Arrays",
        sizeof(someip_parameter_array_uat_t),              /* record size           */
        DATAFILE_SOMEIP_ARRAYS,                            /* filename              */
        TRUE,                                              /* from profile          */
        (void **)&someip_parameter_arrays,                 /* data_ptr              */
        &someip_parameter_arrays_num,                      /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION | UAT_AFFECTS_FIELDS,
        NULL,                                              /* help                  */
        copy_someip_parameter_array_cb,                    /* copy callback         */
        update_someip_parameter_array,                     /* update callback       */
        free_someip_parameter_array_cb,                    /* free callback         */
        post_update_someip_parameter_array_cb,             /* post update callback  */
        reset_someip_parameter_array_cb,                   /* reset callback        */
        someip_parameter_array_uat_fields                  /* UAT field definitions */
    );

    prefs_register_uat_preference(someip_module, "_someip_parameter_arrays", "SOME/IP Parameter Arrays",
        "A table to define arrays used by SOME/IP", someip_parameter_arrays_uat);

    someip_parameter_structs_uat = uat_new("SOME/IP Parameter Structs",
        sizeof(someip_parameter_struct_uat_t),             /* record size           */
        DATAFILE_SOMEIP_STRUCTS,                           /* filename              */
        TRUE,                                              /* from profile          */
        (void **)&someip_parameter_structs,                /* data_ptr              */
        &someip_parameter_structs_num,                     /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION | UAT_AFFECTS_FIELDS,
        NULL,                                              /* help                  */
        copy_someip_parameter_struct_cb,                   /* copy callback         */
        update_someip_parameter_struct,                    /* update callback       */
        free_someip_parameter_struct_cb,                   /* free callback         */
        post_update_someip_parameter_struct_cb,            /* post update callback  */
        reset_someip_parameter_struct_cb,                  /* reset callback        */
        someip_parameter_struct_uat_fields                 /* UAT field definitions */
    );

    prefs_register_uat_preference(someip_module, "_someip_parameter_structs", "SOME/IP Parameter Structs",
        "A table to define structs used by SOME/IP", someip_parameter_structs_uat);

    someip_parameter_unions_uat = uat_new("SOME/IP Parameter Unions",
        sizeof(someip_parameter_union_uat_t),              /* record size           */
        DATAFILE_SOMEIP_UNIONS,                            /* filename              */
        TRUE,                                              /* from profile          */
        (void **)&someip_parameter_unions,                 /* data_ptr              */
        &someip_parameter_unions_num,                      /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION | UAT_AFFECTS_FIELDS,
        NULL,                                              /* help                  */
        copy_someip_parameter_union_cb,                    /* copy callback         */
        update_someip_parameter_union,                     /* update callback       */
        free_someip_parameter_union_cb,                    /* free callback         */
        post_update_someip_parameter_union_cb,             /* post update callback  */
        reset_someip_parameter_union_cb,                   /* reset callback        */
        someip_parameter_union_uat_fields                  /* UAT field definitions */
    );

    prefs_register_uat_preference(someip_module, "_someip_parameter_unions", "SOME/IP Parameter Unions",
        "A table to define unions used by SOME/IP", someip_parameter_unions_uat);

    someip_parameter_enums_uat = uat_new("SOME/IP Parameter Enums",
        sizeof(someip_parameter_enum_uat_t),               /* record size           */
        DATAFILE_SOMEIP_ENUMS,                             /* filename              */
        TRUE,                                              /* from profile          */
        (void **)&someip_parameter_enums,                  /* data_ptr              */
        &someip_parameter_enums_num,                       /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION,                            /* but not fields        */
        NULL,                                              /* help                  */
        copy_someip_parameter_enum_cb,                     /* copy callback         */
        update_someip_parameter_enum,                      /* update callback       */
        free_someip_parameter_enum_cb,                     /* free callback         */
        post_update_someip_parameter_enum_cb,              /* post update callback  */
        reset_someip_parameter_enum_cb,                    /* reset callback        */
        someip_parameter_enum_uat_fields                   /* UAT field definitions */
    );

    prefs_register_uat_preference(someip_module, "_someip_parameter_enums", "SOME/IP Parameter Enums",
        "A table to define enumerations used by SOME/IP", someip_parameter_enums_uat);

    someip_parameter_base_type_list_uat = uat_new("SOME/IP Parameter Base Type List",
        sizeof(someip_parameter_base_type_list_uat_t),     /* record size           */
        DATAFILE_SOMEIP_BASE_TYPES,                        /* filename              */
        TRUE,                                              /* from profile          */
        (void **)&someip_parameter_base_type_list,         /* data_ptr              */
        &someip_parameter_base_type_list_num,              /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION,                            /* but not fields        */
        NULL,                                              /* help                  */
        copy_someip_parameter_base_type_list_cb,           /* copy callback         */
        update_someip_parameter_base_type_list,            /* update callback       */
        free_someip_parameter_base_type_list_cb,           /* free callback         */
        post_update_someip_parameter_base_type_list_cb,    /* post update callback  */
        reset_someip_parameter_base_type_list_cb,          /* reset callback        */
        someip_parameter_base_type_list_uat_fields         /* UAT field definitions */
    );

    prefs_register_uat_preference(someip_module, "_someip_parameter_base_type_list", "SOME/IP Parameter Base Type List",
        "A table to define base types of SOME/IP parameters", someip_parameter_base_type_list_uat);

    someip_parameter_strings_uat = uat_new("SOME/IP Parameter String List",
        sizeof(someip_parameter_string_uat_t),             /* record size           */
        DATAFILE_SOMEIP_STRINGS,                           /* filename              */
        TRUE,                                              /* from profile          */
        (void **)&someip_parameter_strings,                /* data_ptr              */
        &someip_parameter_strings_num,                     /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION,                            /* but not fields        */
        NULL,                                              /* help                  */
        copy_someip_parameter_string_list_cb,              /* copy callback         */
        update_someip_parameter_string_list,               /* update callback       */
        free_someip_parameter_string_list_cb,              /* free callback         */
        post_update_someip_parameter_string_list_cb,       /* post update callback  */
        reset_someip_parameter_string_list_cb,             /* reset callback        */
        someip_parameter_string_list_uat_fields            /* UAT field definitions */
    );

    prefs_register_uat_preference(someip_module, "_someip_parameter_string_list", "SOME/IP Parameter String List",
        "A table to define strings parameters", someip_parameter_strings_uat);

    someip_parameter_typedefs_uat = uat_new("SOME/IP Parameter Typedef List",
        sizeof(someip_parameter_typedef_uat_t),            /* record size           */
        DATAFILE_SOMEIP_TYPEDEFS,                          /* filename              */
        TRUE,                                              /* from profile          */
        (void **)&someip_parameter_typedefs,               /* data_ptr              */
        &someip_parameter_typedefs_num,                    /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION,                            /* but not fields        */
        NULL,                                              /* help                  */
        copy_someip_parameter_typedef_list_cb,             /* copy callback         */
        update_someip_parameter_typedef_list,              /* update callback       */
        free_someip_parameter_typedef_list_cb,             /* free callback         */
        post_update_someip_parameter_typedef_list_cb,      /* post update callback  */
        reset_someip_parameter_typedef_list_cb,            /* reset callback        */
        someip_parameter_typedef_list_uat_fields           /* UAT field definitions */
    );

    prefs_register_uat_preference(someip_module, "_someip_parameter_typedef_list", "SOME/IP Parameter Typedef List",
        "A table to define typedefs", someip_parameter_typedefs_uat);
}

static void
clean_all_hashtables_with_empty_uat(void) {
    /* On config change, we delete all hashtables which should have 0 entries! */
    /* Usually this is already done in the post update cb of the uat.*/
    /* Unfortunately, Wireshark does not call the post_update_cb on config errors. :( */
    if (data_someip_services && someip_service_ident_num==0) {
        g_hash_table_destroy(data_someip_services);
        data_someip_services = NULL;
    }
    if (data_someip_methods && someip_method_ident_num==0) {
        g_hash_table_destroy(data_someip_methods);
        data_someip_methods = NULL;
    }
    if (data_someip_eventgroups && someip_eventgroup_ident_num==0) {
        g_hash_table_destroy(data_someip_eventgroups);
        data_someip_eventgroups = NULL;
    }
    if (data_someip_clients && someip_client_ident_num == 0) {
        g_hash_table_destroy(data_someip_clients);
        data_someip_clients = NULL;
    }
    if (data_someip_parameter_list && someip_parameter_list_num==0) {
        g_hash_table_destroy(data_someip_parameter_list);
        data_someip_parameter_list = NULL;
    }
    if (data_someip_parameter_arrays && someip_parameter_arrays_num==0) {
        g_hash_table_destroy(data_someip_parameter_arrays);
        data_someip_parameter_arrays = NULL;
    }
    if (data_someip_parameter_structs && someip_parameter_structs_num==0) {
        g_hash_table_destroy(data_someip_parameter_structs);
        data_someip_parameter_structs = NULL;
    }
    if (data_someip_parameter_unions && someip_parameter_unions_num==0) {
        g_hash_table_destroy(data_someip_parameter_unions);
        data_someip_parameter_unions = NULL;
    }
    if (data_someip_parameter_enums && someip_parameter_enums_num == 0) {
        g_hash_table_destroy(data_someip_parameter_enums);
        data_someip_parameter_enums = NULL;
    }
    if (data_someip_parameter_base_type_list && someip_parameter_base_type_list_num==0) {
        g_hash_table_destroy(data_someip_parameter_base_type_list);
        data_someip_parameter_base_type_list = NULL;
    }
    if (data_someip_parameter_strings && someip_parameter_strings_num==0) {
        g_hash_table_destroy(data_someip_parameter_strings);
        data_someip_parameter_strings = NULL;
    }
    if (data_someip_parameter_typedefs && someip_parameter_typedefs_num==0) {
        g_hash_table_destroy(data_someip_parameter_typedefs);
        data_someip_parameter_typedefs = NULL;
    }
}

void
proto_reg_handoff_someip(void) {
    static gboolean initialized = FALSE;

    if (!initialized) {
        /* add support for (D)TLS decode as */
        dtls_dissector_add(0, someip_handle_udp);
        ssl_dissector_add(0, someip_handle_tcp);

        heur_dissector_add("udp", dissect_some_ip_heur_udp, "SOME/IP over UDP", "someip_udp_heur", proto_someip, HEURISTIC_DISABLE);
        heur_dissector_add("tcp", dissect_some_ip_heur_tcp, "SOME/IP over TCP", "someip_tcp_heur", proto_someip, HEURISTIC_DISABLE);

        stats_tree_register("someip_messages", "someip_messages", "SOME/IP Messages", 0, someip_messages_stats_tree_packet, someip_messages_stats_tree_init, NULL);

        dissector_add_uint_range_with_preference("udp.port", "", someip_handle_udp);
        dissector_add_uint_range_with_preference("tcp.port", "", someip_handle_tcp);

        dtls_handle = find_dissector("dtls");

        initialized = TRUE;
    } else {
        clean_all_hashtables_with_empty_uat();
    }

    update_dynamic_hf_entries_someip_parameter_list();
    update_dynamic_hf_entries_someip_parameter_arrays();
    update_dynamic_hf_entries_someip_parameter_structs();
    update_dynamic_hf_entries_someip_parameter_unions();
}

/*
 * Editor modelines
 *
 * Local Variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */