2 * Routines for Message Transfer Part Level 3 dissection
4 * It is (hopefully) compliant to:
7 * GF 001-9001 (Chinese ITU variant)
8 * JT-Q704 and NTT-Q704 (Japan)
10 * Note that the division of the Japan SLS into the SLC and A/B bit (for
11 * management messages) is not done.
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>
19 * Wireshark - Network traffic analyzer
20 * By Gerald Combs <gerald@wireshark.org>
21 * Copyright 1998 Gerald Combs
23 * Copied from README.developer
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.
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.
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.
47 #include <epan/packet.h>
49 #include <epan/prefs.h>
50 #include <epan/emem.h>
51 #include "packet-q708.h"
52 #include "packet-sccp.h"
54 /* Initialize the protocol and registered fields */
55 static int proto_mtp3 = -1;
57 static int mtp3_tap = -1;
59 static module_t *mtp3_module;
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;
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;
101 static dissector_table_t mtp3_sio_dissector_table;
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;
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;
115 static gint itu_pc_structure = ITU_PC_STRUCTURE_NONE;
116 static gint japan_pc_structure = JAPAN_PC_STRUCTURE_NONE;
118 #include <packet-mtp3.h>
119 gint mtp3_standard = ITU_STANDARD;
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;
132 #define ROUTING_LABEL_OFFSET (SIO_OFFSET + SIO_LENGTH)
134 #define ITU_ROUTING_LABEL_LENGTH 4
135 #define ITU_HEADER_LENGTH (SIO_LENGTH + ITU_ROUTING_LABEL_LENGTH)
137 #define ITU_SLS_OFFSET (SIO_OFFSET + ITU_HEADER_LENGTH - SLS_LENGTH)
138 #define ITU_MTP_PAYLOAD_OFFSET (SIO_OFFSET + ITU_HEADER_LENGTH)
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)
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)
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)
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)
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
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
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)" },
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" },
187 { 0xc, "AAL type2 Signaling" },
188 { 0xd, "Bearer Independent Call Control (BICC)" },
189 { 0xe, "Gateway Control Protocol" },
194 const value_string mtp3_service_indicator_code_short_vals[] = {
202 { 0x7, "DUP (FAC/CANC)" },
206 { 0xc, "AAL type 2" },
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" },
220 static dissector_handle_t data_handle;
224 * helper routine to format a point code in structured form
228 mtp3_pc_to_str_buf(const guint32 pc, gchar *buf, int buf_len)
230 switch (mtp3_standard)
233 switch (itu_pc_structure) {
234 case ITU_PC_STRUCTURE_NONE:
235 g_snprintf(buf, buf_len, "%u", pc);
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);
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);
246 DISSECTOR_ASSERT_NOT_REACHED();
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));
254 switch (japan_pc_structure) {
255 case JAPAN_PC_STRUCTURE_NONE:
256 g_snprintf(buf, buf_len, "%u", pc);
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));
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));
267 DISSECTOR_ASSERT_NOT_REACHED();
271 DISSECTOR_ASSERT_NOT_REACHED();
275 #define MAX_STRUCTURED_PC_LENGTH 20
278 mtp3_pc_to_str(const guint32 pc)
282 str=ep_alloc(MAX_STRUCTURED_PC_LENGTH);
283 mtp3_pc_to_str_buf(pc, str, MAX_STRUCTURED_PC_LENGTH);
288 mtp3_pc_structured(void)
290 if ((mtp3_standard == ITU_STANDARD) && (itu_pc_structure == ITU_PC_STRUCTURE_NONE))
292 else if ((mtp3_standard == JAPAN_STANDARD) && (japan_pc_structure == JAPAN_PC_STRUCTURE_NONE))
299 * helper routine to format address to string
303 mtp3_addr_to_str_buf(const mtp3_addr_pc_t *addr_pc_p,
304 gchar *buf, int buf_len)
306 switch (mtp3_addr_fmt)
308 case MTP3_ADDR_FMT_DEC:
309 switch (addr_pc_p->type)
312 g_snprintf(buf, buf_len, "%u", addr_pc_p->pc & ITU_PC_MASK);
315 g_snprintf(buf, buf_len, "%u", addr_pc_p->pc & JAPAN_PC_MASK);
318 /* assuming 24-bit */
319 g_snprintf(buf, buf_len, "%u", addr_pc_p->pc & ANSI_PC_MASK);
324 case MTP3_ADDR_FMT_HEX:
325 switch (addr_pc_p->type)
328 g_snprintf(buf, buf_len, "%x", addr_pc_p->pc & ITU_PC_MASK);
331 g_snprintf(buf, buf_len, "%x", addr_pc_p->pc & JAPAN_PC_MASK);
334 /* assuming 24-bit */
335 g_snprintf(buf, buf_len, "%x", addr_pc_p->pc & ANSI_PC_MASK);
340 case MTP3_ADDR_FMT_NI_DEC:
341 switch (addr_pc_p->type)
344 g_snprintf(buf, buf_len, "%u:%u", addr_pc_p->ni, addr_pc_p->pc & ITU_PC_MASK);
347 g_snprintf(buf, buf_len, "%u:%u", addr_pc_p->ni, addr_pc_p->pc & JAPAN_PC_MASK);
350 /* assuming 24-bit */
351 g_snprintf(buf, buf_len, "%u:%u", addr_pc_p->ni, addr_pc_p->pc & ANSI_PC_MASK);
356 case MTP3_ADDR_FMT_NI_HEX:
357 switch (addr_pc_p->type)
360 g_snprintf(buf, buf_len, "%u:%x", addr_pc_p->ni, addr_pc_p->pc & ITU_PC_MASK);
363 g_snprintf(buf, buf_len, "%u:%x", addr_pc_p->ni, addr_pc_p->pc & JAPAN_PC_MASK);
366 /* assuming 24-bit */
367 g_snprintf(buf, buf_len, "%u:%x", addr_pc_p->ni, addr_pc_p->pc & ANSI_PC_MASK);
375 case MTP3_ADDR_FMT_DASHED:
376 mtp3_pc_to_str_buf(addr_pc_p->pc, buf, buf_len);
382 mtp3_pc_hash(const mtp3_addr_pc_t *addr_pc_p) {
385 switch (addr_pc_p->type)
388 pc = (addr_pc_p->pc & ITU_PC_MASK) | ((addr_pc_p->ni % 4) << 14) ;
391 /* assuming 24-bit */
392 pc = (addr_pc_p->pc & ANSI_PC_MASK) | ((addr_pc_p->ni) << 24) ;
399 /* Common function for dissecting 3-byte (ANSI or China) PCs. */
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)
405 proto_item *pc_item, *hidden_item;
407 char pc_string[MAX_STRUCTURED_PC_LENGTH];
409 pc = tvb_get_letoh24(tvb, offset);
410 mtp3_pc_to_str_buf(pc, pc_string, sizeof(pc_string));
412 pc_item = proto_tree_add_string(tree, hf_pc_string, tvb, offset, ANSI_PC_LENGTH, pc_string);
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.
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);
427 pc_tree = proto_item_add_subtree(pc_item, ett_pc);
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);
433 /* add full integer values of DPC as hidden for filtering purposes */
435 hidden_item = proto_tree_add_uint(pc_tree, hf_dpc, tvb, offset, ANSI_PC_LENGTH, pc);
436 PROTO_ITEM_SET_HIDDEN(hidden_item);
439 hidden_item = proto_tree_add_uint(pc_tree, hf_pc, tvb, offset, ANSI_PC_LENGTH, pc);
440 PROTO_ITEM_SET_HIDDEN(hidden_item);
445 dissect_mtp3_sio(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mtp3_tree, void ** const pd_save)
448 proto_item *sio_item;
449 proto_tree *sio_tree;
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);
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);
457 mtp3_addr_opc->ni = (sio & NETWORK_INDICATOR_MASK) >> 6;
458 mtp3_addr_dpc->ni = (sio & NETWORK_INDICATOR_MASK) >> 6;
460 switch(mtp3_standard){
462 proto_tree_add_uint(sio_tree, hf_mtp3_ansi_priority, tvb, SIO_OFFSET, SIO_LENGTH, sio);
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);
469 proto_tree_add_uint(sio_tree, hf_mtp3_itu_spare, tvb, SIO_OFFSET, SIO_LENGTH, sio);
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...
475 proto_tree_add_uint(sio_tree, hf_mtp3_itu_spare, tvb, SIO_OFFSET, SIO_LENGTH, sio);
479 proto_tree_add_uint(sio_tree, hf_mtp3_service_indicator, tvb, SIO_OFFSET, SIO_LENGTH, sio);
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);
487 dissect_mtp3_routing_label(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mtp3_tree)
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;
498 switch (mtp3_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);
503 label = tvb_get_letohl(tvb, ROUTING_LABEL_OFFSET);
505 opc = (label & ITU_OPC_MASK) >> 14;
506 dpc = label & ITU_DPC_MASK;
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);
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)
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);
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)
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);
532 proto_tree_add_uint(label_tree, hf_mtp3_itu_sls, tvb, ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, label);
536 case CHINESE_ITU_STANDARD:
537 if (mtp3_standard == ANSI_STANDARD)
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;
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);
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);
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);
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);
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);
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);
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));
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));
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);
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);
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);
605 DISSECTOR_ASSERT_NOT_REACHED();
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);
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);
618 dissect_mtp3_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
621 guint8 service_indicator;
622 tvbuff_t *payload_tvb = NULL;
624 sio = tvb_get_guint8(tvb, SIO_OFFSET);
625 service_indicator = sio & SERVICE_INDICATOR_MASK;
627 switch (mtp3_standard) {
629 payload_tvb = tvb_new_subset_remaining(tvb, ITU_MTP_PAYLOAD_OFFSET);
632 case CHINESE_ITU_STANDARD:
633 payload_tvb = tvb_new_subset_remaining(tvb, ANSI_MTP_PAYLOAD_OFFSET);
636 payload_tvb = tvb_new_subset_remaining(tvb, JAPAN_MTP_PAYLOAD_OFFSET);
639 DISSECTOR_ASSERT_NOT_REACHED();
642 col_set_str(pinfo->cinfo, COL_INFO, "DATA ");
644 if (!dissector_try_uint(mtp3_sio_dissector_table, service_indicator, payload_tvb, pinfo, tree))
645 call_dissector(data_handle, payload_tvb, pinfo, tree);
648 #define HEURISTIC_FAILED_STANDARD 0xffff
650 heur_mtp3_standard(tvbuff_t *tvb, packet_info *pinfo, guint8 si)
656 len = tvb_length(tvb);
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)) {
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;
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;
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;
677 return HEURISTIC_FAILED_STANDARD;
681 return HEURISTIC_FAILED_STANDARD;
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" },
694 /* Code to actually dissect the packets */
696 dissect_mtp3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
699 mtp3_tap_rec_t* tap_rec = ep_alloc0(sizeof(mtp3_tap_rec_t));
700 guint heuristic_standard, pref_mtp3_standard;
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;
707 pref_mtp3_standard = mtp3_standard;
709 mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0, 0, ENC_NA);
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"));
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;
720 PROTO_ITEM_SET_GENERATED(gen_item);
723 /* Make entries in Protocol column on summary display */
724 switch(mtp3_standard) {
726 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Int. ITU)");
727 proto_item_set_len(mtp3_item, ITU_HEADER_LENGTH);
730 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (ANSI)");
731 proto_item_set_len(mtp3_item, ANSI_HEADER_LENGTH);
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);
738 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Japan)");
739 proto_item_set_len(mtp3_item, JAPAN_HEADER_LENGTH);
744 /* create display subtree for the protocol */
745 mtp3_tree = proto_item_add_subtree(mtp3_item, ett_mtp3);
748 mtp3_addr_opc = ep_alloc0(sizeof(mtp3_addr_pc_t));
749 mtp3_addr_dpc = ep_alloc0(sizeof(mtp3_addr_pc_t));
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);
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));
759 tap_rec->si_code = (tvb_get_guint8(tvb, SIO_OFFSET) & SERVICE_INDICATOR_MASK);
760 tap_rec->size = tvb_length(tvb);
762 tap_queue_packet(mtp3_tap, pinfo, tap_rec);
764 dissect_mtp3_payload(tvb, pinfo, tree);
765 pinfo->private_data = pd_save;
767 mtp3_standard = pref_mtp3_standard;
772 proto_register_mtp3(void)
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 }}
811 /* Setup protocol subtree array */
812 static gint *ett[] = {
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 },
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 },
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 },
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 },
851 /* Register the protocol name and description */
852 proto_mtp3 = proto_register_protocol("Message Transfer Part Level 3",
854 register_dissector("mtp3", dissect_mtp3, proto_mtp3);
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));
860 mtp3_sio_dissector_table = register_dissector_table("mtp3.service_indicator",
861 "MTP3 Service indicator",
864 mtp3_tap = register_tap("mtp3");
866 mtp3_module = prefs_register_protocol(proto_mtp3, NULL);
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);
873 prefs_register_enum_preference(mtp3_module, "standard", "MTP3 standard",
874 "The SS7 standard used in MTP3 packets",
875 &mtp3_standard, mtp3_options, FALSE);
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);
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);
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);
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);
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);
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);
907 proto_reg_handoff_mtp3(void)
909 dissector_handle_t mtp3_handle;
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);
915 data_handle = find_dissector("data");