aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-vrt.c
blob: 6b8e1aae9fc72eefca0bdb3b97949a60cc27daa7 (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
/* packet-vrt.c
 * Routines for VRT (VITA 49) packet disassembly
 * Copyright 2012 Ettus Research LLC - Nick Foster <nick@ettus.com>: original dissector
 * Copyright 2013 Alexander Chemeris <alexander.chemeris@gmail.com>: dissector improvement
 * Copyright 2013 Dario Lombardo (lomato@gmail.com): Official Wireshark port
 * Copyright 2022 Amazon.com, Inc. or its affiliates - Cody Planteen <codplant@amazon.com>: context packet decoding
 *
 * Original dissector repository: https://github.com/bistromath/vrt-dissector
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */


#include "config.h"
#include <epan/packet.h>
#include <epan/prefs.h>
#include <math.h>

void proto_register_vrt(void);
void proto_reg_handoff_vrt(void);

#define VITA_49_PORT    4991
#define DEFAULT_EPHEMERIS_FIELDS { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }
#define DEFAULT_FORMATTED_GPS_INS_FIELDS { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }

typedef int (*complex_dissector_t)(proto_tree *tree, tvbuff_t *tvb, int offset);

typedef struct {
    int tsi; /* 2-bit timestamp type */
    int tsf; /* 2-bit fractional timestamp type */
    int oui; /* 24-bit GPS/INS manufacturer OUI */
    int ts_int; /* 32-bit integer timestamp (opt.) */
    int ts_picosecond; /* 64-bit fractional timestamp (mutually exclusive with below) */
    int ts_frac_sample; /* 64-bit fractional timestamp (mutually exclusive with above) */
    int pos_x; /* 32-bit position X */
    int pos_y; /* 32-bit position Y */
    int pos_z; /* 32-bit position Z */
    int att_alpha; /* 32-bit attitude alpha */
    int att_beta; /* 32-bit attitude beta */
    int att_phi; /* 32-bit attitude phi */
    int vel_dx; /* 32-bit velocity dX */
    int vel_dy; /* 32-bit velocity dY */
    int vel_dz; /* 32-bit velocity dZ */
} ephemeris_fields;

typedef struct {
    int tsi; /* 2-bit timestamp type */
    int tsf; /* 2-bit fractional timestamp type */
    int oui; /* 24-bit GPS/INS manufacturer OUI */
    int ts_int; /* 32-bit integer timestamp (opt.) */
    int ts_picosecond; /* 64-bit fractional timestamp (mutually exclusive with below) */
    int ts_frac_sample; /* 64-bit fractional timestamp (mutually exclusive with above) */
    int lat; /* 32-bit latitude */
    int lon; /* 32-bit longitude */
    int alt; /* 32-bit altitude */
    int speed; /* 32-bit speed over ground */
    int heading; /* 32-bit heading angle */
    int track; /* 32-bit track angle */
    int mag_var; /* 32-bit magnetic variation */
} formatted_gps_ins_fields;

typedef int (*complex_dissector_t)(proto_tree *tree, tvbuff_t *tvb, int offset);

static gboolean vrt_use_ettus_uhd_header_format = FALSE;

static int proto_vrt = -1;

/* fields */
static int hf_vrt_header = -1; /* 32-bit header */
static int hf_vrt_type = -1; /* 4-bit pkt type */
static int hf_vrt_cidflag = -1; /* 1-bit class ID flag */
static int hf_vrt_tflag = -1; /* 1-bit trailer flag */
static int hf_vrt_tsmflag = -1; /* 1-bit timestamp mode */
static int hf_vrt_tsi = -1; /* 2-bit timestamp type */
static int hf_vrt_tsf = -1; /* 2-bit fractional timestamp type */
static int hf_vrt_seq = -1; /* 4-bit sequence number */
static int hf_vrt_len = -1; /* 16-bit length */
static int hf_vrt_sid = -1; /* 32-bit stream ID (opt.) */
static int hf_vrt_cid = -1; /* 64-bit class ID (opt.) */
static int hf_vrt_cid_oui = -1; /* 24-bit class ID OUI */
static int hf_vrt_cid_icc = -1; /* 16-bit class ID ICC */
static int hf_vrt_cid_pcc = -1; /* 16-bit class ID PCC */
static int hf_vrt_cif[8] = { -1, -1, -1, -1, -1, -1, -1, -1}; /* 32-bit CIF0-CIF7 (opt.) */
static int hf_vrt_cif0_change_flag = -1; /* 1-bit context field change indicator */
static int hf_vrt_cif0_ref_pt_id = -1; /* 1-bit reference point identifier */
static int hf_vrt_cif0_bandwidth = -1; /* 1-bit bandwidth */
static int hf_vrt_cif0_if_freq = -1; /* 1-bit IF reference frequency */
static int hf_vrt_cif0_rf_freq = -1; /* 1-bit RF reference frequency */
static int hf_vrt_cif0_rf_freq_offset = -1; /* 1-bit RF reference frequency offset */
static int hf_vrt_cif0_if_band_offset = -1; /* 1-bit IF band offset */
static int hf_vrt_cif0_ref_level = -1; /* 1-bit reference level */
static int hf_vrt_cif0_gain = -1; /* 1-bit gain */
static int hf_vrt_cif0_over_range_count = -1; /* 1-bit over-range count */
static int hf_vrt_cif0_sample_rate = -1; /* 1-bit sample rate */
static int hf_vrt_cif0_timestamp_adjust = -1; /* 1-bit timestamp adjustment */
static int hf_vrt_cif0_timestamp_cal = -1; /* 1-bit timestamp calibration time */
static int hf_vrt_cif0_temperature = -1; /* 1-bit temperature */
static int hf_vrt_cif0_device_id = -1; /* 1-bit device identifier */
static int hf_vrt_cif0_state_event = -1; /* 1-bit state/event indicators */
static int hf_vrt_cif0_signal_data_format = -1; /* 1-bit signal data packet payload format */
static int hf_vrt_cif0_gps = -1; /* 1-bit formatted GPS */
static int hf_vrt_cif0_ins = -1; /* 1-bit formatted INS */
static int hf_vrt_cif0_ecef_ephemeris = -1; /* 1-bit ECEF ephemeris */
static int hf_vrt_cif0_rel_ephemeris = -1; /* 1-bit relative ephemeris */
static int hf_vrt_cif0_ephemeris_ref_id = -1; /* 1-bit ephemeris ref ID */
static int hf_vrt_cif0_gps_ascii = -1; /* 1-bit GPS ASCII */
static int hf_vrt_cif0_context_assoc_lists = -1; /* 1-bit context association lists */
static int hf_vrt_cif0_cif7 = -1; /* 1-bit CIF7 */
static int hf_vrt_cif0_cif6 = -1; /* 1-bit CIF6 */
static int hf_vrt_cif0_cif5 = -1; /* 1-bit CIF5 */
static int hf_vrt_cif0_cif4 = -1; /* 1-bit CIF4 */
static int hf_vrt_cif0_cif3 = -1; /* 1-bit CIF3 */
static int hf_vrt_cif0_cif2 = -1; /* 1-bit CIF2 */
static int hf_vrt_cif0_cif1 = -1; /* 1-bit CIF1 */
/* TODO: complete CIF1 support (have partial CIF1 support) */
static int hf_vrt_cif1_phase_offset = -1; /* 1-bit phase offset */
static int hf_vrt_cif1_polarization = -1; /* 1-bit polarization */
static int hf_vrt_cif1_range = -1; /* 1-bit range (distance) */
static int hf_vrt_cif1_aux_freq = -1; /* 1-bit aux frequency */
static int hf_vrt_cif1_aux_bandwidth = -1; /* 1-bit aux bandwidth */
static int hf_vrt_cif1_io32 = -1; /* 1-bit discrete I/O (32-bit) */
static int hf_vrt_cif1_io64 = -1; /* 1-bit discrete I/O (64-bit) */
static int hf_vrt_cif1_v49_spec = -1; /* 1-bit V49 spec compliance */
static int hf_vrt_cif1_ver = -1; /* 1-bit version and build code */
static int hf_vrt_context_ref_pt_id = -1; /* 32-bit reference point identifier */
static int hf_vrt_context_bandwidth = -1; /* 64-bit bandwidth */
static int hf_vrt_context_if_freq = -1; /* 64-bit IF reference frequency */
static int hf_vrt_context_rf_freq = -1; /* 64-bit RF reference frequency */
static int hf_vrt_context_rf_freq_offset = -1; /* 64-bit RF frequency offset */
static int hf_vrt_context_if_band_offset = -1; /* 64-bit IF band offset */
static int hf_vrt_context_ref_level = -1; /* 16-bit reference level */
static int hf_vrt_context_gain_stage2 = -1; /* 16-bit gain stage 2 */
static int hf_vrt_context_gain_stage1 = -1; /* 16-bit gain stage 1 */
static int hf_vrt_context_over_range_count = -1; /* 32-bit over-range count */
static int hf_vrt_context_sample_rate = -1; /* 64-bit sample rate */
static int hf_vrt_context_timestamp_adjust = -1; /* 64-bit timestamp adjustment */
static int hf_vrt_context_timestamp_cal = -1; /* 32-bit timestamp calibration */
static int hf_vrt_context_temperature = -1; /* 16-bit device temperature */
static int hf_vrt_context_device_id_oui = -1; /* 24-bit device ID OUI */
static int hf_vrt_context_device_id_code = -1; /* 16-bit device ID code */
static int hf_vrt_context_state_event_en_cal_time = -1; /* 1-bit enable calibrated time */
static int hf_vrt_context_state_event_en_valid_data = -1; /* 1-bit enable valid data */
static int hf_vrt_context_state_event_en_ref_lock = -1; /* 1-bit enable reference lock */
static int hf_vrt_context_state_event_en_agc = -1; /* 1-bit enable AGC/MGC */
static int hf_vrt_context_state_event_en_detected_sig = -1; /* 1-bit enable detected signal */
static int hf_vrt_context_state_event_en_spectral_inv = -1; /* 1-bit enable spectral inversion */
static int hf_vrt_context_state_event_en_over_range = -1; /* 1-bit enable over-range */
static int hf_vrt_context_state_event_en_sample_loss = -1; /* 1-bit enable sample loss */
static int hf_vrt_context_state_event_cal_time = -1; /* 1-bit enable calibrated time */
static int hf_vrt_context_state_event_valid_data = -1; /* 1-bit enable valid data */
static int hf_vrt_context_state_event_ref_lock = -1; /* 1-bit enable reference lock */
static int hf_vrt_context_state_event_agc = -1; /* 1-bit enable AGC/MGC */
static int hf_vrt_context_state_event_detected_sig = -1; /* 1-bit enable detected signal */
static int hf_vrt_context_state_event_spectral_inv = -1; /* 1-bit enable spectral inversion */
static int hf_vrt_context_state_event_over_range = -1; /* 1-bit enable over-range */
static int hf_vrt_context_state_event_sample_loss = -1; /* 1-bit enable sample loss */
static int hf_vrt_context_state_event_user = -1; /* 8-bit user-defined */
static int hf_vrt_context_signal_data_format_packing = -1; /* 1-bit signal data format packing */
static int hf_vrt_context_signal_data_format_type = -1; /* 2-bit real/complex type */
static int hf_vrt_context_signal_data_format_item = -1; /* 5-bit data item format */
static int hf_vrt_context_signal_data_format_repeat = -1; /* 1-bit sample-component repeat indicator */
static int hf_vrt_context_signal_data_format_event_size = -1; /* 3-bit event-tag size */
static int hf_vrt_context_signal_data_format_channel_size = -1; /* 4-bit channel-tag size */
static int hf_vrt_context_signal_data_format_fraction_size = -1; /* 4-bit data item fraction size */
static int hf_vrt_context_signal_data_format_packing_size = -1; /* 6-bit item packing field size */
static int hf_vrt_context_signal_data_format_item_size = -1; /* 6-bit data item size */
static int hf_vrt_context_signal_data_format_repeat_count = -1; /* 16-bit repeat count */
static int hf_vrt_context_signal_data_format_vector_size = -1; /* 16-bit vector size */
static formatted_gps_ins_fields hf_vrt_context_gps = DEFAULT_FORMATTED_GPS_INS_FIELDS; /* struct for formatted GPS */
static formatted_gps_ins_fields hf_vrt_context_ins = DEFAULT_FORMATTED_GPS_INS_FIELDS; /* struct for formatted INS */
static ephemeris_fields hf_vrt_context_ecef_ephemeris = DEFAULT_EPHEMERIS_FIELDS; /* struct for ECEF ephemeris */
static ephemeris_fields hf_vrt_context_rel_ephemeris = DEFAULT_EPHEMERIS_FIELDS; /* struct for relative ephemeris */
static int hf_vrt_context_ephemeris_ref_id = -1; /* 32-bit ephemeris reference identifier */
static int hf_vrt_context_gps_ascii_oui; /* 24-bit GPS/INS manufacturer OUI */
static int hf_vrt_context_gps_ascii_size; /* 32-bit number of words */
static int hf_vrt_context_gps_ascii_data = -1; /* Variable GPS ASCII data */
static int hf_vrt_context_assoc_lists_src_size; /* 32-bit source list size */
static int hf_vrt_context_assoc_lists_sys_size; /* 32-bit system list size */
static int hf_vrt_context_assoc_lists_vec_size; /* 32-bit vector-component list size */
static int hf_vrt_context_assoc_lists_a; /* 1-bit "A" bit (asynchronous-channel tag list present) */
static int hf_vrt_context_assoc_lists_asy_size; /* 32-bit asynchronous-channel list size */
static int hf_vrt_context_assoc_lists_src_data; /* Variable source context association list */
static int hf_vrt_context_assoc_lists_sys_data; /* Variable system context association list */
static int hf_vrt_context_assoc_lists_vec_data; /* Variable vector-component context association list */
static int hf_vrt_context_assoc_lists_asy_data; /* Variable asynchronous-channel context association list */
static int hf_vrt_context_assoc_lists_asy_tag_data; /* Variable asynchronous-channel tag list */
static int hf_vrt_context_phase_offset = -1; /* 16-bit phase offset */
static int hf_vrt_context_pol_tilt = -1; /* 16-bit polarization tilt angle */
static int hf_vrt_context_pol_ellipticity = -1; /* 16-bit polarization ellipticity angle */
static int hf_vrt_context_range = -1; /* 32-bit range (distance) */
static int hf_vrt_context_aux_freq = -1; /* 64-bit aux frequency */
static int hf_vrt_context_aux_bandwidth = -1; /* 64-bit aux bandwidth */
static int hf_vrt_context_io32 = -1; /* 32-bit discrete I/O */
static int hf_vrt_context_io64 = -1; /* 64-bit discrete I/O */
static int hf_vrt_context_v49_spec = -1; /* 32-bit V49 spec compliance */
static int hf_vrt_context_ver_year = -1; /* 7-bit year */
static int hf_vrt_context_ver_day = -1; /* 9-bit day */
static int hf_vrt_context_ver_rev = -1; /* 6-bit revision */
static int hf_vrt_context_ver_user = -1; /* 10-bit user defined */
static int hf_vrt_ts_int = -1; /* 32-bit integer timestamp (opt.) */
static int hf_vrt_ts_frac_picosecond = -1; /* 64-bit fractional timestamp (opt.) */
static int hf_vrt_ts_frac_sample = -1; /* 64-bit fractional timestamp (opt.) */
static int hf_vrt_data = -1; /* data */
static int hf_vrt_trailer = -1; /* 32-bit trailer (opt.) */
static int hf_vrt_trailer_enables = -1; /* trailer indicator enables */
static int hf_vrt_trailer_ind = -1; /* trailer indicators */
static int hf_vrt_trailer_e = -1; /* ass con pac cnt enable */
static int hf_vrt_trailer_acpc = -1; /* associated context packet count */
static int hf_vrt_trailer_en_caltime = -1; /* calibrated time indicator */
static int hf_vrt_trailer_en_valid = -1; /* valid data ind */
static int hf_vrt_trailer_en_reflock = -1; /* reference locked ind */
static int hf_vrt_trailer_en_agc = -1; /* AGC/MGC enabled ind */
static int hf_vrt_trailer_en_sig = -1; /* signal detected ind */
static int hf_vrt_trailer_en_inv = -1; /* spectral inversion ind */
static int hf_vrt_trailer_en_overrng = -1; /* overrange indicator */
static int hf_vrt_trailer_en_sampleloss = -1; /* sample loss indicator */
static int hf_vrt_trailer_en_user0 = -1; /* User indicator 0 */
static int hf_vrt_trailer_en_user1 = -1; /* User indicator 1 */
static int hf_vrt_trailer_en_user2 = -1; /* User indicator 2 */
static int hf_vrt_trailer_en_user3 = -1; /* User indicator 3 */
static int hf_vrt_trailer_ind_caltime = -1; /* calibrated time indicator */
static int hf_vrt_trailer_ind_valid = -1; /* valid data ind */
static int hf_vrt_trailer_ind_reflock = -1; /* reference locked ind */
static int hf_vrt_trailer_ind_agc = -1; /* AGC/MGC enabled ind */
static int hf_vrt_trailer_ind_sig = -1; /* signal detected ind */
static int hf_vrt_trailer_ind_inv = -1; /* spectral inversion ind */
static int hf_vrt_trailer_ind_overrng = -1; /* overrange indicator */
static int hf_vrt_trailer_ind_sampleloss = -1; /* sample loss indicator */
static int hf_vrt_trailer_ind_user0 = -1; /* User indicator 0 */
static int hf_vrt_trailer_ind_user1 = -1; /* User indicator 1 */
static int hf_vrt_trailer_ind_user2 = -1; /* User indicator 2 */
static int hf_vrt_trailer_ind_user3 = -1; /* User indicator 3 */

/* fixed sizes (in bytes) of context packet CIF field bits */
static int context_size_cif0[32] = { 0, 4, 4, 4, 4, 4, 4, 4, 8, 8, 4, 52, 52, 44, 44, 8,
    4, 8, 4, 4, 8, 8, 4, 4, 4, 8, 8, 8, 8, 8, 4, 0 };
static int context_size_cif1[32] = { 0, 8, 4, 4, 4, 8, 4, 0, 0, 0, 52, 0, 0, 8, 4, 8,
    4, 4, 4, 4, 4, 0, 0, 0, 4, 4, 4, 4, 0, 4, 4, 4 };

/* subtree state variables */
static gint ett_vrt = -1;
static gint ett_header = -1;
static gint ett_trailer = -1;
static gint ett_indicators = -1;
static gint ett_ind_enables = -1;
static gint ett_cid = -1;
static gint ett_cif0 = -1;
static gint ett_cif1 = -1;
static gint ett_gain = -1;
static gint ett_device_id = -1;
static gint ett_state_event = -1;
static gint ett_signal_data_format = -1;
static gint ett_gps = -1;
static gint ett_ins = -1;
static gint ett_ecef_ephem = -1;
static gint ett_rel_ephem = -1;
static gint ett_gps_ascii = -1;
static gint ett_assoc_lists = -1;
static gint ett_pol = -1;
static gint ett_ver = -1;

/* constants (unit conversion) */
static const double FEMTOSEC_PER_SEC = 1e-15;
static const double RADIX_CELSIUS = 1.0/64.0;
static const double RADIX_DECIBEL = 1.0/128.0;
static const double RADIX_DECIBEL_MILLIWATT = 1.0/128.0;
static const double RADIX_DEGREES = 1.0/4194304.0;
static const double RADIX_HERTZ = 1.0/1048576.0;
static const double RADIX_METER = 1.0/32.0;
static const double RADIX_METER_UNSIGNED = 1.0/64.0;
static const double RADIX_METERS_PER_SECOND = 1.0/65536.0;
static const double RADIX_RADIAN_PHASE = 1.0/128.0;
static const double RADIX_RADIAN_POL = 1.0/8192.0;

/* constants (tree index) */
static const int ETT_IDX_GAIN = 8;
static const int ETT_IDX_DEVICE_ID = 9;
static const int ETT_IDX_STATE_EVENT = 10;
static const int ETT_IDX_SIGNAL_DATA_FORMAT = 11;
static const int ETT_IDX_GPS = 12;
static const int ETT_IDX_INS = 13;
static const int ETT_IDX_ECEF_EPHEM = 14;
static const int ETT_IDX_REL_EPHEM = 15;
static const int ETT_IDX_GPS_ASCII = 16;
static const int ETT_IDX_ASSOC_LISTS = 17;
static const int ETT_IDX_POL = 18;
static const int ETT_IDX_VER = 19;

static const value_string packet_types[] = {
    {0x00, "IF data packet without stream ID"},
    {0x01, "IF data packet with stream ID"},
    {0x02, "Extension data packet without stream ID"},
    {0x03, "Extension data packet with stream ID"},
    {0x04, "IF context packet"},
    {0x05, "Extension context packet"},
    {0, NULL}
};

static const value_string tsi_types[] = {
    {0x00, "No integer-seconds timestamp field included"},
    {0x01, "Coordinated Universal Time (UTC)"},
    {0x02, "GPS time"},
    {0x03, "Other"},
    {0, NULL}
};

static const value_string tsf_types[] = {
    {0x00, "No fractional-seconds timestamp field included"},
    {0x01, "Sample count timestamp"},
    {0x02, "Real time (picoseconds) timestamp"},
    {0x03, "Free running count timestamp"},
    {0, NULL}
};

static const value_string tsm_types[] = {
    {0x00, "Precise timestamp resolution"},
    {0x01, "General timestamp resolution"},
    {0, NULL}
};

static const value_string packing_method[] = {
    {0x00, "Processing efficient"},
    {0x01, "Link efficient"},
    {0, NULL}
};

static const value_string data_sample_type[] = {
    {0x00, "Real"},
    {0x01, "Complex, Cartesian"},
    {0x02, "Complex, polar"},
    {0, NULL}
};

static const value_string data_item_format[] = {
    {0x00, "Signed fixed-point"},
    {0x01, "Signed VRT, 1-bit exponent"},
    {0x02, "Signed VRT, 2-bit exponent"},
    {0x03, "Signed VRT, 3-bit exponent"},
    {0x04, "Signed VRT, 4-bit exponent"},
    {0x05, "Signed VRT, 5-bit exponent"},
    {0x06, "Signed VRT, 6-bit exponent"},
    {0x07, "Signed fixed-point non-normalized"},
    {0x0D, "IEEE-754 half-precision floating-point"},
    {0x0E, "IEEE-754 single-precision floating-point"},
    {0x0F, "IEEE-754 double-precision floating-point"},
    {0x10, "Unsigned fixed-point"},
    {0x11, "Unsigned VRT, 1-bit exponent"},
    {0x12, "Unsigned VRT, 2-bit exponent"},
    {0x13, "Unsigned VRT, 3-bit exponent"},
    {0x14, "Unsigned VRT, 4-bit exponent"},
    {0x15, "Unsigned VRT, 5-bit exponent"},
    {0x16, "Unsigned VRT, 6-bit exponent"},
    {0x17, "Unsigned fixed-point non-normalized"},
    {0, NULL}
};

static const value_string standard_version_codes[] = {
    {0x01, "Implements V49.0"},
    {0x02, "Implements V49.1"},
    {0x03, "Implements V49A"},
    {0x04, "Implements V49.2"},
    {0, NULL}
};

static int * const enable_hfs[] = {
    &hf_vrt_trailer_en_user3,
    &hf_vrt_trailer_en_user2,
    &hf_vrt_trailer_en_user1,
    &hf_vrt_trailer_en_user0,
    &hf_vrt_trailer_en_sampleloss,
    &hf_vrt_trailer_en_overrng,
    &hf_vrt_trailer_en_inv,
    &hf_vrt_trailer_en_sig,
    &hf_vrt_trailer_en_agc,
    &hf_vrt_trailer_en_reflock,
    &hf_vrt_trailer_en_valid,
    &hf_vrt_trailer_en_caltime
};

static int * const ind_hfs[] = {
    &hf_vrt_trailer_ind_user3,
    &hf_vrt_trailer_ind_user2,
    &hf_vrt_trailer_ind_user1,
    &hf_vrt_trailer_ind_user0,
    &hf_vrt_trailer_ind_sampleloss,
    &hf_vrt_trailer_ind_overrng,
    &hf_vrt_trailer_ind_inv,
    &hf_vrt_trailer_ind_sig,
    &hf_vrt_trailer_ind_agc,
    &hf_vrt_trailer_ind_reflock,
    &hf_vrt_trailer_ind_valid,
    &hf_vrt_trailer_ind_caltime
};

static void dissect_header(tvbuff_t *tvb, proto_tree *tree, int type, int offset);
static void dissect_trailer(tvbuff_t *tvb, proto_tree *tree, int offset);
static void dissect_cid(tvbuff_t *tvb, proto_tree *tree, int offset);
static int dissect_context(tvbuff_t *tvb, proto_tree *tree, int offset);
static int dissect_context_as_cif(tvbuff_t *tvb, proto_tree *tree, int offset, uint32_t cif, complex_dissector_t
    *complex_fptr, int **item_ptr, const int *size_ptr, int stop);
static int dissect_context_array_of_records(proto_tree *tree _U_, tvbuff_t *tvb, int offset);
static int dissect_context_assoc_lists(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_cif0(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_cif1(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_device_id(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_ecef_ephemeris(proto_tree *tree, tvbuff_t *tvb, int offset);
static void dissect_context_ephemeris(const ephemeris_fields *s, proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_gain(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_gps(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_gps_ascii(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_ins(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_phase_offset(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_polarization(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_ref_level(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_rel_ephemeris(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_signal_data_format(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_state_event(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_temperature(proto_tree *tree, tvbuff_t *tvb, int offset);
static int dissect_context_ver(proto_tree *tree, tvbuff_t *tvb, int offset);
static const char* get_engr_prefix(double *val);

/* context simple field dissector function pointer array (mutually exclusive with complex below) */
static int* hf_vrt_context_cif0[32] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, &hf_vrt_context_ephemeris_ref_id, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    &hf_vrt_context_timestamp_cal, &hf_vrt_context_timestamp_adjust, &hf_vrt_context_sample_rate,
    &hf_vrt_context_over_range_count, NULL, NULL, &hf_vrt_context_if_band_offset,
    &hf_vrt_context_rf_freq_offset, &hf_vrt_context_rf_freq, &hf_vrt_context_if_freq,
    &hf_vrt_context_bandwidth, &hf_vrt_context_ref_pt_id, NULL };

static int* hf_vrt_context_cif1[32] = { NULL, NULL, NULL, &hf_vrt_context_v49_spec, NULL,
    &hf_vrt_context_io64, &hf_vrt_context_io32, NULL, NULL, NULL, NULL, NULL, NULL,
    &hf_vrt_context_aux_bandwidth, NULL, &hf_vrt_context_aux_freq, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, &hf_vrt_context_range, NULL, NULL, NULL, NULL, NULL, NULL, NULL };


/* context complex field dissector function pointer array */
static complex_dissector_t complex_dissector_cif0[32] = {
    NULL, dissect_context_cif1, NULL, NULL, NULL, NULL, NULL, NULL, dissect_context_assoc_lists,
    dissect_context_gps_ascii, NULL, dissect_context_rel_ephemeris, dissect_context_ecef_ephemeris,
    dissect_context_ins, dissect_context_gps, dissect_context_signal_data_format,
    dissect_context_state_event, dissect_context_device_id, dissect_context_temperature, NULL,
    NULL, NULL, NULL, dissect_context_gain, dissect_context_ref_level, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL };

/* partial CIF1 support */
static complex_dissector_t complex_dissector_cif1[32] = {
    NULL, NULL, dissect_context_ver, NULL, NULL, NULL, NULL, dissect_context_array_of_records,
    NULL, dissect_context_array_of_records, NULL, dissect_context_array_of_records, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    dissect_context_array_of_records, NULL,
    dissect_context_polarization, dissect_context_phase_offset };


static int dissect_vrt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    int     offset = 0;
    guint8  type;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "VITA 49");
    col_clear(pinfo->cinfo,COL_INFO);

    /* HACK to support UHD's weird header offset on data packets. */
    if (vrt_use_ettus_uhd_header_format && tvb_get_guint8(tvb, 0) == 0)
        offset += 4;

    /* get packet type */
    type = tvb_get_guint8(tvb, offset) >> 4;
    col_add_str(pinfo->cinfo, COL_INFO, val_to_str(type, packet_types, "Reserved packet type (0x%02x)"));

    if (tree) { /* we're being asked for details */
        guint8  sidflag;
        guint8  cidflag;
        guint8  tflag;
        guint8  tsitype;
        guint8  tsftype;
        guint16 len;
        guint16 nsamps;

        proto_tree *vrt_tree;
        proto_item *ti;

        /* get SID, CID, T flags and TSI, TSF types */
        sidflag = (((type & 0x01) != 0) || (type == 4)) ? 1 : 0;
        cidflag = (tvb_get_guint8(tvb, offset) >> 3) & 0x01;
        /* tflag is in data packets but not context packets */
        tflag =   (tvb_get_guint8(tvb, offset) >> 2) & 0x01;
        if (type == 4)
            tflag = 0; /* this should be unnecessary but we do it just in case */
        /* tsmflag is in context packets but not data packets
           tsmflag = (tvb_get_guint8(tvb, offset) >> 0) & 0x01; */
        tsitype = (tvb_get_guint8(tvb, offset+1) >> 6) & 0x03;
        tsftype = (tvb_get_guint8(tvb, offset+1) >> 4) & 0x03;
        len     = tvb_get_ntohs(tvb, offset+2);

        nsamps  = len - 1;  /* (Before adjusting word count for optional fields) */

        ti = proto_tree_add_item(tree, proto_vrt, tvb, offset, -1, ENC_NA);
        vrt_tree = proto_item_add_subtree(ti, ett_vrt);

        dissect_header(tvb, vrt_tree, type, offset);
        offset += 4;

        /* header's done! if SID (last bit of type), put the stream ID here */
        if (sidflag) {
            proto_tree_add_item(vrt_tree, hf_vrt_sid, tvb, offset, 4, ENC_BIG_ENDIAN);
            nsamps -= 1;
            offset += 4;

        }

        /* if there's a class ID (cidflag), put the class ID here */
        if (cidflag) {
            dissect_cid(tvb, vrt_tree, offset);
            nsamps -= 2;
            offset += 8;
        }

        /* if TSI and/or TSF, populate those here */
        if (tsitype != 0) {
            proto_tree_add_item(vrt_tree, hf_vrt_ts_int, tvb, offset, 4, ENC_BIG_ENDIAN);
            nsamps -= 1;
            offset += 4;
        }
        if (tsftype != 0) {
            if (tsftype == 1 || tsftype == 3) {
                proto_tree_add_item(vrt_tree, hf_vrt_ts_frac_sample, tvb, offset, 8, ENC_BIG_ENDIAN);
            } else if (tsftype == 2) {
                proto_tree_add_item(vrt_tree, hf_vrt_ts_frac_picosecond, tvb, offset, 8, ENC_BIG_ENDIAN);
            }
            nsamps -= 2;
            offset += 8;
        }

        if (tflag) {
            nsamps -= 1;
        }

        /* now we've got either a context packet or a data packet */
        if (type == 4) {
            /* parse context packet */
            int num_v49_words = dissect_context(tvb, vrt_tree, offset);
            nsamps -= num_v49_words;
            offset += 4*num_v49_words;
        }

        /* we're into the data */
        if (nsamps != 0) {
            proto_tree_add_item(vrt_tree, hf_vrt_data, tvb, offset, nsamps*4, ENC_NA);
        }

        offset += nsamps*4;

        if (tflag) {
            dissect_trailer(tvb, vrt_tree, offset);
        }
    }
    return tvb_captured_length(tvb);
}

static void dissect_header(tvbuff_t *tvb, proto_tree *tree, int type, int offset)
{
    proto_item *hdr_item;
    proto_tree *hdr_tree;

    hdr_item = proto_tree_add_item(tree, hf_vrt_header, tvb, offset, 4, ENC_BIG_ENDIAN);

    hdr_tree = proto_item_add_subtree(hdr_item, ett_header);
    proto_tree_add_item(hdr_tree, hf_vrt_type, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(hdr_tree, hf_vrt_cidflag, tvb, offset, 1, ENC_BIG_ENDIAN);
    if (type == 4) {
        proto_tree_add_item(hdr_tree, hf_vrt_tsmflag, tvb, offset, 1, ENC_BIG_ENDIAN);
    } else {
        proto_tree_add_item(hdr_tree, hf_vrt_tflag, tvb, offset, 1, ENC_BIG_ENDIAN);
    }
    offset += 1;
    proto_tree_add_item(hdr_tree, hf_vrt_tsi, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(hdr_tree, hf_vrt_tsf, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(hdr_tree, hf_vrt_seq, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;
    proto_tree_add_item(hdr_tree, hf_vrt_len, tvb, offset, 2, ENC_BIG_ENDIAN);
}

static void dissect_trailer(tvbuff_t *tvb, proto_tree *tree, int offset)
{
    proto_item *enable_item, *ind_item, *trailer_item;
    proto_tree *enable_tree;
    proto_tree *ind_tree;
    proto_tree *trailer_tree;
    guint16     en_bits;
    gint16      i;

    trailer_item = proto_tree_add_item(tree, hf_vrt_trailer, tvb, offset, 4, ENC_BIG_ENDIAN);
    trailer_tree = proto_item_add_subtree(trailer_item, ett_trailer);

    /* grab the indicator enables and the indicators;
       only display enables, indicators which are enabled */
    enable_item = proto_tree_add_item(trailer_tree, hf_vrt_trailer_enables, tvb, offset, 2, ENC_BIG_ENDIAN);
    ind_item = proto_tree_add_item(trailer_tree, hf_vrt_trailer_ind, tvb, offset + 1, 2, ENC_BIG_ENDIAN);
    /* grab enable bits */
    en_bits = (tvb_get_ntohs(tvb, offset) & 0xFFF0) >> 4;

    /* if there's any enables, start trees for enable bits and for indicators
       only enables and indicators which are enabled get printed. */
    if (en_bits) {
        enable_tree = proto_item_add_subtree(enable_item, ett_ind_enables);
        ind_tree = proto_item_add_subtree(ind_item, ett_indicators);
        for (i = 11; i >= 0; i--) {
            if (en_bits & (1<<i)) {
                /* XXX: Display needs to be improved ... */
                proto_tree_add_item(enable_tree, *enable_hfs[i], tvb, offset,   2, ENC_BIG_ENDIAN);
                proto_tree_add_item(ind_tree, *ind_hfs[i],       tvb, offset+1, 2, ENC_BIG_ENDIAN);
            }
        }
    }
    offset += 3;
    proto_tree_add_item(trailer_tree, hf_vrt_trailer_e,    tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(trailer_tree, hf_vrt_trailer_acpc, tvb, offset, 1, ENC_BIG_ENDIAN);
}

static void dissect_cid(tvbuff_t *tvb, proto_tree *tree, int offset)
{
    proto_item *cid_item;
    proto_tree *cid_tree;

    cid_item = proto_tree_add_item(tree, hf_vrt_cid, tvb, offset, 8, ENC_BIG_ENDIAN);
    cid_tree = proto_item_add_subtree(cid_item, ett_cid);

    offset += 1;
    proto_tree_add_item(cid_tree, hf_vrt_cid_oui, tvb, offset, 3, ENC_BIG_ENDIAN);
    offset += 3;
    proto_tree_add_item(cid_tree, hf_vrt_cid_icc, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;
    proto_tree_add_item(cid_tree, hf_vrt_cid_pcc, tvb, offset, 2, ENC_BIG_ENDIAN);
}

static int dissect_context(tvbuff_t *tvb, proto_tree *tree, int offset)
{
    uint32_t cif[8] = {0, 0, 0, 0, 0, 0, 0, 0};
    int offset_start = offset;

    cif[0] = tvb_get_ntohl(tvb, offset);
    dissect_context_cif0(tree, tvb, offset);
    offset += 4;
    // CIF1-CIF7 bit fields come next with CIF1 first
    for (int i = 1; i < 8; i++) {
        if (cif[0] & (1 << i)) {
            if (complex_dissector_cif0[i] != NULL) {
                (*complex_dissector_cif0[i])(tree, tvb, offset);
            } else {
                proto_tree_add_item(tree, hf_vrt_cif[i], tvb, offset, 4, ENC_BIG_ENDIAN);
            }
            cif[i] = tvb_get_ntohl(tvb, offset);
            offset += 4;
        }
    }

    // decode CIF0 fields
    offset = dissect_context_as_cif(tvb, tree, offset, cif[0], complex_dissector_cif0, hf_vrt_context_cif0,
                                    context_size_cif0, 7);
    // finally other CIFs (only CIF1 for now)
    if (cif[0] & (1 << 1)) {
        offset = dissect_context_as_cif(tvb, tree, offset, cif[1], complex_dissector_cif1, hf_vrt_context_cif1,
                                        context_size_cif1, 0);
    }

    // return how many VITA-49 words were processed
    return (offset - offset_start)/4;
}

static int dissect_context_as_cif(tvbuff_t *tvb, proto_tree *tree, int offset, uint32_t cif,
                                  complex_dissector_t *complex_fptr, int **item_ptr, const int *size_ptr, int stop) {
    for (int i = 31; i > stop; i--) {
        if (cif & (1u << i)) {
            if (complex_fptr[i] != NULL) {
                // a complex dissector returns the variable part of field length (in bytes)
                offset += (*complex_fptr[i])(tree, tvb, offset);
            } else if (item_ptr[i] != NULL) {
                proto_tree_add_item(tree, *item_ptr[i], tvb, offset, size_ptr[i], ENC_BIG_ENDIAN);
            }
            // add fixed part of field length (in bytes)
            offset += size_ptr[i];
        }
    }

    return offset;
}

static int dissect_context_array_of_records(proto_tree *tree _U_, tvbuff_t *tvb, int offset) {
    // This is a placeholder that does not populate a proto tree, but computes & returns the
    // variable field length so subsequent field indexing is correct.
    return tvb_get_ntohl(tvb, offset)*4;
}

static int dissect_context_assoc_lists(proto_tree *tree, tvbuff_t *tvb, int offset) {
    // compute number of variable words in field
    guint32 word1 = tvb_get_ntohl(tvb, offset);
    guint32 src_size = (word1 >> 16) & 0x01FF;
    guint32 sys_size = word1 & 0x01FF;
    guint32 word2 = tvb_get_ntohl(tvb, offset + 4);
    guint32 vec_size = word2 >> 16;
    gboolean a_bit = (word2 & 0x8000) != 0;
    guint32 asy_size = word2 & 0x7FFF;
    guint32 num_words = src_size + sys_size + vec_size + asy_size + a_bit*asy_size;

    proto_tree *assoc_tree = proto_tree_add_subtree(tree, tvb, offset, 8 + num_words*4, ETT_IDX_ASSOC_LISTS, NULL,
                                                    "Context association lists");
    proto_tree_add_item(assoc_tree, hf_vrt_context_assoc_lists_src_size, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(assoc_tree, hf_vrt_context_assoc_lists_sys_size, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(assoc_tree, hf_vrt_context_assoc_lists_vec_size, tvb, offset + 4, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(assoc_tree, hf_vrt_context_assoc_lists_a, tvb, offset + 6, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(assoc_tree, hf_vrt_context_assoc_lists_asy_size, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
    offset += 8;

    if (src_size > 0) {
        proto_tree_add_item(assoc_tree, hf_vrt_context_assoc_lists_src_data, tvb, offset, src_size*4, ENC_NA);
        offset += src_size*4;
    }

    if (sys_size > 0) {
        proto_tree_add_item(assoc_tree, hf_vrt_context_assoc_lists_sys_data, tvb, offset, sys_size*4, ENC_NA);
        offset += sys_size*4;
    }

    if (vec_size > 0) {
        proto_tree_add_item(assoc_tree, hf_vrt_context_assoc_lists_vec_data, tvb, offset, vec_size*4, ENC_NA);
        offset += vec_size*4;
    }

    if (asy_size > 0) {
        proto_tree_add_item(assoc_tree, hf_vrt_context_assoc_lists_asy_data, tvb, offset, asy_size*4, ENC_NA);
        offset += asy_size*4;
        if (a_bit) {
            proto_tree_add_item(assoc_tree, hf_vrt_context_assoc_lists_asy_tag_data, tvb, offset, asy_size*4, ENC_NA);
        }
    }

    return num_words*4;
}

static int dissect_context_cif0(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_item *cif0_item;
    proto_tree *cif0_tree;

    cif0_item = proto_tree_add_item(tree, hf_vrt_cif[0], tvb, offset, 4, ENC_BIG_ENDIAN);
    cif0_tree = proto_item_add_subtree(cif0_item, ett_cif0);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_change_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_ref_pt_id, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_bandwidth, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_if_freq, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_rf_freq, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_rf_freq_offset, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_if_band_offset, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_ref_level, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_gain, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_over_range_count, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_sample_rate, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_timestamp_adjust, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_timestamp_cal, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_temperature, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_device_id, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_state_event, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_signal_data_format, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_gps, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_ins, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_ecef_ephemeris, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_rel_ephemeris, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_ephemeris_ref_id, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_gps_ascii, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_context_assoc_lists, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_cif7, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_cif6, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_cif5, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_cif4, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_cif3, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_cif2, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif0_tree, hf_vrt_cif0_cif1, tvb, offset, 1, ENC_BIG_ENDIAN);
    return 0;
}

static int dissect_context_cif1(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_item *cif1_item = proto_tree_add_item(tree, hf_vrt_cif[1], tvb, offset, 4, ENC_BIG_ENDIAN);
    proto_tree *cif1_tree = proto_item_add_subtree(cif1_item, ett_cif1);
    proto_tree_add_item(cif1_tree, hf_vrt_cif1_phase_offset, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif1_tree, hf_vrt_cif1_polarization, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif1_tree, hf_vrt_cif1_range, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif1_tree, hf_vrt_cif1_aux_freq, tvb, offset + 2, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif1_tree, hf_vrt_cif1_aux_bandwidth, tvb, offset + 2, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif1_tree, hf_vrt_cif1_io32, tvb, offset + 3, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif1_tree, hf_vrt_cif1_io64, tvb, offset + 3, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif1_tree, hf_vrt_cif1_v49_spec, tvb, offset + 3, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(cif1_tree, hf_vrt_cif1_ver, tvb, offset + 3, 1, ENC_BIG_ENDIAN);
    return 0;
}

static int dissect_context_device_id(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree *id_tree = proto_tree_add_subtree(tree, tvb, offset, 8, ETT_IDX_DEVICE_ID, NULL, "Device identifier");
    proto_tree_add_item(id_tree, hf_vrt_context_device_id_oui, tvb, offset + 1, 3, ENC_BIG_ENDIAN);
    proto_tree_add_item(id_tree, hf_vrt_context_device_id_code, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
    return 0;
}

static int dissect_context_ecef_ephemeris(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree *ecef_tree = proto_tree_add_subtree(tree, tvb, offset, 52, ETT_IDX_ECEF_EPHEM, NULL, "ECEF ephemeris");
    dissect_context_ephemeris(&hf_vrt_context_ecef_ephemeris, ecef_tree, tvb, offset);
    return 0;
}

static void dissect_context_ephemeris(const ephemeris_fields *s, proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree_add_item(tree, s->tsi, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->tsf, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->oui, tvb, offset + 1, 3, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->ts_int, tvb, offset + 4, 4, ENC_BIG_ENDIAN);

    guint8 tsftype = tvb_get_guint8(tvb, offset) & 0x03;
    if (tsftype == 1 || tsftype == 3) {
        proto_tree_add_item(tree, s->ts_frac_sample, tvb, offset + 8, 8, ENC_BIG_ENDIAN);
    } else if (tsftype == 2) {
        proto_tree_add_item(tree, s->ts_picosecond, tvb, offset + 8, 8, ENC_BIG_ENDIAN);
    }

    proto_tree_add_item(tree, s->pos_x, tvb, offset + 16, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->pos_y, tvb, offset + 20, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->pos_z, tvb, offset + 24, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->att_alpha, tvb, offset + 28, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->att_beta, tvb, offset + 32, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->att_phi, tvb, offset + 36, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->vel_dx, tvb, offset + 40, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->vel_dy, tvb, offset + 44, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->vel_dz, tvb, offset + 48, 4, ENC_BIG_ENDIAN);
}

static void dissect_context_formatted_gps_ins(const formatted_gps_ins_fields *s, proto_tree *tree, tvbuff_t *tvb,
                                              int offset) {
    proto_tree_add_item(tree, s->tsi, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->tsf, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->oui, tvb, offset + 1, 3, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->ts_int, tvb, offset + 4, 4, ENC_BIG_ENDIAN);

    guint8 tsftype = tvb_get_guint8(tvb, offset) & 0x03;
    if (tsftype == 1 || tsftype == 3) {
        proto_tree_add_item(tree, s->ts_frac_sample, tvb, offset + 8, 8, ENC_BIG_ENDIAN);
    } else if (tsftype == 2) {
        proto_tree_add_item(tree, s->ts_picosecond, tvb, offset + 8, 8, ENC_BIG_ENDIAN);
    }

    proto_tree_add_item(tree, s->lat, tvb, offset + 16, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->lon, tvb, offset + 20, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->alt, tvb, offset + 24, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->speed, tvb, offset + 28, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->heading, tvb, offset + 32, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->track, tvb, offset + 36, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, s->mag_var, tvb, offset + 40, 4, ENC_BIG_ENDIAN);
}

static int dissect_context_gain(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree *gain_tree = proto_tree_add_subtree(tree, tvb, offset, 4, ETT_IDX_GAIN, NULL, "Gain");
    proto_tree_add_item(gain_tree, hf_vrt_context_gain_stage2, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(gain_tree, hf_vrt_context_gain_stage1, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
    return 0;
}

static int dissect_context_gps(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree *gps_tree = proto_tree_add_subtree(tree, tvb, offset, 44, ETT_IDX_GPS, NULL, "Formatted GPS");
    dissect_context_formatted_gps_ins(&hf_vrt_context_gps, gps_tree, tvb, offset);
    return 0;
}

static int dissect_context_gps_ascii(proto_tree *tree, tvbuff_t *tvb, int offset) {
    guint32 nword = tvb_get_ntohl(tvb, offset + 4);
    proto_tree *gps_tree = proto_tree_add_subtree(tree, tvb, offset, 8 + nword*4, ETT_IDX_GPS_ASCII, NULL, "GPS ASCII");
    proto_tree_add_item(gps_tree, hf_vrt_context_gps_ascii_oui, tvb, offset + 1, 3, ENC_BIG_ENDIAN);
    proto_tree_add_item(gps_tree, hf_vrt_context_gps_ascii_size, tvb, offset + 4, 4, ENC_BIG_ENDIAN);

    if (nword > 0) {
        proto_tree_add_item(gps_tree, hf_vrt_context_gps_ascii_data, tvb, offset + 8, nword*4, ENC_NA);
    }

    return nword*4;
}

static int dissect_context_ins(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree *ins_tree = proto_tree_add_subtree(tree, tvb, offset, 44, ETT_IDX_INS, NULL, "Formatted INS");
    dissect_context_formatted_gps_ins(&hf_vrt_context_ins, ins_tree, tvb, offset);
    return 0;
}

static int dissect_context_phase_offset(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree_add_item(tree, hf_vrt_context_phase_offset, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
    return 0;
}

static int dissect_context_polarization(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree *pol_tree = proto_tree_add_subtree(tree, tvb, offset, 4, ETT_IDX_POL, NULL, "Polarization");
    proto_tree_add_item(pol_tree, hf_vrt_context_pol_tilt, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(pol_tree, hf_vrt_context_pol_ellipticity, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
    return 0;
}

static int dissect_context_ref_level(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree_add_item(tree, hf_vrt_context_ref_level, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
    return 0;
}

static int dissect_context_rel_ephemeris(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree *rel_tree = proto_tree_add_subtree(tree, tvb, offset, 52, ETT_IDX_REL_EPHEM, NULL, "Relative ephemeris");
    dissect_context_ephemeris(&hf_vrt_context_rel_ephemeris, rel_tree, tvb, offset);
    return 0;
}

static int dissect_context_signal_data_format(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree *format_tree = proto_tree_add_subtree(tree, tvb, offset, 8, ETT_IDX_SIGNAL_DATA_FORMAT, NULL,
                                                     "Signal data packet payload format");
    proto_tree_add_item(format_tree, hf_vrt_context_signal_data_format_packing, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(format_tree, hf_vrt_context_signal_data_format_type, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(format_tree, hf_vrt_context_signal_data_format_item, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;
    proto_tree_add_item(format_tree, hf_vrt_context_signal_data_format_repeat, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(format_tree, hf_vrt_context_signal_data_format_event_size, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(format_tree, hf_vrt_context_signal_data_format_channel_size, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;
    proto_tree_add_item(format_tree, hf_vrt_context_signal_data_format_fraction_size, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(format_tree, hf_vrt_context_signal_data_format_packing_size, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(format_tree, hf_vrt_context_signal_data_format_item_size, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;
    proto_tree_add_item(format_tree, hf_vrt_context_signal_data_format_repeat_count, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;
    proto_tree_add_item(format_tree, hf_vrt_context_signal_data_format_vector_size, tvb, offset, 2, ENC_BIG_ENDIAN);

    return 0;
}

static int dissect_context_state_event(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree *state_event_tree = proto_tree_add_subtree(tree, tvb, offset, 4, ETT_IDX_STATE_EVENT, NULL,
                                                          "State and event indicators");
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_en_cal_time, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_en_valid_data, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_en_ref_lock, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_en_agc, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_en_detected_sig, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_en_spectral_inv, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_en_over_range, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_en_sample_loss, tvb, offset, 1, ENC_BIG_ENDIAN);

    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_cal_time, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_valid_data, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_ref_lock, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_agc, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_detected_sig, tvb, offset + 2, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_spectral_inv, tvb, offset + 2, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_over_range, tvb, offset + 2, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_sample_loss, tvb, offset + 2, 1, ENC_BIG_ENDIAN);

    proto_tree_add_item(state_event_tree, hf_vrt_context_state_event_user, tvb, offset + 3, 1, ENC_BIG_ENDIAN);
    return 0;
}

static int dissect_context_temperature(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree_add_item(tree, hf_vrt_context_temperature, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
    return 0;
}

static int dissect_context_ver(proto_tree *tree, tvbuff_t *tvb, int offset) {
    proto_tree *ver_tree = proto_tree_add_subtree(tree, tvb, offset, 4, ETT_IDX_VER, NULL,
                                                  "Version and build code");
    proto_tree_add_item(ver_tree, hf_vrt_context_ver_year, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(ver_tree, hf_vrt_context_ver_day, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(ver_tree, hf_vrt_context_ver_rev, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(ver_tree, hf_vrt_context_ver_user, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
    return 0;
}

static void format_celsius(char *str, int16_t val) {
    snprintf(str, ITEM_LABEL_LENGTH, "%f °C", (double)val*RADIX_CELSIUS);
}

static void format_decibel(char *str, int16_t val) {
    snprintf(str, ITEM_LABEL_LENGTH, "%f dB", (double)val*RADIX_DECIBEL);
}

static void format_decibel_milliwatt(char *str, int16_t val) {
    snprintf(str, ITEM_LABEL_LENGTH, "%f dBm", (double)val*RADIX_DECIBEL_MILLIWATT);
}

static void format_degrees(char *str, int32_t val) {
    snprintf(str, ITEM_LABEL_LENGTH, "%f degrees", (double)val*RADIX_DEGREES);
}

static void format_hertz(char *str, int64_t val) {
    double val_f64 = (double)val*RADIX_HERTZ;
    const char *prefix = get_engr_prefix(&val_f64);
    snprintf(str, ITEM_LABEL_LENGTH, "%f %sHz", val_f64, prefix);
}

static void format_meter(char *str, int32_t val) {
    double val_f64 = (double)val*RADIX_METER;
    const char *prefix = get_engr_prefix(&val_f64);
    snprintf(str, ITEM_LABEL_LENGTH, "%f %sm", val_f64, prefix);
}

static void format_meter_unsigned(char *str, uint32_t val) {
    double val_f64 = (double)val*RADIX_METER_UNSIGNED;
    const char *prefix = get_engr_prefix(&val_f64);
    snprintf(str, ITEM_LABEL_LENGTH, "%f %sm", val_f64, prefix);
}

static void format_meters_per_second(char *str, int32_t val) {
    double val_f64 = (double)val*RADIX_METERS_PER_SECOND;
    const char *prefix = get_engr_prefix(&val_f64);
    snprintf(str, ITEM_LABEL_LENGTH, "%f %sm/s", val_f64, prefix);
}

static void format_radian_phase(char *str, int16_t val) {
    snprintf(str, ITEM_LABEL_LENGTH, "%f rad", (double)val*RADIX_RADIAN_PHASE);
}

static void format_radian_pol(char *str, int16_t val) {
    snprintf(str, ITEM_LABEL_LENGTH, "%f rad", (double)val*RADIX_RADIAN_POL);
}

static void format_second(char *str, int64_t val) {
    double val_f64 = (double)val*FEMTOSEC_PER_SEC;
    const char *prefix = get_engr_prefix(&val_f64);
    snprintf(str, ITEM_LABEL_LENGTH, "%f %ss", val_f64, prefix);
}

static const char* get_engr_prefix(double *val) {
    const char* prefix_str = "";
    int32_t exp = (int32_t)floor(log10(fabs(*val))/(double)3.0)*3;

    switch (exp) {
        case -15:
            prefix_str = "f";
            *val *= 1e15;
            break;
        case -12:
            prefix_str = "p";
            *val *= 1e12;
            break;
        case -9:
            prefix_str = "n";
            *val *= 1e9;
            break;
        case -6:
            prefix_str = "µ";
            *val *= 1e6;
            break;
        case -3:
            prefix_str = "m";
            *val *= 1e3;
            break;
        case 3:
            prefix_str = "k";
            *val *= 1e-3;
            break;
        case 6:
            prefix_str = "M";
            *val *= 1e-6;
            break;
        case 9:
            prefix_str = "G";
            *val *= 1e-9;
            break;
        case 12:
            prefix_str = "T";
            *val *= 1e-12;
            break;
    }

    return prefix_str;
}

void
proto_register_vrt(void)
{
    module_t *vrt_module;

    static hf_register_info hf[] = {
        { &hf_vrt_header,
            { "VRT header", "vrt.hdr",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_type,
            { "Packet type", "vrt.type",
            FT_UINT8, BASE_DEC,
            VALS(packet_types), 0xF0,
            NULL, HFILL }
        },
        { &hf_vrt_cidflag,
            { "Class ID included", "vrt.cidflag",
            FT_BOOLEAN, 8,
            NULL, 0x08,
            NULL, HFILL }
        },
        { &hf_vrt_tflag,
            { "Trailer included", "vrt.tflag",
            FT_BOOLEAN, 8,
            NULL, 0x04,
            NULL, HFILL }
        },
        { &hf_vrt_tsmflag,
            { "Timestamp mode", "vrt.tsmflag",
            FT_UINT8, BASE_DEC,
            VALS(tsm_types), 0x01,
            NULL, HFILL }
        },
        { &hf_vrt_tsi,
            { "Integer timestamp type", "vrt.tsi",
            FT_UINT8, BASE_DEC,
            VALS(tsi_types), 0xC0,
            NULL, HFILL }
        },
        { &hf_vrt_tsf,
            { "Fractional timestamp type", "vrt.tsf",
            FT_UINT8, BASE_DEC,
            VALS(tsf_types), 0x30,
            NULL, HFILL }
        },
        { &hf_vrt_seq,
            { "Sequence number", "vrt.seq",
            FT_UINT8, BASE_DEC,
            NULL, 0x0F,
            NULL, HFILL }
        },
        { &hf_vrt_len,
            { "Length", "vrt.len",
            FT_UINT16, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_ts_int,
            { "Integer timestamp", "vrt.ts_int",
            FT_UINT32, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_ts_frac_sample,
            { "Fractional timestamp (samples)", "vrt.ts_frac_sample",
            FT_UINT64, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_ts_frac_picosecond,
            { "Fractional timestamp (picoseconds)", "vrt.ts_frac_picosecond",
            FT_UINT64, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_sid,
            { "Stream ID", "vrt.sid",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_cid,
            { "Class ID", "vrt.cid",
            FT_UINT64, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_cif[0],
            { "CIF0", "vrt.cif0",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_change_flag,
            { "Context field change indicator", "vrt.cif0.change",
            FT_BOOLEAN, 8,
            NULL, 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_ref_pt_id,
            { "Reference point identifier", "vrt.cif0.refptid",
            FT_BOOLEAN, 8,
            NULL, 0x40,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_bandwidth,
            { "Bandwidth", "vrt.cif0.bw",
            FT_BOOLEAN, 8,
            NULL, 0x20,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_if_freq,
            { "IF reference frequency", "vrt.cif0.iffreq",
            FT_BOOLEAN, 8,
            NULL, 0x10,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_rf_freq,
            { "RF reference frequency", "vrt.cif0.rffreq",
            FT_BOOLEAN, 8,
            NULL, 0x08,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_rf_freq_offset,
            { "RF reference frequency offset", "vrt.cif0.rffreqoffset",
            FT_BOOLEAN, 8,
            NULL, 0x04,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_if_band_offset,
            { "IF band offset", "vrt.cif0.ifbandoffset",
            FT_BOOLEAN, 8,
            NULL, 0x02,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_ref_level,
            { "Reference level", "vrt.cif0.reflevel",
            FT_BOOLEAN, 8,
            NULL, 0x01,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_gain,
            { "Gain", "vrt.cif0.gain",
            FT_BOOLEAN, 8,
            NULL, 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_over_range_count,
            { "Over-range count", "vrt.cif0.overrangecount",
            FT_BOOLEAN, 8,
            NULL, 0x40,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_sample_rate,
            { "Sample rate", "vrt.cif0.samplerate",
            FT_BOOLEAN, 8,
            NULL, 0x20,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_timestamp_adjust,
            { "Timestamp adjustment", "vrt.cif0.timestampadjust",
            FT_BOOLEAN, 8,
            NULL, 0x10,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_timestamp_cal,
            { "Timestamp calibration time", "vrt.cif0.timestampcal",
            FT_BOOLEAN, 8,
            NULL, 0x08,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_temperature,
            { "Temperature", "vrt.cif0.temperature",
            FT_BOOLEAN, 8,
            NULL, 0x04,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_device_id,
            { "Device identifier", "vrt.cif0.deviceid",
            FT_BOOLEAN, 8,
            NULL, 0x02,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_state_event,
            { "State/event indicators", "vrt.cif0.stateevent",
            FT_BOOLEAN, 8,
            NULL, 0x01,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_signal_data_format,
            { "Signal data format", "vrt.cif0.signaldataformat",
            FT_BOOLEAN, 8,
            NULL, 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_gps,
            { "Formatted GPS", "vrt.cif0.gps",
            FT_BOOLEAN, 8,
            NULL, 0x40,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_ins,
            { "Formatted INS", "vrt.cif0.ins",
            FT_BOOLEAN, 8,
            NULL, 0x20,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_ecef_ephemeris,
            { "ECEF ephemeris", "vrt.cif0.ecefephem",
            FT_BOOLEAN, 8,
            NULL, 0x10,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_rel_ephemeris,
            { "Relative ephemeris", "vrt.cif0.relephem",
            FT_BOOLEAN, 8,
            NULL, 0x08,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_ephemeris_ref_id,
            { "Ephemeris ref ID", "vrt.cif0.ephemrefid",
            FT_BOOLEAN, 8,
            NULL, 0x04,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_gps_ascii,
            { "GPS ASCII", "vrt.cif0.gpsascii",
            FT_BOOLEAN, 8,
            NULL, 0x02,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_context_assoc_lists,
            { "Context association lists", "vrt.cif0.assoclists",
            FT_BOOLEAN, 8,
            NULL, 0x01,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_cif7,
            { "CIF7", "vrt.cif0.cif7",
            FT_BOOLEAN, 8,
            NULL, 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_cif6,
            { "CIF6", "vrt.cif0.cif6",
            FT_BOOLEAN, 8,
            NULL, 0x40,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_cif5,
            { "CIF5", "vrt.cif0.cif5",
            FT_BOOLEAN, 8,
            NULL, 0x20,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_cif4,
            { "CIF4", "vrt.cif0.cif4",
            FT_BOOLEAN, 8,
            NULL, 0x10,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_cif3,
            { "CIF3", "vrt.cif0.cif3",
            FT_BOOLEAN, 8,
            NULL, 0x08,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_cif2,
            { "CIF2", "vrt.cif0.cif2",
            FT_BOOLEAN, 8,
            NULL, 0x04,
            NULL, HFILL }
        },
        { &hf_vrt_cif0_cif1,
            { "CIF1", "vrt.cif0.cif1",
            FT_BOOLEAN, 8,
            NULL, 0x02,
            NULL, HFILL }
        },
        { &hf_vrt_cif1_phase_offset,
            { "Phase offset", "vrt.cif1.phaseoffset",
            FT_BOOLEAN, 8,
            NULL, 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_cif1_polarization,
            { "Polarization", "vrt.cif1.polarization",
            FT_BOOLEAN, 8,
            NULL, 0x40,
            NULL, HFILL }
        },
        { &hf_vrt_cif1_range,
            { "Range (distance)", "vrt.cif1.range",
            FT_BOOLEAN, 8,
            NULL, 0x01,
            NULL, HFILL }
        },
        { &hf_vrt_cif1_aux_freq,
            { "Aux frequency", "vrt.cif1.auxfreq",
            FT_BOOLEAN, 8,
            NULL, 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_cif1_aux_bandwidth,
            { "Aux bandwidth", "vrt.cif1.auxbw",
            FT_BOOLEAN, 8,
            NULL, 0x20,
            NULL, HFILL }
        },
        { &hf_vrt_cif1_io32,
            { "Discrete I/O (32-bit)", "vrt.cif1.io32",
            FT_BOOLEAN, 8,
            NULL, 0x40,
            NULL, HFILL }
        },
        { &hf_vrt_cif1_io64,
            { "Discrete I/O (64-bit)", "vrt.cif1.io64",
            FT_BOOLEAN, 8,
            NULL, 0x20,
            NULL, HFILL }
        },
        { &hf_vrt_cif1_v49_spec,
            { "V49 spec compliance", "vrt.cif1.v49spec",
            FT_BOOLEAN, 8,
            NULL, 0x08,
            NULL, HFILL }
        },
        { &hf_vrt_cif1_ver,
            { "Version and build code", "vrt.cif1.ver",
            FT_BOOLEAN, 8,
            NULL, 0x04,
            NULL, HFILL }
        },
        { &hf_vrt_cif[1],
            { "CIF1", "vrt.cif1",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_cif[2],
            { "CIF2", "vrt.cif2",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_cif[3],
            { "CIF3", "vrt.cif3",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_cif[4],
            { "CIF4", "vrt.cif4",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_cif[5],
            { "CIF5", "vrt.cif5",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_cif[6],
            { "CIF6", "vrt.cif6",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_cif[7],
            { "CIF7", "vrt.cif7",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ref_pt_id,
            { "Reference point identifier", "vrt.context.refptid",
            FT_UINT32, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_bandwidth,
            { "Bandwidth", "vrt.context.bw",
            FT_INT64, BASE_CUSTOM,
            CF_FUNC(format_hertz), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_if_freq,
            { "IF reference frequency", "vrt.context.iffreq",
            FT_INT64, BASE_CUSTOM,
            CF_FUNC(format_hertz), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rf_freq,
            { "RF reference frequency", "vrt.context.rffreq",
            FT_INT64, BASE_CUSTOM,
            CF_FUNC(format_hertz), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rf_freq_offset,
            { "RF reference frequency offset", "vrt.context.rffreqoffset",
            FT_INT64, BASE_CUSTOM,
            CF_FUNC(format_hertz), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_if_band_offset,
            { "IF band offset", "vrt.context.ifbandoffset",
            FT_INT64, BASE_CUSTOM,
            CF_FUNC(format_hertz), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ref_level,
            { "Reference level", "vrt.context.reflevel",
            FT_INT16, BASE_CUSTOM,
            CF_FUNC(format_decibel_milliwatt), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gain_stage2,
            { "Stage 2", "vrt.context.gain.stage2",
            FT_INT16, BASE_CUSTOM,
            CF_FUNC(format_decibel), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gain_stage1,
            { "Stage 1", "vrt.context.gain.stage1",
            FT_INT16, BASE_CUSTOM,
            CF_FUNC(format_decibel), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_over_range_count,
            { "Over-range count", "vrt.context.overrangecount",
            FT_UINT32, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_sample_rate,
            { "Sample rate", "vrt.context.samplerate",
            FT_INT64, BASE_CUSTOM,
            CF_FUNC(format_hertz), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_timestamp_adjust,
            { "Timestamp adjustment", "vrt.context.timestampadjust",
            FT_INT64, BASE_CUSTOM,
            CF_FUNC(format_second), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_timestamp_cal,
            { "Timestamp calibration", "vrt.context.timestampcal",
            FT_UINT32, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_temperature,
            { "Device temperature", "vrt.context.temperature",
            FT_INT16, BASE_CUSTOM,
            CF_FUNC(format_celsius), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_device_id_oui,
            { "Manufacturer OUI", "vrt.context.deviceid.oui",
            FT_UINT24, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_device_id_code,
            { "Device code", "vrt.context.deviceid.code",
            FT_UINT16, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_en_cal_time,
            { "Calibrated time enable", "vrt.context.stateevent.caltime.en",
            FT_BOOLEAN, 8,
            NULL, 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_en_valid_data,
            { "Valid data enable", "vrt.context.stateevent.validdata.en",
            FT_BOOLEAN, 8,
            NULL, 0x40,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_en_ref_lock,
            { "Reference lock enable", "vrt.context.stateevent.reflock.en",
            FT_BOOLEAN, 8,
            NULL, 0x20,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_en_agc,
            { "AGC/MGC enable", "vrt.context.stateevent.agc.en",
            FT_BOOLEAN, 8,
            NULL, 0x10,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_en_detected_sig,
            { "Detected signal enable", "vrt.context.stateevent.detectedsignal.en",
            FT_BOOLEAN, 8,
            NULL, 0x08,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_en_spectral_inv,
            { "Spectral inversion enable", "vrt.context.stateevent.spectralinv.en",
            FT_BOOLEAN, 8,
            NULL, 0x04,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_en_over_range,
            { "Over-range enable", "vrt.context.stateevent.overrange.en",
            FT_BOOLEAN, 8,
            NULL, 0x02,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_en_sample_loss,
            { "Sample loss enable", "vrt.cif0.context.sampleloss.en",
            FT_BOOLEAN, 8,
            NULL, 0x01,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_cal_time,
            { "Calibrated time indicator", "vrt.context.stateevent.caltime.val",
            FT_BOOLEAN, 8,
            NULL, 0x08,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_valid_data,
            { "Valid data indicator", "vrt.context.stateevent.validdata.val",
            FT_BOOLEAN, 8,
            NULL, 0x04,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_ref_lock,
            { "Reference lock indicator", "vrt.context.stateevent.reflock.val",
            FT_BOOLEAN, 8,
            NULL, 0x02,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_agc,
            { "AGC/MGC indicator", "vrt.context.stateevent.agc.val",
            FT_BOOLEAN, 8,
            NULL, 0x01,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_detected_sig,
            { "Detected signal indicator", "vrt.context.stateevent.detectedsignal.val",
            FT_BOOLEAN, 8,
            NULL, 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_spectral_inv,
            { "Spectral inversion indicator", "vrt.context.stateevent.spectralinv.val",
            FT_BOOLEAN, 8,
            NULL, 0x40,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_over_range,
            { "Over-range indicator", "vrt.context.stateevent.overrange.val",
            FT_BOOLEAN, 8,
            NULL, 0x20,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_sample_loss,
            { "Sample loss indicator", "vrt.context.stateevent.sampleloss.val",
            FT_BOOLEAN, 8,
            NULL, 0x10,
            NULL, HFILL }
        },
        { &hf_vrt_context_state_event_user,
            { "User-defined", "vrt.context.stateevent.user",
            FT_UINT8, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_signal_data_format_packing,
            { "Packing method", "vrt.context.signaldataformat.packing",
            FT_UINT8, BASE_DEC,
            VALS(packing_method), 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_context_signal_data_format_type,
            { "Real/complex type", "vrt.context.signaldataformat.realcomplex",
            FT_UINT8, BASE_DEC,
            VALS(data_sample_type), 0x60,
            NULL, HFILL }
        },
        { &hf_vrt_context_signal_data_format_item,
            { "Data item format", "vrt.context.signaldataformat.format",
            FT_UINT8, BASE_DEC,
            VALS(data_item_format), 0x1F,
            NULL, HFILL }
        },
        { &hf_vrt_context_signal_data_format_repeat,
            { "Sample-component repeat indicator", "vrt.context.signaldataformat.repeat",
            FT_BOOLEAN, 8,
            NULL, 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_context_signal_data_format_event_size,
            { "Event-tag size", "vrt.context.signaldataformat.eventsize",
            FT_UINT8, BASE_DEC,
            NULL, 0x70,
            NULL, HFILL }
        },
        { &hf_vrt_context_signal_data_format_channel_size,
            { "Channel-tag size", "vrt.context.signaldataformat.channelsize",
            FT_UINT8, BASE_DEC,
            NULL, 0x0F,
            NULL, HFILL }
        },
        { &hf_vrt_context_signal_data_format_fraction_size,
            { "Data item fraction size", "vrt.context.signaldataformat.fractionsize",
            FT_UINT16, BASE_DEC,
            NULL, 0xF000,
            NULL, HFILL }
        },
        { &hf_vrt_context_signal_data_format_packing_size,
            { "Item packing field size", "vrt.context.signaldataformat.packingsize",
            FT_UINT16, BASE_DEC,
            NULL, 0x0FC0,
            NULL, HFILL }
        },
        { &hf_vrt_context_signal_data_format_item_size,
            { "Data item size", "vrt.context.signaldataformat.itemsize",
            FT_UINT16, BASE_DEC,
            NULL, 0x003F,
            NULL, HFILL }
        },
        { &hf_vrt_context_signal_data_format_repeat_count,
            { "Repeat count", "vrt.context.signaldataformat.repeatcount",
            FT_UINT16, BASE_DEC,
            NULL, 0xFFFF,
            NULL, HFILL }
        },
        { &hf_vrt_context_signal_data_format_vector_size,
            { "Vector size", "vrt.context.signaldataformat.vectorsize",
            FT_UINT16, BASE_DEC,
            NULL, 0xFFFF,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.tsi,
            { "Integer timestamp type", "vrt.context.gps.tsi",
            FT_UINT8, BASE_DEC,
            VALS(tsi_types), 0x0C,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.tsf,
            { "Fractional timestamp type", "vrt.context.gps.tsf",
            FT_UINT8, BASE_DEC,
            VALS(tsf_types), 0x03,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.oui,
            { "Manufacturer OUI", "vrt.context.gps.oui",
            FT_UINT24, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.ts_int,
            { "Integer timestamp of position fix", "vrt.context.gps.ts_int",
            FT_UINT32, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.ts_frac_sample,
            { "Fractional timestamp (samples)", "vrt.context.gps.ts_frac_sample",
            FT_UINT64, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.ts_picosecond,
            { "Fractional timestamp (picoseconds)", "vrt.context.gps.ts_frac_picosecond",
            FT_UINT64, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.lat,
            { "Latitude", "vrt.context.gps.lat",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.lon,
            { "Longitude", "vrt.context.gps.lon",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.alt,
            { "Altitude", "vrt.context.gps.alt",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meter), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.speed,
            { "Speed over ground", "vrt.context.gps.speed",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meters_per_second), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.heading,
            { "Heading angle", "vrt.context.gps.heading",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.track,
            { "Track angle", "vrt.context.gps.track",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps.mag_var,
            { "Magnetic variation", "vrt.context.gps.mag_var",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.tsi,
            { "Integer timestamp type", "vrt.context.ins.tsi",
            FT_UINT8, BASE_DEC,
            VALS(tsi_types), 0x0C,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.tsf,
            { "Fractional timestamp type", "vrt.context.ins.tsf",
            FT_UINT8, BASE_DEC,
            VALS(tsf_types), 0x03,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.oui,
            { "Manufacturer OUI", "vrt.context.ins.oui",
            FT_UINT24, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.ts_int,
            { "Integer timestamp of position fix", "vrt.context.ins.ts_int",
            FT_UINT32, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.ts_frac_sample,
            { "Fractional timestamp (samples)", "vrt.context.ins.ts_frac_sample",
            FT_UINT64, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.ts_picosecond,
            { "Fractional timestamp (picoseconds)", "vrt.context.ins.ts_frac_picosecond",
            FT_UINT64, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.lat,
            { "Latitude", "vrt.context.ins.lat",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.lon,
            { "Longitude", "vrt.context.ins.lon",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.alt,
            { "Altitude", "vrt.context.ins.alt",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meter), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.speed,
            { "Speed over ground", "vrt.context.ins.speed",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meters_per_second), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.heading,
            { "Heading angle", "vrt.context.ins.heading",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.track,
            { "Track angle", "vrt.context.ins.track",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ins.mag_var,
            { "Magnetic variation", "vrt.context.ins.mag_var",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.tsi,
            { "Integer timestamp type", "vrt.context.ecefephem.tsi",
            FT_UINT8, BASE_DEC,
            VALS(tsi_types), 0x0C,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.tsf,
            { "Fractional timestamp type", "vrt.context.ecefephem.tsf",
            FT_UINT8, BASE_DEC,
            VALS(tsf_types), 0x03,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.oui,
            { "Manufacturer OUI", "vrt.context.ecefephem.oui",
            FT_UINT24, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.ts_int,
            { "Integer timestamp of position fix", "vrt.context.ecefephem.ts_int",
            FT_UINT32, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.ts_frac_sample,
            { "Fractional timestamp (samples)", "vrt.context.ecefephem.ts_frac_sample",
            FT_UINT64, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.ts_picosecond,
            { "Fractional timestamp (picoseconds)", "vrt.context.ecefephem.ts_frac_picosecond",
            FT_UINT64, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.pos_x,
            { "Position X", "vrt.context.ecefephem.posx",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meter), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.pos_y,
            { "Position Y", "vrt.context.ecefephem.posy",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meter), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.pos_z,
            { "Position Z", "vrt.context.ecefephem.posz",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meter), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.att_alpha,
            { "Attitude alpha (α)", "vrt.context.ecefephem.attalpha",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.att_beta,
            { "Attitude beta (β)", "vrt.context.ecefephem.attbeta",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.att_phi,
            { "Attitude phi (φ)", "vrt.context.ecefephem.attphi",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.vel_dx,
            { "Velocity dX", "vrt.context.ecefephem.veldx",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meters_per_second), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.vel_dy,
            { "Velocity dY", "vrt.context.ecefephem.veldy",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meters_per_second), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ecef_ephemeris.vel_dz,
            { "Velocity dZ", "vrt.context.ecefephem.veldz",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meters_per_second), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.tsi,
            { "Integer timestamp type", "vrt.context.relephem.tsi",
            FT_UINT8, BASE_DEC,
            VALS(tsi_types), 0x0C,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.tsf,
            { "Fractional timestamp type", "vrt.context.relephem.tsf",
            FT_UINT8, BASE_DEC,
            VALS(tsf_types), 0x03,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.oui,
            { "Manufacturer OUI", "vrt.context.relephem.oui",
            FT_UINT24, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.ts_int,
            { "Integer timestamp of position fix", "vrt.context.relephem.ts_int",
            FT_UINT32, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.ts_frac_sample,
            { "Fractional timestamp (samples)", "vrt.context.relephem.ts_frac_sample",
            FT_UINT64, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.ts_picosecond,
            { "Fractional timestamp (picoseconds)", "vrt.context.relephem.ts_frac_picosecond",
            FT_UINT64, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.pos_x,
            { "Position X", "vrt.context.relephem.posx",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meter), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.pos_y,
            { "Position Y", "vrt.context.relephem.posy",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meter), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.pos_z,
            { "Position Z", "vrt.context.relephem.posz",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meter), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.att_alpha,
            { "Attitude alpha (α)", "vrt.context.relephem.attalpha",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.att_beta,
            { "Attitude beta (β)", "vrt.context.relephem.attbeta",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.att_phi,
            { "Attitude phi (φ)", "vrt.context.relephem.attphi",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_degrees), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.vel_dx,
            { "Velocity dX", "vrt.context.relephem.veldx",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meters_per_second), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.vel_dy,
            { "Velocity dY", "vrt.context.relephem.veldy",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meters_per_second), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_rel_ephemeris.vel_dz,
            { "Velocity dZ", "vrt.context.relephem.veldz",
            FT_INT32, BASE_CUSTOM,
            CF_FUNC(format_meters_per_second), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ephemeris_ref_id,
            { "Ephemeris reference identifier", "vrt.context.ephemrefid",
            FT_UINT32, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps_ascii_oui,
            { "Manufacturer OUI", "vrt.context.gpsascii.oui",
            FT_UINT24, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps_ascii_size,
            { "Number of words", "vrt.context.gpsascii.size",
            FT_UINT32, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_gps_ascii_data,
            { "Data", "vrt.context.gpsascii.data",
            FT_BYTES, BASE_NONE,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_assoc_lists_src_size,
            { "Source list size", "vrt.context.assoclists.src.size",
            FT_UINT16, BASE_DEC,
            NULL, 0x01FF,
            NULL, HFILL }
        },
        { &hf_vrt_context_assoc_lists_sys_size,
            { "System list size", "vrt.context.assoclists.sys.size",
            FT_UINT16, BASE_DEC,
            NULL, 0x01FF,
            NULL, HFILL }
        },
        { &hf_vrt_context_assoc_lists_vec_size,
            { "Vector-component list size", "vrt.context.assoclists.vec.size",
            FT_UINT16, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_assoc_lists_a,
            { "A bit (asynchronous-channel tag list present)", "vrt.context.assoclists.a",
            FT_BOOLEAN, 8,
            NULL, 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_context_assoc_lists_asy_size,
            { "Asynchronous-channel list size", "vrt.context.assoclists.asy.size",
            FT_UINT16, BASE_DEC,
            NULL, 0x7FFF,
            NULL, HFILL }
        },
        { &hf_vrt_context_assoc_lists_src_data,
            { "Source context association list", "vrt.context.assoclists.src.data",
            FT_BYTES, BASE_NONE,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_assoc_lists_sys_data,
            { "System context association list", "vrt.context.assoclists.sys.data",
            FT_BYTES, BASE_NONE,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_assoc_lists_vec_data,
            { "Vector-component context association list", "vrt.context.assoclists.vec.data",
            FT_BYTES, BASE_NONE,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_assoc_lists_asy_data,
            { "Asynchronous-channel context association list", "vrt.context.assoclists.asy.data",
            FT_BYTES, BASE_NONE,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_assoc_lists_asy_tag_data,
            { "Asynchronous-channel tag list", "vrt.context.assoclists.asy.tagdata",
            FT_BYTES, BASE_NONE,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_phase_offset,
            { "Phase offset", "vrt.context.phaseoffset",
            FT_INT16, BASE_CUSTOM,
            CF_FUNC(format_radian_phase), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_pol_tilt,
            { "Tilt angle (θ)", "vrt.context.polarization.tilt",
            FT_INT16, BASE_CUSTOM,
            CF_FUNC(format_radian_pol), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_pol_ellipticity,
            { "Ellipticity angle (χ)", "vrt.context.polarization.ellipticity",
            FT_INT16, BASE_CUSTOM,
            CF_FUNC(format_radian_pol), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_range,
            { "Range (distance)", "vrt.context.range",
            FT_UINT32, BASE_CUSTOM,
            CF_FUNC(format_meter_unsigned), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_aux_freq,
            { "Aux frequency", "vrt.context.auxfreq",
            FT_INT64, BASE_CUSTOM,
            CF_FUNC(format_hertz), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_aux_bandwidth,
            { "Aux bandwidth", "vrt.context.auxbw",
            FT_INT64, BASE_CUSTOM,
            CF_FUNC(format_hertz), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_io32,
            { "Discrete I/O (32-bit)", "vrt.context.io32",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_io64,
            { "Discrete I/O (64-bit)", "vrt.context.io64",
            FT_UINT64, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_v49_spec,
            { "V49 spec compliance", "vrt.context.v49spec",
            FT_UINT32, BASE_HEX,
            VALS(standard_version_codes), 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ver_year,
            { "Year", "vrt.context.ver.year",
            FT_UINT16, BASE_DEC,
            NULL, 0xFE00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ver_day,
            { "Day", "vrt.context.ver.day",
            FT_UINT16, BASE_DEC,
            NULL, 0x01FF,
            NULL, HFILL }
        },
        { &hf_vrt_context_ver_rev,
            { "Revision", "vrt.context.ver.rev",
            FT_UINT16, BASE_DEC,
            NULL, 0xFC00,
            NULL, HFILL }
        },
        { &hf_vrt_context_ver_user,
            { "User defined", "vrt.context.ver.user",
            FT_UINT16, BASE_DEC,
            NULL, 0x03FF,
            NULL, HFILL }
        },
        { &hf_vrt_data,
            { "Data", "vrt.data",
            FT_BYTES, BASE_NONE,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_trailer,
            { "Trailer", "vrt.trailer",
            FT_UINT32, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_enables,
            { "Indicator enable bits", "vrt.enables",
            FT_UINT16, BASE_HEX,
            NULL, 0xFFF0,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind,
            { "Indicator bits", "vrt.indicators",
            FT_UINT16, BASE_HEX,
            NULL, 0x0FFF,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_e,
            { "Associated context packet count enabled", "vrt.e",
            FT_BOOLEAN, 8,
            NULL, 0x80,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_acpc,
            { "Associated context packet count", "vrt.acpc",
            FT_UINT8, BASE_DEC,
            NULL, 0x7F,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_caltime,
            { "Calibrated time indicator", "vrt.caltime",
            FT_BOOLEAN, 16,
            NULL, 0x0800,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_valid,
            { "Valid signal indicator", "vrt.valid",
            FT_BOOLEAN, 16,
            NULL, 0x0400,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_reflock,
            { "Reference lock indicator", "vrt.reflock",
            FT_BOOLEAN, 16,
            NULL, 0x0200,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_agc,
            { "AGC/MGC indicator", "vrt.agc",
            FT_BOOLEAN, 16,
            NULL, 0x0100,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_sig,
            { "Signal detected indicator", "vrt.sig",
            FT_BOOLEAN, 16,
            NULL, 0x0080,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_inv,
            { "Spectral inversion indicator", "vrt.inv",
            FT_BOOLEAN, 16,
            NULL, 0x0040,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_overrng,
            { "Overrange indicator", "vrt.overrng",
            FT_BOOLEAN, 16,
            NULL, 0x0020,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_sampleloss,
            { "Lost sample indicator", "vrt.sampleloss",
            FT_BOOLEAN, 16,
            NULL, 0x0010,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_user0,
            { "User indicator 0", "vrt.user0",
            FT_BOOLEAN, 16,
            NULL, 0x0008,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_user1,
            { "User indicator 1", "vrt.user1",
            FT_BOOLEAN, 16,
            NULL, 0x0004,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_user2,
            { "User indicator 2", "vrt.user2",
            FT_BOOLEAN, 16,
            NULL, 0x0002,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_ind_user3,
            { "User indicator 3", "vrt.user3",
            FT_BOOLEAN, 16,
            NULL, 0x0001,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_caltime,
            { "Calibrated time indicator enable", "vrt.caltime_en",
            FT_BOOLEAN, 16,
            NULL, 0x8000,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_valid,
            { "Valid signal indicator enable", "vrt.valid_en",
            FT_BOOLEAN, 16,
            NULL, 0x4000,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_reflock,
            { "Reference lock indicator enable", "vrt.reflock_en",
            FT_BOOLEAN, 16,
            NULL, 0x2000,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_agc,
            { "AGC/MGC indicator enable", "vrt.agc_en",
            FT_BOOLEAN, 16,
            NULL, 0x1000,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_sig,
            { "Signal detected indicator enable", "vrt.sig_en",
            FT_BOOLEAN, 16,
            NULL, 0x0800,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_inv,
            { "Spectral inversion indicator enable", "vrt.inv_en",
            FT_BOOLEAN, 16,
            NULL, 0x0400,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_overrng,
            { "Overrange indicator enable", "vrt.overrng_en",
            FT_BOOLEAN, 16,
            NULL, 0x0200,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_sampleloss,
            { "Lost sample indicator enable", "vrt.sampleloss_en",
            FT_BOOLEAN, 16,
            NULL, 0x0100,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_user0,
            { "User indicator 0 enable", "vrt.user0_en",
            FT_BOOLEAN, 16,
            NULL, 0x0080,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_user1,
            { "User indicator 1 enable", "vrt.user1_en",
            FT_BOOLEAN, 16,
            NULL, 0x0040,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_user2,
            { "User indicator 2 enable", "vrt.user2_en",
            FT_BOOLEAN, 16,
            NULL, 0x0020,
            NULL, HFILL }
        },
        { &hf_vrt_trailer_en_user3,
            { "User indicator 3 enable", "vrt.user3_en",
            FT_BOOLEAN, 16,
            NULL, 0x0010,
            NULL, HFILL }
        },
        { &hf_vrt_cid_oui,
            { "Class ID Organizationally Unique ID", "vrt.oui",
            FT_UINT24, BASE_HEX,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_cid_icc,
            { "Class ID Information Class Code", "vrt.icc",
            FT_UINT16, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        },
        { &hf_vrt_cid_pcc,
            { "Class ID Packet Class Code", "vrt.pcc",
            FT_UINT16, BASE_DEC,
            NULL, 0x00,
            NULL, HFILL }
        }
    };

    // update ETT_IDX_* as new items added to track indices
    static gint *ett[] = {
        &ett_vrt,
        &ett_header,
        &ett_trailer,
        &ett_indicators,
        &ett_ind_enables,
        &ett_cid,
        &ett_cif0,
        &ett_cif1,
        &ett_gain, // ETT_IDX_GAIN
        &ett_device_id,  // ETT_IDX_DEVICE_ID
        &ett_state_event, // ETT_IDX_STATE_EVENT
        &ett_signal_data_format, // ETT_IDX_SIGNAL_DATA_FORMAT
        &ett_gps, // ETT_IDX_GPS
        &ett_ins, // ETT_IDX_INS
        &ett_ecef_ephem, // ETT_IDX_ECEF_EPHEM
        &ett_rel_ephem, // ETT_IDX_REL_EPHEM
        &ett_gps_ascii, // ETT_IDX_GPS_ASCII
        &ett_assoc_lists, // ETT_IDX_ASSOC_LISTS
        &ett_pol, // ETT_IDX_POL
        &ett_ver, // ETT_IDX_VER
     };

    proto_vrt = proto_register_protocol ("VITA 49 radio transport protocol", "VITA 49", "vrt");

    proto_register_field_array(proto_vrt, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    vrt_module = prefs_register_protocol(proto_vrt, NULL);
    prefs_register_bool_preference(vrt_module, "ettus_uhd_header_format",
        "Use Ettus UHD header format",
        "Activate workaround for weird Ettus UHD header offset on data packets",
        &vrt_use_ettus_uhd_header_format);
}

void
proto_reg_handoff_vrt(void)
{
    dissector_handle_t vrt_handle;

    vrt_handle = create_dissector_handle(dissect_vrt, proto_vrt);
    dissector_add_uint_with_preference("udp.port", VITA_49_PORT, vrt_handle);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */