HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-2dparityfec.c
blob85221e7f92792c732567669a3e499c5d84ffff94
1 /* packet-2dparityfec.c
2 * Mark Lewis <mlewis@altera.com>
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 ** RTP Payload dissector for packets as specified in:
27 ** Pro-MPEG Code of Practice #3 release 2
29 ** This protocol defines a format for FEC data embedded within RTP packets with
30 ** a payload type of 96 (0x60). The format of the FEC packets, which reside within
31 ** the RTP payload, is as follows...
33 ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 ** | SNBase low bits | Length Recovery |
35 ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 ** |E| PT recovery | Mask |
37 ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 ** | TS recovery |
39 ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 ** |X|D|type |index| Offset | NA |SNBase ext bits|
41 ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 ** | |
43 ** : FEC Payload :
44 ** | |
45 ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 ** For more information on this protocol see...
48 ** http://www.pro-mpeg.org/publications/pdf/Vid-on-IP-CoP3-r2.pdf
51 ** Notes:
53 ** This protocol always resides in RTP packets with payload type 96. However,
54 ** type 96 is dynamic and may refer to other protocols. As Pro-MPEG FEC must
55 ** function in the absence of a control channel, and because this data is
56 ** likely to be transmitted within closed networks, no automatic mechanism
57 ** exists for specifying the existence of Pro-MPEG FEC on payload type 96.
58 ** This dissector is thus disabled by default. Dissection of this protocol
59 ** may be enabled from the 2dparityfec panel under Preferences->Protocols.
61 ** Mark Lewis - 20th June 2006
64 #define NEW_PROTO_TREE_API
66 #include "config.h"
68 #include <epan/packet.h>
69 #include <epan/prefs.h>
71 /* forward reference */
72 void proto_register_2dparityfec(void);
73 void proto_reg_handoff_2dparityfec(void);
75 static dissector_handle_t handle_2dparityfec = NULL;
77 static gboolean dissect_fec = FALSE;
79 static int fec_rtp_payload_type = 96;
80 static gint ett_2dparityfec = -1;
82 static header_field_info *hfi_2dparityfec = NULL;
84 #define _2DPARITYFEC_HFI_INIT HFI_INIT(proto_2dparityfec)
86 static header_field_info hfi_2dparityfec_snbase_low _2DPARITYFEC_HFI_INIT =
87 { "SNBase low",
88 "2dparityfec.snbase_low",
89 FT_UINT16,
90 BASE_DEC,
91 NULL,
92 0x0,
93 NULL,
94 HFILL};
96 static header_field_info hfi_2dparityfec_length_recovery _2DPARITYFEC_HFI_INIT =
97 { "Length recovery",
98 "2dparityfec.lr",
99 FT_UINT16,
100 BASE_HEX,
101 NULL,
102 0x0,
103 NULL,
104 HFILL};
106 static header_field_info hfi_2dparityfec_rfc2733_ext _2DPARITYFEC_HFI_INIT =
107 { "RFC2733 Extension (E)",
108 "2dparityfec.e",
109 FT_BOOLEAN,
111 NULL,
112 0x80,
113 NULL,
114 HFILL};
116 static header_field_info hfi_2dparityfec_pt_recovery _2DPARITYFEC_HFI_INIT =
117 { "Payload Type recovery",
118 "2dparityfec.ptr",
119 FT_UINT8,
120 BASE_HEX,
121 NULL,
122 0x7f,
123 NULL,
124 HFILL};
126 static header_field_info hfi_2dparityfec_mask _2DPARITYFEC_HFI_INIT =
127 { "Mask",
128 "2dparityfec.mask",
129 /*FT_UINT32*/FT_UINT24,
130 BASE_HEX,
131 NULL,
132 /*0x00ffffff*/0x0,
133 NULL,
134 HFILL};
136 static header_field_info hfi_2dparityfec_ts_recovery _2DPARITYFEC_HFI_INIT =
137 { "Timestamp recovery",
138 "2dparityfec.tsr",
139 FT_UINT32,
140 BASE_HEX,
141 NULL,
142 0x0,
143 NULL,
144 HFILL};
146 static header_field_info hfi_2dparityfec_ts_pro_mpeg_ext _2DPARITYFEC_HFI_INIT =
147 { "Pro-MPEG Extension (X)",
148 "2dparityfec.x",
149 FT_BOOLEAN,
151 NULL,
152 0x80,
153 NULL,
154 HFILL};
156 static header_field_info hfi_2dparityfec_row_flag _2DPARITYFEC_HFI_INIT =
157 { "Row FEC (D)",
158 "2dparityfec.d",
159 FT_BOOLEAN,
161 NULL,
162 0x40,
163 NULL,
164 HFILL};
166 static const value_string fec_type_names[] = {
167 {0, "XOR"},
168 {1, "Hamming"},
169 {2, "Reed-Solomon"},
170 {0, NULL}
173 static header_field_info hfi_2dparityfec_type _2DPARITYFEC_HFI_INIT =
174 { "Type",
175 "2dparityfec.type",
176 FT_UINT8,
177 BASE_DEC,
178 VALS(fec_type_names),
179 0x38,
180 NULL,
181 HFILL};
183 static header_field_info hfi_2dparityfec_index _2DPARITYFEC_HFI_INIT =
184 { "Index",
185 "2dparityfec.index",
186 FT_UINT8,
187 BASE_DEC,
188 NULL,
189 0x07,
190 NULL,
191 HFILL};
193 static header_field_info hfi_2dparityfec_offset _2DPARITYFEC_HFI_INIT =
194 { "Offset",
195 "2dparityfec.offset",
196 FT_UINT8,
197 BASE_DEC,
198 NULL,
199 0x0,
200 NULL,
201 HFILL};
203 static header_field_info hfi_2dparityfec_na _2DPARITYFEC_HFI_INIT =
204 { "NA",
205 "2dparityfec.na",
206 FT_UINT8,
207 BASE_DEC,
208 NULL,
209 0x0,
210 NULL,
211 HFILL};
213 static header_field_info hfi_2dparityfec_snbase_ext _2DPARITYFEC_HFI_INIT =
214 { "SNBase ext",
215 "2dparityfec.snbase_ext",
216 FT_UINT8,
217 BASE_DEC,
218 NULL,
219 0x0,
220 NULL,
221 HFILL};
223 static header_field_info hfi_2dparityfec_payload _2DPARITYFEC_HFI_INIT =
224 { "FEC Payload",
225 "2dparityfec.payload",
226 FT_BYTES,
227 BASE_NONE,
228 NULL,
229 0x0,
230 NULL,
231 HFILL};
234 static void dissect_2dparityfec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
236 guint8 OffsetField;
237 guint8 NAField;
238 guint32 SNBase;
239 guint8 D;
241 /* Extract SNBase */
242 SNBase = (guint32)tvb_get_guint8(tvb, 0)<<8;
243 SNBase |= (guint32)tvb_get_guint8(tvb, 1);
244 SNBase |= (guint32)tvb_get_guint8(tvb, 15)<<16;
246 /* Extract D */
247 D = (tvb_get_guint8(tvb, 12)>>6) & 0x1;
249 /* Extract Offset and NA */
250 OffsetField = tvb_get_guint8(tvb, 13);
251 NAField = tvb_get_guint8(tvb, 14);
253 col_set_str(pinfo->cinfo, COL_PROTOCOL, "2dFEC");
255 /* Configure the info column */
256 if(D)
258 col_add_fstr(pinfo->cinfo, COL_INFO, "Row FEC - SNBase=%u, Offset=%u, NA=%u",
259 SNBase, OffsetField, NAField);
261 else
263 col_add_fstr(pinfo->cinfo, COL_INFO, "Column FEC - SNBase=%u, Offset=%u, NA=%u",
264 SNBase, OffsetField, NAField);
267 if(tree)
269 /* we are being asked for details */
270 proto_item *ti = NULL;
271 proto_tree *tree_2dparityfec = NULL;
272 gint offset = 0;
274 ti = proto_tree_add_item(tree, hfi_2dparityfec, tvb, 0, -1, ENC_NA);
275 tree_2dparityfec = proto_item_add_subtree(ti, ett_2dparityfec);
277 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_snbase_low, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2;
278 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_length_recovery, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2;
279 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_rfc2733_ext, tvb, offset, 1, ENC_BIG_ENDIAN);
280 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_pt_recovery, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1;
281 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_mask, tvb, offset, 3, ENC_BIG_ENDIAN); offset += 3;
282 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_ts_recovery, tvb, offset, 4, ENC_BIG_ENDIAN); offset += 4;
283 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_ts_pro_mpeg_ext, tvb, offset, 1, ENC_BIG_ENDIAN);
284 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_row_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
285 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_type, tvb, offset, 1, ENC_BIG_ENDIAN);
286 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_index, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1;
287 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_offset, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1;
288 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_na, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1;
289 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_snbase_ext, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1;
290 proto_tree_add_item(tree_2dparityfec, &hfi_2dparityfec_payload, tvb, offset, -1, ENC_NA);
294 void proto_register_2dparityfec(void)
296 module_t *module_2dparityfec;
298 #ifndef HAVE_HFI_SECTION_INIT
299 /* Payload type definitions */
300 static header_field_info *hfi[] = {
301 &hfi_2dparityfec_snbase_low,
302 &hfi_2dparityfec_length_recovery,
303 &hfi_2dparityfec_rfc2733_ext,
304 &hfi_2dparityfec_pt_recovery,
305 &hfi_2dparityfec_mask,
306 &hfi_2dparityfec_ts_recovery,
307 &hfi_2dparityfec_ts_pro_mpeg_ext,
308 &hfi_2dparityfec_row_flag,
309 &hfi_2dparityfec_type,
310 &hfi_2dparityfec_index,
311 &hfi_2dparityfec_offset,
312 &hfi_2dparityfec_na,
313 &hfi_2dparityfec_snbase_ext,
314 &hfi_2dparityfec_payload,
316 #endif
318 /* Setup protocol subtree array */
319 static gint *ett[] = {
320 &ett_2dparityfec,
323 int proto_2dparityfec;
325 proto_2dparityfec = proto_register_protocol(
326 "Pro-MPEG Code of Practice #3 release 2 FEC Protocol", /* name */
327 "2dparityfec", /* short name */
328 "2dparityfec"); /* abbrev */
329 hfi_2dparityfec = proto_registrar_get_nth(proto_2dparityfec);
331 proto_register_fields(proto_2dparityfec, hfi, array_length(hfi));
332 proto_register_subtree_array(ett, array_length(ett));
334 module_2dparityfec = prefs_register_protocol(proto_2dparityfec,
335 proto_reg_handoff_2dparityfec);
337 prefs_register_bool_preference(module_2dparityfec, "enable",
338 "Decode Pro-MPEG FEC on RTP dynamic payload type 96",
339 "Enable this option to recognise all traffic on RTP dynamic payload type 96 (0x60) "
340 "as FEC data corresponding to Pro-MPEG Code of Practice #3 release 2",
341 &dissect_fec);
343 handle_2dparityfec = create_dissector_handle(dissect_2dparityfec,
344 proto_2dparityfec);
347 void proto_reg_handoff_2dparityfec(void)
349 if (dissect_fec) {
350 dissector_add_uint("rtp.pt", fec_rtp_payload_type, handle_2dparityfec);
351 } else {
352 dissector_delete_uint("rtp.pt", fec_rtp_payload_type, handle_2dparityfec);
357 * Editor modelines
359 * Local Variables:
360 * c-basic-offset: 3
361 * tab-width: 8
362 * indent-tabs-mode: nil
363 * End:
365 * ex: set shiftwidth=3 tabstop=8 expandtab:
366 * :indentSize=3:tabSize=8:noTabs=true: