2 * Routines for Message Transfer Part Level 3 dissection
3 * Copyright 2001, Michael Tuexen <Michael.Tuexen@icn.siemens.de>
4 * Updated for ANSI support by Jeff Morriss <jeff.morriss[AT]ulticom.com>
6 * $Id: packet-mtp3.c,v 1.12 2002/06/20 20:40:36 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * Copied from README.developer
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include <epan/packet.h>
38 /* Initialize the protocol and registered fields */
39 static int proto_mtp3 = -1;
40 static module_t *mtp3_module;
42 static int hf_mtp3_service_indicator = -1;
43 static int hf_mtp3_network_indicator = -1;
44 static int hf_mtp3_itu_spare = -1;
45 static int hf_mtp3_ansi_priority = -1;
46 static int hf_mtp3_itu_opc = -1;
47 static int hf_mtp3_opc_network = -1;
48 static int hf_mtp3_opc_cluster = -1;
49 static int hf_mtp3_opc_member = -1;
50 static int hf_mtp3_itu_dpc = -1;
51 static int hf_mtp3_dpc_network = -1;
52 static int hf_mtp3_dpc_cluster = -1;
53 static int hf_mtp3_dpc_member = -1;
54 static int hf_mtp3_itu_sls = -1;
55 static int hf_mtp3_ansi_5_bit_sls = -1;
56 static int hf_mtp3_ansi_8_bit_sls = -1;
58 /* Initialize the subtree pointers */
59 static gint ett_mtp3 = -1;
60 static gint ett_mtp3_sio = -1;
61 static gint ett_mtp3_label = -1;
62 static gint ett_mtp3_label_dpc = -1;
63 static gint ett_mtp3_label_opc = -1;
65 static dissector_table_t mtp3_sio_dissector_table;
67 #include <packet-mtp3.h>
68 Standard_Type mtp3_standard = ITU_STANDARD;
70 gboolean mtp3_use_ansi_5_bit_sls = FALSE;
74 #define ITU_ROUTING_LABEL_LENGTH 4
75 #define ITU_HEADER_LENGTH (SIO_LENGTH + ITU_ROUTING_LABEL_LENGTH)
76 #define ITU_SLS_LENGTH 1
79 #define ITU_SLS_OFFSET (SIO_OFFSET + ITU_HEADER_LENGTH - ITU_SLS_LENGTH)
80 #define ITU_ROUTING_LABEL_OFFSET (SIO_OFFSET + SIO_LENGTH)
81 #define ITU_MTP_PAYLOAD_OFFSET (SIO_OFFSET + ITU_HEADER_LENGTH)
83 #define ANSI_SLS_LENGTH 1
84 #define ANSI_ROUTING_LABEL_LENGTH (ANSI_PC_LENGTH + ANSI_PC_LENGTH + ANSI_SLS_LENGTH)
85 #define ANSI_HEADER_LENGTH (SIO_LENGTH + ANSI_ROUTING_LABEL_LENGTH)
87 #define ANSI_ROUTING_LABEL_OFFSET (SIO_OFFSET + SIO_LENGTH)
88 #define ANSI_DPC_OFFSET ANSI_ROUTING_LABEL_OFFSET
89 #define ANSI_OPC_OFFSET (ANSI_DPC_OFFSET + ANSI_PC_LENGTH)
90 #define ANSI_SLS_OFFSET (ANSI_OPC_OFFSET + ANSI_PC_LENGTH)
91 #define ANSI_MTP_PAYLOAD_OFFSET (SIO_OFFSET + ANSI_HEADER_LENGTH)
93 #define SERVICE_INDICATOR_MASK 0x0F
94 #define SPARE_MASK 0x30
95 #define ANSI_PRIORITY_MASK SPARE_MASK
96 #define NETWORK_INDICATOR_MASK 0xC0
97 #define ITU_DPC_MASK 0x00003FFF
98 #define ITU_OPC_MASK 0x0FFFC000
99 #define ITU_SLS_MASK 0xF0000000
101 #define ANSI_NETWORK_MASK 0x0000FF
102 #define ANSI_CLUSTER_MASK 0x00FF00
103 #define ANSI_MEMBER_MASK 0xFF0000
104 #define ANSI_5BIT_SLS_MASK 0x1F
105 #define ANSI_8BIT_SLS_MASK 0xFF
107 static const value_string service_indicator_code_vals[] = {
108 { 0x0, "Signalling Network Management Message (SNM)" },
109 { 0x1, "Maintenance Regular Message (MTN)" },
110 { 0x2, "Maintenance Special Message (MTNS)" },
114 { 0x6, "DUP (call and circuit related messages)" },
115 { 0x7, "DUP (facility registration and cancellation message)" },
116 { 0x8, "MTP testing user part" },
127 static const value_string network_indicator_vals[] = {
128 { 0x0, "International network" },
129 { 0x1, "Spare (for international use only)" },
130 { 0x2, "National network" },
131 { 0x3, "Reserved for national use" },
135 static dissector_handle_t data_handle;
138 dissect_mtp3_sio(tvbuff_t *tvb, proto_tree *mtp3_tree)
141 proto_item *sio_item;
142 proto_tree *sio_tree;
144 sio_item = proto_tree_add_text(mtp3_tree, tvb, SIO_OFFSET, SIO_LENGTH,
145 "Service information octet");
146 sio_tree = proto_item_add_subtree(sio_item, ett_mtp3_sio);
148 sio = tvb_get_guint8(tvb, SIO_OFFSET);
149 proto_tree_add_uint(sio_tree, hf_mtp3_network_indicator, tvb, SIO_OFFSET,
152 switch(mtp3_standard){
154 proto_tree_add_uint(sio_tree, hf_mtp3_ansi_priority, tvb, SIO_OFFSET,
158 proto_tree_add_uint(sio_tree, hf_mtp3_itu_spare, tvb, SIO_OFFSET,
163 proto_tree_add_uint(sio_tree, hf_mtp3_service_indicator, tvb, SIO_OFFSET,
168 dissect_mtp3_routing_label(tvbuff_t *tvb, proto_tree *mtp3_tree)
170 guint32 label, dpc, opc;
172 proto_item *label_item, *label_dpc_item, *label_opc_item;
173 proto_tree *label_tree, *label_dpc_tree, *label_opc_tree;
175 switch (mtp3_standard) {
177 label_item = proto_tree_add_text(mtp3_tree, tvb, ITU_ROUTING_LABEL_OFFSET,
178 ITU_ROUTING_LABEL_LENGTH, "Routing label");
179 label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
181 label = tvb_get_letohl(tvb, ITU_ROUTING_LABEL_OFFSET);
182 sls = tvb_get_guint8(tvb, ITU_ROUTING_LABEL_OFFSET);
184 proto_tree_add_uint(label_tree, hf_mtp3_itu_dpc, tvb,
185 ITU_ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH,
187 proto_tree_add_uint(label_tree, hf_mtp3_itu_opc, tvb,
188 ITU_ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH,
190 proto_tree_add_uint(label_tree, hf_mtp3_itu_sls, tvb, ITU_SLS_OFFSET,
191 ITU_SLS_LENGTH, sls);
195 /* this could be 5 or 8 bits */
196 sls = tvb_get_guint8(tvb, ANSI_SLS_OFFSET);
198 /* Create the Routing Label Tree */
199 label_item = proto_tree_add_text(mtp3_tree, tvb, ANSI_ROUTING_LABEL_OFFSET,
200 ANSI_ROUTING_LABEL_LENGTH,
202 label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
204 /* create the DPC tree */
205 dpc = tvb_get_ntoh24(tvb, ANSI_DPC_OFFSET);
206 label_dpc_item = proto_tree_add_text(label_tree, tvb, ANSI_DPC_OFFSET,
207 ANSI_PC_LENGTH, "DPC (%d-%d-%d)",
208 (dpc & ANSI_NETWORK_MASK),
209 ((dpc & ANSI_CLUSTER_MASK) >> 8),
210 ((dpc & ANSI_MEMBER_MASK) >> 16));
212 label_dpc_tree = proto_item_add_subtree(label_dpc_item, ett_mtp3_label_dpc);
214 proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_member, tvb,
215 ANSI_DPC_OFFSET, ANSI_PC_LENGTH, dpc);
216 proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_cluster,tvb,
217 ANSI_DPC_OFFSET, ANSI_PC_LENGTH, dpc);
218 proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_network,tvb,
219 ANSI_DPC_OFFSET, ANSI_PC_LENGTH, dpc);
221 /* create the OPC tree */
222 opc = tvb_get_ntoh24(tvb, ANSI_OPC_OFFSET);
224 label_opc_item = proto_tree_add_text(label_tree, tvb, ANSI_OPC_OFFSET,
225 ANSI_PC_LENGTH, "OPC (%d-%d-%d)",
226 (opc & ANSI_NETWORK_MASK),
227 ((opc & ANSI_CLUSTER_MASK) >> 8),
228 ((opc & ANSI_MEMBER_MASK) >> 16));
229 label_opc_tree = proto_item_add_subtree(label_opc_item, ett_mtp3_label_opc);
231 proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_member, tvb,
232 ANSI_OPC_OFFSET, ANSI_PC_LENGTH, opc);
233 proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_cluster, tvb,
234 ANSI_OPC_OFFSET, ANSI_PC_LENGTH, opc);
235 proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_network,tvb,
236 ANSI_OPC_OFFSET, ANSI_PC_LENGTH, opc);
239 if (mtp3_use_ansi_5_bit_sls)
240 proto_tree_add_item(label_tree, hf_mtp3_ansi_5_bit_sls, tvb,
241 ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, sls);
243 proto_tree_add_item(label_tree, hf_mtp3_ansi_8_bit_sls, tvb,
244 ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, sls);
250 dissect_mtp3_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
253 guint8 service_indicator;
254 tvbuff_t *payload_tvb = NULL;
256 sio = tvb_get_guint8(tvb, SIO_OFFSET);
257 service_indicator = sio & SERVICE_INDICATOR_MASK;
259 switch (mtp3_standard) {
261 payload_tvb = tvb_new_subset(tvb, ITU_MTP_PAYLOAD_OFFSET, -1, -1);
264 payload_tvb = tvb_new_subset(tvb, ANSI_MTP_PAYLOAD_OFFSET, -1, -1);
268 if (!dissector_try_port(mtp3_sio_dissector_table, service_indicator,
269 payload_tvb, pinfo, tree)) {
270 call_dissector(data_handle, payload_tvb, pinfo, tree);
271 if (check_col(pinfo->cinfo, COL_INFO))
272 col_append_str(pinfo->cinfo, COL_INFO, "DATA ");
276 /* Code to actually dissect the packets */
278 dissect_mtp3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
281 /* Set up structures needed to add the protocol subtree and manage it */
282 proto_item *mtp3_item = NULL;
283 proto_tree *mtp3_tree = NULL;
285 /* Make entries in Protocol column and Info column on summary display */
286 if (check_col(pinfo->cinfo, COL_PROTOCOL))
287 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3");
290 /* create display subtree for the protocol */
291 switch (mtp3_standard) {
293 mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0,
294 ITU_HEADER_LENGTH, FALSE);
297 mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0,
298 ANSI_HEADER_LENGTH, FALSE);
301 mtp3_tree = proto_item_add_subtree(mtp3_item, ett_mtp3);
303 /* dissect the packet */
304 dissect_mtp3_sio(tvb, mtp3_tree);
305 dissect_mtp3_routing_label(tvb, mtp3_tree);
308 /* Need to dissect payload even if !tree so can call sub-dissectors */
309 dissect_mtp3_payload(tvb, pinfo, tree);
313 proto_register_mtp3(void)
316 /* Setup list of header fields See Section 1.6.1 for details*/
317 static hf_register_info hf[] = {
318 { &hf_mtp3_service_indicator,
319 { "Service indicator", "mtp3.service_indicator",
320 FT_UINT8, BASE_HEX, VALS(service_indicator_code_vals), SERVICE_INDICATOR_MASK,
322 { &hf_mtp3_network_indicator,
323 { "Network indicator", "mtp3.network_indicator",
324 FT_UINT8, BASE_HEX, VALS(network_indicator_vals), NETWORK_INDICATOR_MASK,
326 { &hf_mtp3_itu_spare,
327 { "Spare", "mtp3.spare",
328 FT_UINT8, BASE_HEX, NULL, SPARE_MASK,
330 { &hf_mtp3_ansi_priority,
331 { "Priority", "mtp3.priority",
332 FT_UINT8, BASE_HEX, NULL, ANSI_PRIORITY_MASK,
336 FT_UINT32, BASE_DEC, NULL, ITU_OPC_MASK,
338 { &hf_mtp3_opc_network,
339 { "OPC Network", "mtp3.opc.network",
340 FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
342 { &hf_mtp3_opc_cluster,
343 { "OPC Cluster", "mtp3.opc.cluster",
344 FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
346 { &hf_mtp3_opc_member,
347 { "OPC Member", "mtp3.opc.member",
348 FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
352 FT_UINT32, BASE_DEC, NULL, ITU_DPC_MASK,
354 { &hf_mtp3_dpc_network,
355 { "DPC Network", "mtp3.dpc.network",
356 FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
358 { &hf_mtp3_dpc_cluster,
359 { "DPC Cluster", "mtp3.dpc.cluster",
360 FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
362 { &hf_mtp3_dpc_member,
363 { "DPC Member", "mtp3.dpc.member",
364 FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
367 { "Signalling Link Selector", "mtp3.sls",
368 FT_UINT32, BASE_DEC, NULL, ITU_SLS_MASK,
370 { &hf_mtp3_ansi_5_bit_sls,
371 { "Signalling Link Selector", "mtp3.sls",
372 FT_UINT8, BASE_DEC, NULL, ANSI_5BIT_SLS_MASK,
374 { &hf_mtp3_ansi_8_bit_sls,
375 { "Signalling Link Selector", "mtp3.sls",
376 FT_UINT8, BASE_DEC, NULL, ANSI_8BIT_SLS_MASK,
380 /* Setup protocol subtree array */
381 static gint *ett[] = {
389 static enum_val_t mtp3_options[] = {
390 { "ITU", ITU_STANDARD },
391 { "ANSI", ANSI_STANDARD },
395 /* Register the protocol name and description */
396 proto_mtp3 = proto_register_protocol("Message Transfer Part Level 3",
398 register_dissector("mtp3", dissect_mtp3, proto_mtp3);
400 /* Required function calls to register the header fields and subtrees used */
401 proto_register_field_array(proto_mtp3, hf, array_length(hf));
402 proto_register_subtree_array(ett, array_length(ett));
404 mtp3_sio_dissector_table = register_dissector_table("mtp3.service_indicator",
405 "MTP3 Service indicator",
408 mtp3_module = prefs_register_protocol(proto_mtp3, NULL);
410 /* Version 1.5 to 1.11 of this module used "mtp3_standard" */
411 prefs_register_obsolete_preference(mtp3_module, "mtp3_standard");
413 prefs_register_enum_preference(mtp3_module, "standard", "MTP3 standard",
414 "The SS7 standard used in MTP3 packets",
415 (gint *)&mtp3_standard, mtp3_options, FALSE);
417 prefs_register_bool_preference(mtp3_module, "ansi_5_bit_sls",
418 "Use 5-bit SLS (ANSI only)",
419 "Use 5-bit (instead of 8-bit) SLS in ANSI MTP3 packets",
420 &mtp3_use_ansi_5_bit_sls);
424 proto_reg_handoff_mtp3(void)
426 data_handle = find_dissector("data");