summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-asam-cmp.c
blob: 2d37c22028be1519bf9e102a49e0d93720583113 (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
/* packet-asam-cmp.c
 * ASAM Capture Module Protocol dissector.
 * Copyright 2021-2023 Alicia Mediano Schikarski, Technica Engineering GmbH
 * Copyright 2021-2024 Dr. Lars Voelker, Technica Engineering GmbH
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

 /*
  * This is a dissector for the Capture Module Protocol standardized by the ASAM.
  * ASAM CMP is the standardized a successor of TECMP.
  */

#include "config.h"

#include <epan/packet.h>
#include <epan/uat.h>
#include <epan/expert.h>

#include "packet-socketcan.h"
#include "packet-flexray.h"
#include "packet-lin.h"

void proto_register_asam_cmp(void);
void proto_reg_handoff_asam_cmp(void);

static int proto_asam_cmp = -1;

static dissector_handle_t eth_handle;

static gboolean heuristic_first = FALSE;
static gboolean old_11bit_canid_encoding = FALSE;

static dissector_table_t lin_subdissector_table;

/* Header fields */
static int hf_cmp_header = -1;
static int hf_cmp_version = -1;
static int hf_cmp_header_res = -1;
static int hf_cmp_device_id = -1;
static int hf_cmp_msg_type = -1;
static int hf_cmp_stream_id = -1;
static int hf_cmp_stream_seq_ctr = -1;

/* Message Fields */
/* Message Header Fields */
static int hf_cmp_msg_header = -1;

static int hf_cmp_common_flag_recal = -1;
static int hf_cmp_common_flag_insync = -1;
static int hf_cmp_common_flag_seg = -1;
static int hf_cmp_common_flag_dir_on_if = -1;
static int hf_cmp_common_flag_overflow = -1;
static int hf_cmp_common_flag_err_in_payload = -1;
static int hf_cmp_common_flag_reserved = -1;
static int hf_cmp_common_flag_reserved_ctrl = -1;

static int hf_cmp_msg_timestamp = -1;
static int hf_cmp_msg_timestamp_ns = -1;
static int hf_cmp_msg_reserved = -1;
static int hf_cmp_msg_common_flags = -1;
static int hf_cmp_msg_vendor_id = -1;
static int hf_cmp_msg_payload_length = -1;
static int hf_cmp_msg_payload = -1;

/* Additional Data Message Header Fields */
static int hf_cmp_interface_id = -1;
static int hf_cmp_payload_type = -1;

/* Additional Control Message Header Fields */
static int hf_cmp_ctrl_msg_reserved = -1;
static int hf_cmp_ctrl_msg_payload_type = -1;

/* Additional Status Message Header Fields */
static int hf_cmp_status_msg_payload_type = -1;

/* Additional Status Message Header Fields */
static int hf_cmp_vendor_msg_payload_type = -1;

/* Data Message Payload Fields */
/* CAN */
#define CMP_CAN_FLAGS_ERRORS        0x03ff
#define CMP_CAN_ID_11BIT_MASK       0x1ffc0000
#define CMP_CAN_ID_11BIT_SHIFT      18
#define CMP_CAN_ID_11BIT_MASK_OLD   0x000007ff
#define CMP_CAN_ID_29BIT_MASK       0x1fffffff
#define CMP_CAN_ID_RES              0x20000000
#define CMP_CAN_ID_RTR              0x40000000
#define CMP_CAN_ID_IDE              0x80000000

#define CMP_CAN_CRC_CRC             0x00007fff
#define CMP_CAN_CRC_RES             0x7fff8000
#define CMP_CAN_CRC_CRC_SUPP        0x80000000

static int hf_cmp_can_flags = -1;

static int hf_cmp_can_flag_crc_err = -1;
static int hf_cmp_can_flag_ack_err = -1;
static int hf_cmp_can_flag_passive_ack_err = -1;
static int hf_cmp_can_flag_active_ack_err = -1;
static int hf_cmp_can_flag_ack_del_err = -1;
static int hf_cmp_can_flag_form_err = -1;
static int hf_cmp_can_flag_stuff_err = -1;
static int hf_cmp_can_flag_crc_del_err = -1;
static int hf_cmp_can_flag_eof_err = -1;
static int hf_cmp_can_flag_bit_err = -1;
static int hf_cmp_can_flag_r0 = -1;
static int hf_cmp_can_flag_srr_dom = -1;
static int hf_cmp_can_flag_reserved = -1;

static int hf_cmp_can_reserved = -1;
static int hf_cmp_can_id = -1;
static int hf_cmp_can_id_11bit = -1;
static int hf_cmp_can_id_11bit_old = -1;
static int hf_cmp_can_id_29bit = -1;
static int hf_cmp_can_id_res = -1;
static int hf_cmp_can_id_rtr = -1;
static int hf_cmp_can_id_ide = -1;
static int hf_cmp_can_crc = -1;
static int hf_cmp_can_crc_crc = -1;
static int hf_cmp_can_crc_res = -1;
static int hf_cmp_can_crc_crc_support = -1;
static int hf_cmp_can_err_pos = -1;
static int hf_cmp_can_dlc = -1;
static int hf_cmp_can_data_len = -1;

/* CAN FD */
#define CMP_CANFD_FLAGS_ERRORS      0x03ff
#define CMP_CANFD_ID_RES            0x20000000
#define CMP_CANFD_ID_RRS            0x40000000
#define CMP_CANFD_ID_IDE            0x80000000

#define CMP_CANFD_CRC_CRC17         0x0001ffff
#define CMP_CANFD_CRC_CRC21         0x001fffff
#define CMP_CANFD_CRC_SBC           0x00e00000
#define CMP_CANFD_CRC_SBC_PARITY    0x01000000
#define CMP_CANFD_CRC_RES           0x3e000000
#define CMP_CANFD_CRC_SBC_SUPP      0x40000000
#define CMP_CANFD_CRC_CRC_SUPP      0x80000000

static int hf_cmp_canfd_flags = -1;

static int hf_cmp_canfd_flag_crc_err = -1;
static int hf_cmp_canfd_flag_ack_err = -1;
static int hf_cmp_canfd_flag_passive_ack_err = -1;
static int hf_cmp_canfd_flag_active_ack_err = -1;
static int hf_cmp_canfd_flag_ack_del_err = -1;
static int hf_cmp_canfd_flag_form_err = -1;
static int hf_cmp_canfd_flag_stuff_err = -1;
static int hf_cmp_canfd_flag_crc_del_err = -1;
static int hf_cmp_canfd_flag_eof_err = -1;
static int hf_cmp_canfd_flag_bit_err = -1;
static int hf_cmp_canfd_flag_res = -1;
static int hf_cmp_canfd_flag_srr_dom = -1;
static int hf_cmp_canfd_flag_brs = -1;
static int hf_cmp_canfd_flag_esi = -1;
static int hf_cmp_canfd_flag_reserved = -1;

static int hf_cmp_canfd_reserved = -1;
static int hf_cmp_canfd_id = -1;
static int hf_cmp_canfd_id_11bit = -1;
static int hf_cmp_canfd_id_11bit_old = -1;
static int hf_cmp_canfd_id_29bit = -1;
static int hf_cmp_canfd_id_res = -1;
static int hf_cmp_canfd_id_rrs = -1;
static int hf_cmp_canfd_id_ide = -1;
static int hf_cmp_canfd_crc = -1;
static int hf_cmp_canfd_crc_crc17 = -1;
static int hf_cmp_canfd_crc_crc21 = -1;
static int hf_cmp_canfd_crc_sbc = -1;
static int hf_cmp_canfd_crc_sbc_parity = -1;
static int hf_cmp_canfd_crc_res = -1;
static int hf_cmp_canfd_crc_sbc_support = -1;
static int hf_cmp_canfd_crc_crc_support = -1;
static int hf_cmp_canfd_err_pos = -1;
static int hf_cmp_canfd_dlc = -1;
static int hf_cmp_canfd_data_len = -1;

/* LIN */
#define CMP_CANFD_PID_PARITY_MASK   0xc0
#define CMP_CANFD_PID_ID_MASK       0x3f

static int hf_cmp_lin_flags = -1;
static int hf_cmp_lin_flag_checksum_err = -1;
static int hf_cmp_lin_flag_col_err = -1;
static int hf_cmp_lin_flag_parity_err = -1;
static int hf_cmp_lin_flag_no_slave_res_err = -1;
static int hf_cmp_lin_flag_sync_err = -1;
static int hf_cmp_lin_flag_framing_err = -1;
static int hf_cmp_lin_flag_short_dom_err = -1;
static int hf_cmp_lin_flag_long_dom_err = -1;
static int hf_cmp_lin_flag_wup = -1;
static int hf_cmp_lin_flag_reserved = -1;

static int hf_cmp_lin_reserved = -1;
static int hf_cmp_lin_pid = -1;
static int hf_cmp_lin_pid_parity = -1;
static int hf_cmp_lin_pid_id = -1;
static int hf_cmp_lin_reserved_2 = -1;
static int hf_cmp_lin_checksum = -1;
static int hf_cmp_lin_data_len = -1;

/* FlexRay */
#define CMP_FLEXRAY_FLAGS_NF 0x0004

static int hf_cmp_flexray_flags = -1;

static int hf_cmp_flexray_flag_crc_frame_err = -1;
static int hf_cmp_flexray_flag_crc_header_err = -1;
static int hf_cmp_flexray_flag_nf = -1;
static int hf_cmp_flexray_flag_sf = -1;
static int hf_cmp_flexray_flag_sync = -1;
static int hf_cmp_flexray_flag_wus = -1;
static int hf_cmp_flexray_flag_ppi = -1;
static int hf_cmp_flexray_flag_cas = -1;
static int hf_cmp_flexray_flag_reserved = -1;

static int hf_cmp_flexray_reserved = -1;
static int hf_cmp_flexray_header_crc = -1;
static int hf_cmp_flexray_frame_id = -1;
static int hf_cmp_flexray_cycle = -1;
static int hf_cmp_flexray_frame_crc = -1;
static int hf_cmp_flexray_reserved_2 = -1;
static int hf_cmp_flexray_data_len = -1;

/* UART/RS-232 */
#define CMP_UART_DATA_DATA_MASK     0x01FF

static int hf_cmp_uart_flags = -1;

static int hf_cmp_uart_flag_cl = -1;
static int hf_cmp_uart_flag_reserved = -1;

static int hf_cmp_uart_reserved = -1;
static int hf_cmp_uart_data_len = -1;
static int hf_cmp_uart_data = -1;

static int hf_cmp_uart_data_data = -1;
static int hf_cmp_uart_data_reserved = -1;
static int hf_cmp_uart_data_framing_err = -1;
static int hf_cmp_uart_data_break_condition = -1;
static int hf_cmp_uart_data_parity_err = -1;

/* Analog */
static int hf_cmp_analog_flags = -1;

static int hf_cmp_analog_flag_sample_dt = -1;
static int hf_cmp_analog_flag_reserved = -1;

static int hf_cmp_analog_reserved = -1;
static int hf_cmp_analog_unit = -1;
static int hf_cmp_analog_sample_interval = -1;
static int hf_cmp_analog_sample_scalar = -1;
static int hf_cmp_analog_sample_offset = -1;
static int hf_cmp_analog_sample = -1;

/* Ethernet */
static int hf_cmp_eth_flags = -1;

static int hf_cmp_eth_flag_fcs_err = -1;
static int hf_cmp_eth_flag_short_err = -1;
static int hf_cmp_eth_flag_tx_down = -1;
static int hf_cmp_eth_flag_collision = -1;
static int hf_cmp_eth_flag_long_err = -1;
static int hf_cmp_eth_flag_phy_err = -1;
static int hf_cmp_eth_flag_truncated = -1;
static int hf_cmp_eth_flag_fcs_supported = -1;
static int hf_cmp_eth_flag_reserved = -1;

static int hf_cmp_eth_reserved = -1;
static int hf_cmp_eth_payload_length = -1;

/* Control Message Payload Fields */
/* Data Sink Ready */
static int hf_cmp_ctrl_msg_device_id = -1;

/* User Event */
static int hf_cmp_ctrl_msg_event_id = -1;

/* Vendor specific */
static int hf_cmp_ctrl_msg_vendor_id = -1;
static int hf_cmp_ctrl_msg_vendor_payload_type = -1;

/* Status Message Payload Fields */
/* Capture Module Status Message */
static int hf_cmp_status_msg_cm_uptime_ns = -1;
static int hf_cmp_status_msg_cm_uptime_s = -1;
static int hf_cmp_status_msg_gm_identity = -1;
static int hf_cmp_status_msg_gm_clock_quality = -1;
static int hf_cmp_status_msg_current_utc_offset = -1;
static int hf_cmp_status_msg_time_source = -1;
static int hf_cmp_status_msg_domain_num = -1;
static int hf_cmp_status_msg_res = -1;
static int hf_cmp_gptp_flags = -1;

static int hf_cmp_gptp_flags_leap61 = -1;
static int hf_cmp_gptp_flags_leap59 = -1;
static int hf_cmp_gptp_flags_cur_utco_valid = -1;
static int hf_cmp_gptp_flags_ptp_timescale = -1;
static int hf_cmp_gptp_flags_time_traceable = -1;
static int hf_cmp_gptp_flags_freq_traceable = -1;
static int hf_cmp_gptp_flags_reserved = -1;

static int hf_cmp_status_dev_desc_length = -1;
static int hf_cmp_status_dev_desc = -1;
static int hf_cmp_status_sn_length = -1;
static int hf_cmp_status_sn = -1;
static int hf_cmp_status_hw_ver_length = -1;
static int hf_cmp_status_hw_ver = -1;
static int hf_cmp_status_sw_ver_length = -1;
static int hf_cmp_status_sw_ver = -1;
static int hf_cmp_status_vendor_data_length = -1;
static int hf_cmp_status_vendor_data = -1;

/* Interface Status Message */
static int hf_cmp_iface_interface = -1;
static int hf_cmp_iface_iface_id = -1;
static int hf_cmp_iface_msg_total_rx = -1;
static int hf_cmp_iface_msg_total_tx = -1;
static int hf_cmp_iface_msg_dropped_rx = -1;
static int hf_cmp_iface_msg_dropped_tx = -1;
static int hf_cmp_iface_errs_total_rx = -1;
static int hf_cmp_iface_errs_total_tx = -1;
static int hf_cmp_iface_iface_type = -1;
static int hf_cmp_iface_iface_status = -1;
static int hf_cmp_iface_stream_id_cnt = -1;
static int hf_cmp_iface_reserved = -1;

static int hf_cmp_iface_feat = -1;
static int hf_cmp_iface_feat_can_pas_ack = -1;
static int hf_cmp_iface_feat_can_act_ack = -1;
static int hf_cmp_iface_feat_can_ack_del_err = -1;
static int hf_cmp_iface_feat_can_crc_del_err = -1;
static int hf_cmp_iface_feat_can_eof_err = -1;
static int hf_cmp_iface_feat_can_r0 = -1;
static int hf_cmp_iface_feat_can_srr_dom = -1;

static int hf_cmp_iface_feat_canfd_pas_ack = -1;
static int hf_cmp_iface_feat_canfd_act_ack = -1;
static int hf_cmp_iface_feat_canfd_ack_del_err = -1;
static int hf_cmp_iface_feat_canfd_crc_del_err = -1;
static int hf_cmp_iface_feat_canfd_eof_err = -1;
static int hf_cmp_iface_feat_canfd_rsvd = -1;
static int hf_cmp_iface_feat_canfd_srr_dom = -1;
static int hf_cmp_iface_feat_canfd_brs_dom = -1;
static int hf_cmp_iface_feat_canfd_esi_dom = -1;

static int hf_cmp_iface_feat_lin_sync_err = -1;
static int hf_cmp_iface_feat_lin_framing_err = -1;
static int hf_cmp_iface_feat_lin_short_dom_err = -1;
static int hf_cmp_iface_feat_lin_long_dom_err = -1;
static int hf_cmp_iface_feat_lin_wup = -1;

static int hf_cmp_iface_feat_eth_too_long = -1;
static int hf_cmp_iface_feat_eth_phy_err = -1;
static int hf_cmp_iface_feat_eth_trunc = -1;

static int hf_cmp_iface_stream_ids = -1;
static int hf_cmp_iface_stream_id = -1;
static int hf_cmp_iface_vendor_data_len = -1;
static int hf_cmp_iface_vendor_data = -1;

/* Configuration Status Message */
static int hf_cmp_status_msg_config = -1;

/* Data Lost Event Status Message */
static int hf_cmp_dataloss_data_sink_port = -1;
static int hf_cmp_dataloss_device_id = -1;
static int hf_cmp_dataloss_reserved = -1;
static int hf_cmp_dataloss_stream_id = -1;
static int hf_cmp_dataloss_last_ssq_value = -1;
static int hf_cmp_dataloss_current_ssq_value = -1;

/* Time Sync Lost Event Status Message */
static int hf_cmp_timeloss_port_nr = -1;
static int hf_cmp_timeloss_device_id = -1;
static int hf_cmp_timeloss_error_flags = -1;

static int hf_cmp_timeloss_error_flags_ts = -1;
static int hf_cmp_timeloss_error_flags_insync = -1;
static int hf_cmp_timeloss_error_flags_delta = -1;
static int hf_cmp_timeloss_error_flags_reserved = -1;

/* Vendor Specific */
static int hf_cmp_status_msg_vendor_specific = -1;

/* Protocol trees */
static gint ett_asam_cmp = -1;
static gint ett_asam_cmp_header = -1;
static gint ett_asam_cmp_timestamp = -1;
static gint ett_asam_cmp_common_flags = -1;
static gint ett_asam_cmp_payload = -1;
static gint ett_asam_cmp_payload_flags = -1;
static gint ett_asam_cmp_lin_pid = -1;
static gint ett_asam_cmp_can_id = -1;
static gint ett_asam_cmp_can_crc = -1;
static gint ett_asam_cmp_uart_data = -1;
static gint ett_asam_cmp_status_cm_flags = -1;
static gint ett_asam_cmp_status_cm_uptime = -1;
static gint ett_asam_cmp_status_timeloss_flags = -1;
static gint ett_asam_cmp_status_interface = -1;
static gint ett_asam_cmp_status_feature_support = -1;
static gint ett_asam_cmp_status_stream_ids = -1;

/* General */
#define CMP_HEADER_LEN                         8
#define CMP_MSG_HEADER_LEN                    16

/* CMP Message Type Names */
#define CMP_MSG_TYPE_DATA_MSG               0x01
#define CMP_MSG_TYPE_CTRL_MSG               0x02
#define CMP_MSG_TYPE_STATUS_MSG             0x03
#define CMP_MSG_TYPE_VENDOR                 0xFF

/* CMP Segmentation Flag Values */
#define CMP_SEG_UNSEGMENTED                 0x00
#define CMP_SEG_FIRST                       0x01
#define CMP_SEG_INTERMEDIARY                0x02
#define CMP_SEG_LAST                        0x03

/* CMP Data Message Payload Type Names */
#define CMP_DATA_MSG_INVALID                0x00
#define CMP_DATA_MSG_CAN                    0x01
#define CMP_DATA_MSG_CANFD                  0x02
#define CMP_DATA_MSG_LIN                    0x03
#define CMP_DATA_MSG_FLEXRAY                0x04
#define CMP_DATA_MSG_DIGITAL                0x05
#define CMP_DATA_MSG_UART_RS_232            0x06
#define CMP_DATA_MSG_ANALOG                 0x07
#define CMP_DATA_MSG_ETHERNET               0x08
#define CMP_DATA_MSG_SPI                    0x09
#define CMP_DATA_MSG_I2C                    0x0A
#define CMP_DATA_MSG_GIGEVISION             0x0B
#define CMP_DATA_MSG_MIPI_CSI2              0x0C
#define CMP_DATA_MSG_USER_DEFINED           0xFF

/* CMP Digital Trigger Pattern Values */
#define CMP_T_PATTERN_FALLING               0x00
#define CMP_T_PATTERN_RISING                0x01

/* CMP Digital Data Message DL Values */
#define CMP_UART_CL_5                       0x00
#define CMP_UART_CL_6                       0x01
#define CMP_UART_CL_7                       0x02
#define CMP_UART_CL_8                       0x03
#define CMP_UART_CL_9                       0x04

/* CMP UART/RS-232 Data Message DT Values */
#define CMP_UART_DATA_MSG_DL_16             0x00
#define CMP_UART_DATA_MSG_DL_32             0x01
#define CMP_UART_DATA_MSG_DL_RES1           0x02
#define CMP_UART_DATA_MSG_DL_RES2           0x03

/* CMP Control Message Payload Type Names */
#define CMP_CTRL_MSG_INVALID                0x00
#define CMP_CTRL_MSG_DSR_CTRL_MSG           0x01
#define CMP_CTRL_MSG_USER_EVENT_CTRL_MSG    0xFE
#define CMP_CTRL_MSG_VENDOR                 0xFF

/* CMP Status Message Payload Type Names */
#define CMP_STATUS_MSG_INVALID              0x00
#define CMP_STATUS_MSG_CM_STAT_MSG          0x01
#define CMP_STATUS_MSG_IF_STAT_MSG          0x02
#define CMP_STATUS_MSG_CONF_STAT_MSG        0x03
#define CMP_STATUS_MSG_DLE_STAT_MSG         0x04
#define CMP_STATUS_MSG_TSLE_STAT_MSG        0x05
#define CMP_STATUS_MSG_VENDOR_STAT_MSG      0xFF

/* Interface Status Message Names */
#define CMP_STATUS_IFACE_DOWN_EN            0x00
#define CMP_STATUS_IFACE_UP_EN              0x01
#define CMP_STATUS_IFACE_DOWN_DIS           0x02

static const value_string msg_type_names[] = {
    {CMP_MSG_TYPE_DATA_MSG,                 "Data Message"},
    {CMP_MSG_TYPE_CTRL_MSG,                 "Control Message"},
    {CMP_MSG_TYPE_STATUS_MSG,               "Status Message"},
    {CMP_MSG_TYPE_VENDOR,                   "Vendor Specific Data"},
    {0, NULL}
};

static const value_string seg_flag_names[] = {
    {CMP_SEG_INTERMEDIARY,                  "Intermediary segment"},
    {CMP_SEG_FIRST,                         "First segment"},
    {CMP_SEG_LAST,                          "Last segment"},
    {CMP_SEG_UNSEGMENTED,                   "Unsegmented"},
    {0, NULL}
};

static const true_false_string interface_direction = {
    "Sending",
    "Receive"
};

static const value_string data_msg_type_names[] = {
    {CMP_DATA_MSG_INVALID,                  "Invalid"},
    {CMP_DATA_MSG_CAN,                      "CAN"},
    {CMP_DATA_MSG_CANFD,                    "CAN-FD"},
    {CMP_DATA_MSG_LIN,                      "LIN"},
    {CMP_DATA_MSG_FLEXRAY,                  "FlexRay"},
    {CMP_DATA_MSG_DIGITAL,                  "Digital"},
    {CMP_DATA_MSG_UART_RS_232,              "UART/RS-232"},
    {CMP_DATA_MSG_ANALOG,                   "Analog"},
    {CMP_DATA_MSG_ETHERNET,                 "Ethernet"},
    {CMP_DATA_MSG_SPI,                      "SPI"},
    {CMP_DATA_MSG_I2C,                      "I2C"},
    {CMP_DATA_MSG_GIGEVISION,               "Gigevision"},
    {CMP_DATA_MSG_MIPI_CSI2,                "MIPI CSI-2"},
    {CMP_DATA_MSG_USER_DEFINED,             "User defined"},
    {0, NULL}
};

static const true_false_string can_dom_rec = {
    "Dominant",
    "Recessive"
};

static const true_false_string can_rec_dom = {
    "Recessive",
    "Dominant"
};

static const true_false_string can_id_ide = {
    "29bit ID",
    "11bit ID"
};

static const true_false_string can_id_rtr = {
    "Remote Frame",
    "Data Frame"
};

static const true_false_string canfd_act_pas = {
    "Error active",
    "Error passive"
};


static const value_string uart_cl_names[] = {
    {CMP_UART_CL_5,                         "5 Bits"},
    {CMP_UART_CL_6,                         "6 Bits"},
    {CMP_UART_CL_7,                         "7 Bits"},
    {CMP_UART_CL_8,                         "8 Bits"},
    {CMP_UART_CL_9,                         "9 Bits"},
    {0, NULL}
};

static const value_string analog_sample_dt[] = {
    {CMP_UART_DATA_MSG_DL_16,               "A_INT16"},
    {CMP_UART_DATA_MSG_DL_32,               "A_INT32"},
    {CMP_UART_DATA_MSG_DL_RES1,             "Reserved"},
    {CMP_UART_DATA_MSG_DL_RES2,             "Reserved"},
    {0, NULL}
};

static const value_string ctrl_msg_type_names[] = {
    {CMP_CTRL_MSG_INVALID,                  "Invalid"},
    {CMP_CTRL_MSG_DSR_CTRL_MSG,             "Data Sink ready to receive Control Message"},
    {CMP_CTRL_MSG_USER_EVENT_CTRL_MSG,      "User Event Message"},
    {CMP_CTRL_MSG_VENDOR,                   "Vendor Specific Control Message"},
    {0, NULL}
};

static const value_string status_msg_type_names[] = {
    {CMP_STATUS_MSG_INVALID,                "Invalid"},
    {CMP_STATUS_MSG_CM_STAT_MSG,            "Capture Module Status"},
    {CMP_STATUS_MSG_IF_STAT_MSG,            "Interface Status"},
    {CMP_STATUS_MSG_CONF_STAT_MSG,          "Configuration Status"},
    {CMP_STATUS_MSG_DLE_STAT_MSG,           "Data Lost Status"},
    {CMP_STATUS_MSG_TSLE_STAT_MSG,          "Time Sync Lost Status"},
    {CMP_STATUS_MSG_VENDOR_STAT_MSG,        "Vendor specific Status"},
    {0, NULL}
};

static const value_string interface_status_names[] = {
    {CMP_STATUS_IFACE_DOWN_EN,              "Down and enabled"},
    {CMP_STATUS_IFACE_UP_EN,                "Up and enabled"},
    {CMP_STATUS_IFACE_DOWN_DIS,             "Down and disabled"},
    {0, NULL}
};

/* As defined by the ASAM Vendor ID registry for POD and CMP */
#define CMP_VENDOR_ID_AVL_LIST              0x0006
#define CMP_VENDOR_DSPACE                   0x000b
#define CMP_VENDOR_ETAS                     0x000c
#define CMP_VENDOR_BOSCH                    0x0027
#define CMP_VENDOR_VECTOR                   0x002d
#define CMP_VENDOR_CONTINENTAL              0x003c
#define CMP_VENDOR_MK                       0x003e
#define CMP_VENDOR_ID_ACCURATE              0x004a
#define CMP_VENDOR_RA                       0x006c
#define CMP_VENDOR_X2E                      0x00ca
#define CMP_VENDOR_INTREPIDCS               0x00f0
#define CMP_VENDOR_ID_BPLUS                 0x010f
#define CMP_VENDOR_VIGEM                    0x012a
#define CMP_VENDOR_TECHNICA                 0x019c
#define CMP_VENDOR_ID_AED_ENG               0x0241

/* As defined by the ASAM Vendor ID registry for POD and CMP */
static const value_string vendor_ids[] = {
    {CMP_VENDOR_ID_ACCURATE,                "Accurate Technologies Inc."},
    {CMP_VENDOR_ID_AED_ENG,                 "AED Engineering GmbH"},
    {CMP_VENDOR_ID_AVL_LIST,                "AVL List GmbH"},
    {CMP_VENDOR_ID_BPLUS,                   "b-plus GmbH"},
    {CMP_VENDOR_CONTINENTAL,                "Continental AG"},
    {CMP_VENDOR_DSPACE,                     "dSPACE GmbH"},
    {CMP_VENDOR_ETAS,                       "ETAS GmbH"},
    {CMP_VENDOR_INTREPIDCS,                 "Intrepid Control Systems, Inc."},
    {CMP_VENDOR_MK,                         "M&K Meß- und Kommunikationstechnik GmbH"},
    {CMP_VENDOR_RA,                         "RA Consulting GmbH"},
    {CMP_VENDOR_BOSCH,                      "Robert Bosch GmbH"},
    {CMP_VENDOR_TECHNICA,                   "Technica Engineering GmbH"},
    {CMP_VENDOR_VECTOR,                     "Vector Informatik GmbH"},
    {CMP_VENDOR_VIGEM,                      "ViGEM GmbH"},
    {CMP_VENDOR_X2E,                        "X2E GmbH"},
    {0, NULL}
};

static const value_string analog_units[] = {
    {0x01, "s"},
    {0x02, "m"},
    {0x03, "kg"},
    {0x04, "A"},
    {0x05, "K"},
    {0x06, "mol"},
    {0x07, "cd"},
    {0x08, "Hz"},
    {0x09, "rad"},
    {0x0a, "sr"},
    {0x0b, "N"},
    {0x0c, "Pa"},
    {0x0d, "J"},
    {0x0e, "W"},
    {0x0f, "C"},
    {0x10, "V"},
    {0x11, "F"},
    {0x12, "Ω"},
    {0x13, "S"},
    {0x14, "Wb"},
    {0x15, "T"},
    {0x16, "H"},
    {0x17, "°C"},
    {0x18, "lm"},
    {0x19, "lx"},
    {0x1A, "Bq"},
    {0x1B, "Gy"},
    {0x1C, "Sv"},
    {0x1D, "kat"},
    {0x1E, "m/s"},
    {0x1F, "m/s2"},
    {0x20, "m/s3"},
    {0x21, "m/s4"},
    {0x22, "rad/s"},
    {0x23, "rad/s2"},
    {0x24, "Hz/s"},
    {0x25, "m3/s"},
    {0x26, "m2"},
    {0x27, "m3"},
    {0x28, "N s"},
    {0x29, "N m s"},
    {0x2A, "N m"},
    {0x2B, "kg/m2"},
    {0x2C, "kg/m3"},
    {0x2D, "m3/kg"},
    {0x2E, "J s"},
    {0x2F, "J/kg"},
    {0x30, "J/m3"},
    {0x31, "N/m"},
    {0x32, "W/m2"},
    {0x33, "m2/s"},
    {0x34, "Pa s"},
    {0x35, "kg/s"},
    {0x36, "W/(sr m2)"},
    {0x37, "Gy/s"},
    {0x38, "m/m3"},
    {0x39, "W/m3"},
    {0x3A, "J/(m2 s)"},
    {0x3B, "kg m2"},
    {0x3C, "W/sr"},
    {0x3D, "mol/m3"},
    {0x3E, "m3/mol"},
    {0x3F, "J/(mol K)"},
    {0x40, "J/mol"},
    {0x41, "mol/kg"},
    {0x42, "kg/mol"},
    {0x45, "C/m3"},
    {0x46, "A/m2"},
    {0x47, "S/m"},
    {0x48, "F/m"},
    {0x49, "H/m"},
    {0x4A, "V/m"},
    {0x4B, "A/m"},
    {0x4C, "C/Kg"},
    {0x4D, "J/T"},
    {0x4E, "lm s"},
    {0x4F, "lx s"},
    {0x50, "cd/m2"},
    {0x51, "lm/W"},
    {0x52, "J/K"},
    {0x53, "J/(K kg)"},
    {0x54, "W/(m K)"},
    {0, NULL}
};

/********* UATs *********/

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

/* Interface UAT */
typedef struct _interface_config {
    guint     id;
    guint     bus_id;
    gchar    *name;
} interface_config_t;

/* Devices */
#define DATAFILE_ASAM_CMP_DEVICES_IDS "ASAM_CMP_devices"

static GHashTable *data_asam_cmp_devices = NULL;
static generic_one_id_string_t *asam_cmp_devices = NULL;
static guint asam_cmp_devices_num = 0;

UAT_HEX_CB_DEF(asam_cmp_devices, id, generic_one_id_string_t)
UAT_CSTRING_CB_DEF(asam_cmp_devices, name, generic_one_id_string_t)

/* Interfaces */
#define DATAFILE_ASAM_CMP_IFACE_IDS "ASAM_CMP_interfaces"

static GHashTable *data_asam_cmp_interfaces = NULL;
static interface_config_t *asam_cmp_interfaces = NULL;
static guint asam_cmp_interface_num = 0;

UAT_HEX_CB_DEF(asam_cmp_interfaces, id, interface_config_t)
UAT_CSTRING_CB_DEF(asam_cmp_interfaces, name, interface_config_t)
UAT_HEX_CB_DEF(asam_cmp_interfaces, bus_id, interface_config_t)

/*** expert info items ***/
static expert_field ef_asam_cmp_length_mismatch = EI_INIT;
static expert_field ef_asam_cmp_unsupported_crc_not_zero = EI_INIT;

/* generic UAT */
static void
tecmp_free_key(gpointer key) {
    wmem_free(wmem_epan_scope(), key);
}

static void
simple_free(gpointer data) {
    /* 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_generic_one_identifier_16bit(void *r, char **err) {
    generic_one_id_string_t *rec = (generic_one_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->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));
    }
}

static char *
ht_lookup_name(GHashTable *ht, unsigned int identifier) {
    char           *tmp = NULL;
    unsigned int   *id = NULL;

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

    id = wmem_new(wmem_epan_scope(), unsigned int);
    *id = (unsigned int)identifier;
    tmp = (char *)g_hash_table_lookup(ht, id);
    wmem_free(wmem_epan_scope(), id);

    return tmp;
}

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

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

static bool
update_interface_config(void *r, char **err) {
    interface_config_t *rec = (interface_config_t *)r;

    if (rec->id > 0xffffffff) {
        *err = ws_strdup_printf("We currently only support 32 bit identifiers (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;
    }

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

    return TRUE;
}

static void
free_interface_config_cb(void *r) {
    interface_config_t *rec = (interface_config_t *)r;
    /* freeing result of g_strdup */
    g_free(rec->name);
    rec->name = NULL;
}

static interface_config_t *
ht_lookup_channel_config(unsigned int identifier) {
    interface_config_t   *tmp = NULL;
    unsigned int       *id = NULL;

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

    id = wmem_new(wmem_epan_scope(), unsigned int);
    *id = (unsigned int)identifier;
    tmp = (interface_config_t *)g_hash_table_lookup(data_asam_cmp_interfaces, id);
    wmem_free(wmem_epan_scope(), id);

    return tmp;
}

static gchar *
ht_interface_config_to_string(unsigned int identifier) {
    interface_config_t   *tmp = ht_lookup_channel_config(identifier);
    if (tmp == NULL) {
        return NULL;
    }

    return tmp->name;
}

static guint16
ht_interface_config_to_bus_id(unsigned int identifier) {
    interface_config_t   *tmp = ht_lookup_channel_config(identifier);
    if (tmp == NULL) {
        /* 0 means basically any or none */
        return 0;
    }

    return tmp->bus_id;
}

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

    /* create new hash table */
    data_asam_cmp_devices = g_hash_table_new_full(g_int_hash, g_int_equal, &tecmp_free_key, &simple_free);
    post_update_one_id_string_template_cb(asam_cmp_devices, asam_cmp_devices_num, data_asam_cmp_devices);
}

static void
post_update_interface_config_cb(void) {
    guint  i;
    int   *key = NULL;

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

    /* create new hash table */
    data_asam_cmp_interfaces = g_hash_table_new_full(g_int_hash, g_int_equal, &tecmp_free_key, NULL);

    if (data_asam_cmp_interfaces == NULL || asam_cmp_interfaces == NULL || asam_cmp_interface_num == 0) {
        return;
    }

    for (i = 0; i < asam_cmp_interface_num; i++) {
        key = wmem_new(wmem_epan_scope(), int);
        *key = asam_cmp_interfaces[i].id;
        g_hash_table_insert(data_asam_cmp_interfaces, key, &asam_cmp_interfaces[i]);
    }
}

static void
add_device_id_text(proto_item *ti, guint16 device_id) {
    const gchar *descr = ht_lookup_name(data_asam_cmp_devices, device_id);

    if (descr != NULL) {
        proto_item_append_text(ti, " (%s)", descr);
    }
}

static void
add_interface_id_text(proto_item *ti, guint32 interface_id) {
    const gchar *descr = ht_interface_config_to_string(interface_id);

    if (descr != NULL) {
        proto_item_append_text(ti, " (%s)", descr);
    }
}

static int
dissect_asam_cmp_data_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *root_tree, proto_tree *tree, guint offset_orig) {
    proto_item *ti = NULL;
    proto_item *ti_msg_header = NULL;
    proto_item *ti_msg_payload = NULL;
    proto_tree *asam_cmp_data_msg_header_tree = NULL;
    proto_tree *asam_cmp_data_msg_payload_tree = NULL;
    proto_tree *subtree = NULL;
    guint offset = offset_orig;

    guint msg_payload_type = 0;
    guint msg_payload_length = 0;
    guint msg_payload_type_length = 0;
    guint interface_id = 0;

    static int * const asam_cmp_common_flags[] = {
        &hf_cmp_common_flag_reserved,
        &hf_cmp_common_flag_err_in_payload,
        &hf_cmp_common_flag_overflow,
        &hf_cmp_common_flag_dir_on_if,
        &hf_cmp_common_flag_seg,
        &hf_cmp_common_flag_insync,
        &hf_cmp_common_flag_recal,
        NULL
    };

    static int * const asam_cmp_can_flags[] = {
        &hf_cmp_can_flag_reserved,
        &hf_cmp_can_flag_srr_dom,
        &hf_cmp_can_flag_r0,
        &hf_cmp_can_flag_bit_err,
        &hf_cmp_can_flag_eof_err,
        &hf_cmp_can_flag_crc_del_err,
        &hf_cmp_can_flag_stuff_err,
        &hf_cmp_can_flag_form_err,
        &hf_cmp_can_flag_ack_del_err,
        &hf_cmp_can_flag_active_ack_err,
        &hf_cmp_can_flag_passive_ack_err,
        &hf_cmp_can_flag_ack_err,
        &hf_cmp_can_flag_crc_err,
        NULL
    };

    static int * const asam_cmp_canfd_flags[] = {
        &hf_cmp_canfd_flag_reserved,
        &hf_cmp_canfd_flag_esi,
        &hf_cmp_canfd_flag_brs,
        &hf_cmp_canfd_flag_srr_dom,
        &hf_cmp_canfd_flag_res,
        &hf_cmp_canfd_flag_bit_err,
        &hf_cmp_canfd_flag_eof_err,
        &hf_cmp_canfd_flag_crc_del_err,
        &hf_cmp_canfd_flag_stuff_err,
        &hf_cmp_canfd_flag_form_err,
        &hf_cmp_canfd_flag_ack_del_err,
        &hf_cmp_canfd_flag_active_ack_err,
        &hf_cmp_canfd_flag_passive_ack_err,
        &hf_cmp_canfd_flag_ack_err,
        &hf_cmp_canfd_flag_crc_err,
        NULL
    };

    static int * const asam_cmp_lin_pid[] = {
        &hf_cmp_lin_pid_parity,
        &hf_cmp_lin_pid_id,
        NULL
    };

    static int * const asam_cmp_lin_flags[] = {
        &hf_cmp_lin_flag_reserved,
        &hf_cmp_lin_flag_wup,
        &hf_cmp_lin_flag_long_dom_err,
        &hf_cmp_lin_flag_short_dom_err,
        &hf_cmp_lin_flag_framing_err,
        &hf_cmp_lin_flag_sync_err,
        &hf_cmp_lin_flag_no_slave_res_err,
        &hf_cmp_lin_flag_parity_err,
        &hf_cmp_lin_flag_col_err,
        &hf_cmp_lin_flag_checksum_err,
        NULL
    };

    static int * const asam_cmp_flexray_flags[] = {
        &hf_cmp_flexray_flag_reserved,
        &hf_cmp_flexray_flag_cas,
        &hf_cmp_flexray_flag_ppi,
        &hf_cmp_flexray_flag_wus,
        &hf_cmp_flexray_flag_sync,
        &hf_cmp_flexray_flag_sf,
        &hf_cmp_flexray_flag_nf,
        &hf_cmp_flexray_flag_crc_header_err,
        &hf_cmp_flexray_flag_crc_frame_err,
        NULL
    };

    static int * const asam_cmp_uart_flags[] = {
        &hf_cmp_uart_flag_reserved,
        &hf_cmp_uart_flag_cl,
        NULL
    };

    static int * const asam_cmp_uart_data[] = {
        &hf_cmp_uart_data_parity_err,
        &hf_cmp_uart_data_break_condition,
        &hf_cmp_uart_data_framing_err,
        &hf_cmp_uart_data_reserved,
        &hf_cmp_uart_data_data,
        NULL
    };

    static int * const asam_cmp_analog_flags[] = {
        &hf_cmp_analog_flag_reserved,
        &hf_cmp_analog_flag_sample_dt,
        NULL
    };

    static int * const asam_cmp_ethernet_flags[] = {
        &hf_cmp_eth_flag_reserved,
        &hf_cmp_eth_flag_fcs_supported,
        &hf_cmp_eth_flag_truncated,
        &hf_cmp_eth_flag_phy_err,
        &hf_cmp_eth_flag_long_err,
        &hf_cmp_eth_flag_collision,
        &hf_cmp_eth_flag_tx_down,
        &hf_cmp_eth_flag_short_err,
        &hf_cmp_eth_flag_fcs_err,
        NULL
    };

    ti_msg_header = proto_tree_add_item(tree, hf_cmp_msg_header, tvb, offset, 8, ENC_BIG_ENDIAN);
    asam_cmp_data_msg_header_tree = proto_item_add_subtree(ti_msg_header, ett_asam_cmp_header);
    proto_item_append_text(ti_msg_header, " %s", "- Data Message");

    guint64 ns = tvb_get_guint64(tvb, offset, ENC_BIG_ENDIAN);
    nstime_t timestamp = { .secs = (time_t)(ns / 1000000000), .nsecs = (int)(ns % 1000000000) };

    ti = proto_tree_add_time(asam_cmp_data_msg_header_tree, hf_cmp_msg_timestamp, tvb, offset, 8, &timestamp);
    subtree = proto_item_add_subtree(ti, ett_asam_cmp_timestamp);
    proto_tree_add_item(subtree, hf_cmp_msg_timestamp_ns, tvb, offset, 8, ENC_BIG_ENDIAN);
    offset += 8;

    ti = proto_tree_add_item_ret_uint(asam_cmp_data_msg_header_tree, hf_cmp_interface_id, tvb, offset, 4, ENC_BIG_ENDIAN, &interface_id);
    add_interface_id_text(ti, interface_id);
    offset += 4;

    proto_tree_add_bitmask(asam_cmp_data_msg_header_tree, tvb, offset, hf_cmp_msg_common_flags, ett_asam_cmp_common_flags, asam_cmp_common_flags, ENC_BIG_ENDIAN);
    offset += 1;

    proto_tree_add_item_ret_uint(asam_cmp_data_msg_header_tree, hf_cmp_payload_type, tvb, offset, 1, ENC_NA, &msg_payload_type);
    offset += 1;

    proto_tree_add_item_ret_uint(asam_cmp_data_msg_header_tree, hf_cmp_msg_payload_length, tvb, offset, 2, ENC_BIG_ENDIAN, &msg_payload_length);
    offset += 2;

    proto_item_set_end(ti_msg_header, tvb, offset);

    ti_msg_payload = proto_tree_add_item(tree, hf_cmp_msg_payload, tvb, offset, msg_payload_length, ENC_BIG_ENDIAN);
    asam_cmp_data_msg_payload_tree = proto_item_add_subtree(ti_msg_payload, ett_asam_cmp_header);
    proto_item_append_text(ti_msg_payload, " %s", "- Data Message");

    switch (msg_payload_type) {
    case CMP_DATA_MSG_INVALID: {
        col_append_str(pinfo->cinfo, COL_INFO, " (Invalid)");
        proto_item_append_text(ti_msg_payload, " %s", "(Invalid)");

        if (msg_payload_length > 0) {
            tvbuff_t *sub_tvb = tvb_new_subset_length(tvb, offset, msg_payload_length);
            call_data_dissector(sub_tvb, pinfo, tree);
            offset += (gint)msg_payload_length;
        }

        proto_item_set_end(ti_msg_payload, tvb, offset);

        break;
    }

    case CMP_DATA_MSG_CAN: {
        static int *const asam_cmp_can_id_field_11bit[] = {
            &hf_cmp_can_id_ide,
            &hf_cmp_can_id_rtr,
            &hf_cmp_can_id_res,
            &hf_cmp_can_id_11bit,
            NULL
        };

        static int *const asam_cmp_can_id_field_11bit_old[] = {
            &hf_cmp_can_id_ide,
            &hf_cmp_can_id_rtr,
            &hf_cmp_can_id_res,
            &hf_cmp_can_id_11bit_old,
            NULL
        };

        static int *const asam_cmp_can_id_field_29bit[] = {
            &hf_cmp_can_id_ide,
            &hf_cmp_can_id_rtr,
            &hf_cmp_can_id_res,
            &hf_cmp_can_id_29bit,
            NULL
        };

        static int *const asam_cmp_can_crc_field[] = {
            &hf_cmp_can_crc_crc_support,
            &hf_cmp_can_crc_res,
            &hf_cmp_can_crc_crc,
            NULL
        };

        col_append_str(pinfo->cinfo, COL_INFO, " (CAN)");
        proto_item_append_text(ti_msg_payload, " %s", "(CAN)");

        guint16 can_flags = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
        proto_tree_add_bitmask(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_can_flags, ett_asam_cmp_payload_flags, asam_cmp_can_flags, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_can_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        guint32 can_id_field = tvb_get_guint32(tvb, offset, ENC_BIG_ENDIAN);
        gboolean can_id_29bit = (can_id_field & CMP_CAN_ID_IDE) == CMP_CAN_ID_IDE;
        guint32 can_id = 0;
        if (can_id_29bit) {
            proto_tree_add_bitmask_with_flags(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_can_id, ett_asam_cmp_can_id, asam_cmp_can_id_field_29bit, ENC_BIG_ENDIAN, BMT_NO_FALSE);
            can_id = can_id_field & (CMP_CAN_ID_29BIT_MASK | CMP_CAN_ID_RTR | CMP_CAN_ID_IDE);
        } else {
            if (old_11bit_canid_encoding) {
                proto_tree_add_bitmask_with_flags(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_can_id, ett_asam_cmp_can_id, asam_cmp_can_id_field_11bit_old, ENC_BIG_ENDIAN, BMT_NO_FALSE);
                can_id = can_id_field & (CMP_CAN_ID_RTR | CMP_CAN_ID_IDE | CMP_CAN_ID_11BIT_MASK_OLD);
            } else {
                proto_tree_add_bitmask_with_flags(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_can_id, ett_asam_cmp_can_id, asam_cmp_can_id_field_11bit, ENC_BIG_ENDIAN, BMT_NO_FALSE);
                can_id = (can_id_field & (CMP_CAN_ID_RTR | CMP_CAN_ID_IDE)) + ((can_id_field & CMP_CAN_ID_11BIT_MASK) >> CMP_CAN_ID_11BIT_SHIFT);
            }
        }
        offset += 4;

        guint64 tmp64;
        proto_tree_add_bitmask_with_flags_ret_uint64(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_can_crc, ett_asam_cmp_can_crc, asam_cmp_can_crc_field, ENC_BIG_ENDIAN, BMT_NO_FALSE, &tmp64);
        if ((tmp64 & CMP_CAN_CRC_CRC_SUPP) == 0 && (tmp64 & CMP_CAN_CRC_CRC) != 0) {
            proto_tree_add_expert(asam_cmp_data_msg_payload_tree, pinfo, &ef_asam_cmp_unsupported_crc_not_zero, tvb, offset, 4);
        }
        offset += 4;

        guint32 err_pos = 0;
        proto_tree_add_item_ret_uint(asam_cmp_data_msg_payload_tree, hf_cmp_can_err_pos, tvb, offset, 2, ENC_BIG_ENDIAN, &err_pos);
        offset += 2;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_can_dlc, tvb, offset, 1, ENC_NA);
        offset += 1;

        proto_tree_add_item_ret_uint(asam_cmp_data_msg_payload_tree, hf_cmp_can_data_len, tvb, offset, 1, ENC_NA, &msg_payload_type_length);
        offset += 1;

        if (msg_payload_type_length > 0) {
            tvbuff_t *sub_tvb = tvb_new_subset_length(tvb, offset, msg_payload_type_length);

            if ((can_flags & CMP_CAN_FLAGS_ERRORS) != 0) {
                can_id = can_id | CAN_ERR_FLAG;
            }

            struct can_info can_info = { .id = can_id, .len = msg_payload_type_length, .fd = CAN_TYPE_CAN_CLASSIC, .bus_id = ht_interface_config_to_bus_id(interface_id) };
            if (!socketcan_call_subdissectors(sub_tvb, pinfo, tree, &can_info, heuristic_first)) {
                call_data_dissector(sub_tvb, pinfo, tree);
            }

            offset += (gint)msg_payload_type_length;
        }

        proto_item_set_end(ti_msg_payload, tvb, offset);
        break;
    }

    case CMP_DATA_MSG_CANFD: {
        static int * const asam_cmp_canfd_id_field_11bit[] = {
            &hf_cmp_canfd_id_ide,
            &hf_cmp_canfd_id_rrs,
            &hf_cmp_canfd_id_res,
            &hf_cmp_canfd_id_11bit,
            NULL
        };

        static int * const asam_cmp_canfd_id_field_11bit_old[] = {
            &hf_cmp_canfd_id_ide,
            &hf_cmp_canfd_id_rrs,
            &hf_cmp_canfd_id_res,
            &hf_cmp_canfd_id_11bit_old,
            NULL
        };

        static int * const asam_cmp_canfd_id_field_29bit[] = {
            &hf_cmp_canfd_id_res,
            &hf_cmp_canfd_id_rrs,
            &hf_cmp_canfd_id_ide,
            &hf_cmp_canfd_id_29bit,
            NULL
        };

        static int * const asam_cmp_canfd_crc_field_17bit[] = {
            &hf_cmp_canfd_crc_crc_support,
            &hf_cmp_canfd_crc_sbc_support,
            &hf_cmp_canfd_crc_res,
            &hf_cmp_canfd_crc_sbc_parity,
            &hf_cmp_canfd_crc_sbc,
            &hf_cmp_canfd_crc_crc17,
            NULL
        };

        static int * const asam_cmp_canfd_crc_field_21bit[] = {
            &hf_cmp_canfd_crc_crc_support,
            &hf_cmp_canfd_crc_sbc_support,
            &hf_cmp_canfd_crc_res,
            &hf_cmp_canfd_crc_sbc_parity,
            &hf_cmp_canfd_crc_sbc,
            &hf_cmp_canfd_crc_crc21,
            NULL
        };

        col_append_str(pinfo->cinfo, COL_INFO, " (CAN FD)");
        proto_item_append_text(ti_msg_payload, " %s", "(CAN FD)");

        guint16 canfd_flags = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
        proto_tree_add_bitmask(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_canfd_flags, ett_asam_cmp_payload_flags, asam_cmp_canfd_flags, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_canfd_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        guint32 can_id_field = tvb_get_guint32(tvb, offset, ENC_BIG_ENDIAN);
        gboolean can_id_29bit = (can_id_field & CMP_CANFD_ID_IDE) == CMP_CANFD_ID_IDE;
        guint32 can_id = 0;
        if (can_id_29bit) {
            proto_tree_add_bitmask_with_flags(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_canfd_id, ett_asam_cmp_can_id, asam_cmp_canfd_id_field_29bit, ENC_BIG_ENDIAN, BMT_NO_FALSE);
            can_id = can_id_field & (CMP_CAN_ID_29BIT_MASK | CMP_CANFD_ID_IDE);
        } else {
            if (old_11bit_canid_encoding) {
                proto_tree_add_bitmask_with_flags(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_canfd_id, ett_asam_cmp_can_id, asam_cmp_canfd_id_field_11bit_old, ENC_BIG_ENDIAN, BMT_NO_FALSE);
                can_id = can_id_field & (CMP_CANFD_ID_IDE | CMP_CAN_ID_11BIT_MASK_OLD);
            } else {
                proto_tree_add_bitmask_with_flags(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_canfd_id, ett_asam_cmp_can_id, asam_cmp_canfd_id_field_11bit, ENC_BIG_ENDIAN, BMT_NO_FALSE);
                can_id = (can_id_field & CMP_CANFD_ID_IDE) + ((can_id_field & CMP_CAN_ID_11BIT_MASK) >> CMP_CAN_ID_11BIT_SHIFT);
            }
        }
        offset += 4;

        /* We peek ahead to find out the DLC. 0..10: 17bit CRC, 11..15: 21bit CRC. */
        if (tvb_get_guint8(tvb, offset + 6) <= 10) {
            proto_tree_add_bitmask_with_flags(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_canfd_crc, ett_asam_cmp_can_crc, asam_cmp_canfd_crc_field_17bit, ENC_BIG_ENDIAN, BMT_NO_FALSE);
        } else {
            proto_tree_add_bitmask_with_flags(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_canfd_crc, ett_asam_cmp_can_crc, asam_cmp_canfd_crc_field_21bit, ENC_BIG_ENDIAN, BMT_NO_FALSE);
        }
        offset += 4;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_canfd_err_pos, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_canfd_dlc, tvb, offset, 1, ENC_NA);
        offset += 1;

        proto_tree_add_item_ret_uint(asam_cmp_data_msg_payload_tree, hf_cmp_canfd_data_len, tvb, offset, 1, ENC_NA, &msg_payload_type_length);
        offset += 1;

        if (msg_payload_type_length > 0) {
            tvbuff_t *sub_tvb = tvb_new_subset_length(tvb, offset, msg_payload_type_length);

            if ((canfd_flags & CMP_CANFD_FLAGS_ERRORS) != 0) {
                can_id = can_id | CAN_ERR_FLAG;
            }

            struct can_info can_info = { .id = can_id, .len = msg_payload_type_length, .fd = CAN_TYPE_CAN_FD, .bus_id = ht_interface_config_to_bus_id(interface_id) };
            if (!socketcan_call_subdissectors(sub_tvb, pinfo, tree, &can_info, heuristic_first)) {
                call_data_dissector(sub_tvb, pinfo, tree);
            }

            offset += (gint)msg_payload_type_length;
        }

        proto_item_set_end(ti_msg_payload, tvb, offset);
        break;
    }

    case CMP_DATA_MSG_LIN: {
        lin_info_t lin_info = {0, 0, 0};

        col_append_str(pinfo->cinfo, COL_INFO, " (LIN)");
        proto_item_append_text(ti_msg_payload, " %s", "(LIN)");

        proto_tree_add_bitmask(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_lin_flags, ett_asam_cmp_payload_flags, asam_cmp_lin_flags, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_lin_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        lin_info.id = tvb_get_guint8(tvb, offset) & CMP_CANFD_PID_ID_MASK;
        proto_tree_add_bitmask(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_lin_pid, ett_asam_cmp_lin_pid, asam_cmp_lin_pid, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_lin_reserved_2, tvb, offset, 1, ENC_NA);
        offset += 1;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_lin_checksum, tvb, offset, 1, ENC_NA);
        offset += 1;

        proto_tree_add_item_ret_uint(asam_cmp_data_msg_payload_tree, hf_cmp_lin_data_len, tvb, offset, 1, ENC_NA, &msg_payload_type_length);
        offset += 1;

        if (msg_payload_type_length > 0) {
            tvbuff_t *sub_tvb = tvb_new_subset_length(tvb, offset, msg_payload_type_length);

            lin_info.bus_id = ht_interface_config_to_bus_id(interface_id);
            lin_info.len = msg_payload_type_length;

            if (!dissector_try_uint_new(lin_subdissector_table, lin_info.id | (lin_info.bus_id << 16), sub_tvb, pinfo, tree, FALSE, &lin_info)) {
                if (!dissector_try_uint_new(lin_subdissector_table, lin_info.id, sub_tvb, pinfo, tree, FALSE, &lin_info)) {
                    call_data_dissector(sub_tvb, pinfo, tree);
                }
            }

            offset += (gint)msg_payload_type_length;
        }

        proto_item_set_end(ti_msg_payload, tvb, offset);
        break;
    }

    case CMP_DATA_MSG_FLEXRAY: {
        flexray_info_t fr_info = {0, 0, 0, 0};
        guint32 tmp;

        col_append_str(pinfo->cinfo, COL_INFO, " (FlexRay)");
        proto_item_append_text(ti_msg_payload, " %s", "(FlexRay)");

        guint16 flags = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
        proto_tree_add_bitmask(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_flexray_flags, ett_asam_cmp_payload_flags, asam_cmp_flexray_flags, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_flexray_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_flexray_header_crc, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item_ret_uint(asam_cmp_data_msg_payload_tree, hf_cmp_flexray_frame_id, tvb, offset, 2, ENC_BIG_ENDIAN, &tmp);
        fr_info.id = (guint16)tmp;
        offset += 2;

        proto_tree_add_item_ret_uint(asam_cmp_data_msg_payload_tree, hf_cmp_flexray_cycle, tvb, offset, 1, ENC_NA, &tmp);
        fr_info.cc= (guint8)tmp;
        offset += 1;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_flexray_frame_crc, tvb, offset, 3, ENC_BIG_ENDIAN);
        offset += 3;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_flexray_reserved_2, tvb, offset, 1, ENC_NA);
        offset += 1;

        proto_tree_add_item_ret_uint(asam_cmp_data_msg_payload_tree, hf_cmp_flexray_data_len, tvb, offset, 1, ENC_NA, &msg_payload_type_length);
        offset += 1;

        if (msg_payload_type_length > 0 && (flags & CMP_FLEXRAY_FLAGS_NF) == 0) {
            fr_info.bus_id = ht_interface_config_to_bus_id(interface_id);
            fr_info.ch = 0; /* Assuming A! Could this be B? */

            tvbuff_t *sub_tvb = tvb_new_subset_length(tvb, offset, msg_payload_type_length);
            if (!flexray_call_subdissectors(sub_tvb, pinfo, tree, &fr_info, heuristic_first)) {
                call_data_dissector(sub_tvb, pinfo, tree);
            }
        }
        offset += (gint)msg_payload_type_length;

        proto_item_set_end(ti_msg_payload, tvb, offset);
        break;
    }

    case CMP_DATA_MSG_UART_RS_232: {
        col_append_str(pinfo->cinfo, COL_INFO, " (UART/RS-232)");
        proto_item_append_text(ti_msg_payload, " %s", "(UART/RS-232)");

        guint64 char_len;
        proto_tree_add_bitmask_ret_uint64(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_uart_flags, ett_asam_cmp_payload_flags, asam_cmp_uart_flags, ENC_BIG_ENDIAN, &char_len);
        char_len = char_len & 0x07;
        offset += 2;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_uart_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item_ret_uint(asam_cmp_data_msg_payload_tree, hf_cmp_uart_data_len, tvb, offset, 2, ENC_BIG_ENDIAN, &msg_payload_type_length);
        offset += 2;

        if (msg_payload_type_length > 0) {
            for (guint i = 0; i < msg_payload_type_length; i++) {
                guint8 *buf = NULL;
                ti = proto_tree_add_bitmask(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_uart_data, ett_asam_cmp_uart_data, asam_cmp_uart_data, ENC_BIG_ENDIAN);
                if (char_len == CMP_UART_CL_7 || char_len == CMP_UART_CL_8) {
                    buf = tvb_get_string_enc(pinfo->pool, tvb, offset + 1, 1, ENC_ASCII | ENC_NA);

                    /* sanitizing buffer */
                    if (buf[0] > 0x00 && buf[0] < 0x20) {
                        buf[0] = 0x20;
                    } else {
                        proto_item_append_text(ti, ": %s", buf);
                    }
                }
                offset += 2;
            }
        }

        proto_item_set_end(ti_msg_payload, tvb, offset);
        break;
    }

    case CMP_DATA_MSG_ANALOG: {
        col_append_str(pinfo->cinfo, COL_INFO, " (Analog)");
        proto_item_append_text(ti_msg_payload, " %s", "(Analog)");

        guint64 flags;
        proto_tree_add_bitmask_ret_uint64(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_analog_flags, ett_asam_cmp_payload_flags, asam_cmp_analog_flags, ENC_BIG_ENDIAN, &flags);
        offset += 2;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_analog_reserved, tvb, offset, 1, ENC_NA);
        offset += 1;

        guint analog_unit;
        proto_tree_add_item_ret_uint(asam_cmp_data_msg_payload_tree, hf_cmp_analog_unit, tvb, offset, 1, ENC_NA, &analog_unit);
        const gchar *unit_symbol;
        unit_symbol = try_val_to_str(analog_unit, analog_units);
        offset += 1;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_analog_sample_interval, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;

        gfloat sample_offset;
        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_analog_sample_offset, tvb, offset, 4, ENC_BIG_ENDIAN);
        sample_offset = tvb_get_ieee_float(tvb, offset, ENC_BIG_ENDIAN);
        offset += 4;

        gfloat sample_scalar;
        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_analog_sample_scalar, tvb, offset, 4, ENC_BIG_ENDIAN);
        sample_scalar = tvb_get_ieee_float(tvb, offset, ENC_BIG_ENDIAN);
        offset += 4;

        gint data_left = msg_payload_length - 16;
        if (data_left > 0) {
            switch (flags & 0x03) {
            case 0: /* INT16 */
                while (data_left >= 2) {
                    gint16 data_sample = tvb_get_gint16(tvb, offset, ENC_BIG_ENDIAN);
                    ti = proto_tree_add_double(asam_cmp_data_msg_payload_tree, hf_cmp_analog_sample, tvb, offset, 2, ((double)data_sample * sample_scalar + sample_offset));

                    if (unit_symbol != NULL) {
                        proto_item_append_text(ti, " %s", unit_symbol);
                    }

                    data_left -= 2;
                    offset += 2;
                }
                break;
            case 1: /* INT32 */
                while (data_left >= 4) {
                    gint32 data_sample = tvb_get_gint32(tvb, offset, ENC_BIG_ENDIAN);
                    ti = proto_tree_add_double(asam_cmp_data_msg_payload_tree, hf_cmp_analog_sample, tvb, offset, 4, ((double)data_sample * sample_scalar + sample_offset));

                    if (unit_symbol != NULL) {
                        proto_item_append_text(ti, " %s", unit_symbol);
                    }

                    data_left -= 4;
                    offset += 4;
                }
                break;
            }
        }

        proto_item_set_end(ti_msg_payload, tvb, offset);
        break;
    }

    case CMP_DATA_MSG_ETHERNET:
        col_append_str(pinfo->cinfo, COL_INFO, " (Ethernet)");
        proto_item_append_text(ti_msg_payload, " %s", "(Ethernet)");

        proto_tree_add_bitmask(asam_cmp_data_msg_payload_tree, tvb, offset, hf_cmp_eth_flags, ett_asam_cmp_payload_flags, asam_cmp_ethernet_flags, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_data_msg_payload_tree, hf_cmp_eth_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item_ret_uint(asam_cmp_data_msg_payload_tree, hf_cmp_eth_payload_length, tvb, offset, 2, ENC_BIG_ENDIAN, &msg_payload_type_length);
        offset += 2;

        if (msg_payload_type_length > 0) {
            tvbuff_t *sub_tvb = tvb_new_subset_length(tvb, offset, (gint)msg_payload_type_length);
            call_dissector(eth_handle, sub_tvb, pinfo, root_tree);
        }
        offset += (gint)msg_payload_type_length;

        proto_item_set_end(ti_msg_payload, tvb, offset);
        break;

    case CMP_DATA_MSG_USER_DEFINED:
        col_append_str(pinfo->cinfo, COL_INFO, " (User defined)");

        if (msg_payload_length > 0) {
            tvbuff_t *sub_tvb = tvb_new_subset_length(tvb, offset, msg_payload_length);
            call_data_dissector(sub_tvb, pinfo, tree);
            offset += (gint)msg_payload_length;
        }

        proto_item_set_end(ti_msg_payload, tvb, offset);
        break;

    default:
        if (msg_payload_length > 0) {
            offset += (gint)msg_payload_length;
        }

        proto_item_set_end(ti_msg_payload, tvb, offset);
        break;
    }

    if ((CMP_MSG_HEADER_LEN + msg_payload_length) < (offset - offset_orig)) {
        proto_tree_add_expert(tree, pinfo, &ef_asam_cmp_length_mismatch, tvb, offset_orig + CMP_MSG_HEADER_LEN, msg_payload_length);
        proto_item_set_end(ti_msg_payload, tvb, offset);
    }

    return CMP_MSG_HEADER_LEN + msg_payload_length;
}

static int
dissect_asam_cmp_ctrl_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *root_tree _U_, proto_tree *tree, guint offset_orig) {

    proto_item *ti = NULL;
    proto_item *ti_msg_header = NULL;
    proto_item *ti_msg_payload = NULL;
    proto_tree *asam_cmp_ctrl_msg_header_tree = NULL;
    proto_tree *asam_cmp_ctrl_msg_payload_tree = NULL;
    proto_tree *subtree = NULL;
    guint asam_cmp_ctrl_msg_payload_type = 0;
    guint asam_cmp_ctrl_msg_payload_length = 0;
    guint offset = offset_orig;

    static int * const asam_cmp_common_flags[] = {
        &hf_cmp_common_flag_reserved_ctrl,
        &hf_cmp_common_flag_seg,
        &hf_cmp_common_flag_insync,
        &hf_cmp_common_flag_recal,
        NULL
    };

    ti_msg_header = proto_tree_add_item(tree, hf_cmp_msg_header, tvb, offset, 8, ENC_BIG_ENDIAN);
    asam_cmp_ctrl_msg_header_tree = proto_item_add_subtree(ti_msg_header, ett_asam_cmp_header);
    proto_item_append_text(ti_msg_header, " %s", "- Control Message");

    guint64 ns = tvb_get_guint64(tvb, offset, ENC_BIG_ENDIAN);
    nstime_t timestamp = { .secs = (time_t)(ns / 1000000000), .nsecs = (int)(ns % 1000000000) };

    ti = proto_tree_add_time(asam_cmp_ctrl_msg_header_tree, hf_cmp_msg_timestamp, tvb, offset, 8, &timestamp);

    subtree = proto_item_add_subtree(ti, ett_asam_cmp_timestamp);
    proto_tree_add_item(subtree, hf_cmp_msg_timestamp_ns, tvb, offset, 8, ENC_BIG_ENDIAN);
    offset += 8;

    proto_tree_add_item(asam_cmp_ctrl_msg_header_tree, hf_cmp_ctrl_msg_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset += 4;

    proto_tree_add_bitmask(asam_cmp_ctrl_msg_header_tree, tvb, offset, hf_cmp_msg_common_flags, ett_asam_cmp_common_flags, asam_cmp_common_flags, ENC_BIG_ENDIAN);
    offset += 1;

    proto_tree_add_item_ret_uint(asam_cmp_ctrl_msg_header_tree, hf_cmp_ctrl_msg_payload_type, tvb, offset, 1, ENC_NA, &asam_cmp_ctrl_msg_payload_type);
    offset += 1;

    proto_tree_add_item_ret_uint(asam_cmp_ctrl_msg_header_tree, hf_cmp_msg_payload_length, tvb, offset, 2, ENC_BIG_ENDIAN, &asam_cmp_ctrl_msg_payload_length);
    offset += 2;

    proto_item_set_end(ti_msg_header, tvb, offset);

    ti_msg_payload = proto_tree_add_item(tree, hf_cmp_msg_payload, tvb, offset, asam_cmp_ctrl_msg_payload_length, ENC_BIG_ENDIAN);
    asam_cmp_ctrl_msg_payload_tree = proto_item_add_subtree(ti_msg_payload, ett_asam_cmp_header);
    proto_item_append_text(ti_msg_payload, " %s", "- Control Message");

    switch (asam_cmp_ctrl_msg_payload_type) {
    case CMP_CTRL_MSG_INVALID:
        col_append_str(pinfo->cinfo, COL_INFO, " (Invalid/Padding)");
        proto_item_append_text(ti_msg_payload, " %s", "(Invalid/Padding)");
        proto_item_set_end(ti_msg_payload, tvb, offset + asam_cmp_ctrl_msg_payload_length);

        return tvb_reported_length_remaining(tvb, offset_orig);
        break;

    case CMP_CTRL_MSG_DSR_CTRL_MSG:
        col_append_str(pinfo->cinfo, COL_INFO, " (Data Sink Ready)");
        proto_item_append_text(ti_msg_payload, " %s", "(Data Sink Ready)");

        proto_tree_add_item(asam_cmp_ctrl_msg_payload_tree, hf_cmp_ctrl_msg_device_id, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        break;

    case CMP_CTRL_MSG_USER_EVENT_CTRL_MSG:
        col_append_str(pinfo->cinfo, COL_INFO, " (User Event)");
        proto_item_append_text(ti_msg_payload, " %s", "(User Event)");

        proto_tree_add_item(asam_cmp_ctrl_msg_payload_tree, hf_cmp_ctrl_msg_event_id, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;

        break;

    case CMP_CTRL_MSG_VENDOR:
        col_append_str(pinfo->cinfo, COL_INFO, " (Vendor specific)");
        proto_item_append_text(ti_msg_payload, " %s", "(Vendor specific)");

        proto_tree_add_item(asam_cmp_ctrl_msg_payload_tree, hf_cmp_ctrl_msg_vendor_id, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;
        asam_cmp_ctrl_msg_payload_length -= 2;

        proto_tree_add_item(asam_cmp_ctrl_msg_payload_tree, hf_cmp_ctrl_msg_vendor_payload_type, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;
        asam_cmp_ctrl_msg_payload_length -= 2;

        if ((asam_cmp_ctrl_msg_payload_length) > 0) {
            tvbuff_t *sub_tvb = tvb_new_subset_length(tvb, offset, asam_cmp_ctrl_msg_payload_length);
            call_data_dissector(sub_tvb, pinfo, tree);
            offset += (gint)asam_cmp_ctrl_msg_payload_length;
        }

        /* we changed the payload length, so lets skip the length check by leaving */
        return (offset + asam_cmp_ctrl_msg_payload_length) - offset_orig;
        break;

    default:
        if (asam_cmp_ctrl_msg_payload_length > 0) {
            offset += (gint)asam_cmp_ctrl_msg_payload_length;
        }

        proto_item_set_end(ti_msg_payload, tvb, offset);
        break;
    }

    if ((CMP_MSG_HEADER_LEN + asam_cmp_ctrl_msg_payload_length) < (offset - offset_orig)) {
        proto_tree_add_expert(tree, pinfo, &ef_asam_cmp_length_mismatch, tvb, offset_orig + CMP_MSG_HEADER_LEN, asam_cmp_ctrl_msg_payload_length);
        proto_item_set_end(ti_msg_payload, tvb, offset);
    }

    return CMP_MSG_HEADER_LEN + asam_cmp_ctrl_msg_payload_length;
}

static int
dissect_asam_cmp_status_interface_support_mask(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint offset_orig, guint8 interface_type) {
    guint offset = offset_orig;
    guint64 temp = 0;

    static int *const can_feature_support[] = {
        &hf_cmp_iface_feat_can_srr_dom,
        &hf_cmp_iface_feat_can_r0,
        &hf_cmp_iface_feat_can_eof_err,
        &hf_cmp_iface_feat_can_crc_del_err,
        &hf_cmp_iface_feat_can_ack_del_err,
        &hf_cmp_iface_feat_can_act_ack,
        &hf_cmp_iface_feat_can_pas_ack,
        NULL
    };

    static int *const canfd_feature_support[] = {
        &hf_cmp_iface_feat_canfd_esi_dom,
        &hf_cmp_iface_feat_canfd_brs_dom,
        &hf_cmp_iface_feat_canfd_srr_dom,
        &hf_cmp_iface_feat_canfd_rsvd,
        &hf_cmp_iface_feat_canfd_eof_err,
        &hf_cmp_iface_feat_canfd_crc_del_err,
        &hf_cmp_iface_feat_canfd_ack_del_err,
        &hf_cmp_iface_feat_canfd_act_ack,
        &hf_cmp_iface_feat_canfd_pas_ack,
        NULL
    };

    static int *const lin_feature_support[] = {
        &hf_cmp_iface_feat_lin_wup,
        &hf_cmp_iface_feat_lin_long_dom_err,
        &hf_cmp_iface_feat_lin_short_dom_err,
        &hf_cmp_iface_feat_lin_framing_err,
        &hf_cmp_iface_feat_lin_sync_err,
        NULL
    };

    static int *const eth_feature_support[] = {
        &hf_cmp_iface_feat_eth_trunc,
        &hf_cmp_iface_feat_eth_phy_err,
        &hf_cmp_iface_feat_eth_too_long,
        NULL
    };

    switch (interface_type) {
    case CMP_DATA_MSG_CAN:
        proto_tree_add_bitmask_ret_uint64(tree, tvb, offset, hf_cmp_iface_feat, ett_asam_cmp_status_feature_support, can_feature_support, ENC_BIG_ENDIAN, &temp);
        break;

    case CMP_DATA_MSG_CANFD:
        proto_tree_add_bitmask_ret_uint64(tree, tvb, offset, hf_cmp_iface_feat, ett_asam_cmp_status_feature_support, canfd_feature_support, ENC_BIG_ENDIAN, &temp);
        break;

    case CMP_DATA_MSG_LIN:
        proto_tree_add_bitmask_ret_uint64(tree, tvb, offset, hf_cmp_iface_feat, ett_asam_cmp_status_feature_support, lin_feature_support, ENC_BIG_ENDIAN, &temp);
        break;

    case CMP_DATA_MSG_ETHERNET:
        proto_tree_add_bitmask_ret_uint64(tree, tvb, offset, hf_cmp_iface_feat, ett_asam_cmp_status_feature_support, eth_feature_support, ENC_BIG_ENDIAN, &temp);
        break;

    default:
        proto_tree_add_item(tree, hf_cmp_iface_feat, tvb, offset, 4, ENC_BIG_ENDIAN);
    }

    offset += 4;

    return offset - offset_orig;
}

static int
dissect_asam_cmp_status_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *root_tree _U_, proto_tree *tree, guint offset_orig) {
    proto_item *ti = NULL;
    proto_item *ti_msg_header = NULL;
    proto_item *ti_msg_payload = NULL;
    proto_item *ti_interface = NULL;
    proto_item *ti_stream_ids = NULL;
    proto_tree *asam_cmp_status_msg_header_tree = NULL;
    proto_tree *asam_cmp_status_msg_payload_tree = NULL;
    proto_tree *subtree = NULL;
    proto_tree *stream_ids_subtree = NULL;
    guint offset = offset_orig;

    guint asam_cmp_status_msg_payload_type = 0;
    guint asam_cmp_status_msg_payload_length = 0;
    guint asam_cmp_status_msg_cm_dev_desc_length = 0;
    guint asam_cmp_status_msg_cm_sn_length = 0;
    guint asam_cmp_status_msg_cm_hw_ver_length = 0;
    guint asam_cmp_status_msg_cm_sw_ver_length = 0;
    guint asam_cmp_status_msg_vendor_data_length = 0;
    guint asam_cmp_status_msg_iface_stream_id_count = 0;
    guint64 uptime = 0;
    const gchar *descr = NULL;

    static int * const asam_cmp_common_flags[] = {
        &hf_cmp_common_flag_reserved_ctrl,
        &hf_cmp_common_flag_seg,
        &hf_cmp_common_flag_insync,
        &hf_cmp_common_flag_recal,
        NULL
    };

    static int * const asam_cmp_status_cm_flags[] = {
        &hf_cmp_gptp_flags_reserved,
        &hf_cmp_gptp_flags_freq_traceable,
        &hf_cmp_gptp_flags_time_traceable,
        &hf_cmp_gptp_flags_ptp_timescale,
        &hf_cmp_gptp_flags_cur_utco_valid,
        &hf_cmp_gptp_flags_leap59,
        &hf_cmp_gptp_flags_leap61,
        NULL
    };

    static int * const asam_cmp_status_timeloss_error_flags[] = {
        &hf_cmp_timeloss_error_flags_reserved,
        &hf_cmp_timeloss_error_flags_delta,
        &hf_cmp_timeloss_error_flags_insync,
        &hf_cmp_timeloss_error_flags_ts,
        NULL
    };

    ti_msg_header = proto_tree_add_item(tree, hf_cmp_msg_header, tvb, offset, 16, ENC_BIG_ENDIAN);
    asam_cmp_status_msg_header_tree = proto_item_add_subtree(ti_msg_header, ett_asam_cmp_header);
    proto_item_append_text(ti_msg_header, " %s", "- Status Message");

    guint64 ns = tvb_get_guint64(tvb, offset, ENC_BIG_ENDIAN);
    nstime_t timestamp = { .secs = (time_t)(ns / 1000000000), .nsecs = (int)(ns % 1000000000) };

    ti = proto_tree_add_time(asam_cmp_status_msg_header_tree, hf_cmp_msg_timestamp, tvb, offset, 8, &timestamp);
    subtree = proto_item_add_subtree(ti, ett_asam_cmp_timestamp);
    proto_tree_add_item(subtree, hf_cmp_msg_timestamp_ns, tvb, offset, 8, ENC_BIG_ENDIAN);
    offset += 8;

    proto_tree_add_item(asam_cmp_status_msg_header_tree, hf_cmp_msg_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(asam_cmp_status_msg_header_tree, hf_cmp_msg_vendor_id, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_bitmask(asam_cmp_status_msg_header_tree, tvb, offset, hf_cmp_msg_common_flags, ett_asam_cmp_common_flags, asam_cmp_common_flags, ENC_BIG_ENDIAN);
    offset += 1;

    proto_tree_add_item_ret_uint(asam_cmp_status_msg_header_tree, hf_cmp_status_msg_payload_type, tvb, offset, 1, ENC_NA, &asam_cmp_status_msg_payload_type);
    offset += 1;

    proto_tree_add_item_ret_uint(asam_cmp_status_msg_header_tree, hf_cmp_msg_payload_length, tvb, offset, 2, ENC_BIG_ENDIAN, &asam_cmp_status_msg_payload_length);
    offset += 2;

    proto_item_set_end(ti_msg_header, tvb, offset);

    ti_msg_payload = proto_tree_add_item(tree, hf_cmp_msg_payload, tvb, offset, asam_cmp_status_msg_payload_length, ENC_BIG_ENDIAN);
    asam_cmp_status_msg_payload_tree = proto_item_add_subtree(ti_msg_payload, ett_asam_cmp_header);
    proto_item_append_text(ti_msg_payload, " %s", "- Status Message");

    switch (asam_cmp_status_msg_payload_type) {
    case CMP_STATUS_MSG_INVALID:
        col_append_str(pinfo->cinfo, COL_INFO, " (Invalid/Padding)");
        proto_item_append_text(ti_msg_payload, " %s", "(Invalid/Padding)");
        proto_item_set_end(ti_msg_payload, tvb, offset + asam_cmp_status_msg_payload_length);

        return tvb_reported_length_remaining(tvb, offset_orig);
        break;

    case CMP_STATUS_MSG_CM_STAT_MSG:
        col_append_str(pinfo->cinfo, COL_INFO, " (CM)");
        proto_item_append_text(ti_msg_payload, " %s", "(CM)");

        ti = proto_tree_add_item_ret_uint64(asam_cmp_status_msg_payload_tree, hf_cmp_status_msg_cm_uptime_ns, tvb, offset, 8, ENC_BIG_ENDIAN, &uptime);

        subtree = proto_item_add_subtree(ti, ett_asam_cmp_status_cm_uptime);
        proto_tree_add_uint64(subtree, hf_cmp_status_msg_cm_uptime_s, tvb, offset, 8, uptime / 1000000000);
        offset += 8;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_msg_gm_identity, tvb, offset, 8, ENC_BIG_ENDIAN);
        offset += 8;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_msg_gm_clock_quality, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_msg_current_utc_offset, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_msg_time_source, tvb, offset, 1, ENC_NA);
        offset += 1;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_msg_domain_num, tvb, offset, 1, ENC_NA);
        offset += 1;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_msg_res, tvb, offset, 1, ENC_NA);
        offset += 1;

        proto_tree_add_bitmask(asam_cmp_status_msg_payload_tree, tvb, offset, hf_cmp_gptp_flags, ett_asam_cmp_status_cm_flags, asam_cmp_status_cm_flags, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item_ret_uint(asam_cmp_status_msg_payload_tree, hf_cmp_status_dev_desc_length, tvb, offset, 2, ENC_BIG_ENDIAN, &asam_cmp_status_msg_cm_dev_desc_length);
        offset += 2;

        if ((asam_cmp_status_msg_cm_dev_desc_length) > 0) {
            asam_cmp_status_msg_cm_dev_desc_length += (asam_cmp_status_msg_cm_dev_desc_length % 2); /* padding to 16bit */
            proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_dev_desc, tvb, offset, asam_cmp_status_msg_cm_dev_desc_length, ENC_UTF_8 | ENC_NA);
            offset += (gint)asam_cmp_status_msg_cm_dev_desc_length;
        }

        proto_tree_add_item_ret_uint(asam_cmp_status_msg_payload_tree, hf_cmp_status_sn_length, tvb, offset, 2, ENC_BIG_ENDIAN, &asam_cmp_status_msg_cm_sn_length);
        offset += 2;

        if ((asam_cmp_status_msg_cm_sn_length) > 0) {
            asam_cmp_status_msg_cm_sn_length += (asam_cmp_status_msg_cm_sn_length % 2); /* padding to 16bit */
            proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_sn, tvb, offset, asam_cmp_status_msg_cm_sn_length, ENC_UTF_8 | ENC_NA);
            offset += (gint)asam_cmp_status_msg_cm_sn_length;
        }

        proto_tree_add_item_ret_uint(asam_cmp_status_msg_payload_tree, hf_cmp_status_hw_ver_length, tvb, offset, 2, ENC_BIG_ENDIAN, &asam_cmp_status_msg_cm_hw_ver_length);
        offset += 2;

        if ((asam_cmp_status_msg_cm_hw_ver_length) > 0) {
            asam_cmp_status_msg_cm_hw_ver_length += (asam_cmp_status_msg_cm_hw_ver_length % 2); /* padding to 16bit */
            proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_hw_ver, tvb, offset, asam_cmp_status_msg_cm_hw_ver_length, ENC_UTF_8 | ENC_NA);
            offset += (gint)asam_cmp_status_msg_cm_hw_ver_length;
        }

        proto_tree_add_item_ret_uint(asam_cmp_status_msg_payload_tree, hf_cmp_status_sw_ver_length, tvb, offset, 2, ENC_BIG_ENDIAN, &asam_cmp_status_msg_cm_sw_ver_length);
        offset += 2;

        if ((asam_cmp_status_msg_cm_sw_ver_length) > 0) {
            asam_cmp_status_msg_cm_sw_ver_length += (asam_cmp_status_msg_cm_sw_ver_length % 2); /* padding to 16bit */
            proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_sw_ver, tvb, offset, asam_cmp_status_msg_cm_sw_ver_length, ENC_UTF_8 | ENC_NA);
            offset += (gint)asam_cmp_status_msg_cm_sw_ver_length;
        }

        proto_tree_add_item_ret_uint(asam_cmp_status_msg_payload_tree, hf_cmp_status_vendor_data_length, tvb, offset, 2, ENC_BIG_ENDIAN, &asam_cmp_status_msg_vendor_data_length);
        offset += 2;

        if ((asam_cmp_status_msg_vendor_data_length) > 0) {
            proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_vendor_data, tvb, offset, asam_cmp_status_msg_vendor_data_length, ENC_NA);
            offset += (gint)asam_cmp_status_msg_vendor_data_length;
        }
        break;

    case CMP_STATUS_MSG_IF_STAT_MSG:
        col_append_str(pinfo->cinfo, COL_INFO, " (Interface)");
        proto_item_append_text(ti_msg_payload, " %s", "(Interface)");

        /* each entry is 40 bytes, header is 16 bytes */
        while (tvb_reported_length_remaining(tvb, offset) >= 40 && offset - offset_orig + 40 <= 16 + asam_cmp_status_msg_payload_length) {
            guint32 ifaceid;
            guint32 ifacetype;

            ti_interface = proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_iface_interface, tvb, offset, 34, ENC_NA);
            subtree = proto_item_add_subtree(ti_interface, ett_asam_cmp_status_interface);

            ti = proto_tree_add_item_ret_uint(subtree, hf_cmp_iface_iface_id, tvb, offset, 4, ENC_BIG_ENDIAN, &ifaceid);
            descr = ht_interface_config_to_string(ifaceid);
            if (descr != NULL) {
                proto_item_append_text(ti, " (%s)", descr);
            }
            offset += 4;

            proto_tree_add_item(subtree, hf_cmp_iface_msg_total_rx, tvb, offset, 4, ENC_BIG_ENDIAN);
            offset += 4;

            proto_tree_add_item(subtree, hf_cmp_iface_msg_total_tx, tvb, offset, 4, ENC_BIG_ENDIAN);
            offset += 4;

            proto_tree_add_item(subtree, hf_cmp_iface_msg_dropped_rx, tvb, offset, 4, ENC_BIG_ENDIAN);
            offset += 4;

            proto_tree_add_item(subtree, hf_cmp_iface_msg_dropped_tx, tvb, offset, 4, ENC_BIG_ENDIAN);
            offset += 4;

            proto_tree_add_item(subtree, hf_cmp_iface_errs_total_rx, tvb, offset, 4, ENC_BIG_ENDIAN);
            offset += 4;

            proto_tree_add_item(subtree, hf_cmp_iface_errs_total_tx, tvb, offset, 4, ENC_BIG_ENDIAN);
            offset += 4;

            proto_tree_add_item_ret_uint(subtree, hf_cmp_iface_iface_type, tvb, offset, 1, ENC_NA, &ifacetype);
            offset += 1;

            if (descr != NULL) {
                proto_item_append_text(ti_interface, " %s, Type: %s", descr, val_to_str(ifacetype, data_msg_type_names, "Unknown (0x%x)"));
            } else {
                proto_item_append_text(ti_interface, " 0x%x, Type: %s", ifaceid, val_to_str(ifacetype, data_msg_type_names, "Unknown (0x%x)"));
            }

            proto_tree_add_item(subtree, hf_cmp_iface_iface_status, tvb, offset, 1, ENC_NA);
            offset += 1;

            proto_tree_add_item(subtree, hf_cmp_iface_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
            offset += 2;

            offset += dissect_asam_cmp_status_interface_support_mask(tvb, pinfo, subtree, offset, (guint8)ifacetype);

            proto_tree_add_item_ret_uint(subtree, hf_cmp_iface_stream_id_cnt, tvb, offset, 2, ENC_BIG_ENDIAN, &asam_cmp_status_msg_iface_stream_id_count);
            offset += 2;

            if ((asam_cmp_status_msg_iface_stream_id_count) > 0) {
                ti_stream_ids = proto_tree_add_item(subtree, hf_cmp_iface_stream_ids, tvb, offset, asam_cmp_status_msg_iface_stream_id_count, ENC_NA);
                stream_ids_subtree = proto_item_add_subtree(ti_stream_ids, ett_asam_cmp_status_stream_ids);

                for (guint i = 0; i < asam_cmp_status_msg_iface_stream_id_count; i++) {
                    proto_tree_add_item(stream_ids_subtree, hf_cmp_iface_stream_id, tvb, offset, 1, ENC_NA);
                    offset += 1;
                }
                offset += (asam_cmp_status_msg_iface_stream_id_count % 2); /* padding to 16bit */
            }

            proto_tree_add_item_ret_uint(subtree, hf_cmp_iface_vendor_data_len, tvb, offset, 2, ENC_BIG_ENDIAN, &asam_cmp_status_msg_vendor_data_length);
            offset += 2;

            if ((asam_cmp_status_msg_vendor_data_length) > 0) {
                proto_tree_add_item(subtree, hf_cmp_iface_vendor_data, tvb, offset, asam_cmp_status_msg_vendor_data_length, ENC_NA);
                offset += (gint)asam_cmp_status_msg_vendor_data_length;
            }

            proto_item_set_end(ti_interface, tvb, offset);
        }
        break;

    case CMP_STATUS_MSG_CONF_STAT_MSG:
        col_append_str(pinfo->cinfo, COL_INFO, " (Configuration)");
        proto_item_append_text(ti_msg_payload, " %s", "(Configuration)");

        if ((asam_cmp_status_msg_payload_length) > 0) {
            proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_msg_config, tvb, offset, asam_cmp_status_msg_payload_length, ENC_NA);
            offset += (gint)asam_cmp_status_msg_payload_length;
        }
        break;

    case CMP_STATUS_MSG_DLE_STAT_MSG:
        col_append_str(pinfo->cinfo, COL_INFO, " (Data Lost Event)");
        proto_item_append_text(ti_msg_payload, " %s", "(Data Lost Event)");

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_dataloss_data_sink_port, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_dataloss_device_id, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_dataloss_reserved, tvb, offset, 1, ENC_NA);
        offset += 1;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_dataloss_stream_id, tvb, offset, 1, ENC_NA);
        offset += 1;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_dataloss_last_ssq_value, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_dataloss_current_ssq_value, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;
        break;

    case CMP_STATUS_MSG_TSLE_STAT_MSG:
        col_append_str(pinfo->cinfo, COL_INFO, " (Time Sync Lost Event)");
        proto_item_append_text(ti_msg_payload, " %s", "(Time Sync Lost Event)");

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_timeloss_port_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_timeloss_device_id, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_bitmask(asam_cmp_status_msg_payload_tree, tvb, offset, hf_cmp_timeloss_error_flags, ett_asam_cmp_status_timeloss_flags, asam_cmp_status_timeloss_error_flags, ENC_BIG_ENDIAN);
        offset += 1;
        break;

    case CMP_STATUS_MSG_VENDOR_STAT_MSG:
        col_append_str(pinfo->cinfo, COL_INFO, " (Vendor specific)");
        proto_item_append_text(ti_msg_payload, " %s", "(Vendor specific)");

        if ((asam_cmp_status_msg_payload_length) > 0) {
            proto_tree_add_item(asam_cmp_status_msg_payload_tree, hf_cmp_status_msg_vendor_specific, tvb, offset, asam_cmp_status_msg_payload_length, ENC_NA);
            offset += (gint)asam_cmp_status_msg_payload_length;
        }
        break;

    default:
        if (asam_cmp_status_msg_payload_length > 0) {
            offset += (gint)asam_cmp_status_msg_payload_length;
        }

        proto_item_set_end(ti_msg_payload, tvb, offset);
        break;
    }

    if ((CMP_MSG_HEADER_LEN + asam_cmp_status_msg_payload_length) < (offset - offset_orig)) {
        proto_tree_add_expert(tree, pinfo, &ef_asam_cmp_length_mismatch, tvb, offset_orig + CMP_MSG_HEADER_LEN, asam_cmp_status_msg_payload_length);
        proto_item_set_end(ti_msg_payload, tvb, offset);
    }

    return CMP_MSG_HEADER_LEN + asam_cmp_status_msg_payload_length;
}

static int
dissect_asam_cmp_vendor_msg(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *root_tree _U_, proto_tree *tree, guint offset_orig) {
    proto_item *ti = NULL;
    proto_item *ti_msg_header = NULL;
    proto_item *ti_msg_payload = NULL;
    proto_tree *asam_cmp_vendor_msg_header_tree = NULL;
    proto_tree *subtree = NULL;
    guint asam_cmp_vendor_msg_payload_type = 0;
    guint asam_cmp_vendor_msg_payload_length = 0;
    guint offset = offset_orig;

    static int * const asam_cmp_common_flags[] = {
        &hf_cmp_common_flag_recal,
        &hf_cmp_common_flag_insync,
        &hf_cmp_common_flag_seg,
        &hf_cmp_common_flag_reserved_ctrl,
        NULL
    };

    ti_msg_header = proto_tree_add_item(tree, hf_cmp_msg_header, tvb, offset, 8, ENC_BIG_ENDIAN);
    asam_cmp_vendor_msg_header_tree = proto_item_add_subtree(ti_msg_header, ett_asam_cmp_header);
    proto_item_append_text(ti_msg_header, " %s", "- Vendor-Defined Message");

    guint64 ns = tvb_get_guint64(tvb, offset, ENC_BIG_ENDIAN);
    nstime_t timestamp = { .secs = (time_t)(ns / 1000000000), .nsecs = (int)(ns % 1000000000) };

    ti = proto_tree_add_time(asam_cmp_vendor_msg_header_tree, hf_cmp_msg_timestamp, tvb, offset, 8, &timestamp);

    subtree = proto_item_add_subtree(ti, ett_asam_cmp_timestamp);
    proto_tree_add_item(subtree, hf_cmp_msg_timestamp_ns, tvb, offset, 8, ENC_BIG_ENDIAN);
    offset += 8;

    proto_tree_add_item(asam_cmp_vendor_msg_header_tree, hf_cmp_msg_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(asam_cmp_vendor_msg_header_tree, hf_cmp_msg_vendor_id, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_bitmask(asam_cmp_vendor_msg_header_tree, tvb, offset, hf_cmp_msg_common_flags, ett_asam_cmp_common_flags, asam_cmp_common_flags, ENC_BIG_ENDIAN);
    offset += 1;

    proto_tree_add_item_ret_uint(asam_cmp_vendor_msg_header_tree, hf_cmp_vendor_msg_payload_type, tvb, offset, 1, ENC_NA, &asam_cmp_vendor_msg_payload_type);
    offset += 1;

    proto_tree_add_item_ret_uint(asam_cmp_vendor_msg_header_tree, hf_cmp_msg_payload_length, tvb, offset, 2, ENC_BIG_ENDIAN, &asam_cmp_vendor_msg_payload_length);
    offset += 2;

    proto_item_set_end(ti_msg_header, tvb, offset);

    ti_msg_payload = proto_tree_add_item(tree, hf_cmp_msg_payload, tvb, offset, asam_cmp_vendor_msg_payload_length, ENC_BIG_ENDIAN);
    proto_item_append_text(ti_msg_payload, " %s", "- Vendor-Defined Message");

    if ((asam_cmp_vendor_msg_payload_length) > 0) {
        offset += (gint)asam_cmp_vendor_msg_payload_length;
        proto_item_set_end(ti_msg_payload, tvb, offset);
    }

    return CMP_MSG_HEADER_LEN + asam_cmp_vendor_msg_payload_length;
}

static int
dissect_asam_cmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
    proto_item *ti_root = NULL;
    proto_item *ti_header = NULL;
    proto_item *ti = NULL;
    proto_tree *asam_cmp_tree = NULL;
    proto_tree *asam_cmp_header_tree = NULL;
    guint msg_type = 0;
    guint device_id = 0;
    guint offset = 0;

    col_clear(pinfo->cinfo, COL_INFO);
    col_set_str(pinfo->cinfo, COL_INFO, "ASAM-CMP");
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "ASAM-CMP");

    ti_root = proto_tree_add_item(tree, proto_asam_cmp, tvb, 0, -1, ENC_NA);
    asam_cmp_tree = proto_item_add_subtree(ti_root, ett_asam_cmp);

    ti_header = proto_tree_add_item(asam_cmp_tree, hf_cmp_header, tvb, offset, CMP_HEADER_LEN, ENC_BIG_ENDIAN);
    asam_cmp_header_tree = proto_item_add_subtree(ti_header, ett_asam_cmp_header);

    proto_tree_add_item(asam_cmp_header_tree, hf_cmp_version, tvb, offset, 1, ENC_NA);
    offset += 1;

    proto_tree_add_item(asam_cmp_header_tree, hf_cmp_header_res, tvb, offset, 1, ENC_NA);
    offset += 1;

    ti = proto_tree_add_item_ret_uint(asam_cmp_header_tree, hf_cmp_device_id, tvb, offset, 2, ENC_BIG_ENDIAN, &device_id);
    add_device_id_text(ti, device_id);
    offset += 2;

    proto_tree_add_item_ret_uint(asam_cmp_header_tree, hf_cmp_msg_type, tvb, offset, 1, ENC_NA, &msg_type);
    offset += 1;

    proto_tree_add_item(asam_cmp_header_tree, hf_cmp_stream_id, tvb, offset, 1, ENC_NA);
    offset += 1;

    proto_tree_add_item(asam_cmp_header_tree, hf_cmp_stream_seq_ctr, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_item_append_text(ti_root, ", Device: 0x%04x, Type: %s", device_id, val_to_str(msg_type, msg_type_names, "Unknown (0x%x)"));

    while (tvb_reported_length_remaining(tvb, offset) >= 16) {
        switch (msg_type) {
        case CMP_MSG_TYPE_CTRL_MSG:
            col_append_str(pinfo->cinfo, COL_INFO, ", Control Msg");
            offset += dissect_asam_cmp_ctrl_msg(tvb, pinfo, tree, asam_cmp_tree, offset);
            break;
        case CMP_MSG_TYPE_STATUS_MSG:
            col_append_str(pinfo->cinfo, COL_INFO, ", Status Msg");
            offset += dissect_asam_cmp_status_msg(tvb, pinfo, tree, asam_cmp_tree, offset);
            break;
        case CMP_MSG_TYPE_VENDOR:
            col_append_str(pinfo->cinfo, COL_INFO, ", Vendor Msg");
            offset += dissect_asam_cmp_vendor_msg(tvb, pinfo, tree, asam_cmp_tree, offset);
            break;
        case CMP_MSG_TYPE_DATA_MSG:
            col_append_str(pinfo->cinfo, COL_INFO, ", Data Msg");
            offset += dissect_asam_cmp_data_msg(tvb, pinfo, tree, asam_cmp_tree, offset);
            break;
        default:
            proto_item_set_end(ti_root, tvb, offset);
            proto_item_set_end(ti_header, tvb, offset);
            return offset;
        }
    }

    proto_item_set_end(ti_root, tvb, offset);
    proto_item_set_end(ti_header, tvb, offset);
    return offset;
}

void
proto_register_asam_cmp(void) {
    module_t *asam_cmp_module = NULL;
    expert_module_t *expert_module_asam_cmp;
    uat_t *asam_cmp_deviceid_uat = NULL;
    uat_t *asam_cmp_interfaceid_uat = NULL;

    static hf_register_info hf[] = {
        /* Header */
        { &hf_cmp_header,                           { "ASAM CMP Header", "asam-cmp.hdr", FT_PROTOCOL, BASE_NONE, NULL, 0x0, NULL, HFILL }},

        { &hf_cmp_version,                          { "Version", "asam-cmp.hdr.version", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_header_res,                       { "Reserved", "asam-cmp.hdr.res", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_device_id,                        { "Device ID", "asam-cmp.hdr.device_id", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_msg_type,                         { "Message Type", "asam-cmp.hdr.msg_type", FT_UINT8, BASE_HEX, VALS(msg_type_names), 0x0, NULL, HFILL }},
        { &hf_cmp_stream_id,                        { "Stream ID", "asam-cmp.hdr.stream_id", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_stream_seq_ctr,                   { "Stream Sequence Counter", "asam-cmp.hdr.stream_seq_cnt", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},

        /* Message Header*/
        { &hf_cmp_msg_header,                       { "ASAM CMP Msg Header", "asam-cmp.msg_hdr", FT_PROTOCOL, BASE_NONE, NULL, 0x0, NULL, HFILL }},

        { &hf_cmp_common_flag_recal,                { "Timestamp recalculated", "asam-cmp.msg_hdr.recalculated", FT_BOOLEAN, 8, NULL, 0x01, NULL, HFILL }},
        { &hf_cmp_common_flag_insync,               { "Synchronized", "asam-cmp.msg_hdr.sync", FT_BOOLEAN, 8, NULL, 0x02, NULL, HFILL } },
        { &hf_cmp_common_flag_seg,                  { "Segmentation", "asam-cmp.msg_hdr.seg", FT_UINT8, BASE_HEX, VALS(seg_flag_names), 0x0C, NULL, HFILL } },
        { &hf_cmp_common_flag_dir_on_if,            { "Direction", "asam-cmp.msg_hdr.dir_on_if", FT_BOOLEAN, 8, TFS(&interface_direction), 0x10, NULL, HFILL } },
        { &hf_cmp_common_flag_overflow,             { "Overflow", "asam-cmp.msg_hdr.overflow", FT_BOOLEAN, 8, NULL, 0x20, NULL, HFILL } },
        { &hf_cmp_common_flag_err_in_payload,       { "Error in payload", "asam-cmp.msg_hdr.error_in_payload", FT_BOOLEAN, 8, NULL, 0x40, NULL, HFILL } },
        { &hf_cmp_common_flag_reserved,             { "Reserved", "asam-cmp.msg_hdr.res", FT_UINT8, BASE_HEX, NULL, 0x80, NULL, HFILL } },
        { &hf_cmp_common_flag_reserved_ctrl,        { "Reserved", "asam-cmp.msg_hdr.res2", FT_UINT8, BASE_HEX, NULL, 0xF0, NULL, HFILL } },

        { &hf_cmp_msg_timestamp,                    { "Timestamp", "asam-cmp.msg_hdr.timestamp", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_msg_timestamp_ns,                 { "Timestamp (ns)", "asam-cmp.msg_hdr.timestamp_ns", FT_UINT64, BASE_DEC, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_msg_reserved,                     { "Reserved", "asam-cmp.msg_hdr.reserved", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_msg_common_flags,                 { "Common Flags", "asam-cmp.msg_hdr.common_flags", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_msg_vendor_id,                    { "Vendor ID", "asam-cmp.msg_hdr.vendor_id", FT_UINT16, BASE_HEX, VALS(vendor_ids), 0x0, NULL, HFILL }},
        { &hf_cmp_msg_payload_length,               { "Payload Length", "asam-cmp.msg_hdr.payload_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_msg_payload,                      { "Payload", "asam-cmp.msg_payload", FT_PROTOCOL, BASE_NONE, NULL, 0x0, NULL, HFILL }},

        /* Data Message Header */
        { &hf_cmp_interface_id,                     { "Interface ID", "asam-cmp.msg_hdr.interface_id", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_payload_type,                     { "Payload Type", "asam-cmp.msg_hdr.payload_type", FT_UINT8, BASE_HEX, VALS(data_msg_type_names), 0x0, NULL, HFILL }},

        /* Additional Control Message Header */
        { &hf_cmp_ctrl_msg_reserved,                { "Reserved", "asam-cmp.msg_hdr.reserved", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_ctrl_msg_payload_type,            { "Payload Type", "asam-cmp.msg_hdr.payload_type", FT_UINT8, BASE_HEX, VALS(ctrl_msg_type_names), 0x0, NULL, HFILL }},

        /* Additional Status Message Header */
        { &hf_cmp_status_msg_payload_type,          { "Payload Type", "asam-cmp.msg_hdr.payload_type", FT_UINT8, BASE_HEX, VALS(status_msg_type_names), 0x0, NULL, HFILL }},

        /* Additional Vendor Message Header */
        { &hf_cmp_vendor_msg_payload_type,          { "Payload Type", "asam-cmp.msg_hdr.payload_type", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},

        /* Data Message Payloads */
        /* CAN Data */
        { &hf_cmp_can_flags,                        { "Flags", "asam-cmp.msg.can.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_can_reserved,                     { "Reserved", "asam-cmp.msg.can.res", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},

        { &hf_cmp_can_id,                           { "ID", "asam-cmp.msg.can.id_field", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_can_id_11bit,                     { "ID (11bit)", "asam-cmp.msg.can.id_11bit", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CAN_ID_11BIT_MASK, NULL, HFILL }},
        { &hf_cmp_can_id_11bit_old,                 { "ID (11bit)", "asam-cmp.msg.can.id_11bit", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CAN_ID_11BIT_MASK_OLD, NULL, HFILL }},
        { &hf_cmp_can_id_29bit,                     { "ID (29bit)", "asam-cmp.msg.can.id_29bit", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CAN_ID_29BIT_MASK, NULL, HFILL }},
        { &hf_cmp_can_id_res,                       { "Reserved", "asam-cmp.msg.can.res", FT_BOOLEAN, 32, NULL, CMP_CAN_ID_RES, NULL, HFILL }},
        { &hf_cmp_can_id_rtr,                       { "RTR", "asam-cmp.msg.can.rtr", FT_BOOLEAN, 32, TFS(&can_id_rtr), CMP_CAN_ID_RTR, NULL, HFILL }},
        { &hf_cmp_can_id_ide,                       { "IDE", "asam-cmp.msg.can.ide", FT_BOOLEAN, 32, TFS(&can_id_ide), CMP_CAN_ID_IDE, NULL, HFILL }},

        { &hf_cmp_can_crc,                          { "CRC", "asam-cmp.msg.can.crc_field", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_can_crc_crc,                      { "CRC", "asam-cmp.msg.can.crc", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CAN_CRC_CRC, NULL, HFILL }},
        { &hf_cmp_can_crc_res,                      { "Reserved", "asam-cmp.msg.can.crc_res", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CAN_CRC_RES, NULL, HFILL }},
        { &hf_cmp_can_crc_crc_support,              { "CRC Supported", "asam-cmp.msg.can.crc_support", FT_BOOLEAN, 32, NULL, CMP_CAN_CRC_CRC_SUPP, NULL, HFILL }},

        { &hf_cmp_can_err_pos,                      { "Error Position", "asam-cmp.msg.can.err_pos", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_can_dlc,                          { "DLC", "asam-cmp.msg.can.dlc", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_can_data_len,                     { "Data length", "asam-cmp.msg.can.data_len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},

        { &hf_cmp_can_flag_crc_err,                 { "CRC Error", "asam-cmp.msg.can.flags.crc_err", FT_BOOLEAN, 16, NULL, 0x0001, NULL, HFILL }},
        { &hf_cmp_can_flag_ack_err,                 { "ACK Error", "asam-cmp.msg.can.flags.ack_err", FT_BOOLEAN, 16, NULL, 0x0002, NULL, HFILL } },
        { &hf_cmp_can_flag_passive_ack_err,         { "Passive ACK Error", "asam-cmp.msg.can.flags.passive_ack_err", FT_BOOLEAN, 16, NULL, 0x0004, NULL, HFILL } },
        { &hf_cmp_can_flag_active_ack_err,          { "Active ACK Error", "asam-cmp.msg.can.flags.active_ack_err", FT_BOOLEAN, 16, NULL, 0x0008, NULL, HFILL } },
        { &hf_cmp_can_flag_ack_del_err,             { "ACK DEL Error", "asam-cmp.msg.can.flags.ack_del_err", FT_BOOLEAN, 16, NULL, 0x0010, NULL, HFILL } },
        { &hf_cmp_can_flag_form_err,                { "Form Error", "asam-cmp.msg.can.flags.form_err", FT_BOOLEAN, 16, NULL, 0x0020, NULL, HFILL } },
        { &hf_cmp_can_flag_stuff_err,               { "Stuff Error", "asam-cmp.msg.can.flags.stuff_err", FT_BOOLEAN, 16, NULL, 0x0040, NULL, HFILL } },
        { &hf_cmp_can_flag_crc_del_err,             { "CRC DEL Error", "asam-cmp.msg.can.flags.crc_del_err", FT_BOOLEAN, 16, NULL, 0x0080, NULL, HFILL } },
        { &hf_cmp_can_flag_eof_err,                 { "EOF Error", "asam-cmp.msg.can.flags.eof_err", FT_BOOLEAN, 16, NULL, 0x0100, NULL, HFILL } },
        { &hf_cmp_can_flag_bit_err,                 { "Bit Error", "asam-cmp.msg.can.flags.bit_err", FT_BOOLEAN, 16, NULL, 0x0200, NULL, HFILL } },
        { &hf_cmp_can_flag_r0,                      { "R0", "asam-cmp.msg.can.flags.r0", FT_BOOLEAN, 16, TFS(&can_rec_dom), 0x0400, NULL, HFILL } },
        { &hf_cmp_can_flag_srr_dom,                 { "Substitute Remote Request (SRR)", "asam-cmp.msg.can.flags.srr", FT_BOOLEAN, 16, TFS(&can_dom_rec), 0x0800, NULL, HFILL } },
        { &hf_cmp_can_flag_reserved,                { "Reserved", "asam-cmp.msg.can.flags.reserved", FT_UINT16, BASE_HEX, NULL, 0xF000, NULL, HFILL } },

        /* CAN-FD Data */
        { &hf_cmp_canfd_flags,                      { "Flags", "asam-cmp.msg.canfd.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_canfd_reserved,                   { "Reserved", "asam-cmp.msg.canfd.res", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },

        { &hf_cmp_canfd_id,                         { "ID", "asam-cmp.msg.canfd.id_field", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_canfd_id_11bit,                   { "ID (11bit)", "asam-cmp.msg.canfd.id_11bit", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CAN_ID_11BIT_MASK, NULL, HFILL }},
        { &hf_cmp_canfd_id_11bit_old,               { "ID (11bit)", "asam-cmp.msg.canfd.id_11bit", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CAN_ID_11BIT_MASK_OLD, NULL, HFILL }},
        { &hf_cmp_canfd_id_29bit,                   { "ID (29bit)", "asam-cmp.msg.canfd.id_29bit", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CAN_ID_29BIT_MASK, NULL, HFILL }},
        { &hf_cmp_canfd_id_res,                     { "Reserved", "asam-cmp.msg.canfd.res", FT_BOOLEAN, 32, NULL, CMP_CANFD_ID_RES, NULL, HFILL }},
        { &hf_cmp_canfd_id_rrs,                     { "RRS", "asam-cmp.msg.canfd.rrs", FT_BOOLEAN, 32, NULL, CMP_CANFD_ID_RRS, NULL, HFILL }},
        { &hf_cmp_canfd_id_ide,                     { "IDE", "asam-cmp.msg.canfd.ide", FT_BOOLEAN, 32, NULL, CMP_CANFD_ID_IDE, NULL, HFILL }},

        { &hf_cmp_canfd_crc,                        { "CRC SBC", "asam-cmp.msg.canfd.crc_field", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_canfd_crc_crc17,                  { "CRC (17bit)", "asam-cmp.msg.canfd.crc17", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CANFD_CRC_CRC17, NULL, HFILL }},
        { &hf_cmp_canfd_crc_crc21,                  { "CRC (21bit)", "asam-cmp.msg.canfd.crc21", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CANFD_CRC_CRC21, NULL, HFILL }},
        { &hf_cmp_canfd_crc_sbc,                    { "SBC", "asam-cmp.msg.canfd.sbc", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CANFD_CRC_SBC, NULL, HFILL }},
        { &hf_cmp_canfd_crc_sbc_parity,             { "SBC Parity", "asam-cmp.msg.canfd.sbc_parity", FT_BOOLEAN, 32, NULL, CMP_CANFD_CRC_SBC_PARITY, NULL, HFILL }},
        { &hf_cmp_canfd_crc_res,                    { "Reserved", "asam-cmp.msg.canfd.crc_res", FT_UINT32, BASE_HEX_DEC, NULL, CMP_CANFD_CRC_RES, NULL, HFILL }},
        { &hf_cmp_canfd_crc_sbc_support,            { "SBC Supported", "asam-cmp.msg.canfd.sbc_support", FT_BOOLEAN, 32, NULL, CMP_CANFD_CRC_SBC_SUPP, NULL, HFILL }},
        { &hf_cmp_canfd_crc_crc_support,            { "CRC Supported", "asam-cmp.msg.canfd.crc_support", FT_BOOLEAN, 32, NULL, CMP_CANFD_CRC_CRC_SUPP, NULL, HFILL }},

        { &hf_cmp_canfd_err_pos,                    { "Error Position", "asam-cmp.msg.canfd.err_pos", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_canfd_dlc,                        { "DLC", "asam-cmp.msg.canfd.dlc", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_canfd_data_len,                   { "Data length", "asam-cmp.msg.canfd.data_len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },

        { &hf_cmp_canfd_flag_crc_err,               { "CRC Error", "asam-cmp.msg.canfd.flags.crc_err", FT_BOOLEAN, 16, NULL, 0x0001, NULL, HFILL }},
        { &hf_cmp_canfd_flag_ack_err,               { "ACK Error", "asam-cmp.msg.canfd.flags.ack_err", FT_BOOLEAN, 16, NULL, 0x0002, NULL, HFILL } },
        { &hf_cmp_canfd_flag_passive_ack_err,       { "Passive ACK Error", "asam-cmp.msg.canfd.flags.passive_ack_err", FT_BOOLEAN, 16, NULL, 0x0004, NULL, HFILL } },
        { &hf_cmp_canfd_flag_active_ack_err,        { "Active ACK Error", "asam-cmp.msg.canfd.flags.active_ack_err", FT_BOOLEAN, 16, NULL, 0x0008, NULL, HFILL } },
        { &hf_cmp_canfd_flag_ack_del_err,           { "ACK DEL Error", "asam-cmp.msg.canfd.flags.ack_del_err", FT_BOOLEAN, 16, NULL, 0x0010, NULL, HFILL } },
        { &hf_cmp_canfd_flag_form_err,              { "Form Error", "asam-cmp.msg.canfd.flags.form_err", FT_BOOLEAN, 16, NULL, 0x0020, NULL, HFILL } },
        { &hf_cmp_canfd_flag_stuff_err,             { "Stuff Error", "asam-cmp.msg.canfd.flags.stuff_err", FT_BOOLEAN, 16, NULL, 0x0040, NULL, HFILL } },
        { &hf_cmp_canfd_flag_crc_del_err,           { "CRC DEL Error", "asam-cmp.msg.canfd.flags.crc_del_err", FT_BOOLEAN, 16, NULL, 0x0080, NULL, HFILL } },
        { &hf_cmp_canfd_flag_eof_err,               { "EOF Error", "asam-cmp.msg.canfd.flags.eof_err", FT_BOOLEAN, 16, NULL, 0x0100, NULL, HFILL } },
        { &hf_cmp_canfd_flag_bit_err,               { "Bit Error", "asam-cmp.msg.canfd.flags.bit_err", FT_BOOLEAN, 16, NULL, 0x0200, NULL, HFILL } },
        { &hf_cmp_canfd_flag_res,                   { "Reserved Bit", "asam-cmp.msg.canfd.flags.res", FT_BOOLEAN, 16, TFS(&can_rec_dom), 0x0400, NULL, HFILL } },
        { &hf_cmp_canfd_flag_srr_dom,               { "Substitute Remote Request (SRR)", "asam-cmp.msg.canfd.flags.srr", FT_BOOLEAN, 16, TFS(&can_dom_rec), 0x0800, NULL, HFILL } },
        { &hf_cmp_canfd_flag_brs,                   { "BRS", "asam-cmp.msg.canfd.flags.brs", FT_BOOLEAN, 16, NULL, 0x1000, NULL, HFILL } },
        { &hf_cmp_canfd_flag_esi,                   { "ESI", "asam-cmp.msg.canfd.flags.esi",  FT_BOOLEAN, 16, TFS(&canfd_act_pas), 0x2000, NULL, HFILL } },
        { &hf_cmp_canfd_flag_reserved,              { "Reserved", "asam-cmp.msg.canfd.flags.reserved",  FT_UINT16, BASE_HEX, NULL, 0xC000, NULL, HFILL } },

        /* LIN */
        { &hf_cmp_lin_flags,                        { "Flags", "asam-cmp.msg.lin.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_lin_reserved,                     { "Reserved", "asam-cmp.msg.lin.res", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_lin_pid,                          { "PID", "asam-cmp.msg.lin.pid", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_lin_pid_id,                       { "ID", "asam-cmp.msg.lin.pid.id", FT_UINT8, BASE_HEX, NULL, CMP_CANFD_PID_ID_MASK, NULL, HFILL } },
        { &hf_cmp_lin_pid_parity,                   { "Parity", "asam-cmp.msg.lin.pid.parity", FT_UINT8, BASE_HEX, NULL, CMP_CANFD_PID_PARITY_MASK, NULL, HFILL } },
        { &hf_cmp_lin_reserved_2,                   { "Reserved", "asam-cmp.msg.lin.res_2", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_lin_checksum,                     { "Checksum", "asam-cmp.msg.lin.checksum", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_lin_data_len,                     { "Data length", "asam-cmp.msg.lin.data_len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },

        { &hf_cmp_lin_flag_checksum_err,            { "Checksum Error", "asam-cmp.msg.lin.flags.checksum_err", FT_BOOLEAN, 16, NULL, 0x0001, NULL, HFILL } },
        { &hf_cmp_lin_flag_col_err,                 { "Collision Error", "asam-cmp.msg.lin.flags.col_err", FT_BOOLEAN, 16, NULL, 0x0002, NULL, HFILL } },
        { &hf_cmp_lin_flag_parity_err,              { "Parity Error", "asam-cmp.msg.lin.flags.parity_err", FT_BOOLEAN, 16, NULL, 0x0004, NULL, HFILL } },
        { &hf_cmp_lin_flag_no_slave_res_err,        { "No Slave Response Error", "asam-cmp.msg.lin.flags.no_slave_res_err", FT_BOOLEAN, 16, NULL, 0x0008, NULL, HFILL } },
        { &hf_cmp_lin_flag_sync_err,                { "Sync Error", "asam-cmp.msg.lin.flags.sync_err", FT_BOOLEAN, 16, NULL, 0x0010, NULL, HFILL } },
        { &hf_cmp_lin_flag_framing_err,             { "Framing Error", "asam-cmp.msg.lin.flags.framing_err", FT_BOOLEAN, 16, NULL, 0x0020, NULL, HFILL } },
        { &hf_cmp_lin_flag_short_dom_err,           { "Short Dominant Error", "asam-cmp.msg.lin.flags.short_dom_err", FT_BOOLEAN, 16, NULL, 0x0040, NULL, HFILL } },
        { &hf_cmp_lin_flag_long_dom_err,            { "Long Dominant Error", "asam-cmp.msg.lin.flags.long_dom_err", FT_BOOLEAN, 16, NULL, 0x0080, NULL, HFILL } },
        { &hf_cmp_lin_flag_wup,                     { "Wake Up Request Detection (WUP)", "asam-cmp.msg.lin.flags.wup", FT_BOOLEAN, 16, NULL, 0x0100, NULL, HFILL } },
        { &hf_cmp_lin_flag_reserved,                { "Reserved", "asam-cmp.msg.lin.flags.reserved", FT_UINT16, BASE_HEX, NULL, 0xFE00, NULL, HFILL } },

        /* FlexRay */
        { &hf_cmp_flexray_flags,                    { "Flags", "asam-cmp.msg.flexray.flags.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_flexray_reserved,                 { "Reserved", "asam-cmp.msg.flexray.flags.res", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_flexray_header_crc,               { "Header CRC", "asam-cmp.msg.flexray.flags.header_crc", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_flexray_frame_id,                 { "Frame ID", "asam-cmp.msg.flexray.flags.frame_id", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_flexray_cycle,                    { "Cycle", "asam-cmp.msg.flexray.flags.cycle", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_flexray_frame_crc,                { "Frame CRC", "asam-cmp.msg.flexray.flags.frame_crc", FT_UINT24, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_flexray_reserved_2,               { "Reserved", "asam-cmp.msg.flexray.flags.res_2", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_flexray_data_len,                 { "Data length", "asam-cmp.msg.flexray.flags.data_len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},

        { &hf_cmp_flexray_flag_crc_frame_err,       { "Frame CRC Error", "asam-cmp.msg.flexray.flags.crc_frame_err", FT_BOOLEAN, 16, NULL, 0x0001, NULL, HFILL }},
        { &hf_cmp_flexray_flag_crc_header_err,      { "Header CRC Error", "asam-cmp.msg.flexray.flags.crc_header_err", FT_BOOLEAN, 16, NULL, 0x0002, NULL, HFILL }},
        { &hf_cmp_flexray_flag_nf,                  { "Null Frame", "asam-cmp.msg.flexray.flags.nf", FT_BOOLEAN, 16, NULL, CMP_FLEXRAY_FLAGS_NF, NULL, HFILL }},
        { &hf_cmp_flexray_flag_sf,                  { "Startup Frame", "asam-cmp.msg.flexray.flags.sf", FT_BOOLEAN, 16, NULL, 0x0008, NULL, HFILL } },
        { &hf_cmp_flexray_flag_sync,                { "Sync Frame", "asam-cmp.msg.flexray.flags.sync", FT_BOOLEAN, 16, NULL, 0x0010, NULL, HFILL } },
        { &hf_cmp_flexray_flag_wus,                 { "Wake Up Symbol", "asam-cmp.msg.flexray.flags.wus", FT_BOOLEAN, 16, NULL, 0x0020, NULL, HFILL } },
        { &hf_cmp_flexray_flag_ppi,                 { "Preamble Indicator", "asam-cmp.msg.flexray.flags.ppi", FT_BOOLEAN, 16, NULL, 0x0040, NULL, HFILL } },
        { &hf_cmp_flexray_flag_cas,                 { "Collision avoidance Symbol (CAS)", "asam-cmp.msg.flexray.flags.cas", FT_BOOLEAN, 16, NULL, 0x0080, NULL, HFILL } },
        { &hf_cmp_flexray_flag_reserved,            { "Reserved", "asam-cmp.msg.flexray.flags.reserved", FT_UINT16, BASE_HEX, NULL, 0xFF00, NULL, HFILL } },

        /* UART/RS-232 */
        { &hf_cmp_uart_flags,                       { "Flags", "asam-cmp.msg.uart.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_uart_reserved,                    { "Reserved", "asam-cmp.msg.uart.reserved", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_uart_data_len,                    { "Data entry count", "asam-cmp.msg.uart.data_len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_uart_data,                        { "Data", "asam-cmp.msg.uart.data", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },

        { &hf_cmp_uart_data_data,                   { "Data", "asam-cmp.msg.uart.data.data", FT_UINT16, BASE_HEX, NULL, CMP_UART_DATA_DATA_MASK, NULL, HFILL }},
        { &hf_cmp_uart_data_reserved,               { "Reserved", "asam-cmp.msg.uart.data.reserved", FT_UINT16, BASE_HEX, NULL, 0x1E00, NULL, HFILL }},
        { &hf_cmp_uart_data_framing_err,            { "Framing Error", "asam-cmp.msg.uart.flags.framing_err", FT_BOOLEAN, 16, NULL, 0x2000, NULL, HFILL }},
        { &hf_cmp_uart_data_break_condition,        { "Break Condition", "asam-cmp.msg.uart.flags.break_condition", FT_BOOLEAN, 16, NULL, 0x4000, NULL, HFILL }},
        { &hf_cmp_uart_data_parity_err,             { "Parity Error", "asam-cmp.msg.uart.data.parity_err", FT_BOOLEAN, 16, NULL, 0x8000, NULL, HFILL }},

        { &hf_cmp_uart_flag_cl,                     { "CL", "asam-cmp.msg.uart.flags.cl",  FT_UINT16, BASE_HEX, VALS(uart_cl_names), 0x0007, NULL, HFILL }},
        { &hf_cmp_uart_flag_reserved,               { "Reserved", "asam-cmp.msg.uart.flags.reserved", FT_UINT16, BASE_HEX, NULL, 0xFFF8, NULL, HFILL }},

        /* Analog */
        { &hf_cmp_analog_flags,                     { "Flags", "asam-cmp.msg.analog.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_analog_reserved,                  { "Reserved", "asam-cmp.msg.analog.reserved",  FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_analog_unit,                      { "Unit", "asam-cmp.msg.analog.unit", FT_UINT8, BASE_HEX, VALS(analog_units), 0x0, NULL, HFILL } },
        { &hf_cmp_analog_sample_interval,           { "Sample Interval", "asam-cmp.msg.analog.sample_interval", FT_FLOAT, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_analog_sample_offset,             { "Sample Offset", "asam-cmp.msg.analog.sample_offset", FT_FLOAT, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_analog_sample_scalar,             { "Sample Scalar", "asam-cmp.msg.analog.sample_scalar", FT_FLOAT, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_analog_sample,                    { "Sample", "asam-cmp.msg.analog.sample", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },

        { &hf_cmp_analog_flag_sample_dt,            { "Sample Datatype", "asam-cmp.msg.analog.flags.sample_dt", FT_UINT16, BASE_HEX, VALS(analog_sample_dt), 0x0003, NULL, HFILL }},
        { &hf_cmp_analog_flag_reserved,             { "Reserved", "asam-cmp.msg.analog.flags.reserved", FT_UINT16, BASE_HEX, NULL, 0xfffc, NULL, HFILL }},

        /* Ethernet */
        { &hf_cmp_eth_flags,                        { "Flags", "asam-cmp.msg.eth.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_eth_reserved,                     { "Reserved", "asam-cmp.msg.eth.res", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
        { &hf_cmp_eth_payload_length,               { "Data length", "asam-cmp.msg.eth.data_len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},

        { &hf_cmp_eth_flag_fcs_err,                 { "FCS Error", "asam-cmp.msg.eth.flags.crc_err", FT_BOOLEAN, 16, NULL, 0x0001, NULL, HFILL }},
        { &hf_cmp_eth_flag_short_err,               { "Short Frame Error", "asam-cmp.msg.eth.flags.short_err", FT_BOOLEAN, 16, NULL, 0x0002, NULL, HFILL } },
        { &hf_cmp_eth_flag_tx_down,                 { "TX Port Down", "asam-cmp.msg.eth.flags.tx_down", FT_BOOLEAN, 16, NULL, 0x0004, NULL, HFILL } },
        { &hf_cmp_eth_flag_collision,               { "Collision detected", "asam-cmp.msg.eth.flags.collision", FT_BOOLEAN, 16, NULL, 0x0008, NULL, HFILL } },
        { &hf_cmp_eth_flag_long_err,                { "Long Frame Error", "asam-cmp.msg.eth.flags.long_err", FT_BOOLEAN, 16, NULL, 0x0010, NULL, HFILL } },
        { &hf_cmp_eth_flag_phy_err,                 { "PHY Error", "asam-cmp.msg.eth.flags.phy_err", FT_BOOLEAN, 16, NULL, 0x0020, NULL, HFILL } },
        { &hf_cmp_eth_flag_truncated,               { "Frame truncated", "asam-cmp.msg.eth.flags.truncated", FT_BOOLEAN, 16, NULL, 0x0040, NULL, HFILL } },
        { &hf_cmp_eth_flag_fcs_supported,           { "FCS supported", "asam-cmp.msg.eth.flags.fcs_supported", FT_BOOLEAN, 16, NULL, 0x0080, NULL, HFILL } },
        { &hf_cmp_eth_flag_reserved,                { "Reserved", "asam-cmp.msg.eth.flags.reserved", FT_UINT16, BASE_HEX, NULL, 0xFF00, NULL, HFILL } },

        /* Control Message Payloads */
        /* Data Sink Ready */
        { &hf_cmp_ctrl_msg_device_id,               { "Device ID", "asam-cmp.msg.dsr.device_id", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },

         /* User Event */
        { &hf_cmp_ctrl_msg_event_id,                { "Event ID", "asam-cmp.msg.ue.event_id", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },

         /* Vendor specific */
        { &hf_cmp_ctrl_msg_vendor_id,               { "Vendor ID", "asam-cmp.msg.vs.vendor_id", FT_UINT16, BASE_HEX, VALS(vendor_ids), 0x0, NULL, HFILL } },
        { &hf_cmp_ctrl_msg_vendor_payload_type,     { "Payload Type", "asam-cmp.msg.vs.payload_type", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },

        /* Status Message Payloads */
        /* Capture Module Status Message */
        { &hf_cmp_status_msg_cm_uptime_ns,          { "Uptime (ns)", "asam-cmp.msg.cm.uptime_ns", FT_UINT64, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_msg_cm_uptime_s,           { "Uptime (s)", "asam-cmp.msg.cm.uptime_s", FT_UINT64, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_msg_gm_identity,           { "gPTP grandmasterIdentity", "asam-cmp.msg.cm.gm_identity", FT_UINT64, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_msg_gm_clock_quality,      { "gPTP grandmasterClockQuality", "asam-cmp.msg.cm.gm_clock_quality", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_msg_current_utc_offset,    { "gPTP currentUtcOffset", "asam-cmp.msg.cm.current_utc_offset", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_msg_time_source,           { "gPTP timeSource", "asam-cmp.msg.cm.time_source", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_msg_domain_num,            { "gPTP domainNumber", "asam-cmp.msg.cm.domain_number", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_msg_res,                   { "Reserved", "asam-cmp.msg.cm.res", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_gptp_flags,                       { "gPTP Flags", "asam-cmp.msg.cm.gptp_flags", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },

        { &hf_cmp_gptp_flags_leap61,                { "Leap61", "asam-cmp.msg.cm.gptp_flags.leap61", FT_BOOLEAN, 8, NULL, 0x01, NULL, HFILL } },
        { &hf_cmp_gptp_flags_leap59,                { "Leap59", "asam-cmp.msg.cm.gptp_flags.leap59", FT_BOOLEAN, 8, NULL, 0x02, NULL, HFILL } },
        { &hf_cmp_gptp_flags_cur_utco_valid,        { "Current UTC Offset Valid", "asam-cmp.msg.cm.gptp_flags.current_utco_valid", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL } },
        { &hf_cmp_gptp_flags_ptp_timescale,         { "PTP Timescale", "asam-cmp.msg.cm.gptp_flags.ptp_timescale", FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL } },
        { &hf_cmp_gptp_flags_time_traceable,        { "Time Traceable", "asam-cmp.msg.cm.gptp_flags.time_traceable", FT_BOOLEAN, 8, NULL, 0x10, NULL, HFILL } },
        { &hf_cmp_gptp_flags_freq_traceable,        { "Frequency Traceable", "asam-cmp.msg.cm.gptp_flags.freq_traceable", FT_BOOLEAN, 8, NULL, 0x20, NULL, HFILL } },
        { &hf_cmp_gptp_flags_reserved,              { "Reserved", "asam-cmp.msg.cm.gptp_flags.res", FT_UINT8, BASE_HEX, NULL, 0xC0, NULL, HFILL } },

        { &hf_cmp_status_dev_desc_length,           { "Length of Device Description", "asam-cmp.msg.cm.dev_desc_len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_dev_desc,                  { "Device Description", "asam-cmp.msg.cm.dev_desc", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_sn_length,                 { "Length of Serial Number", "asam-cmp.msg.cm.sn_len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_sn,                        { "Serial Number (SN)", "asam-cmp.msg.cm.sn", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_hw_ver_length,             { "Length of Hardware Version", "asam-cmp.msg.cm.hw_ver_len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_hw_ver,                    { "HW version", "asam-cmp.msg.cm.hw_ver", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_sw_ver_length,             { "Length of Software Version", "asam-cmp.msg.cm.sw_ver_len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_sw_ver,                    { "SW version", "asam-cmp.msg.cm.sw_ver", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_vendor_data_length,        { "Length of Vendor Data", "asam-cmp.msg.cm.vendor_data_len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_status_vendor_data,               { "Vendor Data", "asam-cmp.msg.cm.vendor_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },

        /* Interface Status Message */
        { &hf_cmp_iface_interface,                  { "Interface", "asam-cmp.msg.iface", FT_PROTOCOL, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_iface_id,                   { "Interface ID", "asam-cmp.msg.iface.iface_id", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_msg_total_rx,               { "Messages Total RX", "asam-cmp.msg.iface.msg_total_rx", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_msg_total_tx,               { "Messages Total TX", "asam-cmp.msg.iface.msg_total_tx", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_msg_dropped_rx,             { "Messages Dropped RX", "asam-cmp.msg.iface.msg_drop_rx", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_msg_dropped_tx,             { "Messages Dropped TX", "asam-cmp.msg.iface.msg_drop_tx", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_errs_total_rx,              { "Errors Total RX", "asam-cmp.msg.iface.errors_total_rx", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_errs_total_tx,              { "Errors Total TX", "asam-cmp.msg.iface.errors_total_tx", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_iface_type,                 { "Interface Type", "asam-cmp.msg.iface.interface_type", FT_UINT8, BASE_HEX, VALS(data_msg_type_names), 0x0, NULL, HFILL } },
        { &hf_cmp_iface_iface_status,               { "Interface Status", "asam-cmp.msg.iface.interface_status", FT_UINT8, BASE_HEX, VALS(interface_status_names), 0x0, NULL, HFILL } },
        { &hf_cmp_iface_stream_id_cnt,              { "Stream ID count", "asam-cmp.msg.iface.stream_id_count", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_reserved,                   { "Reserved", "asam-cmp.msg.iface.res", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },

        { &hf_cmp_iface_feat,                       { "Feature Support Bitmask", "asam-cmp.msg.iface.feat_supp", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_feat_can_pas_ack,           { "Passive Ack Supported", "asam-cmp.msg.iface.feat_supp.can.pas_ack", FT_BOOLEAN, 32, NULL, 0x00000004, NULL, HFILL } },
        { &hf_cmp_iface_feat_can_act_ack,           { "Active Ack Supported", "asam-cmp.msg.iface.feat_supp.can.act_ack", FT_BOOLEAN, 32, NULL, 0x00000008, NULL, HFILL } },
        { &hf_cmp_iface_feat_can_ack_del_err,       { "Ack Del Error Supported", "asam-cmp.msg.iface.feat_supp.can.ack_del_err", FT_BOOLEAN, 32, NULL, 0x00000010, NULL, HFILL } },
        { &hf_cmp_iface_feat_can_crc_del_err,       { "CRC Del Error Supported", "asam-cmp.msg.iface.feat_supp.can.crc_del_err", FT_BOOLEAN, 32, NULL, 0x00000080, NULL, HFILL } },
        { &hf_cmp_iface_feat_can_eof_err,           { "EOF Error Supported", "asam-cmp.msg.iface.feat_supp.can.eof_err", FT_BOOLEAN, 32, NULL, 0x00000100, NULL, HFILL } },
        { &hf_cmp_iface_feat_can_r0,                { "R0 Supported", "asam-cmp.msg.iface.feat_supp.can.r0", FT_BOOLEAN, 32, NULL, 0x00000400, NULL, HFILL } },
        { &hf_cmp_iface_feat_can_srr_dom,           { "SRR Dom Supported", "asam-cmp.msg.iface.feat_supp.can.srr_dom", FT_BOOLEAN, 32, NULL, 0x00000800, NULL, HFILL } },
        { &hf_cmp_iface_feat_canfd_pas_ack,         { "Passive Ack Supported", "asam-cmp.msg.iface.feat_supp.canfd.pas_ack", FT_BOOLEAN, 32, NULL, 0x00000004, NULL, HFILL } },
        { &hf_cmp_iface_feat_canfd_act_ack,         { "Active Ack Supported", "asam-cmp.msg.iface.feat_supp.canfd.act_ack", FT_BOOLEAN, 32, NULL, 0x00000008, NULL, HFILL } },
        { &hf_cmp_iface_feat_canfd_ack_del_err,     { "Ack Del Error Supported", "asam-cmp.msg.iface.feat_supp.canfd.ack_del_err", FT_BOOLEAN, 32, NULL, 0x00000010, NULL, HFILL } },
        { &hf_cmp_iface_feat_canfd_crc_del_err,     { "CRC Del Error Supported", "asam-cmp.msg.iface.feat_supp.canfd.crc_del_err", FT_BOOLEAN, 32, NULL, 0x00000080, NULL, HFILL } },
        { &hf_cmp_iface_feat_canfd_eof_err,         { "EOF Error Supported", "asam-cmp.msg.iface.feat_supp.canfd.eof_err", FT_BOOLEAN, 32, NULL, 0x00000100, NULL, HFILL } },
        { &hf_cmp_iface_feat_canfd_rsvd,            { "RRSV Supported", "asam-cmp.msg.iface.feat_supp.canfd.rsvd", FT_BOOLEAN, 32, NULL, 0x00000400, NULL, HFILL } },
        { &hf_cmp_iface_feat_canfd_srr_dom,         { "SRR Dom Supported", "asam-cmp.msg.iface.feat_supp.canfd.srr_dom", FT_BOOLEAN, 32, NULL, 0x00000800, NULL, HFILL } },
        { &hf_cmp_iface_feat_canfd_brs_dom,         { "BRS Dom Supported", "asam-cmp.msg.iface.feat_supp.canfd.brs_dom", FT_BOOLEAN, 32, NULL, 0x00001000, NULL, HFILL } },
        { &hf_cmp_iface_feat_canfd_esi_dom,         { "ESI Dom Supported", "asam-cmp.msg.iface.feat_supp.canfd.esi_dom", FT_BOOLEAN, 32, NULL, 0x00002000, NULL, HFILL } },
        { &hf_cmp_iface_feat_lin_sync_err,          { "Sync Error Supported", "asam-cmp.msg.iface.feat_supp.lin.sync_err", FT_BOOLEAN, 32, NULL, 0x00000010, NULL, HFILL } },
        { &hf_cmp_iface_feat_lin_framing_err,       { "Framing Error Supported", "asam-cmp.msg.iface.feat_supp.lin.frameing_err", FT_BOOLEAN, 32, NULL, 0x00000020, NULL, HFILL } },
        { &hf_cmp_iface_feat_lin_short_dom_err,     { "Short Dom Error Supported", "asam-cmp.msg.iface.feat_supp.lin.short_dom_err", FT_BOOLEAN, 32, NULL, 0x00000040, NULL, HFILL } },
        { &hf_cmp_iface_feat_lin_long_dom_err,      { "Long Dom Error Supported", "asam-cmp.msg.iface.feat_supp.lin.long_dom_err", FT_BOOLEAN, 32, NULL, 0x00000080, NULL, HFILL } },
        { &hf_cmp_iface_feat_lin_wup,               { "WUP Supported", "asam-cmp.msg.iface.feat_supp.lin.wup", FT_BOOLEAN, 32, NULL, 0x00000100, NULL, HFILL } },
        { &hf_cmp_iface_feat_eth_too_long,          { "Frame too long Supported", "asam-cmp.msg.iface.feat_supp.eth.frame_too_long", FT_BOOLEAN, 32, NULL, 0x00000010, NULL, HFILL } },
        { &hf_cmp_iface_feat_eth_phy_err,           { "PHY Error Supported", "asam-cmp.msg.iface.feat_supp.eth.phy_err", FT_BOOLEAN, 32, NULL, 0x00000020, NULL, HFILL } },
        { &hf_cmp_iface_feat_eth_trunc,             { "Truncated Frames Supported", "asam-cmp.msg.iface.feat_supp.eth.truncated_frames", FT_BOOLEAN, 32, NULL, 0x00000040, NULL, HFILL } },

        { &hf_cmp_iface_stream_ids,                 { "Stream IDs", "asam-cmp.msg.iface.stream_ids", FT_PROTOCOL, BASE_NONE, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_stream_id,                  { "Stream ID", "asam-cmp.msg.iface.stream_id", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_vendor_data_len,            { "Vendor Data Length", "asam-cmp.msg.iface.vendor_data_len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_iface_vendor_data,                { "Vendor Data", "asam-cmp.msg.iface.vendor_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },

        /* Configuration Status Message */
        { &hf_cmp_status_msg_config,                { "Data", "asam-cmp.msg.config.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },

        /* Data Lost Event Status Message */
        { &hf_cmp_dataloss_data_sink_port,          { "Data Sink Port", "asam-cmp.msg.dataloss.data_sink_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_dataloss_device_id,               { "Device ID", "asam-cmp.msg.dataloss.device_id", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_dataloss_reserved,                { "Reserved", "asam-cmp.msg.dataloss.res", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_dataloss_stream_id,               { "Stream ID", "asam-cmp.msg.dataloss.stream_id", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_dataloss_last_ssq_value,          { "Last Stream Sequence Counter Value", "asam-cmp.msg.dataloss.last_ssqc", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_dataloss_current_ssq_value,       { "Current Stream Sequence Counter Value", "asam-cmp.msg.dataloss.current_ssqc", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },

        /* Time Sync Lost Event Status Message */
        { &hf_cmp_timeloss_port_nr,                 { "Port Number", "asam-cmp.msg.timesyncloss.port_nr", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_timeloss_device_id,               { "Device ID", "asam-cmp.msg.timesyncloss.device_id", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
        { &hf_cmp_timeloss_error_flags,             { "Time Sync Loss Error Flags", "asam-cmp.msg.timesyncloss.err_flags", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },

        { &hf_cmp_timeloss_error_flags_ts,          { "Was Time Synced before", "asam-cmp.msg.timesyncloss.err_flags.ts", FT_BOOLEAN, 8, NULL, 0x01, NULL, HFILL } },
        { &hf_cmp_timeloss_error_flags_insync,      { "Original CMP Message had at least one INSYNC=0", "asam-cmp.msg.timesyncloss.err_flags.insync", FT_BOOLEAN, 8, NULL, 0x02, NULL, HFILL } },
        { &hf_cmp_timeloss_error_flags_delta,       { "Configured Time Delta was exceeded", "asam-cmp.msg.timesyncloss.err_flags.delta", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL } },
        { &hf_cmp_timeloss_error_flags_reserved,    { "Reserved", "asam-cmp.msg.timesyncloss.err_flags.res", FT_UINT8, BASE_HEX, NULL, 0xF8, NULL, HFILL } },

        /* Vendor Specific Status Message */
        { &hf_cmp_status_msg_vendor_specific,       { "Vendor Specific", "asam-cmp.msg.vendor_specific", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
    };

    static gint *ett[] = {
        &ett_asam_cmp,
        &ett_asam_cmp_header,
        &ett_asam_cmp_timestamp,
        &ett_asam_cmp_common_flags,
        &ett_asam_cmp_payload,
        &ett_asam_cmp_payload_flags,
        &ett_asam_cmp_lin_pid,
        &ett_asam_cmp_can_id,
        &ett_asam_cmp_can_crc,
        &ett_asam_cmp_uart_data,
        &ett_asam_cmp_status_cm_flags,
        &ett_asam_cmp_status_cm_uptime,
        &ett_asam_cmp_status_timeloss_flags,
        &ett_asam_cmp_status_interface,
        &ett_asam_cmp_status_feature_support,
        &ett_asam_cmp_status_stream_ids
    };

    static ei_register_info ei[] = {
        { &ef_asam_cmp_length_mismatch, {"asam-cmp.expert.length_mismatch", PI_MALFORMED, PI_WARN, "Malformed message, length mismatch!", EXPFILL } },
        { &ef_asam_cmp_unsupported_crc_not_zero, {"asam-cmp.export.deactivated_crc_not_zero", PI_MALFORMED, PI_WARN, "Unsupported CRC is not zero!", EXPFILL } },
    };

    /* UATs for user_data fields */
    static uat_field_t asam_cmp_device_id_uat_fields[] = {
        UAT_FLD_HEX(asam_cmp_devices, id, "Device ID", "Device ID (hex uint16 without leading 0x)"),
        UAT_FLD_CSTRING(asam_cmp_devices, name, "Device Name", "Device Name (string)"),
        UAT_END_FIELDS
    };

    static uat_field_t asam_cmp_interface_id_uat_fields[] = {
        UAT_FLD_HEX(asam_cmp_interfaces, id, "Interface ID", "Interface ID (hex uint32 without leading 0x)"),
        UAT_FLD_CSTRING(asam_cmp_interfaces, name, "Interface Name", "Interface Name (string)"),
        UAT_FLD_HEX(asam_cmp_interfaces, bus_id, "Bus ID", "Bus ID of the Interface (hex uint16 without leading 0x)"),
        UAT_END_FIELDS
    };

    proto_asam_cmp = proto_register_protocol("ASAM Capture Module Protocol", "ASAM CMP", "asam-cmp");
    proto_register_field_array(proto_asam_cmp, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));
    asam_cmp_module = prefs_register_protocol(proto_asam_cmp, NULL);

    expert_module_asam_cmp = expert_register_protocol(proto_asam_cmp);
    expert_register_field_array(expert_module_asam_cmp, ei, array_length(ei));

    /* Configuration Items */
    asam_cmp_deviceid_uat = uat_new("ASAM CMP Devices",
        sizeof(generic_one_id_string_t),        /* record size           */
        DATAFILE_ASAM_CMP_DEVICES_IDS,          /* filename              */
        TRUE,                                   /* from profile          */
        (void**)&asam_cmp_devices,              /* data_ptr              */
        &asam_cmp_devices_num,                  /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION,                 /* but not fields        */
        NULL,                                   /* help                  */
        copy_generic_one_id_string_cb,          /* copy callback         */
        update_generic_one_identifier_16bit,    /* update callback       */
        free_generic_one_id_string_cb,          /* free callback         */
        post_update_asam_cmp_devices_cb,        /* post update callback  */
        NULL,                                   /* reset callback        */
        asam_cmp_device_id_uat_fields           /* UAT field definitions */
    );

    prefs_register_uat_preference(asam_cmp_module, "_udf_asam_cmp_devices", "Devices",
        "A table to define names of Devices.", asam_cmp_deviceid_uat);

    asam_cmp_interfaceid_uat = uat_new("ASAM CMP Interfaces",
        sizeof(interface_config_t),             /* record size           */
        DATAFILE_ASAM_CMP_IFACE_IDS,            /* filename              */
        TRUE,                                   /* from profile          */
        (void**)&asam_cmp_interfaces,           /* data_ptr              */
        &asam_cmp_interface_num,                /* numitems_ptr          */
        UAT_AFFECTS_DISSECTION,                 /* but not fields        */
        NULL,                                   /* help                  */
        copy_interface_config_cb,               /* copy callback         */
        update_interface_config,                /* update callback       */
        free_interface_config_cb,               /* free callback         */
        post_update_interface_config_cb,        /* post update callback  */
        NULL,                                   /* reset callback        */
        asam_cmp_interface_id_uat_fields        /* UAT field definitions */
    );

    prefs_register_uat_preference(asam_cmp_module, "_udf_asam_cmp_interfaces", "Interfaces",
        "A table to define names and mappings of Interfaces.", asam_cmp_interfaceid_uat);

    prefs_register_bool_preference(asam_cmp_module, "try_heuristic_first",
        "Try heuristic sub-dissectors first",
        "Try to decode a packet using an heuristic sub-dissector"
        " before using a sub-dissector registered to \"decode as\"",
        &heuristic_first);

    prefs_register_bool_preference(asam_cmp_module, "use_old_canid_11bit_format",
        "Use old encoding of 11bit CAN/CAN-FD IDs",
        "Use the old encoding of 11bit CAN/CAN-FD IDs",
        &old_11bit_canid_encoding);
}

void
proto_reg_handoff_asam_cmp(void) {
    dissector_handle_t asam_cmp_handle;

    asam_cmp_handle = register_dissector("asam-cmp", dissect_asam_cmp, proto_asam_cmp);
    eth_handle = find_dissector("eth_maybefcs");

    dissector_add_for_decode_as("ethertype", asam_cmp_handle);
    dissector_add_for_decode_as_with_preference("udp.port", asam_cmp_handle);

    lin_subdissector_table = find_dissector_table("lin.frame_id");
}

  /*
   * 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:
   */