6ab66a1c31e1bb1e609cda28391637db626151b3
[metze/wireshark/wip.git] / epan / dissectors / packet-rtp.c
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  * $Id$
10  *
11  * Wireshark - Network traffic analyzer
12  * By Gerald Combs <gerald@wireshark.org>
13  * Copyright 1998 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28  */
29
30 /*
31  * This dissector tries to dissect the RTP protocol according to Annex A
32  * of ITU-T Recommendation H.225.0 (02/98) or RFC 1889
33  *
34  * RTP traffic is handled by an even UDP portnumber. This can be any
35  * port number, but there is a registered port available, port 5004
36  * See Annex B of ITU-T Recommendation H.225.0, section B.7
37  *
38  * This doesn't dissect older versions of RTP, such as:
39  *
40  *    the vat protocol ("version 0") - see
41  *
42  *      ftp://ftp.ee.lbl.gov/conferencing/vat/alpha-test/vatsrc-4.0b2.tar.gz
43  *
44  *    and look in "session-vat.cc" if you want to write a dissector
45  *    (have fun - there aren't any nice header files showing the packet
46  *    format);
47  *
48  *    version 1, as documented in
49  *
50  *      ftp://gaia.cs.umass.edu/pub/hgschulz/rtp/draft-ietf-avt-rtp-04.txt
51  *
52  * It also dissects PacketCable CCC-encapsulated RTP data, as described in
53  * chapter 5 of the PacketCable Electronic Surveillance Specification:
54  *
55  *   http://www.packetcable.com/downloads/specs/PKT-SP-ESP1.5-I01-050128.pdf
56  */
57
58
59 #ifdef HAVE_CONFIG_H
60 # include "config.h"
61 #endif
62
63 #include <epan/packet.h>
64
65 #include "packet-rtp.h"
66 #include <epan/rtp_pt.h>
67 #include <epan/conversation.h>
68 #include <epan/reassemble.h>
69 #include <epan/tap.h>
70
71 #include <epan/prefs.h>
72 #include <epan/emem.h>
73 #include <epan/strutil.h>
74
75 /* uncomment this to enable debugging of fragment reassembly */
76 /* #define DEBUG_FRAGMENTS   1 */
77
78 typedef struct _rfc2198_hdr {
79         unsigned int pt;
80         int offset;
81         int len;
82         struct _rfc2198_hdr *next;
83 } rfc2198_hdr;
84
85 /* we have one of these for each pdu which spans more than one segment
86  */
87 typedef struct _rtp_multisegment_pdu {
88         /* the seqno of the segment where the pdu starts */
89         guint32 startseq;
90
91         /* the seqno of the segment where the pdu ends */
92         guint32 endseq;
93 } rtp_multisegment_pdu;
94
95 typedef struct  _rtp_private_conv_info {
96         /* This tree is indexed by sequence number and keeps track of all
97          * all pdus spanning multiple segments for this flow.
98          */
99         emem_tree_t *multisegment_pdus;
100 } rtp_private_conv_info;
101
102 static GHashTable *fragment_table = NULL;
103
104 static int hf_rtp_fragments = -1;
105 static int hf_rtp_fragment = -1;
106 static int hf_rtp_fragment_overlap = -1;
107 static int hf_rtp_fragment_overlap_conflict = -1;
108 static int hf_rtp_fragment_multiple_tails = -1;
109 static int hf_rtp_fragment_too_long_fragment = -1;
110 static int hf_rtp_fragment_error = -1;
111 static int hf_rtp_fragment_count = -1;
112 static int hf_rtp_reassembled_in = -1;
113 static int hf_rtp_reassembled_length = -1;
114
115 static gint ett_rtp_fragment = -1;
116 static gint ett_rtp_fragments = -1;
117
118 static const fragment_items rtp_fragment_items = {
119         &ett_rtp_fragment,
120         &ett_rtp_fragments,
121         &hf_rtp_fragments,
122         &hf_rtp_fragment,
123         &hf_rtp_fragment_overlap,
124         &hf_rtp_fragment_overlap_conflict,
125         &hf_rtp_fragment_multiple_tails,
126         &hf_rtp_fragment_too_long_fragment,
127         &hf_rtp_fragment_error,
128         &hf_rtp_fragment_count,
129         &hf_rtp_reassembled_in,
130         &hf_rtp_reassembled_length,
131         "RTP fragments"
132 };
133
134 static dissector_handle_t rtp_handle;
135 static dissector_handle_t classicstun_handle;
136 static dissector_handle_t classicstun_heur_handle;
137 static dissector_handle_t t38_handle;
138 static dissector_handle_t zrtp_handle;
139
140 static dissector_handle_t sprt_handle;
141 static dissector_handle_t v150fw_handle;
142
143 static int rtp_tap = -1;
144
145 static dissector_table_t rtp_pt_dissector_table;
146 static dissector_table_t rtp_dyn_pt_dissector_table;
147
148 static dissector_table_t rtp_hdr_ext_dissector_table;
149 static dissector_table_t rtp_hdr_ext_rfc5285_dissector_table;
150
151 /* RTP header fields             */
152 static int proto_rtp           = -1;
153 static int hf_rtp_version      = -1;
154 static int hf_rtp_padding      = -1;
155 static int hf_rtp_extension    = -1;
156 static int hf_rtp_csrc_count   = -1;
157 static int hf_rtp_marker       = -1;
158 static int hf_rtp_payload_type = -1;
159 static int hf_rtp_seq_nr       = -1;
160 static int hf_rtp_ext_seq_nr   = -1;
161 static int hf_rtp_timestamp    = -1;
162 static int hf_rtp_ssrc         = -1;
163 static int hf_rtp_csrc_items   = -1;
164 static int hf_rtp_csrc_item    = -1;
165 static int hf_rtp_data         = -1;
166 static int hf_rtp_padding_data = -1;
167 static int hf_rtp_padding_count= -1;
168 static int hf_rtp_rfc2198_follow= -1;
169 static int hf_rtp_rfc2198_tm_off= -1;
170 static int hf_rtp_rfc2198_bl_len= -1;
171
172 /* RTP header extension fields   */
173 static int hf_rtp_prof_define  = -1;
174 static int hf_rtp_length       = -1;
175 static int hf_rtp_hdr_exts     = -1;
176 static int hf_rtp_hdr_ext      = -1;
177
178 /* RTP setup fields */
179 static int hf_rtp_setup        = -1;
180 static int hf_rtp_setup_frame  = -1;
181 static int hf_rtp_setup_method = -1;
182
183 /* RTP fields defining a sub tree */
184 static gint ett_rtp       = -1;
185 static gint ett_csrc_list = -1;
186 static gint ett_hdr_ext   = -1;
187 static gint ett_hdr_ext_rfc5285 = -1;
188 static gint ett_rtp_setup = -1;
189 static gint ett_rtp_rfc2198 = -1;
190 static gint ett_rtp_rfc2198_hdr = -1;
191
192 /* SRTP fields */
193 static int hf_srtp_encrypted_payload = -1;
194 static int hf_srtp_mki = -1;
195 static int hf_srtp_auth_tag = -1;
196
197 /* PacketCable CCC header fields */
198 static int proto_pkt_ccc       = -1;
199 static int hf_pkt_ccc_id       = -1;
200 static int hf_pkt_ccc_ts       = -1;
201
202 /* PacketCable CCC field defining a sub tree */
203 static gint ett_pkt_ccc = -1;
204
205 /* PacketCable CCC port preference */
206 static guint global_pkt_ccc_udp_port = 0;
207
208 /* RFC 5285 Header extensions */
209 static int hf_rtp_ext_rfc5285_id = -1;
210 static int hf_rtp_ext_rfc5285_length = -1;
211 static int hf_rtp_ext_rfc5285_appbits = -1;
212 static int hf_rtp_ext_rfc5285_data = -1;
213
214 #define RTP0_INVALID 0
215 #define RTP0_CLASSICSTUN    1
216 #define RTP0_T38     2
217 #define RTP0_SPRT    3
218
219 static enum_val_t rtp_version0_types[] = {
220         { "invalid", "Invalid or ZRTP packets", RTP0_INVALID },
221         { "classicstun", "CLASSIC-STUN packets", RTP0_CLASSICSTUN },
222         { "t38", "T.38 packets", RTP0_T38 },
223         { "sprt", "SPRT packets", RTP0_SPRT },
224         { NULL, NULL, 0 }
225 };
226 static gint global_rtp_version0_type = 0;
227
228 static dissector_handle_t data_handle;
229
230 /* Forward declaration we need below */
231 void proto_reg_handoff_rtp(void);
232 void proto_reg_handoff_pkt_ccc(void);
233
234 static void dissect_rtp( tvbuff_t *tvb, packet_info *pinfo,
235     proto_tree *tree );
236 static void show_setup_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
237 static void get_conv_info(packet_info *pinfo, struct _rtp_info *rtp_info);
238
239 /* Preferences bool to control whether or not setup info should be shown */
240 static gboolean global_rtp_show_setup_info = TRUE;
241
242 /* Try heuristic RTP decode */
243 static gboolean global_rtp_heur = FALSE;
244
245 /* desegment RTP streams */
246 static gboolean desegment_rtp = TRUE;
247
248 /* RFC2198 Redundant Audio Data */
249 static guint rtp_rfc2198_pt = 99;
250
251 /*
252  * Fields in the first octet of the RTP header.
253  */
254
255 /* Version is the first 2 bits of the first octet*/
256 #define RTP_VERSION(octet)      ((octet) >> 6)
257
258 /* Padding is the third bit; No need to shift, because true is any value
259    other than 0! */
260 #define RTP_PADDING(octet)      ((octet) & 0x20)
261
262 /* Extension bit is the fourth bit */
263 #define RTP_EXTENSION(octet)    ((octet) & 0x10)
264
265 /* CSRC count is the last four bits */
266 #define RTP_CSRC_COUNT(octet)   ((octet) & 0xF)
267
268 static const value_string rtp_version_vals[] =
269 {
270         { 2, "RFC 1889 Version" }, /* First for speed */
271         { 0, "Old VAT Version" },
272         { 1, "First Draft Version" },
273         { 0, NULL },
274 };
275
276 /*
277  * Fields in the second octet of the RTP header.
278  */
279
280 /* Marker is the first bit of the second octet */
281 #define RTP_MARKER(octet)       ((octet) & 0x80)
282
283 /* Payload type is the last 7 bits */
284 #define RTP_PAYLOAD_TYPE(octet) ((octet) & 0x7F)
285 /* http://www.iana.org/assignments/rtp-parameters */
286
287 static const value_string rtp_payload_type_vals[] =
288 {
289 /*  0 */        { PT_PCMU,                      "ITU-T G.711 PCMU" },
290 /*  1 */        { PT_1016,                      "USA Federal Standard FS-1016" },
291 /*  2 */        { PT_G721,                      "ITU-T G.721" },
292 /*  3 */        { PT_GSM,                       "GSM 06.10" },
293 /*  4 */        { PT_G723,                      "ITU-T G.723" },
294 /*  5 */        { PT_DVI4_8000,         "DVI4 8000 samples/s" },
295 /*  6 */        { PT_DVI4_16000,        "DVI4 16000 samples/s" },
296 /*  7 */        { PT_LPC,                       "Experimental linear predictive encoding from Xerox PARC" },
297 /*  8 */        { PT_PCMA,                      "ITU-T G.711 PCMA" },
298 /*  9 */        { PT_G722,                      "ITU-T G.722" },
299 /* 10 */        { PT_L16_STEREO,        "16-bit uncompressed audio, stereo" },
300 /* 11 */        { PT_L16_MONO,          "16-bit uncompressed audio, monaural" },
301 /* 12 */        { PT_QCELP,                     "Qualcomm Code Excited Linear Predictive coding" },
302 /* 13 */        { PT_CN,                        "Comfort noise" },
303 /* 14 */        { PT_MPA,                       "MPEG-I/II Audio"},
304 /* 15 */        { PT_G728,                      "ITU-T G.728" },
305 /* 16 */        { PT_DVI4_11025,        "DVI4 11025 samples/s" },
306 /* 17 */        { PT_DVI4_22050,        "DVI4 22050 samples/s" },
307 /* 18 */        { PT_G729,                      "ITU-T G.729" },
308 /* 19 */        { PT_CN_OLD,            "Comfort noise (old)" },
309 /* 20 */        { 20,                           "Unassigned" },
310 /* 21 */        { 21,                           "Unassigned" },
311 /* 22 */        { 22,                           "Unassigned" },
312 /* 23 */        { 23,                           "Unassigned" },
313 /* 24 */        { 24,                           "Unassigned" },
314 /* 25 */        { PT_CELB,                      "Sun CellB video encoding" },
315 /* 26 */        { PT_JPEG,                      "JPEG-compressed video" },
316 /* 27 */        { 27,                           "Unassigned" },
317 /* 28 */        { PT_NV,                        "'nv' program" },
318 /* 29 */        { 29,                           "Unassigned" },
319 /* 30 */        { 30,                           "Unassigned" },
320 /* 31 */        { PT_H261,                      "ITU-T H.261" },
321 /* 32 */        { PT_MPV,                       "MPEG-I/II Video"},
322 /* 33 */        { PT_MP2T,                      "MPEG-II transport streams"},
323 /* 34 */        { PT_H263,                      "ITU-T H.263" },
324 /* 35-71     Unassigned  */
325 /* 35 */        { 35,                           "Unassigned" },
326 /* 36 */        { 36,                           "Unassigned" },
327 /* 37 */        { 37,                           "Unassigned" },
328 /* 38 */        { 38,                           "Unassigned" },
329 /* 39 */        { 39,                           "Unassigned" },
330 /* 40 */        { 40,                           "Unassigned" },
331 /* 41 */        { 41,                           "Unassigned" },
332 /* 42 */        { 42,                           "Unassigned" },
333 /* 43 */        { 43,                           "Unassigned" },
334 /* 44 */        { 44,                           "Unassigned" },
335 /* 45 */        { 45,                           "Unassigned" },
336 /* 46 */        { 46,                           "Unassigned" },
337 /* 47 */        { 47,                           "Unassigned" },
338 /* 48 */        { 48,                           "Unassigned" },
339 /* 49 */        { 49,                           "Unassigned" },
340 /* 50 */        { 50,                           "Unassigned" },
341 /* 51 */        { 51,                           "Unassigned" },
342 /* 52 */        { 52,                           "Unassigned" },
343 /* 53 */        { 53,                           "Unassigned" },
344 /* 54 */        { 54,                           "Unassigned" },
345 /* 55 */        { 55,                           "Unassigned" },
346 /* 56 */        { 56,                           "Unassigned" },
347 /* 57 */        { 57,                           "Unassigned" },
348 /* 58 */        { 58,                           "Unassigned" },
349 /* 59 */        { 59,                           "Unassigned" },
350 /* 60 */        { 60,                           "Unassigned" },
351 /* 61 */        { 61,                           "Unassigned" },
352 /* 62 */        { 62,                           "Unassigned" },
353 /* 63 */        { 63,                           "Unassigned" },
354 /* 64 */        { 64,                           "Unassigned" },
355 /* 65 */        { 65,                           "Unassigned" },
356 /* 66 */        { 66,                           "Unassigned" },
357 /* 67 */        { 67,                           "Unassigned" },
358 /* 68 */        { 68,                           "Unassigned" },
359 /* 69 */        { 69,                           "Unassigned" },
360 /* 70 */        { 70,                           "Unassigned" },
361 /* 71 */        { 71,                           "Unassigned" },
362 /* 72-76     Reserved for RTCP conflict avoidance                                  [RFC3551] */
363 /* 72 */        { 72,                           "Reserved for RTCP conflict avoidance" },
364 /* 73 */        { 73,                           "Reserved for RTCP conflict avoidance" },
365 /* 74 */        { 74,                           "Reserved for RTCP conflict avoidance" },
366 /* 75 */        { 75,                           "Reserved for RTCP conflict avoidance" },
367 /* 76 */        { 76,                           "Reserved for RTCP conflict avoidance" },
368 /* 77-95     Unassigned      ? */
369 /* 77 */        { 77,                           "Unassigned" },
370 /* 78 */        { 78,                           "Unassigned" },
371 /* 79 */        { 79,                           "Unassigned" },
372 /* 80 */        { 80,                           "Unassigned" },
373 /* 81 */        { 81,                           "Unassigned" },
374 /* 82 */        { 82,                           "Unassigned" },
375 /* 83 */        { 83,                           "Unassigned" },
376 /* 84 */        { 84,                           "Unassigned" },
377 /* 85 */        { 85,                           "Unassigned" },
378 /* 86 */        { 86,                           "Unassigned" },
379 /* 87 */        { 87,                           "Unassigned" },
380 /* 88 */        { 88,                           "Unassigned" },
381 /* 89 */        { 89,                           "Unassigned" },
382 /* 90 */        { 90,                           "Unassigned" },
383 /* 91 */        { 91,                           "Unassigned" },
384 /* 92 */        { 92,                           "Unassigned" },
385 /* 93 */        { 93,                           "Unassigned" },
386 /* 94 */        { 94,                           "Unassigned" },
387 /* 95 */        { 95,                           "Unassigned" },
388                 /* Added to support addtional RTP payload types
389                  * See epan/rtp_pt.h */
390                 { PT_UNDF_96,   "DynamicRTP-Type-96" },
391                 { PT_UNDF_97,   "DynamicRTP-Type-97" },
392                 { PT_UNDF_98,   "DynamicRTP-Type-98" },
393                 { PT_UNDF_99,   "DynamicRTP-Type-99" },
394                 { PT_UNDF_100,  "DynamicRTP-Type-100" },
395                 { PT_UNDF_101,  "DynamicRTP-Type-101" },
396                 { PT_UNDF_102,  "DynamicRTP-Type-102" },
397                 { PT_UNDF_103,  "DynamicRTP-Type-103" },
398                 { PT_UNDF_104,  "DynamicRTP-Type-104" },
399                 { PT_UNDF_105,  "DynamicRTP-Type-105" },
400                 { PT_UNDF_106,  "DynamicRTP-Type-106" },
401                 { PT_UNDF_107,  "DynamicRTP-Type-107" },
402                 { PT_UNDF_108,  "DynamicRTP-Type-108" },
403                 { PT_UNDF_109,  "DynamicRTP-Type-109" },
404                 { PT_UNDF_110,  "DynamicRTP-Type-110" },
405                 { PT_UNDF_111,  "DynamicRTP-Type-111" },
406                 { PT_UNDF_112,  "DynamicRTP-Type-112" },
407                 { PT_UNDF_113,  "DynamicRTP-Type-113" },
408                 { PT_UNDF_114,  "DynamicRTP-Type-114" },
409                 { PT_UNDF_115,  "DynamicRTP-Type-115" },
410                 { PT_UNDF_116,  "DynamicRTP-Type-116" },
411                 { PT_UNDF_117,  "DynamicRTP-Type-117" },
412                 { PT_UNDF_118,  "DynamicRTP-Type-118" },
413                 { PT_UNDF_119,  "DynamicRTP-Type-119" },
414                 { PT_UNDF_120,  "DynamicRTP-Type-120" },
415                 { PT_UNDF_121,  "DynamicRTP-Type-121" },
416                 { PT_UNDF_122,  "DynamicRTP-Type-122" },
417                 { PT_UNDF_123,  "DynamicRTP-Type-123" },
418                 { PT_UNDF_124,  "DynamicRTP-Type-124" },
419                 { PT_UNDF_125,  "DynamicRTP-Type-125" },
420                 { PT_UNDF_126,  "DynamicRTP-Type-126" },
421                 { PT_UNDF_127,  "DynamicRTP-Type-127" },
422
423                 { 0,            NULL },
424 };
425
426 value_string_ext rtp_payload_type_vals_ext = VALUE_STRING_EXT_INIT(rtp_payload_type_vals);
427
428 static const value_string rtp_payload_type_short_vals[] =
429 {
430         { PT_PCMU,      "g711U" },
431         { PT_1016,      "fs-1016" },
432         { PT_G721,      "g721" },
433         { PT_GSM,       "GSM" },
434         { PT_G723,      "g723" },
435         { PT_DVI4_8000, "DVI4 8k" },
436         { PT_DVI4_16000, "DVI4 16k" },
437         { PT_LPC,       "Exp. from Xerox PARC" },
438         { PT_PCMA,      "g711A" },
439         { PT_G722,      "g722" },
440         { PT_L16_STEREO, "16-bit audio, stereo" },
441         { PT_L16_MONO,  "16-bit audio, monaural" },
442         { PT_QCELP,     "Qualcomm" },
443         { PT_CN,        "CN" },
444         { PT_MPA,       "MPEG-I/II Audio"},
445         { PT_G728,      "g728" },
446         { PT_DVI4_11025, "DVI4 11k" },
447         { PT_DVI4_22050, "DVI4 22k" },
448         { PT_G729,      "g729" },
449         { PT_CN_OLD,    "CN(old)" },
450         { 20,                           "Unassigned" },
451         { 21,                           "Unassigned" },
452         { 22,                           "Unassigned" },
453         { 23,                           "Unassigned" },
454         { 24,                           "Unassigned" },
455         { PT_CELB,      "CellB" },
456         { PT_JPEG,      "JPEG" },
457         { 27,                           "Unassigned" },
458         { PT_NV,        "NV" },
459         { 29,                           "Unassigned" },
460         { 30,                           "Unassigned" },
461         { PT_H261,      "h261" },
462         { PT_MPV,       "MPEG-I/II Video"},
463         { PT_MP2T,      "MPEG-II streams"},
464         { PT_H263,      "h263" },
465 /* 35-71     Unassigned  */
466         { 35,                           "Unassigned" },
467         { 36,                           "Unassigned" },
468         { 37,                           "Unassigned" },
469         { 38,                           "Unassigned" },
470         { 39,                           "Unassigned" },
471         { 40,                           "Unassigned" },
472         { 41,                           "Unassigned" },
473         { 42,                           "Unassigned" },
474         { 43,                           "Unassigned" },
475         { 44,                           "Unassigned" },
476         { 45,                           "Unassigned" },
477         { 46,                           "Unassigned" },
478         { 47,                           "Unassigned" },
479         { 48,                           "Unassigned" },
480         { 49,                           "Unassigned" },
481         { 50,                           "Unassigned" },
482         { 51,                           "Unassigned" },
483         { 52,                           "Unassigned" },
484         { 53,                           "Unassigned" },
485         { 54,                           "Unassigned" },
486         { 55,                           "Unassigned" },
487         { 56,                           "Unassigned" },
488         { 57,                           "Unassigned" },
489         { 58,                           "Unassigned" },
490         { 59,                           "Unassigned" },
491         { 60,                           "Unassigned" },
492         { 61,                           "Unassigned" },
493         { 62,                           "Unassigned" },
494         { 63,                           "Unassigned" },
495         { 64,                           "Unassigned" },
496         { 65,                           "Unassigned" },
497         { 66,                           "Unassigned" },
498         { 67,                           "Unassigned" },
499         { 68,                           "Unassigned" },
500         { 69,                           "Unassigned" },
501         { 70,                           "Unassigned" },
502         { 71,                           "Unassigned" },
503 /* 72-76     Reserved for RTCP conflict avoidance  - [RFC3551] */
504         { 72,                           "Reserved for RTCP conflict avoidance" },
505         { 73,                           "Reserved for RTCP conflict avoidance" },
506         { 74,                           "Reserved for RTCP conflict avoidance" },
507         { 75,                           "Reserved for RTCP conflict avoidance" },
508         { 76,                           "Reserved for RTCP conflict avoidance" },
509 /* 77-95     Unassigned      ? */
510         { 77,                           "Unassigned" },
511         { 78,                           "Unassigned" },
512         { 79,                           "Unassigned" },
513         { 80,                           "Unassigned" },
514         { 81,                           "Unassigned" },
515         { 82,                           "Unassigned" },
516         { 83,                           "Unassigned" },
517         { 84,                           "Unassigned" },
518         { 85,                           "Unassigned" },
519         { 86,                           "Unassigned" },
520         { 87,                           "Unassigned" },
521         { 88,                           "Unassigned" },
522         { 89,                           "Unassigned" },
523         { 90,                           "Unassigned" },
524         { 91,                           "Unassigned" },
525         { 92,                           "Unassigned" },
526         { 93,                           "Unassigned" },
527         { 94,                           "Unassigned" },
528         { 95,                           "Unassigned" },
529         /* Short RTP types */
530         { PT_UNDF_96,   "RTPType-96" },
531         { PT_UNDF_97,   "RTPType-97" },
532         { PT_UNDF_98,   "RTPType-98" },
533         { PT_UNDF_99,   "RTPType-99" },
534         { PT_UNDF_100,  "RTPType-100" },
535         { PT_UNDF_101,  "RTPType-101" },
536         { PT_UNDF_102,  "RTPType-102" },
537         { PT_UNDF_103,  "RTPType-103" },
538         { PT_UNDF_104,  "RTPType-104" },
539         { PT_UNDF_105,  "RTPType-105" },
540         { PT_UNDF_106,  "RTPType-106" },
541         { PT_UNDF_107,  "RTPType-107" },
542         { PT_UNDF_108,  "RTPType-108" },
543         { PT_UNDF_109,  "RTPType-109" },
544         { PT_UNDF_110,  "RTPType-110" },
545         { PT_UNDF_111,  "RTPType-111" },
546         { PT_UNDF_112,  "RTPType-112" },
547         { PT_UNDF_113,  "RTPType-113" },
548         { PT_UNDF_114,  "RTPType-114" },
549         { PT_UNDF_115,  "RTPType-115" },
550         { PT_UNDF_116,  "RTPType-116" },
551         { PT_UNDF_117,  "RTPType-117" },
552         { PT_UNDF_118,  "RTPType-118" },
553         { PT_UNDF_119,  "RTPType-119" },
554         { PT_UNDF_120,  "RTPType-120" },
555         { PT_UNDF_121,  "RTPType-121" },
556         { PT_UNDF_122,  "RTPType-122" },
557         { PT_UNDF_123,  "RTPType-123" },
558         { PT_UNDF_124,  "RTPType-124" },
559         { PT_UNDF_125,  "RTPType-125" },
560         { PT_UNDF_126,  "RTPType-126" },
561         { PT_UNDF_127,  "RTPType-127" },
562
563         { 0,            NULL },
564 };
565 value_string_ext rtp_payload_type_short_vals_ext = VALUE_STRING_EXT_INIT(rtp_payload_type_short_vals);
566
567 #if 0
568 static const value_string srtp_encryption_alg_vals[] =
569 {
570         { SRTP_ENC_ALG_NULL,    "Null Encryption" },
571         { SRTP_ENC_ALG_AES_CM,  "AES-128 Counter Mode" },
572         { SRTP_ENC_ALG_AES_F8,  "AES-128 F8 Mode" },
573         { 0, NULL },
574 };
575
576 static const value_string srtp_auth_alg_vals[] =
577 {
578         { SRTP_AUTH_ALG_NONE,           "No Authentication" },
579         { SRTP_AUTH_ALG_HMAC_SHA1,      "HMAC-SHA1" },
580         { 0, NULL },
581 };
582 #endif
583
584 /* initialisation routine */
585 static void
586 rtp_fragment_init(void)
587 {
588         fragment_table_init(&fragment_table);
589 }
590
591 void
592 rtp_free_hash_dyn_payload(GHashTable *rtp_dyn_payload)
593 {
594         if (rtp_dyn_payload == NULL) return;
595         g_hash_table_destroy(rtp_dyn_payload);
596         rtp_dyn_payload = NULL;
597 }
598
599 /* Set up an SRTP conversation */
600 void
601 srtp_add_address(packet_info *pinfo, address *addr, int port, int other_port,
602                  const gchar *setup_method, guint32 setup_frame_number,
603                  gboolean is_video _U_, GHashTable *rtp_dyn_payload,
604                  struct srtp_info *srtp_info)
605 {
606         address null_addr;
607         conversation_t* p_conv;
608         struct _rtp_conversation_info *p_conv_data = NULL;
609
610         /*
611          * If this isn't the first time this packet has been processed,
612          * we've already done this work, so we don't need to do it
613          * again.
614          */
615         if (pinfo->fd->flags.visited)
616         {
617                 return;
618         }
619
620 #ifdef DEBUG
621         printf("#%u: %srtp_add_address(%s, %u, %u, %s, %u\n",
622                 pinfo->fd->num, (srtp_info)?"s":"", ep_address_to_str(addr), port,
623                 other_port, setup_method, setup_frame_number);
624 #endif
625
626         SET_ADDRESS(&null_addr, AT_NONE, 0, NULL);
627
628         /*
629          * Check if the ip address and port combination is not
630          * already registered as a conversation.
631          */
632         p_conv = find_conversation(setup_frame_number, addr, &null_addr, PT_UDP, port, other_port,
633                                    NO_ADDR_B | (!other_port ? NO_PORT_B : 0));
634
635         /*
636          * If not, create a new conversation.
637          */
638         if (!p_conv || p_conv->setup_frame != setup_frame_number) {
639                 p_conv = conversation_new(setup_frame_number, addr, &null_addr, PT_UDP,
640                                           (guint32)port, (guint32)other_port,
641                                           NO_ADDR2 | (!other_port ? NO_PORT2 : 0));
642         }
643
644         /* Set dissector */
645         conversation_set_dissector(p_conv, rtp_handle);
646
647         /*
648          * Check if the conversation has data associated with it.
649          */
650         p_conv_data = conversation_get_proto_data(p_conv, proto_rtp);
651
652         /*
653          * If not, add a new data item.
654          */
655         if (! p_conv_data) {
656                 /* Create conversation data */
657                 p_conv_data = se_alloc(sizeof(struct _rtp_conversation_info));
658                 p_conv_data->rtp_dyn_payload = NULL;
659
660                 /* start this at 0x10000 so that we cope gracefully with the
661                  * first few packets being out of order (hence 0,65535,1,2,...)
662                  */
663                 p_conv_data->extended_seqno = 0x10000;
664                 p_conv_data->rtp_conv_info = se_alloc(sizeof(rtp_private_conv_info));
665                 p_conv_data->rtp_conv_info->multisegment_pdus = se_tree_create(EMEM_TREE_TYPE_RED_BLACK,"rtp_ms_pdus");
666                 conversation_add_proto_data(p_conv, proto_rtp, p_conv_data);
667         }
668
669         /*
670          * Update the conversation data.
671          */
672         /* Free the hash if already exists */
673         rtp_free_hash_dyn_payload(p_conv_data->rtp_dyn_payload);
674
675         g_strlcpy(p_conv_data->method, setup_method, MAX_RTP_SETUP_METHOD_SIZE+1);
676         p_conv_data->frame_number = setup_frame_number;
677         p_conv_data->is_video = is_video;
678         p_conv_data->rtp_dyn_payload = rtp_dyn_payload;
679         p_conv_data->srtp_info = srtp_info;
680 }
681
682 /* Set up an RTP conversation */
683 void
684 rtp_add_address(packet_info *pinfo, address *addr, int port, int other_port,
685                 const gchar *setup_method, guint32 setup_frame_number,
686                 gboolean is_video , GHashTable *rtp_dyn_payload)
687 {
688         srtp_add_address(pinfo, addr, port, other_port, setup_method, setup_frame_number, is_video, rtp_dyn_payload, NULL);
689 }
690
691 static gboolean
692 dissect_rtp_heur_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean check_destport)
693 {
694         guint8       octet1;
695         unsigned int version;
696         unsigned int offset = 0;
697
698         /* This is a heuristic dissector, which means we get all the UDP
699          * traffic not sent to a known dissector and not claimed by
700          * a heuristic dissector called before us!
701          */
702
703         if (! global_rtp_heur)
704                 return FALSE;
705
706         /* Get the fields in the first octet */
707         octet1 = tvb_get_guint8( tvb, offset );
708         version = RTP_VERSION( octet1 );
709
710         if (version == 0) {
711                 if (!(tvb_memeql(tvb, 4, "ZRTP", 4)))
712                 {
713                         call_dissector_only(zrtp_handle, tvb, pinfo, tree);
714                         return TRUE;
715                 } else {
716                         switch (global_rtp_version0_type) {
717                         case RTP0_CLASSICSTUN:
718                                 return call_dissector_only(classicstun_heur_handle, tvb, pinfo, tree);
719
720                         case RTP0_T38:
721                                 /* XXX: Should really be calling a heuristic dissector for T38 ??? */
722                                 call_dissector_only(t38_handle, tvb, pinfo, tree);
723                                 return TRUE;
724
725                         case RTP0_SPRT:
726                                 call_dissector_only(sprt_handle, tvb, pinfo, tree);
727                                 return TRUE;
728
729                         case RTP0_INVALID:
730
731                         default:
732                                 return FALSE; /* Unknown or unsupported version */
733                         }
734                 }
735         } else if (version != 2) {
736                 /* Unknown or unsupported version */
737                 return FALSE;
738         }
739
740         /* Was it sent to an even-numbered port? */
741         if (check_destport && ((pinfo->destport % 2) != 0)) {
742                 return FALSE;
743         }
744
745         dissect_rtp( tvb, pinfo, tree );
746         return TRUE;
747 }
748
749 static gboolean
750 dissect_rtp_heur_udp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
751 {
752         return dissect_rtp_heur_common(tvb, pinfo, tree, TRUE);
753 }
754
755 static gboolean
756 dissect_rtp_heur_stun( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
757 {
758         return dissect_rtp_heur_common(tvb, pinfo, tree, FALSE);
759 }
760
761 /*
762  * Process the payload of the RTP packet, hand it to the subdissector
763  */
764 static void
765 process_rtp_payload(tvbuff_t *newtvb, packet_info *pinfo, proto_tree *tree,
766                     proto_tree *rtp_tree,
767                     unsigned int payload_type)
768 {
769         struct _rtp_conversation_info *p_conv_data = NULL;
770         gboolean found_match = FALSE;
771         int payload_len;
772         struct srtp_info *srtp_info;
773         int offset=0;
774
775         payload_len = tvb_length_remaining(newtvb, offset);
776
777         /* first check if this is added as an SRTP stream - if so, don't try to dissector the payload data for now */
778         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
779         if (p_conv_data && p_conv_data->srtp_info) {
780                 srtp_info = p_conv_data->srtp_info;
781                 payload_len -= srtp_info->mki_len + srtp_info->auth_tag_len;
782 #if 0
783 #error Currently the srtp_info structure contains no cipher data, see packet-sdp.c adding dummy_srtp_info structure
784                 if (p_conv_data->srtp_info->encryption_algorithm==SRTP_ENC_ALG_NULL) {
785                         if (rtp_tree)
786                                 proto_tree_add_text(rtp_tree, newtvb, offset, payload_len, "SRTP Payload with NULL encryption");
787                 }
788                 else
789 #endif
790                 {
791                         if (rtp_tree)
792                                 proto_tree_add_item(rtp_tree, hf_srtp_encrypted_payload, newtvb, offset, payload_len, ENC_NA);
793                         found_match = TRUE;     /* use this flag to prevent dissection below */
794                 }
795                 offset += payload_len;
796
797                 if (srtp_info->mki_len) {
798                         proto_tree_add_item(rtp_tree, hf_srtp_mki, newtvb, offset, srtp_info->mki_len, ENC_NA);
799                         offset += srtp_info->mki_len;
800                 }
801
802                 if (srtp_info->auth_tag_len) {
803                         proto_tree_add_item(rtp_tree, hf_srtp_auth_tag, newtvb, offset, srtp_info->auth_tag_len, ENC_NA);
804                         offset += srtp_info->auth_tag_len;
805                 }
806         }
807
808         /* if the payload type is dynamic, we check if the conv is set and we look for the pt definition */
809         else if ( (payload_type >= PT_UNDF_96 && payload_type <= PT_UNDF_127) ) {
810                 if (p_conv_data && p_conv_data->rtp_dyn_payload) {
811                         gchar *payload_type_str = NULL;
812                         encoding_name_and_rate_t *encoding_name_and_rate_pt = NULL;
813                         encoding_name_and_rate_pt = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &payload_type);
814                         if (encoding_name_and_rate_pt) {
815                                 payload_type_str = encoding_name_and_rate_pt->encoding_name;
816                         }
817                         if (payload_type_str){
818                                 found_match = dissector_try_string(rtp_dyn_pt_dissector_table,
819                                                                    payload_type_str, newtvb, pinfo, tree);
820                                 /* If payload type string set from conversation and
821                                  * no matching dissector found it's probably because no subdissector
822                                  * exists. Don't call the dissectors based on payload number
823                                  * as that'd probably be the wrong dissector in this case.
824                                  * Just add it as data.
825                                  */
826                                 if(found_match==FALSE)
827                                         proto_tree_add_item( rtp_tree, hf_rtp_data, newtvb, 0, -1, ENC_NA );
828                                 return;
829                         }
830
831                 }
832         }
833
834         /* if we don't found, it is static OR could be set static from the preferences */
835         if (!found_match && !dissector_try_uint(rtp_pt_dissector_table, payload_type, newtvb, pinfo, tree))
836                 proto_tree_add_item( rtp_tree, hf_rtp_data, newtvb, 0, -1, ENC_NA );
837
838 }
839
840 /* Rtp payload reassembly
841  *
842  * This handles the reassembly of PDUs for higher-level protocols.
843  *
844  * We're a bit limited on how we can cope with out-of-order packets, because
845  * we don't have any idea of where the datagram boundaries are. So if we see
846  * packets A, C, B (all of which comprise a single datagram), we cannot know
847  * that C should be added to the same datagram as A, until we come to B (which
848  * may or may not actually be present...).
849  *
850  * What we end up doing in this case is passing A+B to the subdissector as one
851  * datagram, and make out that a new one starts on C.
852  */
853 static void
854 dissect_rtp_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
855                  proto_tree *rtp_tree, int offset, unsigned int data_len,
856                  unsigned int data_reported_len,
857                  unsigned int payload_type)
858 {
859         tvbuff_t *newtvb;
860         struct _rtp_conversation_info *p_conv_data= NULL;
861         gboolean must_desegment = FALSE;
862         rtp_private_conv_info *finfo = NULL;
863         rtp_multisegment_pdu *msp = NULL;
864         guint32 seqno;
865
866         /* Retrieve RTPs idea of a converation */
867         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
868
869         if(p_conv_data != NULL)
870                 finfo = p_conv_data->rtp_conv_info;
871
872         if(finfo == NULL || !desegment_rtp) {
873                 /* Hand the whole lot off to the subdissector */
874                 newtvb=tvb_new_subset(tvb,offset,data_len,data_reported_len);
875                 process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type);
876                 return;
877         }
878
879         seqno = p_conv_data->extended_seqno;
880
881         pinfo->can_desegment = 2;
882         pinfo->desegment_offset = 0;
883         pinfo->desegment_len = 0;
884
885 #ifdef DEBUG_FRAGMENTS
886         g_debug("%d: RTP Part of convo %d(%p); seqno %d",
887                 pinfo->fd->num,
888                 p_conv_data->frame_number, p_conv_data,
889                 seqno
890                 );
891 #endif
892
893         /* look for a pdu which we might be extending */
894         msp = (rtp_multisegment_pdu *)se_tree_lookup32_le(finfo->multisegment_pdus,seqno-1);
895
896         if(msp && msp->startseq < seqno && msp->endseq >= seqno) {
897                 guint32 fid = msp->startseq;
898                 fragment_data *fd_head;
899
900 #ifdef DEBUG_FRAGMENTS
901                 g_debug("\tContinues fragment %d", fid);
902 #endif
903
904                 /* we always assume the datagram is complete; if this is the
905                  * first pass, that's our best guess, and if it's not, what we
906                  * say gets ignored anyway.
907                  */
908                 fd_head = fragment_add_seq(tvb, offset, pinfo, fid, fragment_table,
909                                            seqno-msp->startseq, data_len, FALSE);
910
911                 newtvb = process_reassembled_data(tvb,offset, pinfo, "Reassembled RTP", fd_head,
912                                                   &rtp_fragment_items, NULL, tree);
913
914 #ifdef DEBUG_FRAGMENTS
915                 g_debug("\tFragment Coalesced; fd_head=%p, newtvb=%p (len %d)",fd_head, newtvb,
916                         newtvb?tvb_reported_length(newtvb):0);
917 #endif
918
919                 if(newtvb != NULL) {
920                         /* Hand off to the subdissector */
921                         process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type);
922
923                         /*
924                          * Check to see if there were any complete fragments within the chunk
925                          */
926                         if( pinfo->desegment_len && pinfo->desegment_offset == 0 )
927                         {
928 #ifdef DEBUG_FRAGMENTS
929                                 g_debug("\tNo complete pdus in payload" );
930 #endif
931                                 /* Mark the fragments and not complete yet */
932                                 fragment_set_partial_reassembly(pinfo, fid, fragment_table);
933
934                                 /* we must need another segment */
935                                 msp->endseq = MIN(msp->endseq,seqno) + 1;
936                         }
937                         else
938                         {
939                                 if(pinfo->desegment_len)
940                                 {
941                                         /* the higher-level dissector has asked for some more data - ie,
942                                            the end of this segment does not coincide with the end of a
943                                            higher-level PDU. */
944                                         must_desegment = TRUE;
945                                 }
946                         }
947
948                 }
949
950         }
951         else
952         {
953                 /*
954                  * The segment is not the continuation of a fragmented segment
955                  * so process it as normal
956                  */
957 #ifdef DEBUG_FRAGMENTS
958                 g_debug("\tRTP non-fragment payload");
959 #endif
960                 newtvb = tvb_new_subset( tvb, offset, data_len, data_reported_len );
961
962                 /* Hand off to the subdissector */
963                 process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type);
964
965                 if(pinfo->desegment_len) {
966                         /* the higher-level dissector has asked for some more data - ie,
967                            the end of this segment does not coincide with the end of a
968                            higher-level PDU. */
969                         must_desegment = TRUE;
970                 }
971         }
972
973         /*
974          * There were bytes left over that the higher protocol couldn't dissect so save them
975          */
976         if(must_desegment)
977         {
978                 guint32 deseg_offset = pinfo->desegment_offset;
979                 guint32 frag_len = tvb_reported_length_remaining(newtvb, deseg_offset);
980                 fragment_data *fd_head = NULL;
981
982 #ifdef DEBUG_FRAGMENTS
983                 g_debug("\tRTP Must Desegment: tvb_len=%d ds_len=%d %d frag_len=%d ds_off=%d",
984                         tvb_reported_length(newtvb),
985                         pinfo->desegment_len,
986                         pinfo->fd->flags.visited,
987                         frag_len,
988                         deseg_offset);
989 #endif
990                 /* allocate a new msp for this pdu */
991                 msp = se_alloc(sizeof(rtp_multisegment_pdu));
992                 msp->startseq = seqno;
993                 msp->endseq = seqno+1;
994                 se_tree_insert32(finfo->multisegment_pdus,seqno,msp);
995
996                 /*
997                  * Add the fragment to the fragment table
998                  */
999                 fd_head = fragment_add_seq(newtvb,deseg_offset, pinfo, seqno, fragment_table, 0, frag_len,
1000                                            TRUE );
1001
1002                 if(fd_head != NULL)
1003                 {
1004                         if( fd_head->reassembled_in != 0 && !(fd_head->flags & FD_PARTIAL_REASSEMBLY) )
1005                         {
1006                                 proto_item *rtp_tree_item;
1007                                 rtp_tree_item = proto_tree_add_uint( tree, hf_rtp_reassembled_in,
1008                                                                      newtvb, deseg_offset, tvb_reported_length_remaining(newtvb,deseg_offset),
1009                                                                      fd_head->reassembled_in);
1010                                 PROTO_ITEM_SET_GENERATED(rtp_tree_item);
1011 #ifdef DEBUG_FRAGMENTS
1012                                 g_debug("\tReassembled in %d", fd_head->reassembled_in);
1013 #endif
1014                         }
1015                         else
1016                         {
1017 #ifdef DEBUG_FRAGMENTS
1018                                 g_debug("\tUnfinished fragment");
1019 #endif
1020                                 /* this fragment is never reassembled */
1021                                 proto_tree_add_text( tree, tvb, deseg_offset, -1,"RTP fragment, unfinished");
1022                         }
1023                 }
1024                 else
1025                 {
1026                         /*
1027                          * This fragment was the first fragment in a new entry in the
1028                          * frag_table; we don't yet know where it is reassembled
1029                          */
1030 #ifdef DEBUG_FRAGMENTS
1031                         g_debug("\tnew pdu");
1032 #endif
1033                 }
1034
1035                 if( pinfo->desegment_offset == 0 )
1036                 {
1037                         col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTP");
1038                         col_set_str(pinfo->cinfo, COL_INFO, "[RTP segment of a reassembled PDU]");
1039                 }
1040         }
1041
1042         pinfo->can_desegment = 0;
1043         pinfo->desegment_offset = 0;
1044         pinfo->desegment_len = 0;
1045 }
1046
1047
1048
1049 static void
1050 dissect_rtp_rfc2198(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1051 {
1052         int offset = 0;
1053         guint8 octet1;
1054         int cnt;
1055         gboolean hdr_follow = TRUE;
1056         proto_item *ti = NULL;
1057         proto_tree *rfc2198_tree = NULL;
1058         proto_tree *rfc2198_hdr_tree = NULL;
1059         rfc2198_hdr *hdr_last, *hdr_new;
1060         rfc2198_hdr *hdr_chain = NULL;
1061         struct _rtp_conversation_info *p_conv_data= NULL;
1062         gchar *payload_type_str;
1063
1064         /* Retrieve RTPs idea of a converation */
1065         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
1066
1067         /* Add try to RFC 2198 data */
1068         ti = proto_tree_add_text(tree, tvb, offset, -1, "RFC 2198: Redundant Audio Data");
1069         rfc2198_tree = proto_item_add_subtree(ti, ett_rtp_rfc2198);
1070
1071         hdr_last = NULL;
1072         cnt = 0;
1073         while (hdr_follow) {
1074                 cnt++;
1075                 payload_type_str = NULL;
1076
1077                 /* Allocate and fill in header */
1078                 hdr_new = ep_alloc(sizeof(rfc2198_hdr));
1079                 hdr_new->next = NULL;
1080                 octet1 = tvb_get_guint8(tvb, offset);
1081                 hdr_new->pt = RTP_PAYLOAD_TYPE(octet1);
1082                 hdr_follow = (octet1 & 0x80);
1083
1084                 /* if it is dynamic payload, let use the conv data to see if it is defined */
1085                 if ((hdr_new->pt > 95) && (hdr_new->pt < 128)) {
1086                         if (p_conv_data && p_conv_data->rtp_dyn_payload){
1087                                 encoding_name_and_rate_t *encoding_name_and_rate_pt = NULL;
1088                                 encoding_name_and_rate_pt = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &hdr_new->pt);
1089                                 if (encoding_name_and_rate_pt) {
1090                                         payload_type_str = encoding_name_and_rate_pt->encoding_name;
1091                                 }
1092                         }
1093                 }
1094                 /* Add a subtree for this header and add items */
1095                 ti = proto_tree_add_text(rfc2198_tree, tvb, offset, (hdr_follow)?4:1, "Header %u", cnt);
1096                 rfc2198_hdr_tree = proto_item_add_subtree(ti, ett_rtp_rfc2198_hdr);
1097                 proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_follow, tvb, offset, 1, ENC_BIG_ENDIAN );
1098                 proto_tree_add_uint_format(rfc2198_hdr_tree, hf_rtp_payload_type, tvb,
1099                     offset, 1, octet1, "Payload type: %s (%u)",
1100                         payload_type_str ? payload_type_str : val_to_str_ext_const(hdr_new->pt, &rtp_payload_type_vals_ext, "Unknown"),
1101                         hdr_new->pt);
1102                 proto_item_append_text(ti, ": PT=%s",
1103                                        payload_type_str ? payload_type_str :
1104                                                           val_to_str_ext(hdr_new->pt, &rtp_payload_type_vals_ext, "Unknown (%u)"));
1105                 offset += 1;
1106
1107                 /* Timestamp offset and block length don't apply to last header */
1108                 if (hdr_follow) {
1109                         proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_tm_off, tvb, offset, 2, ENC_BIG_ENDIAN );
1110                         proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_bl_len, tvb, offset + 1, 2, ENC_BIG_ENDIAN );
1111                         hdr_new->len = tvb_get_ntohs(tvb, offset + 1) & 0x03FF;
1112                         proto_item_append_text(ti, ", len=%u", hdr_new->len);
1113                         offset += 3;
1114                 } else {
1115                         hdr_new->len = -1;
1116                         hdr_follow = FALSE;
1117                 }
1118
1119                 if (hdr_last) {
1120                         hdr_last->next = hdr_new;
1121                 } else {
1122                         hdr_chain = hdr_new;
1123                 }
1124                 hdr_last = hdr_new;
1125         }
1126
1127         /* Dissect each data block according to the header info */
1128         hdr_last = hdr_chain;
1129         while (hdr_last) {
1130                 hdr_last->offset = offset;
1131                 if (!hdr_last->next) {
1132                         hdr_last->len = tvb_reported_length_remaining(tvb, offset);
1133                 }
1134                 dissect_rtp_data(tvb, pinfo, tree, rfc2198_tree, hdr_last->offset, hdr_last->len, hdr_last->len, hdr_last->pt);
1135                 offset += hdr_last->len;
1136                 hdr_last = hdr_last->next;
1137         }
1138 }
1139
1140 static void
1141 dissect_rtp_hext_rfc5215_onebyte( tvbuff_t *tvb, packet_info *pinfo,
1142     proto_tree *rtp_hext_tree )
1143 {
1144         proto_item *ti = NULL;
1145         proto_tree *rtp_hext_rfc5285_tree = NULL;
1146         guint ext_offset = 0, start_ext_offset;
1147
1148         while (ext_offset < tvb_length (tvb)) {
1149                 guint8 ext_hdr_hdr;
1150                 guint8 ext_id;
1151                 guint8 ext_length;
1152                 tvbuff_t *subtvb = NULL;
1153
1154                 /* Skip bytes with the value 0, they are padding */
1155                 start_ext_offset = ext_offset;
1156                 while (tvb_get_guint8 (tvb, ext_offset) == 0) {
1157                         if (ext_offset >= tvb_length (tvb))
1158                                 return;
1159                         ext_offset ++;
1160                 }
1161
1162                 /* Add padding */
1163                 if (ext_offset > start_ext_offset)
1164                         proto_tree_add_item(rtp_hext_tree, hf_rtp_padding_data, tvb, ext_offset, ext_offset-start_ext_offset, ENC_NA );
1165
1166                 ext_hdr_hdr = tvb_get_guint8 (tvb, ext_offset);
1167                 ext_id = ext_hdr_hdr >> 4;
1168
1169                 /* 15 is for future extensibility, ignore length, etc and stop processing packet if it shows up */
1170                 if (ext_id == 15)
1171                         return;
1172
1173                 ext_length = (ext_hdr_hdr & 0x0F) + 1;
1174                 if (rtp_hext_tree) {
1175                         ti = proto_tree_add_text(rtp_hext_tree, tvb, ext_offset, ext_length + 1, "RFC 5285 Header Extension (One-Byte Header)");
1176                         rtp_hext_rfc5285_tree = proto_item_add_subtree( ti, ett_hdr_ext_rfc5285);
1177
1178                         proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_id, tvb, ext_offset, 1, ext_id);
1179                         proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_length, tvb, ext_offset, 1, ext_length);
1180                 }
1181                 ext_offset ++;
1182
1183                 subtvb = tvb_new_subset(tvb, ext_offset, ext_length, ext_length);
1184                 if (!dissector_try_uint (rtp_hdr_ext_rfc5285_dissector_table, ext_id, subtvb, pinfo, rtp_hext_rfc5285_tree)) {
1185                         if (rtp_hext_tree) 
1186                                 proto_tree_add_item(rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_data, subtvb, 0, ext_length, ENC_NA );
1187                 }
1188
1189                 ext_offset += ext_length;
1190         }
1191 }
1192
1193
1194 static void
1195 dissect_rtp_hext_rfc5215_twobytes(tvbuff_t *parent_tvb, guint id_offset,
1196     guint8 id, tvbuff_t *tvb, packet_info *pinfo, proto_tree *rtp_hext_tree)
1197 {
1198         proto_item *ti = NULL;
1199         proto_tree *rtp_hext_rfc5285_tree = NULL;
1200         guint ext_offset = 0, start_ext_offset;
1201
1202         while (ext_offset + 2 < tvb_length (tvb)) {
1203                 guint8 ext_id;
1204                 guint8 ext_length;
1205                 tvbuff_t *subtvb = NULL;
1206
1207                 /* Skip bytes with the value 0, they are padding */
1208                 start_ext_offset = ext_offset;
1209                 while (tvb_get_guint8 (tvb, ext_offset) == 0) {
1210                         if (ext_offset + 2 >= tvb_length (tvb))
1211                                 return;
1212                         ext_offset ++;
1213                 }
1214                 /* Add padding */
1215                 if (ext_offset > start_ext_offset)
1216                         proto_tree_add_item(rtp_hext_tree, hf_rtp_padding_data, tvb, ext_offset, ext_offset-start_ext_offset, ENC_NA );
1217
1218                 ext_id = tvb_get_guint8 (tvb, ext_offset);
1219                 ext_length = tvb_get_guint8 (tvb, ext_offset + 1);
1220
1221                 if (rtp_hext_tree) {
1222                         ti = proto_tree_add_text(rtp_hext_tree, tvb, ext_offset, ext_length + 2, "RFC 5285 Header Extension (Two-Byte Header)");
1223                         rtp_hext_rfc5285_tree = proto_item_add_subtree( ti, ett_hdr_ext_rfc5285);
1224
1225                         proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_appbits, parent_tvb, id_offset + 1, 1, id & 0x000F);
1226                         proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_id, tvb, ext_offset, 1, ext_id);
1227                         proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_length, tvb, ext_offset + 1, 1, ext_length);
1228                 }
1229
1230                 ext_offset += 2;
1231
1232                 subtvb = tvb_new_subset(tvb, ext_offset, ext_length, ext_length);
1233                 if (ext_length && !dissector_try_uint (rtp_hdr_ext_rfc5285_dissector_table, ext_id, subtvb, pinfo, rtp_hext_rfc5285_tree)) {
1234                         proto_tree_add_item(rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_data, subtvb, 0, ext_length, ENC_NA );
1235                 }
1236
1237                 ext_offset += ext_length;
1238         }
1239 }
1240
1241 static void
1242 dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
1243 {
1244         proto_item *ti            = NULL;
1245         proto_tree *rtp_tree      = NULL;
1246         proto_tree *rtp_csrc_tree = NULL;
1247         proto_tree *rtp_hext_tree = NULL;
1248         guint8      octet1, octet2;
1249         unsigned int version;
1250         gboolean    padding_set;
1251         gboolean    extension_set;
1252         unsigned int csrc_count;
1253         gboolean    marker_set;
1254         unsigned int payload_type;
1255         gchar *payload_type_str = NULL;
1256         gboolean    is_srtp = FALSE;
1257         unsigned int i            = 0;
1258         unsigned int hdr_extension= 0;
1259         unsigned int hdr_extension_id = 0;
1260         unsigned int padding_count;
1261         gint        length, reported_length;
1262         int         data_len;
1263         unsigned int offset = 0;
1264         guint16     seq_num;
1265         guint32     timestamp;
1266         guint32     sync_src;
1267         guint32     csrc_item;
1268         struct _rtp_conversation_info *p_conv_data = NULL;
1269         /*struct srtp_info *srtp_info = NULL;*/
1270         /*unsigned int srtp_offset;*/
1271         unsigned int hdrext_offset = 0;
1272         tvbuff_t *newtvb = NULL;
1273
1274         /* Can tap up to 4 RTP packets within same packet */
1275         static struct _rtp_info rtp_info_arr[4];
1276         static int rtp_info_current=0;
1277         struct _rtp_info *rtp_info;
1278
1279         rtp_info_current++;
1280         if (rtp_info_current==4) {
1281                 rtp_info_current=0;
1282         }
1283         rtp_info = &rtp_info_arr[rtp_info_current];
1284
1285         /* Get the fields in the first octet */
1286         octet1 = tvb_get_guint8( tvb, offset );
1287         version = RTP_VERSION( octet1 );
1288
1289         if (version == 0) {
1290                 switch (global_rtp_version0_type) {
1291                 case RTP0_CLASSICSTUN:
1292                         call_dissector(classicstun_handle, tvb, pinfo, tree);
1293                         return;
1294
1295                 case RTP0_T38:
1296                         call_dissector(t38_handle, tvb, pinfo, tree);
1297                         return;
1298
1299                 case RTP0_SPRT:
1300                         call_dissector(sprt_handle, tvb, pinfo, tree);
1301                         return;
1302
1303                 case RTP0_INVALID:
1304                         if (!(tvb_memeql(tvb, 4, "ZRTP", 4)))
1305                         {
1306                                 call_dissector(zrtp_handle,tvb,pinfo,tree);
1307                                 return;
1308                         }
1309                 default:
1310                         ; /* Unknown or unsupported version (let it fall through) */
1311                 }
1312         }
1313
1314         /* fill in the rtp_info structure */
1315         rtp_info->info_version = version;
1316         if (version != 2) {
1317                 /*
1318                  * Unknown or unsupported version.
1319                  */
1320                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTP");
1321
1322                 col_add_fstr( pinfo->cinfo, COL_INFO,
1323                     "Unknown RTP version %u", version);
1324
1325                 if ( tree ) {
1326                         ti = proto_tree_add_item( tree, proto_rtp, tvb, offset, -1, ENC_NA );
1327                         rtp_tree = proto_item_add_subtree( ti, ett_rtp );
1328
1329                         proto_tree_add_uint( rtp_tree, hf_rtp_version, tvb,
1330                             offset, 1, octet1);
1331                 }
1332                 return;
1333         }
1334
1335         padding_set = RTP_PADDING( octet1 );
1336         extension_set = RTP_EXTENSION( octet1 );
1337         csrc_count = RTP_CSRC_COUNT( octet1 );
1338
1339         /* Get the fields in the second octet */
1340         octet2 = tvb_get_guint8( tvb, offset + 1 );
1341         marker_set = RTP_MARKER( octet2 );
1342         payload_type = RTP_PAYLOAD_TYPE( octet2 );
1343
1344         /* Get the subsequent fields */
1345         seq_num = tvb_get_ntohs( tvb, offset + 2 );
1346         timestamp = tvb_get_ntohl( tvb, offset + 4 );
1347         sync_src = tvb_get_ntohl( tvb, offset + 8 );
1348
1349         /* fill in the rtp_info structure */
1350         rtp_info->info_padding_set = padding_set;
1351         rtp_info->info_padding_count = 0;
1352         rtp_info->info_marker_set = marker_set;
1353         rtp_info->info_is_video = FALSE;
1354         rtp_info->info_payload_type = payload_type;
1355         rtp_info->info_seq_num = seq_num;
1356         rtp_info->info_timestamp = timestamp;
1357         rtp_info->info_sync_src = sync_src;
1358         rtp_info->info_is_srtp = FALSE;
1359         rtp_info->info_setup_frame_num = 0;
1360         rtp_info->info_payload_type_str = NULL;
1361         rtp_info->info_payload_rate = 0;
1362
1363         /*
1364          * Do we have all the data?
1365          */
1366         length = tvb_length_remaining(tvb, offset);
1367         reported_length = tvb_reported_length_remaining(tvb, offset);
1368         if (reported_length >= 0 && length >= reported_length) {
1369                 /*
1370                  * Yes.
1371                  */
1372                 rtp_info->info_all_data_present = TRUE;
1373                 rtp_info->info_data_len = reported_length;
1374
1375                 /*
1376                  * Save the pointer to raw rtp data (header + payload incl.
1377                  * padding).
1378                  * That should be safe because the "epan_dissect_t"
1379                  * constructed for the packet has not yet been freed when
1380                  * the taps are called.
1381                  * (Destroying the "epan_dissect_t" will end up freeing
1382                  * all the tvbuffs and hence invalidating pointers to
1383                  * their data.)
1384                  * See "add_packet_to_packet_list()" for details.
1385                  */
1386                 rtp_info->info_data = tvb_get_ptr(tvb, 0, -1);
1387         } else {
1388                 /*
1389                  * No - packet was cut short at capture time.
1390                  */
1391                 rtp_info->info_all_data_present = FALSE;
1392                 rtp_info->info_data_len = 0;
1393                 rtp_info->info_data = NULL;
1394         }
1395
1396         /* Look for conv and add to the frame if found */
1397         get_conv_info(pinfo, rtp_info);
1398         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
1399
1400         if (p_conv_data)
1401                 rtp_info->info_is_video = p_conv_data->is_video;
1402
1403         if (p_conv_data && p_conv_data->srtp_info) is_srtp = TRUE;
1404         rtp_info->info_is_srtp = is_srtp;
1405
1406         col_set_str( pinfo->cinfo, COL_PROTOCOL, (is_srtp) ? "SRTP" : "RTP" );
1407
1408         /* check if this is added as an SRTP stream - if so, don't try to dissect the payload data for now */
1409         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
1410
1411 #if 0 /* XXX: srtp_offset never actually used ?? */
1412         if (p_conv_data && p_conv_data->srtp_info) {
1413                 srtp_info = p_conv_data->srtp_info;
1414                 if (rtp_info->info_all_data_present) {
1415                         srtp_offset = rtp_info->info_data_len - srtp_info->mki_len - srtp_info->auth_tag_len;
1416                 }
1417         }
1418 #endif
1419
1420         /* if it is dynamic payload, let use the conv data to see if it is defined */
1421         if ( (payload_type>95) && (payload_type<128) ) {
1422                 if (p_conv_data && p_conv_data->rtp_dyn_payload){
1423                         encoding_name_and_rate_t *encoding_name_and_rate_pt = NULL;
1424                         encoding_name_and_rate_pt = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &payload_type);
1425                         if (encoding_name_and_rate_pt) {
1426                                 rtp_info->info_payload_type_str = payload_type_str = encoding_name_and_rate_pt->encoding_name;
1427                                 rtp_info->info_payload_rate = encoding_name_and_rate_pt->sample_rate;
1428                         }
1429                 }
1430         }
1431
1432         col_add_fstr( pinfo->cinfo, COL_INFO,
1433             "PT=%s, SSRC=0x%X, Seq=%u, Time=%u%s",
1434                 payload_type_str ? payload_type_str : val_to_str_ext( payload_type, &rtp_payload_type_vals_ext,"Unknown (%u)" ),
1435             sync_src,
1436             seq_num,
1437             timestamp,
1438             marker_set ? ", Mark " : " ");
1439
1440
1441         if ( tree ) {
1442                 proto_tree *item;
1443                 /* Create RTP protocol tree */
1444                 ti = proto_tree_add_item(tree, proto_rtp, tvb, offset, -1, ENC_NA );
1445                 rtp_tree = proto_item_add_subtree(ti, ett_rtp );
1446
1447                 /* Conversation setup info */
1448                 if (global_rtp_show_setup_info)
1449                 {
1450                         show_setup_info(tvb, pinfo, rtp_tree);
1451                 }
1452
1453                 proto_tree_add_uint( rtp_tree, hf_rtp_version, tvb,
1454                     offset, 1, octet1 );
1455                 proto_tree_add_boolean( rtp_tree, hf_rtp_padding, tvb,
1456                     offset, 1, octet1 );
1457                 proto_tree_add_boolean( rtp_tree, hf_rtp_extension, tvb,
1458                     offset, 1, octet1 );
1459                 proto_tree_add_uint( rtp_tree, hf_rtp_csrc_count, tvb,
1460                     offset, 1, octet1 );
1461                 offset++;
1462
1463                 proto_tree_add_boolean( rtp_tree, hf_rtp_marker, tvb, offset,
1464                     1, octet2 );
1465
1466                 proto_tree_add_uint_format( rtp_tree, hf_rtp_payload_type, tvb,
1467                     offset, 1, octet2, "Payload type: %s (%u)",
1468                         payload_type_str ? payload_type_str : val_to_str_ext_const( payload_type, &rtp_payload_type_vals_ext,"Unknown"),
1469                         payload_type);
1470
1471                 offset++;
1472
1473                 /* Sequence number 16 bits (2 octets) */
1474                 proto_tree_add_uint( rtp_tree, hf_rtp_seq_nr, tvb, offset, 2, seq_num );
1475                 if(p_conv_data != NULL) {
1476                         item = proto_tree_add_uint( rtp_tree, hf_rtp_ext_seq_nr, tvb, offset, 2, p_conv_data->extended_seqno );
1477                         PROTO_ITEM_SET_GENERATED(item);
1478                 }
1479                 offset += 2;
1480
1481                 /* Timestamp 32 bits (4 octets) */
1482                 proto_tree_add_uint( rtp_tree, hf_rtp_timestamp, tvb, offset, 4, timestamp );
1483                 offset += 4;
1484
1485                 /* Synchronization source identifier 32 bits (4 octets) */
1486                 proto_tree_add_uint( rtp_tree, hf_rtp_ssrc, tvb, offset, 4, sync_src );
1487                 offset += 4;
1488         } else {
1489                 offset += 12;
1490         }
1491         /* CSRC list*/
1492         if ( csrc_count > 0 ) {
1493                 if ( tree ) {
1494                         ti = proto_tree_add_item(rtp_tree, hf_rtp_csrc_items, tvb, offset,
1495                                                  csrc_count * 4, ENC_NA);
1496                         proto_item_append_text(ti, " (%u items)", csrc_count);
1497                         rtp_csrc_tree = proto_item_add_subtree( ti, ett_csrc_list );
1498                 }
1499                 for (i = 0; i < csrc_count; i++ ) {
1500                         csrc_item = tvb_get_ntohl( tvb, offset );
1501                         if ( tree ) proto_tree_add_uint_format( rtp_csrc_tree,
1502                             hf_rtp_csrc_item, tvb, offset, 4,
1503                             csrc_item,
1504                             "CSRC item %d: 0x%X",
1505                             i, csrc_item );
1506                         offset += 4;
1507                 }
1508         }
1509
1510         /* Optional RTP header extension */
1511         if ( extension_set ) {
1512                 /* Defined by profile field is 16 bits (2 octets) */
1513                 hdr_extension_id = tvb_get_ntohs( tvb, offset );
1514                 if ( tree ) proto_tree_add_uint( rtp_tree, hf_rtp_prof_define, tvb, offset, 2, hdr_extension_id );
1515                 offset += 2;
1516
1517                 hdr_extension = tvb_get_ntohs( tvb, offset );
1518                 if ( tree ) proto_tree_add_uint( rtp_tree, hf_rtp_length, tvb, offset, 2, hdr_extension);
1519                 offset += 2;
1520                 if ( hdr_extension > 0 ) {
1521                         if ( tree ) {
1522                                 ti = proto_tree_add_item(rtp_tree, hf_rtp_hdr_exts, tvb, offset, hdr_extension * 4, ENC_NA);
1523                                 rtp_hext_tree = proto_item_add_subtree( ti, ett_hdr_ext );
1524                         }
1525
1526                         /* pass interpretation of header extension to a registered subdissector */
1527                         newtvb = tvb_new_subset(tvb, offset, hdr_extension * 4, hdr_extension * 4);
1528                         if ( !(dissector_try_uint(rtp_hdr_ext_dissector_table, hdr_extension_id, newtvb, pinfo, rtp_hext_tree)) ) {
1529
1530                                 /* 0xBEDE is defined by RFC 5215 as a header
1531                                  * extension with a one byte header
1532                                  */
1533                                 if (hdr_extension_id == 0xBEDE) {
1534                                         dissect_rtp_hext_rfc5215_onebyte (newtvb, pinfo, rtp_hext_tree);
1535                                 }
1536                                 else if ((hdr_extension_id & 0xFFF0) == 0x1000) {
1537                                         dissect_rtp_hext_rfc5215_twobytes(tvb,
1538                                                 offset - 4, hdr_extension_id, newtvb,
1539                                                 pinfo, rtp_hext_tree);
1540                                 }
1541                                 else {
1542                                         hdrext_offset = offset;
1543                                         for ( i = 0; i < hdr_extension; i++ ) {
1544                                                 if ( tree ) proto_tree_add_uint( rtp_hext_tree, hf_rtp_hdr_ext, tvb, hdrext_offset, 4, tvb_get_ntohl( tvb, hdrext_offset ) );
1545                                                 hdrext_offset += 4;
1546                                         }
1547                                 }
1548                         }
1549                         offset += hdr_extension * 4;
1550                 }
1551         }
1552
1553         if ( padding_set ) {
1554                 /*
1555                  * This RTP frame has padding - find it.
1556                  *
1557                  * The padding count is found in the LAST octet of
1558                  * the packet; it contains the number of octets
1559                  * that can be ignored at the end of the packet.
1560                  */
1561                 if (tvb_length(tvb) < tvb_reported_length(tvb)) {
1562                         /*
1563                          * We don't *have* the last octet of the
1564                          * packet, so we can't get the padding
1565                          * count.
1566                          *
1567                          * Put an indication of that into the
1568                          * tree, and just put in a raw data
1569                          * item.
1570                          */
1571                         if ( tree ) proto_tree_add_text(rtp_tree, tvb, 0, 0,
1572                             "Frame has padding, but not all the frame data was captured");
1573                         call_dissector(data_handle,
1574                             tvb_new_subset_remaining(tvb, offset),
1575                             pinfo, rtp_tree);
1576                         return;
1577                 }
1578
1579                 padding_count = tvb_get_guint8( tvb,
1580                     tvb_reported_length( tvb ) - 1 );
1581                 data_len =
1582                     tvb_reported_length_remaining( tvb, offset ) - padding_count;
1583
1584                 rtp_info->info_payload_offset = offset;
1585                 rtp_info->info_payload_len = tvb_length_remaining(tvb, offset);
1586                 rtp_info->info_padding_count = padding_count;
1587
1588                 if (data_len > 0) {
1589                         /*
1590                          * There's data left over when you take out
1591                          * the padding; dissect it.
1592                          */
1593                         dissect_rtp_data( tvb, pinfo, tree, rtp_tree,
1594                             offset,
1595                             data_len,
1596                             data_len,
1597                             payload_type );
1598                         offset += data_len;
1599                 } else if (data_len < 0) {
1600                         /*
1601                          * The padding count is bigger than the
1602                          * amount of RTP payload in the packet!
1603                          * Clip the padding count.
1604                          *
1605                          * XXX - put an item in the tree to indicate
1606                          * that the padding count is bogus?
1607                          */
1608                         padding_count =
1609                             tvb_reported_length_remaining(tvb, offset);
1610                 }
1611                 if (padding_count > 1) {
1612                         /*
1613                          * There's more than one byte of padding;
1614                          * show all but the last byte as padding
1615                          * data.
1616                          */
1617                         if ( tree ) proto_tree_add_item( rtp_tree, hf_rtp_padding_data,
1618                             tvb, offset, padding_count - 1, ENC_NA );
1619                         offset += padding_count - 1;
1620                 }
1621                 /*
1622                  * Show the last byte in the PDU as the padding
1623                  * count.
1624                  */
1625                 if ( tree ) proto_tree_add_item( rtp_tree, hf_rtp_padding_count,
1626                     tvb, offset, 1, ENC_BIG_ENDIAN );
1627         }
1628         else {
1629                 /*
1630                  * No padding.
1631                  */
1632                 dissect_rtp_data( tvb, pinfo, tree, rtp_tree, offset,
1633                                   tvb_length_remaining( tvb, offset ),
1634                                   tvb_reported_length_remaining( tvb, offset ),
1635                                   payload_type );
1636                 rtp_info->info_payload_offset = offset;
1637                 rtp_info->info_payload_len = tvb_length_remaining(tvb, offset);
1638         }
1639         if (!pinfo->flags.in_error_pkt)
1640                 tap_queue_packet(rtp_tap, pinfo, rtp_info);
1641 }
1642
1643
1644 /* calculate the extended sequence number - top 16 bits of the previous sequence number,
1645  * plus our own; then correct for wrapping */
1646 static guint32
1647 calculate_extended_seqno(guint32 previous_seqno, guint16 raw_seqno)
1648 {
1649         guint32 seqno = (previous_seqno & 0xffff0000) | raw_seqno;
1650         if(seqno + 0x8000 < previous_seqno) {
1651                 seqno += 0x10000;
1652         } else if(previous_seqno + 0x8000 < seqno) {
1653                 /* we got an out-of-order packet which happened to go backwards over the
1654                  * wrap boundary */
1655                 seqno -= 0x10000;
1656         }
1657         return seqno;
1658 }
1659
1660 /* Look for conversation info */
1661 static void
1662 get_conv_info(packet_info *pinfo, struct _rtp_info *rtp_info)
1663 {
1664         /* Conversation and current data */
1665         conversation_t *p_conv = NULL;
1666         struct _rtp_conversation_info *p_conv_data = NULL;
1667
1668         /* Use existing packet info if available */
1669         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
1670
1671         if (!p_conv_data)
1672         {
1673                 /* First time, get info from conversation */
1674                 p_conv = find_conversation(pinfo->fd->num, &pinfo->net_dst, &pinfo->net_src,
1675                                            pinfo->ptype,
1676                                            pinfo->destport, pinfo->srcport, NO_ADDR_B);
1677                 if (p_conv)
1678                 {
1679                         /* Create space for packet info */
1680                         struct _rtp_conversation_info *p_conv_packet_data;
1681                         p_conv_data = conversation_get_proto_data(p_conv, proto_rtp);
1682
1683                         if (p_conv_data) {
1684                                 guint32 seqno;
1685
1686                                 /* Save this conversation info into packet info */
1687                                 p_conv_packet_data = se_alloc(sizeof(struct _rtp_conversation_info));
1688                                 g_strlcpy(p_conv_packet_data->method, p_conv_data->method, MAX_RTP_SETUP_METHOD_SIZE+1);
1689                                 p_conv_packet_data->frame_number = p_conv_data->frame_number;
1690                                 p_conv_packet_data->is_video = p_conv_data->is_video;
1691                                 p_conv_packet_data->rtp_dyn_payload = p_conv_data->rtp_dyn_payload;
1692                                 p_conv_packet_data->rtp_conv_info = p_conv_data->rtp_conv_info;
1693                                 p_conv_packet_data->srtp_info = p_conv_data->srtp_info;
1694                                 p_add_proto_data(pinfo->fd, proto_rtp, p_conv_packet_data);
1695
1696                                 /* calculate extended sequence number */
1697                                 seqno = calculate_extended_seqno(p_conv_data->extended_seqno,
1698                                                                  rtp_info->info_seq_num);
1699
1700                                 p_conv_packet_data->extended_seqno = seqno;
1701                                 p_conv_data->extended_seqno = seqno;
1702                         }
1703                 }
1704         }
1705         if (p_conv_data) rtp_info->info_setup_frame_num = p_conv_data->frame_number;
1706 }
1707
1708
1709 /* Display setup info */
1710 static void
1711 show_setup_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1712 {
1713         /* Conversation and current data */
1714         struct _rtp_conversation_info *p_conv_data = NULL;
1715         proto_tree *rtp_setup_tree;
1716         proto_item *ti;
1717
1718         /* Use existing packet info if available */
1719         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
1720
1721         if (!p_conv_data) return;
1722
1723         /* Create setup info subtree with summary info. */
1724         ti =  proto_tree_add_string_format(tree, hf_rtp_setup, tvb, 0, 0,
1725                                            "", "Stream setup by %s (frame %u)",
1726                                            p_conv_data->method,
1727                                            p_conv_data->frame_number);
1728                 PROTO_ITEM_SET_GENERATED(ti);
1729                 rtp_setup_tree = proto_item_add_subtree(ti, ett_rtp_setup);
1730                 if (rtp_setup_tree)
1731                 {
1732                         /* Add details into subtree */
1733                         proto_item* item = proto_tree_add_uint(rtp_setup_tree, hf_rtp_setup_frame,
1734                                                                tvb, 0, 0, p_conv_data->frame_number);
1735                         PROTO_ITEM_SET_GENERATED(item);
1736                         item = proto_tree_add_string(rtp_setup_tree, hf_rtp_setup_method,
1737                                                      tvb, 0, 0, p_conv_data->method);
1738                         PROTO_ITEM_SET_GENERATED(item);
1739                 }
1740 }
1741
1742 /* Dissect PacketCable CCC header */
1743
1744 static void
1745 dissect_pkt_ccc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1746 {
1747         proto_item *ti            = NULL;
1748         proto_tree *pkt_ccc_tree      = NULL;
1749
1750         if ( tree ) {
1751                 ti = proto_tree_add_item(tree, proto_pkt_ccc, tvb, 0, 12, ENC_NA);
1752                 pkt_ccc_tree = proto_item_add_subtree(ti, ett_pkt_ccc);
1753
1754                 proto_tree_add_item(pkt_ccc_tree, hf_pkt_ccc_id, tvb, 0, 4, ENC_BIG_ENDIAN);
1755                 proto_tree_add_item(pkt_ccc_tree, hf_pkt_ccc_ts, tvb, 4, 8,
1756                                     ENC_TIME_NTP|ENC_BIG_ENDIAN);
1757         }
1758
1759         dissect_rtp(tvb, pinfo, tree);
1760 }
1761
1762
1763 /* Register PacketCable CCC */
1764
1765 void
1766 proto_register_pkt_ccc(void)
1767 {
1768         static hf_register_info hf[] =
1769         {
1770                 {
1771                         &hf_pkt_ccc_id,
1772                         {
1773                                 "PacketCable CCC Identifier",
1774                                 "pkt_ccc.ccc_id",
1775                                 FT_UINT32,
1776                                 BASE_DEC,
1777                                 NULL,
1778                                 0x0,
1779                                 NULL, HFILL
1780                         }
1781                 },
1782                 {
1783                         &hf_pkt_ccc_ts,
1784                         {
1785                                 "PacketCable CCC Timestamp",
1786                                 "pkt_ccc.ts",
1787                                 FT_ABSOLUTE_TIME,
1788                                 ABSOLUTE_TIME_UTC,
1789                                 NULL,
1790                                 0x0,
1791                                 NULL, HFILL
1792                         }
1793                 },
1794
1795         };
1796
1797         static gint *ett[] =
1798         {
1799                 &ett_pkt_ccc,
1800         };
1801
1802         module_t *pkt_ccc_module;
1803
1804         proto_pkt_ccc = proto_register_protocol("PacketCable Call Content Connection",
1805             "PKT CCC", "pkt_ccc");
1806         proto_register_field_array(proto_pkt_ccc, hf, array_length(hf));
1807         proto_register_subtree_array(ett, array_length(ett));
1808
1809         register_dissector("pkt_ccc", dissect_pkt_ccc, proto_pkt_ccc);
1810
1811         pkt_ccc_module = prefs_register_protocol(proto_pkt_ccc, proto_reg_handoff_pkt_ccc);
1812
1813         prefs_register_uint_preference(pkt_ccc_module, "udp_port",
1814                                        "UDP port",
1815                                        "Decode packets on this UDP port as PacketCable CCC",
1816                                        10, &global_pkt_ccc_udp_port);
1817 }
1818
1819 void
1820 proto_reg_handoff_pkt_ccc(void)
1821 {
1822         /*
1823          * Register this dissector as one that can be selected by a
1824          * UDP port number.
1825          */
1826         static gboolean initialized = FALSE;
1827         static dissector_handle_t pkt_ccc_handle;
1828         static guint saved_pkt_ccc_udp_port;
1829
1830         if (!initialized) {
1831                 pkt_ccc_handle = find_dissector("pkt_ccc");
1832                 dissector_add_handle("udp.port", pkt_ccc_handle);  /* for 'decode-as' */
1833                 initialized = TRUE;
1834         } else {
1835                 if (saved_pkt_ccc_udp_port != 0) {
1836                         dissector_delete_uint("udp.port", saved_pkt_ccc_udp_port, pkt_ccc_handle);
1837                 }
1838         }
1839
1840         if (global_pkt_ccc_udp_port != 0) {
1841                 dissector_add_uint("udp.port", global_pkt_ccc_udp_port, pkt_ccc_handle);
1842         }
1843         saved_pkt_ccc_udp_port = global_pkt_ccc_udp_port;
1844 }
1845
1846 /* Register RTP */
1847
1848 void
1849 proto_register_rtp(void)
1850 {
1851         static hf_register_info hf[] =
1852         {
1853                 {
1854                         &hf_rtp_version,
1855                         {
1856                                 "Version",
1857                                 "rtp.version",
1858                                 FT_UINT8,
1859                                 BASE_DEC,
1860                                 VALS(rtp_version_vals),
1861                                 0xC0,
1862                                 NULL, HFILL
1863                         }
1864                 },
1865                 {
1866                         &hf_rtp_padding,
1867                         {
1868                                 "Padding",
1869                                 "rtp.padding",
1870                                 FT_BOOLEAN,
1871                                 8,
1872                                 NULL,
1873                                 0x20,
1874                                 NULL, HFILL
1875                         }
1876                 },
1877                 {
1878                         &hf_rtp_extension,
1879                         {
1880                                 "Extension",
1881                                 "rtp.ext",
1882                                 FT_BOOLEAN,
1883                                 8,
1884                                 NULL,
1885                                 0x10,
1886                                 NULL, HFILL
1887                         }
1888                 },
1889                 {
1890                         &hf_rtp_csrc_count,
1891                         {
1892                                 "Contributing source identifiers count",
1893                                 "rtp.cc",
1894                                 FT_UINT8,
1895                                 BASE_DEC,
1896                                 NULL,
1897                                 0x0F,
1898                                 NULL, HFILL
1899                         }
1900                 },
1901                 {
1902                         &hf_rtp_marker,
1903                         {
1904                                 "Marker",
1905                                 "rtp.marker",
1906                                 FT_BOOLEAN,
1907                                 8,
1908                                 NULL,
1909                                 0x80,
1910                                 NULL, HFILL
1911                         }
1912                 },
1913                 {
1914                         &hf_rtp_payload_type,
1915                         {
1916                                 "Payload type",
1917                                 "rtp.p_type",
1918                                 FT_UINT8,
1919                                 BASE_DEC,
1920                                 NULL,
1921                                 0x7F,
1922                                 NULL, HFILL
1923                         }
1924                 },
1925                 {
1926                         &hf_rtp_seq_nr,
1927                         {
1928                                 "Sequence number",
1929                                 "rtp.seq",
1930                                 FT_UINT16,
1931                                 BASE_DEC,
1932                                 NULL,
1933                                 0x0,
1934                                 NULL, HFILL
1935                         }
1936                 },
1937                 {
1938                         &hf_rtp_ext_seq_nr,
1939                         {
1940                                 "Extended sequence number",
1941                                 "rtp.extseq",
1942                                 FT_UINT32,
1943                                 BASE_DEC,
1944                                 NULL,
1945                                 0x0,
1946                                 NULL, HFILL
1947                         }
1948                 },
1949                 {
1950                         &hf_rtp_timestamp,
1951                         {
1952                                 "Timestamp",
1953                                 "rtp.timestamp",
1954                                 FT_UINT32,
1955                                 BASE_DEC,
1956                                 NULL,
1957                                 0x0,
1958                                 NULL, HFILL
1959                         }
1960                 },
1961                 {
1962                         &hf_rtp_ssrc,
1963                         {
1964                                 "Synchronization Source identifier",
1965                                 "rtp.ssrc",
1966                                 FT_UINT32,
1967                                 BASE_HEX_DEC,
1968                                 NULL,
1969                                 0x0,
1970                                 NULL, HFILL
1971                         }
1972                 },
1973                 {
1974                         &hf_rtp_prof_define,
1975                         {
1976                                 "Defined by profile",
1977                                 "rtp.ext.profile",
1978                                 FT_UINT16,
1979                                 BASE_HEX_DEC,
1980                                 NULL,
1981                                 0x0,
1982                                 NULL, HFILL
1983                         }
1984                 },
1985                 {
1986                         &hf_rtp_length,
1987                         {
1988                                 "Extension length",
1989                                 "rtp.ext.len",
1990                                 FT_UINT16,
1991                                 BASE_DEC,
1992                                 NULL,
1993                                 0x0,
1994                                 NULL, HFILL
1995                         }
1996                 },
1997                 {
1998                         &hf_rtp_csrc_items,
1999                         {
2000                                 "Contributing Source identifiers",
2001                                 "rtp.csrc.items",
2002                                 FT_NONE,
2003                                 BASE_NONE,
2004                                 NULL,
2005                                 0x0,
2006                                 NULL, HFILL
2007                         }
2008                 },
2009                 {
2010                         &hf_rtp_csrc_item,
2011                         {
2012                                 "CSRC item",
2013                                 "rtp.csrc.item",
2014                                 FT_UINT32,
2015                                 BASE_HEX_DEC,
2016                                 NULL,
2017                                 0x0,
2018                                 NULL, HFILL
2019                         }
2020                 },
2021                 {
2022                         &hf_rtp_hdr_exts,
2023                         {
2024                                 "Header extensions",
2025                                 "rtp.hdr_exts",
2026                                 FT_NONE,
2027                                 BASE_NONE,
2028                                 NULL,
2029                                 0x0,
2030                                 NULL, HFILL
2031                         }
2032                 },
2033                 {
2034                         &hf_rtp_hdr_ext,
2035                         {
2036                                 "Header extension",
2037                                 "rtp.hdr_ext",
2038                                 FT_UINT32,
2039                                 BASE_DEC,
2040                                 NULL,
2041                                 0x0,
2042                                 NULL, HFILL
2043                         }
2044                 },
2045                 {
2046                         &hf_rtp_data,
2047                         {
2048                                 "Payload",
2049                                 "rtp.payload",
2050                                 FT_BYTES,
2051                                 BASE_NONE,
2052                                 NULL,
2053                                 0x0,
2054                                 NULL, HFILL
2055                         }
2056                 },
2057                 {
2058                         &hf_rtp_padding_data,
2059                         {
2060                                 "Padding data",
2061                                 "rtp.padding.data",
2062                                 FT_BYTES,
2063                                 BASE_NONE,
2064                                 NULL,
2065                                 0x0,
2066                                 NULL, HFILL
2067                         }
2068                 },
2069                 {
2070                         &hf_rtp_padding_count,
2071                         {
2072                                 "Padding count",
2073                                 "rtp.padding.count",
2074                                 FT_UINT8,
2075                                 BASE_DEC,
2076                                 NULL,
2077                                 0x0,
2078                                 NULL, HFILL
2079                         }
2080                 },
2081                 {
2082                         &hf_rtp_setup,
2083                         {
2084                                 "Stream setup",
2085                                 "rtp.setup",
2086                                 FT_STRING,
2087                                 BASE_NONE,
2088                                 NULL,
2089                                 0x0,
2090                                 "Stream setup, method and frame number", HFILL
2091                         }
2092                 },
2093                 {
2094                         &hf_rtp_setup_frame,
2095                         {
2096                                 "Setup frame",
2097                                 "rtp.setup-frame",
2098                                 FT_FRAMENUM,
2099                                 BASE_NONE,
2100                                 NULL,
2101                                 0x0,
2102                                 "Frame that set up this stream", HFILL
2103                         }
2104                 },
2105                 {
2106                         &hf_rtp_setup_method,
2107                         {
2108                                 "Setup Method",
2109                                 "rtp.setup-method",
2110                                 FT_STRING,
2111                                 BASE_NONE,
2112                                 NULL,
2113                                 0x0,
2114                                 "Method used to set up this stream", HFILL
2115                         }
2116                 },
2117                 {
2118                         &hf_rtp_rfc2198_follow,
2119                         {
2120                                 "Follow",
2121                                 "rtp.follow",
2122                                 FT_BOOLEAN,
2123                                 8,
2124                                 TFS(&tfs_set_notset),
2125                                 0x80,
2126                                 "Next header follows", HFILL
2127                         }
2128                 },
2129                 {
2130                         &hf_rtp_rfc2198_tm_off,
2131                         {
2132                                 "Timestamp offset",
2133                                 "rtp.timestamp-offset",
2134                                 FT_UINT16,
2135                                 BASE_DEC,
2136                                 NULL,
2137                                 0xFFFC,
2138                                 NULL, HFILL
2139                         }
2140                 },
2141                 {
2142                         &hf_rtp_rfc2198_bl_len,
2143                         {
2144                                 "Block length",
2145                                 "rtp.block-length",
2146                                 FT_UINT16,
2147                                 BASE_DEC,
2148                                 NULL,
2149                                 0x03FF,
2150                                 NULL, HFILL
2151                         }
2152                 },
2153                 {
2154                         &hf_rtp_ext_rfc5285_id,
2155                         {
2156                                 "Identifier",
2157                                 "rtp.ext.rfc5285.id",
2158                                 FT_UINT8,
2159                                 BASE_DEC,
2160                                 NULL,
2161                                 0x0,
2162                                 "RFC 5285 Header Extension Identifier",
2163                                 HFILL
2164                         }
2165                 },
2166                 {
2167                         &hf_rtp_ext_rfc5285_length,
2168                         {
2169                                 "Length",
2170                                 "rtp.ext.rfc5285.len",
2171                                 FT_UINT8,
2172                                 BASE_DEC,
2173                                 NULL,
2174                                 0x0,
2175                                 "RFC 5285 Header Extension length",
2176                                 HFILL
2177                         }
2178                 },
2179                 {
2180                         &hf_rtp_ext_rfc5285_appbits,
2181                         {
2182                                 "Application Bits",
2183                                 "rtp.ext.rfc5285.appbits",
2184                                 FT_UINT8,
2185                                 BASE_DEC,
2186                                 NULL,
2187                                 0x0,
2188                                 "RFC 5285 2-bytes header application bits",
2189                                 HFILL
2190                         }
2191                 },
2192                 {
2193                         &hf_rtp_ext_rfc5285_data,
2194                         {
2195                                 "Extension Data",
2196                                 "rtp.ext.rfc5285.data",
2197                                 FT_BYTES,
2198                                 BASE_NONE,
2199                                 NULL,
2200                                 0x0,
2201                                 "RFC 5285 Extension Data",
2202                                 HFILL
2203                         }
2204                 },
2205
2206                 /* reassembly stuff */
2207                 {&hf_rtp_fragments,
2208                  {"RTP Fragments", "rtp.fragments", FT_NONE, BASE_NONE, NULL, 0x0,
2209                   NULL, HFILL }
2210                 },
2211
2212                 {&hf_rtp_fragment,
2213                  {"RTP Fragment data", "rtp.fragment", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2214                   NULL, HFILL }
2215                 },
2216
2217                 {&hf_rtp_fragment_overlap,
2218                  {"Fragment overlap", "rtp.fragment.overlap", FT_BOOLEAN, BASE_NONE,
2219                   NULL, 0x0, "Fragment overlaps with other fragments", HFILL }
2220                 },
2221
2222                 {&hf_rtp_fragment_overlap_conflict,
2223                  {"Conflicting data in fragment overlap", "rtp.fragment.overlap.conflict",
2224                   FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2225                   "Overlapping fragments contained conflicting data", HFILL }
2226                 },
2227
2228                 {&hf_rtp_fragment_multiple_tails,
2229                  {"Multiple tail fragments found", "rtp.fragment.multipletails",
2230                   FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2231                   "Several tails were found when defragmenting the packet", HFILL }
2232                 },
2233
2234                 {&hf_rtp_fragment_too_long_fragment,
2235                  {"Fragment too long", "rtp.fragment.toolongfragment",
2236                   FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2237                   "Fragment contained data past end of packet", HFILL }
2238                 },
2239
2240                 {&hf_rtp_fragment_error,
2241                  {"Defragmentation error", "rtp.fragment.error",
2242                   FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2243                   "Defragmentation error due to illegal fragments", HFILL }
2244                 },
2245
2246                 {&hf_rtp_fragment_count,
2247                  {"Fragment count", "rtp.fragment.count",
2248                   FT_UINT32, BASE_DEC, NULL, 0x0,
2249                   NULL, HFILL }
2250                 },
2251
2252                 {&hf_rtp_reassembled_in,
2253                  {"RTP fragment, reassembled in frame", "rtp.reassembled_in",
2254                   FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2255                   "This RTP packet is reassembled in this frame", HFILL }
2256                 },
2257                 {&hf_rtp_reassembled_length,
2258                  {"Reassembled RTP length", "rtp.reassembled.length",
2259                   FT_UINT32, BASE_DEC, NULL, 0x0,
2260                   "The total length of the reassembled payload", HFILL }
2261                 },
2262                 {&hf_srtp_encrypted_payload,
2263                  {"SRTP Encrypted Payload", "srtp.enc_payload",
2264                   FT_BYTES, BASE_NONE, NULL, 0x0,
2265                   NULL, HFILL }
2266                 },
2267                 {&hf_srtp_mki,
2268                  {"SRTP MKI", "srtp.mki",
2269                   FT_BYTES, BASE_NONE, NULL, 0x0,
2270                   "SRTP Master Key Index", HFILL }
2271                 },
2272                 {&hf_srtp_auth_tag,
2273                  {"SRTP Auth Tag", "srtp.auth_tag",
2274                   FT_BYTES, BASE_NONE, NULL, 0x0,
2275                   "SRTP Authentication Tag", HFILL }
2276                 }
2277
2278         };
2279
2280         static gint *ett[] =
2281         {
2282                 &ett_rtp,
2283                 &ett_csrc_list,
2284                 &ett_hdr_ext,
2285                 &ett_hdr_ext_rfc5285,
2286                 &ett_rtp_setup,
2287                 &ett_rtp_rfc2198,
2288                 &ett_rtp_rfc2198_hdr,
2289                 &ett_rtp_fragment,
2290                 &ett_rtp_fragments
2291         };
2292
2293         module_t *rtp_module;
2294
2295
2296         proto_rtp = proto_register_protocol("Real-Time Transport Protocol",
2297                                             "RTP", "rtp");
2298         proto_register_field_array(proto_rtp, hf, array_length(hf));
2299         proto_register_subtree_array(ett, array_length(ett));
2300
2301         register_dissector("rtp", dissect_rtp, proto_rtp);
2302         register_dissector("rtp.rfc2198", dissect_rtp_rfc2198, proto_rtp);
2303
2304         rtp_tap = register_tap("rtp");
2305
2306         rtp_pt_dissector_table = register_dissector_table("rtp.pt",
2307                                                                         "RTP payload type", FT_UINT8, BASE_DEC);
2308         rtp_dyn_pt_dissector_table = register_dissector_table("rtp_dyn_payload_type",
2309                                                                         "Dynamic RTP payload type", FT_STRING, BASE_NONE);
2310
2311
2312         rtp_hdr_ext_dissector_table = register_dissector_table("rtp_hdr_ext",
2313                                                                         "RTP header extension", FT_UINT32, BASE_HEX);
2314         rtp_hdr_ext_rfc5285_dissector_table = register_dissector_table("rtp.ext.rfc5285.id",
2315                                                                         "RTP Generic header extension (RFC 5285)", FT_UINT8, BASE_DEC);
2316         rtp_module = prefs_register_protocol(proto_rtp, proto_reg_handoff_rtp);
2317
2318         prefs_register_bool_preference(rtp_module, "show_setup_info",
2319                                                                         "Show stream setup information",
2320                                                                         "Where available, show which protocol and frame caused "
2321                                                                         "this RTP stream to be created",
2322                                                                         &global_rtp_show_setup_info);
2323
2324         prefs_register_bool_preference(rtp_module, "heuristic_rtp",
2325                                                                         "Try to decode RTP outside of conversations",
2326                                                                         "If call control SIP/H323/RTSP/.. messages are missing in the trace, "
2327                                                                         "RTP isn't decoded without this",
2328                                                                         &global_rtp_heur);
2329
2330         prefs_register_bool_preference(rtp_module, "desegment_rtp_streams",
2331                                                                         "Allow subdissector to reassemble RTP streams",
2332                                                                         "Whether subdissector can request RTP streams to be reassembled",
2333                                                                         &desegment_rtp);
2334
2335         prefs_register_enum_preference(rtp_module, "version0_type",
2336                                                                         "Treat RTP version 0 packets as",
2337                                                                         "If an RTP version 0 packet is encountered, it can be treated as "
2338                                                                         "an invalid or ZRTP packet, a CLASSIC-STUN packet, or a T.38 packet",
2339                                                                         &global_rtp_version0_type,
2340                                                                         rtp_version0_types, FALSE);
2341         prefs_register_uint_preference(rtp_module,
2342                                                                         "rfc2198_payload_type", "Payload Type for RFC2198",
2343                                                                         "Payload Type for RFC2198 Redundant Audio Data",
2344                                                                         10,
2345                                                                         &rtp_rfc2198_pt);
2346
2347         register_init_routine(rtp_fragment_init);
2348 }
2349
2350 void
2351 proto_reg_handoff_rtp(void)
2352 {
2353         static gboolean rtp_prefs_initialized = FALSE;
2354         static dissector_handle_t rtp_rfc2198_handle;
2355         static guint rtp_saved_rfc2198_pt;
2356
2357         if (!rtp_prefs_initialized) {
2358                 rtp_handle = find_dissector("rtp");
2359                 rtp_rfc2198_handle = find_dissector("rtp.rfc2198");
2360
2361                 dissector_add_handle("udp.port", rtp_handle);  /* for 'decode-as' */
2362                 dissector_add_string("rtp_dyn_payload_type", "red", rtp_rfc2198_handle);
2363                 heur_dissector_add( "udp", dissect_rtp_heur_udp,  proto_rtp);
2364                 heur_dissector_add("stun", dissect_rtp_heur_stun, proto_rtp);
2365
2366                 data_handle = find_dissector("data");
2367                 classicstun_handle = find_dissector("classicstun");
2368                 classicstun_heur_handle = find_dissector("classicstun-heur");
2369                 t38_handle = find_dissector("t38");
2370                 zrtp_handle = find_dissector("zrtp");
2371
2372                 sprt_handle = find_dissector("sprt");
2373                 v150fw_handle = find_dissector("v150fw");
2374
2375                 dissector_add_string("rtp_dyn_payload_type", "v150fw", v150fw_handle);
2376
2377                 rtp_prefs_initialized = TRUE;
2378         } else {
2379                 dissector_delete_uint("rtp.pt", rtp_saved_rfc2198_pt, rtp_rfc2198_handle);
2380         }
2381         dissector_add_uint("rtp.pt", rtp_rfc2198_pt, rtp_rfc2198_handle);
2382         rtp_saved_rfc2198_pt = rtp_rfc2198_pt;
2383 }
2384
2385 /*
2386  * Local Variables:
2387  * c-basic-offset: 8
2388  * indent-tabs-mode: t
2389  * tab-width: 8
2390  * End:
2391  */