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.4 2001/12/10 00:25:30 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_bytes(m2pa_tree, hf_m2pa_proving_data,
201 message_data_tvb, 0, message_data_length,
202 tvb_get_ptr(message_data_tvb, 0, message_data_length));
207 dissect_m2pa_unknown_message(tvbuff_t *message_data_tvb, proto_tree *m2pa_tree)
209 guint32 message_data_length;
212 message_data_length = tvb_length(message_data_tvb);
213 proto_tree_add_bytes(m2pa_tree, hf_m2pa_unknown_data,
214 message_data_tvb, 0, message_data_length,
215 tvb_get_ptr(message_data_tvb, 0, message_data_length));
220 dissect_m2pa_common_header(tvbuff_t *common_header_tvb, packet_info *pinfo, proto_tree *m2pa_tree)
222 guint8 version, spare, class, type;
225 version = tvb_get_guint8(common_header_tvb, VERSION_OFFSET);
226 spare = tvb_get_guint8(common_header_tvb, SPARE_OFFSET);
227 class = tvb_get_guint8(common_header_tvb, CLASS_OFFSET);
228 type = tvb_get_guint8(common_header_tvb, TYPE_OFFSET);
229 length = tvb_get_ntohl(common_header_tvb, LENGTH_OFFSET);
231 if (check_col(pinfo->cinfo, COL_INFO)) {
232 col_append_str(pinfo->cinfo, COL_INFO, val_to_str(type, m2pa_message_type_values, "Invalid"));
233 col_append_str(pinfo->cinfo, COL_INFO, " ");
237 proto_tree_add_uint(m2pa_tree, hf_m2pa_version, common_header_tvb, VERSION_OFFSET, VERSION_LENGTH, version);
238 proto_tree_add_uint(m2pa_tree, hf_m2pa_spare, common_header_tvb, SPARE_OFFSET, SPARE_LENGTH, spare);
239 proto_tree_add_uint(m2pa_tree, hf_m2pa_type, common_header_tvb, TYPE_OFFSET, TYPE_LENGTH, type);
240 proto_tree_add_uint(m2pa_tree, hf_m2pa_class, common_header_tvb, CLASS_OFFSET, CLASS_LENGTH, class);
241 proto_tree_add_uint(m2pa_tree, hf_m2pa_length, common_header_tvb, LENGTH_OFFSET, LENGTH_LENGTH, length);
246 dissect_m2pa_message_data(tvbuff_t *message_tvb, packet_info *pinfo, proto_item *m2pa_item, proto_tree *m2pa_tree, proto_tree *tree)
248 guint32 message_data_length;
250 tvbuff_t *message_data_tvb;
252 message_data_length = tvb_get_ntohl(message_tvb, LENGTH_OFFSET) - COMMON_HEADER_LENGTH;
253 message_data_tvb = tvb_new_subset(message_tvb, MESSAGE_DATA_OFFSET, message_data_length, message_data_length);
254 type = tvb_get_guint8(message_tvb, TYPE_OFFSET);
257 case MESSAGE_TYPE_USER_DATA:
258 dissect_m2pa_user_data_message(message_data_tvb, pinfo, m2pa_item, m2pa_tree, tree);
261 case MESSAGE_TYPE_LINK_STATUS:
262 dissect_m2pa_link_status_message(message_data_tvb, m2pa_tree);
265 case MESSAGE_TYPE_PROVING_DATA:
266 dissect_m2pa_proving_data_message(message_data_tvb, m2pa_tree);
270 dissect_m2pa_unknown_message(message_data_tvb, m2pa_tree);
275 dissect_m2pa_message(tvbuff_t *message_tvb, packet_info *pinfo, proto_item *m2pa_item, proto_tree *m2pa_tree, proto_tree *tree)
277 tvbuff_t *common_header_tvb;
279 common_header_tvb = tvb_new_subset(message_tvb, COMMON_HEADER_OFFSET, COMMON_HEADER_LENGTH, COMMON_HEADER_LENGTH);
280 dissect_m2pa_common_header(common_header_tvb, pinfo, m2pa_tree);
281 dissect_m2pa_message_data(message_tvb, pinfo, m2pa_item, m2pa_tree, tree);
286 dissect_m2pa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
288 proto_item *m2pa_item;
289 proto_tree *m2pa_tree;
291 /* make entry in the Protocol column on summary display */
292 if (check_col(pinfo->cinfo, COL_PROTOCOL))
293 col_set_str(pinfo->cinfo, COL_PROTOCOL, "M2PA");
295 /* In the interest of speed, if "tree" is NULL, don't do any work not
296 necessary to generate protocol tree items. */
298 /* create the m2pa protocol tree */
299 m2pa_item = proto_tree_add_item(tree, proto_m2pa, tvb, 0, tvb_length(tvb), FALSE);
300 m2pa_tree = proto_item_add_subtree(m2pa_item, ett_m2pa);
306 /* dissect the message */
307 dissect_m2pa_message(tvb, pinfo, m2pa_item, m2pa_tree, tree);
310 /* Register the protocol with Ethereal */
312 proto_register_m2pa(void)
315 /* Setup list of header fields */
316 static hf_register_info hf[] = {
318 { "Version", "m2pa.version",
319 FT_UINT8, BASE_DEC, VALS(m2pa_protocol_version_values), 0x0,
323 { "Spare", "m2pa.spare",
324 FT_UINT8, BASE_HEX, NULL, 0x0,
328 { "Message Type", "m2pa.type",
329 FT_UINT8, BASE_DEC, VALS(m2pa_message_type_values), 0x0,
333 { "Message Class", "m2pa.class",
334 FT_UINT8, BASE_DEC, VALS(m2pa_message_class_values), 0x0,
338 { "Message length", "m2pa.length",
339 FT_UINT32, BASE_DEC, NULL, 0x0,
343 { "Spare", "m2pa.li_spare",
344 FT_UINT8, BASE_HEX, NULL, LI_SPARE_MASK,
348 { "Priority", "m2pa.li_priority",
349 FT_UINT8, BASE_HEX, NULL, LI_PRIORITY_MASK,
353 { "Link Status Status", "m2pa.status",
354 FT_UINT32, BASE_DEC, VALS(m2pa_link_status_values), 0x0,
357 { &hf_m2pa_proving_data,
358 { "Proving Data", "m2pa.proving_data",
359 FT_BYTES, BASE_NONE, NULL, 0x0,
362 { &hf_m2pa_unknown_data,
363 { "Unknown Data", "m2pa.unknown_data",
364 FT_BYTES, BASE_NONE, NULL, 0x0,
369 /* Setup protocol subtree array */
370 static gint *ett[] = {
375 /* Register the protocol name and description */
376 proto_m2pa = proto_register_protocol("MTP2 Peer Adaptation Layer", "M2PA", "m2pa");
378 /* Required function calls to register the header fields and subtrees used */
379 proto_register_field_array(proto_m2pa, hf, array_length(hf));
380 proto_register_subtree_array(ett, array_length(ett));
385 proto_reg_handoff_m2pa(void)
387 dissector_handle_t m2pa_handle;
390 * Get a handle for the MTP3 dissector.
392 mtp3_handle = find_dissector("mtp3");
394 m2pa_handle = create_dissector_handle(dissect_m2pa, proto_m2pa);
395 dissector_add("sctp.ppi", M2PA_PAYLOAD_PROTOCOL_ID, m2pa_handle);
396 dissector_add("sctp.port", SCTP_PORT_M2PA, m2pa_handle);