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.11 2002/03/04 22:39:22 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_sls = -1;
57 /* Initialize the subtree pointers */
58 static gint ett_mtp3 = -1;
59 static gint ett_mtp3_sio = -1;
60 static gint ett_mtp3_label = -1;
61 static gint ett_mtp3_label_dpc = -1;
62 static gint ett_mtp3_label_opc = -1;
64 static dissector_table_t mtp3_sio_dissector_table;
66 #include <packet-mtp3.h>
67 Standard_Type mtp3_standard = ITU_STANDARD;
71 #define ITU_ROUTING_LABEL_LENGTH 4
72 #define ITU_HEADER_LENGTH (SIO_LENGTH + ITU_ROUTING_LABEL_LENGTH)
73 #define ITU_SLS_LENGTH 1
76 #define ITU_SLS_OFFSET (SIO_OFFSET + ITU_HEADER_LENGTH - ITU_SLS_LENGTH)
77 #define ITU_ROUTING_LABEL_OFFSET (SIO_OFFSET + SIO_LENGTH)
78 #define ITU_MTP_PAYLOAD_OFFSET (SIO_OFFSET + ITU_HEADER_LENGTH)
80 #define ANSI_SLS_LENGTH 1
81 #define ANSI_ROUTING_LABEL_LENGTH (ANSI_PC_LENGTH + ANSI_PC_LENGTH + ANSI_SLS_LENGTH)
82 #define ANSI_HEADER_LENGTH (SIO_LENGTH + ANSI_ROUTING_LABEL_LENGTH)
84 #define ANSI_ROUTING_LABEL_OFFSET (SIO_OFFSET + SIO_LENGTH)
85 #define ANSI_DPC_OFFSET ANSI_ROUTING_LABEL_OFFSET
86 #define ANSI_OPC_OFFSET (ANSI_DPC_OFFSET + ANSI_PC_LENGTH)
87 #define ANSI_SLS_OFFSET (ANSI_OPC_OFFSET + ANSI_PC_LENGTH)
88 #define ANSI_MTP_PAYLOAD_OFFSET (SIO_OFFSET + ANSI_HEADER_LENGTH)
90 #define SERVICE_INDICATOR_MASK 0x0F
91 #define SPARE_MASK 0x30
92 #define ANSI_PRIORITY_MASK SPARE_MASK
93 #define NETWORK_INDICATOR_MASK 0xC0
94 #define ITU_DPC_MASK 0x00003FFF
95 #define ITU_OPC_MASK 0x0FFFC000
96 #define ITU_SLS_MASK 0xF0000000
98 #define ANSI_NETWORK_MASK 0x0000FF
99 #define ANSI_CLUSTER_MASK 0x00FF00
100 #define ANSI_MEMBER_MASK 0xFF0000
101 #define ANSI_5BIT_SLS_MASK 0x1F
102 /* TODO: eventually add support for ANSI 8-bit SLS */
103 #define ANSI_8BIT_SLS_MASK 0xFF
105 static const value_string service_indicator_code_vals[] = {
106 { 0x0, "Signalling Network Management Message (SNM)" },
107 { 0x1, "Maintenance Regular Message (MTN)" },
108 { 0x2, "Maintenance Special Message (MTNS)" },
112 { 0x6, "DUP (call and circuit related messages)" },
113 { 0x7, "DUP (facility registration and cancellation message)" },
114 { 0x8, "MTP testing user part" },
125 static const value_string network_indicator_vals[] = {
126 { 0x0, "International network" },
127 { 0x1, "Spare (for international use only)" },
128 { 0x2, "National network" },
129 { 0x3, "Reserved for national use" },
133 static dissector_handle_t data_handle;
136 dissect_mtp3_sio(tvbuff_t *tvb, proto_tree *mtp3_tree)
139 proto_item *sio_item;
140 proto_tree *sio_tree;
142 sio_item = proto_tree_add_text(mtp3_tree, tvb, SIO_OFFSET, SIO_LENGTH, "Service information octet");
143 sio_tree = proto_item_add_subtree(sio_item, ett_mtp3_sio);
145 sio = tvb_get_guint8(tvb, SIO_OFFSET);
146 proto_tree_add_uint(sio_tree, hf_mtp3_network_indicator, tvb, SIO_OFFSET, SIO_LENGTH, sio);
148 switch(mtp3_standard){
150 proto_tree_add_uint(sio_tree, hf_mtp3_ansi_priority, tvb, SIO_OFFSET, SIO_LENGTH, sio);
153 proto_tree_add_uint(sio_tree, hf_mtp3_itu_spare, tvb, SIO_OFFSET, SIO_LENGTH, sio);
157 proto_tree_add_uint(sio_tree, hf_mtp3_service_indicator, tvb, SIO_OFFSET, SIO_LENGTH, sio);
161 dissect_mtp3_routing_label(tvbuff_t *tvb, proto_tree *mtp3_tree)
163 guint32 label, dpc, opc;
165 proto_item *label_item, *label_dpc_item, *label_opc_item;
166 proto_tree *label_tree, *label_dpc_tree, *label_opc_tree;
168 switch (mtp3_standard) {
170 label_item = proto_tree_add_text(mtp3_tree, tvb, ITU_ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, "Routing label");
171 label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
173 label = tvb_get_letohl(tvb, ITU_ROUTING_LABEL_OFFSET);
174 sls = tvb_get_guint8(tvb, ITU_ROUTING_LABEL_OFFSET);
176 proto_tree_add_uint(label_tree, hf_mtp3_itu_dpc, tvb, ITU_ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, label);
177 proto_tree_add_uint(label_tree, hf_mtp3_itu_opc, tvb, ITU_ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH, label);
178 proto_tree_add_uint(label_tree, hf_mtp3_itu_sls, tvb, ITU_SLS_OFFSET, ITU_SLS_LENGTH, sls);
182 /* this could be 5 or 8 bits */
183 sls = tvb_get_guint8(tvb, ANSI_SLS_OFFSET);
185 /* Create the Routing Label Tree */
186 label_item = proto_tree_add_text(mtp3_tree, tvb, ANSI_ROUTING_LABEL_OFFSET, ANSI_ROUTING_LABEL_LENGTH, "Routing label");
187 label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
189 /* create the DPC tree */
190 dpc = tvb_get_ntoh24(tvb, ANSI_DPC_OFFSET);
191 label_dpc_item = proto_tree_add_text(label_tree, tvb, ANSI_DPC_OFFSET, ANSI_PC_LENGTH,
192 "DPC (%d-%d-%d)", (dpc & ANSI_NETWORK_MASK), ((dpc & ANSI_CLUSTER_MASK) >> 8), ((dpc & ANSI_MEMBER_MASK) >> 16));
194 label_dpc_tree = proto_item_add_subtree(label_dpc_item, ett_mtp3_label_dpc);
196 proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_member, tvb, ANSI_DPC_OFFSET, ANSI_PC_LENGTH, dpc);
197 proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_cluster,tvb, ANSI_DPC_OFFSET, ANSI_PC_LENGTH, dpc);
198 proto_tree_add_uint(label_dpc_tree, hf_mtp3_dpc_network,tvb, ANSI_DPC_OFFSET, ANSI_PC_LENGTH, dpc);
200 /* create the OPC tree */
201 opc = tvb_get_ntoh24(tvb, ANSI_OPC_OFFSET);
203 label_opc_item = proto_tree_add_text(label_tree, tvb, ANSI_OPC_OFFSET, ANSI_PC_LENGTH,
204 "OPC (%d-%d-%d)", (opc & ANSI_NETWORK_MASK), ((opc & ANSI_CLUSTER_MASK) >> 8), ((opc & ANSI_MEMBER_MASK) >> 16));
205 label_opc_tree = proto_item_add_subtree(label_opc_item, ett_mtp3_label_opc);
207 proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_member, tvb, ANSI_OPC_OFFSET, ANSI_PC_LENGTH, opc);
208 proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_cluster, tvb, ANSI_OPC_OFFSET, ANSI_PC_LENGTH, opc);
209 proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_network,tvb, ANSI_OPC_OFFSET, ANSI_PC_LENGTH, opc);
211 /* TODO: separate 5-bit and 8-bit SLS */
212 proto_tree_add_item(label_tree, hf_mtp3_ansi_sls, tvb, ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, sls);
213 /* proto_tree_add_uint(label_tree, hf_mtp3_ansi_sls, tvb,ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, sls);*/
219 dissect_mtp3_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
222 guint8 service_indicator;
223 tvbuff_t *payload_tvb = NULL;
225 sio = tvb_get_guint8(tvb, SIO_OFFSET);
226 service_indicator = sio & SERVICE_INDICATOR_MASK;
228 switch (mtp3_standard) {
230 payload_tvb = tvb_new_subset(tvb, ITU_MTP_PAYLOAD_OFFSET, -1, -1);
233 payload_tvb = tvb_new_subset(tvb, ANSI_MTP_PAYLOAD_OFFSET, -1, -1);
237 if (!dissector_try_port(mtp3_sio_dissector_table, service_indicator, payload_tvb, pinfo, tree)) {
238 call_dissector(data_handle, payload_tvb, pinfo, tree);
239 if (check_col(pinfo->cinfo, COL_INFO))
240 col_append_str(pinfo->cinfo, COL_INFO, "DATA ");
244 /* Code to actually dissect the packets */
246 dissect_mtp3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
249 /* Set up structures needed to add the protocol subtree and manage it */
250 proto_item *mtp3_item = NULL;
251 proto_tree *mtp3_tree = NULL;
253 /* Make entries in Protocol column and Info column on summary display */
254 if (check_col(pinfo->cinfo, COL_PROTOCOL))
255 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3");
258 /* create display subtree for the protocol */
259 switch (mtp3_standard) {
261 mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0, ITU_HEADER_LENGTH, FALSE);
264 mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0, ANSI_HEADER_LENGTH, FALSE);
267 mtp3_tree = proto_item_add_subtree(mtp3_item, ett_mtp3);
269 /* dissect the packet */
270 dissect_mtp3_sio(tvb, mtp3_tree);
271 dissect_mtp3_routing_label(tvb, mtp3_tree);
274 /* Need to dissect payload even if !tree so can call sub-dissectors */
275 dissect_mtp3_payload(tvb, pinfo, tree);
279 proto_register_mtp3(void)
282 /* Setup list of header fields See Section 1.6.1 for details*/
283 static hf_register_info hf[] = {
284 { &hf_mtp3_service_indicator,
285 { "Service indicator", "mtp3.service_indicator",
286 FT_UINT8, BASE_HEX, VALS(service_indicator_code_vals), SERVICE_INDICATOR_MASK,
288 { &hf_mtp3_network_indicator,
289 { "Network indicator", "mtp3.network_indicator",
290 FT_UINT8, BASE_HEX, VALS(network_indicator_vals), NETWORK_INDICATOR_MASK,
292 { &hf_mtp3_itu_spare,
293 { "Spare", "mtp3.spare",
294 FT_UINT8, BASE_HEX, NULL, SPARE_MASK,
296 { &hf_mtp3_ansi_priority,
297 { "Priority", "mtp3.priority",
298 FT_UINT8, BASE_HEX, NULL, ANSI_PRIORITY_MASK,
302 FT_UINT32, BASE_DEC, NULL, ITU_OPC_MASK,
304 { &hf_mtp3_opc_network,
305 { "OPC Network", "mtp3.opc.network",
306 FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
308 { &hf_mtp3_opc_cluster,
309 { "OPC Cluster", "mtp3.opc.cluster",
310 FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
312 { &hf_mtp3_opc_member,
313 { "OPC Member", "mtp3.opc.member",
314 FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
318 FT_UINT32, BASE_DEC, NULL, ITU_DPC_MASK,
320 { &hf_mtp3_dpc_network,
321 { "DPC Network", "mtp3.dpc.network",
322 FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
324 { &hf_mtp3_dpc_cluster,
325 { "DPC Cluster", "mtp3.dpc.cluster",
326 FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
328 { &hf_mtp3_dpc_member,
329 { "DPC Member", "mtp3.dpc.member",
330 FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
333 { "Signalling Link Selector", "mtp3.sls",
334 FT_UINT32, BASE_DEC, NULL, ITU_SLS_MASK,
337 { "Signalling Link Selector", "mtp3.sls",
338 FT_UINT8, BASE_DEC, NULL, ANSI_5BIT_SLS_MASK,
342 /* Setup protocol subtree array */
343 static gint *ett[] = {
351 static enum_val_t mtp3_options[] = {
352 { "ITU", ITU_STANDARD },
353 { "ANSI", ANSI_STANDARD },
357 /* Register the protocol name and description */
358 proto_mtp3 = proto_register_protocol("Message Transfer Part Level 3", "MTP3", "mtp3");
359 register_dissector("mtp3", dissect_mtp3, proto_mtp3);
361 /* Required function calls to register the header fields and subtrees used */
362 proto_register_field_array(proto_mtp3, hf, array_length(hf));
363 proto_register_subtree_array(ett, array_length(ett));
365 mtp3_sio_dissector_table = register_dissector_table("mtp3.service_indicator", "MTP3 Service indicator", FT_UINT8, BASE_HEX);
366 mtp3_module = prefs_register_protocol(proto_mtp3, NULL);
367 prefs_register_enum_preference(mtp3_module, "mtp3_standard", "MTP3 standard", "MTP3 standard", (gint *)&mtp3_standard, mtp3_options, FALSE);
371 proto_reg_handoff_mtp3(void)
373 data_handle = find_dissector("data");