summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-s5066dts.c
blob: 522820c144dc4cf248d61e815b1a1e2676462cfb (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
/*
 * packet-s5066dts.c
 * Routines for STANAG 5066 DTS layer packet dissection
 *
 * Copyright (c) 2013
 *  by Ibrahim Can Yuce <canyuce [at] gmail [dot] com>
 *  by M. Baris Demiray <baris.demiray [at] gmail [dot] com>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/expert.h>
#include "packet-tcp.h" /* For tcp_dissect_pdus() */
#include <epan/crc16-tvb.h>
#include <epan/crc32-tvb.h>
#include <wiretap/wtap.h>

#define DISSECTOR_NAME                      "s5066dts"
/* STANAG 5066 DPDU properties */
#define S5066_DPDU_MAX_DPDU_SIZE            1070
#define S5066_DPDU_FRAME_HEADER_LEN         15
/* Header field index (in bytes) and size (in bits) constants */
#define S5066_DPDU_EOW_TYPE_INDEX           2
#define S5066_DPDU_EOW_CONTENT_INDEX        3
#define S5066_DPDU_EOT_INDEX                4
#define S5066_DPDU_SIZE_OF_ADDRESS_INDEX    5
#define S5066_DPDU_SIZE_OF_HEADER_INDEX     5
#define S5066_DPDU_SYNC_SEQUENCE_SIZE       2 /*bytes*/
/* D_PDU message types */
#define S5066_DPDU_DATA_ONLY                0
#define S5066_DPDU_ACK_ONLY                 1
#define S5066_DPDU_DATA_ACK                 2
#define S5066_DPDU_RESET_WIN_RESYNC         3
#define S5066_DPDU_EXP_DATA_ONLY            4
#define S5066_DPDU_EXP_ACK_ONLY             5
#define S5066_DPDU_MANAGEMENT               6
#define S5066_DPDU_NON_ARQ_DATA             7
#define S5066_DPDU_EXP_NON_ARQ_DATA         8
#define S5066_DPDU_WARNING                  15
/* EOW message types */
#define S5066_EOW_RESERVED                  0
#define S5066_EOW_DRC_REQUEST               1
#define S5066_EOW_DRC_RESPONSE              2
#define S5066_EOW_UNRECOGNIZED_TYPE         3
#define S5066_EOW_CAPABILITY                4
#define S5066_EOW_ALM_REQUEST               5
#define S5066_EOW_ALM_RESPONSE              6
#define S5066_EOW_HDR_DRC_REQUEST           7
#define S5066_EOW_HFTRP_TOKEN               15

void proto_register_s5066dts(void);

static int proto_s5066dts;

static dissector_handle_t s5066dts_handle;
static dissector_handle_t s5066dts_over_tcp_handle;

/* Configuration parameters */
static bool config_proto_desegment = true;

/* Initialize expert fields */
static expert_field ei_s5066dts_eow_hdr_drc_request_invalid;
static expert_field ei_s5066dts_eow_hftrp_invalid;

/* TCP port that will be listened by the application that peer
 * dts layers will be connected through
 */
static range_t *config_s5066dts_ports;

static int hf_s5066dts_sync_word;
static int hf_s5066dts_dpdu_type;
static int hf_s5066dts_eow_type;
static int hf_s5066dts_eow_data;
static int hf_s5066dts_eot;
static int hf_s5066dts_address_size;
static int hf_s5066dts_header_size;
static int hf_s5066dts_header_crc;
static int hf_s5066dts_cpdu_crc;
static int hf_s5066dts_segmented_cpdu;
static int hf_s5066dts_dest_addr;
static int hf_s5066dts_src_addr;

/* EOW TYPES */
/* { 1, "DRC_REQUEST"}, */
static int hf_s5066dts_eow_drc_request_data_rate;
static int hf_s5066dts_eow_drc_request_interleaving;
static int hf_s5066dts_eow_drc_request_others;
/* { 2, "DRC_RESPONSE"}, */
static int hf_s5066dts_eow_drc_response_response;
static int hf_s5066dts_eow_drc_response_reason;
/* { 3, "UNRECOGNIZED_TYPE"}, */
static int hf_s5066dts_eow_unrec_type_response;
static int hf_s5066dts_eow_unrec_type_reason;
/* { 4, "CAPABILITY"}, */
static int hf_s5066dts_eow_capability_adaptive;
static int hf_s5066dts_eow_capability_stanag_4529;
static int hf_s5066dts_eow_capability_mil_std_188_110a;
static int hf_s5066dts_eow_capability_extended;
static int hf_s5066dts_eow_capability_full_duplex;
static int hf_s5066dts_eow_capability_split_frequency;
static int hf_s5066dts_eow_capability_non_arcs_ale;
static int hf_s5066dts_eow_capability_arcs;
/* { 5, "ALM_REQUEST"}, */
static int hf_s5066dts_eow_alm_request_data_rate;
static int hf_s5066dts_eow_alm_request_interleaving;
static int hf_s5066dts_eow_alm_request_others;
/* { 6, "ALM_RESPONSE"}, */
static int hf_s5066dts_eow_alm_response_response;
static int hf_s5066dts_eow_alm_response_reason;
/* { 7, "HDR_DRC_REQUEST"}, */
static int hf_s5066dts_eow_hdr_drc_request_waveform;
static int hf_s5066dts_eow_hdr_drc_request_num_channels;
static int hf_s5066dts_eow_hdr_drc_request_data_rate;
static int hf_s5066dts_eow_hdr_drc_request_interleaver_length;
/* {15, "HFTRP FRAME CONTROL"}, */
static int hf_s5066dts_eow_hftrp_hftrp_token;

/* DPDU TYPES */
/* { 0, "DATA_ONLY"}, */
static int hf_s5066dts_data_only_cpdu_start;
static int hf_s5066dts_data_only_cpdu_end;
static int hf_s5066dts_data_only_deliver_in_order;
static int hf_s5066dts_data_only_drop_cpdu;
static int hf_s5066dts_data_only_tx_win_uwe;
static int hf_s5066dts_data_only_tx_win_lwe;
static int hf_s5066dts_data_only_segmented_cpdu_size;
static int hf_s5066dts_data_only_transmit_sequence_number;
/* { 1, "ACK_ONLY"}, */
static int hf_s5066dts_ack_only_rx_lwe;
static int hf_s5066dts_ack_only_acks;
/* { 2, "DATA_ACK"}, */
static int hf_s5066dts_data_ack_cpdu_start;
static int hf_s5066dts_data_ack_cpdu_end;
static int hf_s5066dts_data_ack_deliver_in_order;
static int hf_s5066dts_data_ack_drop_cpdu;
static int hf_s5066dts_data_ack_tx_win_uwe;
static int hf_s5066dts_data_ack_tx_win_lwe;
static int hf_s5066dts_data_ack_segmented_cpdu_size;
static int hf_s5066dts_data_ack_transmit_sequence_number;
static int hf_s5066dts_data_ack_rx_lwe;
static int hf_s5066dts_data_ack_acks;
/* { 3, "RESET_WIN_RESYNC"}, */
static int hf_s5066dts_reset_win_resync_unused;
static int hf_s5066dts_reset_win_resync_full_reset_command;
static int hf_s5066dts_reset_win_resync_reset_tx_win_rqst;
static int hf_s5066dts_reset_win_resync_reset_rx_win_cmnd;
static int hf_s5066dts_reset_win_resync_reset_ack;
static int hf_s5066dts_reset_win_resync_new_rx_lwe;
static int hf_s5066dts_reset_win_resync_reset_frame_id_number;
/* { 4, "EXP_DATA_ONLY"}, */
static int hf_s5066dts_exp_data_only_cpdu_start;
static int hf_s5066dts_exp_data_only_cpdu_end;
static int hf_s5066dts_exp_data_only_cpdu_id;
static int hf_s5066dts_exp_data_only_segmented_cpdu_size;
static int hf_s5066dts_exp_data_only_transmit_sequence_number;
/* { 5, "EXP_ACK_ONLY"}, */
static int hf_s5066dts_exp_ack_only_rx_lwe;
static int hf_s5066dts_exp_ack_only_acks;
/* { 6, "MANAGEMENT"}, */
static int hf_s5066dts_management_unused;
static int hf_s5066dts_management_extended_message_flag;
static int hf_s5066dts_management_message;
static int hf_s5066dts_management_ack;
static int hf_s5066dts_management_management_frame_id;
static int hf_s5066dts_management_extended_message;
static int hf_s5066dts_management_extended_message_hftrp_payload_size;
static int hf_s5066dts_management_extended_message_hftrp_ra;
static int hf_s5066dts_management_extended_message_hftrp_seq_id;
static int hf_s5066dts_management_extended_message_hftrp_gen_seq_id;
static int hf_s5066dts_management_extended_message_hftrp_new_successor_id;
static int hf_s5066dts_management_extended_message_hftrp_number_of_nodes;
/* { 7, "NON_ARQ_DATA"}, */
static int hf_s5066dts_non_arq_data_cpdu_id_1;
static int hf_s5066dts_non_arq_data_deliver_in_order;
static int hf_s5066dts_non_arq_data_group_address;
static int hf_s5066dts_non_arq_data_cpdu_id_2;
static int hf_s5066dts_non_arq_data_cpdu_size;
static int hf_s5066dts_non_arq_data_cpdu_segment_offset;
static int hf_s5066dts_non_arq_data_cpdu_reception_window;
static int hf_s5066dts_non_arq_data_segmented_cpdu_size;
/* { 8, "EXP_NON_ARQ_DATA"}, */
static int hf_s5066dts_exp_non_arq_data_cpdu_id_1;
static int hf_s5066dts_exp_non_arq_data_deliver_in_order;
static int hf_s5066dts_exp_non_arq_data_group_address;
static int hf_s5066dts_exp_non_arq_data_cpdu_id_2;
static int hf_s5066dts_exp_non_arq_data_cpdu_size;
static int hf_s5066dts_exp_non_arq_data_cpdu_segment_offset;
static int hf_s5066dts_exp_non_arq_data_cpdu_reception_window;
static int hf_s5066dts_exp_non_arq_data_segmented_cpdu_size;
/* {15, "WARNING"}, */
static int hf_s5066dts_warning_frame_type;
static int hf_s5066dts_warning_reason;

static int ett_s5066dts;
static int ett_s5066dts_eow;
static int ett_s5066dts_address;
static int ett_s5066dts_pdu;
static int ett_s5066dts_hftrp_token;

static const value_string s5066dts_dpdu_type[] = {
    { 0, "DATA_ONLY"},
    { 1, "ACK_ONLY"},
    { 2, "DATA_ACK"},
    { 3, "RESET_WIN_RESYNC"},
    { 4, "EXP_DATA_ONLY"},
    { 5, "EXP_ACK_ONLY"},
    { 6, "MANAGEMENT"},
    { 7, "NON_ARQ_DATA"},
    { 8, "EXP_NON_ARQ_DATA"},
    {15, "WARNING"},
    { 0, NULL},
};

static const value_string s5066dts_eow_type[] = {
    {  0, "RESERVED"},
    {  1, "DRC_REQUEST"},
    {  2, "DRC_RESPONSE"},
    {  3, "UNRECOGNIZED_TYPE"},
    {  4, "CAPABILITY"},
    {  5, "ALM_REQUEST"},
    {  6, "ALM_RESPONSE"},
    {  7, "HDR_DRC_REQUEST"},
    { 15, "HFTRP_TOKEN"},
    {  0, NULL},
};

static const value_string s5066dts_eow_data_rate[] = {
    { 0, "75 bps"},
    { 1, "150 bps"},
    { 2, "300 bps"},
    { 3, "600 bps"},
    { 4, "1200 bps"},
    { 5, "2400 bps"},
    { 6, "3200 bps"},
    { 7, "3600 bps"},
    { 8, "4800 bps"},
    { 9, "6400 bps"},
    { 10, "8000 bps"},
    { 11, "9600 bps"},
    {  0, NULL},
};

static const value_string s5066dts_eow_interleaving[] = {
    { 0, "No interleaving"},
    { 1, "Short interleaving"},
    { 2, "Long interleaving"},
    { 3, "Reserved"},
    { 0, NULL},
};

static const value_string s5066dts_eow_others[] = {
    { 0, "Request: Master has independent data rate"},
    { 1, "Request: Tx=Rx at master"},
    { 2, "Advisory: Advising node has independent data rate"},
    { 3, "Advisory: Tx=Rx at advising node"},
    { 0, NULL},
};

static const value_string s5066dts_eow_response[] = {
    { 0, "Accept"},
    { 1, "Refuse"},
    { 2, "Cancel"},
    { 3, "Confirm"},
    { 0, NULL},
};

static const value_string s5066dts_eow_reason[] = {
    { 0, "No reason"},
    { 1, "Tx and Rx parameters must be the same"},
    { 2, "Not possible to change modem data rate"},
    { 3, "Not possible to change modem interleaving"},
    { 4, "Not possible to change modem data rate or interleaving"},
    { 5, "Not consistent with local conditions"},
    { 0, NULL},
};

static const value_string s5066dts_eow_waveform[] = {
    { 0, "MS110A"},
    { 1, "MS110B"},
    { 2, "STANAG_4285"},
    { 3, "STANAG_4539"},
    { 4, "STANAG_4529"},
    { 5, "STANAG_4415"},
    { 6, "STANAG_4481_FSK"},
    { 7, "USER_CONFIGURATION_OPTION_1"},
    { 8, "USER_CONFIGURATION_OPTION_2"},
    { 9, "USER_CONFIGURATION_OPTION_3"},
    { 0, NULL},
};

/* Used in Packet List pane */
static const value_string s5066dts_eow_hftrp_frame_control_abbr[] = {
    { 1, "RTT"},
    { 2, "ACK"},
    { 3, "SLS"},
    { 4, "SET"},
    { 5, "REL"},
    { 6, "DEL"},
    { 0, NULL},
};

/* Used in Packet Details pane */
static const value_string s5066dts_eow_hftrp_frame_control[] = {
    { 1, "RTT - Right-to-transmit Token"},
    { 2, "ACK - Acknowledgment Token"},
    { 3, "SLS - Solicit Successor Token"},
    { 4, "SET - Set Successor Token"},
    { 5, "REL - Relayed Token"},
    { 6, "DEL - Delete Token"},
    { 0, NULL},
};

static const value_string s5066dts_alm_reason[] = {
    { 0, "No reason"},
    { 1, "Tx and Rx parameters must be the same"},
    { 2, "Not possible to change modem data rate"},
    { 3, "Not possible to change modem interleaving"},
    { 4, "Not possible to change modem data rate or interleaving"},
    { 5, "Not consistent with local conditions"},
    { 6, "Not possible to change frequency"},
    { 0, NULL},
};

/* Register functions' forward references */
void proto_reg_handoff_s5066dts(void);

/* { 1, "DRC_REQUEST"}, */
static void dissect_s5066dts_eow_drc_request(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_eow_drc_request_data_rate, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_drc_request_interleaving, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_drc_request_others, tvb, offset, 1, ENC_BIG_ENDIAN);
}

/* { 2, "DRC_RESPONSE"}, */
static void dissect_s5066dts_eow_drc_response(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_eow_drc_response_response, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_drc_response_reason, tvb, offset, 1, ENC_BIG_ENDIAN);
}

/* { 3, "UNRECOGNIZED_TYPE"}, */
static void dissect_s5066dts_eow_unrec_type(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_eow_unrec_type_response, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_unrec_type_reason, tvb, offset, 1, ENC_BIG_ENDIAN);
}

/* { 4, "CAPABILITY"}, */
static void dissect_s5066dts_eow_capability(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_eow_capability_adaptive, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_capability_stanag_4529, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_capability_mil_std_188_110a, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_capability_extended, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_capability_full_duplex, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_capability_split_frequency, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_capability_non_arcs_ale, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_capability_arcs, tvb, offset, 1, ENC_BIG_ENDIAN);
}

/* { 5, "ALM_REQUEST"}, */
static void dissect_s5066dts_eow_alm_request(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_eow_alm_request_data_rate, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_alm_request_interleaving, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_alm_request_others, tvb, offset, 1, ENC_BIG_ENDIAN);
}

/* { 6, "ALM_RESPONSE"}, */
static void dissect_s5066dts_eow_alm_response(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_eow_alm_response_response, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_alm_response_reason, tvb, offset, 1, ENC_BIG_ENDIAN);
}

/* { 7, "HDR_DRC_REQUEST"}, */
static void dissect_s5066dts_eow_hdr_drc_request(tvbuff_t *tvb, packet_info * pinfo, unsigned offset,
        proto_tree *tree, unsigned pdu_type)
{

    if (pdu_type != S5066_DPDU_MANAGEMENT)
    {
        expert_add_info(pinfo, tree, &ei_s5066dts_eow_hdr_drc_request_invalid);
        return;
    }

    proto_tree_add_item(tree, hf_s5066dts_eow_hdr_drc_request_waveform, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_eow_hdr_drc_request_num_channels, tvb, offset, 1, ENC_BIG_ENDIAN);

}

/* {15, "HFTRP FRAME CONTROL"}, */
static void dissect_s5066dts_eow_hftrp(tvbuff_t *tvb,  packet_info * pinfo, unsigned offset,
        proto_tree *tree, unsigned pdu_type)
{
    if (pdu_type != S5066_DPDU_MANAGEMENT)
    {
        expert_add_info(pinfo, tree, &ei_s5066dts_eow_hftrp_invalid);
        return;
    }

    proto_tree_add_item(tree, hf_s5066dts_eow_hftrp_hftrp_token, tvb, offset, 1, ENC_BIG_ENDIAN);
}

/*
 * Dissect EOW type according to C.5 EOW and Management Message Types
 */
static unsigned dissect_s5066dts_eow(tvbuff_t *tvb,  packet_info * pinfo, unsigned offset, proto_tree *tree,
        unsigned pdu_type)
{
    proto_tree *eow_tree;
    unsigned eow_type;

    eow_type = tvb_get_uint8(tvb, offset) & 0x0F;
    eow_tree = proto_tree_add_subtree(tree, tvb, offset, 2, ett_s5066dts_eow, NULL, "EOW Field");
    proto_tree_add_item(eow_tree, hf_s5066dts_eow_type, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;

    switch (eow_type)
    {
        case  S5066_EOW_RESERVED:
            proto_tree_add_item(eow_tree, hf_s5066dts_eow_data, tvb, offset, 1, ENC_BIG_ENDIAN); break;
        case  S5066_EOW_DRC_REQUEST:
            dissect_s5066dts_eow_drc_request(tvb, offset, eow_tree); break;
        case  S5066_EOW_DRC_RESPONSE:
            dissect_s5066dts_eow_drc_response(tvb, offset, eow_tree); break;
        case  S5066_EOW_UNRECOGNIZED_TYPE:
            dissect_s5066dts_eow_unrec_type(tvb, offset, eow_tree); break;
        case  S5066_EOW_CAPABILITY:
            dissect_s5066dts_eow_capability(tvb, offset, eow_tree); break;
        case  S5066_EOW_ALM_REQUEST:
            dissect_s5066dts_eow_alm_request(tvb, offset, eow_tree); break;
        case  S5066_EOW_ALM_RESPONSE:
            dissect_s5066dts_eow_alm_response(tvb, offset, eow_tree); break;
        case  S5066_EOW_HDR_DRC_REQUEST:
            dissect_s5066dts_eow_hdr_drc_request(tvb, pinfo, offset, eow_tree, pdu_type); break;
        case  S5066_EOW_HFTRP_TOKEN:
            dissect_s5066dts_eow_hftrp(tvb, pinfo, offset, eow_tree, pdu_type); break;
    }
    return ++offset;
}

static void
s5066dts_address_format( char *result, uint32_t address_value )
{
   snprintf( result, ITEM_LABEL_LENGTH, "%d.%d.%d.%d",
            address_value >> 24,
            (address_value >> 16) & 0xFF,
            (address_value >> 8) & 0xFF,
            address_value & 0xFF);
}

static unsigned dissect_s5066dts_address(tvbuff_t *tvb, unsigned offset, proto_tree *tree, packet_info *pinfo,
        unsigned addr_size)
{
    uint32_t source_address = 0, destination_address = 0;
    proto_tree *address_tree;
    unsigned int i;

    for ( i = 0; i < addr_size; i++)
    {
        destination_address = (destination_address << 4) | ((!(i % 2)
                ? (tvb_get_uint8(tvb, offset + i / 2) >> 4)
                : (tvb_get_uint8(tvb, offset + i / 2))) & 0x0F);
        source_address = (source_address << 4) | ((!((i + addr_size) % 2)
                ? (tvb_get_uint8(tvb, offset + (i + addr_size) / 2) >> 4)
                : (tvb_get_uint8(tvb, offset + (i + addr_size) / 2))) & 0x0F);
    }

    address_tree = proto_tree_add_subtree(tree, tvb, offset, addr_size, ett_s5066dts_address, NULL, "Destination & Source Addresses");

    proto_tree_add_uint(address_tree, hf_s5066dts_dest_addr, tvb, offset, addr_size - addr_size / 2, destination_address);
    proto_tree_add_uint(address_tree, hf_s5066dts_src_addr, tvb, offset + addr_size / 2, addr_size - addr_size / 2, source_address);

    col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "%d.%d.%d.%d",
            source_address  >> 24,
            (source_address >> 16) & 0xFF,
            (source_address >> 8) & 0xFF,
            source_address & 0xFF);

    col_add_fstr(pinfo->cinfo, COL_DEF_DST, "%d.%d.%d.%d",
            destination_address  >> 24,
            (destination_address >> 16) & 0xFF,
            (destination_address >> 8) & 0xFF,
            destination_address & 0xFF);

    offset += addr_size;
    return offset;
}

static unsigned dissect_s5066dts_header_crc(tvbuff_t *tvb, unsigned offset, proto_tree *tree,
        unsigned address_size, unsigned header_size)
{
    uint16_t header_crc;
    proto_item *ti;

    header_crc = crc16_0x9949_tvb_offset_seed(tvb, S5066_DPDU_SYNC_SEQUENCE_SIZE,
                header_size + address_size - S5066_DPDU_SYNC_SEQUENCE_SIZE, 0);

    ti = proto_tree_add_item(tree, hf_s5066dts_header_crc, tvb, offset, 2, ENC_BIG_ENDIAN);
    if (header_crc == tvb_get_letohs(tvb, offset))
        proto_item_append_text(ti, " (Correct)");
    else
        proto_item_append_text(ti, " (Incorrect, should be %x)", header_crc);

    offset += 2;
    return offset;
}

static unsigned dissect_s5066dts_cpdu_crc(tvbuff_t *tvb, unsigned offset, proto_tree *tree,
        unsigned address_size, unsigned header_size, unsigned segmented_cpdu_size)
{
    uint32_t cpdu_crc;
    proto_item *ti;

    cpdu_crc = crc32_0x0AA725CF_tvb_offset_seed(tvb, header_size + address_size + S5066_DPDU_SYNC_SEQUENCE_SIZE,
              segmented_cpdu_size, 0);

    ti = proto_tree_add_item(tree, hf_s5066dts_cpdu_crc, tvb, offset, 4, ENC_BIG_ENDIAN);
    if (cpdu_crc == tvb_get_letohl(tvb, offset))
        proto_item_append_text(ti, " (Correct)");
    else
        proto_item_append_text(ti, " (Incorrect, should be %x)", cpdu_crc);

    offset +=4;
    return offset;
}

/* { 0, "DATA_ONLY"}, */
static unsigned dissect_s5066dts_data_only(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_data_only_cpdu_start, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_only_cpdu_end, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_only_deliver_in_order, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_only_drop_cpdu, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_only_tx_win_uwe, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_only_tx_win_lwe, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_only_segmented_cpdu_size, tvb, offset, 2, ENC_BIG_ENDIAN); offset +=2;
    proto_tree_add_item(tree, hf_s5066dts_data_only_transmit_sequence_number, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;

    return offset;
}

/* { 1, "ACK_ONLY"}, */
static unsigned dissect_s5066dts_ack_only(tvbuff_t *tvb, unsigned offset, proto_tree *tree,
        unsigned header_size)
{
    unsigned ack_size;
    ack_size = header_size - 7;

    proto_tree_add_item(tree, hf_s5066dts_ack_only_rx_lwe, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
    if (ack_size > 0){
        proto_tree_add_item(tree, hf_s5066dts_ack_only_acks, tvb, offset, ack_size, ENC_NA); offset += ack_size;
    }

    return offset;
}

/* { 2, "DATA_ACK"}, */
static unsigned dissect_s5066dts_data_ack(tvbuff_t *tvb, unsigned offset, proto_tree *tree,
        unsigned header_size)
{
    unsigned ack_size;
    ack_size = header_size - 10;

    proto_tree_add_item(tree, hf_s5066dts_data_ack_cpdu_start, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_ack_cpdu_end, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_ack_deliver_in_order, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_ack_drop_cpdu, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_ack_tx_win_uwe, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_ack_tx_win_lwe, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_data_ack_segmented_cpdu_size, tvb, offset, 2, ENC_BIG_ENDIAN); offset +=2;
    proto_tree_add_item(tree, hf_s5066dts_data_ack_transmit_sequence_number, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
    proto_tree_add_item(tree, hf_s5066dts_data_ack_rx_lwe, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
    if (ack_size > 0){
        proto_tree_add_item(tree, hf_s5066dts_data_ack_acks, tvb, offset, ack_size, ENC_NA); offset += ack_size;
    }

    return offset;
}

/* { 3, "RESET_WIN_RESYNC"}, */
static unsigned dissect_s5066dts_reset_win_resync(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_reset_win_resync_unused, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_reset_win_resync_full_reset_command, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_reset_win_resync_reset_tx_win_rqst, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_reset_win_resync_reset_rx_win_cmnd, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_reset_win_resync_reset_ack, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
    proto_tree_add_item(tree, hf_s5066dts_reset_win_resync_new_rx_lwe, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
    proto_tree_add_item(tree, hf_s5066dts_reset_win_resync_reset_frame_id_number, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;

    return offset;
}

/* { 4, "EXP_DATA_ONLY"}, */
static unsigned dissect_s5066dts_exp_data_only(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_exp_data_only_cpdu_start, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_exp_data_only_cpdu_end, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_exp_data_only_cpdu_id, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_exp_data_only_segmented_cpdu_size, tvb, offset, 2, ENC_BIG_ENDIAN); offset +=2;
    proto_tree_add_item(tree, hf_s5066dts_exp_data_only_transmit_sequence_number, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;

    return offset;
}

/* { 5, "EXP_ACK_ONLY"}, */
static unsigned dissect_s5066dts_exp_ack_only(tvbuff_t *tvb, unsigned offset, proto_tree *tree,
        unsigned header_size)
{
    unsigned ack_size;
    ack_size = header_size - 7;

    proto_tree_add_item(tree, hf_s5066dts_exp_ack_only_rx_lwe, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
    if (ack_size > 0)
        proto_tree_add_item(tree, hf_s5066dts_exp_ack_only_acks, tvb, offset, ack_size, ENC_NA);
    offset += ack_size;

    return offset;
}

/* { 6, "MANAGEMENT"}, */
static unsigned dissect_s5066dts_management(tvbuff_t *tvb, unsigned offset, proto_tree *tree, unsigned header_size)
{
    uint8_t eow_content;
    proto_tree *hftrp_token_tree = NULL;
    unsigned eow_type;
    unsigned extended_message_size;

    eow_type = tvb_get_uint8(tvb, offset) & 0x0F;
    eow_content = tvb_get_uint8(tvb, S5066_DPDU_EOW_CONTENT_INDEX);
    extended_message_size = header_size - 8;

    proto_tree_add_item(tree, hf_s5066dts_management_unused, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_management_extended_message_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_management_message, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_management_ack, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
    proto_tree_add_item(tree, hf_s5066dts_management_management_frame_id, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset++;

    if (eow_type == S5066_EOW_HDR_DRC_REQUEST)
    {
        proto_tree_add_item(tree, hf_s5066dts_eow_hdr_drc_request_data_rate, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;

        proto_tree_add_item(tree, hf_s5066dts_eow_hdr_drc_request_interleaver_length, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;
    }
    else if (extended_message_size > 0)
    {
        /* If eow type is 15 then parse HFTRP token details */
        if (eow_type == S5066_EOW_HFTRP_TOKEN)
        {
            /* Add a new subtree for HFTRP token details */
            hftrp_token_tree = proto_tree_add_subtree_format(tree, tvb, offset, extended_message_size,
                    ett_s5066dts_hftrp_token, NULL, "HFTRP Token (%s)",
                    val_to_str_const(eow_content, s5066dts_eow_hftrp_frame_control, "UNKNOWN_HFTRP_TOKEN"));
            proto_tree_add_item(hftrp_token_tree,
                    hf_s5066dts_management_extended_message_hftrp_payload_size, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2;
            proto_tree_add_item(hftrp_token_tree,
                    hf_s5066dts_management_extended_message_hftrp_ra, tvb, offset, 4, ENC_BIG_ENDIAN); offset += 4;
            proto_tree_add_item(hftrp_token_tree,
                    hf_s5066dts_management_extended_message_hftrp_seq_id, tvb, offset, 4, ENC_BIG_ENDIAN); offset += 4;
            proto_tree_add_item(hftrp_token_tree,
                    hf_s5066dts_management_extended_message_hftrp_gen_seq_id, tvb, offset, 4, ENC_BIG_ENDIAN); offset += 4;
            proto_tree_add_item(hftrp_token_tree,
                    hf_s5066dts_management_extended_message_hftrp_new_successor_id, tvb, offset, 4, ENC_BIG_ENDIAN); offset += 4;
            proto_tree_add_item(hftrp_token_tree,
                    hf_s5066dts_management_extended_message_hftrp_number_of_nodes, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2;
        }
        /* otherwise just display it as a byte stream */
        else
        {
            proto_tree_add_item(tree, hf_s5066dts_management_extended_message, tvb, offset, extended_message_size, ENC_NA);
            offset += extended_message_size;
        }
    }

    return offset;
}

/* { 7, "NON_ARQ_DATA"}, */
static unsigned dissect_s5066dts_non_arq_data(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_non_arq_data_cpdu_id_1, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_non_arq_data_deliver_in_order, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_non_arq_data_group_address, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_non_arq_data_segmented_cpdu_size, tvb, offset, 2, ENC_BIG_ENDIAN); offset +=2;
    proto_tree_add_item(tree, hf_s5066dts_non_arq_data_cpdu_id_2, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
    proto_tree_add_item(tree, hf_s5066dts_non_arq_data_cpdu_size, tvb, offset, 2, ENC_BIG_ENDIAN); offset +=2;
    proto_tree_add_item(tree, hf_s5066dts_non_arq_data_cpdu_segment_offset, tvb, offset, 2, ENC_BIG_ENDIAN); offset +=2;
    proto_tree_add_item(tree, hf_s5066dts_non_arq_data_cpdu_reception_window, tvb, offset, 2, ENC_BIG_ENDIAN); offset +=2;

    return offset;
}

/* { 8, "EXP_NON_ARQ_DATA"}, */
static unsigned dissect_s5066dts_exp_non_arq_data(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_exp_non_arq_data_cpdu_id_1, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_exp_non_arq_data_deliver_in_order, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_exp_non_arq_data_group_address, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_exp_non_arq_data_segmented_cpdu_size, tvb, offset, 2, ENC_BIG_ENDIAN); offset +=2;
    proto_tree_add_item(tree, hf_s5066dts_exp_non_arq_data_cpdu_id_2, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
    proto_tree_add_item(tree, hf_s5066dts_exp_non_arq_data_cpdu_size, tvb, offset, 2, ENC_BIG_ENDIAN); offset +=2;
    proto_tree_add_item(tree, hf_s5066dts_exp_non_arq_data_cpdu_segment_offset, tvb, offset, 2, ENC_BIG_ENDIAN); offset +=2;
    proto_tree_add_item(tree, hf_s5066dts_exp_non_arq_data_cpdu_reception_window, tvb, offset, 2, ENC_BIG_ENDIAN); offset +=2;

    return offset;
}

/* {15, "WARNING"}, */
static unsigned dissect_s5066dts_warning(tvbuff_t *tvb, unsigned offset, proto_tree *tree)
{
    proto_tree_add_item(tree, hf_s5066dts_warning_frame_type, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(tree, hf_s5066dts_warning_reason, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;

    return offset;
}

static unsigned calculate_s5066dts_dpdu_len(packet_info *pinfo _U_, tvbuff_t *tvb,
                                         int offset _U_, void *data _U_)
{
    unsigned pdu_type;
    unsigned address_size;
    unsigned header_size;
    unsigned pdu_size;
    unsigned segmented_cpdu_size;

    /* XXX: why is the offset not used to get this value? */
    if (tvb_get_uint8(tvb, 0) != 0x90)
        return 1;
    else if (tvb_get_uint8(tvb, 1) != 0xEB)
        return 2;

    pdu_type = (tvb_get_uint8(tvb, 2) & 0xF0) >> 4;
    address_size = (tvb_get_uint8(tvb, S5066_DPDU_SIZE_OF_ADDRESS_INDEX) & 0xE0) >> 5;
    header_size = tvb_get_uint8(tvb, S5066_DPDU_SIZE_OF_HEADER_INDEX) & 0x1F;
    pdu_size = header_size + address_size + S5066_DPDU_SYNC_SEQUENCE_SIZE;

    if (pdu_type == S5066_DPDU_DATA_ONLY || pdu_type == S5066_DPDU_DATA_ACK ||
            pdu_type == S5066_DPDU_EXP_DATA_ONLY || pdu_type == S5066_DPDU_NON_ARQ_DATA ||
            pdu_type == S5066_DPDU_EXP_NON_ARQ_DATA)
    {
        segmented_cpdu_size = tvb_get_ntohs(tvb, 6 + address_size) & 0x03FF;
        pdu_size += segmented_cpdu_size + 4;
    }
    return pdu_size;
}

static int dissect_s5066dts(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    proto_tree *s5066dts_tree = NULL, *pdu_tree = NULL;
    proto_item *ti = NULL;
    unsigned offset = 0;
    unsigned pdu_type;
    unsigned address_size;
    unsigned header_size;
    unsigned segmented_cpdu_size;
    /* Add EOW (Engineering OrderWire */
    uint8_t eow_type;
    uint8_t eow_content;

    if (tvb_get_uint8(tvb, 0) != 0x90 || tvb_get_uint8(tvb, 1) != 0xEB) {
        /* Cannot find sync pattern at dissect_s5066dts()! */
        return 0;
    }

    col_set_str(pinfo->cinfo, COL_PROTOCOL, DISSECTOR_NAME);
    pdu_type = (tvb_get_uint8(tvb, 2) & 0xF0) >> 4;

    /* Add DPDU type and name */
    col_add_fstr(pinfo->cinfo, COL_INFO, "DpduType=%d (%s)", pdu_type, val_to_str(pdu_type, s5066dts_dpdu_type,
            "Unknown (0x%02x)"));

    address_size = (tvb_get_uint8(tvb, S5066_DPDU_SIZE_OF_ADDRESS_INDEX) & 0xE0) >> 5;
    eow_type = tvb_get_uint8(tvb, S5066_DPDU_EOW_TYPE_INDEX) & 0x0F;
    eow_content = tvb_get_uint8(tvb, S5066_DPDU_EOW_CONTENT_INDEX);

    switch (eow_type)
    {
        case S5066_EOW_RESERVED:
            col_append_str(pinfo->cinfo, COL_INFO, " EowType=RESERVED");
            break;
        case S5066_EOW_DRC_REQUEST: /* Data Rate Change Request */
        case S5066_EOW_DRC_RESPONSE: /* Data Rate Change Response */
        case S5066_EOW_UNRECOGNIZED_TYPE: /* Unrecognized Type Error */
        case S5066_EOW_CAPABILITY: /* Capability Advertisement */
        case S5066_EOW_ALM_REQUEST: /* Frequency Change / ALM Request */
        case S5066_EOW_ALM_RESPONSE: /* Frequency Change / ALM Response */
        case S5066_EOW_HDR_DRC_REQUEST: /* High Data Rate (HDR) Change Request */
            col_append_fstr(pinfo->cinfo, COL_INFO, " EowType=%d (%s)", eow_type,
                    val_to_str_const(eow_type, s5066dts_eow_type, "UNKNOWN_EOW_TYPE"));
            break;
        case 8: /* Unspecified/User Defined */
        case 9: /* Unspecified/User Defined */
        case 10: /* Unspecified/User Defined */
        case 11: /* Unspecified/User Defined */
        case 12: /* Unspecified/User Defined */
        case 13: /* Unspecified/User Defined */
        case 14: /* Unspecified/User Defined */
            col_append_str(pinfo->cinfo, COL_INFO, " EowType=UNSPECIFIED");
            break;
        case S5066_EOW_HFTRP_TOKEN:
            col_append_fstr(pinfo->cinfo, COL_INFO, " EowType=%d (%s:%s)", eow_type,
                    val_to_str_const(eow_type, s5066dts_eow_type, "UNKNOWN_EOW_TYPE"),
                    val_to_str_const(eow_content, s5066dts_eow_hftrp_frame_control_abbr, "UNKNOWN_HFTRP_TOKEN"));
            break;
    }

    /* Append EOT (End of Transmission) */
    col_append_fstr(pinfo->cinfo, COL_INFO, " EOT=%d", tvb_get_uint8(tvb, S5066_DPDU_EOT_INDEX));

    /* Append DPDU-specific information */
    switch (pdu_type)
    {
        case S5066_DPDU_DATA_ONLY:
        case S5066_DPDU_EXP_DATA_ONLY:
            col_append_fstr(pinfo->cinfo, COL_INFO, " Seq=%d", tvb_get_uint8(tvb, 8 + address_size));
            break;
        case S5066_DPDU_ACK_ONLY:
        case S5066_DPDU_EXP_ACK_ONLY:
            col_append_fstr(pinfo->cinfo, COL_INFO, " RxLWE=%d", tvb_get_uint8(tvb, 6 + address_size));
            break;
        case S5066_DPDU_DATA_ACK:
            col_append_fstr(pinfo->cinfo, COL_INFO, " Seq=%d RxLWE=%d",
                    tvb_get_uint8(tvb, 8 + address_size),
                    tvb_get_uint8(tvb, 9 + address_size));
            break;
        case S5066_DPDU_MANAGEMENT:
            col_append_fstr(pinfo->cinfo, COL_INFO, " FrameID=%d", tvb_get_uint8(tvb, 7 + address_size));
            break;
    }

    if (tree)
    {
        ti = proto_tree_add_protocol_format(tree, proto_s5066dts, tvb, 0, -1, "STANAG 5066 (DTS Layer)");
        s5066dts_tree = proto_item_add_subtree(ti, ett_s5066dts);
        proto_tree_add_item(s5066dts_tree, hf_s5066dts_sync_word, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2;
        proto_tree_add_item(s5066dts_tree, hf_s5066dts_dpdu_type, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset = dissect_s5066dts_eow(tvb, pinfo, offset, s5066dts_tree, pdu_type);

        /*
         * Append DPDU type to the root
         */
        proto_item_append_text(ti, ", DPDU Type %s ", val_to_str_const(pdu_type, s5066dts_dpdu_type, "UNKNOWN_DPDU_TYPE"));
        proto_tree_add_item(s5066dts_tree, hf_s5066dts_eot, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
        proto_tree_add_item(s5066dts_tree, hf_s5066dts_address_size, tvb, offset, 1, ENC_BIG_ENDIAN);
        proto_tree_add_item(s5066dts_tree, hf_s5066dts_header_size, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
        offset = dissect_s5066dts_address(tvb, offset, s5066dts_tree, pinfo, address_size);
        header_size = tvb_get_uint8(tvb, S5066_DPDU_SIZE_OF_HEADER_INDEX) & 0x1F;
        pdu_tree = proto_tree_add_subtree(s5066dts_tree, tvb, offset, header_size - 6, ett_s5066dts_pdu, NULL, "D_PDU Type Specific Header");

        switch (pdu_type)
        {
            case  S5066_DPDU_DATA_ONLY: offset = dissect_s5066dts_data_only(tvb, offset, pdu_tree); break;
            case  S5066_DPDU_ACK_ONLY: offset = dissect_s5066dts_ack_only(tvb, offset, pdu_tree, header_size); break;
            case  S5066_DPDU_DATA_ACK: offset = dissect_s5066dts_data_ack(tvb, offset, pdu_tree, header_size); break;
            case  S5066_DPDU_RESET_WIN_RESYNC: offset = dissect_s5066dts_reset_win_resync(tvb, offset, pdu_tree); break;
            case  S5066_DPDU_EXP_DATA_ONLY: offset = dissect_s5066dts_exp_data_only(tvb, offset, pdu_tree); break;
            case  S5066_DPDU_EXP_ACK_ONLY: offset = dissect_s5066dts_exp_ack_only(tvb, offset, pdu_tree, header_size); break;
            case  S5066_DPDU_MANAGEMENT: offset = dissect_s5066dts_management(tvb, offset, pdu_tree, header_size); break;
            case  S5066_DPDU_NON_ARQ_DATA: offset = dissect_s5066dts_non_arq_data(tvb, offset, pdu_tree); break;
            case  S5066_DPDU_EXP_NON_ARQ_DATA: offset = dissect_s5066dts_exp_non_arq_data(tvb, offset, pdu_tree); break;
            case  S5066_DPDU_WARNING: offset = dissect_s5066dts_warning(tvb, offset, pdu_tree); break;
        }
        offset = dissect_s5066dts_header_crc(tvb, offset, s5066dts_tree, address_size, header_size);
        if (pdu_type == S5066_DPDU_DATA_ONLY || pdu_type == S5066_DPDU_DATA_ACK
                || pdu_type == S5066_DPDU_EXP_DATA_ONLY || pdu_type == S5066_DPDU_NON_ARQ_DATA
                || pdu_type == S5066_DPDU_EXP_NON_ARQ_DATA)
        {
            segmented_cpdu_size = tvb_get_ntohs(tvb, 6 + address_size) & 0x03FF;
            proto_tree_add_item(s5066dts_tree, hf_s5066dts_segmented_cpdu, tvb, offset, segmented_cpdu_size, ENC_NA);
            offset += segmented_cpdu_size;
            /*offset = */dissect_s5066dts_cpdu_crc(tvb, offset, s5066dts_tree, address_size, header_size, segmented_cpdu_size);
        }
    }

    return tvb_captured_length(tvb);
}

static int dissect_s5066dts_raw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
    unsigned b_length =  tvb_captured_length(tvb);

    /* Make sure there are enough bytes for a DPDU */
    if ( b_length < S5066_DPDU_FRAME_HEADER_LEN){
        /* "There are not enough bytes for a DPDU! */
        return 0;
    }

    /* Check if the first two bytes are 0x90 and 0xEB
     * If not then this is neither a DPDU nor an un-reassembled one
     */
    if ((tvb_get_uint8(tvb, 0) != 0x90) || (tvb_get_uint8(tvb, 1) != 0xEB)) {
        /* Cannot find sync pattern at dissect_s5066dts_raw()! */
        return 0;
    }
    calculate_s5066dts_dpdu_len(pinfo, tvb, 0, NULL);
    dissect_s5066dts(tvb, pinfo, tree, NULL);

    return b_length;
}

static int dissect_s5066dts_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
    unsigned b_length = tvb_captured_length(tvb);

    /* Make sure there are enough bytes for a DPDU */
    if ( b_length < S5066_DPDU_FRAME_HEADER_LEN){
        /* "There are not enough bytes for a DPDU! */
        return 0;
    }

    /* Check if the first two bytes are 0x90 and 0xEB
     * If not then this is neitger a DPDU nor an un-reassembled one
     */
    if ((tvb_get_uint8(tvb, 0) != 0x90) || (tvb_get_uint8(tvb, 1) != 0xEB)) {
        /* Cannot find sync pattern at dissect_s5066dts_tcp()! */
        return 0;
    }

    /* Drop packets with port matches other than the destination port. */
    if (!value_is_in_range(config_s5066dts_ports, pinfo->destport)) {
        /* Configured to dissect TCP destination port matches only, dropping.. */
        return 0;
    }

    tcp_dissect_pdus(tvb, pinfo, tree, config_proto_desegment, S5066_DPDU_FRAME_HEADER_LEN, calculate_s5066dts_dpdu_len,
                dissect_s5066dts, data);

    return b_length;
}

static void
apply_s5066dts_prefs(void)
{
    /* STANAG 5066 uses the port preference for some heuristics */
    config_s5066dts_ports = prefs_get_range_value("s5066dts", "tcp.port");
}

void proto_register_s5066dts (void)
{
    module_t *s5066dts_module;
    static hf_register_info hf[] = {
            { &hf_s5066dts_sync_word,
                { "Sync preamble", "s5066dts.sync", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_dpdu_type,
                { "D_PDU type", "s5066dts.type", FT_UINT8, BASE_DEC, VALS(s5066dts_dpdu_type), 0xF0, NULL, HFILL }
            },
            { &hf_s5066dts_eow_type,
                { "EOW type", "s5066dts.eow.type", FT_UINT8, BASE_DEC, VALS(s5066dts_eow_type), 0x0F, NULL, HFILL }
            },
            { &hf_s5066dts_eow_data,
                { "EOW data", "s5066dts.eow.data", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_eot,
                { "EOT", "s5066dts.eot", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_address_size,
                { "Address size (1/2 bytes)", "s5066dts.address.size", FT_UINT8, BASE_DEC, NULL, 0xE0, NULL, HFILL }
            },
            { &hf_s5066dts_header_size,
                { "Header size", "s5066dts.header_size", FT_UINT8, BASE_DEC, NULL, 0x1F, NULL, HFILL }
            },
            { &hf_s5066dts_segmented_cpdu,
                { "C_PDU Segment", "s5066dts.segmented_cpdu", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_dest_addr,
                { "Destination Address", "s5066dts.dest_addr", FT_UINT32, BASE_CUSTOM, CF_FUNC(s5066dts_address_format), 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_src_addr,
                { "Source Address", "s5066dts.src_addr", FT_UINT32, BASE_CUSTOM, CF_FUNC(s5066dts_address_format), 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_header_crc,
                { "CRC on header", "s5066dts.header_crc", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_cpdu_crc,
                { "CRC on C_PDU segment", "s5066dts.cpdu_crc", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
            },
            /* { 1, "DRC_REQUEST"}, */
            { &hf_s5066dts_eow_drc_request_data_rate,
                { "Data Rate", "s5066dts.eow.drc_request.data_rate", FT_UINT8, BASE_DEC, VALS(s5066dts_eow_data_rate),
                        0xF0, NULL, HFILL }
            },
            { &hf_s5066dts_eow_drc_request_interleaving,
                { "Interleaver parameter", "s5066dts.eow.drc_request.interleaving", FT_UINT8, BASE_DEC,
                        VALS(s5066dts_eow_interleaving), 0x0C, NULL, HFILL }
            },
            { &hf_s5066dts_eow_drc_request_others,
                { "Other parameters", "s5066dts.eow.drc_request.others", FT_UINT8, BASE_DEC,
                        VALS(s5066dts_eow_others), 0x03, NULL, HFILL }
            },
            /* { 2, "DRC_RESPONSE"}, */
            { &hf_s5066dts_eow_drc_response_response,
                { "Response for DRC", "s5066dts.eow.drc_response.response", FT_UINT8, BASE_DEC,
                        VALS(s5066dts_eow_response), 0xE0, NULL, HFILL }
            },
            { &hf_s5066dts_eow_drc_response_reason,
                { "Reason", "s5066dts.eow.drc_response.reason", FT_UINT8, BASE_DEC,
                        VALS(s5066dts_eow_reason), 0x1F, NULL, HFILL }
            },
            /* { 3, "UNRECOGNIZED_TYPE"}, */
            { &hf_s5066dts_eow_unrec_type_response,
                { "This value should be set to 0", "s5066dts.eow.unrec_type.response", FT_UINT8, BASE_DEC,
                        NULL, 0xE0, NULL, HFILL }
            },
            { &hf_s5066dts_eow_unrec_type_reason,
                { "Reason", "s5066dts.eow.unrec_type.reason", FT_UINT8, BASE_DEC, NULL, 0x1F, NULL, HFILL }
            },
            /* { 4, "CAPABILITY"}, */
            { &hf_s5066dts_eow_capability_adaptive,
                { "Adaptive modem parameters capable", "s5066dts.eow.capability.adaptive", FT_BOOLEAN, 8, NULL, 0x80, NULL, HFILL }
            },
            { &hf_s5066dts_eow_capability_stanag_4529,
                { "STANAG 4529 available", "s5066dts.eow.capability.stanag_4529", FT_BOOLEAN, 8, NULL, 0x40, NULL, HFILL }
            },
            { &hf_s5066dts_eow_capability_mil_std_188_110a,
                { "MIL-STD-188-110A available", "s5066dts.eow.capability.mil_std_188_110a", FT_BOOLEAN, 8, NULL, 0x20, NULL, HFILL }
            },
            { &hf_s5066dts_eow_capability_extended,
                { "Extended data rate available", "s5066dts.eow.capability.extended", FT_BOOLEAN, 8, NULL, 0x10, NULL, HFILL }
            },
            { &hf_s5066dts_eow_capability_full_duplex,
                { "Full duplex supported", "s5066dts.eow.capability.full_duplex", FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL }
            },
            { &hf_s5066dts_eow_capability_split_frequency,
                { "Split frequency supported", "s5066dts.eow.capability.split_frequency", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL }
            },
            { &hf_s5066dts_eow_capability_non_arcs_ale,
                { "Non-ARCS ALE capable", "s5066dts.eow.capability.non_arcs_ale", FT_BOOLEAN, 8, NULL, 0x02, NULL, HFILL }
            },
            { &hf_s5066dts_eow_capability_arcs,
                { "ARCS capable", "s5066dts.eow.capability.arcs", FT_BOOLEAN, 8, NULL, 0x01, NULL, HFILL }
            },
            /* { 5, "ALM_REQUEST"}, */
            { &hf_s5066dts_eow_alm_request_data_rate,
                { "Data Rate", "s5066dts.eow.alm_request.data_rate", FT_UINT8, BASE_DEC,
                        VALS(s5066dts_eow_data_rate), 0xF0, NULL, HFILL }
            },
            { &hf_s5066dts_eow_alm_request_interleaving,
                { "Interleaver parameter", "s5066dts.eow.alm_request.interleaving", FT_UINT8, BASE_DEC,
                        VALS(s5066dts_eow_interleaving), 0x0C, NULL, HFILL }
            },
            { &hf_s5066dts_eow_alm_request_others,
                { "Other parameters", "s5066dts.eow.alm_request.others", FT_UINT8, BASE_DEC,
                        VALS(s5066dts_eow_others), 0x03, NULL, HFILL }
            },
            /* { 6, "ALM_RESPONSE"}, */
            { &hf_s5066dts_eow_alm_response_response,
                { "Response for DRC", "s5066dts.eow.alm_response.response", FT_UINT8, BASE_DEC,
                        VALS(s5066dts_eow_response), 0xE0, NULL, HFILL }
            },
            { &hf_s5066dts_eow_alm_response_reason,
                { "Reason", "s5066dts.eow.alm_response.reason", FT_UINT8, BASE_DEC, VALS(s5066dts_alm_reason), 0x1F, NULL, HFILL }
            },
            /* { 7, "HDR_DRC_REQUEST"}, */
            { &hf_s5066dts_eow_hdr_drc_request_waveform,
                { "Modem waveform", "s5066dts.eow.hdr_drc_request.waveform", FT_UINT8, BASE_DEC,
                        VALS(s5066dts_eow_waveform), 0xF8, NULL, HFILL }
            },
            { &hf_s5066dts_eow_hdr_drc_request_num_channels,
                { "Number of channels", "s5066dts.eow.hdr_drc_request.num_channels", FT_UINT8, BASE_DEC, NULL, 0x07, NULL, HFILL }
            },
            { &hf_s5066dts_eow_hdr_drc_request_data_rate,
                { "Requested data rate for each channel", "s5066dts.eow.hdr_drc_request.data_rate",
                        FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_eow_hdr_drc_request_interleaver_length,
                { "Interleaver length for each channel", "s5066dts.eow.hdr_drc_request.interleaver_length",
                        FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            /* { 15, "HFTRP FRAME CONTROL"}, */
            { &hf_s5066dts_eow_hftrp_hftrp_token,
                { "HFTRP Token Type", "s5066dts.eow.hftrp.token_type", FT_UINT8, BASE_DEC, NULL, 0x00, NULL, HFILL }
            },
            /* { 0, "DATA_ONLY"}, */
            { &hf_s5066dts_data_only_cpdu_start,
                { "C_PDU Start", "s5066dts.data_only.cpdu_start", FT_BOOLEAN, 8, NULL, 0x80, NULL, HFILL }
            },
            { &hf_s5066dts_data_only_cpdu_end,
                { "C_PDU End", "s5066dts.data_only.cpdu_end", FT_BOOLEAN, 8, NULL, 0x40, NULL, HFILL }
            },
            { &hf_s5066dts_data_only_deliver_in_order,
                { "C_PDU Deliver-in-Order", "s5066dts.data_only.deliver_in_order", FT_BOOLEAN, 8, NULL, 0x20, NULL, HFILL }
            },
            { &hf_s5066dts_data_only_drop_cpdu,
                { "Drop C_PDU", "s5066dts.data_only.drop_cpdu", FT_BOOLEAN, 8, NULL, 0x10, NULL, HFILL }
            },
            { &hf_s5066dts_data_only_tx_win_uwe,
                { "TX WIN UWE", "s5066dts.data_only.tx_win_uwe", FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL }
            },
            { &hf_s5066dts_data_only_tx_win_lwe,
                { "TX WIN LWE", "s5066dts.data_only.tx_win_lwe", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL }
            },
            { &hf_s5066dts_data_only_segmented_cpdu_size,
                { "Size of segmented C_PDU", "s5066dts.data_only.segmented_cpdu_size", FT_UINT16, BASE_DEC,
                        NULL, 0x03FF, NULL, HFILL }
            },
            { &hf_s5066dts_data_only_transmit_sequence_number,
                { "TX Frame Sequence Number", "s5066dts.data_only.transmit_sequence_number", FT_UINT8, BASE_DEC,
                        NULL, 0x0, NULL, HFILL }
            },
            /* { 1, "ACK_ONLY"}, */
            { &hf_s5066dts_ack_only_rx_lwe,
                { "RX LWE", "s5066dts.ack_only.rx_lwe", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_ack_only_acks,
                { "Selective ACK", "s5066dts.ack_only.acks", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
            },
            /* { 2, "DATA_ACK"}, */
            { &hf_s5066dts_data_ack_cpdu_start,
                { "C_PDU Start", "s5066dts.data_ack.cpdu_start", FT_BOOLEAN, 8, NULL, 0x80, NULL, HFILL }
            },
            { &hf_s5066dts_data_ack_cpdu_end,
                { "C_PDU End", "s5066dts.data_ack.cpdu_end", FT_BOOLEAN, 8, NULL, 0x40, NULL, HFILL }
            },
            { &hf_s5066dts_data_ack_deliver_in_order,
                { "C_PDU Deliver-in-Order", "s5066dts.data_ack.deliver_in_order", FT_BOOLEAN, 8, NULL, 0x20, NULL, HFILL }
            },
            { &hf_s5066dts_data_ack_drop_cpdu,
                { "Drop C_PDU", "s5066dts.data_ack.drop_cpdu", FT_BOOLEAN, 8, NULL, 0x10, NULL, HFILL }
            },
            { &hf_s5066dts_data_ack_tx_win_uwe,
                { "TX WIN UWE", "s5066dts.data_ack.tx_win_uwe", FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL }
            },
            { &hf_s5066dts_data_ack_tx_win_lwe,
                { "TX WIN LWE", "s5066dts.data_ack.tx_win_lwe", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL }
            },
            { &hf_s5066dts_data_ack_segmented_cpdu_size,
                { "Size of segmented C_PDU", "s5066dts.data_ack.segmented_cpdu_size", FT_UINT16, BASE_DEC,
                        NULL, 0x03FF, NULL, HFILL }
            },
            { &hf_s5066dts_data_ack_transmit_sequence_number,
                { "TX frame sequence number", "s5066dts.data_ack.transmit_sequence_number", FT_UINT8, BASE_DEC,
                        NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_data_ack_rx_lwe,
                { "RX LWE", "s5066dts.data_ack.rx_lwe", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_data_ack_acks,
                { "Selective ACK", "s5066dts.data_ack.acks", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
            },
            /* { 3, "RESET_WIN_RESYNC"}, */
            { &hf_s5066dts_reset_win_resync_unused,
                { "Unused", "s5066dts.reset_win_resync.unused", FT_UINT8, BASE_HEX, NULL, 0xF0, NULL, HFILL }
            },
            { &hf_s5066dts_reset_win_resync_full_reset_command,
                { "Full reset command", "s5066dts.reset_win_resync.full_reset", FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL }
            },
            { &hf_s5066dts_reset_win_resync_reset_tx_win_rqst,
                { "Reset TX-WIN request", "s5066dts.reset_win_resync.reset_tx_win", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL }
            },
            { &hf_s5066dts_reset_win_resync_reset_rx_win_cmnd,
                { "Reset RX-WIN command", "s5066dts.reset_win_resync.reset_rx_win", FT_BOOLEAN, 8, NULL, 0x02, NULL, HFILL }
            },
            { &hf_s5066dts_reset_win_resync_reset_ack,
                { "Reset acknowledgment", "s5066dts.reset_win_resync.reset_ack", FT_BOOLEAN, 8, NULL, 0x01, NULL, HFILL }
            },
            { &hf_s5066dts_reset_win_resync_new_rx_lwe,
                { "New receiver ARQ RX-LWE", "s5066dts.reset_win_resync.new_rx_lwe", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_reset_win_resync_reset_frame_id_number,
                { "Reset frame ID number", "s5066dts.reset_win_resync.reset_frame_id", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            /* { 4, "EXP_DATA_ONLY"}, */
            { &hf_s5066dts_exp_data_only_cpdu_start,
                { "C_PDU Start", "s5066dts.exp_data_only.cpdu_start", FT_BOOLEAN, 8, NULL, 0x80, NULL, HFILL }
            },
            { &hf_s5066dts_exp_data_only_cpdu_end,
                { "C_PDU End", "s5066dts.exp_data_only.cpdu_end", FT_BOOLEAN, 8, NULL, 0x40, NULL, HFILL }
            },
            { &hf_s5066dts_exp_data_only_cpdu_id,
                { "Segmented C_PDU ID", "s5066dts.exp_data_only.cpdu_id", FT_UINT8, BASE_DEC, NULL, 0x3C, NULL, HFILL }
            },
            { &hf_s5066dts_exp_data_only_segmented_cpdu_size,
                { "Size of segmented C_PDU", "s5066dts.exp_data_only.segmented_cpdu_size", FT_UINT16, BASE_DEC, NULL, 0x03FF, NULL, HFILL }
            },
            { &hf_s5066dts_exp_data_only_transmit_sequence_number,
                { "TX frame sequence number", "s5066dts.exp_data_only.transmit_sequence_number", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            /* { 5, "EXP_ACK_ONLY"}, */
            { &hf_s5066dts_exp_ack_only_rx_lwe,
                { "RX LWE", "s5066dts.exp_ack_only.rx_lwe", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_exp_ack_only_acks,
                { "Selective ACK", "s5066dts.exp_ack_only.acks", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
            },
            /* { 6, "MANAGEMENT"}, */
            { &hf_s5066dts_management_unused,
                { "Unused", "s5066dts.management.unused", FT_UINT8, BASE_HEX, NULL, 0xF8, NULL, HFILL }
            },
            { &hf_s5066dts_management_extended_message_flag,
                { "Extended message flag", "s5066dts.management.extended_message_flag", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL }
            },
            { &hf_s5066dts_management_message,
                { "Valid message", "s5066dts.management.message", FT_BOOLEAN, 8, NULL, 0x02, NULL, HFILL }
            },
            { &hf_s5066dts_management_ack,
                { "Acknowledgment", "s5066dts.management.ack", FT_BOOLEAN, 8, NULL, 0x01, NULL, HFILL }
            },
            { &hf_s5066dts_management_management_frame_id,
                { "Management frame ID number", "s5066dts.management.management_frame_id", FT_UINT8, BASE_DEC,
                        NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_management_extended_message,
                { "Extended management message", "s5066dts.management.extended_message", FT_BYTES, BASE_NONE,
                        NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_management_extended_message_hftrp_payload_size,
                { "Payload Size", "s5066dts.management.extended_message.reserved", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_management_extended_message_hftrp_ra,
                { "Ring Address", "s5066dts.management.extended_message.ring_address", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_management_extended_message_hftrp_seq_id,
                { "Sequence ID", "s5066dts.management.extended_message.sequence_id", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_management_extended_message_hftrp_gen_seq_id,
                { "Generation Sequence ID", "s5066dts.management.extended_message.generation_sequence_id",
                        FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_management_extended_message_hftrp_new_successor_id,
                { "New Successor ID", "s5066dts.management.extended_message.new_successor_id", FT_UINT32, BASE_DEC,
                        NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_management_extended_message_hftrp_number_of_nodes,
                { "Number of Nodes", "s5066dts.management.extended_message.number_of_nodes", FT_UINT16, BASE_DEC,
                        NULL, 0x0, NULL, HFILL }
            },
            /* { 7, "NON_ARQ_DATA"}, */
            { &hf_s5066dts_non_arq_data_cpdu_id_1,
                { "C_PDU ID number (field 1)", "s5066dts.non_arq_data.cpdu_id_1", FT_UINT8, BASE_DEC, NULL, 0xF0, NULL, HFILL }
            },
            { &hf_s5066dts_non_arq_data_deliver_in_order,
                { "C_PDU Deliver-in-Order", "s5066dts.non_arq_data.deliver_in_order", FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL }
            },
            { &hf_s5066dts_non_arq_data_group_address,
                { "Group Address", "s5066dts.non_arq_data.group_address", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL }
            },
            { &hf_s5066dts_non_arq_data_cpdu_id_2,
                { "C_PDU ID number (field 2)", "s5066dts.non_arq_data.cpdu_id_2", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_non_arq_data_cpdu_size,
                { "C_PDU size", "s5066dts.non_arq_data.cpdu_size", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_non_arq_data_cpdu_segment_offset,
                { "Offset of segmented C_PDU", "s5066dts.non_arq_data.cpdu_segment_offset", FT_UINT16, BASE_DEC,
                        NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_non_arq_data_cpdu_reception_window,
                { "C_PDU reception window", "s5066dts.non_arq_data.cpdu_reception_window", FT_UINT16, BASE_DEC,
                        NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_non_arq_data_segmented_cpdu_size,
                { "Size of segmented C_PDU", "s5066dts.non_arq_data.segmented_cpdu_size", FT_UINT16, BASE_DEC,
                        NULL, 0x03FF, NULL, HFILL }
            },
            /* { 8, "EXP_NON_ARQ_DATA"}, */
            { &hf_s5066dts_exp_non_arq_data_cpdu_id_1,
                { "C_PDU ID number (field 1)", "s5066dts.exp_non_arq_data.cpdu_id_1", FT_UINT8, BASE_DEC, NULL, 0xF0, NULL, HFILL }
            },
            { &hf_s5066dts_exp_non_arq_data_deliver_in_order,
                { "C_PDU Deliver-in-Order", "s5066dts.exp_non_arq_data.deliver_in_order", FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL }
            },
            { &hf_s5066dts_exp_non_arq_data_group_address,
                { "Group Address", "s5066dts.exp_non_arq_data.group_address", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL }
            },
            { &hf_s5066dts_exp_non_arq_data_cpdu_id_2,
                { "C_PDU ID number (field 2)", "s5066dts.exp_non_arq_data.cpdu_id_2", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_exp_non_arq_data_cpdu_size,
                { "C_PDU size", "s5066dts.exp_non_arq_data.cpdu_size", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_exp_non_arq_data_cpdu_segment_offset,
                { "Offset of segmented C_PDU", "s5066dts.exp_non_arq_data.cpdu_segment_offset", FT_UINT16, BASE_DEC,
                        NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_exp_non_arq_data_cpdu_reception_window,
                { "C_PDU reception window", "s5066dts.exp_non_arq_data.cpdu_reception_window", FT_UINT16, BASE_DEC,
                        NULL, 0x0, NULL, HFILL }
            },
            { &hf_s5066dts_exp_non_arq_data_segmented_cpdu_size,
                { "Size of segmented C_PDU", "s5066dts.exp_non_arq_data.segmented_cpdu_size", FT_UINT16, BASE_DEC,
                        NULL, 0x03FF, NULL, HFILL }
            },
            /* {15, "WARNING"}, */
            { &hf_s5066dts_warning_frame_type,
                { "Received frame type", "s5066dts.warning.frame_type", FT_UINT8, BASE_DEC, NULL, 0xF0, NULL, HFILL }
            },
            { &hf_s5066dts_warning_reason,
                { "Reason warning sent", "s5066dts.warning.reason", FT_UINT8, BASE_DEC, NULL, 0x0F, NULL, HFILL }
            },
    };

    static int *ett[] = {
            &ett_s5066dts,
            &ett_s5066dts_eow,
            &ett_s5066dts_address,
            &ett_s5066dts_pdu,
            &ett_s5066dts_hftrp_token,
    };

    /* Setup protocol expert items */
    static ei_register_info ei[] = {
            { &ei_s5066dts_eow_hdr_drc_request_invalid, { "s5066dts.eow_hdr_drc_request.invalid", PI_MALFORMED, PI_ERROR,
                    "High data rate change request can only be made in Management D_PDU", EXPFILL }},
            { &ei_s5066dts_eow_hftrp_invalid, { "s5066dts.eow_hftrp.invalid", PI_MALFORMED, PI_ERROR,
                    "HFTRP tokens can only be carried with Management D_PDU", EXPFILL }},
        };

    expert_module_t* expert_s5066dts;

    if (proto_s5066dts <= 0) /* do protocol initialization only once */
    {
        proto_s5066dts = proto_register_protocol ("STANAG 5066(DTS layer)", "STANAG 5066 DTS", "s5066dts");
        proto_register_field_array(proto_s5066dts, hf, array_length(hf));
        proto_register_subtree_array(ett, array_length(ett));
        expert_s5066dts = expert_register_protocol(proto_s5066dts);
        expert_register_field_array(expert_s5066dts, ei, array_length(ei));
        s5066dts_handle = register_dissector(DISSECTOR_NAME ".raw", dissect_s5066dts_raw, proto_s5066dts);
        s5066dts_over_tcp_handle = register_dissector(DISSECTOR_NAME, dissect_s5066dts_tcp, proto_s5066dts);
    }

    s5066dts_module = prefs_register_protocol(proto_s5066dts, apply_s5066dts_prefs);

    prefs_register_bool_preference(s5066dts_module, "proto_desegment",
        "Reassemble STANAG 5066 DPDUs spanning multiple TCP segments",
        "Whether the STANAG 5066 DTS Layer dissector should reassemble DPDUs spanning multiple TCP segments",
        &config_proto_desegment);
}

/* Routine that will be called when s5066dts is handing off to the next dissector */
void proto_reg_handoff_s5066dts(void)
{
    dissector_add_uint("wtap_encap", WTAP_ENCAP_STANAG_5066_D_PDU, s5066dts_handle);
    dissector_add_for_decode_as_with_preference("tcp.port", s5066dts_over_tcp_handle);
    apply_s5066dts_prefs();
}

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