summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-h263p.c
blob: 64b0fa849f59c7d1b8ee845ad98eb128f522b3c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/* packet-h263p.c
 *
 * Routines for RFC-4629-encapsulated H.263 dissection
 *
 * Copyright 2003 Niklas Ogren <niklas.ogren@7l.se>
 * Seven Levels Consultants AB
 *
 * Copyright 2008 Richard van der Hoff, MX Telecom
 * <richardv@mxtelecom.com>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>

#include <epan/prefs.h>

#include "packet-h263.h"

void proto_reg_handoff_h263P(void);
void proto_register_h263P(void);

static int proto_h263P = -1;

/* H.263 RFC 4629 fields */
static int hf_h263P_payload = -1;
static int hf_h263P_rr = -1;
static int hf_h263P_pbit = -1;
static int hf_h263P_vbit = -1;
static int hf_h263P_plen = -1;
static int hf_h263P_pebit = -1;
static int hf_h263P_tid = -1;
static int hf_h263P_trun = -1;
static int hf_h263P_s = -1;
static int hf_h263P_extra_hdr = -1;
/* static int hf_h263P_PSC = -1; */
/* static int hf_h263P_TR = -1; */


/* H.263-1998 fields defining a sub tree */
static gint ett_h263P = -1;
static gint ett_h263P_extra_hdr = -1;
static gint ett_h263P_payload   = -1;
static gint ett_h263P_data = -1;

static dissector_handle_t h263P_handle;

/* RFC 4629 */
static int
dissect_h263P( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ )
{
    proto_item *ti                  = NULL;
    proto_item *data_item           = NULL;
    proto_item *extra_hdr_item      = NULL;
    proto_tree *h263P_tree          = NULL;
    proto_tree *h263P_extr_hdr_tree = NULL;
    proto_tree *h263P_data_tree     = NULL;
    unsigned int offset             = 0;
    guint16 data16, plen;
    guint8 startcode;

    /*
    tvbuff_t *next_tvb;
    */

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.263 RFC4629 ");

    if ( tree ) {
      ti = proto_tree_add_item( tree, proto_h263P, tvb, offset, -1, ENC_NA );
      h263P_tree = proto_item_add_subtree( ti, ett_h263P );

      data16 = tvb_get_ntohs(tvb,offset);
      proto_tree_add_item( h263P_tree, hf_h263P_rr, tvb, offset, 2, ENC_BIG_ENDIAN );
      proto_tree_add_item( h263P_tree, hf_h263P_pbit, tvb, offset, 2, ENC_BIG_ENDIAN );
      proto_tree_add_item( h263P_tree, hf_h263P_vbit, tvb, offset, 2, ENC_BIG_ENDIAN );
      proto_tree_add_item( h263P_tree, hf_h263P_plen, tvb, offset, 2, ENC_BIG_ENDIAN );
      proto_tree_add_item( h263P_tree, hf_h263P_pebit, tvb, offset, 2, ENC_BIG_ENDIAN );
      offset = offset +2;
      /*
       *   V: 1 bit
       *
       *      Indicates the presence of an 8-bit field containing information
       *      for Video Redundancy Coding (VRC), which follows immediately after
       *      the initial 16 bits of the payload header, if present.  For syntax
       *      and semantics of that 8-bit VRC field, see Section 5.2.
       */

      if ((data16&0x0200)==0x0200){
          /* V bit = 1
           *   The format of the VRC header extension is as follows:
           *
           *         0 1 2 3 4 5 6 7
           *        +-+-+-+-+-+-+-+-+
           *        | TID | Trun  |S|
           *        +-+-+-+-+-+-+-+-+
           *
           *   TID: 3 bits
           *
           *   Thread ID.  Up to 7 threads are allowed.  Each frame of H.263+ VRC
           *   data will use as reference information only sync frames or frames
           *   within the same thread.  By convention, thread 0 is expected to be
           *   the "canonical" thread, which is the thread from which the sync frame
           *   should ideally be used.  In the case of corruption or loss of the
           *   thread 0 representation, a representation of the sync frame with a
           *   higher thread number can be used by the decoder.  Lower thread
           *   numbers are expected to contain representations of the sync frames
           *   equal to or better than higher thread numbers in the absence of data
           *   corruption or loss.  See [Vredun] for a detailed discussion of VRC.
           *
           *   Trun: 4 bits
           *
           *   Monotonically increasing (modulo 16) 4-bit number counting the packet
           *   number within each thread.
           *
           *   S: 1 bit
           *
           *   A bit that indicates that the packet content is for a sync frame.
           *   :
           */
          proto_tree_add_item( h263P_tree, hf_h263P_tid, tvb, offset, 1, ENC_BIG_ENDIAN );
          proto_tree_add_item( h263P_tree, hf_h263P_trun, tvb, offset, 1, ENC_BIG_ENDIAN );
          proto_tree_add_item( h263P_tree, hf_h263P_s, tvb, offset, 1, ENC_BIG_ENDIAN );
          offset++;
      }

      /* Length, in bytes, of the extra picture header. */
      plen = (data16 & 0x01f8) >> 3;
      if (plen != 0){
          extra_hdr_item = proto_tree_add_item( h263P_tree, hf_h263P_extra_hdr, tvb, offset, plen, ENC_NA );
          h263P_extr_hdr_tree = proto_item_add_subtree( extra_hdr_item, ett_h263P_extra_hdr );
          dissect_h263_picture_layer( tvb, pinfo, h263P_extr_hdr_tree, offset, plen, TRUE);
          offset += plen;
      }
      if ((data16&0x0400)!=0){
          /* P bit = 1 */
          data_item = proto_tree_add_item( h263P_tree, hf_h263P_payload, tvb, offset, -1, ENC_NA );
          h263P_data_tree = proto_item_add_subtree( data_item, ett_h263P_data );
          /* Startc code holds bit 17 -23 of the codeword */
          startcode = tvb_get_guint8(tvb,offset)&0xfe;
          if (startcode & 0x80){
              /* All picture, slice, and EOSBS start codes
               * shall be byte aligned, and GOB and EOS start codes may be byte aligned.
               */
              switch(startcode){
              case 0xf8:
                  /* End Of Sub-Bitstream code (EOSBS)
                   * EOSBS codes shall be byte aligned
                   * ( 1111 100. )
                   */
                  break;
              case 0x80:
              case 0x82:
                  /* Picture Start Code (PSC)
                   * ( 1000 00x.)
                   */
                  col_append_str( pinfo->cinfo, COL_INFO, "(PSC) ");
                  dissect_h263_picture_layer( tvb, pinfo, h263P_data_tree, offset, -1, TRUE);
                  break;
              case 0xfc:
              case 0xfe:
                  /* End Of Sequence (EOS)
                   * ( 1111 11x. )
                   */
              default:
                  /* Group of Block Start Code (GBSC) or
                   * Slice Start Code (SSC)
                   */
                  col_append_str( pinfo->cinfo, COL_INFO, "(GBSC) ");
                  dissect_h263_group_of_blocks_layer( tvb, h263P_data_tree, offset,TRUE);
                  break;
              }
          }else{
              /* Error */
          }
          return tvb_captured_length(tvb);
      }
      proto_tree_add_item( h263P_tree, hf_h263P_payload, tvb, offset, -1, ENC_NA );
    }
    return tvb_captured_length(tvb);
}

void
proto_reg_handoff_h263P(void)
{
    dissector_add_string("rtp_dyn_payload_type","H263-1998", h263P_handle);
    dissector_add_string("rtp_dyn_payload_type","H263-2000", h263P_handle);
    dissector_add_uint_range_with_preference("rtp.pt", "", h263P_handle);
}


void
proto_register_h263P(void)
{
    module_t *h263P_module;

    static hf_register_info hf[] =
    {
        {
            &hf_h263P_payload,
            {
                "H.263 RFC4629 payload",
                "h263p.payload",
                FT_NONE,
                BASE_NONE,
                NULL,
                0x0,
                "The actual H.263 RFC4629 data", HFILL
            }
        },
        {
            &hf_h263P_rr,
            {
                "Reserved",
                "h263p.rr",
                FT_UINT16,
                BASE_DEC,
                NULL,
                0xf800,
                "Reserved SHALL be zero", HFILL
            }
        },
        {
            &hf_h263P_pbit,
            {
                "P",
                "h263p.p",
                FT_BOOLEAN,
                16,
                NULL,
                0x0400,
                "Indicates (GOB/Slice) start or (EOS or EOSBS)", HFILL
            }
        },
        {
            &hf_h263P_vbit,
            {
                "V",
                "h263p.v",
                FT_BOOLEAN,
                16,
                NULL,
                0x0200,
                "presence of Video Redundancy Coding (VRC) field", HFILL
            }
        },
        {
            &hf_h263P_plen,
            {
                "PLEN",
                "h263p.plen",
                FT_UINT16,
                BASE_DEC,
                NULL,
                0x01f8,
                "Length, in bytes, of the extra picture header", HFILL
            }
        },
        {
            &hf_h263P_pebit,
            {
                "PEBIT",
                "h263p.pebit",
                FT_UINT16,
                BASE_DEC,
                NULL,
                0x0003,
                "number of bits that shall be ignored in the last byte of the picture header", HFILL
            }
        },


        {
            &hf_h263P_tid,
            {
                "Thread ID",
                "h263p.tid",
                FT_UINT8,
                BASE_DEC,
                NULL,
                0xe0,
                NULL, HFILL
            }
        },
        {
            &hf_h263P_trun,
            {
                "Trun",
                "h263p.trun",
                FT_UINT8,
                BASE_DEC,
                NULL,
                0x1e,
                "Monotonically increasing (modulo 16) 4-bit number counting the packet number within each thread", HFILL
            }
        },
        {
            &hf_h263P_s,
            {
                "S",
                "h263p.s",
                FT_UINT8,
                BASE_DEC,
                NULL,
                0x01,
                "Indicates that the packet content is for a sync frame", HFILL
            }
        },
        {
            &hf_h263P_extra_hdr,
            {
                "Extra picture header",
                "h263p.extra_hdr",
                FT_BYTES,
                BASE_NONE,
                NULL,
                0x0,
                NULL, HFILL
            }
        },
#if 0
        {
            &hf_h263P_PSC,
            {
                "H.263 PSC",
                "h263p.PSC",
                FT_UINT16,
                BASE_HEX,
                NULL,
                0xfc00,
                "Picture Start Code(PSC)", HFILL
            }
        },
#endif
#if 0
        {
            &hf_h263P_TR,
            {
                "H.263 Temporal Reference",
                "h263p.tr",
                FT_UINT16,
                BASE_HEX,
                NULL,
                0x03fc,
                "Temporal Reference, TR", HFILL
            }
        },
#endif

    };

    static gint *ett[] =
    {
        &ett_h263P,
        &ett_h263P_extra_hdr,
        &ett_h263P_payload,
        &ett_h263P_data,
    };


    proto_h263P = proto_register_protocol("ITU-T Recommendation H.263 RTP Payload header (RFC4629)",
        "H.263P", "h263p");

    proto_register_field_array(proto_h263P, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    h263P_module = prefs_register_protocol(proto_h263P, NULL);

    prefs_register_obsolete_preference(h263P_module, "dynamic.payload.type");

    h263P_handle = register_dissector("h263P", dissect_h263P, proto_h263P);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */