Move the STRING dissector to packet-dcerpc-nt.c and add one more parameter
[obnox/wireshark/wip.git] / packet-h261.c
1 /* packet-h261.c
2  *
3  * Routines for ITU-T Recommendation H.261 dissection
4  *
5  * $Id: packet-h261.c,v 1.15 2002/02/01 07:37:20 guy Exp $
6  * 
7  * Copyright 2000, Philips Electronics N.V.
8  * Andreas Sikkema <andreas.sikkema@philips.com>
9  *
10  * Ethereal - Network traffic analyzer
11  * By Gerald Combs <gerald@ethereal.com>
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  * This dissector is called by the RTP dissector
34  */
35
36
37 #ifdef HAVE_CONFIG_H
38 # include "config.h"
39 #endif
40
41 #include <glib.h>
42 #include <epan/packet.h>
43
44 #ifdef HAVE_SYS_TYPES_H
45 #  include <sys/types.h>
46 #endif
47
48 #ifdef HAVE_NETINET_IN_H
49 #  include <netinet/in.h>
50 #endif
51
52 #include <stdio.h>
53 #include <string.h>
54
55 /* H.261 header fields             */
56 static int proto_h261          = -1;
57 static int hf_h261_sbit        = -1;
58 static int hf_h261_ebit        = -1;
59 static int hf_h261_ibit        = -1;
60 static int hf_h261_vbit        = -1;
61 static int hf_h261_gobn        = -1;
62 static int hf_h261_mbap        = -1;
63 static int hf_h261_quant       = -1;
64 static int hf_h261_hmvd        = -1; /* Mislabeled in a figure in section C.3.1 as HMDV */
65 static int hf_h261_vmvd        = -1;
66 static int hf_h261_data        = -1;
67
68 /* H.261 fields defining a sub tree */
69 static gint ett_h261           = -1;
70
71 static void
72 dissect_h261( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
73 {
74         proto_item *ti            = NULL;
75         proto_tree *h261_tree     = NULL;
76         unsigned int offset       = 0;
77
78         if ( check_col( pinfo->cinfo, COL_PROTOCOL ) )   {
79                 col_set_str( pinfo->cinfo, COL_PROTOCOL, "H.261" );
80         }
81         
82         if ( check_col( pinfo->cinfo, COL_INFO) ) {
83                 col_set_str( pinfo->cinfo, COL_INFO, "H.261 message");
84         }
85
86         if ( tree ) {
87                 ti = proto_tree_add_item( tree, proto_h261, tvb, offset, -1, FALSE );
88                 h261_tree = proto_item_add_subtree( ti, ett_h261 );
89                 /* SBIT 1st octet, 3 bits */
90                 proto_tree_add_uint( h261_tree, hf_h261_sbit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) >> 5 );
91                 /* EBIT 1st octet, 3 bits */
92                 proto_tree_add_uint( h261_tree, hf_h261_ebit, tvb, offset, 1, ( tvb_get_guint8( tvb, offset )  << 3 ) >> 5 );
93                 /* I flag, 1 bit */
94                 proto_tree_add_boolean( h261_tree, hf_h261_ibit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 2 );
95                 /* V flag, 1 bit */
96                 proto_tree_add_boolean( h261_tree, hf_h261_vbit, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 1 );
97                 offset++;
98
99                 /* GOBN 2nd octet, 4 bits */
100                 proto_tree_add_uint( h261_tree, hf_h261_gobn, tvb, offset, 1, tvb_get_guint8( tvb, offset ) >> 4 );
101                 /* MBAP 2nd octet, 4 bits, 3rd octet 1 bit */
102                 proto_tree_add_uint( h261_tree, hf_h261_mbap, tvb, offset, 1,
103                     ( tvb_get_guint8( tvb, offset ) & 15 )
104                     + ( tvb_get_guint8( tvb, offset + 1 ) >> 7 ) );
105                 offset++;
106
107                 /* QUANT 3rd octet, 5 bits (starting at bit 2!) */
108                 proto_tree_add_uint( h261_tree, hf_h261_quant, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 124 );
109                 /* HMVD 3rd octet 2 bits, 4th octet 3 bits */
110                 proto_tree_add_uint( h261_tree, hf_h261_hmvd, tvb, offset, 1,
111                     ( ( tvb_get_guint8( tvb, offset ) << 4) >> 4 )
112                      + ( tvb_get_guint8( tvb, offset ) >> 5 ) );
113                 offset++;
114
115                 /* VMVD 4th octet, last 5 bits */
116                 proto_tree_add_uint( h261_tree, hf_h261_vmvd, tvb, offset, 1, tvb_get_guint8( tvb, offset ) & 31 );
117                 offset++;
118
119                 /* The rest of the packet is the H.261 stream */
120                 proto_tree_add_item( h261_tree, hf_h261_data, tvb, offset, -1, FALSE );
121         }
122 }
123
124 void
125 proto_register_h261(void)
126 {
127         static hf_register_info hf[] = 
128         {
129                 { 
130                         &hf_h261_sbit,
131                         { 
132                                 "Start bit position", 
133                                 "h261.sbit", 
134                                 FT_UINT8, 
135                                 BASE_DEC, 
136                                 NULL, 
137                                 0x0,
138                                 "", HFILL 
139                         }
140                 },
141                 { 
142                         &hf_h261_ebit,
143                         { 
144                                 "End bit position", 
145                                 "h261.ebit", 
146                                 FT_UINT8, 
147                                 BASE_DEC, 
148                                 NULL, 
149                                 0x0,
150                                 "", HFILL 
151                         }
152                 },
153                 { 
154                         &hf_h261_ibit,
155                         { 
156                                 "Intra frame encoded data flag", 
157                                 "h261.i", 
158                                 FT_BOOLEAN, 
159                                 BASE_NONE, 
160                                 NULL, 
161                                 0x0,
162                                 "", HFILL 
163                         }
164                 },
165                 { 
166                         &hf_h261_vbit,
167                         { 
168                                 "Motion vector flag", 
169                                 "h261.v", 
170                                 FT_BOOLEAN, 
171                                 BASE_NONE, 
172                                 NULL, 
173                                 0x0,
174                                 "", HFILL 
175                         }
176                 },
177                 { 
178                         &hf_h261_gobn,
179                         { 
180                                 "GOB Number", 
181                                 "h261.gobn", 
182                                 FT_UINT8, 
183                                 BASE_DEC, 
184                                 NULL, 
185                                 0x0,
186                                 "", HFILL 
187                         }
188                 },
189                 { 
190                         &hf_h261_mbap,
191                         { 
192                                 "Macroblock address predictor", 
193                                 "h261.mbap", 
194                                 FT_UINT8, 
195                                 BASE_DEC, 
196                                 NULL, 
197                                 0x0,
198                                 "", HFILL 
199                         }
200                 },
201                 { 
202                         &hf_h261_quant,
203                         { 
204                                 "Quantizer", 
205                                 "h261.quant", 
206                                 FT_UINT8, 
207                                 BASE_DEC, 
208                                 NULL, 
209                                 0x0,
210                                 "", HFILL 
211                         }
212                 },
213                 { 
214                         &hf_h261_hmvd,
215                         { 
216                                 "Horizontal motion vector data", 
217                                 "h261.hmvd", 
218                                 FT_UINT8, 
219                                 BASE_DEC, 
220                                 NULL, 
221                                 0x0,
222                                 "", HFILL 
223                         }
224                 },
225                 { 
226                         &hf_h261_vmvd,
227                         { 
228                                 "Vertical motion vector data", 
229                                 "h261.vmvd", 
230                                 FT_UINT8, 
231                                 BASE_DEC, 
232                                 NULL, 
233                                 0x0,
234                                 "", HFILL 
235                         }
236                 },
237                 { 
238                         &hf_h261_data,
239                         { 
240                                 "H.261 stream", 
241                                 "h261.stream", 
242                                 FT_BYTES, 
243                                 BASE_NONE, 
244                                 NULL, 
245                                 0x0,
246                                 "", HFILL 
247                         }
248                 },
249 };
250         
251         static gint *ett[] = 
252         {
253                 &ett_h261,
254         };
255
256
257         proto_h261 = proto_register_protocol("ITU-T Recommendation H.261",
258             "H.261", "h261");
259         proto_register_field_array(proto_h261, hf, array_length(hf));
260         proto_register_subtree_array(ett, array_length(ett));
261
262         register_dissector("h261", dissect_h261, proto_h261);
263 }