GSM A DTAP: add UMTS EVS to supported codecs list IE
[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  * SPDX-License-Identifier: GPL-2.0-or-later
13  */
14
15 /*
16  * This dissector tries to dissect the H.261 protocol according to Annex C
17  * of ITU-T Recommendation H.225.0 (02/98)
18  */
19
20
21 #include "config.h"
22
23 #include <epan/packet.h>
24
25 #include <epan/rtp_pt.h>
26 #include <epan/iax2_codec_type.h>
27
28 void proto_register_h261(void);
29 void proto_reg_handoff_h261(void);
30
31 /* H.261 header fields             */
32 static int proto_h261          = -1;
33 static int hf_h261_sbit        = -1;
34 static int hf_h261_ebit        = -1;
35 static int hf_h261_ibit        = -1;
36 static int hf_h261_vbit        = -1;
37 static int hf_h261_gobn        = -1;
38 static int hf_h261_mbap        = -1;
39 static int hf_h261_quant       = -1;
40 static int hf_h261_hmvd        = -1; /* Mislabeled in a figure in section C.3.1 as HMDV */
41 static int hf_h261_vmvd        = -1;
42 static int hf_h261_data        = -1;
43
44 /* H.261 fields defining a sub tree */
45 static gint ett_h261           = -1;
46
47 static int
48 dissect_h261( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ )
49 {
50         proto_item *ti            = NULL;
51         proto_tree *h261_tree     = NULL;
52         unsigned int offset       = 0;
53         static const int * bits[] = {
54                 /* SBIT 1st octet, 3 bits */
55                 &hf_h261_sbit,
56                 /* EBIT 1st octet, 3 bits */
57                 &hf_h261_ebit,
58                 /* I flag, 1 bit */
59                 &hf_h261_ibit,
60                 /* V flag, 1 bit */
61                 &hf_h261_vbit,
62                 NULL
63         };
64
65         col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.261");
66
67         col_set_str(pinfo->cinfo, COL_INFO, "H.261 message");
68
69         if ( tree ) {
70                 ti = proto_tree_add_item( tree, proto_h261, tvb, offset, -1, ENC_NA );
71                 h261_tree = proto_item_add_subtree( ti, ett_h261 );
72
73                 proto_tree_add_bitmask_list(h261_tree, tvb, offset, 1, bits, ENC_NA);
74                 offset++;
75
76                 /* GOBN 2nd octet, 4 bits */
77                 proto_tree_add_item( h261_tree, hf_h261_gobn, tvb, offset, 1, ENC_NA);
78                 /* MBAP 2nd octet, 4 bits, 3rd octet 1 bit */
79                 proto_tree_add_item( h261_tree, hf_h261_mbap, tvb, offset, 1, ENC_BIG_ENDIAN);
80                 offset++;
81
82                 /* QUANT 3rd octet, 5 bits (starting at bit 2!) */
83                 proto_tree_add_item( h261_tree, hf_h261_quant, tvb, offset, 1, ENC_NA );
84
85                 /* HMVD 3rd octet 2 bits, 4th octet 3 bits */
86                 proto_tree_add_item( h261_tree, hf_h261_hmvd, tvb, offset, 2, ENC_BIG_ENDIAN);
87                 offset++;
88
89                 /* VMVD 4th octet, last 5 bits */
90                 proto_tree_add_item( h261_tree, hf_h261_vmvd, tvb, offset, 1, 0x1F );
91                 offset++;
92
93                 /* The rest of the packet is the H.261 stream */
94                 proto_tree_add_item( h261_tree, hf_h261_data, tvb, offset, -1, ENC_NA );
95         }
96         return tvb_captured_length(tvb);
97 }
98
99 void
100 proto_register_h261(void)
101 {
102         static hf_register_info hf[] =
103         {
104                 {
105                         &hf_h261_sbit,
106                         {
107                                 "Start bit position",
108                                 "h261.sbit",
109                                 FT_UINT8,
110                                 BASE_DEC,
111                                 NULL,
112                                 0xe0,
113                                 NULL, HFILL
114                         }
115                 },
116                 {
117                         &hf_h261_ebit,
118                         {
119                                 "End bit position",
120                                 "h261.ebit",
121                                 FT_UINT8,
122                                 BASE_DEC,
123                                 NULL,
124                                 0x1c,
125                                 NULL, HFILL
126                         }
127                 },
128                 {
129                         &hf_h261_ibit,
130                         {
131                                 "Intra frame encoded data flag",
132                                 "h261.i",
133                                 FT_BOOLEAN,
134                                 8,
135                                 NULL,
136                                 0x02,
137                                 NULL, HFILL
138                         }
139                 },
140                 {
141                         &hf_h261_vbit,
142                         {
143                                 "Motion vector flag",
144                                 "h261.v",
145                                 FT_BOOLEAN,
146                                 8,
147                                 NULL,
148                                 0x01,
149                                 NULL, HFILL
150                         }
151                 },
152                 {
153                         &hf_h261_gobn,
154                         {
155                                 "GOB Number",
156                                 "h261.gobn",
157                                 FT_UINT8,
158                                 BASE_DEC,
159                                 NULL,
160                                 0xF0,
161                                 NULL, HFILL
162                         }
163                 },
164                 {
165                         &hf_h261_mbap,
166                         {
167                                 "Macroblock address predictor",
168                                 "h261.mbap",
169                                 FT_UINT8,
170                                 BASE_DEC,
171                                 NULL,
172                                 0x0E80,
173                                 NULL, HFILL
174                         }
175                 },
176                 {
177                         &hf_h261_quant,
178                         {
179                                 "Quantizer",
180                                 "h261.quant",
181                                 FT_UINT8,
182                                 BASE_DEC,
183                                 NULL,
184                                 0x7C,
185                                 NULL, HFILL
186                         }
187                 },
188                 {
189                         &hf_h261_hmvd,
190                         {
191                                 "Horizontal motion vector data",
192                                 "h261.hmvd",
193                                 FT_UINT8,
194                                 BASE_DEC,
195                                 NULL,
196                                 0x03E0,
197                                 NULL, HFILL
198                         }
199                 },
200                 {
201                         &hf_h261_vmvd,
202                         {
203                                 "Vertical motion vector data",
204                                 "h261.vmvd",
205                                 FT_UINT8,
206                                 BASE_DEC,
207                                 NULL,
208                                 0x0,
209                                 NULL, HFILL
210                         }
211                 },
212                 {
213                         &hf_h261_data,
214                         {
215                                 "H.261 stream",
216                                 "h261.stream",
217                                 FT_BYTES,
218                                 BASE_NONE,
219                                 NULL,
220                                 0x0,
221                                 NULL, HFILL
222                         }
223                 },
224 };
225
226         static gint *ett[] =
227         {
228                 &ett_h261,
229         };
230
231
232         proto_h261 = proto_register_protocol("ITU-T Recommendation H.261",
233             "H.261", "h261");
234         proto_register_field_array(proto_h261, hf, array_length(hf));
235         proto_register_subtree_array(ett, array_length(ett));
236 }
237
238 void
239 proto_reg_handoff_h261(void)
240 {
241         dissector_handle_t h261_handle;
242
243         h261_handle = create_dissector_handle(dissect_h261, proto_h261);
244         dissector_add_uint("rtp.pt", PT_H261, h261_handle);
245         dissector_add_uint("iax2.codec", AST_FORMAT_H261, h261_handle);
246 }
247
248 /*
249  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
250  *
251  * Local variables:
252  * c-basic-offset: 8
253  * tab-width: 8
254  * indent-tabs-mode: t
255  * End:
256  *
257  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
258  * :indentSize=8:tabSize=8:noTabs=false:
259  */