2 * Routines for MTP2 Peer Adaptation Layer dissection
3 * It is hopefully (needs testing) compliant to
4 * http://www.ietf.org/internet-drafts/draft-ietf-sigtran-m2pa-03.txt
6 * Copyright 2001, Jeff Morriss <jeff.morriss[AT]ulticom.com>,
7 * updated by Michael Tuexen <michael.tuexen[AT]icn.siemens.de>
9 * $Id: packet-m2pa.c,v 1.5 2002/01/20 22:12:26 guy Exp $
11 * Ethereal - Network traffic analyzer
12 * By Gerald Combs <gerald@ethereal.com>
13 * Copyright 1998 Gerald Combs
15 * Copied from packet-m3ua.c
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
44 #ifdef HAVE_NETINET_IN_H
45 # include <netinet/in.h>
51 #ifdef NEED_SNPRINTF_H
52 # include "snprintf.h"
58 /* Warning: Neither of these are standardized yet! */
59 #define SCTP_PORT_M2PA 2904
60 #define M2PA_PAYLOAD_PROTOCOL_ID 5
62 #define VERSION_LENGTH 1
63 #define SPARE_LENGTH 1
64 #define CLASS_LENGTH 1
66 #define LENGTH_LENGTH 4
67 #define COMMON_HEADER_LENGTH (VERSION_LENGTH + SPARE_LENGTH + \
68 CLASS_LENGTH + TYPE_LENGTH + LENGTH_LENGTH)
70 #define VERSION_OFFSET 0
71 #define SPARE_OFFSET (VERSION_OFFSET + VERSION_LENGTH)
72 #define CLASS_OFFSET (SPARE_OFFSET + SPARE_LENGTH)
73 #define TYPE_OFFSET (CLASS_OFFSET + CLASS_LENGTH)
74 #define LENGTH_OFFSET (TYPE_OFFSET + TYPE_LENGTH)
75 #define COMMON_HEADER_OFFSET VERSION_OFFSET
76 #define MESSAGE_DATA_OFFSET (COMMON_HEADER_OFFSET + COMMON_HEADER_LENGTH)
78 #define PROTOCOL_VERSION_RELEASE_1 1
79 static const value_string m2pa_protocol_version_values[] = {
80 { PROTOCOL_VERSION_RELEASE_1, "Release 1" },
84 #define MESSAGE_CLASS_M2PA 0xb
86 static const value_string m2pa_message_class_values[] = {
87 { MESSAGE_CLASS_M2PA, "M2PA" },
91 #define MESSAGE_TYPE_USER_DATA 0x1
92 #define MESSAGE_TYPE_LINK_STATUS 0x2
93 #define MESSAGE_TYPE_PROVING_DATA 0x3
95 static const value_string m2pa_message_type_values[] = {
96 { MESSAGE_TYPE_USER_DATA, "User Data" },
97 { MESSAGE_TYPE_LINK_STATUS, "Link Status" },
98 { MESSAGE_TYPE_PROVING_DATA, "Proving Data" },
102 /* parts of User Data message */
105 #define MTP3_OFFSET (LI_OFFSET + LI_LENGTH)
107 /* LI is only used for (ITU national) priority in M2PA */
108 #define LI_SPARE_MASK 0xfc
109 #define LI_PRIORITY_MASK 0x3
112 /* parts of Link Status message */
113 #define STATUS_LENGTH 4
114 #define STATUS_OFFSET 0
116 #define STATUS_ALIGNMENT 1
117 #define STATUS_PROVING_NORMAL 2
118 #define STATUS_PROVING_EMERGENCY 3
119 #define STATUS_READY 4
120 #define STATUS_PROCESSOR_OUTAGE 5
121 #define STATUS_PROCESSOR_OUTAGE_ENDED 6
122 #define STATUS_BUSY 7
123 #define STATUS_BUSY_ENDED 8
125 static const value_string m2pa_link_status_values[] = {
126 { STATUS_ALIGNMENT, "Alignment" },
127 { STATUS_PROVING_NORMAL, "Proving Normal" },
128 { STATUS_PROVING_EMERGENCY, "Proving Emergency" },
129 { STATUS_READY, "Ready" },
130 { STATUS_PROCESSOR_OUTAGE, "Processor Outage" },
131 { STATUS_PROCESSOR_OUTAGE_ENDED, "Processor Outage Ended" },
132 { STATUS_BUSY, "Busy" },
133 { STATUS_BUSY_ENDED, "Busy Ended" },
137 /* Initialize the protocol and registered fields */
138 static int proto_m2pa = -1;
139 static int hf_m2pa_version = -1;
140 static int hf_m2pa_spare = -1;
141 static int hf_m2pa_type = -1;
142 static int hf_m2pa_class = -1;
143 static int hf_m2pa_length = -1;
144 static int hf_m2pa_status = -1;
145 static int hf_m2pa_li_spare = -1;
146 static int hf_m2pa_li_prio = -1;
147 static int hf_m2pa_proving_data = -1;
148 static int hf_m2pa_unknown_data = -1;
149 /* Initialize the subtree pointers */
150 static gint ett_m2pa = -1;
151 static gint ett_m2pa_li = -1;
153 static dissector_handle_t mtp3_handle;
156 dissect_m2pa_user_data_message(tvbuff_t *message_data_tvb, packet_info *pinfo, proto_item *m2pa_item, proto_tree *m2pa_tree, proto_tree *tree)
158 proto_item *m2pa_li_item;
159 proto_tree *m2pa_li_tree;
160 tvbuff_t *payload_tvb;
162 guint32 payload_length;
164 payload_length = tvb_length(message_data_tvb) - LI_LENGTH;
167 li = tvb_get_guint8(message_data_tvb, LI_OFFSET);
168 m2pa_li_item = proto_tree_add_text(m2pa_tree, message_data_tvb, LI_OFFSET, LI_LENGTH, "Length Indicator");
169 m2pa_li_tree = proto_item_add_subtree(m2pa_li_item, ett_m2pa_li);
170 proto_tree_add_uint(m2pa_li_tree, hf_m2pa_li_spare, message_data_tvb, LI_OFFSET, LI_LENGTH, li);
171 proto_tree_add_uint(m2pa_li_tree, hf_m2pa_li_prio, message_data_tvb, LI_OFFSET, LI_LENGTH, li);
173 /* Re-adjust length of M2PA item since it will be dissected as MTP3 */
174 proto_item_set_len(m2pa_item, COMMON_HEADER_LENGTH + LI_LENGTH);
177 payload_tvb = tvb_new_subset(message_data_tvb, MTP3_OFFSET, payload_length, payload_length);
178 call_dissector(mtp3_handle, payload_tvb, pinfo, tree);
182 dissect_m2pa_link_status_message(tvbuff_t *message_data_tvb, proto_tree *m2pa_tree)
187 status = tvb_get_ntohl (message_data_tvb, STATUS_OFFSET);
188 proto_tree_add_uint(m2pa_tree, hf_m2pa_status, message_data_tvb, STATUS_OFFSET, STATUS_LENGTH, status);
194 dissect_m2pa_proving_data_message(tvbuff_t *message_data_tvb, proto_tree *m2pa_tree)
196 guint32 message_data_length;
199 message_data_length = tvb_length(message_data_tvb);
200 proto_tree_add_item(m2pa_tree, hf_m2pa_proving_data,
201 message_data_tvb, 0, message_data_length, FALSE);
206 dissect_m2pa_unknown_message(tvbuff_t *message_data_tvb, proto_tree *m2pa_tree)
208 guint32 message_data_length;
211 message_data_length = tvb_length(message_data_tvb);
212 proto_tree_add_item(m2pa_tree, hf_m2pa_unknown_data,
213 message_data_tvb, 0, message_data_length, FALSE);
218 dissect_m2pa_common_header(tvbuff_t *common_header_tvb, packet_info *pinfo, proto_tree *m2pa_tree)
220 guint8 version, spare, class, type;
223 version = tvb_get_guint8(common_header_tvb, VERSION_OFFSET);
224 spare = tvb_get_guint8(common_header_tvb, SPARE_OFFSET);
225 class = tvb_get_guint8(common_header_tvb, CLASS_OFFSET);
226 type = tvb_get_guint8(common_header_tvb, TYPE_OFFSET);
227 length = tvb_get_ntohl(common_header_tvb, LENGTH_OFFSET);
229 if (check_col(pinfo->cinfo, COL_INFO)) {
230 col_append_str(pinfo->cinfo, COL_INFO, val_to_str(type, m2pa_message_type_values, "Invalid"));
231 col_append_str(pinfo->cinfo, COL_INFO, " ");
235 proto_tree_add_uint(m2pa_tree, hf_m2pa_version, common_header_tvb, VERSION_OFFSET, VERSION_LENGTH, version);
236 proto_tree_add_uint(m2pa_tree, hf_m2pa_spare, common_header_tvb, SPARE_OFFSET, SPARE_LENGTH, spare);
237 proto_tree_add_uint(m2pa_tree, hf_m2pa_type, common_header_tvb, TYPE_OFFSET, TYPE_LENGTH, type);
238 proto_tree_add_uint(m2pa_tree, hf_m2pa_class, common_header_tvb, CLASS_OFFSET, CLASS_LENGTH, class);
239 proto_tree_add_uint(m2pa_tree, hf_m2pa_length, common_header_tvb, LENGTH_OFFSET, LENGTH_LENGTH, length);
244 dissect_m2pa_message_data(tvbuff_t *message_tvb, packet_info *pinfo, proto_item *m2pa_item, proto_tree *m2pa_tree, proto_tree *tree)
246 guint32 message_data_length;
248 tvbuff_t *message_data_tvb;
250 message_data_length = tvb_get_ntohl(message_tvb, LENGTH_OFFSET) - COMMON_HEADER_LENGTH;
251 message_data_tvb = tvb_new_subset(message_tvb, MESSAGE_DATA_OFFSET, message_data_length, message_data_length);
252 type = tvb_get_guint8(message_tvb, TYPE_OFFSET);
255 case MESSAGE_TYPE_USER_DATA:
256 dissect_m2pa_user_data_message(message_data_tvb, pinfo, m2pa_item, m2pa_tree, tree);
259 case MESSAGE_TYPE_LINK_STATUS:
260 dissect_m2pa_link_status_message(message_data_tvb, m2pa_tree);
263 case MESSAGE_TYPE_PROVING_DATA:
264 dissect_m2pa_proving_data_message(message_data_tvb, m2pa_tree);
268 dissect_m2pa_unknown_message(message_data_tvb, m2pa_tree);
273 dissect_m2pa_message(tvbuff_t *message_tvb, packet_info *pinfo, proto_item *m2pa_item, proto_tree *m2pa_tree, proto_tree *tree)
275 tvbuff_t *common_header_tvb;
277 common_header_tvb = tvb_new_subset(message_tvb, COMMON_HEADER_OFFSET, COMMON_HEADER_LENGTH, COMMON_HEADER_LENGTH);
278 dissect_m2pa_common_header(common_header_tvb, pinfo, m2pa_tree);
279 dissect_m2pa_message_data(message_tvb, pinfo, m2pa_item, m2pa_tree, tree);
284 dissect_m2pa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
286 proto_item *m2pa_item;
287 proto_tree *m2pa_tree;
289 /* make entry in the Protocol column on summary display */
290 if (check_col(pinfo->cinfo, COL_PROTOCOL))
291 col_set_str(pinfo->cinfo, COL_PROTOCOL, "M2PA");
293 /* In the interest of speed, if "tree" is NULL, don't do any work not
294 necessary to generate protocol tree items. */
296 /* create the m2pa protocol tree */
297 m2pa_item = proto_tree_add_item(tree, proto_m2pa, tvb, 0, -1, FALSE);
298 m2pa_tree = proto_item_add_subtree(m2pa_item, ett_m2pa);
304 /* dissect the message */
305 dissect_m2pa_message(tvb, pinfo, m2pa_item, m2pa_tree, tree);
308 /* Register the protocol with Ethereal */
310 proto_register_m2pa(void)
313 /* Setup list of header fields */
314 static hf_register_info hf[] = {
316 { "Version", "m2pa.version",
317 FT_UINT8, BASE_DEC, VALS(m2pa_protocol_version_values), 0x0,
321 { "Spare", "m2pa.spare",
322 FT_UINT8, BASE_HEX, NULL, 0x0,
326 { "Message Type", "m2pa.type",
327 FT_UINT8, BASE_DEC, VALS(m2pa_message_type_values), 0x0,
331 { "Message Class", "m2pa.class",
332 FT_UINT8, BASE_DEC, VALS(m2pa_message_class_values), 0x0,
336 { "Message length", "m2pa.length",
337 FT_UINT32, BASE_DEC, NULL, 0x0,
341 { "Spare", "m2pa.li_spare",
342 FT_UINT8, BASE_HEX, NULL, LI_SPARE_MASK,
346 { "Priority", "m2pa.li_priority",
347 FT_UINT8, BASE_HEX, NULL, LI_PRIORITY_MASK,
351 { "Link Status Status", "m2pa.status",
352 FT_UINT32, BASE_DEC, VALS(m2pa_link_status_values), 0x0,
355 { &hf_m2pa_proving_data,
356 { "Proving Data", "m2pa.proving_data",
357 FT_BYTES, BASE_NONE, NULL, 0x0,
360 { &hf_m2pa_unknown_data,
361 { "Unknown Data", "m2pa.unknown_data",
362 FT_BYTES, BASE_NONE, NULL, 0x0,
367 /* Setup protocol subtree array */
368 static gint *ett[] = {
373 /* Register the protocol name and description */
374 proto_m2pa = proto_register_protocol("MTP2 Peer Adaptation Layer", "M2PA", "m2pa");
376 /* Required function calls to register the header fields and subtrees used */
377 proto_register_field_array(proto_m2pa, hf, array_length(hf));
378 proto_register_subtree_array(ett, array_length(ett));
383 proto_reg_handoff_m2pa(void)
385 dissector_handle_t m2pa_handle;
388 * Get a handle for the MTP3 dissector.
390 mtp3_handle = find_dissector("mtp3");
392 m2pa_handle = create_dissector_handle(dissect_m2pa, proto_m2pa);
393 dissector_add("sctp.ppi", M2PA_PAYLOAD_PROTOCOL_ID, m2pa_handle);
394 dissector_add("sctp.port", SCTP_PORT_M2PA, m2pa_handle);