more sophisticated H245 OLC handling focusing on more reliable T.38 establishment
[obnox/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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 <glib.h>
64 #include <epan/packet.h>
65
66 #include <stdio.h>
67 #include <string.h>
68
69 #include "packet-rtp.h"
70 #include <epan/rtp_pt.h>
71 #include "packet-ntp.h"
72 #include <epan/conversation.h>
73 #include <epan/reassemble.h>
74 #include <epan/tap.h>
75
76 #include <epan/prefs.h>
77 #include <epan/emem.h>
78
79 #include "log.h"
80
81 /* uncomment this to enable debugging of fragment reassembly */
82 /* #define DEBUG_FRAGMENTS   1 */
83
84 typedef struct _rfc2198_hdr {
85   unsigned int pt;
86   int offset;
87   int len;
88   struct _rfc2198_hdr *next;
89 } rfc2198_hdr;
90
91 /* we have one of these for each pdu which spans more than one segment
92  */
93 typedef struct _rtp_multisegment_pdu {
94         /* the seqno of the segment where the pdu starts */
95         guint32 startseq;
96
97         /* the seqno of the segment where the pdu ends */
98         guint32 endseq;
99 } rtp_multisegment_pdu;
100
101 typedef struct  _rtp_private_conv_info {
102         /* This tree is indexed by sequence number and keeps track of all
103          * all pdus spanning multiple segments for this flow.
104          */
105         emem_tree_t *multisegment_pdus;
106 } rtp_private_conv_info;
107
108 static GHashTable *fragment_table = NULL;
109 static GHashTable * fid_table = NULL;
110
111 static int hf_rtp_fragments = -1;
112 static int hf_rtp_fragment = -1;
113 static int hf_rtp_fragment_overlap = -1;
114 static int hf_rtp_fragment_overlap_conflict = -1;
115 static int hf_rtp_fragment_multiple_tails = -1;
116 static int hf_rtp_fragment_too_long_fragment = -1;
117 static int hf_rtp_fragment_error = -1;
118 static int hf_rtp_reassembled_in = -1;
119
120 static gint ett_rtp_fragment = -1;
121 static gint ett_rtp_fragments = -1;
122
123 static const fragment_items rtp_fragment_items = {
124   &ett_rtp_fragment,
125   &ett_rtp_fragments,
126   &hf_rtp_fragments,
127   &hf_rtp_fragment,
128   &hf_rtp_fragment_overlap,
129   &hf_rtp_fragment_overlap_conflict,
130   &hf_rtp_fragment_multiple_tails,
131   &hf_rtp_fragment_too_long_fragment,
132   &hf_rtp_fragment_error,
133   &hf_rtp_reassembled_in,
134   "RTP fragments"
135 };
136
137 static dissector_handle_t rtp_handle;
138 static dissector_handle_t rtp_rfc2198_handle;
139 static dissector_handle_t stun_handle;
140 static dissector_handle_t t38_handle;
141
142 static dissector_handle_t pkt_ccc_handle;
143
144 static int rtp_tap = -1;
145
146 static dissector_table_t rtp_pt_dissector_table;
147 static dissector_table_t rtp_dyn_pt_dissector_table;
148
149 static dissector_table_t rtp_hdr_ext_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_rtp_setup = -1;
188 static gint ett_rtp_rfc2198 = -1;
189 static gint ett_rtp_rfc2198_hdr = -1;
190
191 /* SRTP fields */
192 static int hf_srtp_encrypted_payload = -1;
193 static int hf_srtp_mki = -1;
194 static int hf_srtp_auth_tag = -1;
195
196 /* PacketCable CCC header fields */
197 static int proto_pkt_ccc       = -1;
198 static int hf_pkt_ccc_id       = -1;
199 static int hf_pkt_ccc_ts       = -1;
200
201 /* PacketCable CCC field defining a sub tree */
202 static gint ett_pkt_ccc = -1;
203
204 /* PacketCable CCC port preference */
205 static gboolean global_pkt_ccc_udp_port = 0;
206
207
208 #define RTP0_INVALID 0
209 #define RTP0_STUN    1
210 #define RTP0_T38     2
211
212 static enum_val_t rtp_version0_types[] = {
213         { "invalid", "Invalid RTP packets", RTP0_INVALID },
214         { "stun", "STUN packets", RTP0_STUN },
215         { "t38", "T.38 packets", RTP0_T38 },
216         { NULL, NULL, 0 }
217 };
218 static guint global_rtp_version0_type = 0;
219
220 static dissector_handle_t data_handle;
221
222 /* Forward declaration we need below */
223 void proto_reg_handoff_rtp(void);
224
225 static gboolean dissect_rtp_heur( tvbuff_t *tvb, packet_info *pinfo,
226     proto_tree *tree );
227 static void dissect_rtp( tvbuff_t *tvb, packet_info *pinfo,
228     proto_tree *tree );
229 static void show_setup_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
230 static void get_conv_info(packet_info *pinfo, struct _rtp_info *rtp_info);
231
232 /* Preferences bool to control whether or not setup info should be shown */
233 static gboolean global_rtp_show_setup_info = TRUE;
234
235 /* Try heuristic RTP decode */
236 static gboolean global_rtp_heur = FALSE;
237
238 /* desegment RTP streams */
239 static gboolean desegment_rtp = TRUE;
240
241 /* RFC2198 Redundant Audio Data */
242 static guint rtp_rfc2198_pt = 99;
243 static guint rtp_saved_rfc2198_pt = 0;
244
245 /*
246  * Fields in the first octet of the RTP header.
247  */
248
249 /* Version is the first 2 bits of the first octet*/
250 #define RTP_VERSION(octet)      ((octet) >> 6)
251
252 /* Padding is the third bit; No need to shift, because true is any value
253    other than 0! */
254 #define RTP_PADDING(octet)      ((octet) & 0x20)
255
256 /* Extension bit is the fourth bit */
257 #define RTP_EXTENSION(octet)    ((octet) & 0x10)
258
259 /* CSRC count is the last four bits */
260 #define RTP_CSRC_COUNT(octet)   ((octet) & 0xF)
261
262 static const value_string rtp_version_vals[] =
263 {
264         { 0, "Old VAT Version" },
265         { 1, "First Draft Version" },
266         { 2, "RFC 1889 Version" },
267         { 0, NULL },
268 };
269
270 /*
271  * Fields in the second octet of the RTP header.
272  */
273
274 /* Marker is the first bit of the second octet */
275 #define RTP_MARKER(octet)       ((octet) & 0x80)
276
277 /* Payload type is the last 7 bits */
278 #define RTP_PAYLOAD_TYPE(octet) ((octet) & 0x7F)
279
280 const value_string rtp_payload_type_vals[] =
281 {
282         { PT_PCMU,      "ITU-T G.711 PCMU" },
283         { PT_1016,      "USA Federal Standard FS-1016" },
284         { PT_G721,      "ITU-T G.721" },
285         { PT_GSM,       "GSM 06.10" },
286         { PT_G723,      "ITU-T G.723" },
287         { PT_DVI4_8000, "DVI4 8000 samples/s" },
288         { PT_DVI4_16000, "DVI4 16000 samples/s" },
289         { PT_LPC,       "Experimental linear predictive encoding from Xerox PARC" },
290         { PT_PCMA,      "ITU-T G.711 PCMA" },
291         { PT_G722,      "ITU-T G.722" },
292         { PT_L16_STEREO, "16-bit uncompressed audio, stereo" },
293         { PT_L16_MONO,  "16-bit uncompressed audio, monaural" },
294         { PT_QCELP,     "Qualcomm Code Excited Linear Predictive coding" },
295         { PT_CN,        "Comfort noise" },
296         { PT_MPA,       "MPEG-I/II Audio"},
297         { PT_G728,      "ITU-T G.728" },
298         { PT_DVI4_11025, "DVI4 11025 samples/s" },
299         { PT_DVI4_22050, "DVI4 22050 samples/s" },
300         { PT_G729,      "ITU-T G.729" },
301         { PT_CN_OLD,    "Comfort noise (old)" },
302         { PT_CELB,      "Sun CellB video encoding" },
303         { PT_JPEG,      "JPEG-compressed video" },
304         { PT_NV,        "'nv' program" },
305         { PT_H261,      "ITU-T H.261" },
306         { PT_MPV,       "MPEG-I/II Video"},
307         { PT_MP2T,      "MPEG-II transport streams"},
308         { PT_H263,      "ITU-T H.263" },
309         { 0,            NULL },
310 };
311
312 const value_string rtp_payload_type_short_vals[] =
313 {
314        { PT_PCMU,      "g711U" },
315        { PT_1016,      "fs-1016" },
316        { PT_G721,      "g721" },
317        { PT_GSM,       "GSM" },
318        { PT_G723,      "g723" },
319        { PT_DVI4_8000, "DVI4 8k" },
320        { PT_DVI4_16000, "DVI4 16k" },
321        { PT_LPC,       "Exp. from Xerox PARC" },
322        { PT_PCMA,      "g711A" },
323        { PT_G722,      "g722" },
324        { PT_L16_STEREO, "16-bit audio, stereo" },
325        { PT_L16_MONO,  "16-bit audio, monaural" },
326        { PT_QCELP,     "Qualcomm" },
327        { PT_CN,        "CN" },
328        { PT_MPA,       "MPEG-I/II Audio"},
329        { PT_G728,      "g728" },
330        { PT_DVI4_11025, "DVI4 11k" },
331        { PT_DVI4_22050, "DVI4 22k" },
332        { PT_G729,      "g729" },
333        { PT_CN_OLD,    "CN(old)" },
334        { PT_CELB,      "CellB" },
335        { PT_JPEG,      "JPEG" },
336        { PT_NV,        "NV" },
337        { PT_H261,      "h261" },
338        { PT_MPV,       "MPEG-I/II Video"},
339        { PT_MP2T,      "MPEG-II streams"},
340        { PT_H263,      "h263" },
341        { 0,            NULL },
342 };
343
344 static const value_string srtp_encryption_alg_vals[] =
345 {
346         { SRTP_ENC_ALG_NULL,    "Null Encryption" },
347         { SRTP_ENC_ALG_AES_CM, "AES-128 Counter Mode" },
348         { SRTP_ENC_ALG_AES_F8,  "AES-128 F8 Mode" },
349         { 0, NULL },
350 };
351
352 static const value_string srtp_auth_alg_vals[] =
353 {
354         { SRTP_AUTH_ALG_NONE,           "No Authentication" },
355         { SRTP_AUTH_ALG_HMAC_SHA1,      "HMAC-SHA1" },
356         { 0, NULL },
357 };
358
359
360 /* initialisation routine */
361 static void rtp_fragment_init(void)
362 {
363         fragment_table_init(&fragment_table);
364         fid_table = g_hash_table_new(g_direct_hash, g_direct_equal);
365 }
366
367 void
368 rtp_free_hash_dyn_payload(GHashTable *rtp_dyn_payload)
369 {
370         if (rtp_dyn_payload == NULL) return;
371         g_hash_table_destroy(rtp_dyn_payload);
372         rtp_dyn_payload = NULL;
373 }
374
375 /* Set up an SRTP conversation */
376 void srtp_add_address(packet_info *pinfo,
377                      address *addr, int port,
378                      int other_port,
379                      const gchar *setup_method, guint32 setup_frame_number, GHashTable *rtp_dyn_payload,
380                      struct srtp_info *srtp_info)
381 {
382         address null_addr;
383         conversation_t* p_conv;
384         struct _rtp_conversation_info *p_conv_data = NULL;
385
386         /*
387          * If this isn't the first time this packet has been processed,
388          * we've already done this work, so we don't need to do it
389          * again.
390          */
391         if (pinfo->fd->flags.visited)
392         {
393                 return;
394         }
395
396         printf("#%u: %srtp_add_address(%s, %u, %u, %s, %u\n", pinfo->fd->num, (srtp_info)?"s":"", address_to_str(addr), port, other_port, setup_method, setup_frame_number);
397
398         SET_ADDRESS(&null_addr, AT_NONE, 0, NULL);
399
400         /*
401          * Check if the ip address and port combination is not
402          * already registered as a conversation.
403          */
404         p_conv = find_conversation( setup_frame_number, addr, &null_addr, PT_UDP, port, other_port,
405                                 NO_ADDR_B | (!other_port ? NO_PORT_B : 0));
406
407         /*
408          * If not, create a new conversation.
409          */
410         if ( !p_conv || p_conv->setup_frame != setup_frame_number) {
411                 p_conv = conversation_new( setup_frame_number, addr, &null_addr, PT_UDP,
412                                            (guint32)port, (guint32)other_port,
413                                                                    NO_ADDR2 | (!other_port ? NO_PORT2 : 0));
414         }
415
416         /* Set dissector */
417         conversation_set_dissector(p_conv, rtp_handle);
418
419         /*
420          * Check if the conversation has data associated with it.
421          */
422         p_conv_data = conversation_get_proto_data(p_conv, proto_rtp);
423
424         /*
425          * If not, add a new data item.
426          */
427         if ( ! p_conv_data ) {
428                 /* Create conversation data */
429                 p_conv_data = se_alloc(sizeof(struct _rtp_conversation_info));
430                 p_conv_data->rtp_dyn_payload = NULL;
431
432                 /* start this at 0x10000 so that we cope gracefully with the
433                  * first few packets being out of order (hence 0,65535,1,2,...)
434                  */
435                 p_conv_data->extended_seqno = 0x10000;
436                 p_conv_data->rtp_conv_info = se_alloc(sizeof(rtp_private_conv_info));
437                 p_conv_data->rtp_conv_info->multisegment_pdus = se_tree_create(EMEM_TREE_TYPE_RED_BLACK,"rtp_ms_pdus");
438                 conversation_add_proto_data(p_conv, proto_rtp, p_conv_data);
439         }
440
441         /*
442          * Update the conversation data.
443          */
444         /* Free the hash if already exists */
445         rtp_free_hash_dyn_payload(p_conv_data->rtp_dyn_payload);
446
447         strncpy(p_conv_data->method, setup_method, MAX_RTP_SETUP_METHOD_SIZE);
448         p_conv_data->method[MAX_RTP_SETUP_METHOD_SIZE] = '\0';
449         p_conv_data->frame_number = setup_frame_number;
450         p_conv_data->rtp_dyn_payload = rtp_dyn_payload;
451         p_conv_data->srtp_info = srtp_info;
452 }
453
454 /* Set up an RTP conversation */
455 void rtp_add_address(packet_info *pinfo,
456                      address *addr, int port,
457                      int other_port,
458                      const gchar *setup_method, guint32 setup_frame_number, GHashTable *rtp_dyn_payload)
459 {
460         srtp_add_address(pinfo, addr, port, other_port, setup_method, setup_frame_number, rtp_dyn_payload, NULL);
461 }
462
463 static gboolean
464 dissect_rtp_heur( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
465 {
466         guint8      octet1, octet2;
467         unsigned int version;
468         unsigned int payload_type;
469         unsigned int offset = 0;
470
471         /* This is a heuristic dissector, which means we get all the UDP
472          * traffic not sent to a known dissector and not claimed by
473          * a heuristic dissector called before us!
474          */
475
476         if (! global_rtp_heur)
477                 return FALSE;
478
479         /* Get the fields in the first octet */
480         octet1 = tvb_get_guint8( tvb, offset );
481         version = RTP_VERSION( octet1 );
482
483         if (version == 0) {
484                 switch (global_rtp_version0_type) {
485                 case RTP0_STUN:
486                         call_dissector(stun_handle, tvb, pinfo, tree);
487                         return TRUE;
488
489                 case RTP0_T38:
490                         call_dissector(t38_handle, tvb, pinfo, tree);
491                         return TRUE;
492
493                 case RTP0_INVALID:
494                 default:
495                         return FALSE; /* Unknown or unsupported version */
496                 }
497         } else if (version != 2) {
498                 /* Unknown or unsupported version */
499                 return FALSE;
500         }
501
502         /* Get the fields in the second octet */
503         octet2 = tvb_get_guint8( tvb, offset + 1 );
504         payload_type = RTP_PAYLOAD_TYPE( octet2 );
505         /*      if (payload_type == PT_PCMU ||
506          *                   payload_type == PT_PCMA)
507          *           payload_type == PT_G729)
508          *       */
509         if (payload_type <= PT_H263) {
510                 dissect_rtp( tvb, pinfo, tree );
511                 return TRUE;
512         }
513         else {
514                 return FALSE;
515         }
516 }
517
518 /*
519  * Process the payload of the RTP packet, hand it to the subdissector
520  */
521 static void
522 process_rtp_payload(tvbuff_t *newtvb, packet_info *pinfo, proto_tree *tree,
523     proto_tree *rtp_tree,
524     unsigned int payload_type)
525 {
526         struct _rtp_conversation_info *p_conv_data = NULL;
527         gboolean found_match = FALSE;
528         int payload_len;
529         struct srtp_info *srtp_info;
530         int offset=0;
531
532         payload_len = tvb_length_remaining(newtvb, offset);
533
534         /* first check if this is added as an SRTP stream - if so, don't try to dissector the payload data for now */
535         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
536         if (p_conv_data && p_conv_data->srtp_info) {
537                 srtp_info = p_conv_data->srtp_info;
538                 payload_len -= srtp_info->mki_len + srtp_info->auth_tag_len;
539
540                 if (p_conv_data->srtp_info->encryption_algorithm==SRTP_ENC_ALG_NULL) {
541                         if (rtp_tree)
542                                 proto_tree_add_text(rtp_tree, newtvb, offset, payload_len, "SRTP Payload with NULL encryption");
543                 }
544                 else {
545                         if (rtp_tree)
546                                 proto_tree_add_item(rtp_tree, hf_srtp_encrypted_payload, newtvb, offset, payload_len, FALSE);
547                         found_match = TRUE;     /* use this flag to prevent dissection below */
548                 }
549                 offset += payload_len;
550
551                 if (srtp_info->mki_len) {
552                         proto_tree_add_item(rtp_tree, hf_srtp_mki, newtvb, offset, srtp_info->mki_len, FALSE);
553                         offset += srtp_info->mki_len;
554                 }
555
556                 if (srtp_info->auth_tag_len) {
557                         proto_tree_add_item(rtp_tree, hf_srtp_auth_tag, newtvb, offset, srtp_info->auth_tag_len, FALSE);
558                         offset += srtp_info->auth_tag_len;
559                 }
560         }
561
562         /* if the payload type is dynamic (96 to 127), we check if the conv is set and we look for the pt definition */
563         else if ( (payload_type >=96) && (payload_type <=127) ) {
564                 if (p_conv_data && p_conv_data->rtp_dyn_payload) {
565                         gchar *payload_type_str = NULL;
566                         payload_type_str = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &payload_type);
567                         if (payload_type_str){
568                                 found_match = dissector_try_string(rtp_dyn_pt_dissector_table,
569                                                                                                         payload_type_str, newtvb, pinfo, tree);
570                                 /* If payload type string set from conversation and
571                                  * no matching dissector found it's probably because no subdissector
572                                  * exists. Don't call the dissectors based on payload number
573                                  * as that'd probably be the wrong dissector in this case.
574                                  * Just add it as data.
575                                  */
576                                 if(found_match==FALSE)
577                                         proto_tree_add_item( rtp_tree, hf_rtp_data, newtvb, 0, -1, FALSE );
578                                 return;
579                         }
580
581                 }
582         }
583
584         /* if we don't found, it is static OR could be set static from the preferences */
585         if (!found_match && !dissector_try_port(rtp_pt_dissector_table, payload_type, newtvb, pinfo, tree))
586                 proto_tree_add_item( rtp_tree, hf_rtp_data, newtvb, 0, -1, FALSE );
587
588 }
589
590 /* Rtp payload reassembly
591  *
592  * This handles the reassembly of PDUs for higher-level protocols.
593  *
594  * We're a bit limited on how we can cope with out-of-order packets, because
595  * we don't have any idea of where the datagram boundaries are. So if we see
596  * packets A, C, B (all of which comprise a single datagram), we cannot know
597  * that C should be added to the same datagram as A, until we come to B (which
598  * may or may not actually be present...).
599  *
600  * What we end up doing in this case is passing A+B to the subdissector as one
601  * datagram, and make out that a new one starts on C.
602  */
603 static void
604 dissect_rtp_data( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
605     proto_tree *rtp_tree, int offset, unsigned int data_len,
606     unsigned int data_reported_len,
607         unsigned int payload_type )
608 {
609         tvbuff_t *newtvb;
610         struct _rtp_conversation_info *p_conv_data= NULL;
611         gboolean must_desegment = FALSE;
612         rtp_private_conv_info *finfo = NULL;
613         rtp_multisegment_pdu *msp = NULL;
614         guint32 seqno;
615
616         /* Retrieve RTPs idea of a converation */
617         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
618
619         if(p_conv_data != NULL) 
620                 finfo = p_conv_data->rtp_conv_info;
621
622         if(finfo == NULL || !desegment_rtp) {
623                 /* Hand the whole lot off to the subdissector */
624                 newtvb=tvb_new_subset(tvb,offset,data_len,data_reported_len);
625                 process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type);
626                 return;
627         }
628
629         seqno = p_conv_data->extended_seqno;
630
631         pinfo->can_desegment = 2;
632         pinfo->desegment_offset = 0;
633         pinfo->desegment_len = 0;
634
635 #ifdef DEBUG_FRAGMENTS
636         g_debug("%d: RTP Part of convo %d(%p); seqno %d",
637                 pinfo->fd->num,
638                 p_conv_data->frame_number, p_conv_data,
639                 seqno
640                 );
641 #endif
642
643         /* look for a pdu which we might be extending */
644         msp = (rtp_multisegment_pdu *)se_tree_lookup32_le(finfo->multisegment_pdus,seqno-1);
645
646         if(msp && msp->startseq < seqno && msp->endseq >= seqno) {
647                 guint32 fid = msp->startseq;
648                 fragment_data *fd_head;
649                 
650 #ifdef DEBUG_FRAGMENTS
651                 g_debug("\tContinues fragment %d", fid);
652 #endif
653
654                 /* we always assume the datagram is complete; if this is the
655                  * first pass, that's our best guess, and if it's not, what we
656                  * say gets ignored anyway.
657                  */
658                 fd_head = fragment_add_seq(tvb, offset, pinfo, fid, fragment_table,
659                                            seqno-msp->startseq, data_len, FALSE);
660
661                 newtvb = process_reassembled_data(tvb,offset, pinfo, "Reassembled RTP", fd_head,
662                                                   &rtp_fragment_items, NULL, tree);
663
664 #ifdef DEBUG_FRAGMENTS
665                 g_debug("\tFragment Coalesced; fd_head=%p, newtvb=%p (len %d)",fd_head, newtvb,
666                         newtvb?tvb_reported_length(newtvb):0);
667 #endif
668
669                 if(newtvb != NULL) {
670                         /* Hand off to the subdissector */
671                         process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type);
672             
673                         /*
674                          * Check to see if there were any complete fragments within the chunk
675                          */
676                         if( pinfo->desegment_len && pinfo->desegment_offset == 0 )
677                         {
678 #ifdef DEBUG_FRAGMENTS
679                                 g_debug("\tNo complete pdus in payload" );
680 #endif
681                                 /* Mark the fragments and not complete yet */
682                                 fragment_set_partial_reassembly(pinfo, fid, fragment_table);
683                                         
684                                 /* we must need another segment */
685                                 msp->endseq = MIN(msp->endseq,seqno) + 1;
686                         }
687                         else 
688                         {
689                                 /*
690                                  * Data was dissected so add the protocol tree to the display
691                                  */
692                                 proto_item *rtp_tree_item, *frag_tree_item;
693                                 /* this nargery is to insert the fragment tree into the main tree
694                                  * between the RTP protocol entry and the subdissector entry */
695                                 show_fragment_tree(fd_head, &rtp_fragment_items, tree, pinfo, newtvb, &frag_tree_item);
696                                 rtp_tree_item = proto_item_get_parent( proto_tree_get_parent( rtp_tree ));
697                                 if( frag_tree_item && rtp_tree_item )
698                                         proto_tree_move_item( tree, rtp_tree_item, frag_tree_item );
699
700             
701                                 if(pinfo->desegment_len) 
702                                 {
703                                         /* the higher-level dissector has asked for some more data - ie,
704                                            the end of this segment does not coincide with the end of a
705                                            higher-level PDU. */
706                                         must_desegment = TRUE;
707                                 }
708                         }       
709                 
710                 } 
711         
712         } 
713         else
714         {
715                 /*
716                  * The segment is not the continuation of a fragmented segment
717                  * so process it as normal
718                  */               
719 #ifdef DEBUG_FRAGMENTS
720                 g_debug("\tRTP non-fragment payload");
721 #endif
722                 newtvb = tvb_new_subset( tvb, offset, data_len, data_reported_len );
723         
724                 /* Hand off to the subdissector */
725                 process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type);
726         
727                 if(pinfo->desegment_len) {
728                         /* the higher-level dissector has asked for some more data - ie,
729                            the end of this segment does not coincide with the end of a
730                            higher-level PDU. */
731                         must_desegment = TRUE;
732                 }
733         }
734         
735         /* 
736          * There were bytes left over that the higher protocol couldn't dissect so save them
737          */
738         if(must_desegment)
739         {
740                 guint32 deseg_offset = pinfo->desegment_offset;
741                 guint32 frag_len = tvb_reported_length_remaining(newtvb, deseg_offset);
742                 fragment_data *fd_head = NULL;
743     
744 #ifdef DEBUG_FRAGMENTS
745                 g_debug("\tRTP Must Desegment: tvb_len=%d ds_len=%d %d frag_len=%d ds_off=%d",
746                         tvb_reported_length(newtvb),
747                         pinfo->desegment_len,
748                         pinfo->fd->flags.visited,
749                         frag_len,
750                         deseg_offset); 
751 #endif
752                 /* allocate a new msp for this pdu */
753                 msp = se_alloc(sizeof(rtp_multisegment_pdu));
754                 msp->startseq = seqno;
755                 msp->endseq = seqno+1;
756                 se_tree_insert32(finfo->multisegment_pdus,seqno,msp);
757                         
758                 /*
759                  * Add the fragment to the fragment table
760                  */    
761                 fd_head = fragment_add_seq(newtvb,deseg_offset, pinfo, seqno, fragment_table, 0, frag_len,
762                                            TRUE );
763
764                 if(fd_head != NULL)
765                 {
766                         if( fd_head->reassembled_in != 0 && !(fd_head->flags & FD_PARTIAL_REASSEMBLY) ) 
767                         {
768                                 proto_item *rtp_tree_item;
769                                 rtp_tree_item = proto_tree_add_uint( tree, hf_rtp_reassembled_in,
770                                                                      newtvb, deseg_offset, tvb_reported_length_remaining(newtvb,deseg_offset),
771                                                                      fd_head->reassembled_in);
772                                 PROTO_ITEM_SET_GENERATED(rtp_tree_item);          
773 #ifdef DEBUG_FRAGMENTS
774                                 g_debug("\tReassembled in %d", fd_head->reassembled_in);
775 #endif
776                         }         
777                         else 
778                         {
779 #ifdef DEBUG_FRAGMENTS
780                                 g_debug("\tUnfinished fragment");
781 #endif
782                                 /* this fragment is never reassembled */
783                                 proto_tree_add_text( tree, tvb, deseg_offset, -1,"RTP fragment, unfinished");
784                         }       
785                 }
786                 else
787                 {
788                         /* 
789                          * This fragment was the first fragment in a new entry in the
790                          * frag_table; we don't yet know where it is reassembled
791                          */      
792 #ifdef DEBUG_FRAGMENTS
793                         g_debug("\tnew pdu");
794 #endif
795                 }
796                         
797                 if( pinfo->desegment_offset == 0 ) 
798                 {
799                         if (check_col(pinfo->cinfo, COL_PROTOCOL))
800                         {
801                                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTP");
802                         }
803                         if (check_col(pinfo->cinfo, COL_INFO))
804                         {
805                                 col_set_str(pinfo->cinfo, COL_INFO, "[RTP segment of a reassembled PDU]");
806                         }
807                 }
808         }
809
810
811
812         pinfo->can_desegment = 0;
813         pinfo->desegment_offset = 0;
814         pinfo->desegment_len = 0;
815 }
816
817
818
819 static void
820 dissect_rtp_rfc2198(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
821 {
822         int offset = 0;
823         guint8 octet1;
824         int cnt;
825         gboolean hdr_follow = TRUE;
826         proto_item *ti = NULL;
827         proto_tree *rfc2198_tree = NULL;
828         proto_tree *rfc2198_hdr_tree = NULL;
829         rfc2198_hdr *hdr_last, *hdr_new;
830         rfc2198_hdr *hdr_chain = NULL;
831         struct _rtp_conversation_info *p_conv_data= NULL;
832         gchar *payload_type_str;
833
834         /* Retrieve RTPs idea of a converation */
835         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
836
837         /* Add try to RFC 2198 data */
838         ti = proto_tree_add_text(tree, tvb, offset, -1, "RFC 2198: Redundant Audio Data");
839         rfc2198_tree = proto_item_add_subtree(ti, ett_rtp_rfc2198);
840
841         hdr_last = NULL;
842         cnt = 0;
843         while (hdr_follow) {
844                 cnt++;
845                 payload_type_str = NULL;
846
847                 /* Allocate and fill in header */
848                 hdr_new = ep_alloc(sizeof(rfc2198_hdr));
849                 hdr_new->next = NULL;
850                 octet1 = tvb_get_guint8(tvb, offset);
851                 hdr_new->pt = RTP_PAYLOAD_TYPE(octet1);
852                 hdr_follow = (octet1 & 0x80);
853
854                 /* if it is dynamic payload, let use the conv data to see if it is defined */
855                 if ((hdr_new->pt > 95) && (hdr_new->pt < 128)) {
856                         if (p_conv_data && p_conv_data->rtp_dyn_payload){
857                                 payload_type_str = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &hdr_new->pt);
858                         }
859                 }
860                 /* Add a subtree for this header and add items */
861                 ti = proto_tree_add_text(rfc2198_tree, tvb, offset, (hdr_follow)?4:1, "Header %u", cnt);
862                 rfc2198_hdr_tree = proto_item_add_subtree(ti, ett_rtp_rfc2198_hdr);
863                 proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_follow, tvb, offset, 1, FALSE );
864                 proto_tree_add_uint_format(rfc2198_hdr_tree, hf_rtp_payload_type, tvb,
865                     offset, 1, octet1, "Payload type: %s (%u)",
866                         payload_type_str ? payload_type_str : val_to_str(hdr_new->pt, rtp_payload_type_vals, "Unknown"),
867                         hdr_new->pt);
868                 proto_item_append_text(ti, ": PT=%s", payload_type_str ? payload_type_str : val_to_str(hdr_new->pt, rtp_payload_type_vals, "Unknown (%u)"));
869                 offset += 1;
870
871                 /* Timestamp offset and block length don't apply to last header */
872                 if (hdr_follow) {
873                         proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_tm_off, tvb, offset, 2, FALSE );
874                         proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_bl_len, tvb, offset + 1, 2, FALSE );
875                         hdr_new->len = tvb_get_ntohs(tvb, offset + 1) & 0x03FF;
876                         proto_item_append_text(ti, ", len=%u", hdr_new->len);
877                         offset += 3;
878                 } else {
879                         hdr_new->len = -1;
880                         hdr_follow = FALSE;
881                 }
882
883                 if (hdr_last) {
884                         hdr_last->next = hdr_new;
885                 } else {
886                         hdr_chain = hdr_new;
887                 }
888                 hdr_last = hdr_new;
889         }
890
891         /* Dissect each data block according to the header info */
892         hdr_last = hdr_chain;
893         while (hdr_last) {
894                 hdr_last->offset = offset;
895                 if (!hdr_last->next) {
896                         hdr_last->len = tvb_reported_length_remaining(tvb, offset);
897                 }
898                 dissect_rtp_data(tvb, pinfo, tree, rfc2198_tree, hdr_last->offset, hdr_last->len, hdr_last->len, hdr_last->pt);
899                 offset += hdr_last->len;
900                 hdr_last = hdr_last->next;
901         }
902 }
903
904 static void
905 dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
906 {
907         proto_item *ti            = NULL;
908         proto_tree *rtp_tree      = NULL;
909         proto_tree *rtp_csrc_tree = NULL;
910         proto_tree *rtp_hext_tree = NULL;
911         guint8      octet1, octet2;
912         unsigned int version;
913         gboolean    padding_set;
914         gboolean    extension_set;
915         unsigned int csrc_count;
916         gboolean    marker_set;
917         unsigned int payload_type;
918         gchar *payload_type_str = NULL;
919         gboolean    is_srtp = FALSE;
920         unsigned int i            = 0;
921         unsigned int hdr_extension= 0;
922         unsigned int padding_count;
923         gint        length, reported_length;
924         int         data_len;
925         unsigned int offset = 0;
926         guint16     seq_num;
927         guint32     timestamp;
928         guint32     sync_src;
929         guint32     csrc_item;
930         struct _rtp_conversation_info *p_conv_data = NULL;
931         struct srtp_info *srtp_info = NULL;
932         unsigned int srtp_offset;
933         tvbuff_t *newtvb = NULL;
934
935         /* Can tap up to 4 RTP packets within same packet */
936         static struct _rtp_info rtp_info_arr[4];
937         static int rtp_info_current=0;
938         struct _rtp_info *rtp_info;
939
940         rtp_info_current++;
941         if (rtp_info_current==4) {
942                 rtp_info_current=0;
943         }
944         rtp_info = &rtp_info_arr[rtp_info_current];
945
946         /* Get the fields in the first octet */
947         octet1 = tvb_get_guint8( tvb, offset );
948         version = RTP_VERSION( octet1 );
949
950         if (version == 0) {
951                 switch (global_rtp_version0_type) {
952                 case RTP0_STUN:
953                         call_dissector(stun_handle, tvb, pinfo, tree);
954                         return;
955
956                 case RTP0_T38:
957                         call_dissector(t38_handle, tvb, pinfo, tree);
958                         return;
959
960                 case RTP0_INVALID:
961                 default:
962                         ; /* Unknown or unsupported version (let it fall through */
963                 }
964         }
965
966         /* fill in the rtp_info structure */
967         rtp_info->info_version = version;
968         if (version != 2) {
969                 /*
970                  * Unknown or unsupported version.
971                  */
972                 if ( check_col( pinfo->cinfo, COL_PROTOCOL ) )   {
973                         col_set_str( pinfo->cinfo, COL_PROTOCOL, "RTP" );
974                 }
975
976                 if ( check_col( pinfo->cinfo, COL_INFO) ) {
977                         col_add_fstr( pinfo->cinfo, COL_INFO,
978                             "Unknown RTP version %u", version);
979                 }
980
981                 if ( tree ) {
982                         ti = proto_tree_add_item( tree, proto_rtp, tvb, offset, -1, FALSE );
983                         rtp_tree = proto_item_add_subtree( ti, ett_rtp );
984
985                         proto_tree_add_uint( rtp_tree, hf_rtp_version, tvb,
986                             offset, 1, octet1);
987                 }
988                 return;
989         }
990
991         padding_set = RTP_PADDING( octet1 );
992         extension_set = RTP_EXTENSION( octet1 );
993         csrc_count = RTP_CSRC_COUNT( octet1 );
994
995         /* Get the fields in the second octet */
996         octet2 = tvb_get_guint8( tvb, offset + 1 );
997         marker_set = RTP_MARKER( octet2 );
998         payload_type = RTP_PAYLOAD_TYPE( octet2 );
999
1000         /* Get the subsequent fields */
1001         seq_num = tvb_get_ntohs( tvb, offset + 2 );
1002         timestamp = tvb_get_ntohl( tvb, offset + 4 );
1003         sync_src = tvb_get_ntohl( tvb, offset + 8 );
1004
1005         /* fill in the rtp_info structure */
1006         rtp_info->info_padding_set = padding_set;
1007         rtp_info->info_padding_count = 0;
1008         rtp_info->info_marker_set = marker_set;
1009         rtp_info->info_payload_type = payload_type;
1010         rtp_info->info_seq_num = seq_num;
1011         rtp_info->info_timestamp = timestamp;
1012         rtp_info->info_sync_src = sync_src;
1013         rtp_info->info_is_srtp = FALSE;
1014         rtp_info->info_setup_frame_num = 0;
1015         rtp_info->info_payload_type_str = NULL;
1016
1017         /*
1018          * Do we have all the data?
1019          */
1020         length = tvb_length_remaining(tvb, offset);
1021         reported_length = tvb_reported_length_remaining(tvb, offset);
1022         if (reported_length >= 0 && length >= reported_length) {
1023                 /*
1024                  * Yes.
1025                  */
1026                 rtp_info->info_all_data_present = TRUE;
1027                 rtp_info->info_data_len = reported_length;
1028
1029                 /*
1030                  * Save the pointer to raw rtp data (header + payload incl.
1031                  * padding).
1032                  * That should be safe because the "epan_dissect_t"
1033                  * constructed for the packet has not yet been freed when
1034                  * the taps are called.
1035                  * (Destroying the "epan_dissect_t" will end up freeing
1036                  * all the tvbuffs and hence invalidating pointers to
1037                  * their data.)
1038                  * See "add_packet_to_packet_list()" for details.
1039                  */
1040                 rtp_info->info_data = tvb_get_ptr(tvb, 0, -1);
1041         } else {
1042                 /*
1043                  * No - packet was cut short at capture time.
1044                  */
1045                 rtp_info->info_all_data_present = FALSE;
1046                 rtp_info->info_data_len = 0;
1047                 rtp_info->info_data = NULL;
1048         }
1049
1050         /* Look for conv and add to the frame if found */
1051         get_conv_info(pinfo, rtp_info);
1052         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
1053
1054         if (p_conv_data && p_conv_data->srtp_info) is_srtp = TRUE;
1055         rtp_info->info_is_srtp = is_srtp;
1056
1057         if ( check_col( pinfo->cinfo, COL_PROTOCOL ) )   {
1058                 col_set_str( pinfo->cinfo, COL_PROTOCOL, (is_srtp) ? "SRTP" : "RTP" );
1059         }
1060
1061         /* check if this is added as an SRTP stream - if so, don't try to dissector the payload data for now */
1062         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
1063         if (p_conv_data && p_conv_data->srtp_info) {
1064                 srtp_info = p_conv_data->srtp_info;
1065                 if (rtp_info->info_all_data_present) {
1066                         srtp_offset = rtp_info->info_data_len - srtp_info->mki_len - srtp_info->auth_tag_len;
1067                 }
1068         }
1069
1070         /* if it is dynamic payload, let use the conv data to see if it is defined */
1071         if ( (payload_type>95) && (payload_type<128) ) {
1072                 if (p_conv_data && p_conv_data->rtp_dyn_payload){
1073                         payload_type_str = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &payload_type);
1074                         rtp_info->info_payload_type_str = payload_type_str;
1075                 }
1076         }
1077
1078         if ( check_col( pinfo->cinfo, COL_INFO) ) {
1079                 col_add_fstr( pinfo->cinfo, COL_INFO,
1080                     "PT=%s, SSRC=0x%X, Seq=%u, Time=%u%s",
1081                         payload_type_str ? payload_type_str : val_to_str( payload_type, rtp_payload_type_vals,"Unknown (%u)" ),
1082                     sync_src,
1083                     seq_num,
1084                     timestamp,
1085                     marker_set ? ", Mark " : " ");
1086         }
1087
1088
1089         if ( tree ) {
1090                 proto_tree *item;
1091                 /* Create RTP protocol tree */
1092                 ti = proto_tree_add_item(tree, proto_rtp, tvb, offset, -1, FALSE );
1093                 rtp_tree = proto_item_add_subtree(ti, ett_rtp );
1094
1095                 /* Conversation setup info */
1096                 if (global_rtp_show_setup_info)
1097                 {
1098                         show_setup_info(tvb, pinfo, rtp_tree);
1099                 }
1100
1101                 proto_tree_add_uint( rtp_tree, hf_rtp_version, tvb,
1102                     offset, 1, octet1 );
1103                 proto_tree_add_boolean( rtp_tree, hf_rtp_padding, tvb,
1104                     offset, 1, octet1 );
1105                 proto_tree_add_boolean( rtp_tree, hf_rtp_extension, tvb,
1106                     offset, 1, octet1 );
1107                 proto_tree_add_uint( rtp_tree, hf_rtp_csrc_count, tvb,
1108                     offset, 1, octet1 );
1109                 offset++;
1110
1111                 proto_tree_add_boolean( rtp_tree, hf_rtp_marker, tvb, offset,
1112                     1, octet2 );
1113
1114                 item = proto_tree_add_uint_format( rtp_tree, hf_rtp_payload_type, tvb,
1115                     offset, 1, octet2, "Payload type: %s (%u)",
1116                         payload_type_str ? payload_type_str : val_to_str( payload_type, rtp_payload_type_vals,"Unknown"),
1117                         payload_type);
1118
1119                 offset++;
1120
1121                 /* Sequence number 16 bits (2 octets) */
1122                 proto_tree_add_uint( rtp_tree, hf_rtp_seq_nr, tvb, offset, 2, seq_num );
1123                 if(p_conv_data != NULL) {
1124                         item = proto_tree_add_uint( rtp_tree, hf_rtp_ext_seq_nr, tvb, offset, 2, p_conv_data->extended_seqno );
1125                         PROTO_ITEM_SET_GENERATED(item);
1126                 }
1127                 offset += 2;
1128
1129                 /* Timestamp 32 bits (4 octets) */
1130                 proto_tree_add_uint( rtp_tree, hf_rtp_timestamp, tvb, offset, 4, timestamp );
1131                 offset += 4;
1132
1133                 /* Synchronization source identifier 32 bits (4 octets) */
1134                 proto_tree_add_uint( rtp_tree, hf_rtp_ssrc, tvb, offset, 4, sync_src );
1135                 offset += 4;
1136         } else {
1137                 offset += 12;
1138         }
1139         /* CSRC list*/
1140         if ( csrc_count > 0 ) {
1141                 if ( tree ) {
1142                         ti = proto_tree_add_item(rtp_tree, hf_rtp_csrc_items, tvb, offset,
1143                                                  csrc_count * 4, FALSE);
1144                         proto_item_append_text(ti, " (%u items)", csrc_count);
1145                         rtp_csrc_tree = proto_item_add_subtree( ti, ett_csrc_list );
1146                 }
1147                 for (i = 0; i < csrc_count; i++ ) {
1148                         csrc_item = tvb_get_ntohl( tvb, offset );
1149                         if ( tree ) proto_tree_add_uint_format( rtp_csrc_tree,
1150                             hf_rtp_csrc_item, tvb, offset, 4,
1151                             csrc_item,
1152                             "CSRC item %d: 0x%X",
1153                             i, csrc_item );
1154                         offset += 4;
1155                 }
1156         }
1157
1158         /* Optional RTP header extension */
1159         if ( extension_set ) {
1160                 /* Defined by profile field is 16 bits (2 octets) */
1161                 if ( tree ) proto_tree_add_uint( rtp_tree, hf_rtp_prof_define, tvb, offset, 2, tvb_get_ntohs( tvb, offset ) );
1162                 offset += 2;
1163
1164                 hdr_extension = tvb_get_ntohs( tvb, offset );
1165                 if ( tree ) proto_tree_add_uint( rtp_tree, hf_rtp_length, tvb, offset, 2, hdr_extension);
1166                 offset += 2;
1167                 if ( hdr_extension > 0 ) {
1168                         if ( tree ) {
1169                                 ti = proto_tree_add_item(rtp_tree, hf_rtp_hdr_exts, tvb, offset, hdr_extension * 4, FALSE);
1170                                 rtp_hext_tree = proto_item_add_subtree( ti, ett_hdr_ext );
1171                         }
1172
1173                         /* pass interpretation of header extension to a registered subdissector */
1174                         newtvb = tvb_new_subset(tvb, offset, hdr_extension * 4, hdr_extension * 4);
1175                         if ( !(rtp_info->info_payload_type_str && dissector_try_string(rtp_hdr_ext_dissector_table,
1176                                 rtp_info->info_payload_type_str, newtvb, pinfo, rtp_hext_tree)) ) {
1177                                 for ( i = 0; i < hdr_extension; i++ ) {
1178                                         if ( tree ) proto_tree_add_uint( rtp_hext_tree, hf_rtp_hdr_ext, tvb, offset, 4, tvb_get_ntohl( tvb, offset ) );
1179                                 }
1180                         }
1181                         offset += hdr_extension * 4;
1182                 }
1183         }
1184
1185         if ( padding_set ) {
1186                 /*
1187                  * This RTP frame has padding - find it.
1188                  *
1189                  * The padding count is found in the LAST octet of
1190                  * the packet; it contains the number of octets
1191                  * that can be ignored at the end of the packet.
1192                  */
1193                 if (tvb_length(tvb) < tvb_reported_length(tvb)) {
1194                         /*
1195                          * We don't *have* the last octet of the
1196                          * packet, so we can't get the padding
1197                          * count.
1198                          *
1199                          * Put an indication of that into the
1200                          * tree, and just put in a raw data
1201                          * item.
1202                          */
1203                         if ( tree ) proto_tree_add_text(rtp_tree, tvb, 0, 0,
1204                             "Frame has padding, but not all the frame data was captured");
1205                         call_dissector(data_handle,
1206                             tvb_new_subset(tvb, offset, -1, -1),
1207                             pinfo, rtp_tree);
1208                         return;
1209                 }
1210
1211                 padding_count = tvb_get_guint8( tvb,
1212                     tvb_reported_length( tvb ) - 1 );
1213                 data_len =
1214                     tvb_reported_length_remaining( tvb, offset ) - padding_count;
1215
1216                 rtp_info->info_payload_offset = offset;
1217                 rtp_info->info_payload_len = tvb_length_remaining(tvb, offset);
1218                 rtp_info->info_padding_count = padding_count;
1219
1220                 if (data_len > 0) {
1221                         /*
1222                          * There's data left over when you take out
1223                          * the padding; dissect it.
1224                          */
1225                         dissect_rtp_data( tvb, pinfo, tree, rtp_tree,
1226                             offset,
1227                             data_len,
1228                             data_len,
1229                             payload_type );
1230                         offset += data_len;
1231                 } else if (data_len < 0) {
1232                         /*
1233                          * The padding count is bigger than the
1234                          * amount of RTP payload in the packet!
1235                          * Clip the padding count.
1236                          *
1237                          * XXX - put an item in the tree to indicate
1238                          * that the padding count is bogus?
1239                          */
1240                         padding_count =
1241                             tvb_reported_length_remaining(tvb, offset);
1242                 }
1243                 if (padding_count > 1) {
1244                         /*
1245                          * There's more than one byte of padding;
1246                          * show all but the last byte as padding
1247                          * data.
1248                          */
1249                         if ( tree ) proto_tree_add_item( rtp_tree, hf_rtp_padding_data,
1250                             tvb, offset, padding_count - 1, FALSE );
1251                         offset += padding_count - 1;
1252                 }
1253                 /*
1254                  * Show the last byte in the PDU as the padding
1255                  * count.
1256                  */
1257                 if ( tree ) proto_tree_add_item( rtp_tree, hf_rtp_padding_count,
1258                     tvb, offset, 1, FALSE );
1259         }
1260         else {
1261                 /*
1262                  * No padding.
1263                  */
1264                 dissect_rtp_data( tvb, pinfo, tree, rtp_tree, offset,
1265                     tvb_length_remaining( tvb, offset ),
1266                     tvb_reported_length_remaining( tvb, offset ),
1267                     payload_type );
1268                 rtp_info->info_payload_offset = offset;
1269                 rtp_info->info_payload_len = tvb_length_remaining(tvb, offset);
1270         }
1271         if (!pinfo->in_error_pkt)
1272                 tap_queue_packet(rtp_tap, pinfo, rtp_info);
1273 }
1274
1275
1276 /* calculate the extended sequence number - top 16 bits of the previous sequence number,
1277  * plus our own; then correct for wrapping */
1278 static guint32 calculate_extended_seqno(guint32 previous_seqno, guint16 raw_seqno)
1279 {
1280         guint32 seqno = (previous_seqno & 0xffff0000) | raw_seqno;
1281         if(seqno + 0x8000 < previous_seqno) {
1282                 seqno += 0x10000;
1283         } else if(previous_seqno + 0x8000 < seqno) {
1284                 /* we got an out-of-order packet which happened to go backwards over the
1285                  * wrap boundary */
1286                 seqno -= 0x10000;
1287         }
1288         return seqno;
1289 }
1290
1291 /* Look for conversation info */
1292 static void get_conv_info(packet_info *pinfo, struct _rtp_info *rtp_info)
1293 {
1294         /* Conversation and current data */
1295         conversation_t *p_conv = NULL;
1296         struct _rtp_conversation_info *p_conv_data = NULL;
1297
1298         /* Use existing packet info if available */
1299         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
1300
1301         if (!p_conv_data)
1302         {
1303                 /* First time, get info from conversation */
1304                 p_conv = find_conversation(pinfo->fd->num, &pinfo->net_dst, &pinfo->net_src,
1305                                            pinfo->ptype,
1306                                            pinfo->destport, pinfo->srcport, NO_ADDR_B);
1307                 if (p_conv)
1308                 {
1309                         /* Create space for packet info */
1310                         struct _rtp_conversation_info *p_conv_packet_data;
1311                         p_conv_data = conversation_get_proto_data(p_conv, proto_rtp);
1312
1313                         if (p_conv_data) {
1314                                 guint32 seqno;
1315
1316                                 /* Save this conversation info into packet info */
1317                                 p_conv_packet_data = se_alloc(sizeof(struct _rtp_conversation_info));
1318                                 g_snprintf(p_conv_packet_data->method, MAX_RTP_SETUP_METHOD_SIZE+1, "%s", p_conv_data->method);
1319                                 p_conv_packet_data->method[MAX_RTP_SETUP_METHOD_SIZE]='\0';
1320                                 p_conv_packet_data->frame_number = p_conv_data->frame_number;
1321                                 p_conv_packet_data->rtp_dyn_payload = p_conv_data->rtp_dyn_payload;
1322                                 p_conv_packet_data->rtp_conv_info = p_conv_data->rtp_conv_info;
1323                                 p_conv_packet_data->srtp_info = p_conv_data->srtp_info;
1324                                 p_add_proto_data(pinfo->fd, proto_rtp, p_conv_packet_data);
1325
1326                                 /* calculate extended sequence number */
1327                                 seqno = calculate_extended_seqno(p_conv_data->extended_seqno,
1328                                                                  rtp_info->info_seq_num);
1329
1330                                 p_conv_packet_data->extended_seqno = seqno;
1331                                 p_conv_data->extended_seqno = seqno;
1332                         }
1333                 }
1334         }
1335         if (p_conv_data) rtp_info->info_setup_frame_num = p_conv_data->frame_number;
1336 }
1337
1338
1339 /* Display setup info */
1340 static void show_setup_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1341 {
1342         /* Conversation and current data */
1343         struct _rtp_conversation_info *p_conv_data = NULL;
1344                 proto_tree *rtp_setup_tree;
1345         proto_item *ti;
1346
1347         /* Use existing packet info if available */
1348         p_conv_data = p_get_proto_data(pinfo->fd, proto_rtp);
1349
1350         if (!p_conv_data) return;
1351
1352         /* Create setup info subtree with summary info. */
1353         ti =  proto_tree_add_string_format(tree, hf_rtp_setup, tvb, 0, 0,
1354                                                                "",
1355                                                                "Stream setup by %s (frame %u)",
1356                                                                p_conv_data->method,
1357                                                                p_conv_data->frame_number);
1358                 PROTO_ITEM_SET_GENERATED(ti);
1359                 rtp_setup_tree = proto_item_add_subtree(ti, ett_rtp_setup);
1360                 if (rtp_setup_tree)
1361                 {
1362                         /* Add details into subtree */
1363                         proto_item* item = proto_tree_add_uint(rtp_setup_tree, hf_rtp_setup_frame,
1364                                                                tvb, 0, 0, p_conv_data->frame_number);
1365                         PROTO_ITEM_SET_GENERATED(item);
1366                         item = proto_tree_add_string(rtp_setup_tree, hf_rtp_setup_method,
1367                                                      tvb, 0, 0, p_conv_data->method);
1368                         PROTO_ITEM_SET_GENERATED(item);
1369                 }
1370 }
1371
1372 /* Dissect PacketCable CCC header */
1373
1374 static void
1375 dissect_pkt_ccc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1376 {
1377         proto_item *ti            = NULL;
1378         proto_tree *pkt_ccc_tree      = NULL;
1379         const guint8 *ptime = tvb_get_ptr(tvb, 4, 8);
1380
1381         if ( tree ) {
1382                 ti = proto_tree_add_item(tree, proto_pkt_ccc, tvb, 0, 12, FALSE);
1383                 pkt_ccc_tree = proto_item_add_subtree(ti, ett_pkt_ccc);
1384
1385                 proto_tree_add_item(pkt_ccc_tree, hf_pkt_ccc_id, tvb, 0, 4, FALSE);
1386                 proto_tree_add_bytes_format(pkt_ccc_tree, hf_pkt_ccc_ts, tvb,
1387                     4, 8, "NTP timestamp: %s", ntp_fmt_ts(ptime));
1388         }
1389
1390         dissect_rtp(tvb, pinfo, tree);
1391 }
1392
1393
1394 /* Register PacketCable CCC */
1395
1396 void
1397 proto_register_pkt_ccc(void)
1398 {
1399         static hf_register_info hf[] =
1400         {
1401                 {
1402                         &hf_pkt_ccc_id,
1403                         {
1404                                 "PacketCable CCC Identifier",
1405                                 "pkt_ccc.ccc_id",
1406                                 FT_UINT32,
1407                                 BASE_DEC,
1408                                 NULL,
1409                                 0x0,
1410                                 "CCC_ID", HFILL
1411                         }
1412                 },
1413                 {
1414                         &hf_pkt_ccc_ts,
1415                         {
1416                                 "PacketCable CCC Timestamp",
1417                                 "pkt_ccc.ts",
1418                                 FT_BYTES,
1419                                 BASE_NONE,
1420                                 NULL,
1421                                 0x0,
1422                                 "Timestamp", HFILL
1423                         }
1424                 },
1425
1426         };
1427
1428         static gint *ett[] =
1429         {
1430                 &ett_pkt_ccc,
1431         };
1432
1433         module_t *pkt_ccc_module;
1434
1435
1436         proto_pkt_ccc = proto_register_protocol("PacketCable Call Content Connection",
1437             "PKT CCC", "pkt_ccc");
1438         proto_register_field_array(proto_pkt_ccc, hf, array_length(hf));
1439         proto_register_subtree_array(ett, array_length(ett));
1440
1441         register_dissector("pkt_ccc", dissect_pkt_ccc, proto_pkt_ccc);
1442
1443         pkt_ccc_module = prefs_register_protocol(proto_pkt_ccc, NULL);
1444
1445         prefs_register_uint_preference(pkt_ccc_module, "udp_port",
1446                                        "UDP port",
1447                                        "Decode packets on this UDP port as PacketCable CCC",
1448                                        10, &global_pkt_ccc_udp_port);
1449 }
1450
1451 void
1452 proto_reg_handoff_pkt_ccc(void)
1453 {
1454         /*
1455          * Register this dissector as one that can be selected by a
1456          * UDP port number.
1457          */
1458         pkt_ccc_handle = find_dissector("pkt_ccc");
1459         dissector_add_handle("udp.port", pkt_ccc_handle);
1460 }
1461
1462 /* Register RTP */
1463
1464 void
1465 proto_register_rtp(void)
1466 {
1467         static hf_register_info hf[] =
1468         {
1469                 {
1470                         &hf_rtp_version,
1471                         {
1472                                 "Version",
1473                                 "rtp.version",
1474                                 FT_UINT8,
1475                                 BASE_DEC,
1476                                 VALS(rtp_version_vals),
1477                                 0xC0,
1478                                 "", HFILL
1479                         }
1480                 },
1481                 {
1482                         &hf_rtp_padding,
1483                         {
1484                                 "Padding",
1485                                 "rtp.padding",
1486                                 FT_BOOLEAN,
1487                                 8,
1488                                 NULL,
1489                                 0x20,
1490                                 "", HFILL
1491                         }
1492                 },
1493                 {
1494                         &hf_rtp_extension,
1495                         {
1496                                 "Extension",
1497                                 "rtp.ext",
1498                                 FT_BOOLEAN,
1499                                 8,
1500                                 NULL,
1501                                 0x10,
1502                                 "", HFILL
1503                         }
1504                 },
1505                 {
1506                         &hf_rtp_csrc_count,
1507                         {
1508                                 "Contributing source identifiers count",
1509                                 "rtp.cc",
1510                                 FT_UINT8,
1511                                 BASE_DEC,
1512                                 NULL,
1513                                 0x0F,
1514                                 "", HFILL
1515                         }
1516                 },
1517                 {
1518                         &hf_rtp_marker,
1519                         {
1520                                 "Marker",
1521                                 "rtp.marker",
1522                                 FT_BOOLEAN,
1523                                 8,
1524                                 NULL,
1525                                 0x80,
1526                                 "", HFILL
1527                         }
1528                 },
1529                 {
1530                         &hf_rtp_payload_type,
1531                         {
1532                                 "Payload type",
1533                                 "rtp.p_type",
1534                                 FT_UINT8,
1535                                 BASE_DEC,
1536                                 NULL,
1537                                 0x7F,
1538                                 "", HFILL
1539                         }
1540                 },
1541                 {
1542                         &hf_rtp_seq_nr,
1543                         {
1544                                 "Sequence number",
1545                                 "rtp.seq",
1546                                 FT_UINT16,
1547                                 BASE_DEC,
1548                                 NULL,
1549                                 0x0,
1550                                 "", HFILL
1551                         }
1552                 },
1553                 {
1554                         &hf_rtp_ext_seq_nr,
1555                         {
1556                                 "Extended sequence number",
1557                                 "rtp.extseq",
1558                                 FT_UINT32,
1559                                 BASE_DEC,
1560                                 NULL,
1561                                 0x0,
1562                                 "", HFILL
1563                         }
1564                 },
1565                 {
1566                         &hf_rtp_timestamp,
1567                         {
1568                                 "Timestamp",
1569                                 "rtp.timestamp",
1570                                 FT_UINT32,
1571                                 BASE_DEC,
1572                                 NULL,
1573                                 0x0,
1574                                 "", HFILL
1575                         }
1576                 },
1577                 {
1578                         &hf_rtp_ssrc,
1579                         {
1580                                 "Synchronization Source identifier",
1581                                 "rtp.ssrc",
1582                                 FT_UINT32,
1583                                 BASE_HEX_DEC,
1584                                 NULL,
1585                                 0x0,
1586                                 "", HFILL
1587                         }
1588                 },
1589                 {
1590                         &hf_rtp_prof_define,
1591                         {
1592                                 "Defined by profile",
1593                                 "rtp.ext.profile",
1594                                 FT_UINT16,
1595                                 BASE_DEC,
1596                                 NULL,
1597                                 0x0,
1598                                 "", HFILL
1599                         }
1600                 },
1601                 {
1602                         &hf_rtp_length,
1603                         {
1604                                 "Extension length",
1605                                 "rtp.ext.len",
1606                                 FT_UINT16,
1607                                 BASE_DEC,
1608                                 NULL,
1609                                 0x0,
1610                                 "", HFILL
1611                         }
1612                 },
1613                 {
1614                         &hf_rtp_csrc_items,
1615                         {
1616                                 "Contributing Source identifiers",
1617                                 "rtp.csrc.items",
1618                                 FT_NONE,
1619                                 BASE_NONE,
1620                                 NULL,
1621                                 0x0,
1622                                 "", HFILL
1623                         }
1624                 },
1625                 {
1626                         &hf_rtp_csrc_item,
1627                         {
1628                                 "CSRC item",
1629                                 "rtp.csrc.item",
1630                                 FT_UINT32,
1631                                 BASE_HEX_DEC,
1632                                 NULL,
1633                                 0x0,
1634                                 "", HFILL
1635                         }
1636                 },
1637                 {
1638                         &hf_rtp_hdr_exts,
1639                         {
1640                                 "Header extensions",
1641                                 "rtp.hdr_exts",
1642                                 FT_NONE,
1643                                 BASE_NONE,
1644                                 NULL,
1645                                 0x0,
1646                                 "", HFILL
1647                         }
1648                 },
1649                 {
1650                         &hf_rtp_hdr_ext,
1651                         {
1652                                 "Header extension",
1653                                 "rtp.hdr_ext",
1654                                 FT_UINT32,
1655                                 BASE_DEC,
1656                                 NULL,
1657                                 0x0,
1658                                 "", HFILL
1659                         }
1660                 },
1661                 {
1662                         &hf_rtp_data,
1663                         {
1664                                 "Payload",
1665                                 "rtp.payload",
1666                                 FT_BYTES,
1667                                 BASE_HEX,
1668                                 NULL,
1669                                 0x0,
1670                                 "", HFILL
1671                         }
1672                 },
1673                 {
1674                         &hf_rtp_padding_data,
1675                         {
1676                                 "Padding data",
1677                                 "rtp.padding.data",
1678                                 FT_BYTES,
1679                                 BASE_HEX,
1680                                 NULL,
1681                                 0x0,
1682                                 "", HFILL
1683                         }
1684                 },
1685                 {
1686                         &hf_rtp_padding_count,
1687                         {
1688                                 "Padding count",
1689                                 "rtp.padding.count",
1690                                 FT_UINT8,
1691                                 BASE_DEC,
1692                                 NULL,
1693                                 0x0,
1694                                 "", HFILL
1695                         }
1696                 },
1697                 {
1698                         &hf_rtp_setup,
1699                         {
1700                                 "Stream setup",
1701                                 "rtp.setup",
1702                                 FT_STRING,
1703                                 BASE_NONE,
1704                                 NULL,
1705                                 0x0,
1706                                 "Stream setup, method and frame number", HFILL
1707                         }
1708                 },
1709                 {
1710                         &hf_rtp_setup_frame,
1711                         {
1712                                 "Setup frame",
1713                                 "rtp.setup-frame",
1714                                 FT_FRAMENUM,
1715                                 BASE_NONE,
1716                                 NULL,
1717                                 0x0,
1718                                 "Frame that set up this stream", HFILL
1719                         }
1720                 },
1721                 {
1722                         &hf_rtp_setup_method,
1723                         {
1724                                 "Setup Method",
1725                                 "rtp.setup-method",
1726                                 FT_STRING,
1727                                 BASE_NONE,
1728                                 NULL,
1729                                 0x0,
1730                                 "Method used to set up this stream", HFILL
1731                         }
1732                 },
1733                 {
1734                         &hf_rtp_rfc2198_follow,
1735                         {
1736                                 "Follow",
1737                                 "rtp.follow",
1738                                 FT_BOOLEAN,
1739                                 8,
1740                                 TFS(&flags_set_truth),
1741                                 0x80,
1742                                 "Next header follows", HFILL
1743                         }
1744                 },
1745                 {
1746                         &hf_rtp_rfc2198_tm_off,
1747                         {
1748                                 "Timestamp offset",
1749                                 "rtp.timestamp-offset",
1750                                 FT_UINT16,
1751                                 BASE_DEC,
1752                                 NULL,
1753                                 0xFFFC,
1754                                 "Timestamp Offset", HFILL
1755                         }
1756                 },
1757                 {
1758                         &hf_rtp_rfc2198_bl_len,
1759                         {
1760                                 "Block length",
1761                                 "rtp.block-length",
1762                                 FT_UINT16,
1763                                 BASE_DEC,
1764                                 NULL,
1765                                 0x03FF,
1766                                 "Block Length", HFILL
1767                         }
1768                 },
1769         
1770                 /* reassembly stuff */
1771                 {&hf_rtp_fragments,
1772                  {"RTP Fragments", "rtp.fragments", FT_NONE, BASE_NONE, NULL, 0x0,
1773                   "RTP Fragments", HFILL }
1774                 },
1775
1776                 {&hf_rtp_fragment,
1777                  {"RTP Fragment data", "rtp.fragment", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1778                   "RTP Fragment data", HFILL }
1779                 },
1780
1781                 {&hf_rtp_fragment_overlap,
1782                  {"Fragment overlap", "rtp.fragment.overlap", FT_BOOLEAN, BASE_NONE,
1783                   NULL, 0x0, "Fragment overlaps with other fragments", HFILL }
1784                 },
1785
1786                 {&hf_rtp_fragment_overlap_conflict,
1787                  {"Conflicting data in fragment overlap", "rtp.fragment.overlap.conflict",
1788                   FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1789                   "Overlapping fragments contained conflicting data", HFILL }
1790                 },
1791
1792                 {&hf_rtp_fragment_multiple_tails,
1793                  {"Multiple tail fragments found", "rtp.fragment.multipletails",
1794                   FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1795                   "Several tails were found when defragmenting the packet", HFILL }
1796                 },
1797
1798                 {&hf_rtp_fragment_too_long_fragment,
1799                  {"Fragment too long", "rtp.fragment.toolongfragment",
1800                   FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1801                   "Fragment contained data past end of packet", HFILL }
1802                 },
1803
1804                 {&hf_rtp_fragment_error,
1805                  {"Defragmentation error", "rtp.fragment.error",
1806                   FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1807                   "Defragmentation error due to illegal fragments", HFILL }
1808                 },
1809
1810                 {&hf_rtp_reassembled_in,
1811                  {"RTP fragment, reassembled in frame", "rtp.reassembled_in",
1812                   FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1813                   "This RTP packet is reassembled in this frame", HFILL }
1814                 },
1815                 {&hf_srtp_encrypted_payload,
1816                  {"SRTP Encrypted Payload", "srtp.enc_payload",
1817                   FT_BYTES, BASE_NONE, NULL, 0x0,
1818                   "SRTP Encrypted Payload", HFILL }
1819                 },
1820                 {&hf_srtp_mki,
1821                  {"SRTP MKI", "srtp.mki",
1822                   FT_BYTES, BASE_NONE, NULL, 0x0,
1823                   "SRTP Master Key Index", HFILL }
1824                 },
1825                 {&hf_srtp_auth_tag,
1826                  {"SRTP Auth Tag", "srtp.auth_tag",
1827                   FT_BYTES, BASE_NONE, NULL, 0x0,
1828                   "SRTP Authentication Tag", HFILL }
1829                 }
1830
1831         };
1832
1833         static gint *ett[] =
1834         {
1835                 &ett_rtp,
1836                 &ett_csrc_list,
1837                 &ett_hdr_ext,
1838                 &ett_rtp_setup,
1839                 &ett_rtp_rfc2198,
1840                 &ett_rtp_rfc2198_hdr,
1841                 &ett_rtp_fragment,
1842                 &ett_rtp_fragments
1843         };
1844
1845         module_t *rtp_module;
1846
1847
1848         proto_rtp = proto_register_protocol("Real-Time Transport Protocol",
1849             "RTP", "rtp");
1850         proto_register_field_array(proto_rtp, hf, array_length(hf));
1851         proto_register_subtree_array(ett, array_length(ett));
1852
1853         register_dissector("rtp", dissect_rtp, proto_rtp);
1854         register_dissector("rtp.rfc2198", dissect_rtp_rfc2198, proto_rtp);
1855
1856         rtp_tap = register_tap("rtp");
1857
1858         rtp_pt_dissector_table = register_dissector_table("rtp.pt",
1859                                                           "RTP payload type", FT_UINT8, BASE_DEC);
1860         rtp_dyn_pt_dissector_table = register_dissector_table("rtp_dyn_payload_type",
1861                                                                                                     "Dynamic RTP payload type", FT_STRING, BASE_NONE);
1862
1863
1864         rtp_hdr_ext_dissector_table = register_dissector_table("rtp_hdr_ext", 
1865                                                                                                         "RTP header extension", FT_STRING, BASE_NONE);
1866
1867         rtp_module = prefs_register_protocol(proto_rtp, proto_reg_handoff_rtp);
1868
1869         prefs_register_bool_preference(rtp_module, "show_setup_info",
1870                                        "Show stream setup information",
1871                                        "Where available, show which protocol and frame caused "
1872                                        "this RTP stream to be created",
1873                                        &global_rtp_show_setup_info);
1874
1875         prefs_register_bool_preference(rtp_module, "heuristic_rtp",
1876                                        "Try to decode RTP outside of conversations",
1877                                        "If call control SIP/H323/RTSP/.. messages are missing in the trace, "
1878                                        "RTP isn't decoded without this",
1879                                        &global_rtp_heur);
1880
1881         prefs_register_bool_preference(rtp_module, "desegment_rtp_streams",
1882                                        "Allow subdissector to reassemble RTP streams",
1883                                        "Whether subdissector can request RTP streams to be reassembled",
1884                                        &desegment_rtp);
1885
1886         prefs_register_enum_preference(rtp_module, "version0_type",
1887                                        "Treat RTP version 0 packets as",
1888                                        "If an RTP version 0 packet is encountered, it can be treated as an invalid packet, a STUN packet, or a T.38 packet",
1889                                        &global_rtp_version0_type,
1890                                        rtp_version0_types, FALSE);
1891     prefs_register_uint_preference(rtp_module,
1892                                    "rfc2198_payload_type", "Payload Type for RFC2198",
1893                                    "Payload Type for RFC2198 Redundant Audio Data",
1894                                    10,
1895                                    &rtp_rfc2198_pt);
1896     
1897         register_init_routine(rtp_fragment_init);
1898 }
1899
1900 void
1901 proto_reg_handoff_rtp(void)
1902 {
1903         static gboolean rtp_prefs_initialized = FALSE;
1904
1905         data_handle = find_dissector("data");
1906         stun_handle = find_dissector("stun");
1907         t38_handle = find_dissector("t38");
1908         /*
1909          * Register this dissector as one that can be selected by a
1910          * UDP port number.
1911          */
1912         rtp_handle = find_dissector("rtp");
1913         rtp_rfc2198_handle = find_dissector("rtp.rfc2198");
1914
1915         dissector_add_handle("udp.port", rtp_handle);
1916
1917         dissector_add_string("rtp_dyn_payload_type", "red", rtp_rfc2198_handle);
1918
1919         if (rtp_prefs_initialized) {
1920                 dissector_delete("rtp.pt", rtp_saved_rfc2198_pt, rtp_rfc2198_handle);
1921         } else {
1922                 rtp_prefs_initialized = TRUE;
1923         }
1924         rtp_saved_rfc2198_pt = rtp_rfc2198_pt;
1925         dissector_add("rtp.pt", rtp_saved_rfc2198_pt, rtp_rfc2198_handle);
1926
1927         heur_dissector_add( "udp", dissect_rtp_heur, proto_rtp);
1928 }
1929
1930 /*
1931  * Local Variables:
1932  * c-basic-offset: 8
1933  * indent-tabs-mode: t
1934  * tab-width: 8
1935  * End:
1936  */