Coverage Report

Created: 2025-02-15 06:25

/src/wireshark/epan/dissectors/packet-h263p.c
Line
Count
Source (jump to first uncovered line)
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
14
{
191
14
    dissector_add_string("rtp_dyn_payload_type","H263-1998", h263P_handle);
192
14
    dissector_add_string("rtp_dyn_payload_type","H263-2000", h263P_handle);
193
14
    dissector_add_uint_range_with_preference("rtp.pt", "", h263P_handle);
194
14
}
195
196
197
void
198
proto_register_h263P(void)
199
14
{
200
14
    module_t *h263P_module;
201
202
14
    static hf_register_info hf[] =
203
14
    {
204
14
        {
205
14
            &hf_h263P_payload,
206
14
            {
207
14
                "H.263 RFC4629 payload",
208
14
                "h263p.payload",
209
14
                FT_NONE,
210
14
                BASE_NONE,
211
14
                NULL,
212
14
                0x0,
213
14
                "The actual H.263 RFC4629 data", HFILL
214
14
            }
215
14
        },
216
14
        {
217
14
            &hf_h263P_rr,
218
14
            {
219
14
                "Reserved",
220
14
                "h263p.rr",
221
14
                FT_UINT16,
222
14
                BASE_DEC,
223
14
                NULL,
224
14
                0xf800,
225
14
                "Reserved SHALL be zero", HFILL
226
14
            }
227
14
        },
228
14
        {
229
14
            &hf_h263P_pbit,
230
14
            {
231
14
                "P",
232
14
                "h263p.p",
233
14
                FT_BOOLEAN,
234
14
                16,
235
14
                NULL,
236
14
                0x0400,
237
14
                "Indicates (GOB/Slice) start or (EOS or EOSBS)", HFILL
238
14
            }
239
14
        },
240
14
        {
241
14
            &hf_h263P_vbit,
242
14
            {
243
14
                "V",
244
14
                "h263p.v",
245
14
                FT_BOOLEAN,
246
14
                16,
247
14
                NULL,
248
14
                0x0200,
249
14
                "presence of Video Redundancy Coding (VRC) field", HFILL
250
14
            }
251
14
        },
252
14
        {
253
14
            &hf_h263P_plen,
254
14
            {
255
14
                "PLEN",
256
14
                "h263p.plen",
257
14
                FT_UINT16,
258
14
                BASE_DEC,
259
14
                NULL,
260
14
                0x01f8,
261
14
                "Length, in bytes, of the extra picture header", HFILL
262
14
            }
263
14
        },
264
14
        {
265
14
            &hf_h263P_pebit,
266
14
            {
267
14
                "PEBIT",
268
14
                "h263p.pebit",
269
14
                FT_UINT16,
270
14
                BASE_DEC,
271
14
                NULL,
272
14
                0x0003,
273
14
                "number of bits that shall be ignored in the last byte of the picture header", HFILL
274
14
            }
275
14
        },
276
277
278
14
        {
279
14
            &hf_h263P_tid,
280
14
            {
281
14
                "Thread ID",
282
14
                "h263p.tid",
283
14
                FT_UINT8,
284
14
                BASE_DEC,
285
14
                NULL,
286
14
                0xe0,
287
14
                NULL, HFILL
288
14
            }
289
14
        },
290
14
        {
291
14
            &hf_h263P_trun,
292
14
            {
293
14
                "Trun",
294
14
                "h263p.trun",
295
14
                FT_UINT8,
296
14
                BASE_DEC,
297
14
                NULL,
298
14
                0x1e,
299
14
                "Monotonically increasing (modulo 16) 4-bit number counting the packet number within each thread", HFILL
300
14
            }
301
14
        },
302
14
        {
303
14
            &hf_h263P_s,
304
14
            {
305
14
                "S",
306
14
                "h263p.s",
307
14
                FT_UINT8,
308
14
                BASE_DEC,
309
14
                NULL,
310
14
                0x01,
311
14
                "Indicates that the packet content is for a sync frame", HFILL
312
14
            }
313
14
        },
314
14
        {
315
14
            &hf_h263P_extra_hdr,
316
14
            {
317
14
                "Extra picture header",
318
14
                "h263p.extra_hdr",
319
14
                FT_BYTES,
320
14
                BASE_NONE,
321
14
                NULL,
322
14
                0x0,
323
14
                NULL, HFILL
324
14
            }
325
14
        },
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
14
    };
356
357
14
    static int *ett[] =
358
14
    {
359
14
        &ett_h263P,
360
14
        &ett_h263P_extra_hdr,
361
14
        &ett_h263P_payload,
362
14
        &ett_h263P_data,
363
14
    };
364
365
366
14
    proto_h263P = proto_register_protocol("ITU-T Recommendation H.263 RTP Payload header (RFC4629)",
367
14
        "H.263P", "h263p");
368
369
14
    proto_register_field_array(proto_h263P, hf, array_length(hf));
370
14
    proto_register_subtree_array(ett, array_length(ett));
371
372
14
    h263P_module = prefs_register_protocol(proto_h263P, NULL);
373
374
14
    prefs_register_obsolete_preference(h263P_module, "dynamic.payload.type");
375
376
14
    h263P_handle = register_dissector("h263P", dissect_h263P, proto_h263P);
377
14
}
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
 */