From Anders Broman: add some filterable fields, and un-hide some other
[obnox/wireshark/wip.git] / 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  *
9  * Copyright 2001, Michael Tuexen <tuexen [AT] fh-muenster.de>
10  * Updated for ANSI and Chinese ITU support by Jeff Morriss <jeff.morriss[AT]ulticom.com>
11  *
12  * $Id: packet-mtp3.c,v 1.26 2004/02/29 08:30:10 guy Exp $
13  *
14  * Ethereal - Network traffic analyzer
15  * By Gerald Combs <gerald@ethereal.com>
16  * Copyright 1998 Gerald Combs
17  *
18  * Copied from README.developer
19  *
20  * This program is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU General Public License
22  * as published by the Free Software Foundation; either version 2
23  * of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33  */
34
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include <glib.h>
40
41 #ifdef NEED_SNPRINTF_H
42 #include "snprintf.h"
43 #endif
44
45 #include <epan/packet.h>
46 #include "prefs.h"
47
48 /* Initialize the protocol and registered fields */
49 static int proto_mtp3  = -1;
50 static module_t *mtp3_module;
51
52 static int hf_mtp3_service_indicator = -1;
53 static int hf_mtp3_network_indicator = -1;
54 static int hf_mtp3_itu_spare = -1;
55 static int hf_mtp3_ansi_priority = -1;
56 static int hf_mtp3_itu_opc = -1;
57 static int hf_mtp3_24bit_opc = -1;
58 static int hf_mtp3_ansi_opc = -1;
59 static int hf_mtp3_chinese_opc = -1;
60 static int hf_mtp3_opc_network = -1;
61 static int hf_mtp3_opc_cluster = -1;
62 static int hf_mtp3_opc_member = -1;
63 static int hf_mtp3_itu_dpc = -1;
64 static int hf_mtp3_24bit_dpc = -1;
65 static int hf_mtp3_ansi_dpc = -1;
66 static int hf_mtp3_chinese_dpc = -1;
67 static int hf_mtp3_dpc_network = -1;
68 static int hf_mtp3_dpc_cluster = -1;
69 static int hf_mtp3_dpc_member = -1;
70 static int hf_mtp3_itu_sls = -1;
71 static int hf_mtp3_ansi_5_bit_sls = -1;
72 static int hf_mtp3_ansi_8_bit_sls = -1;
73 static int hf_mtp3_chinese_itu_sls = -1;
74
75 /* Initialize the subtree pointers */
76 static gint ett_mtp3 = -1;
77 static gint ett_mtp3_sio = -1;
78 static gint ett_mtp3_label = -1;
79 static gint ett_mtp3_label_dpc = -1;
80 static gint ett_mtp3_label_opc = -1;
81
82 static dissector_table_t mtp3_sio_dissector_table;
83
84 #include <packet-mtp3.h>
85 Standard_Type mtp3_standard = ITU_STANDARD;
86
87 static gboolean mtp3_use_ansi_5_bit_sls = FALSE;
88 static mtp3_net_addr_fmt_e mtp3_net_addr_fmt = MTP3_NET_ADDR_FMT_DASHED;
89 static mtp3_addr_pc_t mtp3_addr_dpc, mtp3_addr_opc;
90
91 #define SIO_LENGTH                1
92
93 #define ITU_ROUTING_LABEL_LENGTH  4
94 #define ITU_HEADER_LENGTH         (SIO_LENGTH + ITU_ROUTING_LABEL_LENGTH)
95 #define ITU_SLS_LENGTH            1
96
97 #define SIO_OFFSET                0
98 #define ITU_SLS_OFFSET            (SIO_OFFSET + ITU_HEADER_LENGTH - ITU_SLS_LENGTH)
99 #define ITU_ROUTING_LABEL_OFFSET  (SIO_OFFSET + SIO_LENGTH)
100 #define ITU_MTP_PAYLOAD_OFFSET    (SIO_OFFSET + ITU_HEADER_LENGTH)
101
102 #define ANSI_SLS_LENGTH           1
103 #define ANSI_ROUTING_LABEL_LENGTH (ANSI_PC_LENGTH + ANSI_PC_LENGTH + ANSI_SLS_LENGTH)
104 #define ANSI_HEADER_LENGTH        (SIO_LENGTH + ANSI_ROUTING_LABEL_LENGTH)
105
106 #define ANSI_ROUTING_LABEL_OFFSET (SIO_OFFSET + SIO_LENGTH)
107 #define ANSI_DPC_OFFSET           ANSI_ROUTING_LABEL_OFFSET
108 #define ANSI_OPC_OFFSET           (ANSI_DPC_OFFSET + ANSI_PC_LENGTH)
109 #define ANSI_SLS_OFFSET           (ANSI_OPC_OFFSET + ANSI_PC_LENGTH)
110 #define ANSI_MTP_PAYLOAD_OFFSET   (SIO_OFFSET + ANSI_HEADER_LENGTH)
111
112 #define SERVICE_INDICATOR_MASK         0x0F
113 #define SPARE_MASK                     0x30
114 #define ANSI_PRIORITY_MASK             SPARE_MASK
115 #define NETWORK_INDICATOR_MASK         0xC0
116 #define ITU_DPC_MASK                   0x00003FFF
117 #define ITU_OPC_MASK                   0x0FFFC000
118 #define ITU_SLS_MASK                   0xF0000000
119
120 #define ANSI_NETWORK_MASK              0x0000FF
121 #define ANSI_CLUSTER_MASK              0x00FF00
122 #define ANSI_MEMBER_MASK               0xFF0000
123 #define ANSI_5BIT_SLS_MASK             0x1F
124 #define ANSI_8BIT_SLS_MASK             0xFF
125 #define CHINESE_ITU_SLS_MASK           0xF
126
127 static const value_string service_indicator_code_vals[] = {
128         { 0x0,  "Signalling Network Management Message (SNM)" },
129         { 0x1,  "Maintenance Regular Message (MTN)" },
130         { 0x2,  "Maintenance Special Message (MTNS)" },
131         { 0x3,  "SCCP" },
132         { 0x4,  "TUP" },
133         { 0x5,  "ISUP" },
134         { 0x6,  "DUP (call and circuit related messages)" },
135         { 0x7,  "DUP (facility registration and cancellation message)" },
136         { 0x8,  "MTP testing user part" },
137         { 0x9,  "Spare" },
138         { 0xa,  "Spare" },
139         { 0xb,  "Spare" },
140         { 0xc,  "Spare" },
141         { 0xd,  "Spare" },
142         { 0xe,  "Spare" },
143         { 0xf,  "Spare" },
144         { 0,    NULL }
145 };
146
147 static const value_string network_indicator_vals[] = {
148         { 0x0,  "International network" },
149         { 0x1,  "Spare (for international use only)" },
150         { 0x2,  "National network" },
151         { 0x3,  "Reserved for national use" },
152         { 0,    NULL }
153 };
154
155 static dissector_handle_t data_handle;
156
157
158 /*
159  * helper routine to format address to string
160  */
161 void
162 mtp3_addr_to_str_buf(
163   const guint8          *data,
164   gchar                 *buf)
165 {
166   mtp3_addr_pc_t        *addr_pc_p = (mtp3_addr_pc_t *) data;
167
168   switch (mtp3_net_addr_fmt)
169   {
170   case MTP3_NET_ADDR_FMT_DEC:
171     switch (addr_pc_p->type)
172     {
173     case ITU_STANDARD:
174       sprintf(buf, "%u", addr_pc_p->pc & ITU_PC_MASK);
175       break;
176     default:
177       /* assuming 24-bit */
178       sprintf(buf, "%u", addr_pc_p->pc & ANSI_PC_MASK);
179       break;
180     }
181     break;
182
183   case MTP3_NET_ADDR_FMT_HEX:
184     switch (addr_pc_p->type)
185     {
186     case ITU_STANDARD:
187       sprintf(buf, "%x", addr_pc_p->pc & ITU_PC_MASK);
188       break;
189     default:
190       /* assuming 24-bit */
191       sprintf(buf, "%x", addr_pc_p->pc & ANSI_PC_MASK);
192       break;
193     }
194     break;
195
196   case MTP3_NET_ADDR_FMT_NI_DEC:
197     switch (addr_pc_p->type)
198     {
199     case ITU_STANDARD:
200       sprintf(buf, "%u:%u", addr_pc_p->ni, addr_pc_p->pc & ITU_PC_MASK);
201       break;
202     default:
203       /* assuming 24-bit */
204       sprintf(buf, "%u:%u", addr_pc_p->ni, addr_pc_p->pc & ANSI_PC_MASK);
205       break;
206     }
207     break;
208
209   case MTP3_NET_ADDR_FMT_NI_HEX:
210     switch (addr_pc_p->type)
211     {
212     case ITU_STANDARD:
213       sprintf(buf, "%u:%x", addr_pc_p->ni, addr_pc_p->pc & ITU_PC_MASK);
214       break;
215     default:
216       /* assuming 24-bit */
217       sprintf(buf, "%u:%x", addr_pc_p->ni, addr_pc_p->pc & ANSI_PC_MASK);
218       break;
219     }
220     break;
221
222   default:
223     /* FALLTHRU */
224
225   case MTP3_NET_ADDR_FMT_DASHED:
226     switch (addr_pc_p->type)
227     {
228     case ITU_STANDARD:
229       sprintf(buf, "%u-%u-%u",
230         (addr_pc_p->pc & 0x3800) >> 11,
231         ((addr_pc_p->pc & 0x7f8) >> 3),
232         (addr_pc_p->pc & 0x07));
233       break;
234     default:
235       /* assuming 24-bit */
236       sprintf(buf, "%u-%u-%u",
237         (addr_pc_p->pc & ANSI_NETWORK_MASK),
238         ((addr_pc_p->pc & ANSI_CLUSTER_MASK) >> 8),
239         ((addr_pc_p->pc & ANSI_MEMBER_MASK) >> 16));
240       break;
241     }
242     break;
243   }
244 }
245
246 static void
247 dissect_mtp3_sio(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mtp3_tree)
248 {
249   guint8 sio;
250   proto_item *sio_item;
251   proto_tree *sio_tree;
252
253   sio_item = proto_tree_add_text(mtp3_tree, tvb, SIO_OFFSET, SIO_LENGTH,
254                                  "Service information octet");
255   sio_tree = proto_item_add_subtree(sio_item, ett_mtp3_sio);
256
257   sio = tvb_get_guint8(tvb, SIO_OFFSET);
258   proto_tree_add_uint(sio_tree, hf_mtp3_network_indicator, tvb, SIO_OFFSET,
259                       SIO_LENGTH, sio);
260
261   mtp3_addr_opc.ni = (sio & NETWORK_INDICATOR_MASK) >> 6;
262   mtp3_addr_dpc.ni = (sio & NETWORK_INDICATOR_MASK) >> 6;
263
264   switch(mtp3_standard){
265   case ANSI_STANDARD:
266     proto_tree_add_uint(sio_tree, hf_mtp3_ansi_priority, tvb, SIO_OFFSET,
267                         SIO_LENGTH, sio);
268     break;
269   case ITU_STANDARD:
270   case CHINESE_ITU_STANDARD:
271     proto_tree_add_uint(sio_tree, hf_mtp3_itu_spare, tvb, SIO_OFFSET,
272                         SIO_LENGTH, sio);
273     break;
274   }
275
276   proto_tree_add_uint(sio_tree, hf_mtp3_service_indicator, tvb, SIO_OFFSET,
277                       SIO_LENGTH, sio);
278
279   /* Store the SI so that subidissectors know what SI this msg is */
280   pinfo->private_data = (void *)(sio & SERVICE_INDICATOR_MASK);
281 }
282
283 static void
284 dissect_mtp3_routing_label(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mtp3_tree)
285 {
286   guint32 label, dpc = 0, opc = 0;
287   guint8 sls;
288   proto_item *label_item, *label_dpc_item, *label_opc_item;
289   proto_tree *label_tree, *label_dpc_tree, *label_opc_tree;
290   char pc[ANSI_PC_STRING_LENGTH];
291   int *hf_dpc_string;
292   int *hf_opc_string;
293
294
295   switch (mtp3_standard) {
296   case ITU_STANDARD:
297     label_item = proto_tree_add_text(mtp3_tree, tvb, ITU_ROUTING_LABEL_OFFSET,
298                                      ITU_ROUTING_LABEL_LENGTH, "Routing label");
299     label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
300
301     label = tvb_get_letohl(tvb, ITU_ROUTING_LABEL_OFFSET);
302     sls   = tvb_get_guint8(tvb, ITU_SLS_OFFSET);
303
304     opc = (label & ITU_OPC_MASK) >> 14;
305     dpc = label & ITU_DPC_MASK;
306
307     label_dpc_item =
308         proto_tree_add_uint(label_tree, hf_mtp3_itu_dpc, tvb,
309                             ITU_ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH,
310                             label);
311     proto_item_append_text(label_dpc_item, " (%u-%u-%u)",
312                            (dpc & 0x3800) >> 11,
313                            ((dpc & 0x7f8) >> 3),
314                            (dpc & 0x07));
315
316     label_opc_item =
317         proto_tree_add_uint(label_tree, hf_mtp3_itu_opc, tvb,
318                             ITU_ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH,
319                             label);
320     proto_item_append_text(label_opc_item, " (%u-%u-%u)",
321                            (opc & 0x3800) >> 11,
322                            ((opc & 0x7f8) >> 3),
323                            (opc & 0x07));
324
325     proto_tree_add_uint(label_tree, hf_mtp3_itu_sls, tvb, ITU_SLS_OFFSET,
326                         ITU_SLS_LENGTH, sls);
327     break;
328
329   case ANSI_STANDARD:
330   case CHINESE_ITU_STANDARD:
331     if (mtp3_standard == ANSI_STANDARD)
332     {
333       hf_dpc_string = &hf_mtp3_ansi_dpc;
334       hf_opc_string = &hf_mtp3_ansi_opc;
335     } else /* CHINESE_ITU_STANDARD */ {
336       hf_dpc_string = &hf_mtp3_chinese_dpc;
337       hf_opc_string = &hf_mtp3_chinese_opc;
338     }
339
340     /* Create the Routing Label Tree */
341     label_item = proto_tree_add_text(mtp3_tree, tvb, ANSI_ROUTING_LABEL_OFFSET,
342                                      ANSI_ROUTING_LABEL_LENGTH,
343                                      "Routing label");
344     label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
345
346     /* create the DPC tree */
347     dpc = tvb_get_ntoh24(tvb, ANSI_DPC_OFFSET);
348     snprintf(pc, sizeof(pc), "%d-%d-%d", (dpc & ANSI_NETWORK_MASK),
349                                          ((dpc & ANSI_CLUSTER_MASK) >> 8),
350                                          ((dpc & ANSI_MEMBER_MASK) >> 16));
351
352     label_dpc_item = proto_tree_add_string_format(label_tree, *hf_dpc_string,
353                                                   tvb, ANSI_DPC_OFFSET,
354                                                   ANSI_PC_LENGTH, pc,
355                                                   "DPC (%s) (%u)", pc, dpc);
356
357     label_dpc_tree = proto_item_add_subtree(label_dpc_item, ett_mtp3_label_dpc);
358
359     proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_member, tvb,
360                         ANSI_DPC_OFFSET + ANSI_MEMBER_OFFSET, ANSI_NCM_LENGTH,
361                         dpc);
362     proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_cluster,tvb,
363                         ANSI_DPC_OFFSET + ANSI_CLUSTER_OFFSET, ANSI_NCM_LENGTH,
364                         dpc);
365     proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_network,tvb,
366                         ANSI_DPC_OFFSET + ANSI_NETWORK_OFFSET, ANSI_NCM_LENGTH,
367                         dpc);
368
369
370     /* add full integer values of DPC as hidden for filtering purposes */
371     proto_tree_add_uint_hidden(label_dpc_tree, hf_mtp3_24bit_dpc, tvb, ANSI_DPC_OFFSET,
372                                ANSI_PC_LENGTH, dpc);
373
374     /* create the OPC tree */
375     opc = tvb_get_ntoh24(tvb, ANSI_OPC_OFFSET);
376     snprintf(pc, sizeof(pc), "%d-%d-%d", (opc & ANSI_NETWORK_MASK),
377                                          ((opc & ANSI_CLUSTER_MASK) >> 8),
378                                          ((opc & ANSI_MEMBER_MASK) >> 16));
379     label_opc_item = proto_tree_add_string_format(label_tree, *hf_opc_string,
380                                                   tvb, ANSI_OPC_OFFSET,
381                                                   ANSI_PC_LENGTH, pc,
382                                                   "OPC (%s) (%u)", pc, opc);
383
384     label_opc_tree = proto_item_add_subtree(label_opc_item, ett_mtp3_label_opc);
385
386     proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_member, tvb,
387                         ANSI_OPC_OFFSET + ANSI_MEMBER_OFFSET, ANSI_NCM_LENGTH,
388                         opc);
389     proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_cluster, tvb,
390                         ANSI_OPC_OFFSET + ANSI_CLUSTER_OFFSET, ANSI_NCM_LENGTH,
391                         opc);
392     proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_network,tvb,
393                         ANSI_OPC_OFFSET + ANSI_NETWORK_OFFSET, ANSI_NCM_LENGTH,
394                         opc);
395
396     /* add full integer values of OPC as hidden for filtering purposes */
397     proto_tree_add_uint_hidden(label_opc_tree, hf_mtp3_24bit_opc, tvb, ANSI_OPC_OFFSET,
398                                ANSI_PC_LENGTH, opc);
399
400     /* SLS */
401     if (mtp3_standard == ANSI_STANDARD)
402     {
403         if (mtp3_use_ansi_5_bit_sls)
404             proto_tree_add_item(label_tree, hf_mtp3_ansi_5_bit_sls, tvb,
405                                 ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, TRUE);
406         else
407             proto_tree_add_item(label_tree, hf_mtp3_ansi_8_bit_sls, tvb,
408                                 ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, TRUE);
409     } else /* CHINESE_ITU_STANDARD */ {
410         proto_tree_add_item(label_tree, hf_mtp3_chinese_itu_sls, tvb,
411                             ANSI_SLS_OFFSET, ITU_SLS_LENGTH, FALSE);
412     }
413
414     break;
415   }
416
417   mtp3_addr_opc.type = mtp3_standard;
418   mtp3_addr_opc.pc = opc;
419   SET_ADDRESS(&pinfo->net_src, AT_SS7PC, sizeof(mtp3_addr_opc), (guint8 *) &mtp3_addr_opc);
420
421   mtp3_addr_dpc.type = mtp3_standard;
422   mtp3_addr_dpc.pc = dpc;
423   SET_ADDRESS(&pinfo->net_dst, AT_SS7PC, sizeof(mtp3_addr_dpc), (guint8 *) &mtp3_addr_dpc);
424 }
425
426 static void
427 dissect_mtp3_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
428 {
429   guint8 sio;
430   guint8 service_indicator;
431   tvbuff_t *payload_tvb = NULL;
432
433   sio               = tvb_get_guint8(tvb, SIO_OFFSET);
434   service_indicator = sio & SERVICE_INDICATOR_MASK;
435
436   switch (mtp3_standard) {
437   case ITU_STANDARD:
438     payload_tvb = tvb_new_subset(tvb, ITU_MTP_PAYLOAD_OFFSET, -1, -1);
439     break;
440   case ANSI_STANDARD:
441   case CHINESE_ITU_STANDARD:
442     payload_tvb = tvb_new_subset(tvb, ANSI_MTP_PAYLOAD_OFFSET, -1, -1);
443     break;
444   }
445
446   if (check_col(pinfo->cinfo, COL_INFO))
447       col_set_str(pinfo->cinfo, COL_INFO, "DATA ");
448
449   if (!dissector_try_port(mtp3_sio_dissector_table, service_indicator,
450                           payload_tvb, pinfo, tree))
451     call_dissector(data_handle, payload_tvb, pinfo, tree);
452 }
453
454 /* Code to actually dissect the packets */
455 static void
456 dissect_mtp3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
457 {
458
459   /* Set up structures needed to add the protocol subtree and manage it */
460   proto_item *mtp3_item = NULL;
461   proto_tree *mtp3_tree = NULL;
462
463   /* Make entries in Protocol column on summary display */
464   if (check_col(pinfo->cinfo, COL_PROTOCOL))
465     switch(mtp3_standard) {
466       case ITU_STANDARD:
467         col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Int. ITU)");
468         break;
469       case ANSI_STANDARD:
470         col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (ANSI)");
471         break;
472       case CHINESE_ITU_STANDARD:
473         col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Chin. ITU)");
474         break;
475     };      
476
477   if (tree) {
478     /* create display subtree for the protocol */
479     switch (mtp3_standard) {
480     case ITU_STANDARD:
481       mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0,
482                                       ITU_HEADER_LENGTH, TRUE);
483       break;
484     case ANSI_STANDARD:
485     case CHINESE_ITU_STANDARD:
486       mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0,
487                                       ANSI_HEADER_LENGTH, TRUE);
488       break;
489     }
490     mtp3_tree = proto_item_add_subtree(mtp3_item, ett_mtp3);
491
492   }
493
494   /* Dissect the packet (even if !tree so can call sub-dissectors and update
495    * the source and destination address columns) */
496   dissect_mtp3_sio(tvb, pinfo, mtp3_tree);
497   dissect_mtp3_routing_label(tvb, pinfo, mtp3_tree);
498   dissect_mtp3_payload(tvb, pinfo, tree);
499 }
500
501 void
502 proto_register_mtp3(void)
503 {
504
505   /* Setup list of header fields  See Section 1.6.1 for details*/
506   static hf_register_info hf[] = {
507     { &hf_mtp3_service_indicator,
508       { "Service indicator", "mtp3.service_indicator",
509         FT_UINT8, BASE_HEX, VALS(service_indicator_code_vals), SERVICE_INDICATOR_MASK,
510               "", HFILL }},
511     { &hf_mtp3_network_indicator,
512       { "Network indicator", "mtp3.network_indicator",
513               FT_UINT8, BASE_HEX, VALS(network_indicator_vals), NETWORK_INDICATOR_MASK,
514               "", HFILL }},
515     { &hf_mtp3_itu_spare,
516       { "Spare", "mtp3.spare",
517               FT_UINT8, BASE_HEX, NULL, SPARE_MASK,
518               "", HFILL }},
519     { &hf_mtp3_ansi_priority,
520       { "Priority", "mtp3.priority",
521               FT_UINT8, BASE_HEX, NULL, ANSI_PRIORITY_MASK,
522               "", HFILL }},
523     { &hf_mtp3_itu_opc,
524       { "OPC", "mtp3.opc",
525               FT_UINT32, BASE_DEC, NULL, ITU_OPC_MASK,
526               "", HFILL }},
527     { &hf_mtp3_24bit_opc,
528       { "OPC", "mtp3.opc",
529               FT_UINT32, BASE_DEC, NULL, ANSI_PC_MASK,
530               "", HFILL }},
531     { &hf_mtp3_ansi_opc,
532       { "DPC", "mtp3.ansi_opc",
533               FT_STRING, BASE_NONE, NULL, 0x0,
534               "", HFILL }},
535     { &hf_mtp3_chinese_opc,
536       { "DPC", "mtp3.chinese_opc",
537               FT_STRING, BASE_NONE, NULL, 0x0,
538               "", HFILL }},
539     { &hf_mtp3_opc_network,
540      { "OPC Network", "mtp3.opc.network",
541              FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
542              "", HFILL }},
543     { &hf_mtp3_opc_cluster,
544       { "OPC Cluster", "mtp3.opc.cluster",
545               FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
546               "", HFILL }},
547     { &hf_mtp3_opc_member,
548       { "OPC Member", "mtp3.opc.member",
549               FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
550               "", HFILL }},
551     { &hf_mtp3_itu_dpc,
552       { "DPC", "mtp3.dpc",
553               FT_UINT32, BASE_DEC, NULL, ITU_DPC_MASK,
554               "", HFILL }},
555     { &hf_mtp3_24bit_dpc,
556       { "DPC", "mtp3.dpc",
557               FT_UINT32, BASE_DEC, NULL, ANSI_PC_MASK,
558               "", HFILL }},
559     { &hf_mtp3_ansi_dpc,
560       { "DPC", "mtp3.ansi_dpc",
561               FT_STRING, BASE_NONE, NULL, 0x0,
562               "", HFILL }},
563     { &hf_mtp3_chinese_dpc,
564       { "DPC", "mtp3.chinese_dpc",
565               FT_STRING, BASE_NONE, NULL, 0x0,
566               "", HFILL }},
567     { &hf_mtp3_dpc_network,
568       { "DPC Network", "mtp3.dpc.network",
569               FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
570               "", HFILL }},
571     { &hf_mtp3_dpc_cluster,
572       { "DPC Cluster", "mtp3.dpc.cluster",
573               FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
574               "", HFILL }},
575     { &hf_mtp3_dpc_member,
576       { "DPC Member", "mtp3.dpc.member",
577               FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
578               "", HFILL }},
579     { &hf_mtp3_itu_sls,
580       { "Signalling Link Selector", "mtp3.sls",
581               FT_UINT32, BASE_DEC, NULL, ITU_SLS_MASK,
582               "", HFILL }},
583     { &hf_mtp3_ansi_5_bit_sls,
584       { "Signalling Link Selector", "mtp3.sls",
585               FT_UINT8, BASE_DEC, NULL, ANSI_5BIT_SLS_MASK,
586               "", HFILL }},
587     { &hf_mtp3_ansi_8_bit_sls,
588       { "Signalling Link Selector", "mtp3.sls",
589               FT_UINT8, BASE_DEC, NULL, ANSI_8BIT_SLS_MASK,
590               "", HFILL }},
591     { &hf_mtp3_chinese_itu_sls,
592       { "Signalling Link Selector", "mtp3.sls",
593               FT_UINT8, BASE_DEC, NULL, CHINESE_ITU_SLS_MASK,
594               "", HFILL }}
595   };
596
597   /* Setup protocol subtree array */
598   static gint *ett[] = {
599     &ett_mtp3,
600     &ett_mtp3_sio,
601     &ett_mtp3_label,
602     &ett_mtp3_label_dpc,
603     &ett_mtp3_label_opc
604   };
605
606   static enum_val_t mtp3_options[] = {
607     { "ITU",         ITU_STANDARD },
608     { "ANSI",        ANSI_STANDARD },
609     { "Chinese ITU", CHINESE_ITU_STANDARD },
610     { NULL, 0 }
611   };
612
613   static enum_val_t mtp3_net_addr_fmt_str_e[] = {
614     { "Decimal",                MTP3_NET_ADDR_FMT_DEC },
615     { "Hexadecimal",            MTP3_NET_ADDR_FMT_HEX },
616     { "NI-Decimal",             MTP3_NET_ADDR_FMT_NI_DEC },
617     { "NI-Hexadecimal",         MTP3_NET_ADDR_FMT_NI_HEX },
618     { "Dashed",                 MTP3_NET_ADDR_FMT_DASHED },
619     { NULL,                     0 }
620   };
621
622   /* Register the protocol name and description */
623   proto_mtp3 = proto_register_protocol("Message Transfer Part Level 3",
624                                        "MTP3", "mtp3");
625   register_dissector("mtp3", dissect_mtp3, proto_mtp3);
626
627   /* Required function calls to register the header fields and subtrees used */
628   proto_register_field_array(proto_mtp3, hf, array_length(hf));
629   proto_register_subtree_array(ett, array_length(ett));
630
631   mtp3_sio_dissector_table = register_dissector_table("mtp3.service_indicator",
632                                                       "MTP3 Service indicator",
633                                                       FT_UINT8, BASE_HEX);
634
635   mtp3_module = prefs_register_protocol(proto_mtp3, NULL);
636
637   prefs_register_enum_preference(mtp3_module, "standard", "MTP3 standard",
638                                  "The SS7 standard used in MTP3 packets",
639                                  (gint *)&mtp3_standard, mtp3_options, FALSE);
640
641   prefs_register_bool_preference(mtp3_module, "ansi_5_bit_sls",
642                                  "Use 5-bit SLS (ANSI only)",
643                                  "Use 5-bit (instead of 8-bit) SLS in ANSI MTP3 packets",
644                                  &mtp3_use_ansi_5_bit_sls);
645
646   prefs_register_enum_preference(mtp3_module, "net_addr_format", "Network Address Format",
647                                  "Format for point code in the network address columns",
648                                  (gint *)&mtp3_net_addr_fmt, mtp3_net_addr_fmt_str_e, FALSE);
649 }
650
651 void
652 proto_reg_handoff_mtp3(void)
653 {
654   dissector_handle_t mtp3_handle;        
655          
656   mtp3_handle = create_dissector_handle(dissect_mtp3, proto_mtp3);       
657                  
658   dissector_add("wtap_encap", WTAP_ENCAP_MTP3, mtp3_handle);     
659                  
660   data_handle = find_dissector("data");
661 }