Don't guard col_set_str (COL_INFO/COL_PROTOCOL) with col_check
[obnox/wireshark/wip.git] / epan / dissectors / packet-2dparityfec.c
1 /* packet-2dparityfec.c
2  * Mark Lewis <mlewis@altera.com>
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 /*
26 ** RTP Payload dissector for packets as specified in:
27 ** Pro-MPEG Code of Practice #3 release 2
28 **
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...
32 **
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 **   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 **
47 ** For more information on this protocol see...
48 ** http://www.pro-mpeg.org/publications/pdf/Vid-on-IP-CoP3-r2.pdf
49 **
50 **
51 ** Notes:
52 **
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 existance 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.
60 **
61 ** Mark Lewis - 20th June 2006
62 */
63
64 #ifdef HAVE_CONFIG_H
65 # include "config.h"
66 #endif
67
68 #include <epan/packet.h>
69 #include <epan/prefs.h>
70
71 /* forward reference */
72 void proto_reg_handoff_2dparityfec(void);
73
74 static gboolean dissect_fec = FALSE;
75
76 static int proto_2dparityfec = -1;
77 static int fec_rtp_payload_type = 96;
78 static gint ett_2dparityfec = -1;
79
80 static int hf_2dparityfec_snbase_low      = -1;
81 static int hf_2dparityfec_length_recovery = -1;
82 static int hf_2dparityfec_rfc2733_ext     = -1;
83 static int hf_2dparityfec_pt_recovery     = -1;
84 static int hf_2dparityfec_mask            = -1;
85 static int hf_2dparityfec_ts_recovery     = -1;
86 static int hf_2dparityfec_ts_pro_mpeg_ext = -1;
87 static int hf_2dparityfec_row_flag        = -1;
88 static int hf_2dparityfec_type            = -1;
89 static int hf_2dparityfec_index           = -1;
90 static int hf_2dparityfec_offset          = -1;
91 static int hf_2dparityfec_na              = -1;
92 static int hf_2dparityfec_snbase_ext      = -1;
93 static int hf_2dparityfec_payload         = -1;
94
95 static const value_string fec_type_names[] = {
96    {0, "XOR"},
97    {1, "Hamming"},
98    {2, "Reed-Solomon"},
99    {0, NULL}
100 };
101
102 static void dissect_2dparityfec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
103 {
104    guint8   OffsetField;
105    guint8   NAField;
106    guint32  SNBase;
107    guint8   D;
108
109    /* Extract SNBase */
110    SNBase  = (guint32)tvb_get_guint8(tvb, 0)<<8;
111    SNBase |= (guint32)tvb_get_guint8(tvb, 1);
112    SNBase |= (guint32)tvb_get_guint8(tvb, 15)<<16;
113
114    /* Extract D */
115    D = (tvb_get_guint8(tvb, 12)>>6) & 0x1;
116
117    /* Extract Offset and NA */
118    OffsetField    = tvb_get_guint8(tvb, 13);
119    NAField        = tvb_get_guint8(tvb, 14);
120
121    col_set_str(pinfo->cinfo, COL_PROTOCOL, "2dFEC");
122
123    /* Configure the info column */
124    if(check_col(pinfo->cinfo, COL_INFO))
125    {
126       col_clear(pinfo->cinfo, COL_INFO);
127
128       if(D)
129       {
130          col_add_fstr(pinfo->cinfo, COL_INFO, "Row FEC - SNBase=%u, Offset=%u, NA=%u",
131                                                 SNBase, OffsetField, NAField);
132       }
133       else
134       {
135          col_add_fstr(pinfo->cinfo, COL_INFO, "Column FEC - SNBase=%u, Offset=%u, NA=%u",
136                                                 SNBase, OffsetField, NAField);
137       }
138    }
139
140    if(tree)
141    {
142       /* we are being asked for details */
143       proto_item *ti = NULL;
144       proto_tree *tree_2dparityfec = NULL;
145       gint offset = 0;
146
147       ti = proto_tree_add_item(tree, proto_2dparityfec, tvb, 0, -1, FALSE);
148       tree_2dparityfec = proto_item_add_subtree(ti, ett_2dparityfec);
149
150       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_snbase_low,      tvb, offset, 2, FALSE); offset += 2;
151       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_length_recovery, tvb, offset, 2, FALSE); offset += 2;
152       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_rfc2733_ext,     tvb, offset, 1, FALSE);
153       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_pt_recovery,     tvb, offset, 1, FALSE); offset += 1;
154       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_mask,            tvb, offset, 3, FALSE); offset += 3;
155       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_ts_recovery,     tvb, offset, 4, FALSE); offset += 4;
156       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_ts_pro_mpeg_ext, tvb, offset, 1, FALSE);
157       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_row_flag,        tvb, offset, 1, FALSE);
158       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_type,            tvb, offset, 1, FALSE);
159       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_index,           tvb, offset, 1, FALSE); offset += 1;
160       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_offset,          tvb, offset, 1, FALSE); offset += 1;
161       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_na,              tvb, offset, 1, FALSE); offset += 1;
162       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_snbase_ext,      tvb, offset, 1, FALSE); offset += 1;
163       proto_tree_add_item(tree_2dparityfec, hf_2dparityfec_payload,         tvb, offset, -1, FALSE);
164    }
165 }
166
167 void proto_register_2dparityfec(void)
168 {
169    module_t *module_2dparityfec;
170
171 /* Payload type definitions */
172 static hf_register_info hf[] = {
173    {&hf_2dparityfec_snbase_low,
174       {   "SNBase low",
175          "2dparityfec.snbase_low",
176          FT_UINT16,
177          BASE_DEC,
178          NULL,
179          0x0,
180          NULL,
181          HFILL}   },
182
183    {&hf_2dparityfec_length_recovery,
184       {  "Length recovery",
185          "2dparityfec.lr",
186          FT_UINT16,
187          BASE_HEX,
188          NULL,
189          0x0,
190          NULL,
191          HFILL}   },
192
193    {&hf_2dparityfec_rfc2733_ext,
194       {  "RFC2733 Extension (E)",
195          "2dparityfec.e",
196          FT_BOOLEAN,
197          8,
198          NULL,
199          0x80,
200          NULL,
201          HFILL}   },
202
203    {&hf_2dparityfec_pt_recovery,
204       {  "Payload Type recovery",
205          "2dparityfec.ptr",
206          FT_UINT8,
207          BASE_HEX,
208          NULL,
209          0x7f,
210          NULL,
211          HFILL}   },
212
213    {&hf_2dparityfec_mask,
214       {  "Mask",
215          "2dparityfec.mask",
216          /*FT_UINT32*/FT_UINT24,
217          BASE_HEX,
218          NULL,
219          /*0x00ffffff*/0x0,
220          NULL,
221          HFILL}   },
222
223    {&hf_2dparityfec_ts_recovery,
224       {  "Timestamp recovery",
225          "2dparityfec.tsr",
226          FT_UINT32,
227          BASE_HEX,
228          NULL,
229          0x0,
230          NULL,
231          HFILL}   },
232
233    {&hf_2dparityfec_ts_pro_mpeg_ext,
234       {  "Pro-MPEG Extension (X)",
235          "2dparityfec.x",
236          FT_BOOLEAN,
237          8,
238          NULL,
239          0x80,
240          NULL,
241          HFILL}   },
242
243    {&hf_2dparityfec_row_flag,
244       {  "Row FEC (D)",
245          "2dparityfec.d",
246          FT_BOOLEAN,
247          8,
248          NULL,
249          0x40,
250          NULL,
251          HFILL}   },
252
253    {&hf_2dparityfec_type,
254       {  "Type",
255          "2dparityfec.type",
256          FT_UINT8,
257          BASE_DEC,
258          VALS(fec_type_names),
259          0x38,
260          NULL,
261          HFILL}   },
262
263    {&hf_2dparityfec_index,
264       {  "Index",
265          "2dparityfec.index",
266          FT_UINT8,
267          BASE_DEC,
268          NULL,
269          0x07,
270          NULL,
271          HFILL}   },
272
273    {&hf_2dparityfec_offset,
274       {  "Offset",
275          "2dparityfec.offset",
276          FT_UINT8,
277          BASE_DEC,
278          NULL,
279          0x0,
280          NULL,
281          HFILL}   },
282
283    {&hf_2dparityfec_na,
284       {  "NA",
285          "2dparityfec.na",
286          FT_UINT8,
287          BASE_DEC,
288          NULL,
289          0x0,
290          NULL,
291          HFILL}   },
292
293    {&hf_2dparityfec_snbase_ext,
294       {  "SNBase ext",
295          "2dparityfec.snbase_ext",
296          FT_UINT8,
297          BASE_DEC,
298          NULL,
299          0x0,
300          NULL,
301          HFILL}   },
302
303    {&hf_2dparityfec_payload,
304       {  "FEC Payload",
305          "2dparityfec.payload",
306          FT_BYTES,
307          BASE_NONE,
308          NULL,
309          0x0,
310          NULL,
311          HFILL}   }
312
313
314 };
315
316 /* Setup protocol subtree array */
317 static gint *ett[] = {
318    &ett_2dparityfec,
319 };
320
321    proto_2dparityfec = proto_register_protocol(
322       "Pro-MPEG Code of Practice #3 release 2 FEC Protocol",   /* name */
323       "2dparityfec",            /* short name */
324       "2dparityfec");           /* abbrev */
325
326    proto_register_field_array(proto_2dparityfec, hf, array_length(hf));
327    proto_register_subtree_array(ett, array_length(ett));
328
329    module_2dparityfec = prefs_register_protocol(proto_2dparityfec,
330                                                 proto_reg_handoff_2dparityfec);
331
332    prefs_register_bool_preference(module_2dparityfec, "enable",
333         "Decode Pro-MPEG FEC on RTP dynamic payload type 96",
334         "Enable this option to recognise all traffic on RTP dynamic payload type 96 (0x60) "
335         "as FEC data corresponding to Pro-MPEG Code of Practice #3 release 2",
336         &dissect_fec);
337
338 }
339
340 void proto_reg_handoff_2dparityfec(void)
341 {
342    static dissector_handle_t handle_2dparityfec = NULL;
343
344    if (!handle_2dparityfec) {
345       handle_2dparityfec = create_dissector_handle(dissect_2dparityfec,
346                                                    proto_2dparityfec);
347    }
348
349    if (dissect_fec) {
350       dissector_add("rtp.pt", fec_rtp_payload_type, handle_2dparityfec);
351    } else {
352       dissector_delete("rtp.pt", fec_rtp_payload_type, handle_2dparityfec);
353    }
354 }
355
356 /*
357  * Editor modelines
358  *
359  * Local Variables:
360  * c-basic-offset: 3
361  * tab-width: 3
362  * indent-tabs-mode: nil
363  * End:
364  *
365  * ex: set shiftwidth=3 tabstop=3 expandtab
366  * :indentSize=3:tabSize=3:noTabs=true:
367  */