aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/acn/packet-acn.c
blob: 9fcea45853dc23eb0cf2e577bb0963c71d65786b (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
/* packet-acn.c
 * Routines for ACN packet disassembly
 *
 * $Id$
 *
 * Copyright (c) 2003 by Erwin Rol <erwin@erwinrol.com>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1999 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/* Include files */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <string.h>

#include <glib.h>

#include <epan/packet.h>
#include <epan/addr_resolv.h>
#include <epan/prefs.h>
#include <epan/strutil.h>

#include "acn.h"

/*
 * See
 *
 *	http://www.esta.org/tsp/E1-17inst.htm
 */

static const value_string acn_proto_vals[] = {
	{ ACN_PDU_PROTO_UNKNOWN,	"Unknown"},
	{ ACN_PDU_PROTO_SDT,		"SDT" },
	{ ACN_PDU_PROTO_DMP,		"DMP" },
	{ 0,				NULL }
};

static const value_string acn_sdt_type_vals[] = {
	{ ACN_SDT_TYPE_UNKNOWN,		"Unknown"},
	{ ACN_SDT_TYPE_RELSEQDATA,	"RELSEQDATA"},
	{ ACN_SDT_TYPE_UNRELSEQDATA,	"UNRELSEQDATA"},
	{ ACN_SDT_TYPE_UNSEQDATA,	"UNSEQDATA"},
	{ ACN_SDT_TYPE_JOIN,		"JOIN"},
	{ ACN_SDT_TYPE_TRANSFER,	"TRANSFER"},
	{ ACN_SDT_TYPE_JOINREF,		"JOINREF"},
	{ ACN_SDT_TYPE_JOINACC,		"JOINACC"},
	{ ACN_SDT_TYPE_LEAVEREQ,	"LEAVEREQ"},
	{ ACN_SDT_TYPE_LEAVE,		"LEAVE"},
	{ ACN_SDT_TYPE_LEAVING,		"LEAVING"},
	{ ACN_SDT_TYPE_NAKUPON,		"NAKUPON"},
	{ ACN_SDT_TYPE_NAKUPOFF,	"NAKUPOFF"},
	{ ACN_SDT_TYPE_NAKDOWNON,	"NAKDOWNON"},
	{ ACN_SDT_TYPE_NAKDOWNOFF,	"NAKDOWNOFF"},
	{ ACN_SDT_TYPE_REPLOSTSEQON,	"REPLOSTSEQON"},
	{ ACN_SDT_TYPE_REPLOSTSEQOFF,	"REPLOSTSEQOFF"},
	{ ACN_SDT_TYPE_SESSEXPIRY,	"SESEXPIRY"},
	{ ACN_SDT_TYPE_MAK,		"MAK"},
	{ ACN_SDT_TYPE_ACK,		"ACK"},
	{ ACN_SDT_TYPE_NAK,		"NAK"},
	{ ACN_SDT_TYPE_SEQLOST,		"SEQLOST"},
	{ ACN_SDT_TYPE_NAKPARAMS,	"NAKPARAMS"},
	{ 0,				NULL }
};

static const value_string acn_dmp_type_vals[] = {
	{ ACN_DMP_TYPE_UNKNOWN,		"Unknown"},
	{ 0,				NULL }
};


static const value_string acn_sdt_address_type_vals[] = {
	{ ACN_SDT_ADDR_NULL,		"Unspecified"},
	{ ACN_SDT_ADDR_IPV4,		"IP version 4"},
	{ ACN_SDT_ADDR_IPV6,		"IP version 6"},
	{ 0,				NULL }
};

static const value_string acn_sdt_des_flag_vals[] = {
	{ 0,				"Default"},
	{ 1,				"Protocol Specific"},
	{ 2,				"CID"},
	{ 3,				"All"}, 
	{ 0,				NULL }
};

static const value_string acn_sdt_src_flag_vals[] = {
	{ 0,				"Default"},
	{ 1,				"Protocol Specific"},
	{ 2,				"CID"},
	{ 3,				"Unspecified"}, 
	{ 0,				NULL }
};


void proto_reg_handoff_acn(void);

/* Define the acn proto */
static int proto_acn = -1;

/* Define the tree for acn */
static int ett_acn = -1;

/* PDU */
static int hf_acn_pdu = -1;

static int hf_acn_pdu_flags = -1;

static int hf_acn_pdu_des = -1;
static int hf_acn_pdu_src = -1;
static int hf_acn_pdu_flag_p = -1;
static int hf_acn_pdu_flag_t = -1;
static int hf_acn_pdu_flag_res = -1;
static int hf_acn_pdu_flag_z = -1;
static int hf_acn_pdu_length = -1;

/* PDU optional */
static int hf_acn_pdu_ext_length_16 = -1;
static int hf_acn_pdu_ext_length_32 = -1;
static int hf_acn_pdu_source_ps = -1;
static int hf_acn_pdu_source_cid = -1;
static int hf_acn_pdu_destination_ps = -1;
static int hf_acn_pdu_destination_cid = -1;
static int hf_acn_pdu_protocol = -1;
static int hf_acn_pdu_type = -1;
static int hf_acn_pdu_type_sdt = -1;
static int hf_acn_pdu_type_dmp = -1;
static int hf_acn_pdu_data = -1;
static int hf_acn_pdu_unknown_data = -1;

static int hf_acn_pdu_padding = -1;

/* SDT */
static int hf_acn_sdt_session_nr = -1;
static int hf_acn_sdt_tot_seq_nr = -1;
static int hf_acn_sdt_rel_seq_nr = -1;
static int hf_acn_sdt_unavailable_wrappers = -1;
static int hf_acn_sdt_refuse_code = -1;
static int hf_acn_sdt_last_rel_seq = -1;
static int hf_acn_sdt_new_rel_seq = -1;
static int hf_acn_sdt_last_rel_wrapper = -1;
static int hf_acn_sdt_nr_lost_wrappers = -1;
static int hf_acn_sdt_session_exp_time = -1;
static int hf_acn_sdt_upstream_address_type = -1;
static int hf_acn_sdt_upstream_ipv4_address = -1;
static int hf_acn_sdt_upstream_ipv6_address = -1;
static int hf_acn_sdt_upstream_port = -1;
static int hf_acn_sdt_downstream_address_type = -1;
static int hf_acn_sdt_downstream_ipv4_address = -1;
static int hf_acn_sdt_downstream_ipv6_address = -1;
static int hf_acn_sdt_downstream_port = -1;

static int hf_acn_sdt_flags = -1;
static int hf_acn_sdt_flag_u = -1;
static int hf_acn_sdt_flag_d = -1;
static int hf_acn_sdt_flag_l = -1;

static int hf_acn_sdt_mid = -1;
static int hf_acn_sdt_nak_holdoff_interval = -1;
static int hf_acn_sdt_nak_modulus = -1;
static int hf_acn_sdt_max_nak_wait_time = -1;
static int hf_acn_sdt_leader_cid = -1;
static int hf_acn_sdt_member_cid = -1;
static int hf_acn_sdt_ack_threshold = -1;

/*
 * Here are the global variables associated with the preferences
 * for acn
 */

static guint global_udp_port_acn = 0;
static guint udp_port_acn = 0;

/* A static handle for the ip dissector */
static dissector_handle_t ip_handle;

static guint dissect_pdu(tvbuff_t *tvb, guint offset, proto_tree *tree, acn_pdu_history_t* parent_hist, guint max_size);
static guint dissect_sdt(tvbuff_t *tvb, guint offset, proto_tree *tree, acn_pdu_history_t* parent_hist, guint max_size);
static guint dissect_dmp(tvbuff_t *tvb, guint offset, proto_tree *tree, acn_pdu_history_t* parent_hist, guint max_size);

static guint 
dissect_sdt(tvbuff_t *tvb, guint offset, proto_tree *tree, acn_pdu_history_t* parent_hist, guint max_size)
{
	proto_tree *flags_tree, *flags_item;
	guint start_offset = offset;
	acn_pdu_history_t hist;
	guint size = 0;
	guint flags;
	guint type;
	guint count;

	hist = *parent_hist;

	switch( parent_hist->type )
	{
		case ACN_SDT_TYPE_UNKNOWN:
			break;

		case ACN_SDT_TYPE_RELSEQDATA:
		case ACN_SDT_TYPE_UNRELSEQDATA:
			proto_tree_add_item(tree, hf_acn_sdt_session_nr, tvb,
						offset, 2, FALSE);
			offset += 2;
			
			proto_tree_add_item(tree, hf_acn_sdt_tot_seq_nr, tvb,
						offset, 4, FALSE);
			offset += 4;

			proto_tree_add_item(tree, hf_acn_sdt_rel_seq_nr, tvb,
						offset, 4, FALSE);
			offset += 4;

			proto_tree_add_item(tree, hf_acn_sdt_unavailable_wrappers, tvb,
						offset, 4, FALSE);
			offset += 4;

			max_size = max_size - (offset - start_offset);
			while( max_size >= ACN_PDU_MIN_SIZE) {
				size = dissect_pdu( tvb, offset, tree, &hist, max_size);
				offset += size;
				max_size -= size;
			}
			
			size = offset - start_offset;

			break;

		case ACN_SDT_TYPE_UNSEQDATA:
			proto_tree_add_item(tree, hf_acn_sdt_session_nr, tvb,
						offset, 2, FALSE);
			offset += 2;

			max_size = max_size - (offset - start_offset);
			while( max_size >= ACN_PDU_MIN_SIZE) {
				size = dissect_pdu( tvb, offset, tree, &hist, max_size);
				offset += size;
				max_size -= size;
			}
			
			size = offset - start_offset;

			break;
			
		case ACN_SDT_TYPE_JOIN:
			proto_tree_add_item(tree, hf_acn_sdt_session_nr, tvb,
						offset, 2, FALSE);
			offset += 2;

			flags = tvb_get_guint8(tvb, offset);
			flags_item = proto_tree_add_uint(tree, hf_acn_sdt_flags, tvb,
							offset, 1, flags);

			flags_tree=proto_item_add_subtree(flags_item, ett_acn);
			proto_tree_add_item(flags_tree, hf_acn_sdt_flag_u, tvb, offset, 1, FALSE);
			proto_tree_add_item(flags_tree, hf_acn_sdt_flag_d, tvb, offset, 1, FALSE);
			proto_tree_add_item(flags_tree, hf_acn_sdt_flag_l, tvb, offset, 1, FALSE);
			offset += 1;

			type = tvb_get_guint8(tvb, offset);
			proto_tree_add_item(tree, hf_acn_sdt_upstream_address_type, tvb,
					    offset, 1, FALSE);
			offset += 1;
			
			switch( type )
			{
				default:
				case ACN_SDT_ADDR_NULL:
					break;
					
				case ACN_SDT_ADDR_IPV4:
					proto_tree_add_item(tree, hf_acn_sdt_upstream_port, tvb,
								offset, 2, FALSE);
					offset += 2;
				
					proto_tree_add_item(tree, hf_acn_sdt_upstream_ipv4_address, tvb,
								offset, 4, FALSE);
					offset += 4;
				
					break;
					
				case ACN_SDT_ADDR_IPV6:
					proto_tree_add_item(tree, hf_acn_sdt_upstream_port, tvb,
								offset, 2, FALSE);
					offset += 2;

					proto_tree_add_item(tree, hf_acn_sdt_upstream_ipv6_address, tvb,
								offset, 16, FALSE);
					offset += 16;
				
					break;		
			}
			
			flags = tvb_get_guint8(tvb, offset);
			flags_item = proto_tree_add_uint(tree, hf_acn_sdt_flags, tvb,
							offset, 1, flags);

			flags_tree=proto_item_add_subtree(flags_item, ett_acn);
			offset += 1;

			type = tvb_get_guint8(tvb, offset);
			proto_tree_add_item(tree, hf_acn_sdt_downstream_address_type, tvb,
					    offset, 1, FALSE);
			offset += 1;
			
			switch( type )
			{
				default:
				case ACN_SDT_ADDR_NULL:
					break;
					
				case ACN_SDT_ADDR_IPV4:
					proto_tree_add_item(tree, hf_acn_sdt_downstream_port, tvb,
								offset, 2, FALSE);
					offset += 2;

					proto_tree_add_item(tree, hf_acn_sdt_downstream_ipv4_address, tvb,
								offset, 4, FALSE);
					offset += 4;
				
				
					break;
					
				case ACN_SDT_ADDR_IPV6:
					proto_tree_add_item(tree, hf_acn_sdt_downstream_port, tvb,
								offset, 2, FALSE);
					offset += 2;

					proto_tree_add_item(tree, hf_acn_sdt_downstream_ipv6_address, tvb,
								offset, 16, FALSE);
					offset += 16;
				
					break;		
			}
			
							
			proto_tree_add_item(tree, hf_acn_sdt_mid, tvb,
						offset, 2, FALSE);
			offset += 2;

			proto_tree_add_item(tree, hf_acn_sdt_tot_seq_nr, tvb,
						offset, 4, FALSE);
			offset += 4;

			proto_tree_add_item(tree, hf_acn_sdt_rel_seq_nr, tvb,
						offset, 4, FALSE);
			offset += 4;
			
			proto_tree_add_item(tree, hf_acn_sdt_session_exp_time, tvb,
						offset, 2, FALSE);
			offset += 2;

			proto_tree_add_item(tree, hf_acn_sdt_nak_holdoff_interval, tvb,
						offset, 2, FALSE);
			offset += 2;
			
			proto_tree_add_item(tree, hf_acn_sdt_nak_modulus, tvb,
						offset, 2, FALSE);
			offset += 2;
			
			proto_tree_add_item(tree, hf_acn_sdt_max_nak_wait_time, tvb,
						offset, 2, FALSE);
			offset += 2;
					
			size = offset - start_offset;

			break;

		case ACN_SDT_TYPE_TRANSFER:
			proto_tree_add_item(tree, hf_acn_sdt_leader_cid, tvb,
						offset, 16, FALSE);
			offset += 16;

			proto_tree_add_item(tree, hf_acn_sdt_session_nr, tvb,
						offset, 2, FALSE);
			offset += 2;

			flags = tvb_get_guint8(tvb, offset);
			flags_item = proto_tree_add_uint(tree, hf_acn_sdt_flags, tvb,
							offset, 1, flags);

			flags_tree=proto_item_add_subtree(flags_item, ett_acn);
			proto_tree_add_item(flags_tree, hf_acn_sdt_flag_u, tvb, offset, 1, FALSE);
			proto_tree_add_item(flags_tree, hf_acn_sdt_flag_d, tvb, offset, 1, FALSE);
			proto_tree_add_item(flags_tree, hf_acn_sdt_flag_l, tvb, offset, 1, FALSE);
			offset += 1;

			type = tvb_get_guint8(tvb, offset);
			proto_tree_add_item(tree, hf_acn_sdt_upstream_address_type, tvb,
					    offset, 1, FALSE);
			offset += 1;
			
			switch( type )
			{
				default:
				case ACN_SDT_ADDR_NULL:
					break;
					
				case ACN_SDT_ADDR_IPV4:
					proto_tree_add_item(tree, hf_acn_sdt_upstream_ipv4_address, tvb,
								offset, 4, FALSE);
					offset += 4;
				
					proto_tree_add_item(tree, hf_acn_sdt_upstream_port, tvb,
								offset, 2, FALSE);
					offset += 2;
				
					break;
					
				case ACN_SDT_ADDR_IPV6:
					proto_tree_add_item(tree, hf_acn_sdt_upstream_ipv6_address, tvb,
								offset, 16, FALSE);
					offset += 16;
				
					proto_tree_add_item(tree, hf_acn_sdt_upstream_port, tvb,
								offset, 2, FALSE);
					offset += 2;
					break;		
			}
			
			flags = tvb_get_guint8(tvb, offset);
			flags_item = proto_tree_add_uint(tree, hf_acn_sdt_flags, tvb,
							offset, 1, flags);

			flags_tree=proto_item_add_subtree(flags_item, ett_acn);
			offset += 1;

			type = tvb_get_guint8(tvb, offset);
			proto_tree_add_item(tree, hf_acn_sdt_downstream_address_type, tvb,
					    offset, 1, FALSE);
			offset += 1;
			
			switch( type )
			{
				default:
				case ACN_SDT_ADDR_NULL:
					break;
					
				case ACN_SDT_ADDR_IPV4:
					proto_tree_add_item(tree, hf_acn_sdt_downstream_ipv4_address, tvb,
								offset, 4, FALSE);
					offset += 4;
				
					proto_tree_add_item(tree, hf_acn_sdt_downstream_port, tvb,
								offset, 2, FALSE);
					offset += 2;
				
					break;
					
				case ACN_SDT_ADDR_IPV6:
					proto_tree_add_item(tree, hf_acn_sdt_downstream_ipv6_address, tvb,
								offset, 16, FALSE);
					offset += 16;
				
					proto_tree_add_item(tree, hf_acn_sdt_downstream_port, tvb,
								offset, 2, FALSE);
					offset += 2;
					break;		
			}
			
							
			proto_tree_add_item(tree, hf_acn_sdt_mid, tvb,
						offset, 2, FALSE);
			offset += 2;

			proto_tree_add_item(tree, hf_acn_sdt_tot_seq_nr, tvb,
						offset, 4, FALSE);
			offset += 4;

			proto_tree_add_item(tree, hf_acn_sdt_rel_seq_nr, tvb,
						offset, 4, FALSE);
			offset += 4;
			
			proto_tree_add_item(tree, hf_acn_sdt_session_exp_time, tvb,
						offset, 2, FALSE);
			offset += 2;

			proto_tree_add_item(tree, hf_acn_sdt_nak_holdoff_interval, tvb,
						offset, 2, FALSE);
			offset += 2;
			
			proto_tree_add_item(tree, hf_acn_sdt_nak_modulus, tvb,
						offset, 2, FALSE);
			offset += 2;
			
			proto_tree_add_item(tree, hf_acn_sdt_max_nak_wait_time, tvb,
						offset, 2, FALSE);
			offset += 2;
			
			/* CID+MID list */
			count = (max_size - (offset - start_offset)) / 18;
			while( count > 0) {
				proto_tree_add_item(tree, hf_acn_sdt_member_cid, tvb,
							offset, 16, FALSE);
				offset += 16;

				proto_tree_add_item(tree, hf_acn_sdt_mid, tvb,
							offset, 2, FALSE);
				offset += 2;

				count--;
			}
			
			size = offset - start_offset;

			break;

		case ACN_SDT_TYPE_JOINREF:
			proto_tree_add_item(tree, hf_acn_sdt_session_nr, tvb,
						offset, 2, FALSE);
			offset += 2;

			proto_tree_add_item(tree, hf_acn_sdt_refuse_code, tvb,
						offset, 2, FALSE);
			offset += 2;

			size = offset - start_offset;
			break;

		case ACN_SDT_TYPE_JOINACC:
		case ACN_SDT_TYPE_ACK:
			proto_tree_add_item(tree, hf_acn_sdt_last_rel_seq, tvb,
						offset, 4, FALSE);
			offset += 4;

			size = offset - start_offset;
			break;

		case ACN_SDT_TYPE_LEAVING:
			proto_tree_add_item(tree, hf_acn_sdt_last_rel_wrapper, tvb,
						offset, 4, FALSE);
			offset += 4;

			size = offset - start_offset;
			break;


		case ACN_SDT_TYPE_SESSEXPIRY:
			proto_tree_add_item(tree, hf_acn_sdt_session_exp_time, tvb,
						offset, 2, FALSE);
			offset += 2;

			size = offset - start_offset;
			break;

		case ACN_SDT_TYPE_MAK:
			proto_tree_add_item(tree, hf_acn_sdt_ack_threshold, tvb,
						offset, 2, FALSE);
			offset += 2;

			count = (max_size - (offset - start_offset)) / 2;
			while( count > 0) {
				proto_tree_add_item(tree, hf_acn_sdt_mid, tvb,
							offset, 2, FALSE);
				offset += 2;

				count--;
			}
			
			size = offset - start_offset;
			break;
			
		case ACN_SDT_TYPE_NAK:				
			proto_tree_add_item(tree, hf_acn_sdt_session_nr, tvb,
						offset, 2, FALSE);
			offset += 2;

			proto_tree_add_item(tree, hf_acn_sdt_mid, tvb,
						offset, 2, FALSE);
			offset += 2;

			proto_tree_add_item(tree, hf_acn_sdt_last_rel_seq, tvb,
						offset, 4, FALSE);
			offset += 4;

			proto_tree_add_item(tree, hf_acn_sdt_nr_lost_wrappers, tvb,
						offset, 2, FALSE);
			offset += 2;

			size = offset - start_offset;
			break;
			
		case ACN_SDT_TYPE_SEQLOST:
			proto_tree_add_item(tree, hf_acn_sdt_last_rel_seq, tvb,
						offset, 4, FALSE);
			offset += 4;

			proto_tree_add_item(tree, hf_acn_sdt_new_rel_seq, tvb,
						offset, 4, FALSE);
			offset += 4;
			size = offset - start_offset;
			break;

		case ACN_SDT_TYPE_NAKPARAMS:
			proto_tree_add_item(tree, hf_acn_sdt_nak_holdoff_interval, tvb,
						offset, 2, FALSE);
			offset += 2;
			
			proto_tree_add_item(tree, hf_acn_sdt_nak_modulus, tvb,
						offset, 2, FALSE);
			offset += 2;
			
			proto_tree_add_item(tree, hf_acn_sdt_max_nak_wait_time, tvb,
						offset, 2, FALSE);
			offset += 2;

			size = offset - start_offset;
			break;

		case ACN_SDT_TYPE_LEAVEREQ:
		case ACN_SDT_TYPE_LEAVE:
		case ACN_SDT_TYPE_NAKUPON:
		case ACN_SDT_TYPE_NAKUPOFF:
		case ACN_SDT_TYPE_NAKDOWNON:
		case ACN_SDT_TYPE_NAKDOWNOFF:
		case ACN_SDT_TYPE_REPLOSTSEQON:
		case ACN_SDT_TYPE_REPLOSTSEQOFF:
			/* no data */
			size = offset - start_offset;
			break;

		default:
			break;
	}
	
	return size;
}

static guint 
dissect_dmp(tvbuff_t *tvb _U_, guint offset _U_, proto_tree *tree _U_, acn_pdu_history_t* parent_hist _U_, guint max_size _U_)
{
	return 0;
}

static guint 
dissect_pdu(tvbuff_t *tvb, guint offset, proto_tree *tree, acn_pdu_history_t* parent_hist, guint max_size)
{
	guint size,data_size;
	guint8 flags;
	guint src,des;
	proto_tree *ti, *si, *flags_tree, *flags_item, *data_tree, *data_item;
	guint start_offset = offset;
	acn_pdu_history_t hist = *parent_hist;
	

	ti = proto_tree_add_item(tree,
				hf_acn_pdu,
				tvb,
				offset,
				0,
				FALSE);
 
	si = proto_item_add_subtree(ti, ett_acn);
 
	flags = tvb_get_guint8(tvb, offset);
	flags_item = proto_tree_add_uint(si, hf_acn_pdu_flags, tvb,
					offset, 1, flags);

	flags_tree=proto_item_add_subtree(flags_item, ett_acn);
	
	proto_tree_add_item(flags_tree, hf_acn_pdu_des, tvb, offset, 1, FALSE);
	proto_tree_add_item(flags_tree, hf_acn_pdu_src, tvb, offset, 1, FALSE);
	proto_tree_add_item(flags_tree, hf_acn_pdu_flag_p, tvb, offset, 1, FALSE);
	proto_tree_add_item(flags_tree, hf_acn_pdu_flag_t, tvb, offset, 1, FALSE);
	proto_tree_add_item(flags_tree, hf_acn_pdu_flag_res, tvb, offset, 1, FALSE);
	proto_tree_add_item(flags_tree, hf_acn_pdu_flag_z, tvb, offset, 1, FALSE);

	offset += 1;

	size = tvb_get_guint8(tvb, offset);	
	proto_tree_add_uint(si, hf_acn_pdu_length, tvb,
	                          offset, 1, size);
	offset += 1;
	

	if( size == 0 ){
		size = tvb_get_ntohs(tvb, offset);
		proto_tree_add_uint(si, hf_acn_pdu_ext_length_16, tvb,
					offset, 2, size);	
		offset += 2;	
	} else if( size == 1 ){
		size = tvb_get_ntohl( tvb, offset);
		proto_tree_add_uint(si, hf_acn_pdu_ext_length_32, tvb,
					offset, 4, size);	
		offset += 4;
	}
	
	if(size > max_size )
		size = max_size;

	switch( flags & ACN_PDU_DES )
	{	
		case ACN_PDU_DES_SAME:
			break;
			
		case ACN_PDU_DES_PS:
			hist.destination_type = ACN_PDU_DES_PS;
			des = tvb_get_ntohs(tvb, offset);
			hist.destination.ps = des;
			proto_tree_add_uint(si, hf_acn_pdu_destination_ps, tvb,
						offset, 2, des);	
			offset += 2;
			break;
			
		case ACN_PDU_DES_CID:
			hist.destination_type = ACN_PDU_DES_CID;
			tvb_memcpy(tvb, hist.destination.cid, offset, 16 );
			proto_tree_add_item(si, hf_acn_pdu_destination_cid, tvb,
						offset, 16, FALSE);
			offset += 16;
			break;
			
		case ACN_PDU_DES_ALL:
			hist.destination_type = ACN_PDU_DES_ALL;
			break;	
	} 


	switch( flags & ACN_PDU_SRC )
	{
		case ACN_PDU_SRC_SAME:
			break;
			
		case ACN_PDU_SRC_PS:
			hist.source_type = ACN_PDU_SRC_PS;
			src = tvb_get_ntohs(tvb, offset);
			hist.source.ps = src;
			proto_tree_add_uint(si, hf_acn_pdu_source_ps, tvb,
						offset, 2, src);
			offset += 2;
			break;
			
		case ACN_PDU_SRC_CID:
			hist.source_type = ACN_PDU_SRC_CID;
			tvb_memcpy(tvb, hist.source.cid, offset, 16 );
			proto_tree_add_item(si, hf_acn_pdu_source_cid, tvb,
						offset, 16, FALSE);
			offset += 16;
			break;
			
		case ACN_PDU_SRC_UM:
			hist.source_type = ACN_PDU_SRC_UM;
			break;	
	} 



	if( flags & ACN_PDU_FLAG_P )
	{
		hist.protocol = tvb_get_ntohs( tvb, offset );
		proto_tree_add_item(si, hf_acn_pdu_protocol, tvb,
					offset, 2, FALSE );
		offset += 2;
	}

	if( flags & ACN_PDU_FLAG_T )
	{
		hist.type = tvb_get_ntohs( tvb, offset );
	
		switch( hist.protocol ) { 
			case ACN_PDU_PROTO_SDT:
				proto_tree_add_item(si, hf_acn_pdu_type_sdt, tvb,
						offset, 2, FALSE );
				break;

			case ACN_PDU_PROTO_DMP:
				proto_tree_add_item(si, hf_acn_pdu_type_dmp, tvb,
						offset, 2, FALSE );
				break;
				
			default:
				proto_tree_add_item(si, hf_acn_pdu_type, tvb,
						offset, 2, FALSE );
				break;	
	
	
	
		}
		
		offset += 2;
	}

	if( flags & ACN_PDU_FLAG_Z )
	{
		data_size = size - (offset - start_offset);


		data_item = proto_tree_add_item(si, hf_acn_pdu_data, tvb,
						offset, data_size, FALSE);

		data_tree=proto_item_add_subtree(data_item, ett_acn);


		switch( hist.protocol ) {
			case ACN_PDU_PROTO_SDT:
				dissect_sdt( tvb, offset, data_tree, &hist, data_size);
				break;
			
			case ACN_PDU_PROTO_DMP:
				dissect_dmp( tvb, offset, data_tree, &hist, data_size);	
				break;
	
			default:
				proto_tree_add_item(si, hf_acn_pdu_unknown_data, tvb,
							offset, data_size, FALSE );
				break;	
		}

		offset += data_size;
	}

	if( size & 0x00000001 )
	{
	
		proto_tree_add_item(si, hf_acn_pdu_padding, tvb,
					offset, 1, TRUE );
		
		size += 1;
		offset += 1;
	}

	proto_item_set_len(si, size);

	return size;
}

static void
dissect_acn(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
	gint offset = 0;
	guint size,max_size;
	acn_pdu_history_t hist;

	/* Set the protocol column */
	if(check_col(pinfo->cinfo,COL_PROTOCOL)){
		col_set_str(pinfo->cinfo,COL_PROTOCOL,"ACN");
	}

	/* Clear out stuff in the info column */
	if(check_col(pinfo->cinfo,COL_INFO)){
		col_clear(pinfo->cinfo,COL_INFO);
	}

	if (tree) 
	{
		/* history default values */
		hist.destination_type = ACN_PDU_DES_ALL; 
		hist.source_type = ACN_PDU_SRC_UM;
		hist.protocol = ACN_PDU_PROTO_UNKNOWN;
		hist.type = ACN_PDU_TYPE_UNKNOWN;
		
		max_size = tvb_reported_length_remaining(tvb, offset);
		
		while( max_size >= ACN_PDU_MIN_SIZE) {
			size = dissect_pdu( tvb, offset, tree, &hist, max_size);
			offset += size;
			max_size -= size;
		}
	}
}

void
proto_register_acn(void) {
  static hf_register_info hf[] = {
	/* PDU */
	{ &hf_acn_pdu,
	    { "ACN PDU", "acn.pdu",
		FT_NONE, BASE_NONE, NULL, 0,
		"ACN PDU", HFILL }},

	{ &hf_acn_pdu_flags,
	    { "Flags","acn.pdu.flags",
		FT_UINT8, BASE_HEX, NULL, 0x0,
		"Flags", HFILL }},

	{ &hf_acn_pdu_des,
	    { "des","acn.pdu.des",
		FT_UINT8, BASE_HEX, VALS( acn_sdt_des_flag_vals ), 0xC0,
		"des", HFILL }},

	{ &hf_acn_pdu_src,
	    { "src","acn.pdu.src",
		FT_UINT8, BASE_HEX, VALS( acn_sdt_src_flag_vals ), 0x30,
		"src", HFILL }},

	{ &hf_acn_pdu_flag_p,
	    { "P","acn.pdu.flag_p",
		FT_UINT8, BASE_HEX, NULL, 0x08,
		"P", HFILL }},

	{ &hf_acn_pdu_flag_t,
	    { "T","acn.pdu.flag_t",
		FT_UINT8, BASE_HEX, NULL, 0x04,
		"T", HFILL }},

	{ &hf_acn_pdu_flag_z,
	    { "Z","acn.pdu.flag_z",
		FT_UINT8, BASE_HEX, NULL, 0x01,
		"Z", HFILL }},

	{ &hf_acn_pdu_flag_res,
	    { "res","acn.pdu.flag_res",
		FT_UINT8, BASE_HEX, NULL, 0x02,
		"res", HFILL }},

	{ &hf_acn_pdu_length,
	    { "Length","acn.pdu.length",
		FT_UINT8, BASE_DEC, NULL, 0x0,
		"Length", HFILL }},

	{ &hf_acn_pdu_ext_length_16,
	    { "Ext Length 16bit","acn.pdu.ext_length_16",
		FT_UINT16, BASE_DEC, NULL, 0x0,
		"Ext Length 16bit", HFILL }},

	{ &hf_acn_pdu_ext_length_32,
	    { "Ext Length 32bit","acn.pdu.ext_length_32",
		FT_UINT32, BASE_DEC, NULL, 0x0,
		"Ext Length 32bit", HFILL }},

	{ &hf_acn_pdu_source_ps,
	    { "Source PS","acn.pdu.source_ps",
		FT_UINT16, BASE_HEX, NULL, 0x0,
		"Source PS", HFILL }},

	{ &hf_acn_pdu_source_cid,
	    { "Source CID","acn.pdu.source_cid",
		FT_BYTES, BASE_HEX, NULL, 0x0,
		"Source CID", HFILL }},

	{ &hf_acn_pdu_destination_ps,
	    { "Destination PS","acn.pdu.destination_ps",
		FT_UINT16, BASE_HEX, NULL, 0x0,
		"Destination PS", HFILL }},

	{ &hf_acn_pdu_destination_cid,
	    { "Destination CID","acn.pdu.destination_cid",
		FT_BYTES, BASE_HEX, NULL, 0x0,
		"Destination CID", HFILL }},

	{ &hf_acn_pdu_protocol,
	    { "Protocol","acn.pdu.protocol",
		FT_UINT16, BASE_HEX, VALS(acn_proto_vals), 0x0,
		"Protocol", HFILL }},

	{ &hf_acn_pdu_type,
	    { "Type","acn.pdu.type",
		FT_UINT16, BASE_HEX, NULL, 0x0,
		"Type", HFILL }},

	{ &hf_acn_pdu_type_sdt,
	    { "SDT Type","acn.pdu.type_sdt",
		FT_UINT16, BASE_HEX, VALS(acn_sdt_type_vals), 0x0,
		"SDT Type", HFILL }},

	{ &hf_acn_pdu_type_dmp,
	    { "DMP Type","acn.pdu.type_dmp",
		FT_UINT16, BASE_HEX, VALS(acn_dmp_type_vals), 0x0,
		"DMP Type", HFILL }},
		
	{ &hf_acn_pdu_data,
	    { "Data","acn.pdu.data",
		FT_NONE, BASE_HEX, NULL, 0x0,
		"Data", HFILL }},

	{ &hf_acn_pdu_unknown_data,
	    { "Unknown Data","acn.pdu.unknown_data",
		FT_BYTES, BASE_HEX, NULL, 0x0,
		"Unknown Data", HFILL }},

	{ &hf_acn_pdu_padding,
	    { "Padding","acn.pdu.padding",
		FT_UINT8, BASE_DEC, NULL, 0x0,
		"Padding", HFILL }},

	{ &hf_acn_sdt_session_nr,
	    { "SDT Session Nr","acn.sdt.session_nr",
		FT_UINT16, BASE_DEC, NULL, 0x0,
		"SDT Session Nr", HFILL }},

	{ &hf_acn_sdt_tot_seq_nr,
	    { "SDT Total Sequence Nr","acn.sdt.tot_seq_nr",
		FT_UINT32, BASE_DEC, NULL, 0x0,
		"SDT Total Sequence Nr", HFILL }},

	{ &hf_acn_sdt_rel_seq_nr,
	    { "SDT Rel Seq Nr","acn.sdt.rel_seq_nr",
		FT_UINT32, BASE_DEC, NULL, 0x0,
		"SDT Rel Sequence Nr", HFILL }},

	{ &hf_acn_sdt_unavailable_wrappers,
	    { "SDT Unavailable Wrappers","acn.sdt.unavailable_wrappers",
		FT_UINT32, BASE_DEC, NULL, 0x0,
		"SDT Unavailable Wrappers", HFILL }},
		
	{ &hf_acn_sdt_refuse_code,
	    { "SDT Refuse code","acn.sdt.refuse_code",
		FT_UINT16, BASE_DEC, NULL, 0x0,
		"SDT Refuse Code", HFILL }},

	{ &hf_acn_sdt_last_rel_seq,
	    { "SDT Last reliable seq nr","acn.sdt.last_rel_seq",
		FT_UINT32, BASE_DEC, NULL, 0x0,
		"SDT Last reliable seq nr", HFILL }},

	{ &hf_acn_sdt_new_rel_seq,
	    { "SDT reliable seq nr to continue with","acn.sdt.new_rel_seq",
		FT_UINT32, BASE_DEC, NULL, 0x0,
		"SDT reliable seq nr to continue with", HFILL }},

	{ &hf_acn_sdt_last_rel_wrapper,
	    { "SDT Last reliable Wrapper","acn.sdt.last_rel_wrapper",
		FT_UINT32, BASE_DEC, NULL, 0x0,
		"SDT Last reliable Wrapper", HFILL }},

	{ &hf_acn_sdt_nr_lost_wrappers,
	    { "SDT Nr of lost Wrappers","acn.sdt.nr_lost_wrappers",
		FT_UINT32, BASE_DEC, NULL, 0x0,
		"SDT Nr of lost  Wrappers", HFILL }},

	{ &hf_acn_sdt_session_exp_time,
	    { "SDT Session expire time","acn.sdt.session_exp_time",
		FT_UINT16, BASE_DEC, NULL, 0x0,
		"SDT Session expire time", HFILL }},
		
	{ &hf_acn_sdt_flags,
	    { "SDT Flags","acn.sdt.flags",
		FT_UINT8, BASE_HEX, NULL, 0x0,
		"SDT Flags", HFILL }},

	{ &hf_acn_sdt_flag_u,
	    { "U","acn.sdt.flag_u",
		FT_UINT8, BASE_HEX, NULL, 0x80,
		"U", HFILL }},

	{ &hf_acn_sdt_flag_d,
	    { "D","acn.sdt.flag_d",
		FT_UINT8, BASE_HEX, NULL, 0x40,
		"D", HFILL }},

	{ &hf_acn_sdt_flag_l,
	    { "L","acn.sdt.flag_l",
		FT_UINT8, BASE_HEX, NULL, 0x20,
		"L", HFILL }},

	{ &hf_acn_sdt_upstream_address_type,
	    { "SDT Upstream address type","acn.sdt.upstream_address_type",
		FT_UINT8, BASE_HEX, VALS(acn_sdt_address_type_vals), 0x0,
		"SDT Upstream address type", HFILL }},

	{ &hf_acn_sdt_downstream_address_type,
	    { "SDT Downstream address type","acn.sdt.downstream_address_type",
		FT_UINT8, BASE_HEX, VALS(acn_sdt_address_type_vals), 0x0,
		"SDT Downstream address type", HFILL }},

	{ &hf_acn_sdt_upstream_port,
	    { "SDT Upstream Port","acn.sdt.upstream_port",
		FT_UINT16, BASE_DEC, NULL, 0x0,
		"SDT Upstream Port", HFILL }},

	{ &hf_acn_sdt_downstream_port,
	    { "SDT Donwstream Port","acn.sdt.downstream_port",
		FT_UINT16, BASE_DEC, NULL, 0x0,
		"SDT Downstream Port", HFILL }},

	{ &hf_acn_sdt_downstream_ipv4_address,
	    { "SDT Donwstream IPv4 Address","acn.sdt.downstream_ipv4_address",
		FT_IPv4, BASE_DEC, NULL, 0x0,
		"SDT Downstream IPv4 Address", HFILL }},

	{ &hf_acn_sdt_upstream_ipv4_address,
	    { "SDT Upstream IPv4 Address","acn.sdt.upstream_ipv4_address",
		FT_IPv4, BASE_DEC, NULL, 0x0,
		"SDT Upstream IPv4 Address", HFILL }},

	{ &hf_acn_sdt_downstream_ipv6_address,
	    { "SDT Donwstream IPv6 Address","acn.sdt.downstream_ipv6_address",
		FT_IPv6, BASE_DEC, NULL, 0x0,
		"SDT Downstream IPv6 Address", HFILL }},

	{ &hf_acn_sdt_upstream_ipv6_address,
	    { "SDT Upstream IPv6 Address","acn.sdt.upstream_ipv6_address",
		FT_IPv6, BASE_DEC, NULL, 0x0,
		"SDT Upstream IPv6 Address", HFILL }},

	{ &hf_acn_sdt_mid,
	    { "SDT Member ID","acn.sdt.mid",
		FT_UINT16, BASE_DEC, NULL, 0x0,
		"SDT Member ID", HFILL }},

	{ &hf_acn_sdt_nak_holdoff_interval,
	    { "SDT NAK holdoff interval","acn.sdt.nak_holdoff_interval",
		FT_UINT16, BASE_DEC, NULL, 0x0,
		"SDT NAK holdoff interval", HFILL }},

	{ &hf_acn_sdt_nak_modulus,
	    { "SDT NAK modulus","acn.sdt.nak_modulus",
		FT_UINT16, BASE_DEC, NULL, 0x0,
		"SDT NAK modulus", HFILL }},

	{ &hf_acn_sdt_max_nak_wait_time,
	    { "SDT Max. NAK wait time","acn.sdt.max_nak_wait_time",
		FT_UINT16, BASE_DEC, NULL, 0x0,
		"SDT Max. NAK wait time ", HFILL }},

	{ &hf_acn_sdt_ack_threshold,
	    { "SDT ACK threshold","acn.sdt.ack_threshold",
		FT_UINT16, BASE_DEC, NULL, 0x0,
		"SDT ACK threshold", HFILL }},

	{ &hf_acn_sdt_member_cid,
	    { "SDT Memebr CID","acn.sdt.member_cid",
		FT_BYTES, BASE_HEX, NULL, 0x0,
		"SDT Member CID", HFILL }},

	{ &hf_acn_sdt_leader_cid,
	    { "SDT Leader CID","acn.sdt.leader_cid",
		FT_BYTES, BASE_HEX, NULL, 0x0,
		"SDT Leader CID", HFILL }}

  };

  static gint *ett[] = {
    &ett_acn,
  };

  module_t *acn_module;

  proto_acn = proto_register_protocol("ACN",
				      "ACN","acn");
  proto_register_field_array(proto_acn,hf,array_length(hf));
  proto_register_subtree_array(ett,array_length(ett));

  acn_module = prefs_register_protocol(proto_acn,
				       proto_reg_handoff_acn);
#if 0
  prefs_register_uint_preference(artnet_module, "udp_port",
				 "ARTNET UDP Port",
				 "The UDP port on which "
				 "Art-Net "
				 "packets will be sent",
				 10,&global_udp_port_artnet);
#endif
}

/* The registration hand-off routing */

void
proto_reg_handoff_acn(void) {
  static int acn_initialized = FALSE;
  static dissector_handle_t acn_handle;

  ip_handle = find_dissector("ip");

  if(!acn_initialized) {
    acn_handle = create_dissector_handle(dissect_acn,proto_acn);
    acn_initialized = TRUE;
  } else {
    dissector_delete("udp.port",udp_port_acn,acn_handle);
  }

  udp_port_acn = global_udp_port_acn;
  
  dissector_add("udp.port",global_udp_port_acn,acn_handle);
}