Coverage Report

Created: 2025-12-27 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-rtp.c
Line
Count
Source
1
/* packet-rtp.c
2
 *
3
 * Routines for RTP dissection
4
 * RTP = Real time Transport Protocol
5
 *
6
 * Copyright 2000, Philips Electronics N.V.
7
 * Written by Andreas Sikkema <h323@ramdyne.nl>
8
 *
9
 * Wireshark - Network traffic analyzer
10
 * By Gerald Combs <gerald@wireshark.org>
11
 * Copyright 1998 Gerald Combs
12
 *
13
 * SPDX-License-Identifier: GPL-2.0-or-later
14
 */
15
16
/*
17
 * This dissector tries to dissect the RTP protocol according to Annex A
18
 * of ITU-T Recommendation H.225.0 (02/98) or RFC 3550 (obsoleting 1889).
19
 *
20
 * RTP traffic is traditionally handled by an even UDP portnumber. This can
21
 * be any port number, but there is a registered port available, port 5004
22
 * See Annex B of ITU-T Recommendation H.225.0, section B.7
23
 *
24
 * Note that nowadays RTP and RTCP are often multiplexed onto a single port,
25
 * per RFC 5671.
26
 *
27
 * This doesn't dissect older versions of RTP, such as:
28
 *
29
 *    the vat protocol ("version 0") - see
30
 *
31
 *  ftp://ftp.ee.lbl.gov/conferencing/vat/alpha-test/vatsrc-4.0b2.tar.gz
32
 *
33
 *    and look in "session-vat.cc" if you want to write a dissector
34
 *    (have fun - there aren't any nice header files showing the packet
35
 *    format);
36
 *
37
 *    version 1, as documented in
38
 *
39
 *  ftp://gaia.cs.umass.edu/pub/hgschulz/rtp/draft-ietf-avt-rtp-04.txt
40
 *
41
 * It also dissects PacketCable CCC-encapsulated RTP data, as described in
42
 * chapter 5 of the PacketCable Electronic Surveillance Specification:
43
 *
44
 *   http://www.packetcable.com/downloads/specs/PKT-SP-ESP1.5-I01-050128.pdf
45
 */
46
47
48
#include "config.h"
49
50
#include <epan/packet.h>
51
#include <epan/exceptions.h>
52
#include <epan/show_exception.h>
53
#include <epan/expert.h>
54
#include <epan/proto_data.h>
55
#include <epan/decode_as.h>
56
#include <epan/tfs.h>
57
#include <wsutil/array.h>
58
59
#include "packet-rtp.h"
60
#include "packet-rtcp.h"
61
#include "packet-tcp.h"
62
#include "packet-rtp_pt.h"
63
64
#include <epan/tap.h>
65
#include <epan/prefs.h>
66
67
/* un-comment the following as well as this line in conversation.c, to enable debug printing */
68
/* #define DEBUG_CONVERSATION */
69
#include "conversation_debug.h"
70
71
/* uncomment this to enable debugging of fragment reassembly */
72
/* #define DEBUG   1 */
73
/* #define DEBUG_FRAGMENTS   1 */
74
75
typedef struct _rfc2198_hdr {
76
    unsigned int pt;
77
    int offset;
78
    int len;
79
    const char* payload_type_str;
80
    int payload_rate;
81
    unsigned payload_channels;
82
    wmem_map_t *payload_fmtp_map;
83
    struct _rfc2198_hdr *next;
84
} rfc2198_hdr;
85
86
/* we have one of these for each pdu which spans more than one segment
87
 */
88
typedef struct _rtp_multisegment_pdu {
89
    /* the seqno of the segment where the pdu starts */
90
    uint32_t startseq;
91
92
    /* the seqno of the segment where the pdu ends */
93
    uint32_t endseq;
94
} rtp_multisegment_pdu;
95
96
typedef struct  _rtp_private_conv_info {
97
    /* This tree is indexed by sequence number and keeps track of all
98
     * all pdus spanning multiple segments for this flow.
99
     */
100
    wmem_tree_t *multisegment_pdus;
101
} rtp_private_conv_info;
102
103
typedef struct _rtp_number_space {
104
105
    uint32_t extended_seqno;
106
    uint64_t extended_timestamp;
107
} rtp_number_space;
108
109
/** Info to save in RTP conversation */
110
struct _rtp_conversation_info
111
{
112
    char     method[MAX_RTP_SETUP_METHOD_SIZE + 1];
113
    uint32_t frame_number;                          /**> the frame where this conversation is started */
114
    uint32_t media_types;
115
    rtp_dyn_payload_t* rtp_dyn_payload;             /**> the dynamic RTP payload info - see comments above */
116
117
    wmem_map_t* ssrc_number_space;                  /**> maps the SSRCs to the last seen seqno and timestamp
118
                                                     * for that SSRC in the conversation */
119
    struct _rtp_private_conv_info* rtp_conv_info;   /**> conversation info private
120
                                                     * to the rtp dissector
121
                                                     */
122
    struct srtp_info* srtp_info;                    /* SRTP context */
123
    bta2dp_codec_info_t* bta2dp_info;
124
    btvdp_codec_info_t* btvdp_info;
125
    wmem_array_t* rtp_sdp_setup_info_list;           /**> List with data from all SDP occurrences for this stream holding a call ID)*/
126
};
127
128
typedef struct {
129
    char *encoding_name;
130
    int   sample_rate;
131
    unsigned channels;
132
    wmem_map_t *fmtp_map;
133
} encoding_name_and_rate_t;
134
135
struct _rtp_dyn_payload_t
136
{
137
    GHashTable *table;
138
    size_t ref_count;
139
};
140
141
static reassembly_table rtp_reassembly_table;
142
143
static int hf_rtp_fragments;
144
static int hf_rtp_fragment;
145
static int hf_rtp_fragment_overlap;
146
static int hf_rtp_fragment_overlap_conflict;
147
static int hf_rtp_fragment_multiple_tails;
148
static int hf_rtp_fragment_too_long_fragment;
149
static int hf_rtp_fragment_error;
150
static int hf_rtp_fragment_count;
151
static int hf_rtp_reassembled_in;
152
static int hf_rtp_reassembled_length;
153
154
static int ett_rtp_fragment;
155
static int ett_rtp_fragments;
156
157
static const fragment_items rtp_fragment_items = {
158
    &ett_rtp_fragment,
159
    &ett_rtp_fragments,
160
    &hf_rtp_fragments,
161
    &hf_rtp_fragment,
162
    &hf_rtp_fragment_overlap,
163
    &hf_rtp_fragment_overlap_conflict,
164
    &hf_rtp_fragment_multiple_tails,
165
    &hf_rtp_fragment_too_long_fragment,
166
    &hf_rtp_fragment_error,
167
    &hf_rtp_fragment_count,
168
    &hf_rtp_reassembled_in,
169
    &hf_rtp_reassembled_length,
170
    /* Reassembled data field */
171
    NULL,
172
    "RTP fragments"
173
};
174
175
static dissector_handle_t rtp_handle;
176
static dissector_handle_t rtp_rfc4571_handle;
177
static dissector_handle_t rtcp_handle;
178
static dissector_handle_t classicstun_handle;
179
static dissector_handle_t stun_handle;
180
static dissector_handle_t t38_handle;
181
static dissector_handle_t zrtp_handle;
182
static dissector_handle_t dtls_handle;
183
static dissector_handle_t rtp_rfc2198_handle;
184
185
static dissector_handle_t sprt_handle;
186
static dissector_handle_t v150fw_handle;
187
188
static dissector_handle_t bta2dp_content_protection_header_scms_t;
189
static dissector_handle_t btvdp_content_protection_header_scms_t;
190
static dissector_handle_t bta2dp_handle;
191
static dissector_handle_t btvdp_handle;
192
static dissector_handle_t sbc_handle;
193
194
static int rtp_tap;
195
196
static dissector_table_t rtp_pt_dissector_table;
197
static dissector_table_t rtp_dyn_pt_dissector_table;
198
199
static dissector_table_t rtp_hdr_ext_dissector_table;
200
static dissector_table_t rtp_hdr_ext_rfc5285_dissector_table;
201
202
/* Used for storing data to be retrieved by the SDP dissector*/
203
static int proto_sdp;
204
205
/* RTP header fields             */
206
static int proto_rtp;
207
static int proto_rtp_rfc2198;
208
static int hf_rtp_version;
209
static int hf_rtp_padding;
210
static int hf_rtp_extension;
211
static int hf_rtp_csrc_count;
212
static int hf_rtp_marker;
213
static int hf_rtp_payload_type;
214
static int hf_rtp_seq_nr;
215
static int hf_rtp_ext_seq_nr;
216
static int hf_rtp_timestamp;
217
static int hf_rtp_ext_timestamp;
218
static int hf_rtp_ssrc;
219
static int hf_rtp_csrc_items;
220
static int hf_rtp_csrc_item;
221
static int hf_rtp_data;
222
static int hf_rtp_padding_data;
223
static int hf_rtp_padding_count;
224
static int hf_rtp_rfc2198_follow;
225
static int hf_rtp_rfc2198_tm_off;
226
static int hf_rtp_rfc2198_bl_len;
227
228
/* RTP header extension fields   */
229
static int hf_rtp_prof_define;
230
static int hf_rtp_length;
231
static int hf_rtp_hdr_exts;
232
static int hf_rtp_hdr_ext;
233
234
/* RTP setup fields */
235
static int hf_rtp_setup;
236
static int hf_rtp_setup_frame;
237
static int hf_rtp_setup_method;
238
239
/* RTP fields defining a sub tree */
240
static int ett_rtp;
241
static int ett_csrc_list;
242
static int ett_hdr_ext;
243
static int ett_hdr_ext_rfc5285;
244
static int ett_rtp_setup;
245
static int ett_rtp_rfc2198;
246
static int ett_rtp_rfc2198_hdr;
247
248
/* SRTP fields */
249
static int hf_srtp_encrypted_payload;
250
/* static int hf_srtp_null_encrypted_payload; */
251
static int hf_srtp_mki;
252
static int hf_srtp_auth_tag;
253
254
/* PacketCable CCC header fields */
255
static int proto_pkt_ccc;
256
static int hf_pkt_ccc_id;
257
static int hf_pkt_ccc_ts;
258
259
/* PacketCable CCC field defining a sub tree */
260
static int ett_pkt_ccc;
261
262
static expert_field ei_rtp_fragment_unfinished;
263
static expert_field ei_rtp_padding_missing;
264
static expert_field ei_rtp_padding_bogus;
265
266
/* RFC 5285 Header extensions */
267
static int hf_rtp_ext_rfc5285_id;
268
static int hf_rtp_ext_rfc5285_length;
269
static int hf_rtp_ext_rfc5285_appbits;
270
static int hf_rtp_ext_rfc5285_data;
271
272
/* RFC 4571 Header extension */
273
static int hf_rfc4571_header_len;
274
275
0
#define RTP0_INVALID 0
276
0
#define RTP0_STUN    1
277
0
#define RTP0_CLASSICSTUN    2
278
0
#define RTP0_T38     3
279
0
#define RTP0_SPRT    4
280
103
#define RTP0_RFC7983 5
281
282
static const enum_val_t rtp_version0_types[] = {
283
    { "invalid", "Invalid or ZRTP packets", RTP0_INVALID },
284
    { "stun", "STUN packets", RTP0_STUN },
285
    { "classicstun", "CLASSIC-STUN packets", RTP0_CLASSICSTUN },
286
    { "t38", "T.38 packets", RTP0_T38 },
287
    { "sprt", "SPRT packets", RTP0_SPRT },
288
    { "rfc7983", "Multiplexed as in RFC 7983", RTP0_RFC7983 },
289
    { NULL, NULL, 0 }
290
};
291
static int global_rtp_version0_type = 5;
292
293
/* Forward declaration we need below */
294
void proto_register_rtp(void);
295
void proto_reg_handoff_rtp(void);
296
void proto_register_pkt_ccc(void);
297
void proto_reg_handoff_pkt_ccc(void);
298
299
static int dissect_rtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data);
300
static void show_setup_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
301
static struct _rtp_packet_info *get_rtp_packet_info(packet_info *pinfo, struct _rtp_info *rtp_info);
302
303
/* Preferences bool to control whether or not setup info should be shown */
304
static bool global_rtp_show_setup_info = true;
305
306
/* desegment RTP streams */
307
static bool desegment_rtp = true;
308
309
/* RFC2198 Redundant Audio Data */
310
14
#define RFC2198_DEFAULT_PT_RANGE "99"
311
312
static bool rfc2198_deencapsulate = true;
313
314
315
316
/*
317
 * Fields in the first octet of the RTP header.
318
 */
319
320
/* Version is the first 2 bits of the first octet*/
321
154
#define RTP_VERSION(octet)  ((octet) >> 6)
322
323
/* Padding is the third bit; No need to shift, because true is any value
324
   other than 0! */
325
65
#define RTP_PADDING(octet)  ((octet) & 0x20)
326
327
/* Extension bit is the fourth bit */
328
65
#define RTP_EXTENSION(octet)    ((octet) & 0x10)
329
330
/* ED137 signature */
331
#define RTP_ED137_SIG    0x0067
332
333
/* ED137A signature */
334
#define RTP_ED137A_SIG   0x0167
335
336
/* RFC 5285 one byte header signature */
337
0
#define RTP_RFC5285_ONE_BYTE_SIG        0xBEDE
338
339
/* RFC 5285 two byte header mask and signature */
340
0
#define RTP_RFC5285_TWO_BYTE_MASK       0xFFF0
341
0
#define RTP_RFC5285_TWO_BYTE_SIG        0x1000
342
343
/* CSRC count is the last four bits */
344
65
#define RTP_CSRC_COUNT(octet)   ((octet) & 0xF)
345
346
static const value_string rtp_version_vals[] =
347
{
348
    { 2, "RFC 1889 Version" }, /* First for speed */
349
    { 0, "Old VAT Version" },
350
    { 1, "First Draft Version" },
351
    { 0, NULL },
352
};
353
354
static const range_string rtp_ext_profile_rvals[] =
355
{
356
    { RTP_ED137_SIG, RTP_ED137_SIG, "ED137" },
357
    { RTP_ED137A_SIG, RTP_ED137A_SIG, "ED137A" },
358
    { RTP_RFC5285_TWO_BYTE_SIG, RTP_RFC5285_TWO_BYTE_SIG + 0xF, "RFC 5285 Two-Byte Header Extensions" },
359
    { RTP_RFC5285_ONE_BYTE_SIG, RTP_RFC5285_ONE_BYTE_SIG, "RFC 5285 One-Byte Header Extensions" },
360
    { 0, 0, NULL },
361
};
362
363
/*
364
 * Fields in the second octet of the RTP header.
365
 */
366
367
/* Marker is the first bit of the second octet */
368
65
#define RTP_MARKER(octet)   ((octet) & 0x80)
369
370
/* Payload type is the last 7 bits */
371
65
#define RTP_PAYLOAD_TYPE(octet) ((octet) & 0x7F)
372
/* https://www.iana.org/assignments/rtp-parameters/ */
373
374
56
#define FIRST_RTCP_CONFLICT_PAYLOAD_TYPE 64
375
0
#define LAST_RTCP_CONFLICT_PAYLOAD_TYPE  95
376
377
static const value_string rtp_payload_type_vals[] =
378
{
379
/*  0 */    { PT_PCMU,          "ITU-T G.711 PCMU" },
380
/*  1 */    { PT_1016,          "USA Federal Standard FS-1016" },
381
/*  2 */    { PT_G721,          "ITU-T G.721" },
382
/*  3 */    { PT_GSM,           "GSM 06.10" },
383
/*  4 */    { PT_G723,          "ITU-T G.723" },
384
/*  5 */    { PT_DVI4_8000,     "DVI4 8000 samples/s" },
385
/*  6 */    { PT_DVI4_16000,    "DVI4 16000 samples/s" },
386
/*  7 */    { PT_LPC,           "Experimental linear predictive encoding from Xerox PARC" },
387
/*  8 */    { PT_PCMA,          "ITU-T G.711 PCMA" },
388
/*  9 */    { PT_G722,          "ITU-T G.722" },
389
/* 10 */    { PT_L16_STEREO,    "16-bit uncompressed audio, stereo" },
390
/* 11 */    { PT_L16_MONO,      "16-bit uncompressed audio, monaural" },
391
/* 12 */    { PT_QCELP,         "Qualcomm Code Excited Linear Predictive coding" },
392
/* 13 */    { PT_CN,            "Comfort noise" },
393
/* 14 */    { PT_MPA,           "MPEG-I/II Audio"},
394
/* 15 */    { PT_G728,          "ITU-T G.728" },
395
/* 16 */    { PT_DVI4_11025,    "DVI4 11025 samples/s" },
396
/* 17 */    { PT_DVI4_22050,    "DVI4 22050 samples/s" },
397
/* 18 */    { PT_G729,          "ITU-T G.729" },
398
/* 19 */    { PT_CN_OLD,        "Comfort noise (old)" },
399
/* 20 */    { 20,               "Unassigned" },
400
/* 21 */    { 21,               "Unassigned" },
401
/* 22 */    { 22,               "Unassigned" },
402
/* 23 */    { 23,               "Unassigned" },
403
/* 24 */    { 24,               "Unassigned" },
404
/* 25 */    { PT_CELB,          "Sun CellB video encoding" },
405
/* 26 */    { PT_JPEG,          "JPEG-compressed video" },
406
/* 27 */    { 27,               "Unassigned" },
407
/* 28 */    { PT_NV,            "'nv' program" },
408
/* 29 */    { 29,               "Unassigned" },
409
/* 30 */    { 30,               "Unassigned" },
410
/* 31 */    { PT_H261,          "ITU-T H.261" },
411
/* 32 */    { PT_MPV,           "MPEG-I/II Video"},
412
/* 33 */    { PT_MP2T,          "MPEG-II transport streams"},
413
/* 34 */    { PT_H263,          "ITU-T H.263" },
414
/* 35-71     Unassigned  */
415
/* 35 */    { 35,               "Unassigned" },
416
/* 36 */    { 36,               "Unassigned" },
417
/* 37 */    { 37,               "Unassigned" },
418
/* 38 */    { 38,               "Unassigned" },
419
/* 39 */    { 39,               "Unassigned" },
420
/* 40 */    { 40,               "Unassigned" },
421
/* 41 */    { 41,               "Unassigned" },
422
/* 42 */    { 42,               "Unassigned" },
423
/* 43 */    { 43,               "Unassigned" },
424
/* 44 */    { 44,               "Unassigned" },
425
/* 45 */    { 45,               "Unassigned" },
426
/* 46 */    { 46,               "Unassigned" },
427
/* 47 */    { 47,               "Unassigned" },
428
/* 48 */    { 48,               "Unassigned" },
429
/* 49 */    { 49,               "Unassigned" },
430
/* 50 */    { 50,               "Unassigned" },
431
/* 51 */    { 51,               "Unassigned" },
432
/* 52 */    { 52,               "Unassigned" },
433
/* 53 */    { 53,               "Unassigned" },
434
/* 54 */    { 54,               "Unassigned" },
435
/* 55 */    { 55,               "Unassigned" },
436
/* 56 */    { 56,               "Unassigned" },
437
/* 57 */    { 57,               "Unassigned" },
438
/* 58 */    { 58,               "Unassigned" },
439
/* 59 */    { 59,               "Unassigned" },
440
/* 60 */    { 60,               "Unassigned" },
441
/* 61 */    { 61,               "Unassigned" },
442
/* 62 */    { 62,               "Unassigned" },
443
/* 63 */    { 63,               "Unassigned" },
444
/* 64 */    { 64,               "Unassigned" },
445
/* 65 */    { 65,               "Unassigned" },
446
/* 66 */    { 66,               "Unassigned" },
447
/* 67 */    { 67,               "Unassigned" },
448
/* 68 */    { 68,               "Unassigned" },
449
/* 69 */    { 69,               "Unassigned" },
450
/* 70 */    { 70,               "Unassigned" },
451
/* 71 */    { 71,               "Unassigned" },
452
/* 72-76     Reserved for RTCP conflict avoidance                                  [RFC3551] */
453
/* 72 */    { 72,               "Reserved for RTCP conflict avoidance" },
454
/* 73 */    { 73,               "Reserved for RTCP conflict avoidance" },
455
/* 74 */    { 74,               "Reserved for RTCP conflict avoidance" },
456
/* 75 */    { 75,               "Reserved for RTCP conflict avoidance" },
457
/* 76 */    { 76,               "Reserved for RTCP conflict avoidance" },
458
/* 77-95     Unassigned, MAY be used if > 32 PT are used */
459
/* 77 */    { 77,               "Unassigned" },
460
/* 78 */    { 78,               "Unassigned" },
461
/* 79 */    { 79,               "Unassigned" },
462
/* 80 */    { 80,               "Unassigned" },
463
/* 81 */    { 81,               "Unassigned" },
464
/* 82 */    { 82,               "Unassigned" },
465
/* 83 */    { 83,               "Unassigned" },
466
/* 84 */    { 84,               "Unassigned" },
467
/* 85 */    { 85,               "Unassigned" },
468
/* 86 */    { 86,               "Unassigned" },
469
/* 87 */    { 87,               "Unassigned" },
470
/* 88 */    { 88,               "Unassigned" },
471
/* 89 */    { 89,               "Unassigned" },
472
/* 90 */    { 90,               "Unassigned" },
473
/* 91 */    { 91,               "Unassigned" },
474
/* 92 */    { 92,               "Unassigned" },
475
/* 93 */    { 93,               "Unassigned" },
476
/* 94 */    { 94,               "Unassigned" },
477
/* 95 */    { 95,               "Unassigned" },
478
        /* Added to support additional RTP payload types
479
         * See packet-rtp_pt.h */
480
        { PT_UNDF_96,   "DynamicRTP-Type-96" },
481
        { PT_UNDF_97,   "DynamicRTP-Type-97" },
482
        { PT_UNDF_98,   "DynamicRTP-Type-98" },
483
        { PT_UNDF_99,   "DynamicRTP-Type-99" },
484
        { PT_UNDF_100,  "DynamicRTP-Type-100" },
485
        { PT_UNDF_101,  "DynamicRTP-Type-101" },
486
        { PT_UNDF_102,  "DynamicRTP-Type-102" },
487
        { PT_UNDF_103,  "DynamicRTP-Type-103" },
488
        { PT_UNDF_104,  "DynamicRTP-Type-104" },
489
        { PT_UNDF_105,  "DynamicRTP-Type-105" },
490
        { PT_UNDF_106,  "DynamicRTP-Type-106" },
491
        { PT_UNDF_107,  "DynamicRTP-Type-107" },
492
        { PT_UNDF_108,  "DynamicRTP-Type-108" },
493
        { PT_UNDF_109,  "DynamicRTP-Type-109" },
494
        { PT_UNDF_110,  "DynamicRTP-Type-110" },
495
        { PT_UNDF_111,  "DynamicRTP-Type-111" },
496
        { PT_UNDF_112,  "DynamicRTP-Type-112" },
497
        { PT_UNDF_113,  "DynamicRTP-Type-113" },
498
        { PT_UNDF_114,  "DynamicRTP-Type-114" },
499
        { PT_UNDF_115,  "DynamicRTP-Type-115" },
500
        { PT_UNDF_116,  "DynamicRTP-Type-116" },
501
        { PT_UNDF_117,  "DynamicRTP-Type-117" },
502
        { PT_UNDF_118,  "DynamicRTP-Type-118" },
503
        { PT_UNDF_119,  "DynamicRTP-Type-119" },
504
        { PT_UNDF_120,  "DynamicRTP-Type-120" },
505
        { PT_UNDF_121,  "DynamicRTP-Type-121" },
506
        { PT_UNDF_122,  "DynamicRTP-Type-122" },
507
        { PT_UNDF_123,  "DynamicRTP-Type-123" },
508
        { PT_UNDF_124,  "DynamicRTP-Type-124" },
509
        { PT_UNDF_125,  "DynamicRTP-Type-125" },
510
        { PT_UNDF_126,  "DynamicRTP-Type-126" },
511
        { PT_UNDF_127,  "DynamicRTP-Type-127" },
512
513
        { 0,        NULL },
514
};
515
516
value_string_ext rtp_payload_type_vals_ext = VALUE_STRING_EXT_INIT(rtp_payload_type_vals);
517
518
static const value_string rtp_payload_type_short_vals[] =
519
{
520
    { PT_PCMU,      "g711U" },
521
    { PT_1016,      "fs-1016" },
522
    { PT_G721,      "g721" },
523
    { PT_GSM,       "GSM" },
524
    { PT_G723,      "g723" },
525
    { PT_DVI4_8000, "DVI4 8k" },
526
    { PT_DVI4_16000, "DVI4 16k" },
527
    { PT_LPC,       "Exp. from Xerox PARC" },
528
    { PT_PCMA,      "g711A" },
529
    { PT_G722,      "g722" },
530
    { PT_L16_STEREO, "16-bit audio, stereo" },
531
    { PT_L16_MONO,  "16-bit audio, monaural" },
532
    { PT_QCELP,     "Qualcomm" },
533
    { PT_CN,        "CN" },
534
    { PT_MPA,       "MPEG-I/II Audio"},
535
    { PT_G728,      "g728" },
536
    { PT_DVI4_11025, "DVI4 11k" },
537
    { PT_DVI4_22050, "DVI4 22k" },
538
    { PT_G729,      "g729" },
539
    { PT_CN_OLD,    "CN(old)" },
540
    { 20,               "Unassigned" },
541
    { 21,               "Unassigned" },
542
    { 22,               "Unassigned" },
543
    { 23,               "Unassigned" },
544
    { 24,               "Unassigned" },
545
    { PT_CELB,      "CellB" },
546
    { PT_JPEG,      "JPEG" },
547
    { 27,               "Unassigned" },
548
    { PT_NV,        "NV" },
549
    { 29,               "Unassigned" },
550
    { 30,               "Unassigned" },
551
    { PT_H261,      "h261" },
552
    { PT_MPV,       "MPEG-I/II Video"},
553
    { PT_MP2T,      "MPEG-II streams"},
554
    { PT_H263,      "h263" },
555
/* 35-71     Unassigned  */
556
    { 35,               "Unassigned" },
557
    { 36,               "Unassigned" },
558
    { 37,               "Unassigned" },
559
    { 38,               "Unassigned" },
560
    { 39,               "Unassigned" },
561
    { 40,               "Unassigned" },
562
    { 41,               "Unassigned" },
563
    { 42,               "Unassigned" },
564
    { 43,               "Unassigned" },
565
    { 44,               "Unassigned" },
566
    { 45,               "Unassigned" },
567
    { 46,               "Unassigned" },
568
    { 47,               "Unassigned" },
569
    { 48,               "Unassigned" },
570
    { 49,               "Unassigned" },
571
    { 50,               "Unassigned" },
572
    { 51,               "Unassigned" },
573
    { 52,               "Unassigned" },
574
    { 53,               "Unassigned" },
575
    { 54,               "Unassigned" },
576
    { 55,               "Unassigned" },
577
    { 56,               "Unassigned" },
578
    { 57,               "Unassigned" },
579
    { 58,               "Unassigned" },
580
    { 59,               "Unassigned" },
581
    { 60,               "Unassigned" },
582
    { 61,               "Unassigned" },
583
    { 62,               "Unassigned" },
584
    { 63,               "Unassigned" },
585
    { 64,               "Unassigned" },
586
    { 65,               "Unassigned" },
587
    { 66,               "Unassigned" },
588
    { 67,               "Unassigned" },
589
    { 68,               "Unassigned" },
590
    { 69,               "Unassigned" },
591
    { 70,               "Unassigned" },
592
    { 71,               "Unassigned" },
593
/* 72-76     Reserved for RTCP conflict avoidance  - [RFC3551] */
594
    { 72,               "Reserved for RTCP conflict avoidance" },
595
    { 73,               "Reserved for RTCP conflict avoidance" },
596
    { 74,               "Reserved for RTCP conflict avoidance" },
597
    { 75,               "Reserved for RTCP conflict avoidance" },
598
    { 76,               "Reserved for RTCP conflict avoidance" },
599
/* 77-95     Unassigned, MAY be used if > 32 PT are used */
600
    { 77,               "Unassigned" },
601
    { 78,               "Unassigned" },
602
    { 79,               "Unassigned" },
603
    { 80,               "Unassigned" },
604
    { 81,               "Unassigned" },
605
    { 82,               "Unassigned" },
606
    { 83,               "Unassigned" },
607
    { 84,               "Unassigned" },
608
    { 85,               "Unassigned" },
609
    { 86,               "Unassigned" },
610
    { 87,               "Unassigned" },
611
    { 88,               "Unassigned" },
612
    { 89,               "Unassigned" },
613
    { 90,               "Unassigned" },
614
    { 91,               "Unassigned" },
615
    { 92,               "Unassigned" },
616
    { 93,               "Unassigned" },
617
    { 94,               "Unassigned" },
618
    { 95,               "Unassigned" },
619
    /* Short RTP types */
620
    { PT_UNDF_96,   "RTPType-96" },
621
    { PT_UNDF_97,   "RTPType-97" },
622
    { PT_UNDF_98,   "RTPType-98" },
623
    { PT_UNDF_99,   "RTPType-99" },
624
    { PT_UNDF_100,  "RTPType-100" },
625
    { PT_UNDF_101,  "RTPType-101" },
626
    { PT_UNDF_102,  "RTPType-102" },
627
    { PT_UNDF_103,  "RTPType-103" },
628
    { PT_UNDF_104,  "RTPType-104" },
629
    { PT_UNDF_105,  "RTPType-105" },
630
    { PT_UNDF_106,  "RTPType-106" },
631
    { PT_UNDF_107,  "RTPType-107" },
632
    { PT_UNDF_108,  "RTPType-108" },
633
    { PT_UNDF_109,  "RTPType-109" },
634
    { PT_UNDF_110,  "RTPType-110" },
635
    { PT_UNDF_111,  "RTPType-111" },
636
    { PT_UNDF_112,  "RTPType-112" },
637
    { PT_UNDF_113,  "RTPType-113" },
638
    { PT_UNDF_114,  "RTPType-114" },
639
    { PT_UNDF_115,  "RTPType-115" },
640
    { PT_UNDF_116,  "RTPType-116" },
641
    { PT_UNDF_117,  "RTPType-117" },
642
    { PT_UNDF_118,  "RTPType-118" },
643
    { PT_UNDF_119,  "RTPType-119" },
644
    { PT_UNDF_120,  "RTPType-120" },
645
    { PT_UNDF_121,  "RTPType-121" },
646
    { PT_UNDF_122,  "RTPType-122" },
647
    { PT_UNDF_123,  "RTPType-123" },
648
    { PT_UNDF_124,  "RTPType-124" },
649
    { PT_UNDF_125,  "RTPType-125" },
650
    { PT_UNDF_126,  "RTPType-126" },
651
    { PT_UNDF_127,  "RTPType-127" },
652
653
    { 0,            NULL },
654
};
655
value_string_ext rtp_payload_type_short_vals_ext = VALUE_STRING_EXT_INIT(rtp_payload_type_short_vals);
656
657
#if 0
658
static const value_string srtp_encryption_alg_vals[] =
659
{
660
    { SRTP_ENC_ALG_NULL,    "Null Encryption" },
661
    { SRTP_ENC_ALG_AES_CM,  "AES-128 Counter Mode" },
662
    { SRTP_ENC_ALG_AES_F8,  "AES-128 F8 Mode" },
663
    { 0, NULL },
664
};
665
666
static const value_string srtp_auth_alg_vals[] =
667
{
668
    { SRTP_AUTH_ALG_NONE,       "No Authentication" },
669
    { SRTP_AUTH_ALG_HMAC_SHA1,  "HMAC-SHA1" },
670
    { 0, NULL },
671
};
672
#endif
673
674
static void rtp_prompt(packet_info *pinfo _U_, char* result)
675
0
{
676
0
    unsigned payload_type = GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_rtp, RTP_DECODE_AS_PROTO_DATA));
677
678
    /* Dynamic payload range, don't expose value as it may change within conversation */
679
0
    if (payload_type > 95)
680
0
    {
681
0
        snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "RTP payload type as");
682
0
    }
683
0
    else
684
0
    {
685
0
        snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "RTP payload type %d as", payload_type);
686
0
    }
687
0
}
688
689
static void *rtp_value(packet_info *pinfo)
690
0
{
691
0
    unsigned payload_type = GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_rtp, RTP_DECODE_AS_PROTO_DATA));
692
693
0
    return GUINT_TO_POINTER(payload_type);
694
0
}
695
696
#ifdef DEBUG_CONVERSATION
697
/* Called for each entry in the rtp_dyn_payload hash table. */
698
static void
699
rtp_dyn_payload_table_foreach_func(void *key, void *value, void *user_data _U_) {
700
    unsigned pt = GPOINTER_TO_UINT(key);
701
    encoding_name_and_rate_t *encoding = (encoding_name_and_rate_t*) value;
702
703
    DPRINT2(("pt=%d", pt));
704
    if (encoding) {
705
        DPRINT2(("encoding_name=%s",
706
                encoding->encoding_name ? encoding->encoding_name : "NULL"));
707
        DPRINT2(("sample_rate=%d", encoding->sample_rate));
708
        DPRINT2(("channels=%u", encoding->channels));
709
    } else {
710
        DPRINT2(("encoding=NULL"));
711
    }
712
}
713
714
void
715
rtp_dump_dyn_payload(rtp_dyn_payload_t *rtp_dyn_payload) {
716
    DPRINT2(("rtp_dyn_payload hash table contents:"));
717
    DINDENT();
718
        if (!rtp_dyn_payload) {
719
            DPRINT2(("null pointer to rtp_dyn_payload"));
720
            DENDENT();
721
            return;
722
        }
723
        DPRINT2(("ref_count=%zu", rtp_dyn_payload->ref_count));
724
        if (!rtp_dyn_payload->table) {
725
            DPRINT2(("null rtp_dyn_payload table"));
726
            DENDENT();
727
            return;
728
        }
729
        if (g_hash_table_size(rtp_dyn_payload->table) == 0) {
730
            DPRINT2(("rtp_dyn_payload has no entries"));
731
        } else {
732
            g_hash_table_foreach(rtp_dyn_payload->table, rtp_dyn_payload_table_foreach_func, NULL);
733
        }
734
    DENDENT();
735
}
736
#endif /* DEBUG_CONVERSATION */
737
738
/* A single hash table to hold pointers to all the rtp_dyn_payload_t's we create/destroy.
739
   This is necessary because we need to g_hash_table_destroy() them, either individually or
740
   all at once at the end of the wmem file scope. Since rtp_dyn_payload_free() removes them
741
   individually, we need to remove those then; and when the file scope is over, we have a
742
   single registered callback walk this GHashTable and destroy each member as well as this
743
   GHashTable.
744
 */
745
static GHashTable *rtp_dyn_payloads;
746
747
static gboolean
748
fmtp_free(void *key, void *value, void *user_data)
749
0
{
750
0
    wmem_allocator_t *scope = (wmem_allocator_t*)user_data;
751
752
0
    wmem_free(scope, key);
753
0
    wmem_free(scope, value);
754
755
0
    return true;
756
0
}
757
758
/* the following is the GDestroyNotify function used when the individual rtp_dyn_payload_t
759
   GHashTables are destroyed */
760
static void
761
rtp_dyn_payload_value_destroy(void *data)
762
0
{
763
0
    encoding_name_and_rate_t *encoding_name_and_rate_pt = (encoding_name_and_rate_t*) data;
764
0
    wmem_free(wmem_file_scope(), encoding_name_and_rate_pt->encoding_name);
765
0
    wmem_map_foreach_remove(encoding_name_and_rate_pt->fmtp_map, fmtp_free, wmem_file_scope());
766
0
    wmem_map_destroy(encoding_name_and_rate_pt->fmtp_map, false, false);
767
0
    wmem_free(wmem_file_scope(), encoding_name_and_rate_pt);
768
0
}
769
770
/* this gets called by wmem_rtp_dyn_payload_destroy_cb */
771
static gboolean
772
rtp_dyn_payloads_table_steal_func(void *key _U_, void *value, void *user_data _U_)
773
0
{
774
0
    rtp_dyn_payload_t *rtp_dyn_payload = (rtp_dyn_payload_t *)value;
775
776
#ifdef DEBUG_CONVERSATION
777
    DPRINT(("about to steal_all and destroy the following:"));
778
    DINDENT();
779
    rtp_dump_dyn_payload(rtp_dyn_payload);
780
    DENDENT();
781
#endif
782
783
0
    if (rtp_dyn_payload->ref_count == 0) {
784
        /* this shouldn't happen */
785
0
        DPRINT(("rtp_dyn_payload cannot be free'd because it should already have been!\n"));
786
0
    }
787
0
    else if (rtp_dyn_payload->table) {
788
        /* each member was created with a wmem file scope, so there's no point in calling the
789
           destroy functions for the GHashTable entries, so we steal them instead */
790
0
        g_hash_table_steal_all(rtp_dyn_payload->table);
791
0
        g_hash_table_destroy(rtp_dyn_payload->table);
792
0
    }
793
794
0
    return true;
795
0
}
796
797
/* the following is used as the wmem callback to destroy *all* alive rtp_dyn_payload_t's,
798
   which are pointed to by the single rtp_dyn_payloads GHashTable above.
799
 */
800
static bool
801
wmem_rtp_dyn_payload_destroy_cb(wmem_allocator_t *allocator _U_, wmem_cb_event_t event _U_,
802
        void *user_data _U_)
803
0
{
804
0
    DPRINT(("destroying %u remaining rtp_dyn_payload_t's", g_hash_table_size(rtp_dyn_payloads)));
805
806
    /* each member was created with a wmem file scope, so there's no point in calling the
807
       destroy functions for the GHashTable entries, so we steal them instead */
808
0
    g_hash_table_foreach_steal(rtp_dyn_payloads, rtp_dyn_payloads_table_steal_func, NULL);
809
0
    g_hash_table_destroy(rtp_dyn_payloads);
810
0
    rtp_dyn_payloads = NULL;
811
812
    /* remove this callback? */
813
0
    return false;
814
0
}
815
816
/* the following initializes the single GHashTable - this is invoked as an init_routine,
817
   but those are called both at init and cleanup times, and the cleanup time is before
818
   wmem scope is exited, so we ignore this if rtp_dyn_payloads is not NULL.
819
 */
820
static void
821
rtp_dyn_payloads_init(void)
822
14
{
823
14
    if (rtp_dyn_payloads == NULL) {
824
14
        rtp_dyn_payloads = g_hash_table_new(NULL, NULL);
825
14
        wmem_register_callback(wmem_file_scope(), wmem_rtp_dyn_payload_destroy_cb, NULL);
826
14
    }
827
14
}
828
829
/* creates a new hashtable and sets ref_count to 1, returning the newly created object */
830
rtp_dyn_payload_t* rtp_dyn_payload_new(void)
831
785
{
832
    /* create the new entry */
833
785
    rtp_dyn_payload_t * rtp_dyn_payload = wmem_new(wmem_file_scope(), rtp_dyn_payload_t);
834
785
    rtp_dyn_payload->table = g_hash_table_new_full(NULL, NULL, NULL, rtp_dyn_payload_value_destroy);
835
785
    rtp_dyn_payload->ref_count = 1;
836
837
    /* now put it in our single rtp_dyn_payloads GHashTable */
838
785
    g_hash_table_insert(rtp_dyn_payloads, rtp_dyn_payload, rtp_dyn_payload);
839
840
785
    return rtp_dyn_payload;
841
785
}
842
843
/* Creates a copy of the given dynamic payload information. */
844
rtp_dyn_payload_t* rtp_dyn_payload_dup(rtp_dyn_payload_t *rtp_dyn_payload)
845
475
{
846
475
    rtp_dyn_payload_t *rtp_dyn_payload2 = rtp_dyn_payload_new();
847
475
    GHashTableIter iter;
848
475
    void *key, *value;
849
850
475
    g_hash_table_iter_init(&iter, rtp_dyn_payload->table);
851
475
    while (g_hash_table_iter_next(&iter, &key, &value)) {
852
0
        const unsigned pt = GPOINTER_TO_UINT(key);
853
0
        encoding_name_and_rate_t *encoding_name_and_rate_pt =
854
0
            (encoding_name_and_rate_t *)value;
855
856
0
        rtp_dyn_payload_insert_full(rtp_dyn_payload2, pt,
857
0
                encoding_name_and_rate_pt->encoding_name,
858
0
                encoding_name_and_rate_pt->sample_rate,
859
0
                encoding_name_and_rate_pt->channels,
860
0
                encoding_name_and_rate_pt->fmtp_map);
861
862
0
    }
863
864
475
    return rtp_dyn_payload2;
865
475
}
866
867
static rtp_dyn_payload_t*
868
rtp_dyn_payload_ref(rtp_dyn_payload_t *rtp_dyn_payload)
869
0
{
870
0
    if (rtp_dyn_payload) {
871
0
        rtp_dyn_payload->ref_count++;
872
0
    }
873
0
    return rtp_dyn_payload;
874
0
}
875
876
static void
877
rtp_dyn_payload_add_fmtp_int(void *key, void *value, void *user_data)
878
0
{
879
0
    wmem_map_t *fmtp_map = (wmem_map_t*)user_data;
880
0
    const char *k = (const char*)key;
881
0
    const char *v = (const char*)value;
882
883
0
    wmem_map_insert(fmtp_map, wmem_strdup(wmem_file_scope(), k), wmem_strdup(wmem_file_scope(), v));
884
0
}
885
886
/* Inserts the given payload type key, for the encoding name and sample rate,
887
   into the hash table. Copy all the format parameters in the map given into
888
   the format parameter map for the new entry.
889
   This makes copies of the encoding name and the format parameters, scoped to
890
   the life of the capture file or sooner if rtp_dyn_payload_free is called.
891
 */
892
void
893
rtp_dyn_payload_insert_full(rtp_dyn_payload_t *rtp_dyn_payload,
894
                       const unsigned pt,
895
                       const char* encoding_name,
896
                       const int sample_rate,
897
                       const unsigned channels,
898
                       wmem_map_t *fmtp_map)
899
0
{
900
0
    if (rtp_dyn_payload && rtp_dyn_payload->table) {
901
0
        encoding_name_and_rate_t *encoding_name_and_rate_pt = (encoding_name_and_rate_t*)g_hash_table_lookup(rtp_dyn_payload->table,
902
0
                             GUINT_TO_POINTER(pt));
903
0
        if (!encoding_name_and_rate_pt) {
904
0
            encoding_name_and_rate_pt = wmem_new(wmem_file_scope(), encoding_name_and_rate_t);
905
            // XXX - Do we really need to create these maps on later passes?
906
0
            encoding_name_and_rate_pt->fmtp_map = wmem_map_new(wmem_file_scope(), wmem_str_hash, g_str_equal);
907
0
            g_hash_table_insert(rtp_dyn_payload->table, GUINT_TO_POINTER(pt), encoding_name_and_rate_pt);
908
0
        }
909
0
        encoding_name_and_rate_pt->encoding_name = wmem_strdup(wmem_file_scope(), encoding_name);
910
0
        encoding_name_and_rate_pt->sample_rate = sample_rate;
911
0
        encoding_name_and_rate_pt->channels = channels;
912
0
        if (fmtp_map) {
913
0
            wmem_map_foreach(fmtp_map, rtp_dyn_payload_add_fmtp_int, encoding_name_and_rate_pt->fmtp_map);
914
0
        }
915
0
    }
916
0
}
917
918
/* Inserts the given payload type key, for the encoding name and sample rate,
919
   into the hash table.
920
   This makes copies of the encoding name, scoped to the life of the capture
921
   file or sooner if rtp_dyn_payload_free is called. */
922
void
923
rtp_dyn_payload_insert(rtp_dyn_payload_t *rtp_dyn_payload,
924
                       const unsigned pt,
925
                       const char* encoding_name,
926
                       const int sample_rate,
927
                       const unsigned channels)
928
0
{
929
0
    rtp_dyn_payload_insert_full(rtp_dyn_payload, pt, encoding_name, sample_rate, channels, NULL);
930
0
}
931
932
/* Adds the given format parameter to the fmtp_map for the given payload type
933
   in the RTP dynamic payload hashtable, if that payload type has been
934
   inserted with rtp_dyn_payload_insert. The format parameter name and value
935
   are copied, with scope the lifetime of the capture file.
936
 */
937
void
938
rtp_dyn_payload_add_fmtp(rtp_dyn_payload_t *rtp_dyn_payload,
939
                         const unsigned pt,
940
                         const char *key, const char *value)
941
0
{
942
0
    if (rtp_dyn_payload && rtp_dyn_payload->table) {
943
0
        encoding_name_and_rate_t *encoding_name_and_rate_pt = (encoding_name_and_rate_t*)g_hash_table_lookup(rtp_dyn_payload->table,
944
0
                             GUINT_TO_POINTER(pt));
945
946
0
        if (!encoding_name_and_rate_pt) {
947
0
            rtp_dyn_payload_insert(rtp_dyn_payload, pt, "Unknown", 0, 1);
948
0
            encoding_name_and_rate_pt = (encoding_name_and_rate_t*)g_hash_table_lookup(rtp_dyn_payload->table, GUINT_TO_POINTER(pt));
949
0
        }
950
951
0
        rtp_dyn_payload_add_fmtp_int((void*)key, (void*)value, encoding_name_and_rate_pt->fmtp_map);
952
0
    }
953
0
}
954
955
/* Replaces the given payload type key in the hash table, with the encoding name and sample rate.
956
   This makes copies of the encoding name, scoped to the life of the capture file or sooner if
957
   rtp_dyn_payload_free is called. */
958
/* Not used anymore
959
void
960
rtp_dyn_payload_replace(rtp_dyn_payload_t *rtp_dyn_payload,
961
                        const unsigned pt,
962
                        const char* encoding_name,
963
                        const int sample_rate)
964
{
965
    if (rtp_dyn_payload && rtp_dyn_payload->table) {
966
        encoding_name_and_rate_t *encoding_name_and_rate_pt =
967
                    wmem_new(wmem_file_scope(), encoding_name_and_rate_t);
968
        encoding_name_and_rate_pt->encoding_name = wmem_strdup(wmem_file_scope(), encoding_name);
969
        encoding_name_and_rate_pt->sample_rate = sample_rate;
970
        g_hash_table_replace(rtp_dyn_payload->table, GUINT_TO_POINTER(pt), encoding_name_and_rate_pt);
971
    }
972
}
973
*/
974
975
/* removes the given payload type */
976
/* Not used anymore
977
bool
978
rtp_dyn_payload_remove(rtp_dyn_payload_t *rtp_dyn_payload, const unsigned pt)
979
{
980
    return (rtp_dyn_payload && rtp_dyn_payload->table &&
981
            g_hash_table_remove(rtp_dyn_payload->table, GUINT_TO_POINTER(pt)));
982
}
983
*/
984
985
/* retrieves the encoding name for the given payload type */
986
const char*
987
rtp_dyn_payload_get_name(rtp_dyn_payload_t *rtp_dyn_payload, const unsigned pt)
988
0
{
989
0
    encoding_name_and_rate_t *encoding_name_and_rate_pt;
990
991
0
    if (!rtp_dyn_payload || !rtp_dyn_payload->table) return NULL;
992
993
0
    encoding_name_and_rate_pt = (encoding_name_and_rate_t*)g_hash_table_lookup(rtp_dyn_payload->table,
994
0
                                                                               GUINT_TO_POINTER(pt));
995
996
0
    return (encoding_name_and_rate_pt ? encoding_name_and_rate_pt->encoding_name : NULL);
997
0
}
998
999
/*
1000
   Retrieves the encoding name, sample rate, and format parameters map for the
1001
   given payload type. The encoding string pointed to is only valid until
1002
   the entry is replaced, removed, or the hash table is destroyed, so duplicate
1003
   it if you need it long. Each of the three output parameters are optional and
1004
   can be NULL.
1005
 */
1006
bool
1007
rtp_dyn_payload_get_full(rtp_dyn_payload_t *rtp_dyn_payload, const unsigned pt,
1008
                         const char **encoding_name, int *sample_rate,
1009
                         unsigned *channels, wmem_map_t **fmtp_map)
1010
32.3k
{
1011
32.3k
    encoding_name_and_rate_t *encoding_name_and_rate_pt;
1012
32.3k
    if (encoding_name) {
1013
32.3k
        *encoding_name = NULL;
1014
32.3k
    }
1015
32.3k
    if (sample_rate) {
1016
32.3k
        *sample_rate = 0;
1017
32.3k
    }
1018
32.3k
    if (channels) {
1019
32.3k
        *channels = 0;
1020
32.3k
    }
1021
32.3k
    if (fmtp_map) {
1022
32.3k
        *fmtp_map = NULL;
1023
32.3k
    }
1024
1025
32.3k
    if (!rtp_dyn_payload || !rtp_dyn_payload->table) return false;
1026
1027
32.3k
    encoding_name_and_rate_pt = (encoding_name_and_rate_t*)g_hash_table_lookup(rtp_dyn_payload->table,
1028
32.3k
                                                                               GUINT_TO_POINTER(pt));
1029
1030
32.3k
    if (encoding_name_and_rate_pt) {
1031
0
        if (encoding_name) {
1032
0
            *encoding_name = encoding_name_and_rate_pt->encoding_name;
1033
0
        }
1034
0
        if (sample_rate) {
1035
0
            *sample_rate = encoding_name_and_rate_pt->sample_rate;
1036
0
        }
1037
0
        if (channels) {
1038
0
            *channels = encoding_name_and_rate_pt->channels;
1039
0
        }
1040
0
        if (fmtp_map) {
1041
0
            *fmtp_map = encoding_name_and_rate_pt->fmtp_map;
1042
0
        }
1043
0
    }
1044
1045
32.3k
    return (encoding_name_and_rate_pt != NULL);
1046
32.3k
}
1047
1048
/* Free's and destroys the dyn_payload hash table; internally this decrements the ref_count
1049
   and only free's it if the ref_count == 0. */
1050
void
1051
rtp_dyn_payload_free(rtp_dyn_payload_t *rtp_dyn_payload)
1052
885
{
1053
885
    if (!rtp_dyn_payload) return;
1054
1055
782
    if (rtp_dyn_payload->ref_count > 0)
1056
782
        --(rtp_dyn_payload->ref_count);
1057
1058
782
    if (rtp_dyn_payload->ref_count == 0) {
1059
1060
#ifdef DEBUG_CONVERSATION
1061
        DPRINT(("free'ing the following rtp_dyn_payload:"));
1062
        DINDENT();
1063
        rtp_dump_dyn_payload(rtp_dyn_payload);
1064
        DENDENT();
1065
#endif
1066
1067
        /* remove it from the single rtp_dyn_payloads GHashTable */
1068
782
        if (!g_hash_table_remove(rtp_dyn_payloads, rtp_dyn_payload)) {
1069
0
            DPRINT(("rtp_dyn_payload not found in rtp_dyn_payloads table to remove!"));
1070
0
        }
1071
1072
        /* destroy the table GHashTable in it - this automatically deletes the
1073
           members too, because we used destroy function callbacks */
1074
782
        if (rtp_dyn_payload->table)
1075
782
            g_hash_table_destroy(rtp_dyn_payload->table);
1076
1077
        /* free the object itself */
1078
782
        wmem_free(wmem_file_scope(), rtp_dyn_payload);
1079
782
    }
1080
782
}
1081
1082
void
1083
bluetooth_add_address(packet_info *pinfo, address *addr, uint32_t stream_number,
1084
         const char *setup_method, uint32_t setup_frame_number,
1085
         uint32_t media_types, void *data)
1086
103
{
1087
103
    address null_addr;
1088
103
    conversation_t* p_conv;
1089
103
    struct _rtp_conversation_info *p_conv_data = NULL;
1090
    /*
1091
     * If this isn't the first time this packet has been processed,
1092
     * we've already done this work, so we don't need to do it
1093
     * again.
1094
     */
1095
103
    if ((pinfo->fd->visited) || (rtp_handle == NULL))
1096
0
    {
1097
0
        return;
1098
0
    }
1099
1100
103
    clear_address(&null_addr);
1101
1102
    /*
1103
     * Check if the ip address and port combination is not
1104
     * already registered as a conversation.
1105
     */
1106
103
    p_conv = find_conversation(setup_frame_number, addr, &null_addr, CONVERSATION_BLUETOOTH, stream_number, stream_number,
1107
103
                   NO_ADDR_B | NO_PORT_B);
1108
1109
    /*
1110
     * If not, create a new conversation.
1111
     */
1112
103
    if (!p_conv || p_conv->setup_frame != setup_frame_number) {
1113
40
        p_conv = conversation_new(setup_frame_number, addr, &null_addr, CONVERSATION_BLUETOOTH, stream_number, stream_number,
1114
40
                   NO_ADDR2 | NO_PORT2);
1115
40
    }
1116
1117
    /* Set dissector */
1118
103
    conversation_set_dissector(p_conv, rtp_handle);
1119
1120
    /*
1121
     * Check if the conversation has data associated with it.
1122
     */
1123
103
    p_conv_data = (struct _rtp_conversation_info *)conversation_get_proto_data(p_conv, proto_rtp);
1124
1125
    /*
1126
     * If not, add a new data item.
1127
     */
1128
103
    if (! p_conv_data) {
1129
        /* Create conversation data */
1130
40
        p_conv_data = wmem_new0(wmem_file_scope(), struct _rtp_conversation_info);
1131
1132
40
        p_conv_data->ssrc_number_space = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
1133
40
        p_conv_data->rtp_conv_info = wmem_new(wmem_file_scope(), rtp_private_conv_info);
1134
40
        p_conv_data->rtp_conv_info->multisegment_pdus = wmem_tree_new(wmem_file_scope());
1135
40
        conversation_add_proto_data(p_conv, proto_rtp, p_conv_data);
1136
1137
40
        if (media_types == RTP_MEDIA_AUDIO) {
1138
40
            p_conv_data->bta2dp_info = (bta2dp_codec_info_t *) wmem_memdup(wmem_file_scope(), data, sizeof(bta2dp_codec_info_t));
1139
40
        } else if (media_types == RTP_MEDIA_VIDEO) {
1140
0
            p_conv_data->btvdp_info = (btvdp_codec_info_t *) wmem_memdup(wmem_file_scope(), data, sizeof(btvdp_codec_info_t));
1141
0
        }
1142
40
    }
1143
1144
    /*
1145
     * Update the conversation data.
1146
     */
1147
    /* Free the hash if already exists */
1148
103
    rtp_dyn_payload_free(p_conv_data->rtp_dyn_payload);
1149
1150
103
    (void) g_strlcpy(p_conv_data->method, setup_method, MAX_RTP_SETUP_METHOD_SIZE+1);
1151
103
    p_conv_data->frame_number = setup_frame_number;
1152
103
    p_conv_data->media_types = media_types;
1153
103
    p_conv_data->rtp_dyn_payload = NULL;
1154
103
    p_conv_data->srtp_info = NULL;
1155
103
}
1156
static void
1157
rtp_add_setup_info_if_no_duplicate(sdp_setup_info_t *setup_info, wmem_array_t *sdp_conv_info_list)
1158
0
{
1159
0
    sdp_setup_info_t *stored_setup_info;
1160
0
    unsigned i;
1161
1162
0
    for (i = 0; i < wmem_array_get_count(sdp_conv_info_list); i++) {
1163
0
        stored_setup_info = (sdp_setup_info_t *)wmem_array_index(sdp_conv_info_list, i);
1164
1165
        /* Check if we have the call id already */
1166
0
        if ((stored_setup_info->hf_type == SDP_TRACE_ID_HF_TYPE_STR) && (setup_info->hf_type == SDP_TRACE_ID_HF_TYPE_STR)) {
1167
0
            if (strcmp(stored_setup_info->trace_id.str, setup_info->trace_id.str) == 0) {
1168
0
                return; /* Do not store the call id */
1169
0
            }
1170
0
        } else if ((stored_setup_info->hf_type == SDP_TRACE_ID_HF_TYPE_UINT32) && (setup_info->hf_type == SDP_TRACE_ID_HF_TYPE_UINT32)) {
1171
0
            if (stored_setup_info->trace_id.num == setup_info->trace_id.num) {
1172
0
                return; /* Do not store the call id */
1173
0
            }
1174
0
        }
1175
0
    }
1176
1177
0
    wmem_array_append(sdp_conv_info_list, setup_info, 1);
1178
1179
0
}
1180
/* Set up an SRTP conversation */
1181
void
1182
srtp_add_address(packet_info *pinfo, const port_type ptype, address *addr, int port, int other_port,
1183
         const char *setup_method, uint32_t setup_frame_number,
1184
         uint32_t media_types _U_, rtp_dyn_payload_t *rtp_dyn_payload,
1185
         struct srtp_info *srtp_info, sdp_setup_info_t *setup_info)
1186
100
{
1187
100
    address null_addr;
1188
100
    conversation_t* p_conv;
1189
100
    struct _rtp_conversation_info *p_conv_data;
1190
100
    wmem_array_t *rtp_conv_info_list = NULL;
1191
100
    wmem_map_t *ssrc_number_space = NULL;
1192
1193
    /*
1194
     * If this isn't the first time this packet has been processed,
1195
     * we've already done this work, so we don't need to do it
1196
     * again.
1197
     */
1198
100
    if ((pinfo->fd->visited) || (rtp_handle == NULL) || (rtp_rfc4571_handle == NULL))
1199
0
    {
1200
0
        return;
1201
0
    }
1202
1203
100
    DPRINT(("#%u: %srtp_add_address(%d, %s, %u, %u, %s, %u)",
1204
100
            pinfo->num, (srtp_info)?"s":"", ptype, address_to_str(pinfo->pool, addr), port,
1205
100
            other_port, setup_method, setup_frame_number));
1206
100
    DINDENT();
1207
1208
100
    clear_address(&null_addr);
1209
1210
    /*
1211
     * Check if the ip address and port combination is not
1212
     * already registered as a conversation.
1213
     */
1214
100
    p_conv = find_conversation_strat_xtd(pinfo, setup_frame_number, addr, &null_addr, conversation_pt_to_conversation_type(ptype), port, other_port,
1215
100
                   NO_ADDR_B | (!other_port ? NO_PORT_B : 0));
1216
1217
100
    if (p_conv) {
1218
        /*
1219
         * Check if the conversation has data associated with it.
1220
         * Sometimes there are multiple setup messages for the same
1221
         * conversation, and it's worth copying over some of our
1222
         * internal data to the new conversation. The extended sequence
1223
         * number and timestamp cycle information is per-SSRC, and it
1224
         * doesn't hurt (and can definitely help) to ensure that the
1225
         * new conversation uses the same extended cycles as the old one.
1226
         * XXX: It's not actually clear that we really need to create
1227
         * extra conversations for each setup frame, because we save the
1228
         * relevant information to per-packet data for the subsequent passes.
1229
         */
1230
59
        p_conv_data = (struct _rtp_conversation_info *)conversation_get_proto_data(p_conv, proto_rtp);
1231
59
        if (p_conv_data) {
1232
59
            rtp_conv_info_list = p_conv_data->rtp_sdp_setup_info_list;
1233
59
            ssrc_number_space = p_conv_data->ssrc_number_space;
1234
59
        }
1235
59
    }
1236
1237
100
    DENDENT();
1238
100
    DPRINT(("did %sfind conversation", p_conv?"":"NOT "));
1239
1240
    /*
1241
     * If not, create a new conversation.
1242
     */
1243
100
    if (!p_conv || p_conv->setup_frame != setup_frame_number) {
1244
        /* XXX - If setup_frame_number < pinfo->num, creating this conversation
1245
         * can mean that the dissection is different on later passes.
1246
         */
1247
72
        p_conv = conversation_new_strat_xtd(pinfo, setup_frame_number, addr, &null_addr, conversation_pt_to_conversation_type(ptype),
1248
72
                                  (uint32_t)port, (uint32_t)other_port,
1249
72
                      NO_ADDR2 | (!other_port ? NO_PORT2 : 0));
1250
72
    }
1251
1252
    /* Set dissector */
1253
100
    if (ptype == PT_UDP) {
1254
        /* For RFC 5761 multiplexing, go ahead and create/update [S]RTCP
1255
         * info for the conversation, since this dissector will pass RTCP PTs
1256
         * to the RTCP dissector anyway.
1257
         * XXX: We only do this on UDP, as RFC 4571 specifies RTP and RTCP on
1258
         * different ports, but the RTCP dissector (like SDP) doesn't support
1259
         * RFC 4571 currently anyway.
1260
         */
1261
100
        srtcp_add_address(pinfo, addr, port, other_port, setup_method, setup_frame_number, srtp_info);
1262
        /* Set the dissector afterwards, since RTCP will set the conversation
1263
         * to its dissector, but packets should go to RTP first.
1264
         */
1265
100
        conversation_set_dissector(p_conv, rtp_handle);
1266
100
    } else if (ptype == PT_TCP) {
1267
0
        conversation_set_dissector(p_conv, rtp_rfc4571_handle);
1268
0
    } else {
1269
0
        DISSECTOR_ASSERT(false);
1270
0
    }
1271
1272
    /*
1273
     * Check if the conversation has data associated with it.
1274
     */
1275
100
    p_conv_data = (struct _rtp_conversation_info *)conversation_get_proto_data(p_conv, proto_rtp);
1276
1277
    /*
1278
     * If not, add a new data item.
1279
     */
1280
100
    if (! p_conv_data) {
1281
72
        DPRINT(("creating new conversation data"));
1282
1283
        /* Create conversation data */
1284
72
        p_conv_data = wmem_new0(wmem_file_scope(), struct _rtp_conversation_info);
1285
1286
72
        p_conv_data->ssrc_number_space = ssrc_number_space ? ssrc_number_space : wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
1287
72
        p_conv_data->rtp_conv_info = wmem_new(wmem_file_scope(), rtp_private_conv_info);
1288
72
        p_conv_data->rtp_conv_info->multisegment_pdus = wmem_tree_new(wmem_file_scope());
1289
72
        DINDENT();
1290
72
        conversation_add_proto_data(p_conv, proto_rtp, p_conv_data);
1291
72
        DENDENT();
1292
72
    }
1293
#ifdef DEBUG_CONVERSATION
1294
    else {
1295
        DPRINT(("conversation already exists"));
1296
    }
1297
#endif
1298
1299
    /*
1300
     * Update the conversation data.
1301
     */
1302
    /* Free the hash if a different one already exists */
1303
100
    if (p_conv_data->rtp_dyn_payload != rtp_dyn_payload) {
1304
0
        rtp_dyn_payload_free(p_conv_data->rtp_dyn_payload);
1305
0
        p_conv_data->rtp_dyn_payload = rtp_dyn_payload_ref(rtp_dyn_payload);
1306
100
    } else {
1307
100
        DPRINT(("passed-in rtp_dyn_payload is the same as in the conversation"));
1308
100
    }
1309
1310
100
    (void) g_strlcpy(p_conv_data->method, setup_method, MAX_RTP_SETUP_METHOD_SIZE+1);
1311
100
    p_conv_data->frame_number = setup_frame_number;
1312
100
    p_conv_data->media_types = media_types;
1313
100
    p_conv_data->srtp_info = srtp_info;
1314
100
    p_conv_data->bta2dp_info = NULL;
1315
100
    p_conv_data->btvdp_info = NULL;
1316
1317
    /* If we had a sdp setup info list put it back in the potentially new conversation*/
1318
100
    p_conv_data->rtp_sdp_setup_info_list = rtp_conv_info_list;
1319
100
    if (setup_info) {
1320
        /* If we have new setup info add it to the list*/
1321
0
        if (p_conv_data->rtp_sdp_setup_info_list) {
1322
            /* Add info to the SDP conversation */
1323
0
            rtp_add_setup_info_if_no_duplicate(setup_info, p_conv_data->rtp_sdp_setup_info_list);
1324
0
        } else {
1325
0
            p_conv_data->rtp_sdp_setup_info_list = wmem_array_new(wmem_file_scope(), sizeof(sdp_setup_info_t));
1326
0
            wmem_array_append(p_conv_data->rtp_sdp_setup_info_list, setup_info, 1);
1327
0
        }
1328
0
    }
1329
100
    if (p_conv_data->rtp_sdp_setup_info_list) {
1330
        /* Convey the collected information to SDP */
1331
        /* This is pinfo->pool because this function might not have been called
1332
         * by SDP, in which case we don't need to save it, and SDP might have
1333
         * a file scoped transport info to store it in (using the Offer/Answer
1334
         * model, e.g. with SIP.)
1335
         */
1336
0
        p_add_proto_data(pinfo->pool, pinfo, proto_sdp, 0, p_conv_data->rtp_sdp_setup_info_list);
1337
0
    }
1338
1339
100
}
1340
1341
/* Set up an RTP conversation */
1342
void
1343
rtp_add_address(packet_info *pinfo, const port_type ptype, address *addr, int port, int other_port,
1344
        const char *setup_method, uint32_t setup_frame_number,
1345
        uint32_t media_types, rtp_dyn_payload_t *rtp_dyn_payload)
1346
92
{
1347
92
    srtp_add_address(pinfo, ptype, addr, port, other_port, setup_method, setup_frame_number, media_types, rtp_dyn_payload, NULL, NULL);
1348
92
}
1349
1350
static bool
1351
dissect_rtp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
1352
0
{
1353
0
    uint8_t      octet1, octet2;
1354
0
    unsigned int version, payload_type;
1355
0
    unsigned int offset = 0;
1356
0
    int          padding_count;
1357
1358
0
    if (tvb_captured_length_remaining(tvb, offset) < 2) {
1359
0
        return false;
1360
0
    }
1361
1362
    /* Get the fields in the first octet */
1363
0
    octet1 = tvb_get_uint8( tvb, offset );
1364
0
    version = RTP_VERSION( octet1 );
1365
1366
    /* XXX: Why are we calling these dissectors from the *heuristic*
1367
     * RTP dissector? These almost all have their own heuristic dissector,
1368
     * enabled by default (unlike RTP, which has a much less accurate
1369
     * heuristic.) We should just reject and let the protocols' own heuristic
1370
     * dissectors handle this.
1371
     */
1372
0
    if (version == 0) {
1373
0
        if (!(tvb_memeql(tvb, 4, (const uint8_t*)"ZRTP", 4)))
1374
0
        {
1375
0
            call_dissector_only(zrtp_handle, tvb, pinfo, tree, NULL);
1376
0
            return true;
1377
0
        } else {
1378
0
            switch (global_rtp_version0_type) {
1379
1380
            /*
1381
             * The two STUN dissectors return 0 if the packet doesn't appear
1382
             * to be a STUN packet and the number of bytes dissected if
1383
             * it does.  Just call that and test whether the return value
1384
             * is != 0 or not.
1385
             */
1386
0
            case RTP0_STUN:
1387
0
                return call_dissector_only(stun_handle, tvb, pinfo, tree, NULL) != 0;
1388
0
            case RTP0_CLASSICSTUN:
1389
0
                return call_dissector_only(classicstun_handle, tvb, pinfo, tree, NULL) != 0;
1390
1391
0
            case RTP0_T38:
1392
                /* XXX: Should really be calling a heuristic dissector for T38 ??? */
1393
0
                call_dissector_only(t38_handle, tvb, pinfo, tree, NULL);
1394
0
                return true;
1395
1396
0
            case RTP0_SPRT:
1397
                /* XXX: Should really be calling a heuristic dissector for SPRT ??? */
1398
0
                call_dissector_only(sprt_handle, tvb, pinfo, tree, NULL);
1399
0
                return true;
1400
1401
0
            case RTP0_INVALID:
1402
0
            case RTP0_RFC7983:
1403
0
            default:
1404
0
                return false; /* Unknown or unsupported version */
1405
0
            }
1406
0
        }
1407
0
    } else if (version != 2) {
1408
        /* Unknown or unsupported version */
1409
0
        return false;
1410
0
    }
1411
1412
0
    octet2 = tvb_get_uint8( tvb, offset + 1 );
1413
0
    payload_type = RTP_PAYLOAD_TYPE( octet2 );
1414
1415
0
    if (payload_type >= 72 && payload_type <= 76) {
1416
        /* XXX: This range is definitely excluded by RFCs 3550, 3551.
1417
         * There's an argument, per RFC 5761, for expanding the
1418
         * excluded range to [FIRST_RTCP_CONFLICT_PAYLOAD_TYPE,
1419
         * LAST_RTCP_CONFLICT_PAYLOAD_TYPE] in the heuristic dissector,
1420
         * leaving those values only when specified by other means
1421
         * (SDP, Decode As, etc.)
1422
         */
1423
0
        return false;
1424
0
    }
1425
1426
    /* Skip fixed header */
1427
0
    offset += 12;
1428
1429
0
    offset += 4 * RTP_CSRC_COUNT( octet1 );
1430
0
    if (RTP_EXTENSION( octet1 )) {
1431
0
        if (tvb_captured_length_remaining(tvb, offset) < 4) {
1432
0
            return false;
1433
0
        }
1434
0
        offset += 4 + 4*tvb_get_uint16(tvb, offset+2, ENC_BIG_ENDIAN);
1435
0
    }
1436
0
    if (tvb_reported_length(tvb) < offset) {
1437
0
        return false;
1438
0
    }
1439
0
    if (RTP_PADDING( octet1 )) {
1440
0
        if (tvb_captured_length(tvb) == tvb_reported_length(tvb)) {
1441
            /* We can test the padding if the last octet is present. */
1442
0
            padding_count = tvb_get_uint8(tvb, tvb_reported_length(tvb) - 1);
1443
0
            if (tvb_reported_length_remaining(tvb, offset) < padding_count ||
1444
0
                    padding_count == 0) {
1445
0
                return false;
1446
0
            }
1447
0
        }
1448
0
    }
1449
1450
    /* Create a conversation in case none exists so as to allow reassembly code to work */
1451
0
    if (!find_conversation_strat_xtd(pinfo, pinfo->num, &pinfo->net_dst, &pinfo->net_src, conversation_pt_to_conversation_type(pinfo->ptype),
1452
0
                           pinfo->destport, pinfo->srcport, NO_ADDR_B)) {
1453
0
        conversation_t *p_conv;
1454
0
        struct _rtp_conversation_info *p_conv_data;
1455
0
        p_conv = conversation_new_strat_xtd(pinfo, pinfo->num, &pinfo->net_dst, &pinfo->net_src, conversation_pt_to_conversation_type(pinfo->ptype),
1456
0
                                  pinfo->destport, pinfo->srcport, NO_ADDR2);
1457
0
        p_conv_data = (struct _rtp_conversation_info *)conversation_get_proto_data(p_conv, proto_rtp);
1458
0
        if (! p_conv_data) {
1459
            /* Create conversation data */
1460
0
            p_conv_data = wmem_new0(wmem_file_scope(), struct _rtp_conversation_info);
1461
0
            p_conv_data->ssrc_number_space = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
1462
0
            p_conv_data->rtp_conv_info = wmem_new(wmem_file_scope(), rtp_private_conv_info);
1463
0
            p_conv_data->rtp_conv_info->multisegment_pdus = wmem_tree_new(wmem_file_scope());
1464
0
            conversation_add_proto_data(p_conv, proto_rtp, p_conv_data);
1465
0
        }
1466
0
        (void) g_strlcpy(p_conv_data->method, "HEUR RTP", MAX_RTP_SETUP_METHOD_SIZE+1);
1467
0
        p_conv_data->frame_number = pinfo->num;
1468
0
        p_conv_data->media_types = 0;
1469
0
        p_conv_data->srtp_info = NULL;
1470
0
        p_conv_data->bta2dp_info = NULL;
1471
0
        p_conv_data->btvdp_info = NULL;
1472
0
    }
1473
0
    dissect_rtp( tvb, pinfo, tree, data );
1474
0
    return true;
1475
0
}
1476
1477
/*
1478
 * Process the payload of the RTP packet, hand it to the subdissector
1479
 */
1480
static void
1481
process_rtp_payload(tvbuff_t *newtvb, packet_info *pinfo, proto_tree *tree,
1482
            proto_tree *rtp_tree, unsigned int payload_type,
1483
            struct _rtp_info *rtp_info)
1484
4
{
1485
4
    struct _rtp_packet_info *p_packet_data;
1486
4
    int payload_len;
1487
4
    struct srtp_info *srtp_info;
1488
4
    int offset = 0;
1489
4
    proto_item *rtp_data;
1490
1491
4
    payload_len = tvb_captured_length_remaining(newtvb, offset);
1492
1493
    /* first check if this is added as an SRTP stream - if so, don't try to dissector the payload data for now */
1494
4
    p_packet_data = (struct _rtp_packet_info *)p_get_proto_data(wmem_file_scope(), pinfo, proto_rtp, RTP_CONVERSATION_PROTO_DATA);
1495
4
    if (p_packet_data && p_packet_data->srtp_info) {
1496
0
        srtp_info = p_packet_data->srtp_info;
1497
0
        payload_len -= srtp_info->mki_len + srtp_info->auth_tag_len;
1498
#if 0
1499
#error Currently the srtp_info structure contains no cipher data, see packet-sdp.c adding dummy_srtp_info structure
1500
        if (p_conv_data->srtp_info->encryption_algorithm == SRTP_ENC_ALG_NULL) {
1501
            if (rtp_tree)
1502
                proto_tree_add_item(rtp_tree, hf_srtp_null_encrypted_payload, newtvb, offset, payload_len, ENC_NA);
1503
        }
1504
        else
1505
#endif
1506
0
        {
1507
0
            if (rtp_tree)
1508
0
                proto_tree_add_item(rtp_tree, hf_srtp_encrypted_payload, newtvb, offset, payload_len, ENC_NA);
1509
0
        }
1510
0
        offset += payload_len;
1511
1512
0
        if (srtp_info->mki_len) {
1513
0
            proto_tree_add_item(rtp_tree, hf_srtp_mki, newtvb, offset, srtp_info->mki_len, ENC_NA);
1514
0
            offset += srtp_info->mki_len;
1515
0
        }
1516
1517
0
        if (srtp_info->auth_tag_len) {
1518
0
            proto_tree_add_item(rtp_tree, hf_srtp_auth_tag, newtvb, offset, srtp_info->auth_tag_len, ENC_NA);
1519
            /*offset += srtp_info->auth_tag_len;*/
1520
0
        }
1521
0
        return;
1522
1523
4
    } if (p_packet_data && p_packet_data->bta2dp_info) {
1524
0
        tvbuff_t  *nexttvb;
1525
0
        int        suboffset = 0;
1526
1527
0
        if (p_packet_data->bta2dp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
1528
0
            nexttvb = tvb_new_subset_length(newtvb, 0, 1);
1529
0
             call_dissector(bta2dp_content_protection_header_scms_t, nexttvb, pinfo, tree);
1530
0
            suboffset = 1;
1531
0
        }
1532
1533
0
        nexttvb = tvb_new_subset_remaining(newtvb, suboffset);
1534
0
        if (p_packet_data->bta2dp_info->codec_dissector)
1535
0
            call_dissector_with_data(p_packet_data->bta2dp_info->codec_dissector, nexttvb, pinfo, tree, p_packet_data->bta2dp_info);
1536
0
        else
1537
0
            call_data_dissector(nexttvb, pinfo, tree);
1538
1539
0
        return;
1540
1541
4
    } if (p_packet_data && p_packet_data->btvdp_info) {
1542
0
        tvbuff_t  *nexttvb;
1543
0
        int        suboffset = 0;
1544
1545
0
        if (p_packet_data->btvdp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
1546
0
            nexttvb = tvb_new_subset_length(newtvb, 0, 1);
1547
0
            call_dissector(btvdp_content_protection_header_scms_t, nexttvb, pinfo, tree);
1548
0
            suboffset = 1;
1549
0
        }
1550
1551
0
        nexttvb = tvb_new_subset_remaining(newtvb, suboffset);
1552
0
        if (p_packet_data->btvdp_info->codec_dissector)
1553
0
            call_dissector_with_data(p_packet_data->btvdp_info->codec_dissector, nexttvb, pinfo, tree, p_packet_data->btvdp_info);
1554
0
        else
1555
0
            call_data_dissector(nexttvb, pinfo, tree);
1556
1557
0
        return;
1558
0
    }
1559
1560
4
    rtp_data = proto_tree_add_item(rtp_tree, hf_rtp_data, newtvb, 0, -1, ENC_NA);
1561
1562
    /* We have checked for !p_conv_data->bta2dp_info && !p_conv_data->btvdp_info above*/
1563
4
    if (p_packet_data && payload_type >= PT_UNDF_96 && payload_type <= PT_UNDF_127) {
1564
        /* if the payload type is dynamic, we check if the conv is set and we look for the pt definition */
1565
0
        if (p_packet_data->rtp_dyn_payload) {
1566
0
            const char *payload_type_str = rtp_dyn_payload_get_name(p_packet_data->rtp_dyn_payload, payload_type);
1567
0
            if (payload_type_str) {
1568
0
                int len;
1569
0
                len = dissector_try_string_with_data(rtp_dyn_pt_dissector_table,
1570
0
                    payload_type_str, newtvb, pinfo, tree, true, rtp_info);
1571
                /* If payload type string set from conversation and
1572
                * no matching dissector found it's probably because no subdissector
1573
                * exists. Don't call the dissectors based on payload number
1574
                * as that'd probably be the wrong dissector in this case.
1575
                * Just add it as data.
1576
                */
1577
0
                if (len > 0)
1578
0
                    proto_item_set_hidden(rtp_data);
1579
0
                return;
1580
0
            }
1581
0
        }
1582
0
    }
1583
1584
    /* if we don't found, it is static OR could be set static from the preferences */
1585
4
    if (dissector_try_uint_with_data(rtp_pt_dissector_table, payload_type, newtvb, pinfo, tree, true, rtp_info))
1586
2
        proto_item_set_hidden(rtp_data);
1587
4
}
1588
1589
/* Rtp payload reassembly
1590
 *
1591
 * This handles the reassembly of PDUs for higher-level protocols.
1592
 *
1593
 * We're a bit limited on how we can cope with out-of-order packets, because
1594
 * we don't have any idea of where the datagram boundaries are. So if we see
1595
 * packets A, C, B (all of which comprise a single datagram), we cannot know
1596
 * that C should be added to the same datagram as A, until we come to B (which
1597
 * may or may not actually be present...).
1598
 *
1599
 * What we end up doing in this case is passing A+B to the subdissector as one
1600
 * datagram, and make out that a new one starts on C.
1601
 */
1602
static void
1603
dissect_rtp_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
1604
         proto_tree *rtp_tree, int offset, unsigned int data_reported_len,
1605
         unsigned int payload_type, struct _rtp_info *rtp_info)
1606
4
{
1607
4
    tvbuff_t *newtvb;
1608
4
    struct _rtp_packet_info *p_packet_data;
1609
4
    bool must_desegment = false;
1610
4
    rtp_private_conv_info *finfo = NULL;
1611
4
    rtp_multisegment_pdu *msp;
1612
4
    uint32_t seqno;
1613
4
    uint16_t save_can_desegment;
1614
1615
    /* Retrieve RTPs idea of a conversation */
1616
4
    p_packet_data = (struct _rtp_packet_info *)p_get_proto_data(wmem_file_scope(), pinfo, proto_rtp, RTP_CONVERSATION_PROTO_DATA);
1617
1618
4
    if(p_packet_data != NULL)
1619
4
        finfo = p_packet_data->rtp_conv_info;
1620
1621
4
    if(finfo == NULL || !desegment_rtp || !tvb_bytes_exist(tvb, offset, data_reported_len)) {
1622
        /* Hand the whole lot off to the subdissector */
1623
0
        newtvb = tvb_new_subset_length(tvb, offset, data_reported_len);
1624
0
        process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type, rtp_info);
1625
0
        return;
1626
0
    }
1627
1628
4
    seqno = p_packet_data->extended_seqno;
1629
1630
    /* Preserve the current desegmentation ability in case this is
1631
     * RTP encapsulated in TCP (RFC 4571).
1632
     */
1633
4
    save_can_desegment = pinfo->can_desegment;
1634
4
    pinfo->can_desegment = 2;
1635
4
    pinfo->desegment_offset = 0;
1636
4
    pinfo->desegment_len = 0;
1637
1638
#ifdef DEBUG_FRAGMENTS
1639
    ws_debug("%d: RTP Part of convo %d(%p); seqno %d",
1640
        pinfo->num,
1641
        p_packet_data->frame_number, p_packet_data,
1642
        seqno
1643
        );
1644
#endif
1645
1646
    /* look for a pdu which we might be extending */
1647
4
    msp = (rtp_multisegment_pdu *)wmem_tree_lookup32_le(finfo->multisegment_pdus, seqno-1);
1648
1649
4
    if(msp && msp->startseq < seqno && msp->endseq >= seqno) {
1650
0
        uint32_t fid = msp->startseq;
1651
0
        fragment_head *fd_head;
1652
1653
#ifdef DEBUG_FRAGMENTS
1654
        ws_debug("\tContinues fragment %d", fid);
1655
#endif
1656
1657
        /* we always assume the datagram is complete; if this is the
1658
         * first pass, that's our best guess, and if it's not, what we
1659
         * say gets ignored anyway.
1660
         */
1661
0
        fd_head = fragment_add_seq(&rtp_reassembly_table,
1662
0
                       tvb, offset, pinfo, fid, NULL,
1663
0
                       seqno-msp->startseq, data_reported_len,
1664
0
                       false, 0);
1665
1666
0
        newtvb = process_reassembled_data(tvb, offset, pinfo, "Reassembled RTP", fd_head,
1667
0
                          &rtp_fragment_items, NULL, tree);
1668
1669
#ifdef DEBUG_FRAGMENTS
1670
        ws_debug("\tFragment Coalesced; fd_head=%p, newtvb=%p (len %d)", fd_head, newtvb,
1671
            newtvb?tvb_reported_length(newtvb):0);
1672
#endif
1673
1674
0
        if(newtvb != NULL) {
1675
            /* Hand off to the subdissector */
1676
0
            process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type, rtp_info);
1677
1678
            /*
1679
             * Check to see if there were any complete fragments within the chunk
1680
             */
1681
0
            if( pinfo->desegment_len )
1682
0
            {
1683
0
                if (pinfo->desegment_offset == 0) {
1684
#ifdef DEBUG_FRAGMENTS
1685
                    ws_debug("\tNo complete pdus in payload" );
1686
#endif
1687
                    /* Mark the fragments as not complete yet */
1688
0
                    fragment_set_partial_reassembly(&rtp_reassembly_table,
1689
0
                                    pinfo, fid, NULL);
1690
1691
                    /* we must need another segment */
1692
0
                    msp->endseq = MIN(msp->endseq, seqno) + 1;
1693
1694
0
                }
1695
1696
                /* the higher-level dissector has asked for some more data - ie,
1697
                   the end of this segment does not coincide with the end of a
1698
                   higher-level PDU. */
1699
0
                must_desegment = true;
1700
0
            }
1701
1702
0
        }
1703
1704
0
    }
1705
4
    else
1706
4
    {
1707
        /*
1708
         * The segment is not the continuation of a fragmented segment
1709
         * so process it as normal
1710
         */
1711
#ifdef DEBUG_FRAGMENTS
1712
        ws_debug("\tRTP non-fragment payload");
1713
#endif
1714
4
        newtvb = tvb_new_subset_length(tvb, offset, data_reported_len);
1715
1716
        /* Hand off to the subdissector */
1717
4
        process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type, rtp_info);
1718
1719
4
        if(pinfo->desegment_len) {
1720
            /* the higher-level dissector has asked for some more data - ie,
1721
               the end of this segment does not coincide with the end of a
1722
               higher-level PDU. */
1723
0
            must_desegment = true;
1724
0
        }
1725
4
    }
1726
1727
    /*
1728
     * There were bytes left over that the higher protocol couldn't dissect so save them
1729
     */
1730
4
    if(must_desegment)
1731
0
    {
1732
0
        uint32_t deseg_offset = pinfo->desegment_offset;
1733
0
        uint32_t frag_len = tvb_reported_length_remaining(newtvb, deseg_offset);
1734
0
        fragment_head *fd_head;
1735
1736
#ifdef DEBUG_FRAGMENTS
1737
        ws_debug("\tRTP Must Desegment: tvb_len=%d ds_len=%d %d frag_len=%d ds_off=%d",
1738
            tvb_reported_length(newtvb),
1739
            pinfo->desegment_len,
1740
            pinfo->fd->visited,
1741
            frag_len,
1742
            deseg_offset);
1743
#endif
1744
        /* allocate a new msp for this pdu */
1745
0
        if (!PINFO_FD_VISITED(pinfo)) {
1746
0
            msp = wmem_new(wmem_file_scope(), rtp_multisegment_pdu);
1747
0
            msp->startseq = seqno;
1748
0
            msp->endseq = seqno+1;
1749
0
            wmem_tree_insert32(finfo->multisegment_pdus, seqno, msp);
1750
0
        }
1751
1752
        /*
1753
         * Add the fragment to the fragment table
1754
         */
1755
0
        fd_head = fragment_add_seq(&rtp_reassembly_table,
1756
0
                       newtvb, deseg_offset, pinfo, seqno, NULL, 0, frag_len,
1757
0
                       true, 0);
1758
1759
0
        if(fd_head != NULL)
1760
0
        {
1761
0
            if( fd_head->reassembled_in != 0 && !(fd_head->flags & FD_PARTIAL_REASSEMBLY) )
1762
0
            {
1763
0
                proto_item *rtp_tree_item;
1764
0
                rtp_tree_item = proto_tree_add_uint( tree, hf_rtp_reassembled_in,
1765
0
                                     newtvb, deseg_offset, tvb_reported_length_remaining(newtvb, deseg_offset),
1766
0
                                     fd_head->reassembled_in);
1767
0
                proto_item_set_generated(rtp_tree_item);
1768
#ifdef DEBUG_FRAGMENTS
1769
                ws_debug("\tReassembled in %d", fd_head->reassembled_in);
1770
#endif
1771
0
            }
1772
0
            else if (fd_head->reassembled_in == 0)
1773
0
            {
1774
#ifdef DEBUG_FRAGMENTS
1775
                ws_debug("\tUnfinished fragment");
1776
#endif
1777
                /* this fragment is never reassembled */
1778
0
                proto_tree_add_expert(tree, pinfo, &ei_rtp_fragment_unfinished, tvb, deseg_offset, -1);
1779
0
            }
1780
0
        }
1781
0
        else
1782
0
        {
1783
            /*
1784
             * This fragment was the first fragment in a new entry in the
1785
             * frag_table; we don't yet know where it is reassembled
1786
             */
1787
#ifdef DEBUG_FRAGMENTS
1788
            ws_debug("\tnew pdu");
1789
#endif
1790
0
        }
1791
1792
0
        if( pinfo->desegment_offset == 0 )
1793
0
        {
1794
0
            col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTP");
1795
0
            col_set_str(pinfo->cinfo, COL_INFO, "[RTP segment of a reassembled PDU]");
1796
0
        }
1797
0
    }
1798
1799
    /* Restore desegmentation ability */
1800
4
    pinfo->can_desegment = save_can_desegment;
1801
4
    pinfo->desegment_offset = 0;
1802
4
    pinfo->desegment_len = 0;
1803
4
}
1804
1805
static int
1806
dissect_rtp_rfc2198(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
1807
0
{
1808
0
    volatile int offset = 0;
1809
0
    int cnt;
1810
0
    bool hdr_follow = true;
1811
0
    proto_tree *rfc2198_tree;
1812
0
    rfc2198_hdr *hdr_last;
1813
0
    rfc2198_hdr *hdr_chain = NULL;
1814
0
    struct _rtp_packet_info *p_packet_data;
1815
0
    struct _rtp_info* rtp_info = NULL;
1816
0
    struct _rtp_info rfc2198_rtp_info;
1817
0
    volatile unsigned rtp_info_offset = 0;
1818
1819
0
    if (data) {
1820
0
        rtp_info = (struct _rtp_info*)data;
1821
0
        rfc2198_rtp_info = *rtp_info;
1822
0
        rtp_info_offset = rtp_info->info_payload_offset;
1823
0
    }
1824
1825
    /* Retrieve RTPs idea of a conversation */
1826
0
    p_packet_data = (struct _rtp_packet_info *)p_get_proto_data(wmem_file_scope(), pinfo, proto_rtp, RTP_CONVERSATION_PROTO_DATA);
1827
1828
    /* Add try to RFC 2198 data */
1829
0
    rfc2198_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_rtp_rfc2198, NULL, "RFC 2198: Redundant Audio Data");
1830
1831
0
    hdr_last = NULL;
1832
0
    cnt = 0;
1833
0
    while (hdr_follow) {
1834
0
        proto_item *ti;
1835
0
        proto_tree *rfc2198_hdr_tree;
1836
0
        const char *payload_type_str;
1837
0
        rfc2198_hdr *hdr_new;
1838
0
        uint8_t octet1;
1839
1840
0
        cnt++;
1841
0
        payload_type_str = NULL;
1842
1843
        /* Allocate and fill in header */
1844
0
        hdr_new = wmem_new0(pinfo->pool, rfc2198_hdr);
1845
0
        hdr_new->next = NULL;
1846
0
        octet1 = tvb_get_uint8(tvb, offset);
1847
0
        hdr_new->pt = RTP_PAYLOAD_TYPE(octet1);
1848
0
        hdr_follow = (octet1 & 0x80);
1849
1850
        /* Save the payload type for Decode As */
1851
0
        p_add_proto_data(pinfo->pool, pinfo, proto_rtp, RTP_DECODE_AS_PROTO_DATA, GUINT_TO_POINTER(hdr_new->pt));
1852
1853
        /* if it is dynamic payload, let use the conv data to see if it is defined */
1854
0
        if ((hdr_new->pt > 95) && (hdr_new->pt < 128)) {
1855
0
            if (p_packet_data && p_packet_data->rtp_dyn_payload){
1856
0
                rtp_dyn_payload_get_full(p_packet_data->rtp_dyn_payload, hdr_new->pt, &payload_type_str, &hdr_new->payload_rate, &hdr_new->payload_channels, &hdr_new->payload_fmtp_map);
1857
0
                hdr_new->payload_type_str = payload_type_str;
1858
0
            } else {
1859
                /* See if we have a dissector tied to the dynamic payload
1860
                 * through preferences / Decode As */
1861
0
                dissector_handle_t pt_dissector_handle;
1862
1863
0
                pt_dissector_handle = dissector_get_uint_handle(rtp_pt_dissector_table, hdr_new->pt);
1864
0
                if (pt_dissector_handle) {
1865
0
                    hdr_new->payload_type_str = dissector_handle_get_dissector_name(pt_dissector_handle);
1866
0
                }
1867
0
            }
1868
0
        }
1869
        /* Add a subtree for this header and add items */
1870
0
        rfc2198_hdr_tree = proto_tree_add_subtree_format(rfc2198_tree, tvb, offset, (hdr_follow)?4:1,
1871
0
                                    ett_rtp_rfc2198_hdr, &ti, "Header %u", cnt);
1872
0
        proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_follow, tvb, offset, 1, ENC_BIG_ENDIAN );
1873
0
        proto_tree_add_uint_format_value(rfc2198_hdr_tree, hf_rtp_payload_type, tvb,
1874
0
            offset, 1, octet1, "%s (%u)",
1875
0
            payload_type_str ? payload_type_str : val_to_str_ext_const(hdr_new->pt, &rtp_payload_type_vals_ext, "Unknown"),
1876
0
            hdr_new->pt);
1877
0
        proto_item_append_text(ti, ": PT=%s",
1878
0
                       payload_type_str ? payload_type_str :
1879
0
                                          val_to_str_ext(pinfo->pool, hdr_new->pt, &rtp_payload_type_vals_ext, "Unknown (%u)"));
1880
0
        offset += 1;
1881
1882
        /* Timestamp offset and block length don't apply to last header */
1883
0
        if (hdr_follow) {
1884
0
            proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_tm_off, tvb, offset, 2, ENC_BIG_ENDIAN );
1885
0
            proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_bl_len, tvb, offset + 1, 2, ENC_BIG_ENDIAN );
1886
0
            hdr_new->len = tvb_get_ntohs(tvb, offset + 1) & 0x03FF;
1887
0
            proto_item_append_text(ti, ", len=%u", hdr_new->len);
1888
0
            offset += 3;
1889
0
        } else {
1890
0
            hdr_new->len = -1;
1891
0
            hdr_follow = false;
1892
0
        }
1893
1894
0
        if (hdr_last) {
1895
0
            hdr_last->next = hdr_new;
1896
0
        } else {
1897
0
            hdr_chain = hdr_new;
1898
0
        }
1899
0
        hdr_last = hdr_new;
1900
0
    }
1901
1902
    /* Dissect each data block according to the header info */
1903
0
    hdr_last = hdr_chain;
1904
0
    while (hdr_last) {
1905
0
        hdr_last->offset = offset;
1906
0
        if (!hdr_last->next) {
1907
0
            hdr_last->len = tvb_reported_length_remaining(tvb, offset);
1908
0
        }
1909
0
        if (rtp_info) {
1910
0
            rfc2198_rtp_info.info_payload_offset = rtp_info_offset + hdr_last->offset;
1911
0
            rfc2198_rtp_info.info_payload_len = hdr_last->len;
1912
0
            rfc2198_rtp_info.info_payload_type = hdr_last->pt;
1913
0
            rfc2198_rtp_info.info_payload_type_str = hdr_last->payload_type_str;
1914
0
            rfc2198_rtp_info.info_payload_rate = hdr_last->payload_rate;
1915
0
            rfc2198_rtp_info.info_payload_channels = hdr_last->payload_channels;
1916
0
            rfc2198_rtp_info.info_payload_fmtp_map = hdr_last->payload_fmtp_map;
1917
0
        }
1918
0
        const char *saved_proto = pinfo->current_proto;
1919
0
        TRY {
1920
0
            dissect_rtp_data(tvb, pinfo, tree, rfc2198_tree, hdr_last->offset, hdr_last->len, hdr_last->pt, &rfc2198_rtp_info);
1921
0
        }
1922
0
        CATCH_NONFATAL_ERRORS {
1923
0
            show_exception(tvb, pinfo, rfc2198_tree, EXCEPT_CODE, GET_MESSAGE);
1924
0
            pinfo->current_proto = saved_proto;
1925
0
        }
1926
0
        ENDTRY;
1927
0
        if (rtp_info && rfc2198_deencapsulate && !hdr_last->next) {
1928
            /* Set the payload for the tap to that of the primary encoding
1929
             * to remove the RFC 2198 encapsulation. (Since this is the
1930
             * last encoding in the packet, the calculated length includes
1931
             * the padding and padding stays the same.)
1932
             * Ideally we should process the redundant encoding or FEC,
1933
             * but just treating the primary encoding as the only payload
1934
             * for the tap is closer than doing nothing, and at least has
1935
             * some chance of playing or saving the primary media payload.
1936
             *
1937
             * XXX: WebRTC/Chromium, when using RED with ULPFEC (RFC 5109),
1938
             * violates the RFCs by having the FEC set in separate packets
1939
             * as a different primary encoding (using duplicate sequence
1940
             * numbers already used by the video.) This is done because of
1941
             * a concern that the combined payload size of FEC plus video
1942
             * encodings like VP8 could push a packet over the MTU size,
1943
             * also a problem.
1944
             * See RFC 8872 3.2.4 "RTP Payload Type" and Appendix A
1945
             * "Dismissing Payload Type Multiplexing," also
1946
             * https://bugs.chromium.org/p/webrtc/issues/detail?id=9188
1947
             * https://bugs.chromium.org/p/webrtc/issues/detail?id=12530
1948
             * https://bugs.chromium.org/p/webrtc/issues/detail?id=1467
1949
             * However, since duplicate sequence numbers as used, a user
1950
             * Ignoring all the FEC packets could be a workaround.
1951
             * RFC 2198 in WebRTC/Chromium with actual redundant audio is
1952
             * RFC-compliant, though:
1953
             * https://bugs.chromium.org/p/webrtc/issues/detail?id=11640
1954
             */
1955
0
            *rtp_info = rfc2198_rtp_info;
1956
0
        }
1957
0
        offset += hdr_last->len;
1958
0
        hdr_last = hdr_last->next;
1959
0
    }
1960
0
    return tvb_captured_length(tvb);
1961
0
}
1962
1963
static int
1964
dissect_full_rfc4571(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
1965
0
{
1966
    /* rfc4571 packet frame
1967
      0                   1                   2                   3
1968
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1969
      ---------------------------------------------------------------
1970
     |             LENGTH            |  RTP or RTCP packet ...       |
1971
      ---------------------------------------------------------------
1972
     */
1973
0
    int offset = 0;
1974
0
    uint32_t length = 0;
1975
0
    proto_tree_add_item_ret_uint(tree, hf_rfc4571_header_len, tvb, offset, 2, ENC_BIG_ENDIAN, &length);
1976
0
    if (length == 0) {
1977
0
        return 2;
1978
0
    }
1979
1980
0
    offset += 2;
1981
0
    tvbuff_t *tvb_sub;
1982
0
    tvb_sub = tvb_new_subset_remaining(tvb, offset);
1983
1984
0
    dissect_rtp(tvb_sub, pinfo, tree, data);
1985
0
    return tvb_reported_length(tvb);
1986
0
}
1987
1988
static unsigned
1989
get_rtp_rfc4571_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
1990
0
{
1991
0
    uint16_t rtp_length = tvb_get_ntohs(tvb, offset); /* length field is at the beginning, 2 bytes */
1992
0
    return (unsigned)rtp_length + 2; /* plus the length field */
1993
0
}
1994
1995
0
#define RTP_RFC4571_HEADER_LEN    2
1996
1997
static int
1998
dissect_rtp_rfc4571(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
1999
0
{
2000
0
    tcp_dissect_pdus(tvb, pinfo, tree, true, RTP_RFC4571_HEADER_LEN,
2001
0
                     get_rtp_rfc4571_len, dissect_full_rfc4571, data);
2002
0
    return tvb_captured_length(tvb);
2003
0
}
2004
2005
static void
2006
dissect_rtp_hext_rfc5285_onebyte( tvbuff_t *tvb, packet_info *pinfo,
2007
        proto_tree *rtp_hext_tree )
2008
0
{
2009
0
    proto_tree *rtp_hext_rfc5285_tree = NULL;
2010
0
    unsigned ext_offset = 0;
2011
2012
0
    while (ext_offset < tvb_captured_length (tvb)) {
2013
0
        uint8_t   ext_hdr_hdr;
2014
0
        uint8_t   ext_id;
2015
0
        uint8_t   ext_length;
2016
0
        unsigned  start_ext_offset;
2017
0
        tvbuff_t *subtvb;
2018
2019
        /* Skip bytes with the value 0, they are padding */
2020
0
        start_ext_offset = ext_offset;
2021
0
        while (tvb_get_uint8 (tvb, ext_offset) == 0) {
2022
0
            ext_offset ++;
2023
0
            if (ext_offset >= tvb_captured_length (tvb))
2024
0
                return;
2025
0
        }
2026
2027
        /* Add padding */
2028
0
        if (ext_offset > start_ext_offset)
2029
0
            proto_tree_add_item(rtp_hext_tree, hf_rtp_padding_data, tvb, start_ext_offset, ext_offset-start_ext_offset, ENC_NA );
2030
2031
0
        ext_hdr_hdr = tvb_get_uint8 (tvb, ext_offset);
2032
0
        ext_id = ext_hdr_hdr >> 4;
2033
2034
        /* 15 is for future extensibility, ignore length, etc and stop processing packet if it shows up */
2035
0
        if (ext_id == 15)
2036
0
            return;
2037
2038
0
        ext_length = (ext_hdr_hdr & 0x0F) + 1;
2039
2040
        /* Exit on malformed extension headers */
2041
0
        if (ext_offset + ext_length + 1 > tvb_captured_length (tvb)) {
2042
0
            return;
2043
0
        }
2044
2045
0
        if (rtp_hext_tree) {
2046
0
            rtp_hext_rfc5285_tree = proto_tree_add_subtree(rtp_hext_tree, tvb, ext_offset, ext_length + 1,
2047
0
                                            ett_hdr_ext_rfc5285, NULL, "RFC 5285 Header Extension (One-Byte Header)");
2048
2049
0
            proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_id, tvb, ext_offset, 1, ext_id);
2050
0
            proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_length, tvb, ext_offset, 1, ext_length);
2051
0
        }
2052
0
        ext_offset ++;
2053
2054
0
        subtvb = tvb_new_subset_length(tvb, ext_offset, ext_length);
2055
0
        if (!dissector_try_uint (rtp_hdr_ext_rfc5285_dissector_table, ext_id, subtvb, pinfo, rtp_hext_rfc5285_tree)) {
2056
0
            if (rtp_hext_tree)
2057
0
                proto_tree_add_item(rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_data, subtvb, 0, ext_length, ENC_NA );
2058
0
        }
2059
2060
0
        ext_offset += ext_length;
2061
0
    }
2062
0
}
2063
2064
2065
static void
2066
dissect_rtp_hext_rfc5285_twobytes(tvbuff_t *parent_tvb, unsigned id_offset,
2067
        uint8_t id, tvbuff_t *tvb, packet_info *pinfo, proto_tree *rtp_hext_tree)
2068
0
{
2069
0
    proto_tree *rtp_hext_rfc5285_tree = NULL;
2070
0
    unsigned ext_offset = 0, start_ext_offset;
2071
2072
0
    while (ext_offset + 2 < tvb_captured_length (tvb)) {
2073
0
        uint8_t   ext_id;
2074
0
        uint8_t   ext_length;
2075
0
        tvbuff_t *subtvb;
2076
2077
        /* Skip bytes with the value 0, they are padding */
2078
0
        start_ext_offset = ext_offset;
2079
0
        while (tvb_get_uint8 (tvb, ext_offset) == 0) {
2080
0
            if (ext_offset + 2 >= tvb_captured_length (tvb))
2081
0
                return;
2082
0
            ext_offset ++;
2083
0
        }
2084
        /* Add padding */
2085
0
        if (ext_offset > start_ext_offset)
2086
0
            proto_tree_add_item(rtp_hext_tree, hf_rtp_padding_data, tvb, start_ext_offset, ext_offset-start_ext_offset, ENC_NA );
2087
2088
0
        ext_id = tvb_get_uint8 (tvb, ext_offset);
2089
0
        ext_length = tvb_get_uint8 (tvb, ext_offset + 1);
2090
2091
0
        if (rtp_hext_tree) {
2092
0
            rtp_hext_rfc5285_tree = proto_tree_add_subtree(rtp_hext_tree, tvb, ext_offset, ext_length + 2,
2093
0
                                    ett_hdr_ext_rfc5285, NULL, "RFC 5285 Header Extension (Two-Byte Header)");
2094
2095
0
            proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_appbits, parent_tvb, id_offset + 1, 1, id & 0x000F);
2096
0
            proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_id, tvb, ext_offset, 1, ext_id);
2097
0
            proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_length, tvb, ext_offset + 1, 1, ext_length);
2098
0
        }
2099
2100
0
        ext_offset += 2;
2101
2102
0
        subtvb = tvb_new_subset_length(tvb, ext_offset, ext_length);
2103
0
        if (ext_length && !dissector_try_uint (rtp_hdr_ext_rfc5285_dissector_table, ext_id, subtvb, pinfo, rtp_hext_rfc5285_tree)) {
2104
0
            proto_tree_add_item(rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_data, subtvb, 0, ext_length, ENC_NA );
2105
0
        }
2106
2107
0
        ext_offset += ext_length;
2108
0
    }
2109
0
}
2110
2111
static int
2112
dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
2113
103
{
2114
103
    proto_item *ti            = NULL;
2115
103
    proto_tree *volatile rtp_tree = NULL;
2116
103
    uint8_t     octet1, octet2;
2117
103
    unsigned int version;
2118
103
    bool        padding_set;
2119
103
    bool        extension_set;
2120
103
    unsigned int csrc_count;
2121
103
    bool        marker_set;
2122
103
    unsigned int payload_type;
2123
103
    const char *payload_type_str = NULL;
2124
103
    bool        is_srtp = false;
2125
103
    unsigned int i;
2126
103
    int         length, reported_length;
2127
103
    int         data_len;
2128
103
    volatile unsigned int offset = 0;
2129
103
    uint16_t    seq_num;
2130
103
    uint32_t    timestamp;
2131
103
    uint32_t    sync_src;
2132
103
    struct _rtp_packet_info *p_packet_data;
2133
    /*struct srtp_info *srtp_info = NULL;*/
2134
    /*unsigned int srtp_offset;*/
2135
103
    const char   *pt = NULL;
2136
103
    struct _rtp_info *rtp_info;
2137
103
    static int * const octet1_fields[] = {
2138
103
        &hf_rtp_version,
2139
103
        &hf_rtp_padding,
2140
103
        &hf_rtp_extension,
2141
103
        &hf_rtp_csrc_count,
2142
103
        NULL
2143
103
    };
2144
2145
    /* Get the fields in the first octet */
2146
103
    octet1 = tvb_get_uint8( tvb, offset );
2147
103
    version = RTP_VERSION( octet1 );
2148
2149
    /* RFC 7983 gives current best practice in demultiplexing RTP packets:
2150
     * Examine the first byte of the packet:
2151
     *              +----------------+
2152
     *              |        [0..3] -+--> forward to STUN
2153
     *              |                |
2154
     *              |      [16..19] -+--> forward to ZRTP
2155
     *              |                |
2156
     *  packet -->  |      [20..63] -+--> forward to DTLS
2157
     *              |                |
2158
     *              |      [64..79] -+--> forward to TURN Channel
2159
     *              |                |
2160
     *              |    [128..191] -+--> forward to RTP/RTCP
2161
     *              +----------------+
2162
     *
2163
     * DTLS-SRTP MUST support multiplexing of DTLS and RTP over the same
2164
     * port pair (RFCs 5764, 8835), and this frequently occurs after SDP
2165
     * has been used to set up a RTP conversation and set the conversation
2166
     * dissector RTP. In addition, STUN packets sharing one port are common
2167
     * as well.
2168
     *
2169
     * In practice, RTP0_INVALID rejects packets and lets heuristic dissectors
2170
     * take a look. The STUN, ZRTP, and DTLS heuristic dissectors are all
2171
     * enabled by default so out of the box it more or less looks correct - at
2172
     * least on the second pass, on tshark there's incorrect RTP information in
2173
     * the tree. However, the STUN heuristic dissector can change the
2174
     * dissector for the conversation to itself (the non-heuristic dissector
2175
     * does not), see #18832, and TURN ChannelData messages are impossible to
2176
     * heuristically detect.
2177
     */
2178
103
    if (global_rtp_version0_type == RTP0_RFC7983) {
2179
103
        switch (version) {
2180
53
        case 0:
2181
53
            if (octet1 < 4) {
2182
6
                call_dissector(stun_handle, tvb, pinfo, tree);
2183
6
                return tvb_captured_length(tvb);
2184
47
            } else if ((octet1 & 0xfc) == 0x10) {
2185
9
                call_dissector(zrtp_handle, tvb,pinfo, tree);
2186
9
                return tvb_captured_length(tvb);
2187
38
            } else if (octet1 > 19) {
2188
38
                call_dissector(dtls_handle, tvb,pinfo, tree);
2189
38
                return tvb_captured_length(tvb);
2190
38
            }
2191
0
            break;
2192
7
        case 1:
2193
7
            if (octet1 < 80) {
2194
                /* The STUN dissector will dissect TURN ChannelData
2195
                 * XXX: Maybe we should call the turnchannel dissector?
2196
                 *
2197
                 * Should we be assuming we have TURN ChannelData for
2198
                 * the RTP0_STUN and option too?
2199
                 */
2200
1
                call_dissector(stun_handle, tvb, pinfo, tree);
2201
1
                return tvb_captured_length(tvb);
2202
1
            }
2203
6
            break;
2204
12
        case 3:
2205
12
            if (octet1 == 0xFF) {
2206
0
                if (tvb_get_uint8( tvb, offset + 1 ) == 0x10) {
2207
                    /* Special MS-TURN Multiplexed TURN Channel */
2208
0
                    call_dissector(stun_handle, tvb, pinfo, tree);
2209
0
                    return tvb_captured_length(tvb);
2210
0
                }
2211
0
            }
2212
        /* FALLTHROUGH */
2213
43
        case 2:
2214
43
        default:
2215
43
            break;
2216
103
        }
2217
103
    } else if (version == 0) {
2218
0
        switch (global_rtp_version0_type) {
2219
0
        case RTP0_STUN:
2220
0
            call_dissector(stun_handle, tvb, pinfo, tree);
2221
0
            return tvb_captured_length(tvb);
2222
0
        case RTP0_CLASSICSTUN:
2223
0
            call_dissector(classicstun_handle, tvb, pinfo, tree);
2224
0
            return tvb_captured_length(tvb);
2225
2226
0
        case RTP0_T38:
2227
0
            call_dissector(t38_handle, tvb, pinfo, tree);
2228
0
            return tvb_captured_length(tvb);
2229
2230
0
        case RTP0_SPRT:
2231
0
            call_dissector(sprt_handle, tvb, pinfo, tree);
2232
0
            return tvb_captured_length(tvb);
2233
2234
0
        case RTP0_INVALID:
2235
0
            if (!(tvb_memeql(tvb, 4, (const uint8_t*)"ZRTP", 4)))
2236
0
            {
2237
0
                call_dissector(zrtp_handle, tvb,pinfo, tree);
2238
0
                return tvb_captured_length(tvb);
2239
0
            }
2240
0
        default:
2241
0
            ; /* Unknown or unsupported version (let it fall through) */
2242
0
        }
2243
0
    }
2244
2245
    /* fill in the rtp_info structure */
2246
49
    rtp_info = wmem_new0(pinfo->pool, struct _rtp_info);
2247
49
    rtp_info->info_version = version;
2248
49
    if (version != 2) {
2249
        /*
2250
         * Unknown or unsupported version.
2251
         */
2252
18
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTP");
2253
2254
18
        col_add_fstr( pinfo->cinfo, COL_INFO,
2255
18
            "Unknown RTP version %u", version);
2256
2257
18
        if ( tree ) {
2258
18
            ti = proto_tree_add_item( tree, proto_rtp, tvb, offset, -1, ENC_NA );
2259
18
            rtp_tree = proto_item_add_subtree( ti, ett_rtp );
2260
2261
18
            proto_tree_add_uint( rtp_tree, hf_rtp_version, tvb,
2262
18
                offset, 1, octet1);
2263
18
        }
2264
        /* XXX: Offset is zero here, so in practice this rejects the packet
2265
         * and lets heuristic dissectors make an attempt, though after
2266
         * adding entries to the tree (at least on a first pass in tshark.)
2267
         */
2268
18
        return offset;
2269
18
    }
2270
2271
31
    padding_set = RTP_PADDING( octet1 );
2272
31
    extension_set = RTP_EXTENSION( octet1 );
2273
31
    csrc_count = RTP_CSRC_COUNT( octet1 );
2274
2275
    /* Get the fields in the second octet */
2276
31
    octet2 = tvb_get_uint8( tvb, offset + 1 );
2277
31
    marker_set = RTP_MARKER( octet2 );
2278
31
    payload_type = RTP_PAYLOAD_TYPE( octet2 );
2279
2280
    /* Save the payload type for Decode As */
2281
31
    p_add_proto_data(pinfo->pool, pinfo, proto_rtp, RTP_DECODE_AS_PROTO_DATA, GUINT_TO_POINTER(payload_type));
2282
2283
31
    if (marker_set && payload_type >= FIRST_RTCP_CONFLICT_PAYLOAD_TYPE && payload_type <=  LAST_RTCP_CONFLICT_PAYLOAD_TYPE) {
2284
0
        call_dissector(rtcp_handle, tvb, pinfo, tree);
2285
0
        return tvb_captured_length(tvb);
2286
0
    }
2287
2288
    /* Get the subsequent fields */
2289
31
    seq_num = tvb_get_ntohs( tvb, offset + 2 );
2290
31
    timestamp = tvb_get_ntohl( tvb, offset + 4 );
2291
31
    sync_src = tvb_get_ntohl( tvb, offset + 8 );
2292
2293
    /* fill in the rtp_info structure */
2294
31
    rtp_info->info_padding_set = padding_set;
2295
31
    rtp_info->info_marker_set = marker_set;
2296
31
    rtp_info->info_media_types = 0;
2297
31
    rtp_info->info_payload_type = payload_type;
2298
31
    rtp_info->info_seq_num = seq_num;
2299
31
    rtp_info->info_extended_seq_num = seq_num; /* initial with seq_number */
2300
31
    rtp_info->info_timestamp = timestamp;
2301
31
    rtp_info->info_extended_timestamp = timestamp; /* initial with timestamp */
2302
31
    rtp_info->info_sync_src = sync_src;
2303
31
    rtp_info->info_is_srtp = false;
2304
31
    rtp_info->info_setup_frame_num = 0;
2305
31
    rtp_info->info_payload_type_str = NULL;
2306
31
    rtp_info->info_payload_rate = 0;
2307
31
    rtp_info->info_payload_fmtp_map = NULL;
2308
31
    rtp_info->info_is_ed137 = false;
2309
31
    rtp_info->info_ed137_info = NULL;
2310
31
    rtp_info->info_is_iuup = false;
2311
2312
    /*
2313
     * Do we have all the data?
2314
     */
2315
31
    length = tvb_captured_length_remaining(tvb, offset);
2316
31
    reported_length = tvb_reported_length_remaining(tvb, offset);
2317
31
    if (reported_length >= 0 && length >= reported_length) {
2318
        /*
2319
         * Yes.
2320
         */
2321
28
        rtp_info->info_all_data_present = true;
2322
28
        rtp_info->info_data_len = reported_length;
2323
2324
        /*
2325
         * Save the pointer to raw rtp data (header + payload incl.
2326
         * padding).
2327
         * That should be safe because the "epan_dissect_t"
2328
         * constructed for the packet has not yet been freed when
2329
         * the taps are called.
2330
         * (Destroying the "epan_dissect_t" will end up freeing
2331
         * all the tvbuffs and hence invalidating pointers to
2332
         * their data.)
2333
         * See "add_packet_to_packet_list()" for details.
2334
         */
2335
28
        rtp_info->info_data = tvb_get_ptr(tvb, 0, -1);
2336
28
    } else {
2337
        /*
2338
         * No - packet was cut short at capture time.
2339
         */
2340
3
        rtp_info->info_all_data_present = false;
2341
3
        rtp_info->info_data_len = 0;
2342
3
        rtp_info->info_data = NULL;
2343
3
    }
2344
2345
    /* Look for conv and add to the frame if found */
2346
2347
31
    p_packet_data = get_rtp_packet_info(pinfo, rtp_info);
2348
2349
31
    if (p_packet_data && p_packet_data->srtp_info) is_srtp = true;
2350
31
    rtp_info->info_is_srtp = is_srtp;
2351
2352
31
    col_set_str( pinfo->cinfo, COL_PROTOCOL, (is_srtp) ? "SRTP" : "RTP" );
2353
2354
#if 0 /* XXX: srtp_offset never actually used ?? */
2355
    /* check if this is added as an SRTP stream - if so, don't try to dissect the payload data for now */
2356
    if (p_conv_data && p_conv_data->srtp_info) {
2357
        srtp_info = p_conv_data->srtp_info;
2358
        if (rtp_info->info_all_data_present) {
2359
            srtp_offset = rtp_info->info_data_len - srtp_info->mki_len - srtp_info->auth_tag_len;
2360
        }
2361
    }
2362
#endif
2363
2364
31
    if (p_packet_data && p_packet_data->bta2dp_info && p_packet_data->bta2dp_info->codec_dissector) {
2365
0
        rtp_info->info_payload_type_str = (const char *) dissector_handle_get_protocol_short_name(p_packet_data->bta2dp_info->codec_dissector);
2366
31
    } else if (p_packet_data && p_packet_data->btvdp_info && p_packet_data->btvdp_info->codec_dissector) {
2367
0
        rtp_info->info_payload_type_str = (const char *) dissector_handle_get_protocol_short_name(p_packet_data->btvdp_info->codec_dissector);
2368
0
    }
2369
2370
    /* if it is dynamic payload, let use the conv data to see if it is defined */
2371
31
    if ( (payload_type>95) && (payload_type<128) ) {
2372
0
        if (p_packet_data && p_packet_data->rtp_dyn_payload) {
2373
0
            int sample_rate = 0;
2374
0
            unsigned channels = 1;
2375
0
            wmem_map_t *fmtp_map;
2376
2377
#ifdef DEBUG_CONVERSATION
2378
            rtp_dump_dyn_payload(p_packet_data->rtp_dyn_payload);
2379
#endif
2380
0
            DPRINT(("looking up conversation data for dyn_pt=%d", payload_type));
2381
2382
0
            if (rtp_dyn_payload_get_full(p_packet_data->rtp_dyn_payload, payload_type,
2383
0
                                        &payload_type_str, &sample_rate,
2384
0
                                        &channels, &fmtp_map)) {
2385
0
                DPRINT(("found conversation data for dyn_pt=%d, enc_name=%s",
2386
0
                        payload_type, payload_type_str));
2387
0
                rtp_info->info_payload_type_str = payload_type_str;
2388
0
                rtp_info->info_payload_rate     = sample_rate;
2389
0
                rtp_info->info_payload_channels = channels;
2390
0
                rtp_info->info_payload_fmtp_map = fmtp_map;
2391
0
            }
2392
0
        } else {
2393
            /* See if we have a dissector tied to the dynamic payload trough preferences*/
2394
0
            dissector_handle_t pt_dissector_handle;
2395
0
            const char *name;
2396
2397
0
            pt_dissector_handle = dissector_get_uint_handle(rtp_pt_dissector_table, payload_type);
2398
0
            if (pt_dissector_handle) {
2399
0
                name = dissector_handle_get_dissector_name(pt_dissector_handle);
2400
0
                if (name) {
2401
0
                    rtp_info->info_payload_type_str = name;
2402
0
                }
2403
0
            }
2404
0
        }
2405
0
    }
2406
2407
31
    if (p_packet_data && p_packet_data->bta2dp_info) {
2408
0
        pt = (p_packet_data->bta2dp_info->codec_dissector) ? dissector_handle_get_protocol_short_name(p_packet_data->bta2dp_info->codec_dissector) : "Unknown";
2409
31
    } else if (p_packet_data && p_packet_data->btvdp_info) {
2410
0
        pt = (p_packet_data->btvdp_info->codec_dissector) ? dissector_handle_get_protocol_short_name(p_packet_data->btvdp_info->codec_dissector) : "Unknown";
2411
31
    } else {
2412
31
        pt = (payload_type_str ? payload_type_str : val_to_str_ext(pinfo->pool, payload_type, &rtp_payload_type_vals_ext, "Unknown (%u)"));
2413
31
    }
2414
2415
31
    col_add_fstr( pinfo->cinfo, COL_INFO,
2416
31
        "PT=%s, SSRC=0x%X, Seq=%u, Time=%u%s",
2417
31
        pt,
2418
31
        sync_src,
2419
31
        seq_num,
2420
31
        timestamp,
2421
31
        marker_set ? ", Mark" : "");
2422
2423
31
    if ( tree ) {
2424
28
        proto_tree *item;
2425
        /* Create RTP protocol tree */
2426
28
        ti = proto_tree_add_item(tree, proto_rtp, tvb, offset, -1, ENC_NA );
2427
28
        rtp_tree = proto_item_add_subtree(ti, ett_rtp );
2428
2429
        /* Conversation setup info */
2430
28
        if (global_rtp_show_setup_info)
2431
28
        {
2432
28
            show_setup_info(tvb, pinfo, rtp_tree);
2433
28
        }
2434
2435
28
        proto_tree_add_bitmask_list(rtp_tree, tvb, offset, 1, octet1_fields, ENC_NA);
2436
28
        offset++;
2437
2438
28
        proto_tree_add_boolean( rtp_tree, hf_rtp_marker, tvb, offset,
2439
28
            1, octet2 );
2440
2441
28
        proto_tree_add_uint_format_value( rtp_tree, hf_rtp_payload_type, tvb,
2442
28
            offset, 1, octet2, "%s (%u)", pt, payload_type);
2443
2444
28
        offset++;
2445
2446
        /* Sequence number 16 bits (2 octets) */
2447
28
        proto_tree_add_uint( rtp_tree, hf_rtp_seq_nr, tvb, offset, 2, seq_num );
2448
28
        if(p_packet_data != NULL) {
2449
28
            item = proto_tree_add_uint(rtp_tree, hf_rtp_ext_seq_nr, tvb, offset, 2, p_packet_data->extended_seqno);
2450
28
            proto_item_set_generated(item);
2451
28
        }
2452
28
        offset += 2;
2453
2454
        /* Timestamp 32 bits (4 octets) */
2455
28
        proto_tree_add_uint( rtp_tree, hf_rtp_timestamp, tvb, offset, 4, timestamp );
2456
28
        if(p_packet_data != NULL) {
2457
28
            item = proto_tree_add_uint64(rtp_tree, hf_rtp_ext_timestamp, tvb, offset, 4, p_packet_data->extended_timestamp);
2458
28
            proto_item_set_generated(item);
2459
28
        }
2460
28
        offset += 4;
2461
2462
        /* Synchronization source identifier 32 bits (4 octets) */
2463
28
        proto_tree_add_uint( rtp_tree, hf_rtp_ssrc, tvb, offset, 4, sync_src );
2464
28
        offset += 4;
2465
28
    } else {
2466
3
        offset += 12;
2467
3
    }
2468
    /* CSRC list*/
2469
31
    if ( csrc_count > 0 ) {
2470
2
        proto_tree *rtp_csrc_tree;
2471
2
        uint32_t csrc_item;
2472
2
        ti = proto_tree_add_item(rtp_tree, hf_rtp_csrc_items, tvb, offset,
2473
2
                                     csrc_count * 4, ENC_NA);
2474
2
        proto_item_append_text(ti, " (%u items)", csrc_count);
2475
2
        rtp_csrc_tree = proto_item_add_subtree( ti, ett_csrc_list );
2476
2477
18
        for (i = 0; i < csrc_count; i++ ) {
2478
16
            csrc_item = tvb_get_ntohl( tvb, offset );
2479
16
            proto_tree_add_uint_format( rtp_csrc_tree,
2480
16
                hf_rtp_csrc_item, tvb, offset, 4,
2481
16
                csrc_item,
2482
16
                "CSRC item %d: 0x%X",
2483
16
                i, csrc_item );
2484
16
            offset += 4;
2485
16
        }
2486
2
    }
2487
2488
    /* Optional RTP header extension */
2489
31
    if ( extension_set ) {
2490
0
        unsigned int hdr_extension_len;
2491
0
        unsigned int hdr_extension_id;
2492
2493
        /* Defined by profile field is 16 bits (2 octets) */
2494
0
        hdr_extension_id = tvb_get_ntohs( tvb, offset );
2495
0
        proto_tree_add_uint( rtp_tree, hf_rtp_prof_define, tvb, offset, 2, hdr_extension_id );
2496
0
        offset += 2;
2497
2498
0
        hdr_extension_len = tvb_get_ntohs( tvb, offset );
2499
0
        proto_tree_add_uint( rtp_tree, hf_rtp_length, tvb, offset, 2, hdr_extension_len);
2500
0
        offset += 2;
2501
0
        if ( hdr_extension_len > 0 ) {
2502
0
            proto_tree *rtp_hext_tree = NULL;
2503
0
            tvbuff_t   *newtvb;
2504
2505
0
            ti = proto_tree_add_item(rtp_tree, hf_rtp_hdr_exts, tvb, offset, hdr_extension_len * 4, ENC_NA);
2506
0
            rtp_hext_tree = proto_item_add_subtree( ti, ett_hdr_ext );
2507
2508
            /* pass interpretation of header extension to a registered subdissector */
2509
0
            newtvb = tvb_new_subset_length(tvb, offset, hdr_extension_len * 4);
2510
2511
0
            if (hdr_extension_id == RTP_RFC5285_ONE_BYTE_SIG) {
2512
0
                dissect_rtp_hext_rfc5285_onebyte (newtvb, pinfo, rtp_hext_tree);
2513
0
            }
2514
0
            else if ((hdr_extension_id & RTP_RFC5285_TWO_BYTE_MASK) == RTP_RFC5285_TWO_BYTE_SIG) {
2515
0
                dissect_rtp_hext_rfc5285_twobytes(tvb,
2516
0
                    offset - 4, hdr_extension_id, newtvb,
2517
0
                    pinfo, rtp_hext_tree);
2518
0
            }
2519
0
            else {
2520
0
                if ( !(dissector_try_uint_with_data(rtp_hdr_ext_dissector_table, hdr_extension_id, newtvb, pinfo, rtp_hext_tree, false, rtp_info)) ) {
2521
0
                    unsigned int hdrext_offset;
2522
2523
0
                    hdrext_offset = offset;
2524
0
                    for ( i = 0; i < hdr_extension_len; i++ ) {
2525
0
                        proto_tree_add_item( rtp_hext_tree, hf_rtp_hdr_ext, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN );
2526
0
                        hdrext_offset += 4;
2527
0
                    }
2528
0
                }
2529
0
            }
2530
0
        }
2531
0
        offset += hdr_extension_len * 4;
2532
0
    }
2533
2534
31
    if ( padding_set ) {
2535
        /*
2536
         * This RTP frame has padding - find it.
2537
         *
2538
         * The padding count is found in the LAST octet of
2539
         * the packet; it contains the number of octets
2540
         * that can be ignored at the end of the packet.
2541
         */
2542
26
        volatile unsigned int padding_count;
2543
26
        volatile bool padding_bogus = false;
2544
26
        if (tvb_captured_length(tvb) < tvb_reported_length(tvb)) {
2545
            /*
2546
             * We don't *have* the last octet of the
2547
             * packet, so we can't get the padding
2548
             * count.
2549
             *
2550
             * Put an indication of that into the
2551
             * tree, and just put in a raw data
2552
             * item.
2553
             */
2554
0
            proto_tree_add_expert(rtp_tree, pinfo, &ei_rtp_padding_missing, tvb, 0, 0);
2555
0
            call_data_dissector(tvb_new_subset_remaining(tvb, offset),
2556
0
                pinfo, rtp_tree);
2557
0
            return tvb_captured_length(tvb);
2558
0
        }
2559
2560
26
        padding_count = tvb_get_uint8( tvb,
2561
26
            tvb_reported_length( tvb ) - 1 );
2562
26
        data_len =
2563
26
            tvb_reported_length_remaining( tvb, offset ) - padding_count;
2564
2565
26
        rtp_info->info_payload_offset = offset;
2566
2567
26
        if (p_packet_data && p_packet_data->bta2dp_info) {
2568
0
            if (p_packet_data->bta2dp_info->codec_dissector == sbc_handle) {
2569
0
                rtp_info->info_payload_offset += 1;
2570
0
            }
2571
2572
0
            if (p_packet_data->bta2dp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
2573
0
                rtp_info->info_payload_offset += 1;
2574
0
            }
2575
0
        }
2576
2577
26
        if (p_packet_data && p_packet_data->btvdp_info &&
2578
0
                p_packet_data->btvdp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
2579
0
            rtp_info->info_payload_offset += 1;
2580
0
        }
2581
2582
26
        rtp_info->info_payload_len = tvb_reported_length_remaining(tvb, rtp_info->info_payload_offset);
2583
2584
26
        if (rtp_info->info_payload_len > padding_count) {
2585
2
            rtp_info->info_payload_len -= padding_count;
2586
24
        } else {
2587
24
            rtp_info->info_payload_len = 0;
2588
24
        }
2589
2590
26
        if (data_len > 0) {
2591
            /*
2592
             * There's data left over when you take out
2593
             * the padding; dissect it.
2594
             */
2595
2
            struct _rtp_pkt_info *rtp_pkt_info = wmem_new(pinfo->pool, struct _rtp_pkt_info);
2596
2597
2
            rtp_pkt_info->payload_len = data_len;
2598
2
            rtp_pkt_info->padding_len = padding_count - 1;
2599
2
            p_add_proto_data(pinfo->pool, pinfo, proto_rtp, pinfo->curr_layer_num, rtp_pkt_info);
2600
2601
            /* Ensure that tap is called after packet dissection, even in case of exception */
2602
2
            TRY {
2603
2
                dissect_rtp_data( tvb, pinfo, tree, rtp_tree,
2604
2
                    offset,
2605
2
                    data_len,
2606
2
                    payload_type,
2607
2
                    rtp_info);
2608
2
            } CATCH_ALL {
2609
0
                if (!pinfo->flags.in_error_pkt)
2610
0
                    tap_queue_packet(rtp_tap, pinfo, rtp_info);
2611
0
                RETHROW;
2612
0
            }
2613
2
            ENDTRY;
2614
2
            offset += data_len;
2615
24
        } else if (data_len < 0) {
2616
            /*
2617
             * The padding count is bigger than the
2618
             * amount of RTP payload in the packet!
2619
             * Clip the padding count.
2620
             */
2621
24
            padding_count =
2622
24
                tvb_reported_length_remaining(tvb, offset);
2623
24
            padding_bogus = true;
2624
24
        }
2625
26
        if (padding_count) {
2626
25
            if (padding_count > 1) {
2627
                /*
2628
                 * There's more than one byte of padding;
2629
                 * show all but the last byte as padding
2630
                 * data.
2631
                 */
2632
24
                proto_tree_add_item( rtp_tree, hf_rtp_padding_data,
2633
24
                    tvb, offset, padding_count - 1, ENC_NA );
2634
24
                offset += padding_count - 1;
2635
24
            }
2636
            /*
2637
             * Show the last byte in the PDU as the padding
2638
             * count.
2639
             */
2640
25
            ti = proto_tree_add_item( rtp_tree, hf_rtp_padding_count,
2641
25
                tvb, offset, 1, ENC_BIG_ENDIAN );
2642
25
            if (padding_bogus) {
2643
24
                expert_add_info(pinfo, ti, &ei_rtp_padding_bogus);
2644
24
            }
2645
25
        } else {
2646
            /* The padding length includes itself, so zero is an illegal
2647
             * value. Trying to add it to the tree at this point would
2648
             * create a malformed error by running off the end of the tvb.
2649
             */
2650
1
            proto_tree_add_expert_format(rtp_tree, pinfo, &ei_rtp_padding_bogus, tvb, tvb_reported_length(tvb) - 1, 1, "Frame has padding, but of illegal length zero");
2651
1
        }
2652
26
    }
2653
5
    else {
2654
        /*
2655
         * No padding.
2656
         */
2657
5
        rtp_info->info_payload_offset = offset;
2658
5
        rtp_info->info_payload_len = tvb_captured_length_remaining(tvb, offset);
2659
2660
5
        if (p_packet_data && p_packet_data->bta2dp_info) {
2661
0
            if (p_packet_data->bta2dp_info->codec_dissector == sbc_handle) {
2662
0
                rtp_info->info_payload_offset += 1;
2663
0
                rtp_info->info_payload_len -= 1;
2664
0
            }
2665
2666
0
            if (p_packet_data->bta2dp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
2667
0
                rtp_info->info_payload_offset += 1;
2668
0
                rtp_info->info_payload_len -= 1;
2669
0
            }
2670
0
        }
2671
2672
5
        if (p_packet_data && p_packet_data->btvdp_info &&
2673
0
                p_packet_data->btvdp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
2674
0
            rtp_info->info_payload_offset += 1;
2675
0
            rtp_info->info_payload_len -= 1;
2676
0
        }
2677
2678
5
        if (tvb_reported_length_remaining(tvb, offset) > 0) {
2679
2
            struct _rtp_pkt_info *rtp_pkt_info = wmem_new(pinfo->pool, struct _rtp_pkt_info);
2680
2681
2
            rtp_pkt_info->payload_len = tvb_captured_length_remaining(tvb, offset);
2682
2
            rtp_pkt_info->padding_len = 0;
2683
2
            p_set_proto_data(pinfo->pool, pinfo, proto_rtp, pinfo->curr_layer_num, rtp_pkt_info);
2684
2685
            /* Ensure that tap is called after packet dissection, even in case of exception */
2686
2
            TRY {
2687
2
                dissect_rtp_data( tvb, pinfo, tree, rtp_tree, offset,
2688
2
                          tvb_reported_length_remaining( tvb, offset ),
2689
2
                          payload_type, rtp_info);
2690
2
            } CATCH_ALL {
2691
0
                if (!pinfo->flags.in_error_pkt)
2692
0
                    tap_queue_packet(rtp_tap, pinfo, rtp_info);
2693
0
                RETHROW;
2694
0
            }
2695
2
            ENDTRY;
2696
2
        }
2697
5
    }
2698
31
    if (!pinfo->flags.in_error_pkt)
2699
28
        tap_queue_packet(rtp_tap, pinfo, rtp_info);
2700
2701
31
    return offset;
2702
31
}
2703
2704
int
2705
dissect_rtp_shim_header(tvbuff_t *tvb, int start, packet_info *pinfo _U_, proto_tree *tree, struct _rtp_info *rtp_info)
2706
51
{
2707
51
    proto_item *rtp_ti = NULL;
2708
51
    proto_tree *rtp_tree = NULL;
2709
51
    proto_item *ti;
2710
51
    uint8_t     octet1, octet2;
2711
51
    unsigned int version;
2712
51
    bool        padding_set;
2713
51
    bool        extension_set;
2714
51
    unsigned int csrc_count;
2715
51
    bool        marker_set;
2716
51
    unsigned int payload_type;
2717
51
    unsigned int i;
2718
51
    int         offset = start;
2719
51
    uint16_t    seq_num;
2720
51
    uint32_t    timestamp;
2721
51
    uint32_t    sync_src;
2722
51
    const char *pt = NULL;
2723
51
    static int * const octet1_fields[] = {
2724
51
        &hf_rtp_version,
2725
51
        &hf_rtp_padding,
2726
51
        &hf_rtp_extension,
2727
51
        &hf_rtp_csrc_count,
2728
51
        NULL
2729
51
    };
2730
2731
    /* Get the fields in the first octet */
2732
51
    octet1 = tvb_get_uint8( tvb, offset );
2733
51
    version = RTP_VERSION( octet1 );
2734
2735
    /* fill in the rtp_info structure */
2736
51
    if (rtp_info) rtp_info->info_version = version;
2737
51
    if (version != 2) {
2738
        /*
2739
         * Unknown or unsupported version.
2740
         */
2741
17
        if ( tree ) {
2742
17
            ti = proto_tree_add_item( tree, proto_rtp, tvb, offset, 1, ENC_NA );
2743
17
            rtp_tree = proto_item_add_subtree( ti, ett_rtp );
2744
2745
17
            proto_tree_add_uint( rtp_tree, hf_rtp_version, tvb,
2746
17
                offset, 1, octet1);
2747
17
        }
2748
17
        return 0;
2749
17
    }
2750
2751
34
    padding_set = RTP_PADDING( octet1 );
2752
34
    extension_set = RTP_EXTENSION( octet1 );
2753
34
    csrc_count = RTP_CSRC_COUNT( octet1 );
2754
2755
    /* Get the fields in the second octet */
2756
34
    octet2 = tvb_get_uint8( tvb, offset + 1 );
2757
34
    marker_set = RTP_MARKER( octet2 );
2758
34
    payload_type = RTP_PAYLOAD_TYPE( octet2 );
2759
2760
    /* Get the subsequent fields */
2761
34
    seq_num = tvb_get_ntohs( tvb, offset + 2 );
2762
34
    timestamp = tvb_get_ntohl( tvb, offset + 4 );
2763
34
    sync_src = tvb_get_ntohl( tvb, offset + 8 );
2764
2765
    /* fill in the rtp_info structure */
2766
34
    if (rtp_info) {
2767
32
        rtp_info->info_padding_set = padding_set;
2768
32
        rtp_info->info_marker_set = marker_set;
2769
32
        rtp_info->info_media_types = 0;
2770
32
        rtp_info->info_payload_type = payload_type;
2771
32
        rtp_info->info_seq_num = seq_num;
2772
32
        rtp_info->info_timestamp = timestamp;
2773
32
        rtp_info->info_sync_src = sync_src;
2774
32
        rtp_info->info_data_len = 0;
2775
32
        rtp_info->info_all_data_present = false;
2776
32
        rtp_info->info_payload_offset = 0;
2777
32
        rtp_info->info_payload_len = 0;
2778
32
        rtp_info->info_is_srtp = false;
2779
32
        rtp_info->info_setup_frame_num = 0;
2780
32
        rtp_info->info_data = NULL;
2781
32
        rtp_info->info_payload_type_str = NULL;
2782
32
        rtp_info->info_payload_rate = 0;
2783
32
        rtp_info->info_payload_fmtp_map = NULL;
2784
32
        rtp_info->info_is_ed137 = false;
2785
32
        rtp_info->info_ed137_info = NULL;
2786
32
        rtp_info->info_is_iuup = false;
2787
32
    }
2788
2789
34
    if ( tree ) {
2790
        /* Create RTP protocol tree */
2791
32
        rtp_ti = proto_tree_add_item(tree, proto_rtp, tvb, offset, 0, ENC_NA );
2792
32
        rtp_tree = proto_item_add_subtree(rtp_ti, ett_rtp );
2793
2794
32
        proto_tree_add_bitmask_list(rtp_tree, tvb, offset, 1, octet1_fields, ENC_NA);
2795
32
        offset++;
2796
2797
32
        proto_tree_add_boolean( rtp_tree, hf_rtp_marker, tvb, offset,
2798
32
            1, octet2 );
2799
2800
32
        pt = val_to_str_ext(pinfo->pool, payload_type, &rtp_payload_type_vals_ext, "Unknown (%u)");
2801
2802
32
        proto_tree_add_uint_format_value( rtp_tree, hf_rtp_payload_type, tvb,
2803
32
            offset, 1, octet2, "%s (%u)", pt, payload_type);
2804
2805
32
        offset++;
2806
2807
        /* Sequence number 16 bits (2 octets) */
2808
32
        proto_tree_add_uint( rtp_tree, hf_rtp_seq_nr, tvb, offset, 2, seq_num );
2809
32
        offset += 2;
2810
2811
        /* Timestamp 32 bits (4 octets) */
2812
32
        proto_tree_add_uint( rtp_tree, hf_rtp_timestamp, tvb, offset, 4, timestamp );
2813
32
        offset += 4;
2814
2815
        /* Synchronization source identifier 32 bits (4 octets) */
2816
32
        proto_tree_add_uint( rtp_tree, hf_rtp_ssrc, tvb, offset, 4, sync_src );
2817
32
        offset += 4;
2818
32
    } else {
2819
2
        offset += 12;
2820
2
    }
2821
    /* CSRC list*/
2822
34
    if ( csrc_count > 0 ) {
2823
28
        proto_tree *rtp_csrc_tree;
2824
28
        uint32_t csrc_item;
2825
28
        ti = proto_tree_add_item(rtp_tree, hf_rtp_csrc_items, tvb, offset,
2826
28
                                     csrc_count * 4, ENC_NA);
2827
28
        proto_item_append_text(ti, " (%u items)", csrc_count);
2828
28
        rtp_csrc_tree = proto_item_add_subtree( ti, ett_csrc_list );
2829
2830
127
        for (i = 0; i < csrc_count; i++ ) {
2831
99
            csrc_item = tvb_get_ntohl( tvb, offset );
2832
99
            proto_tree_add_uint_format( rtp_csrc_tree,
2833
99
                hf_rtp_csrc_item, tvb, offset, 4,
2834
99
                csrc_item,
2835
99
                "CSRC item %d: 0x%X",
2836
99
                i, csrc_item );
2837
99
            offset += 4;
2838
99
        }
2839
28
    }
2840
2841
    /* Optional RTP header extension */
2842
34
    if ( extension_set ) {
2843
24
        unsigned int hdr_extension_len;
2844
24
        unsigned int hdr_extension_id;
2845
2846
        /* Defined by profile field is 16 bits (2 octets) */
2847
24
        hdr_extension_id = tvb_get_ntohs( tvb, offset );
2848
24
        proto_tree_add_uint( rtp_tree, hf_rtp_prof_define, tvb, offset, 2, hdr_extension_id );
2849
24
        offset += 2;
2850
2851
24
        hdr_extension_len = tvb_get_ntohs( tvb, offset );
2852
24
        proto_tree_add_uint( rtp_tree, hf_rtp_length, tvb, offset, 2, hdr_extension_len);
2853
24
        offset += 2;
2854
24
        if ( hdr_extension_len > 0 ) {
2855
21
            proto_tree *rtp_hext_tree = NULL;
2856
2857
21
            ti = proto_tree_add_item(rtp_tree, hf_rtp_hdr_exts, tvb, offset, hdr_extension_len * 4, ENC_NA);
2858
21
            rtp_hext_tree = proto_item_add_subtree( ti, ett_hdr_ext );
2859
2860
484
            for ( i = 0; i < hdr_extension_len; i++ ) {
2861
463
                proto_tree_add_item( rtp_hext_tree, hf_rtp_hdr_ext, tvb, offset, 4, ENC_BIG_ENDIAN );
2862
463
                offset += 4;
2863
463
            }
2864
21
        }
2865
24
    }
2866
2867
34
    proto_item_set_len(rtp_ti, offset - start);
2868
2869
34
    return (offset - start);
2870
51
}
2871
2872
/* calculate the extended sequence number - top 16 bits of the previous sequence number,
2873
 * plus our own; then correct for wrapping */
2874
static uint32_t
2875
calculate_extended_seqno(uint32_t previous_seqno, uint16_t raw_seqno)
2876
15
{
2877
15
    uint32_t seqno = (previous_seqno & 0xffff0000) | raw_seqno;
2878
15
    if (seqno + 0x8000 < previous_seqno) {
2879
0
        seqno += 0x10000;
2880
15
    } else if (previous_seqno + 0x8000 < seqno) {
2881
        /* we got an out-of-order packet which happened to go backwards over the
2882
         * wrap boundary */
2883
9
        seqno -= 0x10000;
2884
9
    }
2885
15
    return seqno;
2886
15
}
2887
2888
/* calculate the extended sequence number - top 16 bits of the previous sequence number,
2889
 * plus our own; then correct for wrapping */
2890
static uint64_t
2891
calculate_extended_timestamp(uint64_t previous_timestamp, uint32_t raw_timestamp)
2892
15
{
2893
15
    uint64_t timestamp = (previous_timestamp & 0xffffffff00000000) | raw_timestamp;
2894
15
    if (timestamp + 0x80000000 < previous_timestamp) {
2895
0
        timestamp += 0x100000000;
2896
15
    } else if (previous_timestamp + 0x80000000 < timestamp) {
2897
        /* we got an out-of-order packet which happened to go backwards over the
2898
         * wrap boundary */
2899
8
        timestamp -= 0x100000000;
2900
8
    }
2901
15
    return timestamp;
2902
15
}
2903
2904
/* Look for conversation info */
2905
static struct _rtp_packet_info *
2906
get_rtp_packet_info(packet_info *pinfo, struct _rtp_info *rtp_info)
2907
28
{
2908
    /* Conversation and current data */
2909
28
    struct _rtp_packet_info *p_packet_data;
2910
2911
    /* Use existing packet info if available */
2912
28
    p_packet_data = (struct _rtp_packet_info *)p_get_proto_data(wmem_file_scope(), pinfo, proto_rtp, RTP_CONVERSATION_PROTO_DATA);
2913
2914
28
    if (!p_packet_data)
2915
15
    {
2916
15
        conversation_t *p_conv;
2917
2918
        /* First time, get info from conversation */
2919
15
        p_conv = find_conversation_strat_xtd(pinfo, pinfo->num, &pinfo->net_dst, &pinfo->net_src,
2920
15
                                   conversation_pt_to_conversation_type(pinfo->ptype),
2921
15
                                   pinfo->destport, pinfo->srcport, NO_ADDR_B);
2922
15
        if (!p_conv) {
2923
            /* Create a conversation in case none exists (decode as is used for marking the packet as RTP) */
2924
5
            p_conv = conversation_new_strat_xtd(pinfo, pinfo->num, &pinfo->net_dst, &pinfo->net_src,
2925
5
                conversation_pt_to_conversation_type(pinfo->ptype),
2926
5
                pinfo->destport, pinfo->srcport, NO_ADDR2);
2927
5
        }
2928
2929
        /* Create space for packet info */
2930
15
        struct _rtp_conversation_info *p_conv_data;
2931
15
        p_conv_data = (struct _rtp_conversation_info *)conversation_get_proto_data(p_conv, proto_rtp);
2932
2933
15
        if (!p_conv_data) {
2934
            /* Create conversation data. If RTP was set up by an SDP or by
2935
             * the heuristic dissector, conversation data should already
2936
             * have been created. Therefore, we should only reach this
2937
             * case if Decode As is being used (See Issue #18829).
2938
             */
2939
5
            p_conv_data = wmem_new0(wmem_file_scope(), struct _rtp_conversation_info);
2940
5
            p_conv_data->ssrc_number_space = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
2941
5
            p_conv_data->rtp_conv_info = wmem_new(wmem_file_scope(), rtp_private_conv_info);
2942
5
            p_conv_data->rtp_conv_info->multisegment_pdus = wmem_tree_new(wmem_file_scope());
2943
5
            (void)g_strlcpy(p_conv_data->method, "DECODE AS", MAX_RTP_SETUP_METHOD_SIZE + 1);
2944
5
            p_conv_data->frame_number = pinfo->num;
2945
5
            p_conv_data->media_types = 0;
2946
5
            p_conv_data->srtp_info = NULL;
2947
5
            p_conv_data->bta2dp_info = NULL;
2948
5
            p_conv_data->btvdp_info = NULL;
2949
5
            conversation_add_proto_data(p_conv, proto_rtp, p_conv_data);
2950
5
        }
2951
2952
15
        uint32_t seqno;
2953
15
        uint64_t timestamp;
2954
2955
        /* Save this conversation info into packet info */
2956
        /* This is file scoped because we only do this on the first pass.
2957
         * On nonsequential passes, the conversation data has the values
2958
         * from the last dissected frame, which is not necessarily the
2959
         * immediately previous frame.
2960
         */
2961
15
        p_packet_data = wmem_new(wmem_file_scope(), struct _rtp_packet_info);
2962
15
        (void)g_strlcpy(p_packet_data->method, p_conv_data->method, MAX_RTP_SETUP_METHOD_SIZE + 1);
2963
15
        p_packet_data->frame_number = p_conv_data->frame_number;
2964
15
        p_packet_data->media_types = p_conv_data->media_types;
2965
        /* do not increment ref count for the rtp_dyn_payload */
2966
15
        p_packet_data->rtp_dyn_payload = p_conv_data->rtp_dyn_payload;
2967
15
        p_packet_data->dyn_payload_encoding_name = p_packet_data->rtp_dyn_payload ? wmem_strdup(wmem_file_scope(), rtp_dyn_payload_get_name(p_packet_data->rtp_dyn_payload, rtp_info->info_payload_type)) : NULL;
2968
15
        p_packet_data->rtp_conv_info = p_conv_data->rtp_conv_info;
2969
15
        p_packet_data->srtp_info = p_conv_data->srtp_info;
2970
15
        p_packet_data->rtp_sdp_setup_info_list = p_conv_data->rtp_sdp_setup_info_list;
2971
15
        p_packet_data->bta2dp_info = p_conv_data->bta2dp_info;
2972
15
        p_packet_data->btvdp_info = p_conv_data->btvdp_info;
2973
15
        p_add_proto_data(wmem_file_scope(), pinfo, proto_rtp, RTP_CONVERSATION_PROTO_DATA, p_packet_data);
2974
2975
15
        rtp_number_space* number_space = wmem_map_lookup(p_conv_data->ssrc_number_space, GUINT_TO_POINTER(rtp_info->info_sync_src));
2976
15
        if (number_space == NULL) {
2977
            /* Start the extended numbers up one cycle, to cope gracefully
2978
                with the first few packets being out of order. */
2979
10
            number_space = wmem_new0(wmem_file_scope(), rtp_number_space);
2980
10
            number_space->extended_seqno = 0x10000;
2981
10
            number_space->extended_timestamp = 0x100000000;
2982
10
            wmem_map_insert(p_conv_data->ssrc_number_space, GUINT_TO_POINTER(rtp_info->info_sync_src), number_space);
2983
10
        }
2984
        /* calculate extended sequence number */
2985
15
        seqno = calculate_extended_seqno(number_space->extended_seqno,
2986
15
            rtp_info->info_seq_num);
2987
2988
15
        p_packet_data->extended_seqno = seqno;
2989
15
        number_space->extended_seqno = seqno;
2990
2991
        /* calculate extended timestamp */
2992
15
        timestamp = calculate_extended_timestamp(number_space->extended_timestamp,
2993
15
            rtp_info->info_timestamp);
2994
2995
15
        p_packet_data->extended_timestamp = timestamp;
2996
15
        number_space->extended_timestamp = timestamp;
2997
15
    }
2998
28
    rtp_info->info_setup_frame_num = p_packet_data->frame_number;
2999
28
    rtp_info->info_media_types = p_packet_data->media_types;
3000
28
    rtp_info->info_extended_seq_num = p_packet_data->extended_seqno;
3001
28
    rtp_info->info_extended_timestamp = p_packet_data->extended_timestamp;
3002
28
    return p_packet_data;
3003
28
}
3004
3005
3006
/* Display setup info */
3007
static void
3008
show_setup_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
3009
28
{
3010
    /* Conversation and current data */
3011
28
    struct _rtp_packet_info *p_packet_data;
3012
28
    proto_tree *rtp_setup_tree;
3013
28
    proto_item *ti;
3014
3015
    /* Use existing packet info if available */
3016
28
    p_packet_data = (struct _rtp_packet_info *)p_get_proto_data(wmem_file_scope(), pinfo, proto_rtp, RTP_CONVERSATION_PROTO_DATA);
3017
3018
28
    if (!p_packet_data) return;
3019
3020
    /* Create setup info subtree with summary info. */
3021
28
    ti =  proto_tree_add_string_format(tree, hf_rtp_setup, tvb, 0, 0,
3022
28
                       "", "Stream setup by %s (frame %u)",
3023
28
                       p_packet_data->method,
3024
28
                       p_packet_data->frame_number);
3025
28
        proto_item_set_generated(ti);
3026
28
        rtp_setup_tree = proto_item_add_subtree(ti, ett_rtp_setup);
3027
28
        if (rtp_setup_tree)
3028
28
        {
3029
            /* Add details into subtree */
3030
28
            proto_item* item = proto_tree_add_uint(rtp_setup_tree, hf_rtp_setup_frame,
3031
28
                tvb, 0, 0, p_packet_data->frame_number);
3032
28
            proto_item_set_generated(item);
3033
28
            item = proto_tree_add_string(rtp_setup_tree, hf_rtp_setup_method,
3034
28
                tvb, 0, 0, p_packet_data->method);
3035
28
            proto_item_set_generated(item);
3036
3037
28
            if (p_packet_data->rtp_sdp_setup_info_list){
3038
0
                unsigned i;
3039
0
                sdp_setup_info_t *stored_setup_info;
3040
0
                for (i = 0; i < wmem_array_get_count(p_packet_data->rtp_sdp_setup_info_list); i++) {
3041
0
                    stored_setup_info = (sdp_setup_info_t *)wmem_array_index(p_packet_data->rtp_sdp_setup_info_list, i);
3042
0
                    if (stored_setup_info->hf_id) {
3043
0
                        if (stored_setup_info->hf_type == SDP_TRACE_ID_HF_TYPE_STR) {
3044
0
                            item = proto_tree_add_string(rtp_setup_tree, stored_setup_info->hf_id, tvb, 0, 0, stored_setup_info->trace_id.str);
3045
0
                            proto_item_set_generated(item);
3046
0
                            if (stored_setup_info->add_hidden == true) {
3047
0
                                proto_item_set_hidden(item);
3048
0
                            }
3049
0
                        } else if (stored_setup_info->hf_type == SDP_TRACE_ID_HF_TYPE_UINT32) {
3050
0
                            item = proto_tree_add_uint(rtp_setup_tree, stored_setup_info->hf_id, tvb, 0, 0, stored_setup_info->trace_id.num);
3051
0
                            proto_item_set_generated(item);
3052
0
                            if (stored_setup_info->add_hidden == true) {
3053
0
                                proto_item_set_hidden(item);
3054
0
                            }
3055
0
                        }
3056
0
                    }
3057
0
                }
3058
0
            }
3059
28
        }
3060
28
}
3061
3062
/* Dissect PacketCable CCC header */
3063
3064
static int
3065
dissect_pkt_ccc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
3066
0
{
3067
3068
0
    if ( tree ) {
3069
0
        proto_item *ti;
3070
0
        proto_tree *pkt_ccc_tree;
3071
3072
0
        ti = proto_tree_add_item(tree, proto_pkt_ccc, tvb, 0, 12, ENC_NA);
3073
0
        pkt_ccc_tree = proto_item_add_subtree(ti, ett_pkt_ccc);
3074
3075
0
        proto_tree_add_item(pkt_ccc_tree, hf_pkt_ccc_id, tvb, 0, 4, ENC_BIG_ENDIAN);
3076
0
        proto_tree_add_item(pkt_ccc_tree, hf_pkt_ccc_ts, tvb, 4, 8,
3077
0
                    ENC_TIME_NTP|ENC_BIG_ENDIAN);
3078
0
    }
3079
3080
0
    return dissect_rtp(tvb, pinfo, tree, data);
3081
0
}
3082
3083
3084
/* Register PacketCable CCC */
3085
3086
void
3087
proto_register_pkt_ccc(void)
3088
14
{
3089
14
    static hf_register_info hf[] =
3090
14
    {
3091
14
        {
3092
14
            &hf_pkt_ccc_id,
3093
14
            {
3094
14
                "PacketCable CCC Identifier",
3095
14
                "pkt_ccc.ccc_id",
3096
14
                FT_UINT32,
3097
14
                BASE_DEC,
3098
14
                NULL,
3099
14
                0x0,
3100
14
                NULL, HFILL
3101
14
            }
3102
14
        },
3103
14
        {
3104
14
            &hf_pkt_ccc_ts,
3105
14
            {
3106
14
                "PacketCable CCC Timestamp",
3107
14
                "pkt_ccc.ts",
3108
14
                FT_ABSOLUTE_TIME,
3109
14
                ABSOLUTE_TIME_UTC,
3110
14
                NULL,
3111
14
                0x0,
3112
14
                NULL, HFILL
3113
14
            }
3114
14
        },
3115
3116
14
    };
3117
3118
14
    static int *ett[] =
3119
14
    {
3120
14
        &ett_pkt_ccc,
3121
14
    };
3122
3123
14
    proto_pkt_ccc = proto_register_protocol("PacketCable Call Content Connection", "PKT CCC", "pkt_ccc");
3124
14
    proto_register_field_array(proto_pkt_ccc, hf, array_length(hf));
3125
14
    proto_register_subtree_array(ett, array_length(ett));
3126
3127
14
    register_dissector("pkt_ccc", dissect_pkt_ccc, proto_pkt_ccc);
3128
14
}
3129
3130
void
3131
proto_reg_handoff_pkt_ccc(void)
3132
14
{
3133
    /*
3134
     * Register this dissector as one that can be selected by a
3135
     * UDP port number.
3136
     */
3137
14
    dissector_handle_t pkt_ccc_handle;
3138
3139
14
    pkt_ccc_handle = find_dissector("pkt_ccc");
3140
14
    dissector_add_for_decode_as_with_preference("udp.port", pkt_ccc_handle);
3141
14
}
3142
3143
/* Register RTP */
3144
3145
void
3146
proto_register_rtp(void)
3147
14
{
3148
14
    static hf_register_info hf[] =
3149
14
    {
3150
14
        {
3151
14
            &hf_rtp_version,
3152
14
            {
3153
14
                "Version",
3154
14
                "rtp.version",
3155
14
                FT_UINT8,
3156
14
                BASE_DEC,
3157
14
                VALS(rtp_version_vals),
3158
14
                0xC0,
3159
14
                NULL, HFILL
3160
14
            }
3161
14
        },
3162
14
        {
3163
14
            &hf_rtp_padding,
3164
14
            {
3165
14
                "Padding",
3166
14
                "rtp.padding",
3167
14
                FT_BOOLEAN,
3168
14
                8,
3169
14
                NULL,
3170
14
                0x20,
3171
14
                NULL, HFILL
3172
14
            }
3173
14
        },
3174
14
        {
3175
14
            &hf_rtp_extension,
3176
14
            {
3177
14
                "Extension",
3178
14
                "rtp.ext",
3179
14
                FT_BOOLEAN,
3180
14
                8,
3181
14
                NULL,
3182
14
                0x10,
3183
14
                NULL, HFILL
3184
14
            }
3185
14
        },
3186
14
        {
3187
14
            &hf_rtp_csrc_count,
3188
14
            {
3189
14
                "Contributing source identifiers count",
3190
14
                "rtp.cc",
3191
14
                FT_UINT8,
3192
14
                BASE_DEC,
3193
14
                NULL,
3194
14
                0x0F,
3195
14
                NULL, HFILL
3196
14
            }
3197
14
        },
3198
14
        {
3199
14
            &hf_rtp_marker,
3200
14
            {
3201
14
                "Marker",
3202
14
                "rtp.marker",
3203
14
                FT_BOOLEAN,
3204
14
                8,
3205
14
                NULL,
3206
14
                0x80,
3207
14
                NULL, HFILL
3208
14
            }
3209
14
        },
3210
14
        {
3211
14
            &hf_rtp_payload_type,
3212
14
            {
3213
14
                "Payload type",
3214
14
                "rtp.p_type",
3215
14
                FT_UINT8,
3216
14
                BASE_DEC,
3217
14
                NULL,
3218
14
                0x7F,
3219
14
                NULL, HFILL
3220
14
            }
3221
14
        },
3222
14
        {
3223
14
            &hf_rtp_seq_nr,
3224
14
            {
3225
14
                "Sequence number",
3226
14
                "rtp.seq",
3227
14
                FT_UINT16,
3228
14
                BASE_DEC,
3229
14
                NULL,
3230
14
                0x0,
3231
14
                NULL, HFILL
3232
14
            }
3233
14
        },
3234
14
        {
3235
14
            &hf_rtp_ext_seq_nr,
3236
14
            {
3237
14
                "Extended sequence number",
3238
14
                "rtp.extseq",
3239
14
                FT_UINT32,
3240
14
                BASE_DEC,
3241
14
                NULL,
3242
14
                0x0,
3243
14
                NULL, HFILL
3244
14
            }
3245
14
        },
3246
14
        {
3247
14
            &hf_rtp_timestamp,
3248
14
            {
3249
14
                "Timestamp",
3250
14
                "rtp.timestamp",
3251
14
                FT_UINT32,
3252
14
                BASE_DEC,
3253
14
                NULL,
3254
14
                0x0,
3255
14
                NULL, HFILL
3256
14
            }
3257
14
        },
3258
14
        {
3259
14
            &hf_rtp_ext_timestamp,
3260
14
            {
3261
14
                "Extended timestamp",
3262
14
                "rtp.timestamp_ext",
3263
14
                FT_UINT64,
3264
14
                BASE_DEC,
3265
14
                NULL,
3266
14
                0x0,
3267
14
                NULL, HFILL
3268
14
            }
3269
14
        },
3270
14
        {
3271
14
            &hf_rtp_ssrc,
3272
14
            {
3273
14
                "Synchronization Source identifier",
3274
14
                "rtp.ssrc",
3275
14
                FT_UINT32,
3276
14
                BASE_HEX_DEC,
3277
14
                NULL,
3278
14
                0x0,
3279
14
                NULL, HFILL
3280
14
            }
3281
14
        },
3282
14
        {
3283
14
            &hf_rtp_prof_define,
3284
14
            {
3285
14
                "Defined by profile",
3286
14
                "rtp.ext.profile",
3287
14
                FT_UINT16,
3288
14
                BASE_HEX_DEC | BASE_RANGE_STRING,
3289
14
                RVALS(rtp_ext_profile_rvals),
3290
14
                0x0,
3291
14
                NULL, HFILL
3292
14
            }
3293
14
        },
3294
14
        {
3295
14
            &hf_rtp_length,
3296
14
            {
3297
14
                "Extension length",
3298
14
                "rtp.ext.len",
3299
14
                FT_UINT16,
3300
14
                BASE_DEC,
3301
14
                NULL,
3302
14
                0x0,
3303
14
                NULL, HFILL
3304
14
            }
3305
14
        },
3306
14
        {
3307
14
            &hf_rtp_csrc_items,
3308
14
            {
3309
14
                "Contributing Source identifiers",
3310
14
                "rtp.csrc.items",
3311
14
                FT_NONE,
3312
14
                BASE_NONE,
3313
14
                NULL,
3314
14
                0x0,
3315
14
                NULL, HFILL
3316
14
            }
3317
14
        },
3318
14
        {
3319
14
            &hf_rtp_csrc_item,
3320
14
            {
3321
14
                "CSRC item",
3322
14
                "rtp.csrc.item",
3323
14
                FT_UINT32,
3324
14
                BASE_HEX_DEC,
3325
14
                NULL,
3326
14
                0x0,
3327
14
                NULL, HFILL
3328
14
            }
3329
14
        },
3330
14
        {
3331
14
            &hf_rtp_hdr_exts,
3332
14
            {
3333
14
                "Header extensions",
3334
14
                "rtp.hdr_exts",
3335
14
                FT_NONE,
3336
14
                BASE_NONE,
3337
14
                NULL,
3338
14
                0x0,
3339
14
                NULL, HFILL
3340
14
            }
3341
14
        },
3342
/* Other RTP structures */
3343
14
        {
3344
14
            &hf_rtp_hdr_ext,
3345
14
            {
3346
14
                "Header extension",
3347
14
                "rtp.hdr_ext",
3348
14
                FT_UINT32,
3349
14
                BASE_HEX_DEC,
3350
14
                NULL,
3351
14
                0x0,
3352
14
                NULL, HFILL
3353
14
            }
3354
14
        },
3355
14
        {
3356
14
            &hf_rtp_data,
3357
14
            {
3358
14
                "Payload",
3359
14
                "rtp.payload",
3360
14
                FT_BYTES,
3361
14
                BASE_NONE,
3362
14
                NULL,
3363
14
                0x0,
3364
14
                NULL, HFILL
3365
14
            }
3366
14
        },
3367
14
        {
3368
14
            &hf_rtp_padding_data,
3369
14
            {
3370
14
                "Padding data",
3371
14
                "rtp.padding.data",
3372
14
                FT_BYTES,
3373
14
                BASE_NONE,
3374
14
                NULL,
3375
14
                0x0,
3376
14
                NULL, HFILL
3377
14
            }
3378
14
        },
3379
14
        {
3380
14
            &hf_rtp_padding_count,
3381
14
            {
3382
14
                "Padding count",
3383
14
                "rtp.padding.count",
3384
14
                FT_UINT8,
3385
14
                BASE_DEC,
3386
14
                NULL,
3387
14
                0x0,
3388
14
                NULL, HFILL
3389
14
            }
3390
14
        },
3391
14
        {
3392
14
            &hf_rtp_setup,
3393
14
            {
3394
14
                "Stream setup",
3395
14
                "rtp.setup",
3396
14
                FT_STRING,
3397
14
                BASE_NONE,
3398
14
                NULL,
3399
14
                0x0,
3400
14
                "Stream setup, method and frame number", HFILL
3401
14
            }
3402
14
        },
3403
14
        {
3404
14
            &hf_rtp_setup_frame,
3405
14
            {
3406
14
                "Setup frame",
3407
14
                "rtp.setup-frame",
3408
14
                FT_FRAMENUM,
3409
14
                BASE_NONE,
3410
14
                NULL,
3411
14
                0x0,
3412
14
                "Frame that set up this stream", HFILL
3413
14
            }
3414
14
        },
3415
14
        {
3416
14
            &hf_rtp_setup_method,
3417
14
            {
3418
14
                "Setup Method",
3419
14
                "rtp.setup-method",
3420
14
                FT_STRING,
3421
14
                BASE_NONE,
3422
14
                NULL,
3423
14
                0x0,
3424
14
                "Method used to set up this stream", HFILL
3425
14
            }
3426
14
        },
3427
14
        {
3428
14
            &hf_rtp_rfc2198_follow,
3429
14
            {
3430
14
                "Follow",
3431
14
                "rtp.follow",
3432
14
                FT_BOOLEAN,
3433
14
                8,
3434
14
                TFS(&tfs_set_notset),
3435
14
                0x80,
3436
14
                "Next header follows", HFILL
3437
14
            }
3438
14
        },
3439
14
        {
3440
14
            &hf_rtp_rfc2198_tm_off,
3441
14
            {
3442
14
                "Timestamp offset",
3443
14
                "rtp.timestamp-offset",
3444
14
                FT_UINT16,
3445
14
                BASE_DEC,
3446
14
                NULL,
3447
14
                0xFFFC,
3448
14
                NULL, HFILL
3449
14
            }
3450
14
        },
3451
14
        {
3452
14
            &hf_rtp_rfc2198_bl_len,
3453
14
            {
3454
14
                "Block length",
3455
14
                "rtp.block-length",
3456
14
                FT_UINT16,
3457
14
                BASE_DEC,
3458
14
                NULL,
3459
14
                0x03FF,
3460
14
                NULL, HFILL
3461
14
            }
3462
14
        },
3463
14
        {
3464
14
            &hf_rtp_ext_rfc5285_id,
3465
14
            {
3466
14
                "Identifier",
3467
14
                "rtp.ext.rfc5285.id",
3468
14
                FT_UINT8,
3469
14
                BASE_DEC,
3470
14
                NULL,
3471
14
                0x0,
3472
14
                "RFC 5285 Header Extension Identifier",
3473
14
                HFILL
3474
14
            }
3475
14
        },
3476
14
        {
3477
14
            &hf_rtp_ext_rfc5285_length,
3478
14
            {
3479
14
                "Length",
3480
14
                "rtp.ext.rfc5285.len",
3481
14
                FT_UINT8,
3482
14
                BASE_DEC,
3483
14
                NULL,
3484
14
                0x0,
3485
14
                "RFC 5285 Header Extension length",
3486
14
                HFILL
3487
14
            }
3488
14
        },
3489
14
        {
3490
14
            &hf_rtp_ext_rfc5285_appbits,
3491
14
            {
3492
14
                "Application Bits",
3493
14
                "rtp.ext.rfc5285.appbits",
3494
14
                FT_UINT8,
3495
14
                BASE_DEC,
3496
14
                NULL,
3497
14
                0x0,
3498
14
                "RFC 5285 2-bytes header application bits",
3499
14
                HFILL
3500
14
            }
3501
14
        },
3502
14
        {
3503
14
            &hf_rtp_ext_rfc5285_data,
3504
14
            {
3505
14
                "Extension Data",
3506
14
                "rtp.ext.rfc5285.data",
3507
14
                FT_BYTES,
3508
14
                BASE_NONE,
3509
14
                NULL,
3510
14
                0x0,
3511
14
                "RFC 5285 Extension Data",
3512
14
                HFILL
3513
14
            }
3514
14
        },
3515
14
        {
3516
14
            &hf_rfc4571_header_len,
3517
14
            {
3518
14
                "RFC 4571 packet len",
3519
14
                "rtp.rfc4571.len",
3520
14
                FT_UINT16,
3521
14
                BASE_DEC,
3522
14
                NULL,
3523
14
                0x0,
3524
14
                NULL, HFILL
3525
14
            }
3526
14
        },
3527
3528
        /* reassembly stuff */
3529
14
        {&hf_rtp_fragments,
3530
14
         {"RTP Fragments", "rtp.fragments", FT_NONE, BASE_NONE, NULL, 0x0,
3531
14
          NULL, HFILL }
3532
14
        },
3533
3534
14
        {&hf_rtp_fragment,
3535
14
         {"RTP Fragment data", "rtp.fragment", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
3536
14
          NULL, HFILL }
3537
14
        },
3538
3539
14
        {&hf_rtp_fragment_overlap,
3540
14
         {"Fragment overlap", "rtp.fragment.overlap", FT_BOOLEAN, BASE_NONE,
3541
14
          NULL, 0x0, "Fragment overlaps with other fragments", HFILL }
3542
14
        },
3543
3544
14
        {&hf_rtp_fragment_overlap_conflict,
3545
14
         {"Conflicting data in fragment overlap", "rtp.fragment.overlap.conflict",
3546
14
          FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3547
14
          "Overlapping fragments contained conflicting data", HFILL }
3548
14
        },
3549
3550
14
        {&hf_rtp_fragment_multiple_tails,
3551
14
         {"Multiple tail fragments found", "rtp.fragment.multipletails",
3552
14
          FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3553
14
          "Several tails were found when defragmenting the packet", HFILL }
3554
14
        },
3555
3556
14
        {&hf_rtp_fragment_too_long_fragment,
3557
14
         {"Fragment too long", "rtp.fragment.toolongfragment",
3558
14
          FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3559
14
          "Fragment contained data past end of packet", HFILL }
3560
14
        },
3561
3562
14
        {&hf_rtp_fragment_error,
3563
14
         {"Defragmentation error", "rtp.fragment.error",
3564
14
          FT_FRAMENUM, BASE_NONE, NULL, 0x0,
3565
14
          "Defragmentation error due to illegal fragments", HFILL }
3566
14
        },
3567
3568
14
        {&hf_rtp_fragment_count,
3569
14
         {"Fragment count", "rtp.fragment.count",
3570
14
          FT_UINT32, BASE_DEC, NULL, 0x0,
3571
14
          NULL, HFILL }
3572
14
        },
3573
3574
14
        {&hf_rtp_reassembled_in,
3575
14
         {"RTP fragment, reassembled in frame", "rtp.reassembled_in",
3576
14
          FT_FRAMENUM, BASE_NONE, NULL, 0x0,
3577
14
          "This RTP packet is reassembled in this frame", HFILL }
3578
14
        },
3579
14
        {&hf_rtp_reassembled_length,
3580
14
         {"Reassembled RTP length", "rtp.reassembled.length",
3581
14
          FT_UINT32, BASE_DEC, NULL, 0x0,
3582
14
          "The total length of the reassembled payload", HFILL }
3583
14
        },
3584
14
        {&hf_srtp_encrypted_payload,
3585
14
         {"SRTP Encrypted Payload", "srtp.enc_payload",
3586
14
          FT_BYTES, BASE_NONE, NULL, 0x0,
3587
14
          NULL, HFILL }
3588
14
        },
3589
#if 0
3590
        {&hf_srtp_null_encrypted_payload,
3591
         {"SRTP Payload with NULL encryption", "srtp.null_enc_payload",
3592
          FT_BYTES, BASE_NONE, NULL, 0x0,
3593
          NULL, HFILL }
3594
        },
3595
#endif
3596
14
        {&hf_srtp_mki,
3597
14
         {"SRTP MKI", "srtp.mki",
3598
14
          FT_BYTES, BASE_NONE, NULL, 0x0,
3599
14
          "SRTP Master Key Index", HFILL }
3600
14
        },
3601
14
        {&hf_srtp_auth_tag,
3602
14
         {"SRTP Auth Tag", "srtp.auth_tag",
3603
14
          FT_BYTES, BASE_NONE, NULL, 0x0,
3604
14
          "SRTP Authentication Tag", HFILL }
3605
14
        }
3606
3607
14
    };
3608
3609
14
    static int *ett[] =
3610
14
    {
3611
14
        &ett_rtp,
3612
14
        &ett_csrc_list,
3613
14
        &ett_hdr_ext,
3614
14
        &ett_hdr_ext_rfc5285,
3615
14
        &ett_rtp_setup,
3616
14
        &ett_rtp_rfc2198,
3617
14
        &ett_rtp_rfc2198_hdr,
3618
14
        &ett_rtp_fragment,
3619
14
        &ett_rtp_fragments
3620
14
    };
3621
3622
14
    static ei_register_info ei[] = {
3623
14
        { &ei_rtp_fragment_unfinished, { "rtp.fragment_unfinished", PI_REASSEMBLE, PI_CHAT, "RTP fragment, unfinished", EXPFILL }},
3624
14
        { &ei_rtp_padding_missing, { "rtp.padding_missing", PI_UNDECODED, PI_WARN, "Frame has padding, but not all the frame data was captured", EXPFILL }},
3625
14
        { &ei_rtp_padding_bogus, { "rtp.padding_bogus", PI_PROTOCOL, PI_WARN, "Frame has padding length value greater than payload length", EXPFILL }},
3626
14
    };
3627
3628
    /* Decode As handling */
3629
14
    static build_valid_func rtp_da_build_value[1] = {rtp_value};
3630
14
    static decode_as_value_t rtp_da_values = {rtp_prompt, 1, rtp_da_build_value};
3631
14
    static decode_as_t rtp_da = {"rtp", "rtp.pt", 1, 0, &rtp_da_values, NULL, NULL,
3632
14
                                decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL, NULL, NULL };
3633
3634
14
    module_t *rtp_module;
3635
14
    expert_module_t *expert_rtp;
3636
3637
14
    proto_rtp = proto_register_protocol("Real-Time Transport Protocol", "RTP", "rtp");
3638
14
    proto_rtp_rfc2198 = proto_register_protocol_in_name_only("RTP Payload for Redundant Audio Data (RFC 2198)",
3639
14
                                    "RAD (RFC2198)", "rtp_rfc2198", proto_rtp, FT_PROTOCOL);
3640
3641
14
    proto_register_field_array(proto_rtp, hf, array_length(hf));
3642
14
    proto_register_subtree_array(ett, array_length(ett));
3643
14
    expert_rtp = expert_register_protocol(proto_rtp);
3644
14
    expert_register_field_array(expert_rtp, ei, array_length(ei));
3645
3646
14
    rtp_handle = register_dissector("rtp", dissect_rtp, proto_rtp);
3647
14
    rtp_rfc2198_handle = register_dissector("rtp.rfc2198", dissect_rtp_rfc2198, proto_rtp_rfc2198);
3648
14
    rtp_rfc4571_handle = register_dissector("rtp.rfc4571", dissect_rtp_rfc4571, proto_rtp);
3649
3650
14
    rtp_tap = register_tap("rtp");
3651
3652
14
    rtp_pt_dissector_table = register_dissector_table("rtp.pt",
3653
14
                                    "RTP payload type", proto_rtp, FT_UINT8, BASE_DEC);
3654
14
    rtp_dyn_pt_dissector_table = register_dissector_table("rtp_dyn_payload_type",
3655
14
                                    "Dynamic RTP payload type", proto_rtp, FT_STRING, STRING_CASE_INSENSITIVE);
3656
3657
3658
14
    rtp_hdr_ext_dissector_table = register_dissector_table("rtp.hdr_ext",
3659
14
                                    "RTP header extension", proto_rtp, FT_UINT32, BASE_HEX);
3660
14
    rtp_hdr_ext_rfc5285_dissector_table = register_dissector_table("rtp.ext.rfc5285.id",
3661
14
                                    "RTP Generic header extension (RFC 5285)", proto_rtp, FT_UINT8, BASE_DEC);
3662
3663
14
    rtp_module = prefs_register_protocol(proto_rtp, NULL);
3664
3665
14
    prefs_register_bool_preference(rtp_module, "show_setup_info",
3666
14
                                    "Show stream setup information",
3667
14
                                    "Where available, show which protocol and frame caused "
3668
14
                                    "this RTP stream to be created",
3669
14
                                    &global_rtp_show_setup_info);
3670
3671
14
    prefs_register_obsolete_preference(rtp_module, "heuristic_rtp");
3672
3673
14
    prefs_register_bool_preference(rtp_module, "desegment_rtp_streams",
3674
14
                                    "Allow subdissector to reassemble RTP streams",
3675
14
                                    "Whether subdissector can request RTP streams to be reassembled",
3676
14
                                    &desegment_rtp);
3677
3678
14
    prefs_register_enum_preference(rtp_module, "version0_type",
3679
14
                                    "Treat RTP version 0 packets as",
3680
14
                                    "If an RTP version 0 packet is encountered, it can be treated as "
3681
14
                                    "an invalid or ZRTP packet, a CLASSIC-STUN packet, or a T.38 packet",
3682
14
                                    &global_rtp_version0_type,
3683
14
                                    rtp_version0_types, false);
3684
14
    prefs_register_obsolete_preference(rtp_module, "rfc2198_payload_type");
3685
3686
14
    prefs_register_bool_preference(rtp_module, "rfc2198_deencapsulate",
3687
14
                                    "De-encapsulate RFC 2198 primary encoding",
3688
14
                                    "De-encapsulate the primary encoding from "
3689
14
                                    "the RAD header for RTP analysis and "
3690
14
                                    "playback",
3691
14
                                    &rfc2198_deencapsulate);
3692
3693
14
    reassembly_table_register(&rtp_reassembly_table,
3694
14
                  &addresses_reassembly_table_functions);
3695
3696
14
    register_init_routine(rtp_dyn_payloads_init);
3697
14
    register_decode_as(&rtp_da);
3698
3699
14
    register_external_value_string_ext("rtp_payload_type_vals_ext", &rtp_payload_type_vals_ext);
3700
14
    register_external_value_string_ext("rtp_payload_type_short_vals_ext", &rtp_payload_type_short_vals_ext);
3701
14
}
3702
3703
void
3704
proto_reg_handoff_rtp(void)
3705
14
{
3706
14
    dissector_add_for_decode_as("udp.port", rtp_handle);
3707
14
    dissector_add_for_decode_as("tcp.port", rtp_rfc4571_handle);
3708
14
    dissector_add_string("rtp_dyn_payload_type", "red", rtp_rfc2198_handle);
3709
14
    heur_dissector_add( "udp", dissect_rtp_heur,  "RTP over UDP", "rtp_udp", proto_rtp, HEURISTIC_DISABLE);
3710
14
    heur_dissector_add("stun", dissect_rtp_heur, "RTP over TURN", "rtp_stun", proto_rtp, HEURISTIC_DISABLE);
3711
14
    heur_dissector_add("classicstun", dissect_rtp_heur, "RTP over CLASSICSTUN", "rtp_classicstun", proto_rtp, HEURISTIC_DISABLE);
3712
14
    heur_dissector_add("rtsp", dissect_rtp_heur, "RTP over RTSP", "rtp_rtsp", proto_rtp, HEURISTIC_DISABLE);
3713
3714
14
    dissector_add_for_decode_as("flip.payload", rtp_handle );
3715
3716
3717
14
    rtcp_handle = find_dissector_add_dependency("rtcp", proto_rtp);
3718
14
    stun_handle = find_dissector_add_dependency("stun-udp", proto_rtp);
3719
14
    classicstun_handle = find_dissector_add_dependency("classicstun", proto_rtp);
3720
14
    t38_handle = find_dissector_add_dependency("t38_udp", proto_rtp);
3721
14
    zrtp_handle = find_dissector_add_dependency("zrtp", proto_rtp);
3722
14
    dtls_handle = find_dissector_add_dependency("dtls", proto_rtp);
3723
3724
14
    sprt_handle = find_dissector_add_dependency("sprt", proto_rtp);
3725
14
    v150fw_handle = find_dissector("v150fw");
3726
3727
14
    bta2dp_content_protection_header_scms_t = find_dissector_add_dependency("bta2dp_content_protection_header_scms_t", proto_rtp);
3728
14
    btvdp_content_protection_header_scms_t = find_dissector_add_dependency("btvdp_content_protection_header_scms_t", proto_rtp);
3729
14
    bta2dp_handle = find_dissector_add_dependency("bta2dp", proto_rtp);
3730
14
    btvdp_handle = find_dissector_add_dependency("btvdp", proto_rtp);
3731
14
    sbc_handle = find_dissector_add_dependency("sbc", proto_rtp);
3732
3733
14
    dissector_add_string("rtp_dyn_payload_type", "v150fw", v150fw_handle);
3734
14
    dissector_add_for_decode_as("rtp.pt", v150fw_handle);
3735
3736
14
    dissector_add_for_decode_as("btl2cap.cid", rtp_handle);
3737
3738
14
    dissector_add_uint_range_with_preference("rtp.pt", RFC2198_DEFAULT_PT_RANGE, rtp_rfc2198_handle);
3739
14
    proto_sdp = proto_get_id_by_filter_name("sdp");
3740
14
}
3741
3742
/*
3743
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
3744
 *
3745
 * Local variables:
3746
 * c-basic-offset: 4
3747
 * tab-width: 8
3748
 * indent-tabs-mode: nil
3749
 * End:
3750
 *
3751
 * vi: set shiftwidth=4 tabstop=8 expandtab:
3752
 * :indentSize=4:tabSize=8:noTabs=true:
3753
 */