Sanitize epan includes
[obnox/wireshark/wip.git] / epan / dissectors / packet-h261.c
1 /* packet-h261.c
2  *
3  * Routines for ITU-T Recommendation H.261 dissection
4  *
5  * $Id$
6  *
7  * Copyright 2000, Philips Electronics N.V.
8  * Andreas Sikkema <h323@ramdyne.nl>
9  *
10  * Wireshark - Network traffic analyzer
11  * By Gerald Combs <gerald@wireshark.org>
12  * Copyright 1998 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  */
28
29 /*
30  * This dissector tries to dissect the H.261 protocol according to Annex C
31  * of ITU-T Recommendation H.225.0 (02/98)
32  */
33
34
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include <glib.h>
40 #include <epan/packet.h>
41
42 #include <stdio.h>
43 #include <string.h>
44
45 #include <epan/rtp_pt.h>
46 #include <epan/iax2_codec_type.h>
47
48 /* H.261 header fields             */
49 static int proto_h261          = -1;
50 static int hf_h261_sbit        = -1;
51 static int hf_h261_ebit        = -1;
52 static int hf_h261_ibit        = -1;
53 static int hf_h261_vbit        = -1;
54 static int hf_h261_gobn        = -1;
55 static int hf_h261_mbap        = -1;
56 static int hf_h261_quant       = -1;
57 static int hf_h261_hmvd        = -1; /* Mislabeled in a figure in section C.3.1 as HMDV */
58 static int hf_h261_vmvd        = -1;
59 static int hf_h261_data        = -1;
60
61 /* H.261 fields defining a sub tree */
62 static gint ett_h261           = -1;
63
64 static void
65 dissect_h261( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
66 {
67         proto_item *ti            = NULL;
68         proto_tree *h261_tree     = NULL;
69         unsigned int offset       = 0;
70
71         col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.261");
72
73         col_set_str(pinfo->cinfo, COL_INFO, "H.261 message");
74
75         if ( tree ) {
76                 ti = proto_tree_add_item( tree, proto_h261, tvb, offset, -1, FALSE );
77                 h261_tree = proto_item_add_subtree( ti, ett_h261 );
78                 /* SBIT 1st octet, 3 bits */
79                 proto_tree_add_uint( h261_tree, hf_h261_sbit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) >> 5 );
80                 /* EBIT 1st octet, 3 bits */
81                 proto_tree_add_uint( h261_tree, hf_h261_ebit, tvb, offset, 1, ( tvb_get_guint8( tvb, offset )  >> 2 ) & 7 );
82                 /* I flag, 1 bit */
83                 proto_tree_add_boolean( h261_tree, hf_h261_ibit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 2 );
84                 /* V flag, 1 bit */
85                 proto_tree_add_boolean( h261_tree, hf_h261_vbit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 1 );
86                 offset++;
87
88                 /* GOBN 2nd octet, 4 bits */
89                 proto_tree_add_uint( h261_tree, hf_h261_gobn, tvb, offset, 1, tvb_get_guint8( tvb, offset ) >> 4 );
90                 /* MBAP 2nd octet, 4 bits, 3rd octet 1 bit */
91                 proto_tree_add_uint( h261_tree, hf_h261_mbap, tvb, offset, 1,
92                     ( tvb_get_guint8( tvb, offset ) & 15 )
93                     + ( tvb_get_guint8( tvb, offset + 1 ) >> 7 ) );
94                 offset++;
95
96                 /* QUANT 3rd octet, 5 bits (starting at bit 2!) */
97                 proto_tree_add_uint( h261_tree, hf_h261_quant, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 124 );
98
99                 /* HMVD 3rd octet 2 bits, 4th octet 3 bits */
100                 proto_tree_add_uint( h261_tree, hf_h261_hmvd, tvb, offset, 2,
101                     ( ( tvb_get_guint8( tvb, offset ) & 0x03 ) << 3 )
102                      + ( tvb_get_guint8( tvb, offset+1 ) >> 5 ) );
103                 offset++;
104
105                 /* VMVD 4th octet, last 5 bits */
106                 proto_tree_add_uint( h261_tree, hf_h261_vmvd, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 31 );
107                 offset++;
108
109                 /* The rest of the packet is the H.261 stream */
110                 proto_tree_add_item( h261_tree, hf_h261_data, tvb, offset, -1, FALSE );
111         }
112 }
113
114 void
115 proto_register_h261(void)
116 {
117         static hf_register_info hf[] =
118         {
119                 {
120                         &hf_h261_sbit,
121                         {
122                                 "Start bit position",
123                                 "h261.sbit",
124                                 FT_UINT8,
125                                 BASE_DEC,
126                                 NULL,
127                                 0x0,
128                                 NULL, HFILL
129                         }
130                 },
131                 {
132                         &hf_h261_ebit,
133                         {
134                                 "End bit position",
135                                 "h261.ebit",
136                                 FT_UINT8,
137                                 BASE_DEC,
138                                 NULL,
139                                 0x0,
140                                 NULL, HFILL
141                         }
142                 },
143                 {
144                         &hf_h261_ibit,
145                         {
146                                 "Intra frame encoded data flag",
147                                 "h261.i",
148                                 FT_BOOLEAN,
149                                 BASE_NONE,
150                                 NULL,
151                                 0x0,
152                                 NULL, HFILL
153                         }
154                 },
155                 {
156                         &hf_h261_vbit,
157                         {
158                                 "Motion vector flag",
159                                 "h261.v",
160                                 FT_BOOLEAN,
161                                 BASE_NONE,
162                                 NULL,
163                                 0x0,
164                                 NULL, HFILL
165                         }
166                 },
167                 {
168                         &hf_h261_gobn,
169                         {
170                                 "GOB Number",
171                                 "h261.gobn",
172                                 FT_UINT8,
173                                 BASE_DEC,
174                                 NULL,
175                                 0x0,
176                                 NULL, HFILL
177                         }
178                 },
179                 {
180                         &hf_h261_mbap,
181                         {
182                                 "Macroblock address predictor",
183                                 "h261.mbap",
184                                 FT_UINT8,
185                                 BASE_DEC,
186                                 NULL,
187                                 0x0,
188                                 NULL, HFILL
189                         }
190                 },
191                 {
192                         &hf_h261_quant,
193                         {
194                                 "Quantizer",
195                                 "h261.quant",
196                                 FT_UINT8,
197                                 BASE_DEC,
198                                 NULL,
199                                 0x0,
200                                 NULL, HFILL
201                         }
202                 },
203                 {
204                         &hf_h261_hmvd,
205                         {
206                                 "Horizontal motion vector data",
207                                 "h261.hmvd",
208                                 FT_UINT8,
209                                 BASE_DEC,
210                                 NULL,
211                                 0x0,
212                                 NULL, HFILL
213                         }
214                 },
215                 {
216                         &hf_h261_vmvd,
217                         {
218                                 "Vertical motion vector data",
219                                 "h261.vmvd",
220                                 FT_UINT8,
221                                 BASE_DEC,
222                                 NULL,
223                                 0x0,
224                                 NULL, HFILL
225                         }
226                 },
227                 {
228                         &hf_h261_data,
229                         {
230                                 "H.261 stream",
231                                 "h261.stream",
232                                 FT_BYTES,
233                                 BASE_NONE,
234                                 NULL,
235                                 0x0,
236                                 NULL, HFILL
237                         }
238                 },
239 };
240
241         static gint *ett[] =
242         {
243                 &ett_h261,
244         };
245
246
247         proto_h261 = proto_register_protocol("ITU-T Recommendation H.261",
248             "H.261", "h261");
249         proto_register_field_array(proto_h261, hf, array_length(hf));
250         proto_register_subtree_array(ett, array_length(ett));
251 }
252
253 void
254 proto_reg_handoff_h261(void)
255 {
256         dissector_handle_t h261_handle;
257
258         h261_handle = create_dissector_handle(dissect_h261, proto_h261);
259         dissector_add("rtp.pt", PT_H261, h261_handle);
260         dissector_add("iax2.codec", AST_FORMAT_H261, h261_handle);
261 }