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