2 * Routines for Message Transfer Part Level 3 dissection
4 * It is (hopefully) compliant to:
7 * GF 001-9001 (Chinese ITU variant)
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>
12 * $Id: packet-mtp3.c,v 1.21 2003/09/05 23:54:10 guy Exp $
14 * Ethereal - Network traffic analyzer
15 * By Gerald Combs <gerald@ethereal.com>
16 * Copyright 1998 Gerald Combs
18 * Copied from README.developer
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.
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.
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.
41 #ifdef NEED_SNPRINTF_H
45 #include <epan/packet.h>
48 /* Initialize the protocol and registered fields */
49 static int proto_mtp3 = -1;
50 static module_t *mtp3_module;
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_ansi_opc = -1;
58 static int hf_mtp3_chinese_opc = -1;
59 static int hf_mtp3_opc_network = -1;
60 static int hf_mtp3_opc_cluster = -1;
61 static int hf_mtp3_opc_member = -1;
62 static int hf_mtp3_itu_dpc = -1;
63 static int hf_mtp3_ansi_dpc = -1;
64 static int hf_mtp3_chinese_dpc = -1;
65 static int hf_mtp3_dpc_network = -1;
66 static int hf_mtp3_dpc_cluster = -1;
67 static int hf_mtp3_dpc_member = -1;
68 static int hf_mtp3_itu_sls = -1;
69 static int hf_mtp3_ansi_5_bit_sls = -1;
70 static int hf_mtp3_ansi_8_bit_sls = -1;
71 static int hf_mtp3_chinese_itu_sls = -1;
73 /* Initialize the subtree pointers */
74 static gint ett_mtp3 = -1;
75 static gint ett_mtp3_sio = -1;
76 static gint ett_mtp3_label = -1;
77 static gint ett_mtp3_label_dpc = -1;
78 static gint ett_mtp3_label_opc = -1;
80 static dissector_table_t mtp3_sio_dissector_table;
82 #include <packet-mtp3.h>
83 Standard_Type mtp3_standard = ITU_STANDARD;
85 static gboolean mtp3_use_ansi_5_bit_sls = FALSE;
89 #define ITU_ROUTING_LABEL_LENGTH 4
90 #define ITU_HEADER_LENGTH (SIO_LENGTH + ITU_ROUTING_LABEL_LENGTH)
91 #define ITU_SLS_LENGTH 1
94 #define ITU_SLS_OFFSET (SIO_OFFSET + ITU_HEADER_LENGTH - ITU_SLS_LENGTH)
95 #define ITU_ROUTING_LABEL_OFFSET (SIO_OFFSET + SIO_LENGTH)
96 #define ITU_MTP_PAYLOAD_OFFSET (SIO_OFFSET + ITU_HEADER_LENGTH)
98 #define ANSI_SLS_LENGTH 1
99 #define ANSI_ROUTING_LABEL_LENGTH (ANSI_PC_LENGTH + ANSI_PC_LENGTH + ANSI_SLS_LENGTH)
100 #define ANSI_HEADER_LENGTH (SIO_LENGTH + ANSI_ROUTING_LABEL_LENGTH)
102 #define ANSI_ROUTING_LABEL_OFFSET (SIO_OFFSET + SIO_LENGTH)
103 #define ANSI_DPC_OFFSET ANSI_ROUTING_LABEL_OFFSET
104 #define ANSI_OPC_OFFSET (ANSI_DPC_OFFSET + ANSI_PC_LENGTH)
105 #define ANSI_SLS_OFFSET (ANSI_OPC_OFFSET + ANSI_PC_LENGTH)
106 #define ANSI_MTP_PAYLOAD_OFFSET (SIO_OFFSET + ANSI_HEADER_LENGTH)
108 #define SERVICE_INDICATOR_MASK 0x0F
109 #define SPARE_MASK 0x30
110 #define ANSI_PRIORITY_MASK SPARE_MASK
111 #define NETWORK_INDICATOR_MASK 0xC0
112 #define ITU_DPC_MASK 0x00003FFF
113 #define ITU_OPC_MASK 0x0FFFC000
114 #define ITU_SLS_MASK 0xF0000000
116 #define ANSI_NETWORK_MASK 0x0000FF
117 #define ANSI_CLUSTER_MASK 0x00FF00
118 #define ANSI_MEMBER_MASK 0xFF0000
119 #define ANSI_5BIT_SLS_MASK 0x1F
120 #define ANSI_8BIT_SLS_MASK 0xFF
121 #define CHINESE_ITU_SLS_MASK 0xF
123 static const value_string service_indicator_code_vals[] = {
124 { 0x0, "Signalling Network Management Message (SNM)" },
125 { 0x1, "Maintenance Regular Message (MTN)" },
126 { 0x2, "Maintenance Special Message (MTNS)" },
130 { 0x6, "DUP (call and circuit related messages)" },
131 { 0x7, "DUP (facility registration and cancellation message)" },
132 { 0x8, "MTP testing user part" },
143 static const value_string network_indicator_vals[] = {
144 { 0x0, "International network" },
145 { 0x1, "Spare (for international use only)" },
146 { 0x2, "National network" },
147 { 0x3, "Reserved for national use" },
151 static dissector_handle_t data_handle;
154 dissect_mtp3_sio(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mtp3_tree)
157 proto_item *sio_item;
158 proto_tree *sio_tree;
160 sio_item = proto_tree_add_text(mtp3_tree, tvb, SIO_OFFSET, SIO_LENGTH,
161 "Service information octet");
162 sio_tree = proto_item_add_subtree(sio_item, ett_mtp3_sio);
164 sio = tvb_get_guint8(tvb, SIO_OFFSET);
165 proto_tree_add_uint(sio_tree, hf_mtp3_network_indicator, tvb, SIO_OFFSET,
168 switch(mtp3_standard){
170 proto_tree_add_uint(sio_tree, hf_mtp3_ansi_priority, tvb, SIO_OFFSET,
174 case CHINESE_ITU_STANDARD:
175 proto_tree_add_uint(sio_tree, hf_mtp3_itu_spare, tvb, SIO_OFFSET,
180 proto_tree_add_uint(sio_tree, hf_mtp3_service_indicator, tvb, SIO_OFFSET,
183 /* Store the SI so that subidissectors know what SI this msg is */
184 pinfo->private_data = (void *)(sio & SERVICE_INDICATOR_MASK);
188 dissect_mtp3_routing_label(tvbuff_t *tvb, proto_tree *mtp3_tree)
190 guint32 label, dpc, opc;
192 proto_item *label_item, *label_dpc_item, *label_opc_item;
193 proto_tree *label_tree, *label_dpc_tree, *label_opc_tree;
194 char pc[ANSI_PC_STRING_LENGTH];
199 switch (mtp3_standard) {
201 label_item = proto_tree_add_text(mtp3_tree, tvb, ITU_ROUTING_LABEL_OFFSET,
202 ITU_ROUTING_LABEL_LENGTH, "Routing label");
203 label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
205 label = tvb_get_letohl(tvb, ITU_ROUTING_LABEL_OFFSET);
206 sls = tvb_get_guint8(tvb, ITU_SLS_OFFSET);
208 proto_tree_add_uint(label_tree, hf_mtp3_itu_dpc, tvb,
209 ITU_ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH,
211 proto_tree_add_uint(label_tree, hf_mtp3_itu_opc, tvb,
212 ITU_ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH,
214 proto_tree_add_uint(label_tree, hf_mtp3_itu_sls, tvb, ITU_SLS_OFFSET,
215 ITU_SLS_LENGTH, sls);
219 case CHINESE_ITU_STANDARD:
220 if (mtp3_standard == ANSI_STANDARD)
222 hf_dpc_string = &hf_mtp3_ansi_dpc;
223 hf_opc_string = &hf_mtp3_ansi_opc;
224 } else /* CHINESE_ITU_STANDARD */ {
225 hf_dpc_string = &hf_mtp3_chinese_dpc;
226 hf_opc_string = &hf_mtp3_chinese_opc;
229 /* Create the Routing Label Tree */
230 label_item = proto_tree_add_text(mtp3_tree, tvb, ANSI_ROUTING_LABEL_OFFSET,
231 ANSI_ROUTING_LABEL_LENGTH,
233 label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
235 /* create the DPC tree */
236 dpc = tvb_get_ntoh24(tvb, ANSI_DPC_OFFSET);
237 snprintf(pc, sizeof(pc), "%d-%d-%d", (dpc & ANSI_NETWORK_MASK),
238 ((dpc & ANSI_CLUSTER_MASK) >> 8),
239 ((dpc & ANSI_MEMBER_MASK) >> 16));
241 label_dpc_item = proto_tree_add_string_format(label_tree, *hf_dpc_string,
242 tvb, ANSI_DPC_OFFSET,
246 label_dpc_tree = proto_item_add_subtree(label_dpc_item, ett_mtp3_label_dpc);
248 proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_member, tvb,
249 ANSI_DPC_OFFSET + ANSI_MEMBER_OFFSET, ANSI_NCM_LENGTH,
251 proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_cluster,tvb,
252 ANSI_DPC_OFFSET + ANSI_CLUSTER_OFFSET, ANSI_NCM_LENGTH,
254 proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_network,tvb,
255 ANSI_DPC_OFFSET + ANSI_NETWORK_OFFSET, ANSI_NCM_LENGTH,
258 /* create the OPC tree */
259 opc = tvb_get_ntoh24(tvb, ANSI_OPC_OFFSET);
260 snprintf(pc, sizeof(pc), "%d-%d-%d", (opc & ANSI_NETWORK_MASK),
261 ((opc & ANSI_CLUSTER_MASK) >> 8),
262 ((opc & ANSI_MEMBER_MASK) >> 16));
263 label_opc_item = proto_tree_add_string_format(label_tree, *hf_opc_string,
264 tvb, ANSI_OPC_OFFSET,
268 label_opc_tree = proto_item_add_subtree(label_opc_item, ett_mtp3_label_opc);
270 proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_member, tvb,
271 ANSI_OPC_OFFSET + ANSI_MEMBER_OFFSET, ANSI_NCM_LENGTH,
273 proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_cluster, tvb,
274 ANSI_OPC_OFFSET + ANSI_CLUSTER_OFFSET, ANSI_NCM_LENGTH,
276 proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_network,tvb,
277 ANSI_OPC_OFFSET + ANSI_NETWORK_OFFSET, ANSI_NCM_LENGTH,
281 if (mtp3_standard == ANSI_STANDARD)
283 if (mtp3_use_ansi_5_bit_sls)
284 proto_tree_add_item(label_tree, hf_mtp3_ansi_5_bit_sls, tvb,
285 ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, TRUE);
287 proto_tree_add_item(label_tree, hf_mtp3_ansi_8_bit_sls, tvb,
288 ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, TRUE);
289 } else /* CHINESE_ITU_STANDARD */ {
290 proto_tree_add_item(label_tree, hf_mtp3_chinese_itu_sls, tvb,
291 ANSI_SLS_OFFSET, ITU_SLS_LENGTH, FALSE);
299 dissect_mtp3_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
302 guint8 service_indicator;
303 tvbuff_t *payload_tvb = NULL;
305 sio = tvb_get_guint8(tvb, SIO_OFFSET);
306 service_indicator = sio & SERVICE_INDICATOR_MASK;
308 switch (mtp3_standard) {
310 payload_tvb = tvb_new_subset(tvb, ITU_MTP_PAYLOAD_OFFSET, -1, -1);
313 case CHINESE_ITU_STANDARD:
314 payload_tvb = tvb_new_subset(tvb, ANSI_MTP_PAYLOAD_OFFSET, -1, -1);
318 if (check_col(pinfo->cinfo, COL_INFO))
319 col_set_str(pinfo->cinfo, COL_INFO, "DATA ");
321 if (!dissector_try_port(mtp3_sio_dissector_table, service_indicator,
322 payload_tvb, pinfo, tree))
323 call_dissector(data_handle, payload_tvb, pinfo, tree);
326 /* Code to actually dissect the packets */
328 dissect_mtp3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
331 /* Set up structures needed to add the protocol subtree and manage it */
332 proto_item *mtp3_item = NULL;
333 proto_tree *mtp3_tree = NULL;
335 /* Make entries in Protocol column and Info column on summary display */
336 if (check_col(pinfo->cinfo, COL_PROTOCOL))
337 switch(mtp3_standard) {
339 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Int. ITU)");
342 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (ANSI)");
344 case CHINESE_ITU_STANDARD:
345 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Chin. ITU)");
350 /* create display subtree for the protocol */
351 switch (mtp3_standard) {
353 mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0,
354 ITU_HEADER_LENGTH, TRUE);
357 case CHINESE_ITU_STANDARD:
358 mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0,
359 ANSI_HEADER_LENGTH, TRUE);
362 mtp3_tree = proto_item_add_subtree(mtp3_item, ett_mtp3);
366 /* Dissect the packet (even if !tree so can call sub-dissectors) */
367 dissect_mtp3_sio(tvb, pinfo, mtp3_tree);
369 dissect_mtp3_routing_label(tvb, mtp3_tree);
370 dissect_mtp3_payload(tvb, pinfo, tree);
374 proto_register_mtp3(void)
377 /* Setup list of header fields See Section 1.6.1 for details*/
378 static hf_register_info hf[] = {
379 { &hf_mtp3_service_indicator,
380 { "Service indicator", "mtp3.service_indicator",
381 FT_UINT8, BASE_HEX, VALS(service_indicator_code_vals), SERVICE_INDICATOR_MASK,
383 { &hf_mtp3_network_indicator,
384 { "Network indicator", "mtp3.network_indicator",
385 FT_UINT8, BASE_HEX, VALS(network_indicator_vals), NETWORK_INDICATOR_MASK,
387 { &hf_mtp3_itu_spare,
388 { "Spare", "mtp3.spare",
389 FT_UINT8, BASE_HEX, NULL, SPARE_MASK,
391 { &hf_mtp3_ansi_priority,
392 { "Priority", "mtp3.priority",
393 FT_UINT8, BASE_HEX, NULL, ANSI_PRIORITY_MASK,
397 FT_UINT32, BASE_DEC, NULL, ITU_OPC_MASK,
400 { "DPC", "mtp3.ansi_opc",
401 FT_STRING, BASE_NONE, NULL, 0x0,
403 { &hf_mtp3_chinese_opc,
404 { "DPC", "mtp3.chinese_opc",
405 FT_STRING, BASE_NONE, NULL, 0x0,
407 { &hf_mtp3_opc_network,
408 { "OPC Network", "mtp3.opc.network",
409 FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
411 { &hf_mtp3_opc_cluster,
412 { "OPC Cluster", "mtp3.opc.cluster",
413 FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
415 { &hf_mtp3_opc_member,
416 { "OPC Member", "mtp3.opc.member",
417 FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
421 FT_UINT32, BASE_DEC, NULL, ITU_DPC_MASK,
424 { "DPC", "mtp3.ansi_dpc",
425 FT_STRING, BASE_NONE, NULL, 0x0,
427 { &hf_mtp3_chinese_dpc,
428 { "DPC", "mtp3.chinese_dpc",
429 FT_STRING, BASE_NONE, NULL, 0x0,
431 { &hf_mtp3_dpc_network,
432 { "DPC Network", "mtp3.dpc.network",
433 FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
435 { &hf_mtp3_dpc_cluster,
436 { "DPC Cluster", "mtp3.dpc.cluster",
437 FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
439 { &hf_mtp3_dpc_member,
440 { "DPC Member", "mtp3.dpc.member",
441 FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
444 { "Signalling Link Selector", "mtp3.sls",
445 FT_UINT32, BASE_DEC, NULL, ITU_SLS_MASK,
447 { &hf_mtp3_ansi_5_bit_sls,
448 { "Signalling Link Selector", "mtp3.sls",
449 FT_UINT8, BASE_DEC, NULL, ANSI_5BIT_SLS_MASK,
451 { &hf_mtp3_ansi_8_bit_sls,
452 { "Signalling Link Selector", "mtp3.sls",
453 FT_UINT8, BASE_DEC, NULL, ANSI_8BIT_SLS_MASK,
455 { &hf_mtp3_chinese_itu_sls,
456 { "Signalling Link Selector", "mtp3.sls",
457 FT_UINT8, BASE_DEC, NULL, CHINESE_ITU_SLS_MASK,
461 /* Setup protocol subtree array */
462 static gint *ett[] = {
470 static enum_val_t mtp3_options[] = {
471 { "ITU", ITU_STANDARD },
472 { "ANSI", ANSI_STANDARD },
473 { "Chinese ITU", CHINESE_ITU_STANDARD },
477 /* Register the protocol name and description */
478 proto_mtp3 = proto_register_protocol("Message Transfer Part Level 3",
480 register_dissector("mtp3", dissect_mtp3, proto_mtp3);
482 /* Required function calls to register the header fields and subtrees used */
483 proto_register_field_array(proto_mtp3, hf, array_length(hf));
484 proto_register_subtree_array(ett, array_length(ett));
486 mtp3_sio_dissector_table = register_dissector_table("mtp3.service_indicator",
487 "MTP3 Service indicator",
490 mtp3_module = prefs_register_protocol(proto_mtp3, NULL);
492 prefs_register_enum_preference(mtp3_module, "standard", "MTP3 standard",
493 "The SS7 standard used in MTP3 packets",
494 (gint *)&mtp3_standard, mtp3_options, FALSE);
496 prefs_register_bool_preference(mtp3_module, "ansi_5_bit_sls",
497 "Use 5-bit SLS (ANSI only)",
498 "Use 5-bit (instead of 8-bit) SLS in ANSI MTP3 packets",
499 &mtp3_use_ansi_5_bit_sls);
503 proto_reg_handoff_mtp3(void)
505 data_handle = find_dissector("data");