Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-rfc2190.c
blobd9eb01aa1e67e1b84daa90983b5bc74a09f0b216
1 /* packet-rfc2190.c
3 * Routines for RFC2190-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 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * SPDX-License-Identifier: GPL-2.0-or-later
19 * This dissector tries to dissect the H.263 protocol according to
20 * RFC 2190, https://www.ietf.org/rfc/rfc2190
23 #include "config.h"
25 #include <epan/packet.h>
27 #include <epan/rtp_pt.h>
28 #include <epan/iax2_codec_type.h>
30 #include "packet-h263.h"
32 void proto_register_rfc2190(void);
33 void proto_reg_handoff_rfc2190(void);
35 /* H.263 header fields */
36 static int proto_rfc2190;
38 /* Mode A header */
39 static int hf_rfc2190_ftype;
40 static int hf_rfc2190_pbframes;
41 static int hf_rfc2190_sbit;
42 static int hf_rfc2190_ebit;
43 static int hf_rfc2190_srcformat;
44 static int hf_rfc2190_picture_coding_type_modeA;
45 static int hf_rfc2190_unrestricted_motion_vector_modeA;
46 static int hf_rfc2190_syntax_based_arithmetic_modeA;
47 static int hf_rfc2190_advanced_prediction_modeA;
48 static int hf_rfc2190_r_modeA;
49 static int hf_rfc2190_rr;
50 static int hf_rfc2190_dbq;
51 static int hf_rfc2190_trb;
52 static int hf_rfc2190_tr;
53 /* Additional fields for Mode B or C header */
54 static int hf_rfc2190_picture_coding_type_modeB;
55 static int hf_rfc2190_unrestricted_motion_vector_modeB;
56 static int hf_rfc2190_syntax_based_arithmetic_modeB;
57 static int hf_rfc2190_advanced_prediction_modeB;
58 static int hf_rfc2190_r_modeB;
59 static int hf_rfc2190_quant;
60 static int hf_rfc2190_gobn;
61 static int hf_rfc2190_mba;
62 static int hf_rfc2190_hmv1;
63 static int hf_rfc2190_vmv1;
64 static int hf_rfc2190_hmv2;
65 static int hf_rfc2190_vmv2;
67 static int ett_rfc2190;
68 static dissector_handle_t h263_handle;
69 static dissector_handle_t rfc2190_handle;
72 static int
73 dissect_rfc2190( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ )
75 proto_item *ti = NULL;
76 proto_tree *rfc2190_tree = NULL;
77 int offset = 0;
78 unsigned int rfc2190_version = 0;
79 tvbuff_t *next_tvb;
80 int hdr_len = 0;
82 rfc2190_version = (tvb_get_uint8( tvb, offset ) & 0xc0 ) >> 6;
84 col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.263 ");
86 /* Three formats (mode A, mode B and mode C) are defined for H.263
87 * payload header. In mode A, an H.263 payload header of four bytes is
88 * present before actual compressed H.263 video bitstream in a packet.
89 * It allows fragmentation at GOB boundaries. In mode B, an eight byte
90 * H.263 payload header is used and each packet starts at MB boundaries
91 * without the PB-frames option. Finally, a twelve byte H.263 payload
92 * header is defined in mode C to support fragmentation at MB boundaries
93 * for frames that are coded with the PB-frames option.
95 if( rfc2190_version == 0x00) {
96 col_append_str( pinfo->cinfo, COL_INFO, "MODE A ");
97 hdr_len = 4;
99 else if( rfc2190_version == 0x02) {
100 col_append_str( pinfo->cinfo, COL_INFO, "MODE B ");
101 hdr_len = 8;
103 else if( rfc2190_version == 0x03) {
104 col_append_str( pinfo->cinfo, COL_INFO, "MODE C ");
105 hdr_len = 12;
108 if ( tree ) {
109 ti = proto_tree_add_item( tree, proto_rfc2190, tvb, offset, hdr_len, ENC_NA );
110 rfc2190_tree = proto_item_add_subtree( ti, ett_rfc2190 );
112 /* FBIT 1st octet, 1 bit */
113 proto_tree_add_item( rfc2190_tree, hf_rfc2190_ftype, tvb, offset, 1, ENC_BIG_ENDIAN );
114 /* PBIT 1st octet, 1 bit */
115 proto_tree_add_item( rfc2190_tree, hf_rfc2190_pbframes, tvb, offset, 1, ENC_BIG_ENDIAN );
116 /* SBIT 1st octet, 3 bits */
117 proto_tree_add_item( rfc2190_tree, hf_rfc2190_sbit, tvb, offset, 1, ENC_BIG_ENDIAN );
118 /* EBIT 1st octet, 3 bits */
119 proto_tree_add_item( rfc2190_tree, hf_rfc2190_ebit, tvb, offset, 1, ENC_BIG_ENDIAN );
120 offset++;
122 /* SRC 2nd octet, 3 bits */
123 proto_tree_add_item( rfc2190_tree, hf_rfc2190_srcformat, tvb, offset, 1, ENC_BIG_ENDIAN );
125 if(rfc2190_version == 0x00) { /* MODE A */
126 /* I flag, 1 bit */
127 proto_tree_add_item(rfc2190_tree, hf_rfc2190_picture_coding_type_modeA, tvb, offset, 1, ENC_BIG_ENDIAN);
128 /* U flag, 1 bit */
129 proto_tree_add_item(rfc2190_tree, hf_rfc2190_unrestricted_motion_vector_modeA, tvb, offset, 1, ENC_BIG_ENDIAN);
130 /* S flag, 1 bit */
131 proto_tree_add_item(rfc2190_tree, hf_rfc2190_syntax_based_arithmetic_modeA, tvb, offset, 1, ENC_BIG_ENDIAN);
132 /* A flag, 1 bit */
133 proto_tree_add_item(rfc2190_tree, hf_rfc2190_advanced_prediction_modeA, tvb, offset, 1, ENC_BIG_ENDIAN);
135 /* Reserved 2nd octet, 1 bit + 3rd octet 3 bits */
136 proto_tree_add_item( rfc2190_tree, hf_rfc2190_r_modeA, tvb, offset, 2, ENC_BIG_ENDIAN);
138 offset++;
140 /* DBQ 3 octet, 2 bits */
141 proto_tree_add_item( rfc2190_tree, hf_rfc2190_dbq, tvb, offset, 1, ENC_BIG_ENDIAN );
142 /* TRB 3 octet, 3 bits */
143 proto_tree_add_item( rfc2190_tree, hf_rfc2190_trb, tvb, offset, 1, ENC_BIG_ENDIAN );
144 offset++;
146 /* TR 4 octet, 8 bits */
147 proto_tree_add_item( rfc2190_tree, hf_rfc2190_tr, tvb, offset, 1, ENC_NA );
149 offset++;
151 } else { /* MODE B or MODE C */
152 /* QUANT 2 octet, 5 bits */
153 proto_tree_add_item( rfc2190_tree, hf_rfc2190_quant, tvb, offset, 1, ENC_NA);
155 offset++;
157 /* GOBN 3 octet, 5 bits */
158 proto_tree_add_item( rfc2190_tree, hf_rfc2190_gobn, tvb, offset, 1, ENC_NA);
159 /* MBA 3 octet, 3 bits + 4 octet 6 bits */
160 proto_tree_add_item( rfc2190_tree, hf_rfc2190_mba, tvb, offset, 2, ENC_BIG_ENDIAN );
162 offset++;
164 /* Reserved 4th octet, 2 bits */
165 proto_tree_add_item( rfc2190_tree, hf_rfc2190_r_modeB, tvb, offset, 1, ENC_NA);
167 offset++;
169 /* I flag, 1 bit */
170 proto_tree_add_item( rfc2190_tree, hf_rfc2190_picture_coding_type_modeB, tvb, offset, 1, ENC_BIG_ENDIAN);
171 /* U flag, 1 bit */
172 proto_tree_add_item( rfc2190_tree, hf_rfc2190_unrestricted_motion_vector_modeB, tvb, offset, 1, ENC_BIG_ENDIAN);
173 /* S flag, 1 bit */
174 proto_tree_add_item( rfc2190_tree, hf_rfc2190_syntax_based_arithmetic_modeB, tvb, offset, 1, ENC_BIG_ENDIAN);
175 /* A flag, 1 bit */
176 proto_tree_add_item( rfc2190_tree, hf_rfc2190_advanced_prediction_modeB, tvb, offset, 1, ENC_BIG_ENDIAN);
178 /* HMV1 5th octet, 4 bits + 6th octet 3 bits*/
179 proto_tree_add_item( rfc2190_tree, hf_rfc2190_hmv1, tvb, offset, 2, ENC_BIG_ENDIAN);
181 offset++;
183 /* VMV1 6th octet, 5 bits + 7th octet 2 bits*/
184 proto_tree_add_item( rfc2190_tree, hf_rfc2190_vmv1, tvb, offset, 2, ENC_BIG_ENDIAN);
186 offset++;
188 /* HMV2 7th octet, 6 bits + 8th octet 1 bit*/
189 proto_tree_add_item( rfc2190_tree, hf_rfc2190_hmv2, tvb, offset, 2, ENC_BIG_ENDIAN);
191 offset++;
193 /* VMV2 8th octet, 7 bits*/
194 proto_tree_add_item( rfc2190_tree, hf_rfc2190_vmv2, tvb, offset, 1, ENC_NA);
196 offset++;
198 if(rfc2190_version == 0x03) { /* MODE C */
199 /* Reserved 9th to 11th octet, 8 + 8 + 3 bits */
200 proto_tree_add_item( rfc2190_tree, hf_rfc2190_rr, tvb, offset, 3, ENC_BIG_ENDIAN);
202 offset+=2;
204 /* DBQ 11th octet, 2 bits */
205 proto_tree_add_item( rfc2190_tree, hf_rfc2190_dbq, tvb, offset, 1, ENC_BIG_ENDIAN );
206 /* TRB 11th octet, 3 bits */
207 proto_tree_add_item( rfc2190_tree, hf_rfc2190_trb, tvb, offset, 1, ENC_BIG_ENDIAN );
209 offset++;
211 /* TR 12th octet, 8 bits */
212 proto_tree_add_item( rfc2190_tree, hf_rfc2190_tr, tvb, offset, 1, ENC_NA );
214 offset++;
215 } /* end mode c */
216 } /* end not mode a */
217 } else {
218 switch(rfc2190_version) {
219 case 0x00: /* MODE A */
220 offset += 4;
221 break;
222 case 0x01: /* MODE B */
223 offset += 8;
224 break;
225 case 0x02: /* MODE C */
226 offset += 12;
227 break;
232 /* The rest of the packet is the H.263 stream */
233 next_tvb = tvb_new_subset_remaining( tvb, offset);
234 call_dissector(h263_handle,next_tvb,pinfo,tree);
235 return tvb_captured_length(tvb);
238 void
239 proto_reg_handoff_rfc2190(void)
241 dissector_add_uint("rtp.pt", PT_H263, rfc2190_handle);
242 dissector_add_uint("iax2.codec", AST_FORMAT_H263, rfc2190_handle);
244 h263_handle = find_dissector_add_dependency("h263data", proto_rfc2190);
248 void
249 proto_register_rfc2190(void)
251 static hf_register_info hf[] = {
253 &hf_rfc2190_ftype,
255 "F",
256 "rfc2190.ftype",
257 FT_BOOLEAN,
259 NULL,
260 0x80,
261 "Indicates the mode of the payload header (MODE A or B/C)", HFILL
265 &hf_rfc2190_pbframes,
267 "p/b frame",
268 "rfc2190.pbframes",
269 FT_BOOLEAN,
271 NULL,
272 0x40,
273 "Optional PB-frames mode as defined by H.263 (MODE C)", HFILL
277 &hf_rfc2190_sbit,
279 "Start bit position",
280 "rfc2190.sbit",
281 FT_UINT8,
282 BASE_DEC,
283 NULL,
284 0x38,
285 "Start bit position specifies number of most significant bits that shall be ignored in the first data byte.", HFILL
289 &hf_rfc2190_ebit,
291 "End bit position",
292 "rfc2190.ebit",
293 FT_UINT8,
294 BASE_DEC,
295 NULL,
296 0x7,
297 "End bit position specifies number of least significant bits that shall be ignored in the last data byte.", HFILL
301 &hf_rfc2190_srcformat,
303 "SRC format",
304 "rfc2190.srcformat",
305 FT_UINT8,
306 BASE_DEC,
307 VALS(h263_srcformat_vals),
308 0xe0,
309 "Source format specifies the resolution of the current picture.", HFILL
313 &hf_rfc2190_picture_coding_type_modeA,
315 "Inter-coded frame",
316 "rfc2190.picture_coding_type",
317 FT_BOOLEAN,
319 NULL,
320 0x10,
321 "Picture coding type, intra-coded (false) or inter-coded (true)", HFILL
325 &hf_rfc2190_unrestricted_motion_vector_modeA,
327 "Motion vector",
328 "rfc2190.unrestricted_motion_vector",
329 FT_BOOLEAN,
331 NULL,
332 0x08,
333 "Unrestricted Motion Vector option for current picture", HFILL
337 &hf_rfc2190_syntax_based_arithmetic_modeA,
339 "Syntax-based arithmetic coding",
340 "rfc2190.syntax_based_arithmetic",
341 FT_BOOLEAN,
343 NULL,
344 0x04,
345 "Syntax-based Arithmetic Coding option for current picture", HFILL
349 &hf_rfc2190_advanced_prediction_modeA,
351 "Advanced prediction option",
352 "rfc2190.advanced_prediction",
353 FT_BOOLEAN,
355 NULL,
356 0x02,
357 "Advanced Prediction option for current picture", HFILL
361 &hf_rfc2190_picture_coding_type_modeB,
363 "Inter-coded frame",
364 "rfc2190.picture_coding_type",
365 FT_BOOLEAN,
367 NULL,
368 0x80,
369 "Picture coding type, intra-coded (false) or inter-coded (true)", HFILL
373 &hf_rfc2190_unrestricted_motion_vector_modeB,
375 "Motion vector",
376 "rfc2190.unrestricted_motion_vector",
377 FT_BOOLEAN,
379 NULL,
380 0x40,
381 "Unrestricted Motion Vector option for current picture", HFILL
385 &hf_rfc2190_syntax_based_arithmetic_modeB,
387 "Syntax-based arithmetic coding",
388 "rfc2190.syntax_based_arithmetic",
389 FT_BOOLEAN,
391 NULL,
392 0x20,
393 "Syntax-based Arithmetic Coding option for current picture", HFILL
397 &hf_rfc2190_advanced_prediction_modeB,
399 "Advanced prediction option",
400 "rfc2190.advanced_prediction",
401 FT_BOOLEAN,
403 NULL,
404 0x10,
405 "Advanced Prediction option for current picture", HFILL
409 &hf_rfc2190_dbq,
411 "Differential quantization parameter",
412 "rfc2190.dbq",
413 FT_UINT8,
414 BASE_DEC,
415 NULL,
416 0x18,
417 "Differential quantization parameter used to calculate quantizer for the B frame based on quantizer for the P frame, when PB-frames option is used.", HFILL
421 &hf_rfc2190_trb,
423 "Temporal Reference for B frames",
424 "rfc2190.trb",
425 FT_UINT8,
426 BASE_DEC,
427 NULL,
428 0x07,
429 "Temporal Reference for the B frame as defined by H.263", HFILL
433 &hf_rfc2190_tr,
435 "Temporal Reference for P frames",
436 "rfc2190.tr",
437 FT_UINT8,
438 BASE_DEC,
439 NULL,
440 0x0,
441 "Temporal Reference for the P frame as defined by H.263", HFILL
445 &hf_rfc2190_quant,
447 "Quantizer",
448 "rfc2190.quant",
449 FT_UINT8,
450 BASE_DEC,
451 NULL,
452 0x1F,
453 "Quantization value for the first MB coded at the starting of the packet.", HFILL
457 &hf_rfc2190_gobn,
459 "GOB Number",
460 "rfc2190.gobn",
461 FT_UINT8,
462 BASE_DEC,
463 NULL,
464 0xF8,
465 "GOB number in effect at the start of the packet.", HFILL
469 &hf_rfc2190_mba,
471 "Macroblock address",
472 "rfc2190.mba",
473 FT_UINT16,
474 BASE_DEC,
475 NULL,
476 0x3FE0,
477 "The address within the GOB of the first MB in the packet, counting from zero in scan order.", HFILL
481 &hf_rfc2190_hmv1,
483 "Horizontal motion vector 1",
484 "rfc2190.hmv1",
485 FT_UINT16,
486 BASE_DEC,
487 NULL,
488 0x0FE0,
489 "Horizontal motion vector predictor for the first MB in this packet", HFILL
493 &hf_rfc2190_vmv1,
495 "Vertical motion vector 1",
496 "rfc2190.vmv1",
497 FT_UINT16,
498 BASE_DEC,
499 NULL,
500 0x01FC,
501 "Vertical motion vector predictor for the first MB in this packet", HFILL
505 &hf_rfc2190_hmv2,
507 "Horizontal motion vector 2",
508 "rfc2190.hmv2",
509 FT_UINT16,
510 BASE_DEC,
511 NULL,
512 0x03F8,
513 "Horizontal motion vector predictor for block number 3 in the first MB in this packet when four motion vectors are used with the advanced prediction option.", HFILL
517 &hf_rfc2190_vmv2,
519 "Vertical motion vector 2",
520 "rfc2190.vmv2",
521 FT_UINT8,
522 BASE_DEC,
523 NULL,
524 0x7F,
525 "Vertical motion vector predictor for block number 3 in the first MB in this packet when four motion vectors are used with the advanced prediction option.", HFILL
529 &hf_rfc2190_r_modeA,
531 "Reserved field",
532 "rfc2190.r",
533 FT_UINT16,
534 BASE_DEC,
535 NULL,
536 0x01E0,
537 "Reserved field that should contain zeroes", HFILL
541 &hf_rfc2190_r_modeB,
543 "Reserved field",
544 "rfc2190.r",
545 FT_UINT8,
546 BASE_DEC,
547 NULL,
548 0x03,
549 "Reserved field that should contain zeroes", HFILL
553 &hf_rfc2190_rr,
555 "Reserved field 2",
556 "rfc2190.rr",
557 FT_UINT24,
558 BASE_DEC,
559 NULL,
560 0x07FFFF,
561 "Reserved field that should contain zeroes", HFILL
566 static int *ett[] = {
567 &ett_rfc2190,
570 proto_register_subtree_array(ett, array_length(ett));
572 proto_rfc2190 = proto_register_protocol("H.263 RTP Payload header (RFC2190)",
573 "H.263 (RFC2190)", "rfc2190");
575 proto_register_field_array(proto_rfc2190, hf, array_length(hf));
576 rfc2190_handle = register_dissector("rfc2190", dissect_rfc2190, proto_rfc2190);
580 * Editor modelines - https://www.wireshark.org/tools/modelines.html
582 * Local variables:
583 * c-basic-offset: 4
584 * tab-width: 8
585 * indent-tabs-mode: nil
586 * End:
588 * vi: set shiftwidth=4 tabstop=8 expandtab:
589 * :indentSize=4:tabSize=8:noTabs=true: