Improve heuristic standard detection:
[obnox/wireshark/wip.git] / epan / dissectors / packet-mtp3.c
1 /* packet-mtp3.c
2  * Routines for Message Transfer Part Level 3 dissection
3  *
4  * It is (hopefully) compliant to:
5  *   ANSI T1.111.4-1996
6  *   ITU-T Q.704 7/1996
7  *   GF 001-9001 (Chinese ITU variant)
8  *   JT-Q704 and NTT-Q704 (Japan)
9  *
10  *   Note that the division of the Japan SLS into the SLC and A/B bit (for
11  *   management messages) is not done.
12  *
13  * Copyright 2001, Michael Tuexen <tuexen [AT] fh-muenster.de>
14  * Updated for ANSI, Chinese ITU, and Japan support by
15  *  Jeff Morriss <jeff.morriss.ws [AT] gmail.com>
16  *
17  * $Id$
18  *
19  * Wireshark - Network traffic analyzer
20  * By Gerald Combs <gerald@wireshark.org>
21  * Copyright 1998 Gerald Combs
22  *
23  * Copied from README.developer
24  *
25  * This program is free software; you can redistribute it and/or
26  * modify it under the terms of the GNU General Public License
27  * as published by the Free Software Foundation; either version 2
28  * of the License, or (at your option) any later version.
29  *
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  * GNU General Public License for more details.
34  *
35  * You should have received a copy of the GNU General Public License
36  * along with this program; if not, write to the Free Software
37  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38  */
39
40 #ifdef HAVE_CONFIG_H
41 # include "config.h"
42 #endif
43
44 #include <string.h>
45 #include <glib.h>
46
47 #include <epan/packet.h>
48 #include <epan/tap.h>
49 #include <epan/prefs.h>
50 #include <epan/emem.h>
51 #include "packet-q708.h"
52 #include "packet-sccp.h"
53
54 /* Initialize the protocol and registered fields */
55 static int proto_mtp3  = -1;
56
57 static int mtp3_tap = -1;
58
59 static module_t *mtp3_module;
60
61 static int hf_mtp3_service_indicator = -1;
62 static int hf_mtp3_network_indicator = -1;
63 static int hf_mtp3_itu_spare = -1;
64 static int hf_mtp3_itu_priority = -1;
65 static int hf_mtp3_ansi_priority = -1;
66 static int hf_mtp3_itu_pc = -1;
67 static int hf_mtp3_24bit_pc = -1;
68 static int hf_mtp3_itu_opc = -1;
69 static int hf_mtp3_24bit_opc = -1;
70 static int hf_mtp3_ansi_opc = -1;
71 static int hf_mtp3_chinese_opc = -1;
72 static int hf_mtp3_opc_network = -1;
73 static int hf_mtp3_opc_cluster = -1;
74 static int hf_mtp3_opc_member = -1;
75 static int hf_mtp3_itu_dpc = -1;
76 static int hf_mtp3_24bit_dpc = -1;
77 static int hf_mtp3_ansi_dpc = -1;
78 static int hf_mtp3_chinese_dpc = -1;
79 static int hf_mtp3_dpc_network = -1;
80 static int hf_mtp3_dpc_cluster = -1;
81 static int hf_mtp3_dpc_member = -1;
82 static int hf_mtp3_itu_sls = -1;
83 static int hf_mtp3_ansi_5_bit_sls = -1;
84 static int hf_mtp3_ansi_8_bit_sls = -1;
85 static int hf_mtp3_chinese_itu_sls = -1;
86 static int hf_mtp3_japan_dpc = -1;
87 static int hf_mtp3_japan_opc = -1;
88 static int hf_mtp3_japan_pc = -1;
89 static int hf_mtp3_japan_4_bit_sls = -1;
90 static int hf_mtp3_japan_4_bit_sls_spare = -1;
91 static int hf_mtp3_japan_5_bit_sls = -1;
92 static int hf_mtp3_japan_5_bit_sls_spare = -1;
93
94 /* Initialize the subtree pointers */
95 static gint ett_mtp3 = -1;
96 static gint ett_mtp3_sio = -1;
97 static gint ett_mtp3_label = -1;
98 static gint ett_mtp3_label_dpc = -1;
99 static gint ett_mtp3_label_opc = -1;
100
101 static dissector_table_t mtp3_sio_dissector_table;
102
103 typedef enum {
104   ITU_PC_STRUCTURE_NONE    = 1,
105   ITU_PC_STRUCTURE_3_8_3   = 2,
106   ITU_PC_STRUCTURE_4_3_4_3 = 3
107 } ITU_PC_Structure_Type;
108
109 typedef enum {
110   JAPAN_PC_STRUCTURE_NONE    = 1,
111   JAPAN_PC_STRUCTURE_7_4_5   = 2,
112   JAPAN_PC_STRUCTURE_3_4_4_5 = 3
113 } JAPAN_PC_Structure_Type;
114
115 static gint itu_pc_structure = ITU_PC_STRUCTURE_NONE;
116 static gint japan_pc_structure = JAPAN_PC_STRUCTURE_NONE;
117
118 #include <packet-mtp3.h>
119 gint mtp3_standard = ITU_STANDARD;
120
121 static gboolean mtp3_use_ansi_5_bit_sls = FALSE;
122 static gboolean mtp3_use_japan_5_bit_sls = FALSE;
123 static gboolean mtp3_show_itu_priority = FALSE;
124 static gboolean mtp3_heuristic_standard = FALSE;
125 static gint mtp3_addr_fmt = MTP3_ADDR_FMT_DASHED;
126 static mtp3_addr_pc_t* mtp3_addr_dpc;
127 static mtp3_addr_pc_t* mtp3_addr_opc;
128
129 #define SIO_LENGTH                1
130 #define SLS_LENGTH                1
131 #define SIO_OFFSET                0
132 #define ROUTING_LABEL_OFFSET      (SIO_OFFSET + SIO_LENGTH)
133
134 #define ITU_ROUTING_LABEL_LENGTH  4
135 #define ITU_HEADER_LENGTH         (SIO_LENGTH + ITU_ROUTING_LABEL_LENGTH)
136
137 #define ITU_SLS_OFFSET            (SIO_OFFSET + ITU_HEADER_LENGTH - SLS_LENGTH)
138 #define ITU_MTP_PAYLOAD_OFFSET    (SIO_OFFSET + ITU_HEADER_LENGTH)
139
140 #define ANSI_ROUTING_LABEL_LENGTH (ANSI_PC_LENGTH + ANSI_PC_LENGTH + SLS_LENGTH)
141 #define ANSI_HEADER_LENGTH        (SIO_LENGTH + ANSI_ROUTING_LABEL_LENGTH)
142
143 #define ANSI_DPC_OFFSET           ROUTING_LABEL_OFFSET
144 #define ANSI_OPC_OFFSET           (ANSI_DPC_OFFSET + ANSI_PC_LENGTH)
145 #define ANSI_SLS_OFFSET           (ANSI_OPC_OFFSET + ANSI_PC_LENGTH)
146 #define ANSI_MTP_PAYLOAD_OFFSET   (SIO_OFFSET + ANSI_HEADER_LENGTH)
147
148 #define JAPAN_SLS_SPARE_LENGTH           1
149 #define JAPAN_ROUTING_LABEL_LENGTH (JAPAN_PC_LENGTH + JAPAN_PC_LENGTH + JAPAN_SLS_SPARE_LENGTH)
150 #define JAPAN_HEADER_LENGTH        (SIO_LENGTH + JAPAN_ROUTING_LABEL_LENGTH)
151
152 #define JAPAN_OPC_OFFSET           (ROUTING_LABEL_OFFSET + JAPAN_PC_LENGTH)
153 #define JAPAN_SLS_OFFSET           (JAPAN_OPC_OFFSET + JAPAN_PC_LENGTH)
154 #define JAPAN_SPARE_OFFSET         (ROUTING_LABEL_OFFSET + JAPAN_ROUTING_LABEL_LENGTH)
155 #define JAPAN_MTP_PAYLOAD_OFFSET   (SIO_OFFSET + JAPAN_HEADER_LENGTH)
156
157 #define SERVICE_INDICATOR_MASK     0x0F
158 #define SPARE_MASK                 0x30
159 #define ANSI_PRIORITY_MASK         SPARE_MASK
160 #define NETWORK_INDICATOR_MASK     0xC0
161 #define ITU_DPC_MASK               0x00003FFF
162 #define ITU_OPC_MASK               0x0FFFC000
163 #define ITU_SLS_MASK               0xF0000000
164
165 #define ANSI_5BIT_SLS_MASK         0x1F
166 #define ANSI_8BIT_SLS_MASK         0xFF
167 #define CHINESE_ITU_SLS_MASK       0xF
168 #define JAPAN_4_BIT_SLS_MASK       0xF
169 #define JAPAN_4_BIT_SLS_SPARE_MASK 0xF0
170 #define JAPAN_5_BIT_SLS_MASK       0x1F
171 #define JAPAN_5_BIT_SLS_SPARE_MASK 0xE0
172
173 /* the higher values are taken from the M3UA RFC */
174 static const value_string mtp3_service_indicator_code_vals[] = {
175         { 0x0,  "Signalling Network Management Message (SNM)" },
176         { 0x1,  "Maintenance Regular Message (MTN)" },
177         { 0x2,  "Maintenance Special Message (MTNS)" },
178         { 0x3,  "SCCP" },
179         { 0x4,  "TUP" },
180         { 0x5,  "ISUP" },
181         { 0x6,  "DUP (call and circuit related messages)" },
182         { 0x7,  "DUP (facility registration and cancellation message)" },
183         { 0x8,  "MTP testing user part" },
184         { 0x9,  "Broadband ISUP" },
185         { 0xa,  "Satellite ISUP" },
186         { 0xb,  "Spare" },
187         { 0xc,  "AAL type2 Signaling" },
188         { 0xd,  "Bearer Independent Call Control (BICC)" },
189         { 0xe,  "Gateway Control Protocol" },
190         { 0xf,  "Spare" },
191         { 0,    NULL }
192 };
193
194 const value_string mtp3_service_indicator_code_short_vals[] = {
195         { 0x0,  "SNM" },
196         { 0x1,  "MTN" },
197         { 0x2,  "MTNS" },
198         { 0x3,  "SCCP" },
199         { 0x4,  "TUP" },
200         { 0x5,  "ISUP" },
201         { 0x6,  "DUP (CC)" },
202         { 0x7,  "DUP (FAC/CANC)" },
203         { 0x8,  "MTP Test" },
204         { 0x9,  "ISUP-b" },
205         { 0xa,  "ISUP-s" },
206         { 0xc,  "AAL type 2" },
207         { 0xd,  "BICC" },
208         { 0xe,  "GCP" },
209         { 0,    NULL }
210 };
211
212 static const value_string network_indicator_vals[] = {
213         { 0x0,  "International network" },
214         { 0x1,  "Spare (for international use only)" },
215         { 0x2,  "National network" },
216         { 0x3,  "Reserved for national use" },
217         { 0,    NULL }
218 };
219
220 static dissector_handle_t data_handle;
221
222
223 /*
224  * helper routine to format a point code in structured form
225  */
226
227 void
228 mtp3_pc_to_str_buf(const guint32 pc, gchar *buf, int buf_len)
229 {
230   switch (mtp3_standard)
231   {
232     case ITU_STANDARD:
233       switch (itu_pc_structure) {
234         case ITU_PC_STRUCTURE_NONE:
235           g_snprintf(buf, buf_len, "%u", pc);
236           break;
237         case ITU_PC_STRUCTURE_3_8_3:
238           /* this format is used in international ITU networks */
239           g_snprintf(buf, buf_len, "%u-%u-%u", (pc & 0x3800)>>11, (pc & 0x7f8) >> 3, (pc & 0x07) >> 0);
240           break;
241         case ITU_PC_STRUCTURE_4_3_4_3:
242           /* this format is used in some national ITU networks, the German one for example. */
243           g_snprintf(buf, buf_len, "%u-%u-%u-%u", (pc & 0x3c00) >>10, (pc & 0x0380) >> 7, (pc & 0x0078) >> 3, (pc & 0x0007) >> 0);
244           break;
245         default:
246           DISSECTOR_ASSERT_NOT_REACHED();
247       }
248       break;
249     case ANSI_STANDARD:
250     case CHINESE_ITU_STANDARD:
251       g_snprintf(buf, buf_len, "%u-%u-%u", (pc & ANSI_NETWORK_MASK) >> 16, (pc & ANSI_CLUSTER_MASK) >> 8, (pc & ANSI_MEMBER_MASK));
252       break;
253     case JAPAN_STANDARD:
254       switch (japan_pc_structure) {
255         case JAPAN_PC_STRUCTURE_NONE:
256           g_snprintf(buf, buf_len, "%u", pc);
257           break;
258         case JAPAN_PC_STRUCTURE_7_4_5:
259           /* This format is specified by NTT */
260           g_snprintf(buf, buf_len, "%u-%u-%u", (pc & 0xfe00)>>9, (pc & 0x1e0)>>5, (pc & 0x1f));
261           break;
262         case JAPAN_PC_STRUCTURE_3_4_4_5:
263           /* Where does this format come from? */
264           g_snprintf(buf, buf_len, "%u-%u-%u-%u", (pc & 0xe000)>>13, (pc & 0x1e00)>>9, (pc & 0x1e0)>>5, (pc & 0x1f));
265           break;
266         default:
267           DISSECTOR_ASSERT_NOT_REACHED();
268       }
269       break;
270     default:
271       DISSECTOR_ASSERT_NOT_REACHED();
272     }
273 }
274
275 #define MAX_STRUCTURED_PC_LENGTH 20
276
277 gchar *
278 mtp3_pc_to_str(const guint32 pc)
279 {
280   gchar *str;
281
282   str=ep_alloc(MAX_STRUCTURED_PC_LENGTH);
283   mtp3_pc_to_str_buf(pc, str, MAX_STRUCTURED_PC_LENGTH);
284   return str;
285 }
286
287 gboolean
288 mtp3_pc_structured(void)
289 {
290   if ((mtp3_standard == ITU_STANDARD) && (itu_pc_structure == ITU_PC_STRUCTURE_NONE))
291     return FALSE;
292   else if ((mtp3_standard == JAPAN_STANDARD) && (japan_pc_structure == JAPAN_PC_STRUCTURE_NONE))
293     return FALSE;
294   else
295     return TRUE;
296 }
297
298 /*
299  * helper routine to format address to string
300  */
301
302 void
303 mtp3_addr_to_str_buf(const mtp3_addr_pc_t  *addr_pc_p,
304                      gchar *buf, int buf_len)
305 {
306   switch (mtp3_addr_fmt)
307   {
308   case MTP3_ADDR_FMT_DEC:
309     switch (addr_pc_p->type)
310     {
311     case ITU_STANDARD:
312       g_snprintf(buf, buf_len, "%u", addr_pc_p->pc & ITU_PC_MASK);
313       break;
314     case JAPAN_STANDARD:
315       g_snprintf(buf, buf_len, "%u", addr_pc_p->pc & JAPAN_PC_MASK);
316       break;
317     default:
318       /* assuming 24-bit */
319       g_snprintf(buf, buf_len, "%u", addr_pc_p->pc & ANSI_PC_MASK);
320       break;
321     }
322     break;
323
324   case MTP3_ADDR_FMT_HEX:
325     switch (addr_pc_p->type)
326     {
327     case ITU_STANDARD:
328       g_snprintf(buf, buf_len, "%x", addr_pc_p->pc & ITU_PC_MASK);
329       break;
330     case JAPAN_STANDARD:
331       g_snprintf(buf, buf_len, "%x", addr_pc_p->pc & JAPAN_PC_MASK);
332       break;
333     default:
334       /* assuming 24-bit */
335       g_snprintf(buf, buf_len, "%x", addr_pc_p->pc & ANSI_PC_MASK);
336       break;
337     }
338     break;
339
340   case MTP3_ADDR_FMT_NI_DEC:
341     switch (addr_pc_p->type)
342     {
343     case ITU_STANDARD:
344       g_snprintf(buf, buf_len, "%u:%u", addr_pc_p->ni, addr_pc_p->pc & ITU_PC_MASK);
345       break;
346     case JAPAN_STANDARD:
347       g_snprintf(buf, buf_len, "%u:%u", addr_pc_p->ni, addr_pc_p->pc & JAPAN_PC_MASK);
348       break;
349     default:
350       /* assuming 24-bit */
351       g_snprintf(buf, buf_len, "%u:%u", addr_pc_p->ni, addr_pc_p->pc & ANSI_PC_MASK);
352       break;
353     }
354     break;
355
356   case MTP3_ADDR_FMT_NI_HEX:
357     switch (addr_pc_p->type)
358     {
359     case ITU_STANDARD:
360       g_snprintf(buf, buf_len, "%u:%x", addr_pc_p->ni, addr_pc_p->pc & ITU_PC_MASK);
361       break;
362     case JAPAN_STANDARD:
363       g_snprintf(buf, buf_len, "%u:%x", addr_pc_p->ni, addr_pc_p->pc & JAPAN_PC_MASK);
364       break;
365     default:
366       /* assuming 24-bit */
367       g_snprintf(buf, buf_len, "%u:%x", addr_pc_p->ni, addr_pc_p->pc & ANSI_PC_MASK);
368       break;
369     }
370     break;
371
372   default:
373     /* FALLTHRU */
374
375   case MTP3_ADDR_FMT_DASHED:
376     mtp3_pc_to_str_buf(addr_pc_p->pc, buf, buf_len);
377     break;
378   }
379 }
380
381 guint32
382 mtp3_pc_hash(const mtp3_addr_pc_t *addr_pc_p) {
383     guint32 pc;
384
385     switch (addr_pc_p->type)
386     {
387         case ITU_STANDARD:
388             pc = (addr_pc_p->pc & ITU_PC_MASK) | ((addr_pc_p->ni % 4) << 14) ;
389             break;
390         default:
391             /* assuming 24-bit */
392             pc = (addr_pc_p->pc & ANSI_PC_MASK) | ((addr_pc_p->ni) << 24) ;
393             break;
394     }
395
396     return pc;
397 }
398
399 /*  Common function for dissecting 3-byte (ANSI or China) PCs. */
400 void
401 dissect_mtp3_3byte_pc(tvbuff_t *tvb, guint offset, proto_tree *tree, gint ett_pc, int hf_pc_string, int hf_pc_network,
402                       int hf_pc_cluster, int hf_pc_member, int hf_dpc, int hf_pc)
403 {
404     guint32 pc;
405     proto_item *pc_item, *hidden_item;
406     proto_tree *pc_tree;
407     char pc_string[MAX_STRUCTURED_PC_LENGTH];
408
409     pc = tvb_get_letoh24(tvb, offset);
410     mtp3_pc_to_str_buf(pc, pc_string, sizeof(pc_string));
411
412     pc_item = proto_tree_add_string(tree, hf_pc_string, tvb, offset, ANSI_PC_LENGTH, pc_string);
413
414     /* Add alternate formats of the PC
415      * NOTE: each of these formats is shown to the user,
416      * so I think that using hidden fields in this case is OK.
417      */
418     g_snprintf(pc_string, sizeof(pc_string), "%u", pc);
419     proto_item_append_text(pc_item, " (%s)", pc_string);
420     hidden_item = proto_tree_add_string(tree, hf_pc_string, tvb, offset, ANSI_PC_LENGTH, pc_string);
421     PROTO_ITEM_SET_HIDDEN(hidden_item);
422     g_snprintf(pc_string, sizeof(pc_string), "0x%x", pc);
423     proto_item_append_text(pc_item, " (%s)", pc_string);
424     hidden_item = proto_tree_add_string(tree, hf_pc_string, tvb, offset, ANSI_PC_LENGTH, pc_string);
425     PROTO_ITEM_SET_HIDDEN(hidden_item);
426
427     pc_tree = proto_item_add_subtree(pc_item, ett_pc);
428
429     proto_tree_add_uint(pc_tree, hf_pc_network, tvb, offset + ANSI_NETWORK_OFFSET, ANSI_NCM_LENGTH, pc);
430     proto_tree_add_uint(pc_tree, hf_pc_cluster, tvb, offset + ANSI_CLUSTER_OFFSET, ANSI_NCM_LENGTH, pc);
431     proto_tree_add_uint(pc_tree, hf_pc_member,  tvb, offset + ANSI_MEMBER_OFFSET,  ANSI_NCM_LENGTH, pc);
432
433     /* add full integer values of DPC as hidden for filtering purposes */
434     if (hf_dpc) {
435         hidden_item = proto_tree_add_uint(pc_tree, hf_dpc, tvb, offset, ANSI_PC_LENGTH, pc);
436         PROTO_ITEM_SET_HIDDEN(hidden_item);
437     }
438     if (hf_pc) {
439         hidden_item = proto_tree_add_uint(pc_tree, hf_pc,  tvb, offset, ANSI_PC_LENGTH, pc);
440         PROTO_ITEM_SET_HIDDEN(hidden_item);
441     }
442 }
443
444 static void
445 dissect_mtp3_sio(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mtp3_tree, void ** const pd_save)
446 {
447   guint8 sio;
448   proto_item *sio_item;
449   proto_tree *sio_tree;
450
451   sio_item = proto_tree_add_text(mtp3_tree, tvb, SIO_OFFSET, SIO_LENGTH, "Service information octet");
452   sio_tree = proto_item_add_subtree(sio_item, ett_mtp3_sio);
453
454   sio = tvb_get_guint8(tvb, SIO_OFFSET);
455   proto_tree_add_uint(sio_tree, hf_mtp3_network_indicator, tvb, SIO_OFFSET, SIO_LENGTH, sio);
456
457   mtp3_addr_opc->ni = (sio & NETWORK_INDICATOR_MASK) >> 6;
458   mtp3_addr_dpc->ni = (sio & NETWORK_INDICATOR_MASK) >> 6;
459
460   switch(mtp3_standard){
461   case ANSI_STANDARD:
462     proto_tree_add_uint(sio_tree, hf_mtp3_ansi_priority, tvb, SIO_OFFSET, SIO_LENGTH, sio);
463     break;
464   case ITU_STANDARD:
465   case CHINESE_ITU_STANDARD:
466     if (mtp3_show_itu_priority)
467       proto_tree_add_uint(sio_tree, hf_mtp3_itu_priority, tvb, SIO_OFFSET, SIO_LENGTH, sio);
468     else
469       proto_tree_add_uint(sio_tree, hf_mtp3_itu_spare, tvb, SIO_OFFSET, SIO_LENGTH, sio);
470     break;
471   case JAPAN_STANDARD:
472     /*  The Japan variant has priority but it's on the LI which belongs to
473      *  layer 2.  Not sure what we can do about that...
474      */
475     proto_tree_add_uint(sio_tree, hf_mtp3_itu_spare, tvb, SIO_OFFSET, SIO_LENGTH, sio);
476     break;
477   }
478
479   proto_tree_add_uint(sio_tree, hf_mtp3_service_indicator, tvb, SIO_OFFSET, SIO_LENGTH, sio);
480
481   /* Store the SI so that subidissectors know what SI this msg is */
482   *pd_save = pinfo->private_data;
483   pinfo->private_data = GUINT_TO_POINTER(sio & SERVICE_INDICATOR_MASK);
484 }
485
486 static void
487 dissect_mtp3_routing_label(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mtp3_tree)
488 {
489   guint32 label, dpc, opc;
490   proto_item *label_item, *label_dpc_item, *label_opc_item;
491   proto_item *hidden_item;
492   proto_tree *label_tree;
493   proto_tree *pc_subtree;
494   int hf_dpc_string;
495   int hf_opc_string;
496
497
498   switch (mtp3_standard) {
499   case ITU_STANDARD:
500     label_item = proto_tree_add_text(mtp3_tree, tvb, ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, "Routing label");
501     label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
502
503     label = tvb_get_letohl(tvb, ROUTING_LABEL_OFFSET);
504
505     opc = (label & ITU_OPC_MASK) >> 14;
506     dpc =  label & ITU_DPC_MASK;
507
508     hidden_item = proto_tree_add_uint(label_tree, hf_mtp3_itu_pc, tvb, ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, opc);
509     PROTO_ITEM_SET_HIDDEN(hidden_item);
510     hidden_item = proto_tree_add_uint(label_tree, hf_mtp3_itu_pc, tvb, ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, dpc);
511     PROTO_ITEM_SET_HIDDEN(hidden_item);
512
513     label_dpc_item = proto_tree_add_uint(label_tree, hf_mtp3_itu_dpc, tvb, ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, label);
514     if (mtp3_pc_structured())
515       proto_item_append_text(label_dpc_item, " (%s)", mtp3_pc_to_str(dpc));
516     if(mtp3_addr_dpc->ni == 0)
517     {
518       pc_subtree = proto_item_add_subtree(label_dpc_item, ett_mtp3_label_dpc);
519       analyze_q708_ispc(tvb, pc_subtree, ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, dpc);
520         }
521
522
523     label_opc_item = proto_tree_add_uint(label_tree, hf_mtp3_itu_opc, tvb, ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, label);
524     if (mtp3_pc_structured())
525       proto_item_append_text(label_opc_item, " (%s)", mtp3_pc_to_str(opc));
526     if(mtp3_addr_opc->ni == 0)
527     {
528       pc_subtree = proto_item_add_subtree(label_opc_item, ett_mtp3_label_opc);
529       analyze_q708_ispc(tvb, pc_subtree, ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, opc);
530         }
531
532     proto_tree_add_uint(label_tree, hf_mtp3_itu_sls, tvb, ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, label);
533     break;
534
535   case ANSI_STANDARD:
536   case CHINESE_ITU_STANDARD:
537     if (mtp3_standard == ANSI_STANDARD)
538     {
539       hf_dpc_string = hf_mtp3_ansi_dpc;
540       hf_opc_string = hf_mtp3_ansi_opc;
541     } else /* CHINESE_ITU_STANDARD */ {
542       hf_dpc_string = hf_mtp3_chinese_dpc;
543       hf_opc_string = hf_mtp3_chinese_opc;
544     }
545
546     /* Create the Routing Label Tree */
547     label_item = proto_tree_add_text(mtp3_tree, tvb, ROUTING_LABEL_OFFSET, ANSI_ROUTING_LABEL_LENGTH, "Routing label");
548     label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
549
550
551     /* create and fill the DPC tree */
552     dissect_mtp3_3byte_pc(tvb, ANSI_DPC_OFFSET, label_tree, ett_mtp3_label_dpc, hf_dpc_string, hf_mtp3_dpc_network,
553                           hf_mtp3_dpc_cluster, hf_mtp3_dpc_member, hf_mtp3_24bit_dpc, hf_mtp3_24bit_pc);
554     /* Store dpc for mtp3_addr below */
555     dpc = tvb_get_letoh24(tvb, ANSI_DPC_OFFSET);
556
557     /* create and fill the OPC tree */
558     dissect_mtp3_3byte_pc(tvb, ANSI_OPC_OFFSET, label_tree, ett_mtp3_label_opc, hf_opc_string, hf_mtp3_opc_network,
559                           hf_mtp3_opc_cluster, hf_mtp3_opc_member, hf_mtp3_24bit_opc, hf_mtp3_24bit_pc);
560     /* Store opc for mtp3_addr below */
561     opc = tvb_get_letoh24(tvb, ANSI_OPC_OFFSET);
562
563     /* SLS */
564     if (mtp3_standard == ANSI_STANDARD) {
565       if (mtp3_use_ansi_5_bit_sls)
566         proto_tree_add_item(label_tree, hf_mtp3_ansi_5_bit_sls, tvb, ANSI_SLS_OFFSET, SLS_LENGTH, ENC_NA);
567       else
568         proto_tree_add_item(label_tree, hf_mtp3_ansi_8_bit_sls, tvb, ANSI_SLS_OFFSET, SLS_LENGTH, ENC_NA);
569     } else /* CHINESE_ITU_STANDARD */ {
570       proto_tree_add_item(label_tree, hf_mtp3_chinese_itu_sls, tvb, ANSI_SLS_OFFSET, SLS_LENGTH, ENC_NA);
571     }
572     break;
573
574   case JAPAN_STANDARD:
575     label_item = proto_tree_add_text(mtp3_tree, tvb, ROUTING_LABEL_OFFSET, JAPAN_ROUTING_LABEL_LENGTH, "Routing label");
576     label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
577
578     label_dpc_item = proto_tree_add_item(label_tree, hf_mtp3_japan_dpc, tvb, ROUTING_LABEL_OFFSET, JAPAN_PC_LENGTH, ENC_LITTLE_ENDIAN);
579     dpc = tvb_get_letohs(tvb, ROUTING_LABEL_OFFSET);
580     if (mtp3_pc_structured()) {
581       proto_item_append_text(label_dpc_item, " (%s)", mtp3_pc_to_str(dpc));
582     }
583
584     label_opc_item = proto_tree_add_item(label_tree, hf_mtp3_japan_opc, tvb, JAPAN_OPC_OFFSET, JAPAN_PC_LENGTH, ENC_LITTLE_ENDIAN);
585     opc = tvb_get_letohs(tvb, JAPAN_OPC_OFFSET);
586     if (mtp3_pc_structured()) {
587       proto_item_append_text(label_opc_item, " (%s)", mtp3_pc_to_str(opc));
588     }
589
590     hidden_item = proto_tree_add_item(label_tree, hf_mtp3_japan_pc, tvb, ROUTING_LABEL_OFFSET, JAPAN_PC_LENGTH, ENC_LITTLE_ENDIAN);
591     PROTO_ITEM_SET_HIDDEN(hidden_item);
592     hidden_item = proto_tree_add_item(label_tree, hf_mtp3_japan_pc, tvb, JAPAN_OPC_OFFSET, JAPAN_PC_LENGTH, ENC_LITTLE_ENDIAN);
593     PROTO_ITEM_SET_HIDDEN(hidden_item);
594
595     if (mtp3_use_japan_5_bit_sls) {
596         proto_tree_add_item(label_tree, hf_mtp3_japan_5_bit_sls, tvb, JAPAN_SLS_OFFSET, JAPAN_SLS_SPARE_LENGTH, ENC_NA);
597         proto_tree_add_item(label_tree, hf_mtp3_japan_5_bit_sls_spare, tvb, JAPAN_SLS_OFFSET, JAPAN_SLS_SPARE_LENGTH, ENC_NA);
598     } else {
599         proto_tree_add_item(label_tree, hf_mtp3_japan_4_bit_sls, tvb, JAPAN_SLS_OFFSET, JAPAN_SLS_SPARE_LENGTH, ENC_NA);
600         proto_tree_add_item(label_tree, hf_mtp3_japan_4_bit_sls_spare, tvb, JAPAN_SLS_OFFSET, JAPAN_SLS_SPARE_LENGTH, ENC_NA);
601     }
602
603     break;
604   default:
605     DISSECTOR_ASSERT_NOT_REACHED();
606   }
607
608   mtp3_addr_opc->type = mtp3_standard;
609   mtp3_addr_opc->pc = opc;
610   SET_ADDRESS(&pinfo->src, AT_SS7PC, sizeof(mtp3_addr_pc_t), (guint8 *) mtp3_addr_opc);
611
612   mtp3_addr_dpc->type = mtp3_standard;
613   mtp3_addr_dpc->pc = dpc;
614   SET_ADDRESS(&pinfo->dst, AT_SS7PC, sizeof(mtp3_addr_pc_t), (guint8 *) mtp3_addr_dpc);
615 }
616
617 static void
618 dissect_mtp3_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
619 {
620   guint8 sio;
621   guint8 service_indicator;
622   tvbuff_t *payload_tvb = NULL;
623
624   sio               = tvb_get_guint8(tvb, SIO_OFFSET);
625   service_indicator = sio & SERVICE_INDICATOR_MASK;
626
627   switch (mtp3_standard) {
628   case ITU_STANDARD:
629     payload_tvb = tvb_new_subset_remaining(tvb, ITU_MTP_PAYLOAD_OFFSET);
630     break;
631   case ANSI_STANDARD:
632   case CHINESE_ITU_STANDARD:
633     payload_tvb = tvb_new_subset_remaining(tvb, ANSI_MTP_PAYLOAD_OFFSET);
634     break;
635   case JAPAN_STANDARD:
636     payload_tvb = tvb_new_subset_remaining(tvb, JAPAN_MTP_PAYLOAD_OFFSET);
637     break;
638   default:
639     DISSECTOR_ASSERT_NOT_REACHED();
640   }
641
642   col_set_str(pinfo->cinfo, COL_INFO, "DATA ");
643
644   if (!dissector_try_uint(mtp3_sio_dissector_table, service_indicator, payload_tvb, pinfo, tree))
645     call_dissector(data_handle, payload_tvb, pinfo, tree);
646 }
647
648 #define HEURISTIC_FAILED_STANDARD 0xffff
649 static guint
650 heur_mtp3_standard(tvbuff_t *tvb, packet_info *pinfo, guint8 si)
651 {
652
653     guint32 len;
654     tvbuff_t *payload;
655
656     len = tvb_length(tvb);
657     switch (si) {
658     case 3:
659         {
660             payload = tvb_new_subset(tvb, ITU_HEADER_LENGTH, len-ITU_HEADER_LENGTH, len-ITU_HEADER_LENGTH);
661             if (looks_like_valid_sccp(PINFO_FD_NUM(pinfo), payload, ITU_STANDARD)) {
662                 return ITU_STANDARD;
663             }
664             payload = tvb_new_subset(tvb, ANSI_HEADER_LENGTH, len-ANSI_HEADER_LENGTH, len-ANSI_HEADER_LENGTH);
665             if (looks_like_valid_sccp(PINFO_FD_NUM(pinfo), payload, ANSI_STANDARD)) {
666                 return ANSI_STANDARD;
667             }
668             payload = tvb_new_subset(tvb, ANSI_HEADER_LENGTH, len-ANSI_HEADER_LENGTH, len-ANSI_HEADER_LENGTH);
669             if (looks_like_valid_sccp(PINFO_FD_NUM(pinfo), payload, CHINESE_ITU_STANDARD)) {
670                 return CHINESE_ITU_STANDARD;
671             }
672             payload = tvb_new_subset(tvb, JAPAN_HEADER_LENGTH, len-JAPAN_HEADER_LENGTH, len-JAPAN_HEADER_LENGTH);
673             if (looks_like_valid_sccp(PINFO_FD_NUM(pinfo), payload, JAPAN_STANDARD)) {
674                 return JAPAN_STANDARD;
675             }
676
677             return HEURISTIC_FAILED_STANDARD;
678
679         }
680     default:
681         return HEURISTIC_FAILED_STANDARD;
682     }
683
684 }
685
686 static const value_string mtp3_standard_vals[] = {
687         { ITU_STANDARD,                 "ITU_STANDARD" },
688         { ANSI_STANDARD,                "ANSI_STANDARD" },
689         { CHINESE_ITU_STANDARD,         "CHINESE_ITU_STANDARD" },
690         { JAPAN_STANDARD,               "JAPAN_STANDARD" },
691         { 0,    NULL }
692 };
693
694 /* Code to actually dissect the packets */
695 static void
696 dissect_mtp3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
697 {
698     void* pd_save;
699     mtp3_tap_rec_t* tap_rec = ep_alloc0(sizeof(mtp3_tap_rec_t));
700     guint heuristic_standard, pref_mtp3_standard;
701     guint8 si;
702
703     /* Set up structures needed to add the protocol subtree and manage it */
704     proto_item *mtp3_item = NULL, *gen_item;
705     proto_tree *mtp3_tree = NULL;
706
707     pref_mtp3_standard = mtp3_standard;
708
709     mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0, 0, ENC_NA);
710
711     si = tvb_get_guint8(tvb, SIO_OFFSET) & SERVICE_INDICATOR_MASK;
712     if (mtp3_heuristic_standard) {
713         heuristic_standard = heur_mtp3_standard(tvb, pinfo, si);
714         if (heuristic_standard == HEURISTIC_FAILED_STANDARD) {
715             gen_item = proto_tree_add_text(tree, tvb, 0, 0, "Could not determine Heuristic using %s", val_to_str(mtp3_standard, mtp3_standard_vals, "unknown"));
716         } else {
717             gen_item = proto_tree_add_text(tree, tvb, 0, 0, "%s", val_to_str(heuristic_standard, mtp3_standard_vals, "unknown"));
718             mtp3_standard = heuristic_standard;
719         }
720         PROTO_ITEM_SET_GENERATED(gen_item);
721 }
722
723     /* Make entries in Protocol column on summary display */
724     switch(mtp3_standard) {
725     case ITU_STANDARD:
726         col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Int. ITU)");
727         proto_item_set_len(mtp3_item, ITU_HEADER_LENGTH);
728         break;
729     case ANSI_STANDARD:
730         col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (ANSI)");
731         proto_item_set_len(mtp3_item, ANSI_HEADER_LENGTH);
732         break;
733     case CHINESE_ITU_STANDARD:
734         col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Chin. ITU)");
735         proto_item_set_len(mtp3_item, ANSI_HEADER_LENGTH);
736         break;
737     case JAPAN_STANDARD:
738         col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Japan)");
739         proto_item_set_len(mtp3_item, JAPAN_HEADER_LENGTH);
740         break;
741     };
742
743     if (tree) {
744         /* create display subtree for the protocol */
745         mtp3_tree = proto_item_add_subtree(mtp3_item, ett_mtp3);
746     }
747
748     mtp3_addr_opc = ep_alloc0(sizeof(mtp3_addr_pc_t));
749     mtp3_addr_dpc = ep_alloc0(sizeof(mtp3_addr_pc_t));
750
751     /* Dissect the packet (even if !tree so can call sub-dissectors and update
752     * the source and destination address columns) */
753     dissect_mtp3_sio(tvb, pinfo, mtp3_tree, &pd_save);
754     dissect_mtp3_routing_label(tvb, pinfo, mtp3_tree);
755
756     memcpy(&(tap_rec->addr_opc),mtp3_addr_opc,sizeof(mtp3_addr_pc_t));
757     memcpy(&(tap_rec->addr_dpc),mtp3_addr_dpc,sizeof(mtp3_addr_pc_t));
758
759     tap_rec->si_code = (tvb_get_guint8(tvb, SIO_OFFSET) & SERVICE_INDICATOR_MASK);
760     tap_rec->size = tvb_length(tvb);
761
762     tap_queue_packet(mtp3_tap, pinfo, tap_rec);
763
764     dissect_mtp3_payload(tvb, pinfo, tree);
765     pinfo->private_data = pd_save;
766
767     mtp3_standard = pref_mtp3_standard;
768
769 }
770
771 void
772 proto_register_mtp3(void)
773 {
774
775   /* Setup list of header fields  See Section 1.6.1 for details*/
776   static hf_register_info hf[] = {
777     { &hf_mtp3_service_indicator,     { "Service indicator",        "mtp3.service_indicator", FT_UINT8,  BASE_HEX,  VALS(mtp3_service_indicator_code_vals), SERVICE_INDICATOR_MASK,     NULL, HFILL }},
778     { &hf_mtp3_network_indicator,     { "Network indicator",        "mtp3.network_indicator", FT_UINT8,  BASE_HEX,  VALS(network_indicator_vals),           NETWORK_INDICATOR_MASK,     NULL, HFILL }},
779     { &hf_mtp3_itu_spare,             { "Spare",                    "mtp3.spare",             FT_UINT8,  BASE_HEX,  NULL,                                   SPARE_MASK,                 NULL, HFILL }},
780     { &hf_mtp3_itu_priority,          { "ITU priority",             "mtp3.priority",          FT_UINT8,  BASE_DEC,  NULL,                                   SPARE_MASK,                 NULL, HFILL }},
781     { &hf_mtp3_ansi_priority,         { "ANSI Priority",            "mtp3.priority",          FT_UINT8,  BASE_DEC,  NULL,                                   ANSI_PRIORITY_MASK,         NULL, HFILL }},
782     { &hf_mtp3_itu_opc,               { "OPC",                      "mtp3.opc",               FT_UINT32, BASE_DEC,  NULL,                                   ITU_OPC_MASK,               NULL, HFILL }},
783     { &hf_mtp3_itu_pc,                { "PC",                       "mtp3.pc",                FT_UINT32, BASE_DEC,  NULL,                                   0x0,                        NULL, HFILL }},
784     { &hf_mtp3_24bit_pc,              { "PC",                       "mtp3.pc",                FT_UINT32, BASE_DEC,  NULL,                                   ANSI_PC_MASK,               NULL, HFILL }},
785     { &hf_mtp3_24bit_opc,             { "OPC",                      "mtp3.opc",               FT_UINT32, BASE_DEC,  NULL,                                   ANSI_PC_MASK,               NULL, HFILL }},
786     { &hf_mtp3_ansi_opc,              { "OPC",                      "mtp3.ansi_opc",          FT_STRING, BASE_NONE, NULL,                                   0x0,                        NULL, HFILL }},
787     { &hf_mtp3_chinese_opc,           { "OPC",                      "mtp3.chinese_opc",       FT_STRING, BASE_NONE, NULL,                                   0x0,                        NULL, HFILL }},
788     { &hf_mtp3_opc_network,           { "OPC Network",              "mtp3.opc.network",       FT_UINT24, BASE_DEC,  NULL,                                   ANSI_NETWORK_MASK,          NULL, HFILL }},
789     { &hf_mtp3_opc_cluster,           { "OPC Cluster",              "mtp3.opc.cluster",       FT_UINT24, BASE_DEC,  NULL,                                   ANSI_CLUSTER_MASK,          NULL, HFILL }},
790     { &hf_mtp3_opc_member,            { "OPC Member",               "mtp3.opc.member",        FT_UINT24, BASE_DEC,  NULL,                                   ANSI_MEMBER_MASK,           NULL, HFILL }},
791     { &hf_mtp3_japan_opc,             { "OPC",                      "mtp3.opc",               FT_UINT16, BASE_DEC,  NULL,                                   JAPAN_PC_MASK,              NULL, HFILL }},
792     { &hf_mtp3_japan_pc,              { "PC",                       "mtp3.pc",                FT_UINT16, BASE_DEC,  NULL,                                   JAPAN_PC_MASK,              NULL, HFILL }},
793     { &hf_mtp3_itu_dpc,               { "DPC",                      "mtp3.dpc",               FT_UINT32, BASE_DEC,  NULL,                                   ITU_DPC_MASK,               NULL, HFILL }},
794     { &hf_mtp3_24bit_dpc,             { "DPC",                      "mtp3.dpc",               FT_UINT32, BASE_DEC,  NULL,                                   ANSI_PC_MASK,               NULL, HFILL }},
795     { &hf_mtp3_ansi_dpc,              { "DPC",                      "mtp3.ansi_dpc",          FT_STRING, BASE_NONE, NULL,                                   0x0,                        NULL, HFILL }},
796     { &hf_mtp3_chinese_dpc,           { "DPC",                      "mtp3.chinese_dpc",       FT_STRING, BASE_NONE, NULL,                                   0x0,                        NULL, HFILL }},
797     { &hf_mtp3_dpc_network,           { "DPC Network",              "mtp3.dpc.network",       FT_UINT24, BASE_DEC,  NULL,                                   ANSI_NETWORK_MASK,          NULL, HFILL }},
798     { &hf_mtp3_dpc_cluster,           { "DPC Cluster",              "mtp3.dpc.cluster",       FT_UINT24, BASE_DEC,  NULL,                                   ANSI_CLUSTER_MASK,          NULL, HFILL }},
799     { &hf_mtp3_dpc_member,            { "DPC Member",               "mtp3.dpc.member",        FT_UINT24, BASE_DEC,  NULL,                                   ANSI_MEMBER_MASK,           NULL, HFILL }},
800     { &hf_mtp3_japan_dpc,             { "DPC",                      "mtp3.dpc",               FT_UINT16, BASE_DEC,  NULL,                                   JAPAN_PC_MASK,              NULL, HFILL }},
801     { &hf_mtp3_itu_sls,               { "Signalling Link Selector", "mtp3.sls",               FT_UINT32, BASE_DEC,  NULL,                                   ITU_SLS_MASK,               NULL, HFILL }},
802     { &hf_mtp3_japan_4_bit_sls,       { "Signalling Link Selector", "mtp3.sls",               FT_UINT8,  BASE_DEC,  NULL,                                   JAPAN_4_BIT_SLS_MASK,       NULL, HFILL }},
803     { &hf_mtp3_japan_4_bit_sls_spare, { "SLS Spare",                "mtp3.sls_spare",         FT_UINT8,  BASE_HEX,  NULL,                                   JAPAN_4_BIT_SLS_SPARE_MASK, NULL, HFILL }},
804     { &hf_mtp3_japan_5_bit_sls,       { "Signalling Link Selector", "mtp3.sls",               FT_UINT8,  BASE_DEC,  NULL,                                   JAPAN_5_BIT_SLS_MASK,       NULL, HFILL }},
805     { &hf_mtp3_japan_5_bit_sls_spare, { "SLS Spare",                "mtp3.sls_spare",         FT_UINT8,  BASE_HEX,  NULL,                                   JAPAN_5_BIT_SLS_SPARE_MASK, NULL, HFILL }},
806     { &hf_mtp3_ansi_5_bit_sls,        { "Signalling Link Selector", "mtp3.sls",               FT_UINT8,  BASE_DEC,  NULL,                                   ANSI_5BIT_SLS_MASK,         NULL, HFILL }},
807     { &hf_mtp3_ansi_8_bit_sls,        { "Signalling Link Selector", "mtp3.sls",               FT_UINT8,  BASE_DEC,  NULL,                                   ANSI_8BIT_SLS_MASK,         NULL, HFILL }},
808     { &hf_mtp3_chinese_itu_sls,       { "Signalling Link Selector", "mtp3.sls",               FT_UINT8,  BASE_DEC,  NULL,                                   CHINESE_ITU_SLS_MASK,       NULL, HFILL }}
809   };
810
811   /* Setup protocol subtree array */
812   static gint *ett[] = {
813     &ett_mtp3,
814     &ett_mtp3_sio,
815     &ett_mtp3_label,
816     &ett_mtp3_label_dpc,
817     &ett_mtp3_label_opc
818   };
819
820   static enum_val_t mtp3_options[] = {
821     { "itu",            "ITU",          ITU_STANDARD },
822     { "ansi",           "ANSI",         ANSI_STANDARD },
823     { "chinese-itu",    "Chinese ITU",  CHINESE_ITU_STANDARD },
824     { "japan",          "Japan",        JAPAN_STANDARD },
825     { NULL, NULL, 0 }
826   };
827
828   static enum_val_t mtp3_addr_fmt_str_e[] = {
829     { "decimal",        "Decimal",              MTP3_ADDR_FMT_DEC },
830     { "hexadecimal",    "Hexadecimal",          MTP3_ADDR_FMT_HEX },
831     { "ni-decimal",     "NI-Decimal",           MTP3_ADDR_FMT_NI_DEC },
832     { "ni-hexadecimal", "NI-Hexadecimal",       MTP3_ADDR_FMT_NI_HEX },
833     { "dashed",         "Dashed",               MTP3_ADDR_FMT_DASHED },
834     { NULL,             NULL,                   0 }
835   };
836
837   static enum_val_t itu_pc_structures[] = {
838     { "unstructured",   "Unstructured", ITU_PC_STRUCTURE_NONE},
839     { "3-8-3",          "3-8-3",        ITU_PC_STRUCTURE_3_8_3 },
840     { "4-3-4-3",        "4-3-4-3",      ITU_PC_STRUCTURE_4_3_4_3 },
841     { NULL,             NULL,           0 }
842   };
843
844   static enum_val_t japan_pc_structures[] = {
845     { "unstructured",   "Unstructured", JAPAN_PC_STRUCTURE_NONE},
846     { "7-4-5",          "7-4-5",        JAPAN_PC_STRUCTURE_7_4_5 },
847     { "3-4-4-5",        "3-4-4-5",      JAPAN_PC_STRUCTURE_3_4_4_5 },
848     { NULL,             NULL,           0 }
849   };
850
851  /* Register the protocol name and description */
852   proto_mtp3 = proto_register_protocol("Message Transfer Part Level 3",
853                                        "MTP3", "mtp3");
854   register_dissector("mtp3", dissect_mtp3, proto_mtp3);
855
856   /* Required function calls to register the header fields and subtrees used */
857   proto_register_field_array(proto_mtp3, hf, array_length(hf));
858   proto_register_subtree_array(ett, array_length(ett));
859
860   mtp3_sio_dissector_table = register_dissector_table("mtp3.service_indicator",
861                                                       "MTP3 Service indicator",
862                                                       FT_UINT8, BASE_HEX);
863
864   mtp3_tap = register_tap("mtp3");
865
866   mtp3_module = prefs_register_protocol(proto_mtp3, NULL);
867
868   prefs_register_bool_preference(mtp3_module, "heuristic_standard",
869                                  "Try to determine the MTP3 standard heuristically",
870                                  "This only works for SCCP traffic for now",
871                                  &mtp3_heuristic_standard);
872
873   prefs_register_enum_preference(mtp3_module, "standard", "MTP3 standard",
874                                  "The SS7 standard used in MTP3 packets",
875                                  &mtp3_standard, mtp3_options, FALSE);
876
877   prefs_register_enum_preference(mtp3_module, "itu_pc_structure", "ITU Pointcode structure",
878                                  "The structure of the pointcodes in ITU networks",
879                                  &itu_pc_structure, itu_pc_structures, FALSE);
880
881   prefs_register_enum_preference(mtp3_module, "japan_pc_structure", "Japan Pointcode structure",
882                                  "The structure of the pointcodes in Japan networks",
883                                  &japan_pc_structure, japan_pc_structures, FALSE);
884
885   prefs_register_bool_preference(mtp3_module, "ansi_5_bit_sls",
886                                  "Use 5-bit SLS (ANSI only)",
887                                  "Use 5-bit (instead of 8-bit) SLS in ANSI MTP3 packets",
888                                  &mtp3_use_ansi_5_bit_sls);
889
890   prefs_register_bool_preference(mtp3_module, "japan_5_bit_sls",
891                                  "Use 5-bit SLS (Japan only)",
892                                  "Use 5-bit (instead of 4-bit) SLS in Japan MTP3 packets",
893                                  &mtp3_use_japan_5_bit_sls);
894
895   prefs_register_enum_preference(mtp3_module, "addr_format", "Address Format",
896                                  "Format for point code in the address columns",
897                                  &mtp3_addr_fmt, mtp3_addr_fmt_str_e, FALSE);
898
899   prefs_register_bool_preference(mtp3_module, "itu_priority",
900                                  "Show MSU priority (national option, ITU and China ITU only)",
901                                  "Decode the spare bits of the SIO as the MSU priority (a national option in ITU)",
902                                  &mtp3_show_itu_priority);
903
904 }
905
906 void
907 proto_reg_handoff_mtp3(void)
908 {
909   dissector_handle_t mtp3_handle;
910
911   mtp3_handle = find_dissector("mtp3");
912   dissector_add_uint("wtap_encap", WTAP_ENCAP_MTP3, mtp3_handle);
913   dissector_add_string("tali.opcode", "mtp3", mtp3_handle);
914
915   data_handle = find_dissector("data");
916 }