810f3c64cd15e6f35cade137a926e4feabce1587
[metze/wireshark/wip.git] / epan / dissectors / packet-h261.c
1 /* packet-h261.c
2  *
3  * Routines for ITU-T Recommendation H.261 dissection
4  *
5  * Copyright 2000, Philips Electronics N.V.
6  * Andreas Sikkema <h323@ramdyne.nl>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 /*
28  * This dissector tries to dissect the H.261 protocol according to Annex C
29  * of ITU-T Recommendation H.225.0 (02/98)
30  */
31
32
33 #include "config.h"
34
35 #include <epan/packet.h>
36
37 #include <epan/rtp_pt.h>
38 #include <epan/iax2_codec_type.h>
39
40 void proto_register_h261(void);
41 void proto_reg_handoff_h261(void);
42
43 /* H.261 header fields             */
44 static int proto_h261          = -1;
45 static int hf_h261_sbit        = -1;
46 static int hf_h261_ebit        = -1;
47 static int hf_h261_ibit        = -1;
48 static int hf_h261_vbit        = -1;
49 static int hf_h261_gobn        = -1;
50 static int hf_h261_mbap        = -1;
51 static int hf_h261_quant       = -1;
52 static int hf_h261_hmvd        = -1; /* Mislabeled in a figure in section C.3.1 as HMDV */
53 static int hf_h261_vmvd        = -1;
54 static int hf_h261_data        = -1;
55
56 /* H.261 fields defining a sub tree */
57 static gint ett_h261           = -1;
58
59 static void
60 dissect_h261( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
61 {
62         proto_item *ti            = NULL;
63         proto_tree *h261_tree     = NULL;
64         unsigned int offset       = 0;
65         static const int * bits[] = {
66                 /* SBIT 1st octet, 3 bits */
67                 &hf_h261_sbit,
68                 /* EBIT 1st octet, 3 bits */
69                 &hf_h261_ebit,
70                 /* I flag, 1 bit */
71                 &hf_h261_ibit,
72                 /* V flag, 1 bit */
73                 &hf_h261_vbit,
74                 NULL
75         };
76
77         col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.261");
78
79         col_set_str(pinfo->cinfo, COL_INFO, "H.261 message");
80
81         if ( tree ) {
82                 ti = proto_tree_add_item( tree, proto_h261, tvb, offset, -1, ENC_NA );
83                 h261_tree = proto_item_add_subtree( ti, ett_h261 );
84
85                 proto_tree_add_bitmask_list(h261_tree, tvb, offset, 1, bits, ENC_NA);
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, ENC_NA );
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                                 0xe0,
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                                 0x1c,
140                                 NULL, HFILL
141                         }
142                 },
143                 {
144                         &hf_h261_ibit,
145                         {
146                                 "Intra frame encoded data flag",
147                                 "h261.i",
148                                 FT_BOOLEAN,
149                                 8,
150                                 NULL,
151                                 0x02,
152                                 NULL, HFILL
153                         }
154                 },
155                 {
156                         &hf_h261_vbit,
157                         {
158                                 "Motion vector flag",
159                                 "h261.v",
160                                 FT_BOOLEAN,
161                                 8,
162                                 NULL,
163                                 0x01,
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_uint("rtp.pt", PT_H261, h261_handle);
260         dissector_add_uint("iax2.codec", AST_FORMAT_H261, h261_handle);
261 }
262
263 /*
264  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
265  *
266  * Local variables:
267  * c-basic-offset: 8
268  * tab-width: 8
269  * indent-tabs-mode: t
270  * End:
271  *
272  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
273  * :indentSize=8:tabSize=8:noTabs=false:
274  */