HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-h263p.c
blob4c21b67fd7d8d9e0863ee28a65e2ee2cc1020b3b
1 /* packet-h263p.c
3 * Routines for RFC-4629-encapsulated H.263 dissection
5 * Copyright 2003 Niklas Ogren <niklas.ogren@7l.se>
6 * Seven Levels Consultants AB
8 * Copyright 2008 Richard van der Hoff, MX Telecom
9 * <richardv@mxtelecom.com>
11 * $Id$
13 * Wireshark - Network traffic analyzer
14 * By Gerald Combs <gerald@wireshark.org>
15 * Copyright 1998 Gerald Combs
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include "config.h"
34 #include <glib.h>
35 #include <epan/packet.h>
37 #include <epan/prefs.h>
39 #include "packet-h263.h"
41 static int proto_h263P = -1;
43 /* H.263 RFC 4629 fields */
44 static int hf_h263P_payload = -1;
45 static int hf_h263P_rr = -1;
46 static int hf_h263P_pbit = -1;
47 static int hf_h263P_vbit = -1;
48 static int hf_h263P_plen = -1;
49 static int hf_h263P_pebit = -1;
50 static int hf_h263P_tid = -1;
51 static int hf_h263P_trun = -1;
52 static int hf_h263P_s = -1;
53 static int hf_h263P_extra_hdr = -1;
54 /* static int hf_h263P_PSC = -1; */
55 /* static int hf_h263P_TR = -1; */
58 /* H.263-1998 fields defining a sub tree */
59 static gint ett_h263P = -1;
60 static gint ett_h263P_extra_hdr = -1;
61 static gint ett_h263P_payload = -1;
62 static gint ett_h263P_data = -1;
64 /* The dynamic payload type which will be dissected as H.263-1998/H263-2000 */
66 static guint temp_dynamic_payload_type = 0;
68 /* RFC 4629 */
69 static void
70 dissect_h263P( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
72 proto_item *ti = NULL;
73 proto_item *data_item = NULL;
74 proto_item *extra_hdr_item = NULL;
75 proto_tree *h263P_tree = NULL;
76 proto_tree *h263P_extr_hdr_tree = NULL;
77 proto_tree *h263P_data_tree = NULL;
78 unsigned int offset = 0;
79 guint16 data16, plen;
80 guint8 startcode;
83 tvbuff_t *next_tvb;
86 col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.263 RFC4629 ");
88 if ( tree ) {
89 ti = proto_tree_add_item( tree, proto_h263P, tvb, offset, -1, ENC_NA );
90 h263P_tree = proto_item_add_subtree( ti, ett_h263P );
92 data16 = tvb_get_ntohs(tvb,offset);
93 proto_tree_add_item( h263P_tree, hf_h263P_rr, tvb, offset, 2, ENC_BIG_ENDIAN );
94 proto_tree_add_item( h263P_tree, hf_h263P_pbit, tvb, offset, 2, ENC_BIG_ENDIAN );
95 proto_tree_add_item( h263P_tree, hf_h263P_vbit, tvb, offset, 2, ENC_BIG_ENDIAN );
96 proto_tree_add_item( h263P_tree, hf_h263P_plen, tvb, offset, 2, ENC_BIG_ENDIAN );
97 proto_tree_add_item( h263P_tree, hf_h263P_pebit, tvb, offset, 2, ENC_BIG_ENDIAN );
98 offset = offset +2;
100 * V: 1 bit
102 * Indicates the presence of an 8-bit field containing information
103 * for Video Redundancy Coding (VRC), which follows immediately after
104 * the initial 16 bits of the payload header, if present. For syntax
105 * and semantics of that 8-bit VRC field, see Section 5.2.
108 if ((data16&0x0200)==0x0200){
109 /* V bit = 1
110 * The format of the VRC header extension is as follows:
112 * 0 1 2 3 4 5 6 7
113 * +-+-+-+-+-+-+-+-+
114 * | TID | Trun |S|
115 * +-+-+-+-+-+-+-+-+
117 * TID: 3 bits
119 * Thread ID. Up to 7 threads are allowed. Each frame of H.263+ VRC
120 * data will use as reference information only sync frames or frames
121 * within the same thread. By convention, thread 0 is expected to be
122 * the "canonical" thread, which is the thread from which the sync frame
123 * should ideally be used. In the case of corruption or loss of the
124 * thread 0 representation, a representation of the sync frame with a
125 * higher thread number can be used by the decoder. Lower thread
126 * numbers are expected to contain representations of the sync frames
127 * equal to or better than higher thread numbers in the absence of data
128 * corruption or loss. See [Vredun] for a detailed discussion of VRC.
130 * Trun: 4 bits
132 * Monotonically increasing (modulo 16) 4-bit number counting the packet
133 * number within each thread.
135 * S: 1 bit
137 * A bit that indicates that the packet content is for a sync frame.
140 proto_tree_add_item( h263P_tree, hf_h263P_tid, tvb, offset, 1, ENC_BIG_ENDIAN );
141 proto_tree_add_item( h263P_tree, hf_h263P_trun, tvb, offset, 1, ENC_BIG_ENDIAN );
142 proto_tree_add_item( h263P_tree, hf_h263P_s, tvb, offset, 1, ENC_BIG_ENDIAN );
143 offset++;
146 /* Length, in bytes, of the extra picture header. */
147 plen = (data16 & 0x01f8) >> 3;
148 if (plen != 0){
149 extra_hdr_item = proto_tree_add_item( h263P_tree, hf_h263P_extra_hdr, tvb, offset, plen, ENC_NA );
150 h263P_extr_hdr_tree = proto_item_add_subtree( extra_hdr_item, ett_h263P_extra_hdr );
151 dissect_h263_picture_layer( tvb, pinfo, h263P_extr_hdr_tree, offset, plen, TRUE);
152 offset += plen;
154 if ((data16&0x0400)!=0){
155 /* P bit = 1 */
156 data_item = proto_tree_add_item( h263P_tree, hf_h263P_payload, tvb, offset, -1, ENC_NA );
157 h263P_data_tree = proto_item_add_subtree( data_item, ett_h263P_data );
158 /* Startc code holds bit 17 -23 of the codeword */
159 startcode = tvb_get_guint8(tvb,offset)&0xfe;
160 if (startcode & 0x80){
161 /* All picture, slice, and EOSBS start codes
162 * shall be byte aligned, and GOB and EOS start codes may be byte aligned.
164 switch(startcode){
165 case 0xf8:
166 /* End Of Sub-Bitstream code (EOSBS)
167 * EOSBS codes shall be byte aligned
168 * ( 1111 100. )
170 break;
171 case 0x80:
172 case 0x82:
173 /* Picture Start Code (PSC)
174 * ( 1000 00x.)
176 col_append_str( pinfo->cinfo, COL_INFO, "(PSC) ");
177 dissect_h263_picture_layer( tvb, pinfo, h263P_data_tree, offset, -1, TRUE);
178 break;
179 case 0xfc:
180 case 0xfe:
181 /* End Of Sequence (EOS)
182 * ( 1111 11x. )
184 default:
185 /* Group of Block Start Code (GBSC) or
186 * Slice Start Code (SSC)
188 col_append_str( pinfo->cinfo, COL_INFO, "(GBSC) ");
189 dissect_h263_group_of_blocks_layer( tvb, h263P_data_tree, offset,TRUE);
190 break;
192 }else{
193 /* Error */
195 return;
197 proto_tree_add_item( h263P_tree, hf_h263P_payload, tvb, offset, -1, ENC_NA );
201 void
202 proto_reg_handoff_h263P(void)
204 static dissector_handle_t h263P_handle;
205 static guint dynamic_payload_type;
206 static gboolean h263P_prefs_initialized = FALSE;
208 if (!h263P_prefs_initialized) {
209 h263P_handle = find_dissector("h263P");
210 dissector_add_string("rtp_dyn_payload_type","H263-1998", h263P_handle);
211 dissector_add_string("rtp_dyn_payload_type","H263-2000", h263P_handle);
212 h263P_prefs_initialized = TRUE;
214 else {
215 if ( dynamic_payload_type > 95 )
216 dissector_delete_uint("rtp.pt", dynamic_payload_type, h263P_handle);
218 dynamic_payload_type = temp_dynamic_payload_type;
220 if ( dynamic_payload_type > 95 ){
221 dissector_add_uint("rtp.pt", dynamic_payload_type, h263P_handle);
226 void
227 proto_register_h263P(void)
229 module_t *h263P_module;
231 static hf_register_info hf[] =
234 &hf_h263P_payload,
236 "H.263 RFC4629 payload",
237 "h263p.payload",
238 FT_NONE,
239 BASE_NONE,
240 NULL,
241 0x0,
242 "The actual H.263 RFC4629 data", HFILL
246 &hf_h263P_rr,
248 "Reserved",
249 "h263p.rr",
250 FT_UINT16,
251 BASE_DEC,
252 NULL,
253 0xf800,
254 "Reserved SHALL be zero", HFILL
258 &hf_h263P_pbit,
260 "P",
261 "h263p.p",
262 FT_BOOLEAN,
264 NULL,
265 0x0400,
266 "Indicates (GOB/Slice) start or (EOS or EOSBS)", HFILL
270 &hf_h263P_vbit,
272 "V",
273 "h263p.v",
274 FT_BOOLEAN,
276 NULL,
277 0x0200,
278 "presence of Video Redundancy Coding (VRC) field", HFILL
282 &hf_h263P_plen,
284 "PLEN",
285 "h263p.plen",
286 FT_UINT16,
287 BASE_DEC,
288 NULL,
289 0x01f8,
290 "Length, in bytes, of the extra picture header", HFILL
294 &hf_h263P_pebit,
296 "PEBIT",
297 "h263p.pebit",
298 FT_UINT16,
299 BASE_DEC,
300 NULL,
301 0x0003,
302 "number of bits that shall be ignored in the last byte of the picture header", HFILL
308 &hf_h263P_tid,
310 "Thread ID",
311 "h263p.tid",
312 FT_UINT8,
313 BASE_DEC,
314 NULL,
315 0xe0,
316 NULL, HFILL
320 &hf_h263P_trun,
322 "Trun",
323 "h263p.trun",
324 FT_UINT8,
325 BASE_DEC,
326 NULL,
327 0x1e,
328 "Monotonically increasing (modulo 16) 4-bit number counting the packet number within each thread", HFILL
332 &hf_h263P_s,
334 "S",
335 "h263p.s",
336 FT_UINT8,
337 BASE_DEC,
338 NULL,
339 0x01,
340 "Indicates that the packet content is for a sync frame", HFILL
344 &hf_h263P_extra_hdr,
346 "Extra picture header",
347 "h263p.extra_hdr",
348 FT_BYTES,
349 BASE_NONE,
350 NULL,
351 0x0,
352 NULL, HFILL
355 #if 0
357 &hf_h263P_PSC,
359 "H.263 PSC",
360 "h263p.PSC",
361 FT_UINT16,
362 BASE_HEX,
363 NULL,
364 0xfc00,
365 "Picture Start Code(PSC)", HFILL
368 #endif
369 #if 0
371 &hf_h263P_TR,
373 "H.263 Temporal Reference",
374 "h263p.tr",
375 FT_UINT16,
376 BASE_HEX,
377 NULL,
378 0x03fc,
379 "Temporal Reference, TR", HFILL
382 #endif
386 static gint *ett[] =
388 &ett_h263P,
389 &ett_h263P_extra_hdr,
390 &ett_h263P_payload,
391 &ett_h263P_data,
395 proto_h263P = proto_register_protocol("ITU-T Recommendation H.263 RTP Payload header (RFC4629)",
396 "H263P", "h263p");
398 proto_register_field_array(proto_h263P, hf, array_length(hf));
399 proto_register_subtree_array(ett, array_length(ett));
401 h263P_module = prefs_register_protocol(proto_h263P, proto_reg_handoff_h263P);
403 prefs_register_uint_preference(h263P_module, "dynamic.payload.type",
404 "H263-1998 and H263-2000 dynamic payload type",
405 "The dynamic payload type which will be interpreted as H264"
406 "; The value must be greater than 95",
408 &temp_dynamic_payload_type);
410 register_dissector("h263P", dissect_h263P, proto_h263P);