Coverage Report

Created: 2026-11-12 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-h263p.c
Line
Count
Source
1
/* packet-h263p.c
2
 *
3
 * Routines for RFC-4629-encapsulated H.263 dissection
4
 *
5
 * Copyright 2003 Niklas Ogren <niklas.ogren@7l.se>
6
 * Seven Levels Consultants AB
7
 *
8
 * Copyright 2008 Richard van der Hoff, MX Telecom
9
 * <richardv@mxtelecom.com>
10
 *
11
 * Wireshark - Network traffic analyzer
12
 * By Gerald Combs <gerald@wireshark.org>
13
 * Copyright 1998 Gerald Combs
14
 *
15
 * SPDX-License-Identifier: GPL-2.0-or-later
16
 */
17
18
#include "config.h"
19
20
#include <epan/packet.h>
21
22
#include <epan/prefs.h>
23
24
#include "packet-h263.h"
25
26
void proto_reg_handoff_h263P(void);
27
void proto_register_h263P(void);
28
29
static int proto_h263P;
30
31
/* H.263 RFC 4629 fields */
32
static int hf_h263P_payload;
33
static int hf_h263P_rr;
34
static int hf_h263P_pbit;
35
static int hf_h263P_vbit;
36
static int hf_h263P_plen;
37
static int hf_h263P_pebit;
38
static int hf_h263P_tid;
39
static int hf_h263P_trun;
40
static int hf_h263P_s;
41
static int hf_h263P_extra_hdr;
42
/* static int hf_h263P_PSC; */
43
/* static int hf_h263P_TR; */
44
45
46
/* H.263-1998 fields defining a sub tree */
47
static int ett_h263P;
48
static int ett_h263P_extra_hdr;
49
static int ett_h263P_payload;
50
static int ett_h263P_data;
51
52
static dissector_handle_t h263P_handle;
53
54
/* RFC 4629 */
55
static int
56
dissect_h263P( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ )
57
0
{
58
0
    proto_item *ti                  = NULL;
59
0
    proto_item *data_item           = NULL;
60
0
    proto_item *extra_hdr_item      = NULL;
61
0
    proto_tree *h263P_tree          = NULL;
62
0
    proto_tree *h263P_extr_hdr_tree = NULL;
63
0
    proto_tree *h263P_data_tree     = NULL;
64
0
    unsigned int offset             = 0;
65
0
    uint16_t data16, plen;
66
0
    uint8_t startcode;
67
68
    /*
69
    tvbuff_t *next_tvb;
70
    */
71
72
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.263 RFC4629 ");
73
74
0
    if ( tree ) {
75
0
      ti = proto_tree_add_item( tree, proto_h263P, tvb, offset, -1, ENC_NA );
76
0
      h263P_tree = proto_item_add_subtree( ti, ett_h263P );
77
78
0
      data16 = tvb_get_ntohs(tvb,offset);
79
0
      proto_tree_add_item( h263P_tree, hf_h263P_rr, tvb, offset, 2, ENC_BIG_ENDIAN );
80
0
      proto_tree_add_item( h263P_tree, hf_h263P_pbit, tvb, offset, 2, ENC_BIG_ENDIAN );
81
0
      proto_tree_add_item( h263P_tree, hf_h263P_vbit, tvb, offset, 2, ENC_BIG_ENDIAN );
82
0
      proto_tree_add_item( h263P_tree, hf_h263P_plen, tvb, offset, 2, ENC_BIG_ENDIAN );
83
0
      proto_tree_add_item( h263P_tree, hf_h263P_pebit, tvb, offset, 2, ENC_BIG_ENDIAN );
84
0
      offset = offset +2;
85
      /*
86
       *   V: 1 bit
87
       *
88
       *      Indicates the presence of an 8-bit field containing information
89
       *      for Video Redundancy Coding (VRC), which follows immediately after
90
       *      the initial 16 bits of the payload header, if present.  For syntax
91
       *      and semantics of that 8-bit VRC field, see Section 5.2.
92
       */
93
94
0
      if ((data16&0x0200)==0x0200){
95
          /* V bit = 1
96
           *   The format of the VRC header extension is as follows:
97
           *
98
           *         0 1 2 3 4 5 6 7
99
           *        +-+-+-+-+-+-+-+-+
100
           *        | TID | Trun  |S|
101
           *        +-+-+-+-+-+-+-+-+
102
           *
103
           *   TID: 3 bits
104
           *
105
           *   Thread ID.  Up to 7 threads are allowed.  Each frame of H.263+ VRC
106
           *   data will use as reference information only sync frames or frames
107
           *   within the same thread.  By convention, thread 0 is expected to be
108
           *   the "canonical" thread, which is the thread from which the sync frame
109
           *   should ideally be used.  In the case of corruption or loss of the
110
           *   thread 0 representation, a representation of the sync frame with a
111
           *   higher thread number can be used by the decoder.  Lower thread
112
           *   numbers are expected to contain representations of the sync frames
113
           *   equal to or better than higher thread numbers in the absence of data
114
           *   corruption or loss.  See [Vredun] for a detailed discussion of VRC.
115
           *
116
           *   Trun: 4 bits
117
           *
118
           *   Monotonically increasing (modulo 16) 4-bit number counting the packet
119
           *   number within each thread.
120
           *
121
           *   S: 1 bit
122
           *
123
           *   A bit that indicates that the packet content is for a sync frame.
124
           *   :
125
           */
126
0
          proto_tree_add_item( h263P_tree, hf_h263P_tid, tvb, offset, 1, ENC_BIG_ENDIAN );
127
0
          proto_tree_add_item( h263P_tree, hf_h263P_trun, tvb, offset, 1, ENC_BIG_ENDIAN );
128
0
          proto_tree_add_item( h263P_tree, hf_h263P_s, tvb, offset, 1, ENC_BIG_ENDIAN );
129
0
          offset++;
130
0
      }
131
132
      /* Length, in bytes, of the extra picture header. */
133
0
      plen = (data16 & 0x01f8) >> 3;
134
0
      if (plen != 0){
135
0
          extra_hdr_item = proto_tree_add_item( h263P_tree, hf_h263P_extra_hdr, tvb, offset, plen, ENC_NA );
136
0
          h263P_extr_hdr_tree = proto_item_add_subtree( extra_hdr_item, ett_h263P_extra_hdr );
137
0
          dissect_h263_picture_layer( tvb, pinfo, h263P_extr_hdr_tree, offset, plen, true);
138
0
          offset += plen;
139
0
      }
140
0
      if ((data16&0x0400)!=0){
141
          /* P bit = 1 */
142
0
          data_item = proto_tree_add_item( h263P_tree, hf_h263P_payload, tvb, offset, -1, ENC_NA );
143
0
          h263P_data_tree = proto_item_add_subtree( data_item, ett_h263P_data );
144
          /* Startc code holds bit 17 -23 of the codeword */
145
0
          startcode = tvb_get_uint8(tvb,offset)&0xfe;
146
0
          if (startcode & 0x80){
147
              /* All picture, slice, and EOSBS start codes
148
               * shall be byte aligned, and GOB and EOS start codes may be byte aligned.
149
               */
150
0
              switch(startcode){
151
0
              case 0xf8:
152
                  /* End Of Sub-Bitstream code (EOSBS)
153
                   * EOSBS codes shall be byte aligned
154
                   * ( 1111 100. )
155
                   */
156
0
                  break;
157
0
              case 0x80:
158
0
              case 0x82:
159
                  /* Picture Start Code (PSC)
160
                   * ( 1000 00x.)
161
                   */
162
0
                  col_append_str( pinfo->cinfo, COL_INFO, "(PSC) ");
163
0
                  dissect_h263_picture_layer( tvb, pinfo, h263P_data_tree, offset, -1, true);
164
0
                  break;
165
0
              case 0xfc:
166
0
              case 0xfe:
167
                  /* End Of Sequence (EOS)
168
                   * ( 1111 11x. )
169
                   */
170
0
              default:
171
                  /* Group of Block Start Code (GBSC) or
172
                   * Slice Start Code (SSC)
173
                   */
174
0
                  col_append_str( pinfo->cinfo, COL_INFO, "(GBSC) ");
175
0
                  dissect_h263_group_of_blocks_layer( tvb, h263P_data_tree, offset,true);
176
0
                  break;
177
0
              }
178
0
          }else{
179
              /* Error */
180
0
          }
181
0
          return tvb_captured_length(tvb);
182
0
      }
183
0
      proto_tree_add_item( h263P_tree, hf_h263P_payload, tvb, offset, -1, ENC_NA );
184
0
    }
185
0
    return tvb_captured_length(tvb);
186
0
}
187
188
void
189
proto_reg_handoff_h263P(void)
190
16
{
191
16
    dissector_add_string("rtp_dyn_payload_type","H263-1998", h263P_handle);
192
16
    dissector_add_string("rtp_dyn_payload_type","H263-2000", h263P_handle);
193
16
    dissector_add_uint_range_with_preference("rtp.pt", "", h263P_handle);
194
16
}
195
196
197
void
198
proto_register_h263P(void)
199
16
{
200
16
    module_t *h263P_module;
201
202
16
    static hf_register_info hf[] =
203
16
    {
204
16
        {
205
16
            &hf_h263P_payload,
206
16
            {
207
16
                "H.263 RFC4629 payload",
208
16
                "h263p.payload",
209
16
                FT_NONE,
210
16
                BASE_NONE,
211
16
                NULL,
212
16
                0x0,
213
16
                "The actual H.263 RFC4629 data", HFILL
214
16
            }
215
16
        },
216
16
        {
217
16
            &hf_h263P_rr,
218
16
            {
219
16
                "Reserved",
220
16
                "h263p.rr",
221
16
                FT_UINT16,
222
16
                BASE_DEC,
223
16
                NULL,
224
16
                0xf800,
225
16
                "Reserved SHALL be zero", HFILL
226
16
            }
227
16
        },
228
16
        {
229
16
            &hf_h263P_pbit,
230
16
            {
231
16
                "P",
232
16
                "h263p.p",
233
16
                FT_BOOLEAN,
234
16
                16,
235
16
                NULL,
236
16
                0x0400,
237
16
                "Indicates (GOB/Slice) start or (EOS or EOSBS)", HFILL
238
16
            }
239
16
        },
240
16
        {
241
16
            &hf_h263P_vbit,
242
16
            {
243
16
                "V",
244
16
                "h263p.v",
245
16
                FT_BOOLEAN,
246
16
                16,
247
16
                NULL,
248
16
                0x0200,
249
16
                "presence of Video Redundancy Coding (VRC) field", HFILL
250
16
            }
251
16
        },
252
16
        {
253
16
            &hf_h263P_plen,
254
16
            {
255
16
                "PLEN",
256
16
                "h263p.plen",
257
16
                FT_UINT16,
258
16
                BASE_DEC,
259
16
                NULL,
260
16
                0x01f8,
261
16
                "Length, in bytes, of the extra picture header", HFILL
262
16
            }
263
16
        },
264
16
        {
265
16
            &hf_h263P_pebit,
266
16
            {
267
16
                "PEBIT",
268
16
                "h263p.pebit",
269
16
                FT_UINT16,
270
16
                BASE_DEC,
271
16
                NULL,
272
16
                0x0007,
273
16
                "number of bits that shall be ignored in the last byte of the picture header", HFILL
274
16
            }
275
16
        },
276
277
278
16
        {
279
16
            &hf_h263P_tid,
280
16
            {
281
16
                "Thread ID",
282
16
                "h263p.tid",
283
16
                FT_UINT8,
284
16
                BASE_DEC,
285
16
                NULL,
286
16
                0xe0,
287
16
                NULL, HFILL
288
16
            }
289
16
        },
290
16
        {
291
16
            &hf_h263P_trun,
292
16
            {
293
16
                "Trun",
294
16
                "h263p.trun",
295
16
                FT_UINT8,
296
16
                BASE_DEC,
297
16
                NULL,
298
16
                0x1e,
299
16
                "Monotonically increasing (modulo 16) 4-bit number counting the packet number within each thread", HFILL
300
16
            }
301
16
        },
302
16
        {
303
16
            &hf_h263P_s,
304
16
            {
305
16
                "S",
306
16
                "h263p.s",
307
16
                FT_UINT8,
308
16
                BASE_DEC,
309
16
                NULL,
310
16
                0x01,
311
16
                "Indicates that the packet content is for a sync frame", HFILL
312
16
            }
313
16
        },
314
16
        {
315
16
            &hf_h263P_extra_hdr,
316
16
            {
317
16
                "Extra picture header",
318
16
                "h263p.extra_hdr",
319
16
                FT_BYTES,
320
16
                BASE_NONE,
321
16
                NULL,
322
16
                0x0,
323
16
                NULL, HFILL
324
16
            }
325
16
        },
326
#if 0
327
        {
328
            &hf_h263P_PSC,
329
            {
330
                "H.263 PSC",
331
                "h263p.PSC",
332
                FT_UINT16,
333
                BASE_HEX,
334
                NULL,
335
                0xfc00,
336
                "Picture Start Code(PSC)", HFILL
337
            }
338
        },
339
#endif
340
#if 0
341
        {
342
            &hf_h263P_TR,
343
            {
344
                "H.263 Temporal Reference",
345
                "h263p.tr",
346
                FT_UINT16,
347
                BASE_HEX,
348
                NULL,
349
                0x03fc,
350
                "Temporal Reference, TR", HFILL
351
            }
352
        },
353
#endif
354
355
16
    };
356
357
16
    static int *ett[] =
358
16
    {
359
16
        &ett_h263P,
360
16
        &ett_h263P_extra_hdr,
361
16
        &ett_h263P_payload,
362
16
        &ett_h263P_data,
363
16
    };
364
365
366
16
    proto_h263P = proto_register_protocol("ITU-T Recommendation H.263 RTP Payload header (RFC4629)",
367
16
        "H.263P", "h263p");
368
369
16
    proto_register_field_array(proto_h263P, hf, array_length(hf));
370
16
    proto_register_subtree_array(ett, array_length(ett));
371
372
16
    h263P_module = prefs_register_protocol(proto_h263P, NULL);
373
374
16
    prefs_register_obsolete_preference(h263P_module, "dynamic.payload.type");
375
376
16
    h263P_handle = register_dissector("h263P", dissect_h263P, proto_h263P);
377
16
}
378
379
/*
380
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
381
 *
382
 * Local variables:
383
 * c-basic-offset: 4
384
 * tab-width: 8
385
 * indent-tabs-mode: nil
386
 * End:
387
 *
388
 * vi: set shiftwidth=4 tabstop=8 expandtab:
389
 * :indentSize=4:tabSize=8:noTabs=true:
390
 */