2 * Routines for MTP2 dissection
3 * It is hopefully (needs testing) compliant to
4 * ITU-T Q.703 and Q.703 Annex A.
6 * Copyright 2001, 2004 Michael Tuexen <tuexen [AT] fh-muenster.de>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * Copied from packet-m2pa.c
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <epan/packet.h>
37 #include "epan/prefs.h"
39 #define LITTLE_ENDIAN_BYTE_ORDER TRUE
41 /* Initialize the protocol and registered fields */
42 static int proto_mtp2 = -1;
43 static int hf_mtp2_bsn = -1;
44 static int hf_mtp2_ext_bsn = -1;
45 static int hf_mtp2_ext_res = -1;
46 static int hf_mtp2_bib = -1;
47 static int hf_mtp2_ext_bib = -1;
48 static int hf_mtp2_fsn = -1;
49 static int hf_mtp2_ext_fsn = -1;
50 static int hf_mtp2_fib = -1;
51 static int hf_mtp2_ext_fib = -1;
52 static int hf_mtp2_li = -1;
53 static int hf_mtp2_ext_li = -1;
54 static int hf_mtp2_spare = -1;
55 static int hf_mtp2_ext_spare = -1;
56 static int hf_mtp2_sf = -1;
57 static int hf_mtp2_long_sf = -1;
59 /* Initialize the subtree pointers */
60 static gint ett_mtp2 = -1;
62 static dissector_handle_t mtp3_handle;
63 static int mtp3_proto_id;
64 static gboolean use_extended_sequence_numbers_default = FALSE;
65 static gboolean use_extended_sequence_numbers = FALSE;
67 #define BSN_BIB_LENGTH 1
68 #define FSN_FIB_LENGTH 1
70 #define HEADER_LENGTH (BSN_BIB_LENGTH + FSN_FIB_LENGTH + LI_LENGTH)
72 #define EXTENDED_BSN_BIB_LENGTH 2
73 #define EXTENDED_FSN_FIB_LENGTH 2
74 #define EXTENDED_LI_LENGTH 2
75 #define EXTENDED_HEADER_LENGTH (EXTENDED_BSN_BIB_LENGTH + EXTENDED_FSN_FIB_LENGTH + EXTENDED_LI_LENGTH)
77 #define BSN_BIB_OFFSET 0
78 #define FSN_FIB_OFFSET (BSN_BIB_OFFSET + BSN_BIB_LENGTH)
79 #define LI_OFFSET (FSN_FIB_OFFSET + FSN_FIB_LENGTH)
80 #define SIO_OFFSET (LI_OFFSET + LI_LENGTH)
82 #define EXTENDED_BSN_BIB_OFFSET 0
83 #define EXTENDED_FSN_FIB_OFFSET (EXTENDED_BSN_BIB_OFFSET + EXTENDED_BSN_BIB_LENGTH)
84 #define EXTENDED_LI_OFFSET (EXTENDED_FSN_FIB_OFFSET + EXTENDED_FSN_FIB_LENGTH)
85 #define EXTENDED_SIO_OFFSET (EXTENDED_LI_OFFSET + EXTENDED_LI_LENGTH)
92 #define SPARE_MASK 0xc0
94 #define EXTENDED_BSN_MASK 0x0fff
95 #define EXTENDED_RES_MASK 0x7000
96 #define EXTENDED_BIB_MASK 0x8000
97 #define EXTENDED_FSN_MASK 0x0fff
98 #define EXTENDED_FIB_MASK 0x8000
99 #define EXTENDED_LI_MASK 0x01ff
100 #define EXTENDED_SPARE_MASK 0xfe00
103 dissect_mtp2_header(tvbuff_t *su_tvb, proto_item *mtp2_tree)
106 if (use_extended_sequence_numbers) {
107 proto_tree_add_item(mtp2_tree, hf_mtp2_ext_bsn, su_tvb, EXTENDED_BSN_BIB_OFFSET, EXTENDED_BSN_BIB_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
108 proto_tree_add_item(mtp2_tree, hf_mtp2_ext_res, su_tvb, EXTENDED_BSN_BIB_OFFSET, EXTENDED_BSN_BIB_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
109 proto_tree_add_item(mtp2_tree, hf_mtp2_ext_bib, su_tvb, EXTENDED_BSN_BIB_OFFSET, EXTENDED_BSN_BIB_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
110 proto_tree_add_item(mtp2_tree, hf_mtp2_ext_fsn, su_tvb, EXTENDED_FSN_FIB_OFFSET, EXTENDED_FSN_FIB_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
111 proto_tree_add_item(mtp2_tree, hf_mtp2_ext_res, su_tvb, EXTENDED_BSN_BIB_OFFSET, EXTENDED_BSN_BIB_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
112 proto_tree_add_item(mtp2_tree, hf_mtp2_ext_fib, su_tvb, EXTENDED_FSN_FIB_OFFSET, EXTENDED_FSN_FIB_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
113 proto_tree_add_item(mtp2_tree, hf_mtp2_ext_li, su_tvb, EXTENDED_LI_OFFSET, EXTENDED_LI_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
114 proto_tree_add_item(mtp2_tree, hf_mtp2_ext_spare, su_tvb, EXTENDED_LI_OFFSET, EXTENDED_LI_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
116 proto_tree_add_item(mtp2_tree, hf_mtp2_bsn, su_tvb, BSN_BIB_OFFSET, BSN_BIB_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
117 proto_tree_add_item(mtp2_tree, hf_mtp2_bib, su_tvb, BSN_BIB_OFFSET, BSN_BIB_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
118 proto_tree_add_item(mtp2_tree, hf_mtp2_fsn, su_tvb, FSN_FIB_OFFSET, FSN_FIB_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
119 proto_tree_add_item(mtp2_tree, hf_mtp2_fib, su_tvb, FSN_FIB_OFFSET, FSN_FIB_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
120 proto_tree_add_item(mtp2_tree, hf_mtp2_li, su_tvb, LI_OFFSET, LI_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
121 proto_tree_add_item(mtp2_tree, hf_mtp2_spare, su_tvb, LI_OFFSET, LI_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
127 dissect_mtp2_fisu(packet_info *pinfo)
129 if (check_col(pinfo->cinfo, COL_INFO))
130 col_set_str(pinfo->cinfo, COL_INFO, "FISU ");
133 static const value_string status_field_vals[] = {
134 { 0x0, "Status Indication O" },
135 { 0x1, "Status Indication N" },
136 { 0x2, "Status Indication E" },
137 { 0x3, "Status Indication OS" },
138 { 0x4, "Status Indication PO" },
139 { 0x5, "Status Indication BO" },
143 #define SF_OFFSET (LI_OFFSET + LI_LENGTH)
144 #define EXTENDED_SF_OFFSET (EXTENDED_LI_OFFSET + EXTENDED_LI_LENGTH)
147 #define LONG_SF_LENGTH 2
150 dissect_mtp2_lssu(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_tree)
152 if (check_col(pinfo->cinfo, COL_INFO))
153 col_set_str(pinfo->cinfo, COL_INFO, "LSSU ");
156 if (use_extended_sequence_numbers) {
157 if ((tvb_get_letohs(su_tvb, EXTENDED_LI_OFFSET) & EXTENDED_LI_MASK) == 1)
158 proto_tree_add_item(mtp2_tree, hf_mtp2_sf, su_tvb, EXTENDED_SF_OFFSET, SF_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
160 proto_tree_add_item(mtp2_tree, hf_mtp2_long_sf, su_tvb, EXTENDED_SF_OFFSET, LONG_SF_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
162 if ((tvb_get_guint8(su_tvb, LI_OFFSET) & LI_MASK) == 1)
163 proto_tree_add_item(mtp2_tree, hf_mtp2_sf, su_tvb, SF_OFFSET, SF_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
165 proto_tree_add_item(mtp2_tree, hf_mtp2_long_sf, su_tvb, SF_OFFSET, LONG_SF_LENGTH, LITTLE_ENDIAN_BYTE_ORDER);
171 dissect_mtp2_msu(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_item, proto_item *tree)
174 tvbuff_t *sif_sio_tvb;
176 if (check_col(pinfo->cinfo, COL_INFO))
177 col_set_str(pinfo->cinfo, COL_INFO, "MSU ");
179 if (use_extended_sequence_numbers) {
180 sif_sio_length = tvb_length(su_tvb) - EXTENDED_HEADER_LENGTH;
181 sif_sio_tvb = tvb_new_subset(su_tvb, EXTENDED_SIO_OFFSET, sif_sio_length, sif_sio_length);
183 sif_sio_length = tvb_length(su_tvb) - HEADER_LENGTH;
184 sif_sio_tvb = tvb_new_subset(su_tvb, SIO_OFFSET, sif_sio_length, sif_sio_length);
186 call_dissector(mtp3_handle, sif_sio_tvb, pinfo, tree);
189 if (use_extended_sequence_numbers)
190 proto_item_set_len(mtp2_item, EXTENDED_HEADER_LENGTH);
192 proto_item_set_len(mtp2_item, HEADER_LENGTH);
197 dissect_mtp2_su(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_item, proto_item *mtp2_tree, proto_tree *tree)
201 dissect_mtp2_header(su_tvb, mtp2_tree);
202 if (use_extended_sequence_numbers)
203 li = tvb_get_letohs(su_tvb, EXTENDED_LI_OFFSET) & EXTENDED_LI_MASK;
205 li = tvb_get_guint8(su_tvb, LI_OFFSET) & LI_MASK;
208 dissect_mtp2_fisu(pinfo);
212 dissect_mtp2_lssu(su_tvb, pinfo, mtp2_tree);
215 dissect_mtp2_msu(su_tvb, pinfo, mtp2_item, tree);
221 dissect_mtp2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
223 proto_item *mtp2_item = NULL;
224 proto_tree *mtp2_tree = NULL;
226 if (pinfo->annex_a_used == MTP2_ANNEX_A_USED_UNKNOWN)
227 use_extended_sequence_numbers = use_extended_sequence_numbers_default;
229 use_extended_sequence_numbers = (pinfo->annex_a_used == MTP2_ANNEX_A_USED);
231 if (check_col(pinfo->cinfo, COL_PROTOCOL))
232 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP2");
235 mtp2_item = proto_tree_add_item(tree, proto_mtp2, tvb, 0, -1, FALSE);
236 mtp2_tree = proto_item_add_subtree(mtp2_item, ett_mtp2);
239 dissect_mtp2_su(tvb, pinfo, mtp2_item, mtp2_tree, tree);
243 proto_register_mtp2(void)
246 static hf_register_info hf[] = {
247 { &hf_mtp2_bsn, { "Backward sequence number", "mtp2.bsn", FT_UINT8, BASE_DEC, NULL, BSN_MASK, "", HFILL } },
248 { &hf_mtp2_ext_bsn, { "Backward sequence number", "mtp2.bsn", FT_UINT16, BASE_DEC, NULL, EXTENDED_BSN_MASK, "", HFILL } },
249 { &hf_mtp2_ext_res, { "Reserved", "mtp2.res", FT_UINT16, BASE_DEC, NULL, EXTENDED_RES_MASK, "", HFILL } },
250 { &hf_mtp2_bib, { "Backward indicator bit", "mtp2.bib", FT_UINT8, BASE_DEC, NULL, BIB_MASK, "", HFILL } },
251 { &hf_mtp2_ext_bib, { "Backward indicator bit", "mtp2.bib", FT_UINT16, BASE_DEC, NULL, EXTENDED_BIB_MASK, "", HFILL } },
252 { &hf_mtp2_fsn, { "Forward sequence number", "mtp2.fsn", FT_UINT8, BASE_DEC, NULL, FSN_MASK, "", HFILL } },
253 { &hf_mtp2_ext_fsn, { "Forward sequence number", "mtp2.fsn", FT_UINT16, BASE_DEC, NULL, EXTENDED_FSN_MASK, "", HFILL } },
254 { &hf_mtp2_fib, { "Forward indicator bit", "mtp2.fib", FT_UINT8, BASE_DEC, NULL, FIB_MASK, "", HFILL } },
255 { &hf_mtp2_ext_fib, { "Forward indicator bit", "mtp2.fib", FT_UINT16, BASE_DEC, NULL, EXTENDED_FIB_MASK, "", HFILL } },
256 { &hf_mtp2_li, { "Length Indicator", "mtp2.li", FT_UINT8, BASE_DEC, NULL, LI_MASK, "", HFILL } },
257 { &hf_mtp2_ext_li, { "Length Indicator", "mtp2.li", FT_UINT16, BASE_DEC, NULL, EXTENDED_LI_MASK, "", HFILL } },
258 { &hf_mtp2_spare, { "Spare", "mtp2.spare", FT_UINT8, BASE_DEC, NULL, SPARE_MASK, "", HFILL } },
259 { &hf_mtp2_ext_spare, { "Spare", "mtp2.spare", FT_UINT16, BASE_DEC, NULL, EXTENDED_SPARE_MASK, "", HFILL } },
260 { &hf_mtp2_sf, { "Status field", "mtp2.sf", FT_UINT8, BASE_DEC, VALS(status_field_vals), 0x0, "", HFILL } },
261 { &hf_mtp2_long_sf, { "Status field", "mtp2.sf", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL } }
264 static gint *ett[] = {
268 module_t *mtp2_module;
270 proto_mtp2 = proto_register_protocol("Message Transfer Part Level 2", "MTP2", "mtp2");
271 register_dissector("mtp2", dissect_mtp2, proto_mtp2);
273 proto_register_field_array(proto_mtp2, hf, array_length(hf));
274 proto_register_subtree_array(ett, array_length(ett));
276 mtp2_module = prefs_register_protocol(proto_mtp2, NULL);
277 prefs_register_bool_preference(mtp2_module,
278 "use_extended_sequence_numbers",
279 "Use extended sequence numbers",
280 "Whether the MTP2 dissector should use extended sequence numbers as described in Q.703, Annex A as a default.",
281 &use_extended_sequence_numbers_default);
287 proto_reg_handoff_mtp2(void)
289 dissector_handle_t mtp2_handle;
291 mtp2_handle = create_dissector_handle(dissect_mtp2, proto_mtp2);
293 dissector_add("wtap_encap", WTAP_ENCAP_MTP2, mtp2_handle);
294 dissector_add("wtap_encap", WTAP_ENCAP_MTP2_WITH_PHDR, mtp2_handle);
296 mtp3_handle = find_dissector("mtp3");
297 mtp3_proto_id = proto_get_id_by_filter_name("mtp3");