aboutsummaryrefslogtreecommitdiffstats
path: root/packet-mtp3mg.c
blob: eeb8b2cfe319cd4f3d39ff3852d9d5e7b9758044 (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
/* packet-mtp3mg.c
 * Routines for Message Transfer Part Level 3 Management and Test dissection
 *
 * It is (hopefully) compliant to:
 *   ANSI T1.111.4-1996
 *   ITU-T Q.704 7/1996
 *   ITU-T Q.707 7/1996 and ANSI T1.111.7-1996 (for SLT message formats)
 *   portions of ITU-T Q.2210 7/1996 (for XCO/XCA message formats)
 *   GF 001-9001 (Chinese ITU variant)
 *
 * Copyright 2003, Jeff Morriss <jeff.morriss[AT]ulticom.com>
 *
 * $Id: packet-mtp3mg.c,v 1.11 2003/12/06 19:14:30 jmayer Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-mtp3.c
 *
 * 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.
 */

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

#include <glib.h>

#ifdef NEED_SNPRINTF_H
#include "snprintf.h"
#endif

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

#include <packet-mtp3.h>

/* MTP3 Service Indicators used by this dissector */
#define MTP3MG_SI 0
#define MTP3MG_ITU_TEST_SI 1
#define MTP3MG_ANSI_TEST_SI 2

#define H0H1_LENGTH 1
#define H0_MASK     0x0f
#define H1_MASK     0xf0
#define H1_SHIFT    4

#define H0_CHM 0x01
#define H0_ECM 0x02
#define H0_FCM 0x03
#define H0_TFM 0x04
#define H0_RSM 0x05
#define H0_MIM 0x06
#define H0_TRM 0x07
#define H0_DLM 0x08
#define H0_UFC 0x0a
static const value_string h0_message_type_values[] = {
  { H0_CHM, "Changeover and changeback messages" },
  { H0_ECM, "Emergency changeover messages" },
  { H0_FCM, "Transfer-controlled and signalling route set congestion messages" },
  { H0_TFM, "Transfer prohibited-allowed-restricted messages" },
  { H0_RSM, "Signalling-route-set-test messages" },
  { H0_MIM, "Management inhibit messages" },
  { H0_TRM, "Traffic restart messages" },
  { H0_DLM, "Signalling-data-link-connection messages" },
  { H0_UFC, "User part flow control messages" },
  { 0,      NULL } };

#define TEST_H0_SLT 0x1
static const value_string test_h0_message_type_values[] = {
  { TEST_H0_SLT, "Test messages" },
  { 0,           NULL } };

#define CHM_H1_COO 0x01
#define CHM_H1_COA 0x02
#define CHM_H1_XCO 0x03
#define CHM_H1_XCA 0x04
#define CHM_H1_CBD 0x05
#define CHM_H1_CBA 0x06
static const value_string chm_h1_message_type_values[] = {
  { CHM_H1_COO, "Changeover-order signal" },
  { CHM_H1_COA, "Changeover-ack signal" },
  { CHM_H1_XCO, "Extended changeover-order signal" },
  { CHM_H1_XCA, "Extended changeover-ack signal" },
  { CHM_H1_CBD, "Changeback-declaration signal" },
  { CHM_H1_CBA, "Changeback-ack signal" },
  { 0,          NULL } };

/* Same as above but in acronym form (for the Info column) */
static const value_string chm_h1_message_type_acro_values[] = {
  { CHM_H1_COO, "COO" },
  { CHM_H1_COA, "COA" },
  { CHM_H1_XCO, "XCO" },
  { CHM_H1_XCA, "XCA" },
  { CHM_H1_CBD, "CBD" },
  { CHM_H1_CBA, "CBA" },
  { 0,          NULL } };

#define ECM_H1_ECO 0x01
#define ECM_H1_ECA 0x02
static const value_string ecm_h1_message_type_values[] = {
  { ECM_H1_ECO, "Emergency-changeover-order signal" },
  { ECM_H1_ECA, "Emergency-changeover-ack signal" },
  { 0,          NULL } };

/* Same as above but in acronym form (for the Info column) */
static const value_string ecm_h1_message_type_acro_values[] = {
  { ECM_H1_ECO, "ECO" },
  { ECM_H1_ECA, "ECA" },
  { 0,          NULL } };

#define FCM_H1_RCT 0x01
#define FCM_H1_TFC 0x02
static const value_string fcm_h1_message_type_values[] = {
  { FCM_H1_RCT, "Signalling-route-set-congestion-test signal" },
  { FCM_H1_TFC, "Transfer-controlled signal" },
  { 0,          NULL } };

/* Same as above but in acronym form (for the Info column) */
static const value_string fcm_h1_message_type_acro_values[] = {
  { FCM_H1_RCT, "RCT" },
  { FCM_H1_TFC, "TFC" },
  { 0,          NULL } };

#define TFM_H1_TFP 0x01
#define TFM_H1_TCP 0x02 /* ANSI only */
#define TFM_H1_TFR 0x03
#define TFM_H1_TCR 0x04 /* ANSI only */
#define TFM_H1_TFA 0x05
#define TFM_H1_TCA 0x06 /* ANSI only */
static const value_string tfm_h1_message_type_values[] = {
  { TFM_H1_TFP, "Transfer-prohibited signal" },
  { TFM_H1_TCP, "Transfer-cluster-prohibited signal (ANSI only)" },
  { TFM_H1_TFR, "Transfer-restricted signal" },
  { TFM_H1_TCR, "Transfer-cluster-restricted signal (ANSI only)" },
  { TFM_H1_TFA, "Transfer-allowed signal" },
  { TFM_H1_TCA, "Transfer-cluster-allowed signal (ANSI only)" },
  { 0,          NULL } };

/* Same as above but in acronym form (for the Info column) */
static const value_string tfm_h1_message_type_acro_values[] = {
  { TFM_H1_TFP, "TFP" },
  { TFM_H1_TCP, "TCP" },
  { TFM_H1_TFR, "TFR" },
  { TFM_H1_TCR, "TCR" },
  { TFM_H1_TFA, "TFA" },
  { TFM_H1_TCA, "TCA" },
  { 0,          NULL } };

#define RSM_H1_RST 0x01
#define RSM_H1_RSR 0x02
#define RSM_H1_RCP 0x03 /* ANSI only */
#define RSM_H1_RCR 0x04 /* ANSI only */
static const value_string rsm_h1_message_type_values[] = {
  { RSM_H1_RST, "Signalling-route-set-test prohibited signal" },
  { RSM_H1_RSR, "Signalling-route-set-test restricted signal" },
  { RSM_H1_RCP, "Signalling-route-set-test cluster-prohibited signal (ANSI only)" },
  { RSM_H1_RCR, "Signalling-route-set-test cluster-restricted signal (ANSI only)" },
  { 0,          NULL } };

/* Same as above but in acronym form (for the Info column) */
static const value_string rsm_h1_message_type_acro_values[] = {
  { RSM_H1_RST, "RST" },
  { RSM_H1_RSR, "RSR" },
  { RSM_H1_RCP, "RCP" },
  { RSM_H1_RCR, "RCR" },
  { 0,          NULL } };

#define MIM_H1_LIN 0x01
#define MIM_H1_LUN 0x02
#define MIM_H1_LIA 0x03
#define MIM_H1_LUA 0x04
#define MIM_H1_LID 0x05
#define MIM_H1_LFU 0x06
#define MIM_H1_LLT 0x07 /* LLI in ANSI */
#define MIM_H1_LRT 0x08 /* LRI in ANSI */
static const value_string mim_h1_message_type_values[] = {
  { MIM_H1_LIN, "Link inhibit signal" },
  { MIM_H1_LUN, "Link uninhibit signal" },
  { MIM_H1_LIA, "Link inhibit ack signal" },
  { MIM_H1_LUA, "Link uninhibit ack signal" },
  { MIM_H1_LID, "Link inhibit denied signal" },
  { MIM_H1_LFU, "Link forced uninhibit signal" },
  { MIM_H1_LLT, "Link local inhibit test signal" },
  { MIM_H1_LRT, "Link remote inhibit test signal" },
  { 0,          NULL } };

/* Same as above but in acronym form (for the Info column) */
static const value_string mim_h1_message_type_acro_values[] = {
  { MIM_H1_LIN, "LIN" },
  { MIM_H1_LUN, "LUN" },
  { MIM_H1_LIA, "LIA" },
  { MIM_H1_LUA, "LUA" },
  { MIM_H1_LID, "LID" },
  { MIM_H1_LFU, "LFU" },
  { MIM_H1_LLT, "LLT (LLI)" },
  { MIM_H1_LRT, "LRT (LRI)" },
  { 0,          NULL } };

#define TRM_H1_TRA 0x01
#define TRM_H1_TRW 0x02 /* ANSI only */
static const value_string trm_h1_message_type_values[] = {
  { TRM_H1_TRA, "Traffic-restart-allowed signal" },
  { TRM_H1_TRW, "Traffic-restart-waiting signal (ANSI only)" },
  { 0,          NULL } };

/* Same as above but in acronym form (for the Info column) */
static const value_string trm_h1_message_type_acro_values[] = {
  { TRM_H1_TRA, "TRA" },
  { TRM_H1_TRW, "TRW" },
  { 0,          NULL } };

#define DLM_H1_DLC 0x01
#define DLM_H1_CSS 0x02
#define DLM_H1_CNS 0x03
#define DLM_H1_CNP 0x04
static const value_string dlm_h1_message_type_values[] = {
  { DLM_H1_DLC, "Signalling-data-link-connection-order signal" },
  { DLM_H1_CSS, "Connection-successful signal" },
  { DLM_H1_CNS, "Connection-not-successful signal" },
  { DLM_H1_CNP, "Connection-not-possible signal" },
  { 0,          NULL } };

/* Same as above but in acronym form (for the Info column) */
static const value_string dlm_h1_message_type_acro_values[] = {
  { DLM_H1_DLC, "DLC" },
  { DLM_H1_CSS, "CSS" },
  { DLM_H1_CNS, "CNS" },
  { DLM_H1_CNP, "CNP" },
  { 0,          NULL } };

#define UFC_H1_UPU 0x01
static const value_string ufc_h1_message_type_values[] = {
  { UFC_H1_UPU, "User part unavailable signal" },
  { 0,          NULL } };

/* Same as above but in acronym form (for the Info column) */
static const value_string ufc_h1_message_type_acro_values[] = {
  { UFC_H1_UPU, "UPU" },
  { 0,          NULL } };

static const value_string upu_cause_values[] = {
  { 0x0, "Unknown" },
  { 0x1, "Unequipped remote user" },
  { 0x2, "Inaccessible remote user" },
  { 0,   NULL } };

#define TEST_H1_SLTM 0x1
#define TEST_H1_SLTA 0x2
static const value_string test_h1_message_type_values[] = {
  { TEST_H1_SLTM, "Signalling link test message" },
  { TEST_H1_SLTA, "Signalling link test acknowledgement message" },
  { 0,            NULL } };

/* Same as above but in acronym form (for the Info column) */
static const value_string test_h1_message_type_acro_values[] = {
  { TEST_H1_SLTM, "SLTM" },
  { TEST_H1_SLTA, "SLTA" },
  { 0,            NULL } };


#define COO_LENGTH         2
#define ANSI_COO_SLC_MASK  0x000f
#define ANSI_COO_FSN_MASK  0x07f0
#define ITU_COO_FSN_MASK   0x007f
#define ANSI_XCO_LENGTH    4
#define ANSI_XCO_SLC_MASK  0x0000000f
#define ANSI_XCO_FSN_MASK  0x0ffffff0
#define ITU_XCO_LENGTH     3
#define ANSI_CBD_LENGTH    2
#define ANSI_CBD_SLC_MASK  0x000f
#define ANSI_CBD_CBC_MASK  0x0ff0
#define ITU_CBD_LENGTH     1

#define ANSI_ECO_LENGTH   1
#define ANSI_ECO_SLC_MASK 0x0f

#define ANSI_TFC_STATUS_LENGTH 1
#define ANSI_TFC_STATUS_OFFSET ANSI_PC_LENGTH
#define ANSI_TFC_STATUS_MASK   0x03
#define ITU_TFC_STATUS_LENGTH  ITU_PC_LENGTH
#define ITU_TFC_STATUS_MASK    0xc000

#define ANSI_MIM_LENGTH   1
#define ANSI_MIM_SLC_MASK 0x0f

#define ANSI_DLC_LENGTH    3
#define ANSI_DLC_SLC_MASK  0x0000f
#define ANSI_DLC_LINK_MASK 0x3fff0
#define ITU_DLC_LENGTH     2
#define ITU_DLC_LINK_MASK  0x0fff

#define ANSI_UPU_USER_OFFSET ANSI_PC_LENGTH
#define UPU_USER_LENGTH      1
#define UPU_USER_MASK        0x0f
#define UPU_CAUSE_MASK       0xf0
#define ITU_UPU_USER_OFFSET  ITU_PC_LENGTH

#define TEST_LENGTH         1
#define TEST_LENGTH_MASK    0xf0
#define TEST_LENGTH_SHIFT   4
#define TEST_PATTERN_OFFSET TEST_LENGTH

/* This list is slightly different from that in packet-mtp3.c */
static const value_string service_indicator_code_vals[] = {
	{ 0x0,	"Spare" },
	{ 0x1,	"Spare"},
	{ 0x2,	"Spare" },
	{ 0x3,	"SCCP" },
	{ 0x4,	"TUP" },
	{ 0x5,	"ISUP" },
	{ 0x6,	"DUP (call and circuit related messages)" },
	{ 0x7,	"DUP (facility registration and cancellation message)" },
	{ 0x8,	"MTP testing user part" },
	{ 0x9,	"Spare" },
	{ 0xa,	"Spare" },
	{ 0xb,	"Spare" },
	{ 0xc,	"Spare" },
	{ 0xd,	"Spare" },
	{ 0xe,	"Spare" },
	{ 0xf,	"Spare" },
	{ 0,	NULL }
};

/* Initialize the protocol and registered fields */
static int proto_mtp3mg  = -1;
static int hf_mtp3mg_h0 = -1;
static int hf_mtp3mg_chm_h1 = -1;
static int hf_mtp3mg_ecm_h1 = -1;
static int hf_mtp3mg_fcm_h1 = -1;
static int hf_mtp3mg_tfm_h1 = -1;
static int hf_mtp3mg_rsm_h1 = -1;
static int hf_mtp3mg_mim_h1 = -1;
static int hf_mtp3mg_trm_h1 = -1;
static int hf_mtp3mg_dlm_h1 = -1;
static int hf_mtp3mg_ufc_h1 = -1;
static int hf_mtp3mg_coo_ansi_slc = -1;
static int hf_mtp3mg_coo_ansi_fsn = -1;
static int hf_mtp3mg_coo_itu_fsn = -1;
static int hf_mtp3mg_xco_ansi_slc = -1;
static int hf_mtp3mg_xco_ansi_fsn = -1;
static int hf_mtp3mg_xco_itu_fsn = -1;
static int hf_mtp3mg_cbd_ansi_slc = -1;
static int hf_mtp3mg_cbd_ansi_cbc = -1;
static int hf_mtp3mg_cbd_itu_cbc = -1;
static int hf_mtp3mg_eco_ansi_slc = -1;
static int hf_mtp3mg_tfc_ansi_apc = -1;
static int hf_mtp3mg_tfc_apc_member = -1;
static int hf_mtp3mg_tfc_apc_cluster = -1;
static int hf_mtp3mg_tfc_apc_network = -1;
static int hf_mtp3mg_tfc_ansi_status = -1;
static int hf_mtp3mg_tfc_itu_apc = -1;
static int hf_mtp3mg_tfc_itu_status = -1;
static int hf_mtp3mg_tfc_chinese_apc = -1;
static int hf_mtp3mg_tfm_ansi_apc = -1;
static int hf_mtp3mg_tfm_apc_member = -1;
static int hf_mtp3mg_tfm_apc_cluster = -1;
static int hf_mtp3mg_tfm_apc_network = -1;
static int hf_mtp3mg_tfm_itu_apc = -1;
static int hf_mtp3mg_tfm_chinese_apc = -1;
static int hf_mtp3mg_rsm_ansi_apc = -1;
static int hf_mtp3mg_rsm_apc_member = -1;
static int hf_mtp3mg_rsm_apc_cluster = -1;
static int hf_mtp3mg_rsm_apc_network = -1;
static int hf_mtp3mg_rsm_itu_apc = -1;
static int hf_mtp3mg_rsm_chinese_apc = -1;
static int hf_mtp3mg_mim_ansi_slc = -1;
static int hf_mtp3mg_dlc_ansi_slc = -1;
static int hf_mtp3mg_dlc_ansi_link = -1;
static int hf_mtp3mg_dlc_itu_link = -1;
static int hf_mtp3mg_upu_ansi_apc = -1;
static int hf_mtp3mg_upu_apc_member = -1;
static int hf_mtp3mg_upu_apc_cluster = -1;
static int hf_mtp3mg_upu_apc_network = -1;
static int hf_mtp3mg_upu_itu_apc = -1;
static int hf_mtp3mg_upu_chinese_apc = -1;
static int hf_mtp3mg_upu_user = -1;
static int hf_mtp3mg_upu_cause = -1;
static int hf_mtp3test_h0 = -1;
static int hf_mtp3mg_test_h1 = -1;
static int hf_mtp3mg_test_length = -1;

/* Initialize the subtree pointers */
static gint ett_mtp3mg = -1;
static gint ett_mtp3mg_fcm_apc = -1;
static gint ett_mtp3mg_tfm_apc = -1;
static gint ett_mtp3mg_rsm_apc = -1;
static gint ett_mtp3mg_upu_apc = -1;

static void
dissect_mtp3mg_unknown_message(tvbuff_t *tvb, proto_tree *tree)
{
    guint8 message_length;

    message_length = tvb_length_remaining(tvb, 0);
    proto_tree_add_text(tree, tvb, 0, message_length,
			"Unknown message (%u byte%s)", message_length,
			plurality(message_length, "", "s"));
}

static void
dissect_mtp3mg_chm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		   guint8 h1)
{
    if (check_col(pinfo->cinfo, COL_INFO))
	col_add_fstr(pinfo->cinfo, COL_INFO, "%s ",
		     val_to_str(h1, chm_h1_message_type_acro_values, "Unknown"));
	
    switch (h1)
    {
    case CHM_H1_COO:
    case CHM_H1_COA:
	if (mtp3_standard == ANSI_STANDARD)
	{
	    proto_tree_add_item(tree, hf_mtp3mg_coo_ansi_slc, tvb, 0,
				COO_LENGTH, TRUE);
	    proto_tree_add_item(tree, hf_mtp3mg_coo_ansi_fsn, tvb, 0,
				COO_LENGTH, TRUE);
	} else /* ITU_STANDARD and CHINESE_ITU_STANDARD */ {
	    proto_tree_add_item(tree, hf_mtp3mg_coo_itu_fsn, tvb, 0,
				COO_LENGTH, TRUE);
	}
	break;

    case CHM_H1_XCO:
    case CHM_H1_XCA:
	if (mtp3_standard == ANSI_STANDARD)
	{
	    proto_tree_add_item(tree, hf_mtp3mg_xco_ansi_slc, tvb, 0,
				ANSI_XCO_LENGTH, TRUE);
	    proto_tree_add_item(tree, hf_mtp3mg_xco_ansi_fsn, tvb, 0,
				ANSI_XCO_LENGTH, TRUE);
	} else /* ITU_STANDARD and CHINESE_ITU_STANDARD */ {
	    proto_tree_add_item(tree, hf_mtp3mg_xco_itu_fsn, tvb, 0,
				ITU_XCO_LENGTH, TRUE);
	}
	break;

    case CHM_H1_CBD:
    case CHM_H1_CBA:
	if (mtp3_standard == ANSI_STANDARD)
	{
	    proto_tree_add_item(tree, hf_mtp3mg_cbd_ansi_slc, tvb, 0,
				ANSI_CBD_LENGTH, TRUE);
	    proto_tree_add_item(tree, hf_mtp3mg_cbd_ansi_cbc, tvb, 0,
				ANSI_CBD_LENGTH, TRUE);
	} else /* ITU_STANDARD and CHINESE_ITU_STANDARD */ {
	    proto_tree_add_item(tree, hf_mtp3mg_cbd_itu_cbc, tvb, 0,
				ITU_CBD_LENGTH, TRUE);
	}
	break;

    default:
	dissect_mtp3mg_unknown_message(tvb, tree);
  }
}

static void
dissect_mtp3mg_ecm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		   guint8 h1)
{
    if (check_col(pinfo->cinfo, COL_INFO))
	col_add_fstr(pinfo->cinfo, COL_INFO, "%s ",
		     val_to_str(h1, ecm_h1_message_type_acro_values, "Unknown"));

    switch (h1)
    {
    case ECM_H1_ECO:
    case ECM_H1_ECA:
	if (mtp3_standard == ANSI_STANDARD)
	{
	    proto_tree_add_item(tree, hf_mtp3mg_eco_ansi_slc, tvb, 0,
				ANSI_ECO_LENGTH, TRUE);
	}
	/* else: nothing to dissect */
	break;

    default:
	dissect_mtp3mg_unknown_message(tvb, tree);
    }
}

static void
dissect_mtp3mg_3byte_pc(tvbuff_t *tvb, proto_tree *tree, gint *ett_pc,
			int *hf_pc, int *hf_pc_member, int *hf_pc_cluster,
			int *hf_pc_network)
{
    guint32 apc;
    proto_item *apc_item;
    proto_tree *apc_tree;
    char pc[ANSI_PC_STRING_LENGTH];

    apc = tvb_get_ntoh24(tvb, 0);

    snprintf(pc, sizeof(pc), "%d-%d-%d",
	     (apc & ANSI_NETWORK_MASK),
	     ((apc & ANSI_CLUSTER_MASK) >> 8),
	     ((apc & ANSI_MEMBER_MASK) >> 16));

    apc_item = proto_tree_add_string_format(tree, *hf_pc, tvb, 0,
					    ANSI_PC_LENGTH, pc,
					    "Affected PC (%s)", pc);

    apc_tree = proto_item_add_subtree(apc_item, *ett_pc);

    proto_tree_add_uint(apc_tree, *hf_pc_member, tvb,
			ANSI_MEMBER_OFFSET, ANSI_NCM_LENGTH, apc);
    proto_tree_add_uint(apc_tree, *hf_pc_cluster, tvb,
			ANSI_CLUSTER_OFFSET, ANSI_NCM_LENGTH, apc);
    proto_tree_add_uint(apc_tree, *hf_pc_network, tvb,
			ANSI_NETWORK_OFFSET, ANSI_NCM_LENGTH, apc);

}

static void
dissect_mtp3mg_fcm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		   guint8 h1)
{
    if (check_col(pinfo->cinfo, COL_INFO))
	col_add_fstr(pinfo->cinfo, COL_INFO, "%s ",
		     val_to_str(h1, fcm_h1_message_type_acro_values, "Unknown"));

    switch (h1)
    {
    case FCM_H1_RCT:
	/* nothing to dissect */
	break;

    case FCM_H1_TFC:
	if (mtp3_standard == ITU_STANDARD) {

	    proto_tree_add_item(tree, hf_mtp3mg_tfc_itu_apc, tvb, 0,
				ITU_PC_LENGTH, TRUE);

	    /* Congestion level is a national option */
	    proto_tree_add_item(tree, hf_mtp3mg_tfc_itu_status, tvb, 0,
				ITU_TFC_STATUS_LENGTH, TRUE);



	} else /* ANSI_STANDARD and CHINESE_ITU_STANDARD */ {

	    int *hf_apc_string;

	    if (mtp3_standard == ANSI_STANDARD) {

		hf_apc_string = &hf_mtp3mg_tfc_ansi_apc;

	    } else /* CHINESE_ITU_STANDARD */ {

		hf_apc_string = &hf_mtp3mg_tfc_chinese_apc;
	    }

	    dissect_mtp3mg_3byte_pc(tvb, tree, &ett_mtp3mg_fcm_apc,
				    hf_apc_string,
				    &hf_mtp3mg_tfc_apc_member,
				    &hf_mtp3mg_tfc_apc_cluster,
				    &hf_mtp3mg_tfc_apc_network);

	    proto_tree_add_item(tree, hf_mtp3mg_tfc_ansi_status, tvb,
				ANSI_TFC_STATUS_OFFSET, ANSI_TFC_STATUS_LENGTH,
				TRUE);

	}
	break;

    default:
	dissect_mtp3mg_unknown_message(tvb, tree);
    }
}

static void
dissect_mtp3mg_tfm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		   guint8 h1)
{
    if (check_col(pinfo->cinfo, COL_INFO))
	col_add_fstr(pinfo->cinfo, COL_INFO, "%s ",
		     val_to_str(h1, tfm_h1_message_type_acro_values, "Unknown"));

    switch (h1)
    {
    case TFM_H1_TFP:
    case TFM_H1_TCP:
    case TFM_H1_TFR:
    case TFM_H1_TCR:
    case TFM_H1_TFA:
    case TFM_H1_TCA:
	if (mtp3_standard == ANSI_STANDARD)
	{
	    dissect_mtp3mg_3byte_pc(tvb, tree, &ett_mtp3mg_tfm_apc,
				    &hf_mtp3mg_tfm_ansi_apc,
				    &hf_mtp3mg_tfm_apc_member,
				    &hf_mtp3mg_tfm_apc_cluster,
				    &hf_mtp3mg_tfm_apc_network);

	} else /* ITU_STANDARD and CHINESE_ITU_STANDARD */ {

	    if (h1 == TFM_H1_TCP || h1 == TFM_H1_TCR || h1 == TFM_H1_TCA)
		dissect_mtp3mg_unknown_message(tvb, tree);
	    else if (mtp3_standard == ITU_STANDARD)
		proto_tree_add_item(tree, hf_mtp3mg_tfm_itu_apc, tvb, 0,
				    ITU_PC_LENGTH, TRUE);
	    else /* CHINESE_ITU_STANDARD */
		dissect_mtp3mg_3byte_pc(tvb, tree, &ett_mtp3mg_tfm_apc,
					&hf_mtp3mg_tfm_chinese_apc,
					&hf_mtp3mg_tfm_apc_member,
					&hf_mtp3mg_tfm_apc_cluster,
					&hf_mtp3mg_tfm_apc_network);
	}
	break;

    default:
	dissect_mtp3mg_unknown_message(tvb, tree);
    }
}

static void
dissect_mtp3mg_rsm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		   guint8 h1)
{
    if (check_col(pinfo->cinfo, COL_INFO))
	col_add_fstr(pinfo->cinfo, COL_INFO, "%s ",
		     val_to_str(h1, rsm_h1_message_type_acro_values, "Unknown"));

    switch (h1)
    {
    case RSM_H1_RST:
    case RSM_H1_RSR:
    case RSM_H1_RCP:
    case RSM_H1_RCR:
	if (mtp3_standard == ANSI_STANDARD)
	{
	    dissect_mtp3mg_3byte_pc(tvb, tree, &ett_mtp3mg_rsm_apc,
				    &hf_mtp3mg_rsm_ansi_apc,
				    &hf_mtp3mg_rsm_apc_member,
				    &hf_mtp3mg_rsm_apc_cluster,
				    &hf_mtp3mg_rsm_apc_network);

	} else /* ITU_STANDARD and CHINESE_ITU_STANDARD */ {

	    if (h1 == RSM_H1_RST || h1 == RSM_H1_RSR)
	    {
		if (mtp3_standard == ITU_STANDARD)
		    proto_tree_add_item(tree, hf_mtp3mg_rsm_itu_apc, tvb, 0,
					ITU_PC_LENGTH, TRUE);

		else /* CHINESE_ITU_STANDARD */
		    dissect_mtp3mg_3byte_pc(tvb, tree, &ett_mtp3mg_rsm_apc,
					    &hf_mtp3mg_rsm_chinese_apc,
					    &hf_mtp3mg_rsm_apc_member,
					    &hf_mtp3mg_rsm_apc_cluster,
					    &hf_mtp3mg_rsm_apc_network);
	    } else
		dissect_mtp3mg_unknown_message(tvb, tree);
	}
	break;

    default:
	dissect_mtp3mg_unknown_message(tvb, tree);
    }
}

static void
dissect_mtp3mg_mim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		   guint8 h1)
{
    if (check_col(pinfo->cinfo, COL_INFO))
	col_add_fstr(pinfo->cinfo, COL_INFO, "%s ",
		     val_to_str(h1, mim_h1_message_type_acro_values, "Unknown"));

    switch (h1)
    {
    case MIM_H1_LIN:
    case MIM_H1_LUN:
    case MIM_H1_LIA:
    case MIM_H1_LUA:
    case MIM_H1_LID:
    case MIM_H1_LFU:
    case MIM_H1_LLT:
    case MIM_H1_LRT:
	if (mtp3_standard == ANSI_STANDARD)
	{
	    proto_tree_add_item(tree, hf_mtp3mg_mim_ansi_slc, tvb, 0,
				ANSI_MIM_LENGTH, TRUE);
	}
	/* else: nothing to dissect */
	break;

    default:
	dissect_mtp3mg_unknown_message(tvb, tree);
    }
}

static void
dissect_mtp3mg_trm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		   guint8 h1)
{
    if (check_col(pinfo->cinfo, COL_INFO))
	col_add_fstr(pinfo->cinfo, COL_INFO, "%s ",
		     val_to_str(h1, trm_h1_message_type_acro_values, "Unknown"));

    switch (h1)
    {
    case TRM_H1_TRA:
	/* nothing to dissect */
	break;
    case TRM_H1_TRW:
	if (mtp3_standard != ANSI_STANDARD)
	    dissect_mtp3mg_unknown_message(tvb, tree);
	/* else: nothing to dissect */
	break;

    default:
	dissect_mtp3mg_unknown_message(tvb, tree);
    }
}

static void
dissect_mtp3mg_dlm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		   guint8 h1)
{
    if (check_col(pinfo->cinfo, COL_INFO))
	col_add_fstr(pinfo->cinfo, COL_INFO, "%s ",
		     val_to_str(h1, dlm_h1_message_type_acro_values, "Unknown"));

    switch (h1)
    {
    case DLM_H1_DLC:
	if (mtp3_standard == ANSI_STANDARD)
	{
	    proto_tree_add_item(tree, hf_mtp3mg_dlc_ansi_slc, tvb, 0,
				ANSI_DLC_LENGTH, TRUE);
	    proto_tree_add_item(tree, hf_mtp3mg_dlc_ansi_link, tvb, 0,
				ANSI_DLC_LENGTH, TRUE);
	} else /* ITU_STANDARD and CHINESE_ITU_STANDARD */ {
	    proto_tree_add_item(tree, hf_mtp3mg_dlc_itu_link, tvb, 0,
				ITU_DLC_LENGTH, TRUE);
	}
	break;
    case DLM_H1_CSS:
    case DLM_H1_CNS:
    case DLM_H1_CNP:
	/* nothing to dissect */
	break;

    default:
	dissect_mtp3mg_unknown_message(tvb, tree);
    }
}

static void
dissect_mtp3mg_ufc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		   guint8 h1)
{
    if (check_col(pinfo->cinfo, COL_INFO))
	col_add_fstr(pinfo->cinfo, COL_INFO, "%s ",
		     val_to_str(h1, ufc_h1_message_type_acro_values, "Unknown"));

    switch (h1)
    {
    case UFC_H1_UPU:
	if (mtp3_standard == ANSI_STANDARD
	    || mtp3_standard == CHINESE_ITU_STANDARD)
	{
	    int *hf_apc;

	    if (mtp3_standard == ANSI_STANDARD)
		hf_apc = &hf_mtp3mg_upu_ansi_apc;
	    else /* CHINESE_ITU_STANDARD */
		hf_apc = &hf_mtp3mg_upu_chinese_apc;

	    dissect_mtp3mg_3byte_pc(tvb, tree, &ett_mtp3mg_upu_apc,
				    hf_apc,
				    &hf_mtp3mg_rsm_apc_member,
				    &hf_mtp3mg_rsm_apc_cluster,
				    &hf_mtp3mg_rsm_apc_network);

	    proto_tree_add_item(tree, hf_mtp3mg_upu_user, tvb,
				ANSI_UPU_USER_OFFSET, UPU_USER_LENGTH, TRUE);
	    proto_tree_add_item(tree, hf_mtp3mg_upu_cause, tvb,
				ANSI_UPU_USER_OFFSET, UPU_USER_LENGTH, TRUE);
	} else /* ITU_STANDARD */ {
	    proto_tree_add_item(tree, hf_mtp3mg_upu_itu_apc, tvb, 0,
				ITU_PC_LENGTH, TRUE);
	    proto_tree_add_item(tree, hf_mtp3mg_upu_user, tvb,
				ITU_UPU_USER_OFFSET, UPU_USER_LENGTH, TRUE);
	    proto_tree_add_item(tree, hf_mtp3mg_upu_cause, tvb,
				ITU_UPU_USER_OFFSET, UPU_USER_LENGTH, TRUE);
	}
	break;

    default:
	dissect_mtp3mg_unknown_message(tvb, tree);
    }
}

static void
dissect_mtp3mg_test(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
		   guint8 h1)
{
    guint8 length;

    if (check_col(pinfo->cinfo, COL_INFO))
	col_add_fstr(pinfo->cinfo, COL_INFO, "%s ",
		     val_to_str(h1, test_h1_message_type_acro_values, "Unknown"));

    switch (h1)
    {
    case TEST_H1_SLTM:
    case TEST_H1_SLTA:
	proto_tree_add_item(tree, hf_mtp3mg_test_length, tvb, 0, TEST_LENGTH,
			    TRUE);

	length = tvb_get_guint8(tvb, 0) >> TEST_LENGTH_SHIFT;
	proto_tree_add_text(tree, tvb, TEST_PATTERN_OFFSET, length,
			    "Test pattern (%u byte%s)", length,
			    plurality(length, "", "s"));
	break;

    default:
	dissect_mtp3mg_unknown_message(tvb, tree);
    }
}

static void
dissect_mtp3mg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{

    guint8 h0, h1;
    tvbuff_t *payload_tvb;

    /* Set up structures needed to add the protocol subtree and manage it */
    proto_item *mtp3mg_item = NULL;
    proto_tree *mtp3mg_tree = NULL;

    /* Make entries in Protocol column on summary display */
    if (check_col(pinfo->cinfo, COL_PROTOCOL))
      switch(mtp3_standard) {
        case ITU_STANDARD:
          col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3MG (Int. ITU)");
          break;
        case ANSI_STANDARD:
          col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3MG (ANSI)");
          break;
        case CHINESE_ITU_STANDARD:
          col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3MG (Chin. ITU)");
          break;
      };      

    if (tree) {
	/* create display subtree for the protocol */
	mtp3mg_item = proto_tree_add_item(tree, proto_mtp3mg, tvb, 0, -1,
					  TRUE);
	mtp3mg_tree = proto_item_add_subtree(mtp3mg_item, ett_mtp3mg);
    }

    /*
     *  Dissect the message
     */
    if(pinfo->private_data == (void *)MTP3MG_ANSI_TEST_SI ||
       pinfo->private_data == (void *)MTP3MG_ITU_TEST_SI)
    {	/* Test messages */

	proto_tree_add_item(mtp3mg_tree, hf_mtp3test_h0, tvb, 0, H0H1_LENGTH,
			    TRUE);
	/* H1 is added below */

	h0 = tvb_get_guint8(tvb, 0) & H0_MASK;
	h1 = (tvb_get_guint8(tvb, 0) & H1_MASK) >> H1_SHIFT;

	payload_tvb = tvb_new_subset(tvb, H0H1_LENGTH, -1, -1);

	switch (h0)
	{
	case TEST_H0_SLT:
	    proto_tree_add_item(mtp3mg_tree, hf_mtp3mg_test_h1, tvb, 0,
				H0H1_LENGTH, TRUE);
	    dissect_mtp3mg_test(payload_tvb, pinfo, mtp3mg_tree, h1);
	    break;

	default:
	    if (check_col(pinfo->cinfo, COL_INFO))
		col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown ");

	    dissect_mtp3mg_unknown_message(tvb, mtp3mg_tree);
	} /* switch */

    } else {	/* Real management messages */

	proto_tree_add_item(mtp3mg_tree, hf_mtp3mg_h0, tvb, 0, H0H1_LENGTH,
			    TRUE);
	/* H1 is added below */

	h0 = tvb_get_guint8(tvb, 0) & H0_MASK;
	h1 = (tvb_get_guint8(tvb, 0) & H1_MASK) >> H1_SHIFT;

	payload_tvb = tvb_new_subset(tvb, H0H1_LENGTH, -1, -1);

	switch (h0)
	{
	case H0_CHM:
	    proto_tree_add_item(mtp3mg_tree, hf_mtp3mg_chm_h1, tvb, 0,
				H0H1_LENGTH, TRUE);
	    dissect_mtp3mg_chm(payload_tvb, pinfo, mtp3mg_tree, h1);
	    break;
	case H0_ECM:
	    proto_tree_add_item(mtp3mg_tree, hf_mtp3mg_ecm_h1, tvb, 0,
				H0H1_LENGTH, TRUE);
	    dissect_mtp3mg_ecm(payload_tvb, pinfo, mtp3mg_tree, h1);
	    break;
	case H0_FCM:
	    proto_tree_add_item(mtp3mg_tree, hf_mtp3mg_fcm_h1, tvb, 0,
				H0H1_LENGTH, TRUE);
	    dissect_mtp3mg_fcm(payload_tvb, pinfo, mtp3mg_tree, h1);
	    break;
	case H0_TFM:
	    proto_tree_add_item(mtp3mg_tree, hf_mtp3mg_tfm_h1, tvb, 0,
				H0H1_LENGTH, TRUE);
	    dissect_mtp3mg_tfm(payload_tvb, pinfo, mtp3mg_tree, h1);
	    break;
	case H0_RSM:
	    proto_tree_add_item(mtp3mg_tree, hf_mtp3mg_rsm_h1, tvb, 0,
				H0H1_LENGTH, TRUE);
	    dissect_mtp3mg_rsm(payload_tvb, pinfo, mtp3mg_tree, h1);
	    break;
	case H0_MIM:
	    proto_tree_add_item(mtp3mg_tree, hf_mtp3mg_mim_h1, tvb, 0,
				H0H1_LENGTH, TRUE);
	    dissect_mtp3mg_mim(payload_tvb, pinfo, mtp3mg_tree, h1);
	    break;
	case H0_TRM:
	    proto_tree_add_item(mtp3mg_tree, hf_mtp3mg_trm_h1, tvb, 0,
				H0H1_LENGTH, TRUE);
	    dissect_mtp3mg_trm(payload_tvb, pinfo, mtp3mg_tree, h1);
	    break;
	case H0_DLM:
	    proto_tree_add_item(mtp3mg_tree, hf_mtp3mg_dlm_h1, tvb, 0,
				H0H1_LENGTH, TRUE);
	    dissect_mtp3mg_dlm(payload_tvb, pinfo, mtp3mg_tree, h1);
	    break;
	case H0_UFC:
	    proto_tree_add_item(mtp3mg_tree, hf_mtp3mg_ufc_h1, tvb, 0,
				H0H1_LENGTH, TRUE);
	    dissect_mtp3mg_ufc(payload_tvb, pinfo, mtp3mg_tree, h1);
	    break;

	default:
	    if (check_col(pinfo->cinfo, COL_INFO))
		col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown ");

	    dissect_mtp3mg_unknown_message(tvb, mtp3mg_tree);
	} /* switch */
    } /* else */

}

void
proto_register_mtp3mg(void)
{

    /* Setup list of header fields  See Section 1.6.1 for details*/
    static hf_register_info hf[] = {
	{ &hf_mtp3mg_h0,
	    { "H0 (Message Group)", "mtp3mg.h0",
	      FT_UINT8, BASE_HEX, VALS(h0_message_type_values), H0_MASK,
	      "Message group identifier", HFILL }},
	{ &hf_mtp3mg_chm_h1,
	    { "H1 (Message)", "mtp3mg.h1",
	      FT_UINT8, BASE_HEX, VALS(chm_h1_message_type_values), H1_MASK,
	      "Message type", HFILL }},
	{ &hf_mtp3mg_ecm_h1,
	    { "H1 (Message)", "mtp3mg.h1",
	      FT_UINT8, BASE_HEX, VALS(ecm_h1_message_type_values), H1_MASK,
	      "Message type", HFILL }},
	{ &hf_mtp3mg_fcm_h1,
	    { "H1 (Message)", "mtp3mg.h1",
	      FT_UINT8, BASE_HEX, VALS(fcm_h1_message_type_values), H1_MASK,
	      "Message type", HFILL }},
	{ &hf_mtp3mg_tfm_h1,
	    { "H1 (Message)", "mtp3mg.h1",
	      FT_UINT8, BASE_HEX, VALS(tfm_h1_message_type_values), H1_MASK,
	      "Message type", HFILL }},
	{ &hf_mtp3mg_rsm_h1,
	    { "H1 (Message)", "mtp3mg.h1",
	      FT_UINT8, BASE_HEX, VALS(rsm_h1_message_type_values), H1_MASK,
	      "Message type", HFILL }},
	{ &hf_mtp3mg_mim_h1,
	    { "H1 (Message)", "mtp3mg.h1",
	      FT_UINT8, BASE_HEX, VALS(mim_h1_message_type_values), H1_MASK,
	      "Message type", HFILL }},
	{ &hf_mtp3mg_trm_h1,
	    { "H1 (Message)", "mtp3mg.h1",
	      FT_UINT8, BASE_HEX, VALS(trm_h1_message_type_values), H1_MASK,
	      "Message type", HFILL }},
	{ &hf_mtp3mg_dlm_h1,
	    { "H1 (Message)", "mtp3mg.h1",
	      FT_UINT8, BASE_HEX, VALS(dlm_h1_message_type_values), H1_MASK,
	      "Message type", HFILL }},
	{ &hf_mtp3mg_ufc_h1,
	    { "H1 (Message)", "mtp3mg.h1",
	      FT_UINT8, BASE_HEX, VALS(ufc_h1_message_type_values), H1_MASK,
	      "Message type", HFILL }},
	{ &hf_mtp3mg_coo_ansi_slc,
	    { "Signalling Link Code", "mtp3mg.slc",
	      FT_UINT8, BASE_DEC, NULL, ANSI_COO_SLC_MASK,
	      "SLC of affected link", HFILL }},
	{ &hf_mtp3mg_coo_ansi_fsn,
	    { "Forward Sequence Number", "mtp3mg.fsn",
	      FT_UINT8, BASE_DEC, NULL, ANSI_COO_FSN_MASK,
	      "Forward Sequence Number of last accepted message", HFILL }},
	{ &hf_mtp3mg_coo_itu_fsn,
	    { "Forward Sequence Number", "mtp3mg.fsn",
	      FT_UINT8, BASE_DEC, NULL, ITU_COO_FSN_MASK,
	      "Forward Sequence Number of last accepted message", HFILL }},
	{ &hf_mtp3mg_xco_ansi_slc,
	    { "Signalling Link Code", "mtp3mg.slc",
	      FT_UINT32, BASE_DEC, NULL, ANSI_XCO_SLC_MASK,
	      "SLC of affected link", HFILL }},
	{ &hf_mtp3mg_xco_ansi_fsn,
	    { "Forward Sequence Number", "mtp3mg.fsn",
	      FT_UINT32, BASE_DEC, NULL, ANSI_XCO_FSN_MASK,
	      "Forward Sequence Number of last accepted message", HFILL }},
	{ &hf_mtp3mg_xco_itu_fsn,
	    { "Forward Sequence Number", "mtp3mg.fsn",
	      FT_UINT24, BASE_DEC, NULL, 0x0,
	      "Forward Sequence Number of last accepted message", HFILL }},
	{ &hf_mtp3mg_cbd_ansi_slc,
	    { "Signalling Link Code", "mtp3mg.slc",
	      FT_UINT16, BASE_DEC, NULL, ANSI_CBD_SLC_MASK,
	      "SLC of affected link", HFILL }},
	{ &hf_mtp3mg_cbd_ansi_cbc,
	    { "Change Back Code", "mtp3mg.cbc",
	      FT_UINT16, BASE_DEC, NULL, ANSI_CBD_CBC_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_cbd_itu_cbc,
	    { "Change Back Code", "mtp3mg.cbc",
	      FT_UINT8, BASE_DEC, NULL, 0x0,
	      "", HFILL }},
	{ &hf_mtp3mg_eco_ansi_slc,
	    { "Signalling Link Code", "mtp3mg.slc",
	      FT_UINT8, BASE_DEC, NULL, ANSI_ECO_SLC_MASK,
	      "SLC of affected link", HFILL }},
	{ &hf_mtp3mg_tfc_ansi_apc,
	    { "Affected Point Code", "mtp3mg.ansi_apc",
	      FT_STRING, BASE_NONE, NULL, 0x0,
	      "", HFILL }},
	{ &hf_mtp3mg_tfc_apc_member,
	    { "Affected Point Code member", "mtp3mg.apc.member",
	      FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_tfc_apc_cluster,
	    { "Affected Point Code cluster", "mtp3mg.apc.cluster",
	      FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_tfc_apc_network,
	    { "Affected Point Code network", "mtp3mg.apc.network",
	      FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_tfc_ansi_status,
	    { "Status", "mtp3mg.status",
	      FT_UINT8, BASE_DEC, NULL, ANSI_TFC_STATUS_MASK,
	      "Congestion status", HFILL }},
	{ &hf_mtp3mg_tfc_itu_apc,
	    { "Affected Point Code (ITU)", "mtp3mg.apc",
	      FT_UINT8, BASE_DEC, NULL, ITU_PC_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_tfc_itu_status,
	    { "Status", "mtp3mg.status",
	      FT_UINT8, BASE_DEC, NULL, ITU_TFC_STATUS_MASK,
	      "Congestion status", HFILL }},
	{ &hf_mtp3mg_tfc_chinese_apc,
	    { "Affected Point Code", "mtp3mg.chinese_apc",
	      FT_STRING, BASE_NONE, NULL, 0x0,
	      "", HFILL }},
	{ &hf_mtp3mg_tfm_ansi_apc,
	    { "Affected Point Code", "mtp3mg.ansi_apc",
	      FT_STRING, BASE_NONE, NULL, 0x0,
	      "", HFILL }},
	{ &hf_mtp3mg_tfm_apc_member,
	    { "Affected Point Code member", "mtp3mg.apc.member",
	      FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_tfm_apc_cluster,
	    { "Affected Point Code cluster", "mtp3mg.apc.cluster",
	      FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_tfm_apc_network,
	    { "Affected Point Code network", "mtp3mg.apc.network",
	      FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_tfm_itu_apc,
	    { "Affected Point Code (ITU)", "mtp3mg.apc",
	      FT_UINT8, BASE_DEC, NULL, ITU_PC_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_tfm_chinese_apc,
	    { "Affected Point Code", "mtp3mg.chinese_apc",
	      FT_STRING, BASE_NONE, NULL, 0x0,
	      "", HFILL }},
	{ &hf_mtp3mg_rsm_ansi_apc,
	    { "Affected Point Code", "mtp3mg.ansi_apc",
	      FT_STRING, BASE_NONE, NULL, 0x0,
	      "", HFILL }},
	{ &hf_mtp3mg_rsm_apc_member,
	    { "Affected Point Code member", "mtp3mg.apc.member",
	      FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_rsm_apc_cluster,
	    { "Affected Point Code cluster", "mtp3mg.apc.cluster",
	      FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_rsm_apc_network,
	    { "Affected Point Code network", "mtp3mg.apc.network",
	      FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_rsm_itu_apc,
	    { "Affected Point Code (ITU)", "mtp3mg.apc",
	      FT_UINT8, BASE_DEC, NULL, ITU_PC_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_rsm_chinese_apc,
	    { "Affected Point Code", "mtp3mg.chinese_apc",
	      FT_STRING, BASE_NONE, NULL, 0x0,
	      "", HFILL }},
	{ &hf_mtp3mg_mim_ansi_slc,
	    { "Signalling Link Code", "mtp3mg.slc",
	      FT_UINT8, BASE_DEC, NULL, ANSI_MIM_SLC_MASK,
	      "SLC of affected link", HFILL }},
	{ &hf_mtp3mg_dlc_ansi_slc,
	    { "Signalling Link Code", "mtp3mg.slc",
	      FT_UINT8, BASE_DEC, NULL, ANSI_DLC_SLC_MASK,
	      "SLC of affected link", HFILL }},
	{ &hf_mtp3mg_dlc_ansi_link,
	    { "Link", "mtp3mg.link",
	      FT_UINT8, BASE_DEC, NULL, ANSI_DLC_LINK_MASK,
	      "CIC of BIC used to carry data", HFILL }},
	{ &hf_mtp3mg_dlc_itu_link,
	    { "Link", "mtp3mg.link",
	      FT_UINT8, BASE_DEC, NULL, ITU_DLC_LINK_MASK,
	      "CIC of BIC used to carry data", HFILL }},
	{ &hf_mtp3mg_upu_ansi_apc,
	    { "Affected Point Code", "mtp3mg.ansi_apc",
	      FT_STRING, BASE_NONE, NULL, 0x0,
	      "", HFILL }},
	{ &hf_mtp3mg_upu_apc_member,
	    { "Affected Point Code member", "mtp3mg.apc.member",
	      FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_upu_apc_cluster,
	    { "Affected Point Code cluster", "mtp3mg.apc.cluster",
	      FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_upu_apc_network,
	    { "Affected Point Code network", "mtp3mg.apc.network",
	      FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_upu_itu_apc,
	    { "Affected Point Code", "mtp3mg.apc",
	      FT_UINT8, BASE_DEC, NULL, ITU_PC_MASK,
	      "", HFILL }},
	{ &hf_mtp3mg_upu_chinese_apc,
	    { "Affected Point Code", "mtp3mg.chinese_apc",
	      FT_STRING, BASE_NONE, NULL, 0x0,
	      "", HFILL }},
	{ &hf_mtp3mg_upu_user,
	    { "User", "mtp3mg.user",
	      FT_UINT8, BASE_HEX, VALS(service_indicator_code_vals), UPU_USER_MASK,
	      "Unavailable user part", HFILL }},
	{ &hf_mtp3mg_upu_cause,
	    { "Cause", "mtp3mg.cause",
	      FT_UINT8, BASE_HEX, VALS(upu_cause_values), UPU_CAUSE_MASK,
	      "Cause of user unavailability", HFILL }},
	{ &hf_mtp3test_h0,
	    { "H0 (Message Group)", "mtp3mg.test.h0",
	      FT_UINT8, BASE_HEX, VALS(test_h0_message_type_values), H0_MASK,
	      "Message group identifier", HFILL }},
	{ &hf_mtp3mg_test_h1,
	    { "H1 (Message)", "mtp3mg.test.h1",
	      FT_UINT8, BASE_HEX, VALS(test_h1_message_type_values), H1_MASK,
	      "SLT message type", HFILL }},
	{ &hf_mtp3mg_test_length,
	    { "Test length", "mtp3mg.test.length",
	      FT_UINT8, BASE_DEC, NULL, H1_MASK,
	      "Signalling link test pattern length", HFILL }}
  };

    /* Setup protocol subtree array */
    static gint *ett[] = {
	&ett_mtp3mg,
	&ett_mtp3mg_fcm_apc,
	&ett_mtp3mg_tfm_apc,
	&ett_mtp3mg_rsm_apc,
	&ett_mtp3mg_upu_apc
    };

    /* Register the protocol name and description */
    proto_mtp3mg = proto_register_protocol("Message Transfer Part Level 3 Management",
					   "MTP3MG", "mtp3mg");
    register_dissector("mtp3mg", dissect_mtp3mg, proto_mtp3mg);

    /* Required calls to register the header fields and subtrees used */
    proto_register_field_array(proto_mtp3mg, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

}

void
proto_reg_handoff_mtp3mg(void)
{
    dissector_handle_t mtp3mg_handle;

    mtp3mg_handle = create_dissector_handle(dissect_mtp3mg, proto_mtp3mg);

    dissector_add("mtp3.service_indicator", MTP3MG_SI, mtp3mg_handle);

    /*  SI 1 is unused in ANSI and SI 2 is unused in ITU, so it's okay for us
     *  to grab both (regardless of mtp3.standard setting) here.
     */
    dissector_add("mtp3.service_indicator", MTP3MG_ITU_TEST_SI, mtp3mg_handle);
    dissector_add("mtp3.service_indicator", MTP3MG_ANSI_TEST_SI, mtp3mg_handle);
}