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