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-04.txt
6 * Copyright 2001, 2002, 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.10 2002/06/20 20:58:07 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.
37 #include <epan/packet.h>
39 #define SCTP_PORT_M2PA 3565
40 #define M2PA_PAYLOAD_PROTOCOL_ID 5
42 #define VERSION_LENGTH 1
43 #define SPARE_LENGTH 1
44 #define CLASS_LENGTH 1
46 #define LENGTH_LENGTH 4
50 #define HEADER_LENGTH (VERSION_LENGTH + SPARE_LENGTH + \
51 CLASS_LENGTH + TYPE_LENGTH + LENGTH_LENGTH + \
52 BSN_LENGTH + FSN_LENGTH)
54 #define VERSION_OFFSET 0
55 #define SPARE_OFFSET (VERSION_OFFSET + VERSION_LENGTH)
56 #define CLASS_OFFSET (SPARE_OFFSET + SPARE_LENGTH)
57 #define TYPE_OFFSET (CLASS_OFFSET + CLASS_LENGTH)
58 #define LENGTH_OFFSET (TYPE_OFFSET + TYPE_LENGTH)
59 #define BSN_OFFSET (LENGTH_OFFSET + LENGTH_LENGTH)
60 #define FSN_OFFSET (BSN_OFFSET + BSN_LENGTH)
61 #define HEADER_OFFSET VERSION_OFFSET
62 #define MESSAGE_DATA_OFFSET (HEADER_OFFSET + HEADER_LENGTH)
64 #define PROTOCOL_VERSION_RELEASE_1 1
65 static const value_string m2pa_protocol_version_values[] = {
66 { PROTOCOL_VERSION_RELEASE_1, "Release 1" },
70 #define MESSAGE_CLASS_M2PA 0xb
72 static const value_string m2pa_message_class_values[] = {
73 { MESSAGE_CLASS_M2PA, "M2PA" },
77 #define MESSAGE_TYPE_USER_DATA 0x1
78 #define MESSAGE_TYPE_LINK_STATUS 0x2
80 static const value_string m2pa_message_type_values[] = {
81 { MESSAGE_TYPE_USER_DATA, "User Data" },
82 { MESSAGE_TYPE_LINK_STATUS, "Link Status" },
86 /* parts of User Data message */
89 #define MTP3_OFFSET (LI_OFFSET + LI_LENGTH)
91 /* LI is only used for (ITU national) priority in M2PA */
92 #define LI_SPARE_MASK 0x3f
93 #define LI_PRIORITY_MASK 0xc0
96 /* parts of Link Status message */
97 #define STATUS_LENGTH 4
98 #define STATUS_OFFSET 0
99 #define FILLER_OFFSET (STATUS_OFFSET + STATUS_LENGTH)
101 #define STATUS_ALIGNMENT 1
102 #define STATUS_PROVING_NORMAL 2
103 #define STATUS_PROVING_EMERGENCY 3
104 #define STATUS_READY 4
105 #define STATUS_PROCESSOR_OUTAGE 5
106 #define STATUS_PROCESSOR_OUTAGE_ENDED 6
107 #define STATUS_BUSY 7
108 #define STATUS_BUSY_ENDED 8
109 #define STATUS_OUT_OF_SERVICE 9
110 #define STATUS_IN_SERVICE 10
112 static const value_string m2pa_link_status_values[] = {
113 { STATUS_ALIGNMENT, "Alignment" },
114 { STATUS_PROVING_NORMAL, "Proving Normal" },
115 { STATUS_PROVING_EMERGENCY, "Proving Emergency" },
116 { STATUS_READY, "Ready" },
117 { STATUS_PROCESSOR_OUTAGE, "Processor Outage" },
118 { STATUS_PROCESSOR_OUTAGE_ENDED, "Processor Outage Ended" },
119 { STATUS_BUSY, "Busy" },
120 { STATUS_BUSY_ENDED, "Busy Ended" },
121 { STATUS_OUT_OF_SERVICE, "Out of Service" },
122 { STATUS_IN_SERVICE, "In Service" },
126 /* Initialize the protocol and registered fields */
127 static int proto_m2pa = -1;
128 static int hf_m2pa_version = -1;
129 static int hf_m2pa_spare = -1;
130 static int hf_m2pa_type = -1;
131 static int hf_m2pa_class = -1;
132 static int hf_m2pa_length = -1;
133 static int hf_m2pa_bsn = -1;
134 static int hf_m2pa_fsn = -1;
135 static int hf_m2pa_status = -1;
136 static int hf_m2pa_li_spare = -1;
137 static int hf_m2pa_li_prio = -1;
138 static int hf_m2pa_filler = -1;
139 static int hf_m2pa_unknown_data = -1;
140 /* Initialize the subtree pointers */
141 static gint ett_m2pa = -1;
142 static gint ett_m2pa_li = -1;
144 static dissector_handle_t mtp3_handle;
147 dissect_m2pa_user_data_message(tvbuff_t *message_data_tvb, packet_info *pinfo, proto_item *m2pa_item, proto_tree *m2pa_tree, proto_tree *tree)
149 proto_item *m2pa_li_item;
150 proto_tree *m2pa_li_tree;
151 tvbuff_t *payload_tvb;
153 guint32 payload_length;
155 payload_length = tvb_length(message_data_tvb) - LI_LENGTH;
158 li = tvb_get_guint8(message_data_tvb, LI_OFFSET);
159 m2pa_li_item = proto_tree_add_text(m2pa_tree, message_data_tvb, LI_OFFSET, LI_LENGTH, "Length Indicator");
160 m2pa_li_tree = proto_item_add_subtree(m2pa_li_item, ett_m2pa_li);
161 proto_tree_add_uint(m2pa_li_tree, hf_m2pa_li_prio, message_data_tvb, LI_OFFSET, LI_LENGTH, li);
162 proto_tree_add_uint(m2pa_li_tree, hf_m2pa_li_spare, message_data_tvb, LI_OFFSET, LI_LENGTH, li);
164 /* Re-adjust length of M2PA item since it will be dissected as MTP3 */
165 proto_item_set_len(m2pa_item, HEADER_LENGTH + LI_LENGTH);
168 payload_tvb = tvb_new_subset(message_data_tvb, MTP3_OFFSET, payload_length, payload_length);
169 call_dissector(mtp3_handle, payload_tvb, pinfo, tree);
173 dissect_m2pa_link_status_message(tvbuff_t *message_data_tvb, proto_tree *m2pa_tree)
176 guint16 filler_length;
179 status = tvb_get_ntohl (message_data_tvb, STATUS_OFFSET);
180 filler_length = tvb_length(message_data_tvb) - STATUS_LENGTH;
181 proto_tree_add_uint(m2pa_tree, hf_m2pa_status, message_data_tvb, STATUS_OFFSET, STATUS_LENGTH, status);
182 if (filler_length > 0)
183 proto_tree_add_bytes(m2pa_tree, hf_m2pa_filler, message_data_tvb, FILLER_OFFSET, filler_length,
184 tvb_get_ptr(message_data_tvb, FILLER_OFFSET, filler_length));
190 dissect_m2pa_unknown_message(tvbuff_t *message_data_tvb, proto_tree *m2pa_tree)
192 guint32 message_data_length;
195 message_data_length = tvb_length(message_data_tvb);
196 proto_tree_add_bytes(m2pa_tree, hf_m2pa_unknown_data, message_data_tvb, 0, message_data_length,
197 tvb_get_ptr(message_data_tvb, 0, message_data_length));
202 dissect_m2pa_header(tvbuff_t *header_tvb, packet_info *pinfo, proto_tree *m2pa_tree)
204 guint8 version, spare, class, type;
208 version = tvb_get_guint8(header_tvb, VERSION_OFFSET);
209 spare = tvb_get_guint8(header_tvb, SPARE_OFFSET);
210 class = tvb_get_guint8(header_tvb, CLASS_OFFSET);
211 type = tvb_get_guint8(header_tvb, TYPE_OFFSET);
212 length = tvb_get_ntohl(header_tvb, LENGTH_OFFSET);
213 bsn = tvb_get_ntohs(header_tvb, BSN_OFFSET);
214 fsn = tvb_get_ntohs(header_tvb, FSN_OFFSET);
216 if (check_col(pinfo->cinfo, COL_INFO)) {
217 col_append_str(pinfo->cinfo, COL_INFO, val_to_str(type, m2pa_message_type_values, "Invalid"));
218 col_append_str(pinfo->cinfo, COL_INFO, " ");
222 proto_tree_add_uint(m2pa_tree, hf_m2pa_version, header_tvb, VERSION_OFFSET, VERSION_LENGTH, version);
223 proto_tree_add_uint(m2pa_tree, hf_m2pa_spare, header_tvb, SPARE_OFFSET, SPARE_LENGTH, spare);
224 proto_tree_add_uint(m2pa_tree, hf_m2pa_type, header_tvb, TYPE_OFFSET, TYPE_LENGTH, type);
225 proto_tree_add_uint(m2pa_tree, hf_m2pa_class, header_tvb, CLASS_OFFSET, CLASS_LENGTH, class);
226 proto_tree_add_uint(m2pa_tree, hf_m2pa_length, header_tvb, LENGTH_OFFSET, LENGTH_LENGTH, length);
227 proto_tree_add_uint(m2pa_tree, hf_m2pa_bsn, header_tvb, BSN_OFFSET, BSN_LENGTH, bsn);
228 proto_tree_add_uint(m2pa_tree, hf_m2pa_fsn, header_tvb, FSN_OFFSET, FSN_LENGTH, fsn);
233 dissect_m2pa_message_data(tvbuff_t *message_tvb, packet_info *pinfo, proto_item *m2pa_item, proto_tree *m2pa_tree, proto_tree *tree)
235 guint32 message_data_length;
237 tvbuff_t *message_data_tvb;
239 message_data_length = tvb_get_ntohl(message_tvb, LENGTH_OFFSET) - HEADER_LENGTH;
240 message_data_tvb = tvb_new_subset(message_tvb, MESSAGE_DATA_OFFSET, message_data_length, message_data_length);
241 type = tvb_get_guint8(message_tvb, TYPE_OFFSET);
244 case MESSAGE_TYPE_USER_DATA:
245 dissect_m2pa_user_data_message(message_data_tvb, pinfo, m2pa_item, m2pa_tree, tree);
248 case MESSAGE_TYPE_LINK_STATUS:
249 dissect_m2pa_link_status_message(message_data_tvb, m2pa_tree);
253 dissect_m2pa_unknown_message(message_data_tvb, m2pa_tree);
258 dissect_m2pa_message(tvbuff_t *message_tvb, packet_info *pinfo, proto_item *m2pa_item, proto_tree *m2pa_tree, proto_tree *tree)
260 tvbuff_t *header_tvb;
262 header_tvb = tvb_new_subset(message_tvb, HEADER_OFFSET, HEADER_LENGTH, HEADER_LENGTH);
263 dissect_m2pa_header(header_tvb, pinfo, m2pa_tree);
264 dissect_m2pa_message_data(message_tvb, pinfo, m2pa_item, m2pa_tree, tree);
269 dissect_m2pa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
271 proto_item *m2pa_item;
272 proto_tree *m2pa_tree;
274 /* make entry in the Protocol column on summary display */
275 if (check_col(pinfo->cinfo, COL_PROTOCOL))
276 col_set_str(pinfo->cinfo, COL_PROTOCOL, "M2PA");
278 /* In the interest of speed, if "tree" is NULL, don't do any work not
279 necessary to generate protocol tree items. */
281 /* create the m2pa protocol tree */
282 m2pa_item = proto_tree_add_item(tree, proto_m2pa, tvb, 0, -1, FALSE);
283 m2pa_tree = proto_item_add_subtree(m2pa_item, ett_m2pa);
289 /* dissect the message */
290 dissect_m2pa_message(tvb, pinfo, m2pa_item, m2pa_tree, tree);
293 /* Register the protocol with Ethereal */
295 proto_register_m2pa(void)
298 /* Setup list of header fields */
299 static hf_register_info hf[] = {
301 { "Version", "m2pa.version",
302 FT_UINT8, BASE_DEC, VALS(m2pa_protocol_version_values), 0x0,
306 { "Spare", "m2pa.spare",
307 FT_UINT8, BASE_HEX, NULL, 0x0,
311 { "Message Type", "m2pa.type",
312 FT_UINT8, BASE_DEC, VALS(m2pa_message_type_values), 0x0,
316 { "Message Class", "m2pa.class",
317 FT_UINT8, BASE_DEC, VALS(m2pa_message_class_values), 0x0,
321 { "Message length", "m2pa.length",
322 FT_UINT32, BASE_DEC, NULL, 0x0,
327 FT_UINT16, BASE_DEC, NULL, 0x0,
332 FT_UINT16, BASE_DEC, NULL, 0x0,
336 { "Spare", "m2pa.li_spare",
337 FT_UINT8, BASE_HEX, NULL, LI_SPARE_MASK,
341 { "Priority", "m2pa.li_priority",
342 FT_UINT8, BASE_HEX, NULL, LI_PRIORITY_MASK,
346 { "Link Status Status", "m2pa.status",
347 FT_UINT32, BASE_DEC, VALS(m2pa_link_status_values), 0x0,
351 { "Filler", "m2pa.filler",
352 FT_BYTES, BASE_NONE, NULL, 0x0,
355 { &hf_m2pa_unknown_data,
356 { "Unknown Data", "m2pa.unknown_data",
357 FT_BYTES, BASE_NONE, NULL, 0x0,
362 /* Setup protocol subtree array */
363 static gint *ett[] = {
368 /* Register the protocol name and description */
369 proto_m2pa = proto_register_protocol("MTP2 Peer Adaptation Layer", "M2PA", "m2pa");
371 /* Required function calls to register the header fields and subtrees used */
372 proto_register_field_array(proto_m2pa, hf, array_length(hf));
373 proto_register_subtree_array(ett, array_length(ett));
378 proto_reg_handoff_m2pa(void)
380 dissector_handle_t m2pa_handle;
383 * Get a handle for the MTP3 dissector.
385 mtp3_handle = find_dissector("mtp3");
387 m2pa_handle = create_dissector_handle(dissect_m2pa, proto_m2pa);
388 dissector_add("sctp.ppi", M2PA_PAYLOAD_PROTOCOL_ID, m2pa_handle);
389 dissector_add("sctp.port", SCTP_PORT_M2PA, m2pa_handle);