aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-mint.c
blob: 6360369fe90751e122f426b3d5830792716e0edd (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
/* packet-mint.c
 * Routines for the disassembly of the Media Independent Network Transport
 * protocol used between wireless controllers and APs
 *
 * Copyright 2013 Joerg Mayer (see AUTHORS file)
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

/*
 * Extremenetworks/Zebra/Motorola/Symbol WLAN proprietary protocol
 * http://www.awimobility.com/s.nl/ctype.KB/it.I/id.7761/KB.81/.f
 * and
 * http://www.michaelfmcnamara.com/files/motorola/WiNG_5X_How_To_NOC.pdf
 * looks like a mixture of lwapp/capwap and is-is/ospf
 *
 * MLCP: MINT Link Creation Protocol
 */

/* We don't want the tranported data to pollute the output until
 * we know how to correctly determine the packet type and length
 */
#define MINT_DEVELOPMENT 1

#include "config.h"

#include <epan/packet.h>
#include <epan/exceptions.h>
#include <epan/etypes.h>
#include <epan/show_exception.h>

void proto_register_mint(void);
void proto_reg_handoff_mint(void);

#define PROTO_SHORT_NAME "MINT"
#define PROTO_LONG_NAME "Media Independent Network Transport"

/* 0x8783 ETHERTYPE_MINT */
/* Destmac: 01-a0-f8-00-00-00: Hello packets in multicast mode */
/* Mint overhead: 86 bytes */
/* 24576 = 0x6000 */
#define PORT_MINT_CONTROL_TUNNEL	24576
/* 24577 = 0x6001 */
#define PORT_MINT_DATA_TUNNEL		24577
#define PORT_MINT_RANGE			"24576-24577"
/* MLCP: VLAN or IP-based */

static dissector_handle_t eth_handle;

static int proto_mint = -1;

static int hf_mint_control = -1;
static int hf_mint_control_32zerobytes = -1;
static int hf_mint_control_unknown1 = -1;
static int hf_mint_data = -1;
static int hf_mint_data_seqno = -1;
static int hf_mint_data_unknown1 = -1;
static int hf_mint_data_vlan = -1;
static int hf_mint_ethshim = -1;
static int hf_mint_ethshim_length = -1;
static int hf_mint_ethshim_unknown = -1;
static int hf_mint_header = -1;
static int hf_mint_header_dstdataport = -1;
static int hf_mint_header_dstid = -1;
static int hf_mint_header_srcdataport = -1;
static int hf_mint_header_srcid = -1;
static int hf_mint_header_ttl = -1;
static int hf_mint_header_unknown1 = -1;
static int hf_mint_header_unknown2 = -1;
static int hf_mint_mlcp_length = -1;
static int hf_mint_mlcp_message = -1;
static int hf_mint_mlcp_type = -1;
static int hf_mint_mlcp_value = -1;
static int hf_mint_neighbor_unknown = -1;
static int hf_mint_router_array = -1;
static int hf_mint_router_element = -1;
static int hf_mint_router_header_length = -1;
static int hf_mint_router_header_sender = -1;
static int hf_mint_router_header_unknown = -1;
static int hf_mint_router_length = -1;
static int hf_mint_router_message_type = -1;
static int hf_mint_router_type_csnp = -1;
static int hf_mint_router_type_helo = -1;
static int hf_mint_router_type_lsp = -1;
static int hf_mint_router_type_psnp = -1;
static int hf_mint_router_type_unknown = -1;
static int hf_mint_router_unknown1 = -1;
static int hf_mint_router_unknown2 = -1;
static int hf_mint_router_unknown3 = -1;
static int hf_mint_router_value = -1;

/* ett handles */
static int ett_mint_ethshim = -1;
static int ett_mint = -1;
static int ett_mint_header = -1;
static int ett_mint_ctrl = -1;
static int ett_mint_data = -1;

static dissector_handle_t mint_control_handle;
static dissector_handle_t mint_data_handle;
static dissector_handle_t mint_eth_handle;

/* Output of "service show mint ports" on controller */

typedef enum {
	MINT_PORT_0			=   0,
	MINT_PORT_DATA			=   1,
	MINT_PORT_DATA_FLOOD		=   2,
	MINT_PORT_FDB_UPDATE		=   3,
	MINT_PORT_MDD			=   8,
	MINT_PORT_RIM			=   9,
	MINT_PORT_SMARTRF		=  10,
	MINT_PORT_CONFIG		=  11,
	MINT_PORT_ROUTER		=  12,
	MINT_PORT_REDUNDANCY		=  13,
	MINT_PORT_HOTSPOT		=  14,
	MINT_PORT_PING			=  15,
	MINT_PORT_STATS			=  16,
	MINT_PORT_JOIN			=  18,
	MINT_PORT_FILEXFR		=  19,
	MINT_PORT_SECURITY		=  20,
	MINT_PORT_BOOTSTRAP		=  21,
	MINT_PORT_XPATH			=  22,
	MINT_PORT_MCAST_RP		=  23,
	MINT_PORT_MCAST_CTRL		=  24,
	MINT_PORT_MCAST_DATA		=  25,
	MINT_PORT_RADPROXY		=  26,
	MINT_PORT_CLUSTER		=  27,
	MINT_PORT_MIGRATION		=  28,
	MINT_PORT_CLUSTER_SYNC		=  29,
	MINT_PORT_NEIGHBOR		=  30,
	MINT_PORT_GKEY			=  31,
	MINT_PORT_MARP			=  32,
	MINT_PORT_MPROXY		=  33,
	MINT_PORT_MLCP			=  34,
	MINT_PORT_TELNET		=  35,
	MINT_PORT_RDBG_REQ		=  36,
	MINT_PORT_RDBG_SRV0		=  37,
	MINT_PORT_RDBG_SRV1		=  38,
	MINT_PORT_RDBG_SRV2		=  39,
	MINT_PORT_RDBG_SRV3		=  40,
	MINT_PORT_RDBG_SRV4		=  41,
	MINT_PORT_RDBG_SRV5		=  42,
	MINT_PORT_RDBG_SRV6		=  43,
	MINT_PORT_RDBG_SRV7		=  44,
	MINT_PORT_TRACEROUTE		=  45,
	MINT_PORT_STATS_LISTEN		=  46,
	MINT_PORT_NOC_CONTROLLER	=  47,
	MINT_PORT_NOC_CLIENT		=  48,
	MINT_PORT_STATS_SERVER		=  49,
	MINT_PORT_EXTVLAN		=  50,
	MINT_PORT_RAD_DYNAMIC		=  51,
	MINT_PORT_RFD_CLIENT		=  52,
	MINT_PORT_RFD_SERVER		=  53,
	MINT_PORT_NOC_SERVER		=  54,
	MINT_PORT_NOC__CLIENT		=  55,
	MINT_PORT_CP_STATS_CLIENT	=  56,
	MINT_PORT_NX_URLINFO_SRVR	=  57,
	MINT_PORT_NX_URLINFO_PRXY	=  58,
	MINT_PORT_LDAP_PROXY		=  59,
	MINT_PORT_ANALYTICS		=  60,
	MINT_PORT_ADOPTION		=  61,
	MINT_PORT_CLUSTER_ADOPT		=  62,
	MINT_PORT_NOC_SITE		=  63,
	MINT_PORT_DAD			=  64,
	MINT_PORT_CCACHE		=  65,
	MINT_PORT_GLB_ASSOC_LIST	=  66,
	MINT_PORT_BONJOUR		= 131,
	MINT_PORT_DPD2_EXTIF		= 132,
	MINT_PORT_TROUBLE		= 133,
	MINT_PORT_URLF_CLASSIFIER	= 134,
	MINT_PORT_NF_PROXY		= 135,
	MINT_PORT_WING_EXPRESS		= 136,
	MINT_PORT_NSM_STAT_CLIENT	= 138,
	MINT_PORT_DPD2_STATS_CLIENT	= 140,
	MINT_PORT_BTIM_STATS_CLIENT	= 142
} mint_packettype_t;

static const value_string mint_port_vals[] = {
	{ MINT_PORT_0,			"0 port" },
	{ MINT_PORT_DATA,		"data/dgram" },
	{ MINT_PORT_DATA_FLOOD,		"data-flood/dgram" },
	{ MINT_PORT_FDB_UPDATE,		"fdb-update/dgram" },
	{ MINT_PORT_MDD,		"mdd/dgram" },
	{ MINT_PORT_RIM,		"rim/dgram" },
	{ MINT_PORT_SMARTRF,		"smartrf/seqpkt" },
	{ MINT_PORT_CONFIG,		"config/stream" },
	{ MINT_PORT_ROUTER,		"router/dgram" },
	{ MINT_PORT_REDUNDANCY,		"redundancy/seqpkt" },
	{ MINT_PORT_HOTSPOT,		"hotspot/seqpkt" },
	{ MINT_PORT_PING,		"ping/dgram" },
	{ MINT_PORT_STATS,		"stats/dgram" },
	{ MINT_PORT_JOIN,		"join/seqpkt" },
	{ MINT_PORT_FILEXFR,		"filexfr/stream" },
	{ MINT_PORT_SECURITY,		"security/seqpkt" },
	{ MINT_PORT_BOOTSTRAP,		"bootstrap/seqpkt" },
	{ MINT_PORT_XPATH,		"xpath/stream" },
	{ MINT_PORT_MCAST_RP,		"mcast-rp/dgram" },
	{ MINT_PORT_MCAST_CTRL,		"mcast-ctrl/seqpkt" },
	{ MINT_PORT_MCAST_DATA,		"mcast-data/seqpkt" },
	{ MINT_PORT_RADPROXY,		"radproxy/dgram" },
	{ MINT_PORT_CLUSTER,		"cluster/seqpkt" },
	{ MINT_PORT_MIGRATION,		"migration/stream" },
	{ MINT_PORT_CLUSTER_SYNC,	"cluster-sync/stream" },
	{ MINT_PORT_NEIGHBOR,		"neighbor/seqpkt" },
	{ MINT_PORT_GKEY,		"gkey/dgram" },
	{ MINT_PORT_MARP,		"marp/dgram" },
	{ MINT_PORT_MPROXY,		"mproxy/seqpkt" },
	{ MINT_PORT_MLCP,		"mlcp/dgram" },
	{ MINT_PORT_TELNET,		"telnet/stream" },
	{ MINT_PORT_RDBG_REQ,		"rdbg-req/seqpkt" },
	{ MINT_PORT_RDBG_SRV0,		"rdbg-srv0/seqpkt" },
	{ MINT_PORT_RDBG_SRV1,		"rdbg-srv1/seqpkt" },
	{ MINT_PORT_RDBG_SRV2,		"rdbg-srv2/seqpkt" },
	{ MINT_PORT_RDBG_SRV3,		"rdbg-srv3/seqpkt" },
	{ MINT_PORT_RDBG_SRV4,		"rdbg-srv4/seqpkt" },
	{ MINT_PORT_RDBG_SRV5,		"rdbg-srv5/seqpkt" },
	{ MINT_PORT_RDBG_SRV6,		"rdbg-srv6/seqpkt" },
	{ MINT_PORT_RDBG_SRV7,		"rdbg-srv7/seqpkt" },
	{ MINT_PORT_TRACEROUTE,		"traceroute/seqpkt" },
	{ MINT_PORT_STATS_LISTEN,	"stats-listen/seqpkt" },
	{ MINT_PORT_NOC_CONTROLLER,	"noc-controller/seqpkt" },
	{ MINT_PORT_NOC_CLIENT,		"noc-client/seqpkt" },
	{ MINT_PORT_STATS_SERVER,	"stats-server/seqpkt" },
	{ MINT_PORT_EXTVLAN,		"extvlan/dgram" },
	{ MINT_PORT_RAD_DYNAMIC,	"rad-dynamic/seqpkt" },
	{ MINT_PORT_RFD_CLIENT,		"rfd_client/stream" },
	{ MINT_PORT_RFD_SERVER,		"rfd_server/stream" },
	{ MINT_PORT_NOC_SERVER,		"noc_server/stream" },
	{ MINT_PORT_NOC__CLIENT,	"noc_client/stream" },
	{ MINT_PORT_CP_STATS_CLIENT,	"cp_stats_client/stream" },
	{ MINT_PORT_NX_URLINFO_SRVR,	"nx_urlinfo_srvr/dgram" },
	{ MINT_PORT_NX_URLINFO_PRXY,	"nx_urlinfo_prxy/dgram" },
	{ MINT_PORT_LDAP_PROXY,		"ldap_proxy/stream" },
	{ MINT_PORT_ANALYTICS,		"analytics/dgram" },
	{ MINT_PORT_ADOPTION,		"adoption/seqpkt" },
	{ MINT_PORT_CLUSTER_ADOPT,	"cluster-adopt/seqpkt" },
	{ MINT_PORT_NOC_SITE,		"noc-site/stream" },
	{ MINT_PORT_DAD,		"dad/stream" },
	{ MINT_PORT_CCACHE,		"ccache/dgram" },
	{ MINT_PORT_GLB_ASSOC_LIST,	"glb_assoc_list/dgram" },
	{ MINT_PORT_BONJOUR,		"bonjour/dgram" },
	{ MINT_PORT_DPD2_EXTIF,		"dpd2-extif/dgram" },
	{ MINT_PORT_TROUBLE,		"trouble/dgram" },
	{ MINT_PORT_URLF_CLASSIFIER,	"urlf_classifier/dgram" },
	{ MINT_PORT_NF_PROXY,		"nf-proxy/dgram" },
	{ MINT_PORT_WING_EXPRESS,	"wing_express/dgram" },
	{ MINT_PORT_NSM_STAT_CLIENT,	"nsm-stat-client/stream" },
	{ MINT_PORT_DPD2_STATS_CLIENT,	"dpd2-stats-client/stream" },
	{ MINT_PORT_BTIM_STATS_CLIENT,	"btim-stats-client/stream" },

	{ 0,    NULL }
};

static const value_string mint_router_csnp_tlv_vals[] = {

	{ 0,    NULL }
};

static const value_string mint_router_helo_tlv_vals[] = {
	{ 1,	"MINT ID" },
	{ 8,	"IPv4 address" },

	{ 0,    NULL }
};

static const value_string mint_router_lsp_tlv_vals[] = {
	{ 8,	"MINT ID" },

	{ 0,    NULL }
};

static const value_string mint_router_psnp_tlv_vals[] = {

	{ 0,    NULL }
};

static const value_string mint_0x22_tlv_vals[] = {

	{ 0,    NULL }
};

static int
dissect_eth_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mint_tree,
	volatile guint32 offset, guint32 length)
{
	tvbuff_t *eth_tvb;

#ifdef MINT_DEVELOPMENT
	col_set_writable(pinfo->cinfo, -1, FALSE);
#endif

	eth_tvb = tvb_new_subset_length(tvb, offset, length);
	/* Continue after Ethernet dissection errors */
	TRY {
		call_dissector(eth_handle, eth_tvb, pinfo, mint_tree);
	} CATCH_NONFATAL_ERRORS {
		show_exception(eth_tvb, pinfo, mint_tree, EXCEPT_CODE, GET_MESSAGE);
	} ENDTRY;
	offset += length;

#ifdef MINT_DEVELOPMENT
	col_set_writable(pinfo->cinfo, -1, TRUE);
#endif
	return offset;
}

static int
dissect_mint_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
	guint32 offset, guint32 packet_length, guint received_via)
{
	proto_item *ti;
	proto_tree *mint_tree = NULL;
	proto_tree *mint_header_tree = NULL;
	proto_tree *mint_data_tree = NULL;
	proto_tree *mint_ctrl_tree = NULL;
	guint16 bytes_remaining;
	guint16 mint_port;
	guint8 type, length, header_length;
	guint32 message_type;
	guint8 element_length;
	int hf_tlv_vals;

	mint_port = tvb_get_ntohs(tvb, offset + 12);

	col_set_str(pinfo->cinfo, COL_PROTOCOL, PROTO_SHORT_NAME);
	col_add_str(pinfo->cinfo, COL_INFO, val_to_str(mint_port,
		mint_port_vals, "Type %03d"));

	ti = proto_tree_add_item(tree, proto_mint, tvb,
		offset, packet_length, ENC_NA);
	mint_tree = proto_item_add_subtree(ti, ett_mint);

	ti = proto_tree_add_item(mint_tree, hf_mint_header, tvb,
		offset, 16, ENC_NA);
	mint_header_tree = proto_item_add_subtree(ti, ett_mint_header);

	/* MINT header */
	proto_tree_add_item(mint_header_tree, hf_mint_header_unknown1, tvb,
		offset, 1, ENC_NA);
	offset += 1;
	proto_tree_add_item(mint_header_tree, hf_mint_header_ttl, tvb,
		offset, 1, ENC_NA);
	offset += 1;
	proto_tree_add_item(mint_header_tree, hf_mint_header_unknown2, tvb,
		offset, 2, ENC_NA);
	offset += 2;
	proto_tree_add_item(mint_header_tree, hf_mint_header_dstid, tvb,
		offset, 4, ENC_NA);
	offset += 4;
	proto_tree_add_item(mint_header_tree, hf_mint_header_srcid, tvb,
		offset, 4, ENC_NA);
	offset += 4;
	proto_tree_add_item(mint_header_tree, hf_mint_header_dstdataport, tvb,
		offset, 2, ENC_BIG_ENDIAN);
	offset += 2;
	proto_tree_add_item(mint_header_tree, hf_mint_header_srcdataport, tvb,
		offset, 2, ENC_BIG_ENDIAN);
	offset += 2;
	/* FIXME: This is probably not the right way to determine the packet type.
	 *	  It's more likely something in mint_header_unknown1 but I haven't
	 *        found out what. */
	switch(mint_port) {
	case MINT_PORT_DATA:
		ti = proto_tree_add_item(mint_tree, hf_mint_data, tvb,
			offset, packet_length - 16, ENC_NA);
		mint_data_tree = proto_item_add_subtree(ti, ett_mint_data);
		proto_tree_add_item(mint_data_tree, hf_mint_data_unknown1, tvb,
			offset, 2, ENC_NA);
		offset += 2;
		/* Transported user frame */
		if (offset < packet_length)
			offset += dissect_eth_frame(tvb, pinfo, tree,
				offset, packet_length - offset);
		break;
	case MINT_PORT_DATA_FLOOD:
		ti = proto_tree_add_item(mint_tree, hf_mint_data, tvb,
			offset, packet_length - 16, ENC_NA);
		mint_data_tree = proto_item_add_subtree(ti, ett_mint_data);
		/* Decode as vlan only for now. To be verified against a capture
		 * with CoS != 0 */
		proto_tree_add_item(mint_data_tree, hf_mint_data_vlan, tvb,
			offset, 2, ENC_BIG_ENDIAN);
		offset += 2;
		proto_tree_add_item(mint_data_tree, hf_mint_data_seqno, tvb,
			offset, 4, ENC_NA);
		offset += 4;
		proto_tree_add_item(mint_data_tree, hf_mint_data_unknown1, tvb,
			offset, 4, ENC_NA);
		offset += 4;
		/* Transported user frame */
		if (offset < packet_length)
			offset += dissect_eth_frame(tvb, pinfo, tree,
				offset, packet_length - offset);
		break;
	case MINT_PORT_ROUTER:
		ti = proto_tree_add_item(mint_tree, hf_mint_control, tvb,
			offset, packet_length - 16, ENC_NA);
		mint_ctrl_tree = proto_item_add_subtree(ti, ett_mint_ctrl);
		proto_tree_add_item(mint_ctrl_tree, hf_mint_control_32zerobytes, tvb,
			offset, 32, ENC_NA);
		offset += 32;

		proto_tree_add_item(mint_ctrl_tree, hf_mint_router_unknown1, tvb,
			offset, 1, ENC_NA);
		offset += 1;
		proto_tree_add_item(mint_ctrl_tree, hf_mint_router_unknown2, tvb,
			offset, 1, ENC_NA);
		offset += 1;
		proto_tree_add_item(mint_ctrl_tree, hf_mint_router_unknown3, tvb,
			offset, 1, ENC_NA);
		offset += 1;
		header_length = tvb_get_guint8(tvb, offset);
		proto_tree_add_item(mint_ctrl_tree, hf_mint_router_header_length, tvb,
			offset, 1, ENC_NA);
		offset += 1;
		message_type = tvb_get_ntohl(tvb, offset);
		proto_tree_add_item(mint_ctrl_tree, hf_mint_router_message_type, tvb,
			offset, 4, ENC_ASCII);
		offset += 4;
		proto_tree_add_item(mint_ctrl_tree, hf_mint_router_header_sender, tvb,
			offset, 4, ENC_NA);
		offset += 4;
		switch (message_type) {
			case 0x43534E50: /* CSNP */
				element_length = 12;
				hf_tlv_vals = hf_mint_router_type_csnp;
				break;
			case 0x48454C4F: /* HELO */
				element_length = 0;
				hf_tlv_vals = hf_mint_router_type_helo;
				break;
			case 0x4C535000: /* LSP */
				element_length = 8;
				hf_tlv_vals = hf_mint_router_type_lsp;
				break;
			case 0x50534E50: /* PSNP */
				element_length = 4;
				hf_tlv_vals = hf_mint_router_type_psnp;
				break;
			default:
				element_length = 0;
				hf_tlv_vals = hf_mint_router_type_unknown;
		}
		/* FIXME: This should go into the per message_type switch above */
		if (header_length > 12) {
			proto_tree_add_item(mint_ctrl_tree, hf_mint_router_header_unknown, tvb,
				offset, header_length - 12, ENC_NA);
			offset += header_length - 12;
		}
		while (offset < packet_length - 2) {
			type = tvb_get_guint8(tvb, offset);
			proto_tree_add_item(mint_ctrl_tree, hf_tlv_vals, tvb,
				offset, 1, ENC_NA);
			offset += 1;
			length = tvb_get_guint8(tvb, offset);
			/* FIXME: This is a hack - reliable array detection missing */
			if (type == 1 && length == 128) {
				proto_tree_add_item(mint_ctrl_tree, hf_mint_router_array, tvb,
					offset, 1, ENC_NA);
				offset += 1;
				length = tvb_get_guint8(tvb, offset);
			}
			proto_tree_add_item(mint_ctrl_tree, hf_mint_router_length, tvb,
				offset, 1, ENC_NA);
			offset += 1;
			if (offset + length > packet_length) {
				/* FIXME: print expert information */
				break;
			}
			if (type == 1 && element_length) {
				guint32 end_offset = offset + length;
				for (; offset < end_offset; offset += element_length) {
					proto_tree_add_item(mint_ctrl_tree, hf_mint_router_element, tvb,
						offset, element_length, ENC_NA);
				}
			} else {
				proto_tree_add_item(mint_ctrl_tree, hf_mint_router_value, tvb,
					offset, length, ENC_NA);
				offset += length;
			}
		}
		break;
	case MINT_PORT_NEIGHBOR:
		ti = proto_tree_add_item(mint_tree, hf_mint_control, tvb,
			offset, packet_length - 16, ENC_NA);
		mint_ctrl_tree = proto_item_add_subtree(ti, ett_mint_ctrl);
		proto_tree_add_item(mint_ctrl_tree, hf_mint_control_32zerobytes, tvb,
			offset, 32, ENC_NA);
		offset += 32;
		bytes_remaining = packet_length - offset;
		proto_tree_add_item(mint_ctrl_tree, hf_mint_neighbor_unknown, tvb,
			offset, bytes_remaining, ENC_NA);
		offset += bytes_remaining;
		break;
	case MINT_PORT_MLCP:
		ti = proto_tree_add_item(mint_tree, hf_mint_control, tvb,
			offset, packet_length - 16, ENC_NA);
		mint_ctrl_tree = proto_item_add_subtree(ti, ett_mint_ctrl);
		proto_tree_add_item(mint_ctrl_tree, hf_mint_control_32zerobytes, tvb,
			offset, 32, ENC_NA);
		offset += 32;
		proto_tree_add_item(mint_ctrl_tree, hf_mint_mlcp_message, tvb,
			offset, 2, ENC_BIG_ENDIAN);
		offset += 2;
		while (offset < packet_length - 2) {
			proto_tree_add_item(mint_ctrl_tree, hf_mint_mlcp_type, tvb,
				offset, 1, ENC_NA);
			offset += 1;
			length = tvb_get_guint8(tvb, offset);
			proto_tree_add_item(mint_ctrl_tree, hf_mint_mlcp_length, tvb,
				offset, 1, ENC_NA);
			offset += 1;
			if (offset + length > packet_length) {
				/* print expert information */
				break;
			}
			proto_tree_add_item(mint_ctrl_tree, hf_mint_mlcp_value, tvb,
				offset, length, ENC_NA);
			offset += length;
		}
		break;
	default:
		bytes_remaining = packet_length - offset;
		switch(received_via) {
		case PORT_MINT_CONTROL_TUNNEL:
		case ETHERTYPE_MINT:
			proto_tree_add_item(mint_tree, hf_mint_control_unknown1, tvb,
				offset, bytes_remaining, ENC_NA);
			break;
		case PORT_MINT_DATA_TUNNEL:
			proto_tree_add_item(mint_tree, hf_mint_data_unknown1, tvb,
				offset, bytes_remaining, ENC_NA);
			break;
		default:
			DISSECTOR_ASSERT_NOT_REACHED();
		}
		offset += bytes_remaining;
		break;
	}
#if defined MINT_DEVELOPMENT
	tree_expanded_set(ett_mint, TRUE);
	tree_expanded_set(ett_mint_ethshim, TRUE);
	tree_expanded_set(ett_mint_header, TRUE);
	tree_expanded_set(ett_mint_ctrl, TRUE);
	tree_expanded_set(ett_mint_data, TRUE);
#endif
	return offset;
}

static int
dissect_mint_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	guint32 packet_length = tvb_captured_length(tvb);

	return dissect_mint_common(tvb, pinfo, tree, 0, packet_length,
		PORT_MINT_CONTROL_TUNNEL);
}

static int
dissect_mint_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	guint32 packet_length = tvb_captured_length(tvb);

	return dissect_mint_common(tvb, pinfo, tree, 0, packet_length,
		PORT_MINT_DATA_TUNNEL);
}

static int
dissect_mint_ethshim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	proto_item *ti;
	proto_tree *mint_ethshim_tree = NULL;
	guint32 offset = 0;
	guint32 packet_length;

	ti = proto_tree_add_item(tree, hf_mint_ethshim, tvb,
		offset, 4, ENC_NA);
	mint_ethshim_tree = proto_item_add_subtree(ti, ett_mint_ethshim);

	proto_tree_add_item(mint_ethshim_tree, hf_mint_ethshim_unknown, tvb,
		offset, 2, ENC_NA);
	offset += 2;
	proto_tree_add_item(mint_ethshim_tree, hf_mint_ethshim_length, tvb,
		offset, 2, ENC_BIG_ENDIAN);
	packet_length = tvb_get_ntohs(tvb, offset) + 4;
	offset += 2;

	offset += dissect_mint_common(tvb, pinfo, tree, 4, packet_length, ETHERTYPE_MINT);

	return offset;
}

static gboolean
test_mint_control(tvbuff_t *tvb _U_)
{
#if 0
	/* Minimum of 8 bytes, first byte (version) has value of 3 */
	if ( tvb_length(tvb) < 8
		    || tvb_get_guint8(tvb, 0) != 3
		    /* || tvb_get_guint8(tvb, 2) != 0
		    || tvb_get_ntohs(tvb, 6) > tvb_reported_length(tvb) */
	) {
		return FALSE;
	}
#endif
	return TRUE;
}

static gboolean
test_mint_data(tvbuff_t *tvb _U_)
{
#if 0
	/* Minimum of 8 bytes, first byte (version) has value of 3 */
	if ( tvb_length(tvb) < 8
		    || tvb_get_guint8(tvb, 0) != 3
		    /* || tvb_get_guint8(tvb, 2) != 0
		    || tvb_get_ntohs(tvb, 6) > tvb_reported_length(tvb) */
	) {
		return FALSE;
	}
#endif
	return TRUE;
}

static gboolean
test_mint_eth(tvbuff_t *tvb _U_)
{
#if 0
	/* Minimum of 8 bytes, first byte (version) has value of 3 */
	if ( tvb_length(tvb) < 8
		    || tvb_get_guint8(tvb, 0) != 3
		    /* || tvb_get_guint8(tvb, 2) != 0
		    || tvb_get_ntohs(tvb, 6) > tvb_reported_length(tvb) */
	) {
		return FALSE;
	}
#endif
	return TRUE;
}

static int
dissect_mint_control_static(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
	if ( !test_mint_control(tvb) ) {
		return 0;
	}
	return dissect_mint_control(tvb, pinfo, tree);
}

static int
dissect_mint_data_static(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
	if ( !test_mint_data(tvb) ) {
		return 0;
	}
	return dissect_mint_data(tvb, pinfo, tree);
}

static int
dissect_mint_ethshim_static(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
	if ( !test_mint_eth(tvb) ) {
		return 0;
	}
	return dissect_mint_ethshim(tvb, pinfo, tree);
}

void
proto_register_mint(void)
{
	static hf_register_info hf[] = {
		{ &hf_mint_ethshim,
			{ "MINT Ethernet Shim", "mint.ethshim",
			  FT_PROTOCOL, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_ethshim_unknown,
			{ "Unknown", "mint.ethshim.unknown",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_ethshim_length,
			{ "Length", "mint.ethshim.length",
			  FT_UINT16, BASE_DEC, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_header,
			{ "Header", "mint.header",
			  FT_PROTOCOL, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_header_unknown1,
			{ "HdrUnk1", "mint.header.unknown1",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_header_ttl,
			{ "TTL", "mint.header.ttl",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_header_unknown2,
			{ "HdrUnk2", "mint.header.unknown2",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_header_srcid,
			{ "Src MINT ID", "mint.header.srcid",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_header_dstid,
			{ "Dst MINT ID", "mint.header.dstid",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_header_srcdataport,
			{ "Src port", "mint.header.srcport",
			  FT_UINT16, BASE_DEC, VALS(mint_port_vals), 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_header_dstdataport,
			{ "Dst port", "mint.header.dstport",
			  FT_UINT16, BASE_DEC, VALS(mint_port_vals), 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_data,
			{ "Data Frame", "mint.data",
			  FT_PROTOCOL, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_data_vlan,
			{ "Data VLAN", "mint.data.vlan",
			  FT_UINT16, BASE_DEC, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_data_seqno,
			{ "Sequence Number", "mint.data.seqno",
			  FT_UINT32, BASE_DEC, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_data_unknown1,
			{ "DataUnk1", "mint.data.unknown1",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_control,
			{ "Control Frame", "mint.control",
			  FT_PROTOCOL, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_control_32zerobytes,
			{ "Zero Bytes", "mint.control.32zerobytes",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_control_unknown1,
			{ "CtrlUnk1", "mint.control.unknown1",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_unknown1,
			{ "Unknown1", "mint.control.router.unknown1",
			  FT_UINT8, BASE_HEX, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_unknown2,
			{ "Unknown2", "mint.control.router.unknown2",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_unknown3,
			{ "Unknown3", "mint.control.router.unknown3",
			  FT_UINT8, BASE_HEX, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_header_length,
			{ "Headerlength", "mint.control.router.header.length",
			  FT_UINT8, BASE_HEX, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_message_type,
			{ "Message type", "mint.control.router.message.type",
			  FT_STRING, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_header_sender,
			{ "Sender ID", "mint.control.router.header.sender",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_header_unknown,
			{ "Header unknown", "mint.control.router.header.unknown",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_type_unknown,
			{ "TLV Type", "mint.control.router.tlvtype",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_type_csnp,
			{ "TLV Type", "mint.control.router.tlvtype",
			  FT_UINT8, BASE_DEC, VALS(mint_router_csnp_tlv_vals), 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_type_helo,
			{ "TLV Type", "mint.control.router.tlvtype",
			  FT_UINT8, BASE_DEC, VALS(mint_router_helo_tlv_vals), 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_type_lsp,
			{ "TLV Type", "mint.control.router.tlvtype",
			  FT_UINT8, BASE_DEC, VALS(mint_router_lsp_tlv_vals), 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_type_psnp,
			{ "TLV Type", "mint.control.router.tlvtype",
			  FT_UINT8, BASE_DEC, VALS(mint_router_psnp_tlv_vals), 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_length,
			{ "TLV Length", "mint.control.router.tlvlength",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_array,
			{ "Array indicator", "mint.control.router.array",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_element,
			{ "Array element", "mint.control.router.element",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_router_value,
			{ "TLV Value", "mint.control.router.tlvvalue",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_neighbor_unknown,
			{ "Unknown", "mint.control.neighbor.unknown",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_mlcp_message,
			{ "Message", "mint.control.mlcp.message",
			  FT_UINT16, BASE_HEX, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_mlcp_type,
			{ "TLV Type", "mint.control.mlcp.tlvtype",
			  FT_UINT8, BASE_DEC, VALS(mint_0x22_tlv_vals), 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_mlcp_length,
			{ "TLV Length", "mint.control.mlcp.tlvlength",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL }
		},
		{ &hf_mint_mlcp_value,
			{ "TLV Value", "mint.control.mlcp.tlvvalue",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL }
		},
	};

	static gint *ett[] = {
		&ett_mint_ethshim,
		&ett_mint,
		&ett_mint_header,
		&ett_mint_ctrl,
		&ett_mint_data,
	};

	proto_mint = proto_register_protocol(PROTO_LONG_NAME, PROTO_SHORT_NAME, "mint");
	/* Created to remove Decode As confusion */
	int proto_mint_data = proto_register_protocol_in_name_only("Media Independent Network Transport Data", "MINT (Data)", "mint_data", proto_mint, FT_PROTOCOL);

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

	mint_control_handle = create_dissector_handle(dissect_mint_control_static, proto_mint);
	mint_data_handle = create_dissector_handle(dissect_mint_data_static, proto_mint_data);
	mint_eth_handle = create_dissector_handle(dissect_mint_ethshim_static, proto_mint);
}

void
proto_reg_handoff_mint(void)
{
	dissector_add_uint_range_with_preference("udp.port", PORT_MINT_RANGE, mint_control_handle);
	dissector_add_uint("ethertype", ETHERTYPE_MINT, mint_eth_handle);

	eth_handle = find_dissector_add_dependency("eth_withoutfcs", proto_mint);
}

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