For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[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 <epan/rtp_pt.h>
43 #include <epan/iax2_codec_type.h>
44
45 /* H.261 header fields             */
46 static int proto_h261          = -1;
47 static int hf_h261_sbit        = -1;
48 static int hf_h261_ebit        = -1;
49 static int hf_h261_ibit        = -1;
50 static int hf_h261_vbit        = -1;
51 static int hf_h261_gobn        = -1;
52 static int hf_h261_mbap        = -1;
53 static int hf_h261_quant       = -1;
54 static int hf_h261_hmvd        = -1; /* Mislabeled in a figure in section C.3.1 as HMDV */
55 static int hf_h261_vmvd        = -1;
56 static int hf_h261_data        = -1;
57
58 /* H.261 fields defining a sub tree */
59 static gint ett_h261           = -1;
60
61 static void
62 dissect_h261( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
63 {
64         proto_item *ti            = NULL;
65         proto_tree *h261_tree     = NULL;
66         unsigned int offset       = 0;
67
68         col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.261");
69
70         col_set_str(pinfo->cinfo, COL_INFO, "H.261 message");
71
72         if ( tree ) {
73                 ti = proto_tree_add_item( tree, proto_h261, tvb, offset, -1, ENC_NA );
74                 h261_tree = proto_item_add_subtree( ti, ett_h261 );
75                 /* SBIT 1st octet, 3 bits */
76                 proto_tree_add_uint( h261_tree, hf_h261_sbit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) >> 5 );
77                 /* EBIT 1st octet, 3 bits */
78                 proto_tree_add_uint( h261_tree, hf_h261_ebit, tvb, offset, 1, ( tvb_get_guint8( tvb, offset )  >> 2 ) & 7 );
79                 /* I flag, 1 bit */
80                 proto_tree_add_boolean( h261_tree, hf_h261_ibit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 2 );
81                 /* V flag, 1 bit */
82                 proto_tree_add_boolean( h261_tree, hf_h261_vbit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 1 );
83                 offset++;
84
85                 /* GOBN 2nd octet, 4 bits */
86                 proto_tree_add_uint( h261_tree, hf_h261_gobn, tvb, offset, 1, tvb_get_guint8( tvb, offset ) >> 4 );
87                 /* MBAP 2nd octet, 4 bits, 3rd octet 1 bit */
88                 proto_tree_add_uint( h261_tree, hf_h261_mbap, tvb, offset, 1,
89                     ( tvb_get_guint8( tvb, offset ) & 15 )
90                     + ( tvb_get_guint8( tvb, offset + 1 ) >> 7 ) );
91                 offset++;
92
93                 /* QUANT 3rd octet, 5 bits (starting at bit 2!) */
94                 proto_tree_add_uint( h261_tree, hf_h261_quant, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 124 );
95
96                 /* HMVD 3rd octet 2 bits, 4th octet 3 bits */
97                 proto_tree_add_uint( h261_tree, hf_h261_hmvd, tvb, offset, 2,
98                     ( ( tvb_get_guint8( tvb, offset ) & 0x03 ) << 3 )
99                      + ( tvb_get_guint8( tvb, offset+1 ) >> 5 ) );
100                 offset++;
101
102                 /* VMVD 4th octet, last 5 bits */
103                 proto_tree_add_uint( h261_tree, hf_h261_vmvd, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 31 );
104                 offset++;
105
106                 /* The rest of the packet is the H.261 stream */
107                 proto_tree_add_item( h261_tree, hf_h261_data, tvb, offset, -1, ENC_NA );
108         }
109 }
110
111 void
112 proto_register_h261(void)
113 {
114         static hf_register_info hf[] =
115         {
116                 {
117                         &hf_h261_sbit,
118                         {
119                                 "Start bit position",
120                                 "h261.sbit",
121                                 FT_UINT8,
122                                 BASE_DEC,
123                                 NULL,
124                                 0x0,
125                                 NULL, HFILL
126                         }
127                 },
128                 {
129                         &hf_h261_ebit,
130                         {
131                                 "End bit position",
132                                 "h261.ebit",
133                                 FT_UINT8,
134                                 BASE_DEC,
135                                 NULL,
136                                 0x0,
137                                 NULL, HFILL
138                         }
139                 },
140                 {
141                         &hf_h261_ibit,
142                         {
143                                 "Intra frame encoded data flag",
144                                 "h261.i",
145                                 FT_BOOLEAN,
146                                 BASE_NONE,
147                                 NULL,
148                                 0x0,
149                                 NULL, HFILL
150                         }
151                 },
152                 {
153                         &hf_h261_vbit,
154                         {
155                                 "Motion vector flag",
156                                 "h261.v",
157                                 FT_BOOLEAN,
158                                 BASE_NONE,
159                                 NULL,
160                                 0x0,
161                                 NULL, HFILL
162                         }
163                 },
164                 {
165                         &hf_h261_gobn,
166                         {
167                                 "GOB Number",
168                                 "h261.gobn",
169                                 FT_UINT8,
170                                 BASE_DEC,
171                                 NULL,
172                                 0x0,
173                                 NULL, HFILL
174                         }
175                 },
176                 {
177                         &hf_h261_mbap,
178                         {
179                                 "Macroblock address predictor",
180                                 "h261.mbap",
181                                 FT_UINT8,
182                                 BASE_DEC,
183                                 NULL,
184                                 0x0,
185                                 NULL, HFILL
186                         }
187                 },
188                 {
189                         &hf_h261_quant,
190                         {
191                                 "Quantizer",
192                                 "h261.quant",
193                                 FT_UINT8,
194                                 BASE_DEC,
195                                 NULL,
196                                 0x0,
197                                 NULL, HFILL
198                         }
199                 },
200                 {
201                         &hf_h261_hmvd,
202                         {
203                                 "Horizontal motion vector data",
204                                 "h261.hmvd",
205                                 FT_UINT8,
206                                 BASE_DEC,
207                                 NULL,
208                                 0x0,
209                                 NULL, HFILL
210                         }
211                 },
212                 {
213                         &hf_h261_vmvd,
214                         {
215                                 "Vertical motion vector data",
216                                 "h261.vmvd",
217                                 FT_UINT8,
218                                 BASE_DEC,
219                                 NULL,
220                                 0x0,
221                                 NULL, HFILL
222                         }
223                 },
224                 {
225                         &hf_h261_data,
226                         {
227                                 "H.261 stream",
228                                 "h261.stream",
229                                 FT_BYTES,
230                                 BASE_NONE,
231                                 NULL,
232                                 0x0,
233                                 NULL, HFILL
234                         }
235                 },
236 };
237
238         static gint *ett[] =
239         {
240                 &ett_h261,
241         };
242
243
244         proto_h261 = proto_register_protocol("ITU-T Recommendation H.261",
245             "H.261", "h261");
246         proto_register_field_array(proto_h261, hf, array_length(hf));
247         proto_register_subtree_array(ett, array_length(ett));
248 }
249
250 void
251 proto_reg_handoff_h261(void)
252 {
253         dissector_handle_t h261_handle;
254
255         h261_handle = create_dissector_handle(dissect_h261, proto_h261);
256         dissector_add_uint("rtp.pt", PT_H261, h261_handle);
257         dissector_add_uint("iax2.codec", AST_FORMAT_H261, h261_handle);
258 }