From Michael Labedzki, call data dissector instead if handle is NULL.
[metze/wireshark/wip.git] / epan / dissectors / packet-rtp.c
1 /* packet-rtp.c
2  *
3  * Routines for RTP dissection
4  * RTP = Real time Transport Protocol
5  *
6  * Copyright 2000, Philips Electronics N.V.
7  * Written by Andreas Sikkema <h323@ramdyne.nl>
8  *
9  * $Id$
10  *
11  * Wireshark - Network traffic analyzer
12  * By Gerald Combs <gerald@wireshark.org>
13  * Copyright 1998 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28  */
29
30 /*
31  * This dissector tries to dissect the RTP protocol according to Annex A
32  * of ITU-T Recommendation H.225.0 (02/98) or RFC 1889
33  *
34  * RTP traffic is handled by an even UDP portnumber. This can be any
35  * port number, but there is a registered port available, port 5004
36  * See Annex B of ITU-T Recommendation H.225.0, section B.7
37  *
38  * This doesn't dissect older versions of RTP, such as:
39  *
40  *    the vat protocol ("version 0") - see
41  *
42  *      ftp://ftp.ee.lbl.gov/conferencing/vat/alpha-test/vatsrc-4.0b2.tar.gz
43  *
44  *    and look in "session-vat.cc" if you want to write a dissector
45  *    (have fun - there aren't any nice header files showing the packet
46  *    format);
47  *
48  *    version 1, as documented in
49  *
50  *      ftp://gaia.cs.umass.edu/pub/hgschulz/rtp/draft-ietf-avt-rtp-04.txt
51  *
52  * It also dissects PacketCable CCC-encapsulated RTP data, as described in
53  * chapter 5 of the PacketCable Electronic Surveillance Specification:
54  *
55  *   http://www.packetcable.com/downloads/specs/PKT-SP-ESP1.5-I01-050128.pdf
56  */
57
58
59 #include "config.h"
60
61 #include <epan/packet.h>
62
63 #include "packet-rtp.h"
64
65 #include <epan/rtp_pt.h>
66 #include <epan/conversation.h>
67 #include <epan/reassemble.h>
68 #include <epan/tap.h>
69 #include <epan/epan_dissect.h>
70 #include <epan/prefs.h>
71 #include <epan/wmem/wmem.h>
72 #include <epan/strutil.h>
73
74 /* uncomment this to enable debugging of fragment reassembly */
75 /* #define DEBUG_FRAGMENTS   1 */
76
77 typedef struct _rfc2198_hdr {
78         unsigned int pt;
79         int offset;
80         int len;
81         struct _rfc2198_hdr *next;
82 } rfc2198_hdr;
83
84 /* we have one of these for each pdu which spans more than one segment
85  */
86 typedef struct _rtp_multisegment_pdu {
87         /* the seqno of the segment where the pdu starts */
88         guint32 startseq;
89
90         /* the seqno of the segment where the pdu ends */
91         guint32 endseq;
92 } rtp_multisegment_pdu;
93
94 typedef struct  _rtp_private_conv_info {
95         /* This tree is indexed by sequence number and keeps track of all
96          * all pdus spanning multiple segments for this flow.
97          */
98         wmem_tree_t *multisegment_pdus;
99 } rtp_private_conv_info;
100
101 static reassembly_table rtp_reassembly_table;
102
103 static int hf_rtp_fragments = -1;
104 static int hf_rtp_fragment = -1;
105 static int hf_rtp_fragment_overlap = -1;
106 static int hf_rtp_fragment_overlap_conflict = -1;
107 static int hf_rtp_fragment_multiple_tails = -1;
108 static int hf_rtp_fragment_too_long_fragment = -1;
109 static int hf_rtp_fragment_error = -1;
110 static int hf_rtp_fragment_count = -1;
111 static int hf_rtp_reassembled_in = -1;
112 static int hf_rtp_reassembled_length = -1;
113
114 static gint ett_rtp_fragment = -1;
115 static gint ett_rtp_fragments = -1;
116
117 static const fragment_items rtp_fragment_items = {
118         &ett_rtp_fragment,
119         &ett_rtp_fragments,
120         &hf_rtp_fragments,
121         &hf_rtp_fragment,
122         &hf_rtp_fragment_overlap,
123         &hf_rtp_fragment_overlap_conflict,
124         &hf_rtp_fragment_multiple_tails,
125         &hf_rtp_fragment_too_long_fragment,
126         &hf_rtp_fragment_error,
127         &hf_rtp_fragment_count,
128         &hf_rtp_reassembled_in,
129         &hf_rtp_reassembled_length,
130         /* Reassembled data field */
131         NULL,
132         "RTP fragments"
133 };
134
135 static dissector_handle_t rtp_handle;
136 static dissector_handle_t classicstun_handle;
137 static dissector_handle_t stun_handle;
138 static dissector_handle_t classicstun_heur_handle;
139 static dissector_handle_t stun_heur_handle;
140 static dissector_handle_t t38_handle;
141 static dissector_handle_t zrtp_handle;
142
143 static dissector_handle_t sprt_handle;
144 static dissector_handle_t v150fw_handle;
145
146 static dissector_handle_t bta2dp_content_protection_header_scms_t;
147 static dissector_handle_t btvdp_content_protection_header_scms_t;
148 static dissector_handle_t bta2dp_handle;
149 static dissector_handle_t btvdp_handle;
150 static dissector_handle_t sbc_handle;
151
152 static int rtp_tap = -1;
153
154 static dissector_table_t rtp_pt_dissector_table;
155 static dissector_table_t rtp_dyn_pt_dissector_table;
156
157 static dissector_table_t rtp_hdr_ext_dissector_table;
158 static dissector_table_t rtp_hdr_ext_rfc5285_dissector_table;
159
160 /* RTP header fields             */
161 static int proto_rtp           = -1;
162 static int hf_rtp_version      = -1;
163 static int hf_rtp_padding      = -1;
164 static int hf_rtp_extension    = -1;
165 static int hf_rtp_csrc_count   = -1;
166 static int hf_rtp_marker       = -1;
167 static int hf_rtp_payload_type = -1;
168 static int hf_rtp_seq_nr       = -1;
169 static int hf_rtp_ext_seq_nr   = -1;
170 static int hf_rtp_timestamp    = -1;
171 static int hf_rtp_ssrc         = -1;
172 static int hf_rtp_csrc_items   = -1;
173 static int hf_rtp_csrc_item    = -1;
174 static int hf_rtp_data         = -1;
175 static int hf_rtp_padding_data = -1;
176 static int hf_rtp_padding_count= -1;
177 static int hf_rtp_rfc2198_follow= -1;
178 static int hf_rtp_rfc2198_tm_off= -1;
179 static int hf_rtp_rfc2198_bl_len= -1;
180
181 /* RTP header extension fields   */
182 static int hf_rtp_prof_define  = -1;
183 static int hf_rtp_length       = -1;
184 static int hf_rtp_hdr_exts     = -1;
185 static int hf_rtp_hdr_ext      = -1;
186
187 /* RTP header ED137A extension fields   */
188 static int hf_rtp_hdr_ed137s    = -1;
189 static int hf_rtp_hdr_ed137     = -1;
190 static int hf_rtp_hdr_ed137a     = -1;
191 static int hf_rtp_hdr_ed137_ptt_type  = -1;
192 static int hf_rtp_hdr_ed137_squ       = -1;
193 static int hf_rtp_hdr_ed137_ptt_id    = -1;
194 static int hf_rtp_hdr_ed137_sct       = -1;
195 static int hf_rtp_hdr_ed137_x         = -1;
196 static int hf_rtp_hdr_ed137_x_nu      = -1;
197 static int hf_rtp_hdr_ed137_ft_type   = -1;
198 static int hf_rtp_hdr_ed137_ft_len    = -1;
199 static int hf_rtp_hdr_ed137_ft_value  = -1;
200 static int hf_rtp_hdr_ed137_ft_bss_qidx  = -1;
201 static int hf_rtp_hdr_ed137_ft_bss_rssi_qidx  = -1;
202 static int hf_rtp_hdr_ed137_ft_bss_qidx_ml  = -1;
203 static int hf_rtp_hdr_ed137_ft_bss_nu  = -1;
204 static int hf_rtp_hdr_ed137_vf  = -1;
205 static int hf_rtp_hdr_ed137a_ptt_type  = -1;
206 static int hf_rtp_hdr_ed137a_squ       = -1;
207 static int hf_rtp_hdr_ed137a_ptt_id    = -1;
208 static int hf_rtp_hdr_ed137a_pm        = -1;
209 static int hf_rtp_hdr_ed137a_ptts      = -1;
210 static int hf_rtp_hdr_ed137a_sct       = -1;
211 static int hf_rtp_hdr_ed137a_reserved  = -1;
212 static int hf_rtp_hdr_ed137a_x         = -1;
213 static int hf_rtp_hdr_ed137a_x_nu      = -1;
214 static int hf_rtp_hdr_ed137a_ft_type   = -1;
215 static int hf_rtp_hdr_ed137a_ft_len    = -1;
216 static int hf_rtp_hdr_ed137a_ft_value  = -1;
217 static gint ett_hdr_ext_ed137s  = -1;
218 static gint ett_hdr_ext_ed137   = -1;
219 static gint ett_hdr_ext_ed137a   = -1;
220
221 /* RTP setup fields */
222 static int hf_rtp_setup        = -1;
223 static int hf_rtp_setup_frame  = -1;
224 static int hf_rtp_setup_method = -1;
225
226 /* RTP fields defining a sub tree */
227 static gint ett_rtp       = -1;
228 static gint ett_csrc_list = -1;
229 static gint ett_hdr_ext   = -1;
230 static gint ett_hdr_ext_rfc5285 = -1;
231 static gint ett_rtp_setup = -1;
232 static gint ett_rtp_rfc2198 = -1;
233 static gint ett_rtp_rfc2198_hdr = -1;
234
235 /* SRTP fields */
236 static int hf_srtp_encrypted_payload = -1;
237 static int hf_srtp_mki = -1;
238 static int hf_srtp_auth_tag = -1;
239
240 /* PacketCable CCC header fields */
241 static int proto_pkt_ccc       = -1;
242 static int hf_pkt_ccc_id       = -1;
243 static int hf_pkt_ccc_ts       = -1;
244
245 /* PacketCable CCC field defining a sub tree */
246 static gint ett_pkt_ccc = -1;
247
248 /* PacketCable CCC port preference */
249 static guint global_pkt_ccc_udp_port = 0;
250
251 /* RFC 5285 Header extensions */
252 static int hf_rtp_ext_rfc5285_id = -1;
253 static int hf_rtp_ext_rfc5285_length = -1;
254 static int hf_rtp_ext_rfc5285_appbits = -1;
255 static int hf_rtp_ext_rfc5285_data = -1;
256
257 #define RTP0_INVALID 0
258 #define RTP0_STUN    1
259 #define RTP0_CLASSICSTUN    2
260 #define RTP0_T38     3
261 #define RTP0_SPRT    4
262
263 static const enum_val_t rtp_version0_types[] = {
264         { "invalid", "Invalid or ZRTP packets", RTP0_INVALID },
265         { "stun", "STUN packets", RTP0_STUN },
266         { "classicstun", "CLASSIC-STUN packets", RTP0_CLASSICSTUN },
267         { "t38", "T.38 packets", RTP0_T38 },
268         { "sprt", "SPRT packets", RTP0_SPRT },
269         { NULL, NULL, 0 }
270 };
271 static gint global_rtp_version0_type = 0;
272
273 static dissector_handle_t data_handle;
274
275 /* Forward declaration we need below */
276 void proto_register_rtp(void);
277 void proto_reg_handoff_rtp(void);
278 void proto_register_pkt_ccc(void);
279 void proto_reg_handoff_pkt_ccc(void);
280
281 static gint dissect_rtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data);
282 static void show_setup_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
283 static void get_conv_info(packet_info *pinfo, struct _rtp_info *rtp_info);
284
285 /* Preferences bool to control whether or not setup info should be shown */
286 static gboolean global_rtp_show_setup_info = TRUE;
287
288 /* Try heuristic RTP decode */
289 static gboolean global_rtp_heur = FALSE;
290
291 /* desegment RTP streams */
292 static gboolean desegment_rtp = TRUE;
293
294 /* RFC2198 Redundant Audio Data */
295 static guint rtp_rfc2198_pt = 99;
296
297 /*
298  * Fields in the first octet of the RTP header.
299  */
300
301 /* Version is the first 2 bits of the first octet*/
302 #define RTP_VERSION(octet)      ((octet) >> 6)
303
304 /* Padding is the third bit; No need to shift, because true is any value
305    other than 0! */
306 #define RTP_PADDING(octet)      ((octet) & 0x20)
307
308 /* Extension bit is the fourth bit */
309 #define RTP_EXTENSION(octet)    ((octet) & 0x10)
310
311 /* ED137 signature */
312 #define RTP_ED137_SIG    0x0067
313
314 /* ED137A signature */
315 #define RTP_ED137A_SIG   0x0167
316
317 /* ED137 PTT */
318 #define RTP_ED137_ptt_mask(octet)   ((octet) & 0xE0000000)
319 #define RTP_ED137A_ptt_mask(octet)   ((octet) & 0xE0000000)
320 #define RTP_ED137_squ_mask(octet)   ((octet) & 0x10000000)
321 #define RTP_ED137A_squ_mask(octet)   ((octet) & 0x10000000)
322
323 /* ED137 extended information */
324 #define RTP_ED137_extended_information(octet)   ((octet) & 0x00400000)
325 #define RTP_ED137A_extended_information(octet)  ((octet) & 0x00010000)
326
327 /* ED137 feature type */
328 #define RTP_ED137_feature_type(octet)  (((octet) & 0x003C0000) >> 18)
329 #define RTP_ED137A_feature_type(octet) (((octet) & 0x0000F000) >> 12)
330
331 /* ED137 feature length */
332 #define RTP_ED137_feature_length(octet)  (((octet) & 0x0003C000) >> 14)
333 #define RTP_ED137A_feature_length(octet) (((octet) & 0x00000F00) >> 8)
334
335 /* ED137 feature value */
336 #define RTP_ED137_feature_value(octet)  (((octet) & 0x00003FFE) >> 1)
337 #define RTP_ED137A_feature_value(octet) (((octet) & 0x000000FF) >> 0)
338
339 /* ED137 BSS constants */
340 #define RTP_ED137_feature_bss_type    0x1
341 #define RTP_ED137_feature_bss_len     11
342 #define RTP_ED137_feature_bss_qidx(octet)   (((octet) & 0x00003FC0) >> 6)
343 #define RTP_ED137_feature_bss_qidx_ml(octet)   (((octet) & 0x00000038) >> 2)
344
345 /* RFC 5215 one byte header signature */
346 #define RTP_RFC5215_ONE_BYTE_SIG        0xBEDE
347
348 /* RFC 5215 two byte header mask and signature */
349 #define RTP_RFC5215_TWO_BYTE_MASK       0xFFF0
350 #define RTP_RFC5215_TWO_BYTE_SIG        0x1000
351
352 /* CSRC count is the last four bits */
353 #define RTP_CSRC_COUNT(octet)   ((octet) & 0xF)
354
355 static const value_string rtp_version_vals[] =
356 {
357         { 2, "RFC 1889 Version" }, /* First for speed */
358         { 0, "Old VAT Version" },
359         { 1, "First Draft Version" },
360         { 0, NULL },
361 };
362
363 static const value_string rtp_ext_profile_vals[] =
364 {
365         { RTP_ED137_SIG, "ED137" },
366         { RTP_ED137A_SIG, "ED137A" },
367         { 0, NULL },
368 };
369
370 static const value_string rtp_ext_ed137_ptt_type[] =
371 {
372         { 0x00, "PTT OFF" },
373         { 0x01, "Normal PTT ON" },
374         { 0x02, "Coupling PTT ON" },
375         { 0x03, "Priority PTT ON" },
376         { 0x04, "Emergency PTT ON" },
377         { 0x05, "Reserved" },
378         { 0x06, "Reserved" },
379         { 0x07, "Reserved" },
380         { 0, NULL },
381 };
382
383 static const value_string rtp_ext_ed137_squ[] =
384 {
385         { 0x00, "SQ OFF" },
386         { 0x01, "SQ ON" },
387         { 0, NULL },
388 };
389
390 static const value_string rtp_ext_ed137_ft_type[] =
391 {
392         { 0x0, "No features" },
393         { 0x1, "Best signal selection" },
394         { 0x2, "CLIMAX time delay" },
395         { 0x3, "Reserved" },
396         { 0x4, "Reserved" },
397         { 0x5, "Reserved" },
398         { 0x6, "Reserved" },
399         { 0x7, "Reserved" },
400         { 0x8, "Reserved" },
401         { 0x9, "Reserved" },
402         { 0xA, "Reserved" },
403         { 0xB, "Vendor reserved" },
404         { 0xC, "Vendor reserved" },
405         { 0xD, "Vendor reserved" },
406         { 0xE, "Vendor reserved" },
407         { 0xF, "Vendor reserved" },
408         { 0, NULL },
409 };
410
411 static const value_string rtp_ext_ed137_vf[] =
412 {
413         { 0x00, "VF OFF" },
414         { 0x01, "VF ON" },
415         { 0, NULL },
416 };
417
418 static const value_string rtp_ext_ed137_ft_bss_rssi_qidx[] =
419 {
420         { 0x00, "lower than -100.00 dBm" },
421         { 0x01, "lower than or equal to -97.86 dBm" },
422         { 0x02, "lower than or equal to -95.71 dBm" },
423         { 0x03, "lower than or equal to -93.57 dBm" },
424         { 0x04, "lower than or equal to -91.43 dBm" },
425         { 0x05, "lower than or equal to -89.29 dBm" },
426         { 0x06, "lower than or equal to -87.14 dBm" },
427         { 0x07, "lower than or equal to -85.00 dBm" },
428         { 0x08, "lower than or equal to -82.86 dBm" },
429         { 0x09, "lower than or equal to -80.71 dBm" },
430         { 0x0a, "lower than or equal to -78.57 dBm" },
431         { 0x0b, "lower than or equal to -76.43 dBm" },
432         { 0x0c, "lower than or equal to -74.29 dBm" },
433         { 0x0d, "lower than or equal to -72.14 dBm" },
434         { 0x0e, "lower than or equal to -70.00 dBm" },
435         { 0x0f, "higher than -70.00 dBm" },
436         { 0, NULL },
437 };
438
439 static const value_string rtp_ext_ed137_ft_bss_qidx_ml[] =
440 {
441         { 0x00, "RSSI" },
442         { 0x01, "AGC Level" },
443         { 0x02, "C/N" },
444         { 0x03, "Standardized PSD" },
445         { 0x04, "Vendor specific method" },
446         { 0x05, "Vendor specific method" },
447         { 0x06, "Vendor specific method" },
448         { 0x07, "Vendor specific method" },
449         { 0, NULL },
450 };
451
452 static const value_string rtp_ext_ed137a_ptt_type[] =
453 {
454         { 0x00, "PTT OFF" },
455         { 0x01, "Normal PTT ON" },
456         { 0x02, "Coupling PTT ON" },
457         { 0x03, "Priority PTT ON" },
458         { 0x04, "Emergency PTT ON" },
459         { 0x05, "Reserved" },
460         { 0x06, "Reserved" },
461         { 0x07, "Reserved" },
462         { 0, NULL },
463 };
464
465 static const value_string rtp_ext_ed137a_squ[] =
466 {
467         { 0x00, "SQ OFF" },
468         { 0x01, "SQ ON" },
469         { 0, NULL },
470 };
471
472 static const value_string rtp_ext_ed137a_ft_type[] =
473 {
474         { 0x0, "No features" },
475         { 0x1, "Signal Quality Information" },
476         { 0x2, "CLIMAX time delay" },
477         { 0x3, "Radio remote control" },
478         { 0x4, "CLIMAX dynamic delay compensation" },
479         { 0x5, "Reserved" },
480         { 0x6, "Reserved" },
481         { 0x7, "Reserved" },
482         { 0x8, "Reserved" },
483         { 0x9, "Reserved" },
484         { 0xA, "Reserved" },
485         { 0xB, "Vendor reserved" },
486         { 0xC, "Vendor reserved" },
487         { 0xD, "Vendor reserved" },
488         { 0xE, "Vendor reserved" },
489         { 0xF, "Vendor reserved" },
490         { 0, NULL },
491 };
492
493 /*
494  * Fields in the second octet of the RTP header.
495  */
496
497 /* Marker is the first bit of the second octet */
498 #define RTP_MARKER(octet)       ((octet) & 0x80)
499
500 /* Payload type is the last 7 bits */
501 #define RTP_PAYLOAD_TYPE(octet) ((octet) & 0x7F)
502 /* http://www.iana.org/assignments/rtp-parameters */
503
504 static const value_string rtp_payload_type_vals[] =
505 {
506 /*  0 */        { PT_PCMU,                      "ITU-T G.711 PCMU" },
507 /*  1 */        { PT_1016,                      "USA Federal Standard FS-1016" },
508 /*  2 */        { PT_G721,                      "ITU-T G.721" },
509 /*  3 */        { PT_GSM,                       "GSM 06.10" },
510 /*  4 */        { PT_G723,                      "ITU-T G.723" },
511 /*  5 */        { PT_DVI4_8000,         "DVI4 8000 samples/s" },
512 /*  6 */        { PT_DVI4_16000,        "DVI4 16000 samples/s" },
513 /*  7 */        { PT_LPC,                       "Experimental linear predictive encoding from Xerox PARC" },
514 /*  8 */        { PT_PCMA,                      "ITU-T G.711 PCMA" },
515 /*  9 */        { PT_G722,                      "ITU-T G.722" },
516 /* 10 */        { PT_L16_STEREO,        "16-bit uncompressed audio, stereo" },
517 /* 11 */        { PT_L16_MONO,          "16-bit uncompressed audio, monaural" },
518 /* 12 */        { PT_QCELP,                     "Qualcomm Code Excited Linear Predictive coding" },
519 /* 13 */        { PT_CN,                        "Comfort noise" },
520 /* 14 */        { PT_MPA,                       "MPEG-I/II Audio"},
521 /* 15 */        { PT_G728,                      "ITU-T G.728" },
522 /* 16 */        { PT_DVI4_11025,        "DVI4 11025 samples/s" },
523 /* 17 */        { PT_DVI4_22050,        "DVI4 22050 samples/s" },
524 /* 18 */        { PT_G729,                      "ITU-T G.729" },
525 /* 19 */        { PT_CN_OLD,            "Comfort noise (old)" },
526 /* 20 */        { 20,                           "Unassigned" },
527 /* 21 */        { 21,                           "Unassigned" },
528 /* 22 */        { 22,                           "Unassigned" },
529 /* 23 */        { 23,                           "Unassigned" },
530 /* 24 */        { 24,                           "Unassigned" },
531 /* 25 */        { PT_CELB,                      "Sun CellB video encoding" },
532 /* 26 */        { PT_JPEG,                      "JPEG-compressed video" },
533 /* 27 */        { 27,                           "Unassigned" },
534 /* 28 */        { PT_NV,                        "'nv' program" },
535 /* 29 */        { 29,                           "Unassigned" },
536 /* 30 */        { 30,                           "Unassigned" },
537 /* 31 */        { PT_H261,                      "ITU-T H.261" },
538 /* 32 */        { PT_MPV,                       "MPEG-I/II Video"},
539 /* 33 */        { PT_MP2T,                      "MPEG-II transport streams"},
540 /* 34 */        { PT_H263,                      "ITU-T H.263" },
541 /* 35-71     Unassigned  */
542 /* 35 */        { 35,                           "Unassigned" },
543 /* 36 */        { 36,                           "Unassigned" },
544 /* 37 */        { 37,                           "Unassigned" },
545 /* 38 */        { 38,                           "Unassigned" },
546 /* 39 */        { 39,                           "Unassigned" },
547 /* 40 */        { 40,                           "Unassigned" },
548 /* 41 */        { 41,                           "Unassigned" },
549 /* 42 */        { 42,                           "Unassigned" },
550 /* 43 */        { 43,                           "Unassigned" },
551 /* 44 */        { 44,                           "Unassigned" },
552 /* 45 */        { 45,                           "Unassigned" },
553 /* 46 */        { 46,                           "Unassigned" },
554 /* 47 */        { 47,                           "Unassigned" },
555 /* 48 */        { 48,                           "Unassigned" },
556 /* 49 */        { 49,                           "Unassigned" },
557 /* 50 */        { 50,                           "Unassigned" },
558 /* 51 */        { 51,                           "Unassigned" },
559 /* 52 */        { 52,                           "Unassigned" },
560 /* 53 */        { 53,                           "Unassigned" },
561 /* 54 */        { 54,                           "Unassigned" },
562 /* 55 */        { 55,                           "Unassigned" },
563 /* 56 */        { 56,                           "Unassigned" },
564 /* 57 */        { 57,                           "Unassigned" },
565 /* 58 */        { 58,                           "Unassigned" },
566 /* 59 */        { 59,                           "Unassigned" },
567 /* 60 */        { 60,                           "Unassigned" },
568 /* 61 */        { 61,                           "Unassigned" },
569 /* 62 */        { 62,                           "Unassigned" },
570 /* 63 */        { 63,                           "Unassigned" },
571 /* 64 */        { 64,                           "Unassigned" },
572 /* 65 */        { 65,                           "Unassigned" },
573 /* 66 */        { 66,                           "Unassigned" },
574 /* 67 */        { 67,                           "Unassigned" },
575 /* 68 */        { 68,                           "Unassigned" },
576 /* 69 */        { 69,                           "Unassigned" },
577 /* 70 */        { 70,                           "Unassigned" },
578 /* 71 */        { 71,                           "Unassigned" },
579 /* 72-76     Reserved for RTCP conflict avoidance                                  [RFC3551] */
580 /* 72 */        { 72,                           "Reserved for RTCP conflict avoidance" },
581 /* 73 */        { 73,                           "Reserved for RTCP conflict avoidance" },
582 /* 74 */        { 74,                           "Reserved for RTCP conflict avoidance" },
583 /* 75 */        { 75,                           "Reserved for RTCP conflict avoidance" },
584 /* 76 */        { 76,                           "Reserved for RTCP conflict avoidance" },
585 /* 77-95     Unassigned      ? */
586 /* 77 */        { 77,                           "Unassigned" },
587 /* 78 */        { 78,                           "Unassigned" },
588 /* 79 */        { 79,                           "Unassigned" },
589 /* 80 */        { 80,                           "Unassigned" },
590 /* 81 */        { 81,                           "Unassigned" },
591 /* 82 */        { 82,                           "Unassigned" },
592 /* 83 */        { 83,                           "Unassigned" },
593 /* 84 */        { 84,                           "Unassigned" },
594 /* 85 */        { 85,                           "Unassigned" },
595 /* 86 */        { 86,                           "Unassigned" },
596 /* 87 */        { 87,                           "Unassigned" },
597 /* 88 */        { 88,                           "Unassigned" },
598 /* 89 */        { 89,                           "Unassigned" },
599 /* 90 */        { 90,                           "Unassigned" },
600 /* 91 */        { 91,                           "Unassigned" },
601 /* 92 */        { 92,                           "Unassigned" },
602 /* 93 */        { 93,                           "Unassigned" },
603 /* 94 */        { 94,                           "Unassigned" },
604 /* 95 */        { 95,                           "Unassigned" },
605                 /* Added to support addtional RTP payload types
606                  * See epan/rtp_pt.h */
607                 { PT_UNDF_96,   "DynamicRTP-Type-96" },
608                 { PT_UNDF_97,   "DynamicRTP-Type-97" },
609                 { PT_UNDF_98,   "DynamicRTP-Type-98" },
610                 { PT_UNDF_99,   "DynamicRTP-Type-99" },
611                 { PT_UNDF_100,  "DynamicRTP-Type-100" },
612                 { PT_UNDF_101,  "DynamicRTP-Type-101" },
613                 { PT_UNDF_102,  "DynamicRTP-Type-102" },
614                 { PT_UNDF_103,  "DynamicRTP-Type-103" },
615                 { PT_UNDF_104,  "DynamicRTP-Type-104" },
616                 { PT_UNDF_105,  "DynamicRTP-Type-105" },
617                 { PT_UNDF_106,  "DynamicRTP-Type-106" },
618                 { PT_UNDF_107,  "DynamicRTP-Type-107" },
619                 { PT_UNDF_108,  "DynamicRTP-Type-108" },
620                 { PT_UNDF_109,  "DynamicRTP-Type-109" },
621                 { PT_UNDF_110,  "DynamicRTP-Type-110" },
622                 { PT_UNDF_111,  "DynamicRTP-Type-111" },
623                 { PT_UNDF_112,  "DynamicRTP-Type-112" },
624                 { PT_UNDF_113,  "DynamicRTP-Type-113" },
625                 { PT_UNDF_114,  "DynamicRTP-Type-114" },
626                 { PT_UNDF_115,  "DynamicRTP-Type-115" },
627                 { PT_UNDF_116,  "DynamicRTP-Type-116" },
628                 { PT_UNDF_117,  "DynamicRTP-Type-117" },
629                 { PT_UNDF_118,  "DynamicRTP-Type-118" },
630                 { PT_UNDF_119,  "DynamicRTP-Type-119" },
631                 { PT_UNDF_120,  "DynamicRTP-Type-120" },
632                 { PT_UNDF_121,  "DynamicRTP-Type-121" },
633                 { PT_UNDF_122,  "DynamicRTP-Type-122" },
634                 { PT_UNDF_123,  "DynamicRTP-Type-123" },
635                 { PT_UNDF_124,  "DynamicRTP-Type-124" },
636                 { PT_UNDF_125,  "DynamicRTP-Type-125" },
637                 { PT_UNDF_126,  "DynamicRTP-Type-126" },
638                 { PT_UNDF_127,  "DynamicRTP-Type-127" },
639
640                 { 0,            NULL },
641 };
642
643 value_string_ext rtp_payload_type_vals_ext = VALUE_STRING_EXT_INIT(rtp_payload_type_vals);
644
645 static const value_string rtp_payload_type_short_vals[] =
646 {
647         { PT_PCMU,      "g711U" },
648         { PT_1016,      "fs-1016" },
649         { PT_G721,      "g721" },
650         { PT_GSM,       "GSM" },
651         { PT_G723,      "g723" },
652         { PT_DVI4_8000, "DVI4 8k" },
653         { PT_DVI4_16000, "DVI4 16k" },
654         { PT_LPC,       "Exp. from Xerox PARC" },
655         { PT_PCMA,      "g711A" },
656         { PT_G722,      "g722" },
657         { PT_L16_STEREO, "16-bit audio, stereo" },
658         { PT_L16_MONO,  "16-bit audio, monaural" },
659         { PT_QCELP,     "Qualcomm" },
660         { PT_CN,        "CN" },
661         { PT_MPA,       "MPEG-I/II Audio"},
662         { PT_G728,      "g728" },
663         { PT_DVI4_11025, "DVI4 11k" },
664         { PT_DVI4_22050, "DVI4 22k" },
665         { PT_G729,      "g729" },
666         { PT_CN_OLD,    "CN(old)" },
667         { 20,                           "Unassigned" },
668         { 21,                           "Unassigned" },
669         { 22,                           "Unassigned" },
670         { 23,                           "Unassigned" },
671         { 24,                           "Unassigned" },
672         { PT_CELB,      "CellB" },
673         { PT_JPEG,      "JPEG" },
674         { 27,                           "Unassigned" },
675         { PT_NV,        "NV" },
676         { 29,                           "Unassigned" },
677         { 30,                           "Unassigned" },
678         { PT_H261,      "h261" },
679         { PT_MPV,       "MPEG-I/II Video"},
680         { PT_MP2T,      "MPEG-II streams"},
681         { PT_H263,      "h263" },
682 /* 35-71     Unassigned  */
683         { 35,                           "Unassigned" },
684         { 36,                           "Unassigned" },
685         { 37,                           "Unassigned" },
686         { 38,                           "Unassigned" },
687         { 39,                           "Unassigned" },
688         { 40,                           "Unassigned" },
689         { 41,                           "Unassigned" },
690         { 42,                           "Unassigned" },
691         { 43,                           "Unassigned" },
692         { 44,                           "Unassigned" },
693         { 45,                           "Unassigned" },
694         { 46,                           "Unassigned" },
695         { 47,                           "Unassigned" },
696         { 48,                           "Unassigned" },
697         { 49,                           "Unassigned" },
698         { 50,                           "Unassigned" },
699         { 51,                           "Unassigned" },
700         { 52,                           "Unassigned" },
701         { 53,                           "Unassigned" },
702         { 54,                           "Unassigned" },
703         { 55,                           "Unassigned" },
704         { 56,                           "Unassigned" },
705         { 57,                           "Unassigned" },
706         { 58,                           "Unassigned" },
707         { 59,                           "Unassigned" },
708         { 60,                           "Unassigned" },
709         { 61,                           "Unassigned" },
710         { 62,                           "Unassigned" },
711         { 63,                           "Unassigned" },
712         { 64,                           "Unassigned" },
713         { 65,                           "Unassigned" },
714         { 66,                           "Unassigned" },
715         { 67,                           "Unassigned" },
716         { 68,                           "Unassigned" },
717         { 69,                           "Unassigned" },
718         { 70,                           "Unassigned" },
719         { 71,                           "Unassigned" },
720 /* 72-76     Reserved for RTCP conflict avoidance  - [RFC3551] */
721         { 72,                           "Reserved for RTCP conflict avoidance" },
722         { 73,                           "Reserved for RTCP conflict avoidance" },
723         { 74,                           "Reserved for RTCP conflict avoidance" },
724         { 75,                           "Reserved for RTCP conflict avoidance" },
725         { 76,                           "Reserved for RTCP conflict avoidance" },
726 /* 77-95     Unassigned      ? */
727         { 77,                           "Unassigned" },
728         { 78,                           "Unassigned" },
729         { 79,                           "Unassigned" },
730         { 80,                           "Unassigned" },
731         { 81,                           "Unassigned" },
732         { 82,                           "Unassigned" },
733         { 83,                           "Unassigned" },
734         { 84,                           "Unassigned" },
735         { 85,                           "Unassigned" },
736         { 86,                           "Unassigned" },
737         { 87,                           "Unassigned" },
738         { 88,                           "Unassigned" },
739         { 89,                           "Unassigned" },
740         { 90,                           "Unassigned" },
741         { 91,                           "Unassigned" },
742         { 92,                           "Unassigned" },
743         { 93,                           "Unassigned" },
744         { 94,                           "Unassigned" },
745         { 95,                           "Unassigned" },
746         /* Short RTP types */
747         { PT_UNDF_96,   "RTPType-96" },
748         { PT_UNDF_97,   "RTPType-97" },
749         { PT_UNDF_98,   "RTPType-98" },
750         { PT_UNDF_99,   "RTPType-99" },
751         { PT_UNDF_100,  "RTPType-100" },
752         { PT_UNDF_101,  "RTPType-101" },
753         { PT_UNDF_102,  "RTPType-102" },
754         { PT_UNDF_103,  "RTPType-103" },
755         { PT_UNDF_104,  "RTPType-104" },
756         { PT_UNDF_105,  "RTPType-105" },
757         { PT_UNDF_106,  "RTPType-106" },
758         { PT_UNDF_107,  "RTPType-107" },
759         { PT_UNDF_108,  "RTPType-108" },
760         { PT_UNDF_109,  "RTPType-109" },
761         { PT_UNDF_110,  "RTPType-110" },
762         { PT_UNDF_111,  "RTPType-111" },
763         { PT_UNDF_112,  "RTPType-112" },
764         { PT_UNDF_113,  "RTPType-113" },
765         { PT_UNDF_114,  "RTPType-114" },
766         { PT_UNDF_115,  "RTPType-115" },
767         { PT_UNDF_116,  "RTPType-116" },
768         { PT_UNDF_117,  "RTPType-117" },
769         { PT_UNDF_118,  "RTPType-118" },
770         { PT_UNDF_119,  "RTPType-119" },
771         { PT_UNDF_120,  "RTPType-120" },
772         { PT_UNDF_121,  "RTPType-121" },
773         { PT_UNDF_122,  "RTPType-122" },
774         { PT_UNDF_123,  "RTPType-123" },
775         { PT_UNDF_124,  "RTPType-124" },
776         { PT_UNDF_125,  "RTPType-125" },
777         { PT_UNDF_126,  "RTPType-126" },
778         { PT_UNDF_127,  "RTPType-127" },
779
780         { 0,            NULL },
781 };
782 value_string_ext rtp_payload_type_short_vals_ext = VALUE_STRING_EXT_INIT(rtp_payload_type_short_vals);
783
784 #if 0
785 static const value_string srtp_encryption_alg_vals[] =
786 {
787         { SRTP_ENC_ALG_NULL,    "Null Encryption" },
788         { SRTP_ENC_ALG_AES_CM,  "AES-128 Counter Mode" },
789         { SRTP_ENC_ALG_AES_F8,  "AES-128 F8 Mode" },
790         { 0, NULL },
791 };
792
793 static const value_string srtp_auth_alg_vals[] =
794 {
795         { SRTP_AUTH_ALG_NONE,           "No Authentication" },
796         { SRTP_AUTH_ALG_HMAC_SHA1,      "HMAC-SHA1" },
797         { 0, NULL },
798 };
799 #endif
800
801 /* initialisation routine */
802 static void
803 rtp_fragment_init(void)
804 {
805         reassembly_table_init(&rtp_reassembly_table,
806                               &addresses_reassembly_table_functions);
807 }
808
809 void
810 rtp_free_hash_dyn_payload(GHashTable *rtp_dyn_payload)
811 {
812         if (rtp_dyn_payload == NULL) return;
813         g_hash_table_destroy(rtp_dyn_payload);
814         rtp_dyn_payload = NULL;
815 }
816
817
818 void
819 bluetooth_add_address(packet_info *pinfo, address *addr,
820                  const gchar *setup_method, guint32 setup_frame_number,
821                  gboolean is_video, void *data)
822 {
823         address null_addr;
824         conversation_t* p_conv;
825         struct _rtp_conversation_info *p_conv_data = NULL;
826         /*
827          * If this isn't the first time this packet has been processed,
828          * we've already done this work, so we don't need to do it
829          * again.
830          */
831         if (pinfo->fd->flags.visited)
832         {
833                 return;
834         }
835
836         SET_ADDRESS(&null_addr, AT_NONE, 0, NULL);
837
838         /*
839          * Check if the ip address and port combination is not
840          * already registered as a conversation.
841          */
842         p_conv = find_conversation(setup_frame_number, addr, &null_addr, PT_BLUETOOTH, 0, 0,
843                                    NO_ADDR_B | NO_PORT_B);
844
845         /*
846          * If not, create a new conversation.
847          */
848         if (!p_conv || p_conv->setup_frame != setup_frame_number) {
849                 p_conv = conversation_new(setup_frame_number, addr, &null_addr, PT_BLUETOOTH, 0, 0,
850                                    NO_ADDR2 | NO_PORT2);
851         }
852
853         /* Set dissector */
854         conversation_set_dissector(p_conv, rtp_handle);
855
856         /*
857          * Check if the conversation has data associated with it.
858          */
859         p_conv_data = (struct _rtp_conversation_info *)conversation_get_proto_data(p_conv, proto_rtp);
860
861         /*
862          * If not, add a new data item.
863          */
864         if (! p_conv_data) {
865                 /* Create conversation data */
866                 p_conv_data = wmem_new(wmem_file_scope(), struct _rtp_conversation_info);
867                 p_conv_data->rtp_dyn_payload = NULL;
868
869                 /* start this at 0x10000 so that we cope gracefully with the
870                  * first few packets being out of order (hence 0,65535,1,2,...)
871                  */
872                 p_conv_data->extended_seqno = 0x10000;
873                 p_conv_data->rtp_conv_info = wmem_new(wmem_file_scope(), rtp_private_conv_info);
874                 p_conv_data->rtp_conv_info->multisegment_pdus = wmem_tree_new(wmem_file_scope());
875                 conversation_add_proto_data(p_conv, proto_rtp, p_conv_data);
876
877                 if (is_video) {
878                         p_conv_data->bta2dp_info = NULL;
879                         p_conv_data->btvdp_info = (btvdp_codec_info_t *) wmem_memdup(wmem_file_scope(), data, sizeof(btvdp_codec_info_t));
880                 } else {
881                         p_conv_data->bta2dp_info = (bta2dp_codec_info_t *) wmem_memdup(wmem_file_scope(), data, sizeof(bta2dp_codec_info_t));
882                         p_conv_data->btvdp_info = NULL;
883                 }
884         }
885
886         /*
887          * Update the conversation data.
888          */
889         /* Free the hash if already exists */
890         rtp_free_hash_dyn_payload(p_conv_data->rtp_dyn_payload);
891
892         g_strlcpy(p_conv_data->method, setup_method, MAX_RTP_SETUP_METHOD_SIZE+1);
893         p_conv_data->frame_number = setup_frame_number;
894         p_conv_data->is_video = is_video;
895         p_conv_data->rtp_dyn_payload = NULL;
896         p_conv_data->srtp_info = NULL;
897 }
898
899 /* Set up an SRTP conversation */
900 void
901 srtp_add_address(packet_info *pinfo, address *addr, int port, int other_port,
902                  const gchar *setup_method, guint32 setup_frame_number,
903                  gboolean is_video _U_, GHashTable *rtp_dyn_payload,
904                  struct srtp_info *srtp_info)
905 {
906         address null_addr;
907         conversation_t* p_conv;
908         struct _rtp_conversation_info *p_conv_data = NULL;
909
910         /*
911          * If this isn't the first time this packet has been processed,
912          * we've already done this work, so we don't need to do it
913          * again.
914          */
915         if (pinfo->fd->flags.visited)
916         {
917                 return;
918         }
919
920 #ifdef DEBUG
921         printf("#%u: %srtp_add_address(%s, %u, %u, %s, %u\n",
922                 pinfo->fd->num, (srtp_info)?"s":"", ep_address_to_str(addr), port,
923                 other_port, setup_method, setup_frame_number);
924 #endif
925
926         SET_ADDRESS(&null_addr, AT_NONE, 0, NULL);
927
928         /*
929          * Check if the ip address and port combination is not
930          * already registered as a conversation.
931          */
932         p_conv = find_conversation(setup_frame_number, addr, &null_addr, PT_UDP, port, other_port,
933                                    NO_ADDR_B | (!other_port ? NO_PORT_B : 0));
934
935         /*
936          * If not, create a new conversation.
937          */
938         if (!p_conv || p_conv->setup_frame != setup_frame_number) {
939                 p_conv = conversation_new(setup_frame_number, addr, &null_addr, PT_UDP,
940                                           (guint32)port, (guint32)other_port,
941                                           NO_ADDR2 | (!other_port ? NO_PORT2 : 0));
942         }
943
944         /* Set dissector */
945         conversation_set_dissector(p_conv, rtp_handle);
946
947         /*
948          * Check if the conversation has data associated with it.
949          */
950         p_conv_data = (struct _rtp_conversation_info *)conversation_get_proto_data(p_conv, proto_rtp);
951
952         /*
953          * If not, add a new data item.
954          */
955         if (! p_conv_data) {
956                 /* Create conversation data */
957                 p_conv_data = wmem_new(wmem_file_scope(), struct _rtp_conversation_info);
958                 p_conv_data->rtp_dyn_payload = NULL;
959
960                 /* start this at 0x10000 so that we cope gracefully with the
961                  * first few packets being out of order (hence 0,65535,1,2,...)
962                  */
963                 p_conv_data->extended_seqno = 0x10000;
964                 p_conv_data->rtp_conv_info = wmem_new(wmem_file_scope(), rtp_private_conv_info);
965                 p_conv_data->rtp_conv_info->multisegment_pdus = wmem_tree_new(wmem_file_scope());
966                 conversation_add_proto_data(p_conv, proto_rtp, p_conv_data);
967         }
968
969         /*
970          * Update the conversation data.
971          */
972         /* Free the hash if already exists */
973         rtp_free_hash_dyn_payload(p_conv_data->rtp_dyn_payload);
974
975         g_strlcpy(p_conv_data->method, setup_method, MAX_RTP_SETUP_METHOD_SIZE+1);
976         p_conv_data->frame_number = setup_frame_number;
977         p_conv_data->is_video = is_video;
978         p_conv_data->rtp_dyn_payload = rtp_dyn_payload;
979         p_conv_data->srtp_info = srtp_info;
980         p_conv_data->bta2dp_info = NULL;
981         p_conv_data->btvdp_info = NULL;
982 }
983
984 /* Set up an RTP conversation */
985 void
986 rtp_add_address(packet_info *pinfo, address *addr, int port, int other_port,
987                 const gchar *setup_method, guint32 setup_frame_number,
988                 gboolean is_video , GHashTable *rtp_dyn_payload)
989 {
990         srtp_add_address(pinfo, addr, port, other_port, setup_method, setup_frame_number, is_video, rtp_dyn_payload, NULL);
991 }
992
993 static gboolean
994 dissect_rtp_heur_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data, gboolean check_destport)
995 {
996         guint8       octet1;
997         unsigned int version;
998         unsigned int offset = 0;
999
1000         /* This is a heuristic dissector, which means we get all the UDP
1001          * traffic not sent to a known dissector and not claimed by
1002          * a heuristic dissector called before us!
1003          */
1004
1005         if (! global_rtp_heur)
1006                 return FALSE;
1007
1008         /* Get the fields in the first octet */
1009         octet1 = tvb_get_guint8( tvb, offset );
1010         version = RTP_VERSION( octet1 );
1011
1012         if (version == 0) {
1013                 if (!(tvb_memeql(tvb, 4, "ZRTP", 4)))
1014                 {
1015                         call_dissector_only(zrtp_handle, tvb, pinfo, tree, NULL);
1016                         return TRUE;
1017                 } else {
1018                         switch (global_rtp_version0_type) {
1019                         case RTP0_STUN:
1020                                 return call_dissector_only(stun_heur_handle, tvb, pinfo, tree, NULL);
1021                         case RTP0_CLASSICSTUN:
1022                                 return call_dissector_only(classicstun_heur_handle, tvb, pinfo, tree, NULL);
1023
1024                         case RTP0_T38:
1025                                 /* XXX: Should really be calling a heuristic dissector for T38 ??? */
1026                                 call_dissector_only(t38_handle, tvb, pinfo, tree, NULL);
1027                                 return TRUE;
1028
1029                         case RTP0_SPRT:
1030                                 call_dissector_only(sprt_handle, tvb, pinfo, tree, NULL);
1031                                 return TRUE;
1032
1033                         case RTP0_INVALID:
1034
1035                         default:
1036                                 return FALSE; /* Unknown or unsupported version */
1037                         }
1038                 }
1039         } else if (version != 2) {
1040                 /* Unknown or unsupported version */
1041                 return FALSE;
1042         }
1043
1044         /* Was it sent to an even-numbered port? */
1045         if (check_destport && ((pinfo->destport % 2) != 0)) {
1046                 return FALSE;
1047         }
1048
1049         dissect_rtp( tvb, pinfo, tree, data );
1050         return TRUE;
1051 }
1052
1053 static gboolean
1054 dissect_rtp_heur_udp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data )
1055 {
1056         return dissect_rtp_heur_common(tvb, pinfo, tree, data, TRUE);
1057 }
1058
1059 static gboolean
1060 dissect_rtp_heur_stun( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data )
1061 {
1062         return dissect_rtp_heur_common(tvb, pinfo, tree, data, FALSE);
1063 }
1064
1065 /*
1066  * Process the payload of the RTP packet, hand it to the subdissector
1067  */
1068 static void
1069 process_rtp_payload(tvbuff_t *newtvb, packet_info *pinfo, proto_tree *tree,
1070                     proto_tree *rtp_tree, unsigned int payload_type)
1071 {
1072         struct _rtp_conversation_info *p_conv_data = NULL;
1073         gboolean found_match = FALSE;
1074         int payload_len;
1075         struct srtp_info *srtp_info;
1076         int offset = 0;
1077
1078         payload_len = tvb_length_remaining(newtvb, offset);
1079
1080         /* first check if this is added as an SRTP stream - if so, don't try to dissector the payload data for now */
1081         p_conv_data = (struct _rtp_conversation_info *)p_get_proto_data(pinfo->fd, proto_rtp, 0);
1082         if (p_conv_data && p_conv_data->srtp_info) {
1083                 srtp_info = p_conv_data->srtp_info;
1084                 payload_len -= srtp_info->mki_len + srtp_info->auth_tag_len;
1085 #if 0
1086 #error Currently the srtp_info structure contains no cipher data, see packet-sdp.c adding dummy_srtp_info structure
1087                 if (p_conv_data->srtp_info->encryption_algorithm==SRTP_ENC_ALG_NULL) {
1088                         if (rtp_tree)
1089                                 proto_tree_add_text(rtp_tree, newtvb, offset, payload_len, "SRTP Payload with NULL encryption");
1090                 }
1091                 else
1092 #endif
1093                 {
1094                         if (rtp_tree)
1095                                 proto_tree_add_item(rtp_tree, hf_srtp_encrypted_payload, newtvb, offset, payload_len, ENC_NA);
1096                         found_match = TRUE;     /* use this flag to prevent dissection below */
1097                 }
1098                 offset += payload_len;
1099
1100                 if (srtp_info->mki_len) {
1101                         proto_tree_add_item(rtp_tree, hf_srtp_mki, newtvb, offset, srtp_info->mki_len, ENC_NA);
1102                         offset += srtp_info->mki_len;
1103                 }
1104
1105                 if (srtp_info->auth_tag_len) {
1106                         proto_tree_add_item(rtp_tree, hf_srtp_auth_tag, newtvb, offset, srtp_info->auth_tag_len, ENC_NA);
1107                         /*offset += srtp_info->auth_tag_len;*/
1108                 }
1109         } else if (p_conv_data && !p_conv_data->bta2dp_info && !p_conv_data->btvdp_info &&
1110                         payload_type >= PT_UNDF_96 && payload_type <= PT_UNDF_127) {
1111                 /* if the payload type is dynamic, we check if the conv is set and we look for the pt definition */
1112                 if (p_conv_data && p_conv_data->rtp_dyn_payload) {
1113                         gchar *payload_type_str = NULL;
1114                         encoding_name_and_rate_t *encoding_name_and_rate_pt = NULL;
1115                         encoding_name_and_rate_pt = (encoding_name_and_rate_t *)g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &payload_type);
1116                         if (encoding_name_and_rate_pt) {
1117                                 payload_type_str = encoding_name_and_rate_pt->encoding_name;
1118                         }
1119                         if (payload_type_str){
1120                                 found_match = dissector_try_string(rtp_dyn_pt_dissector_table,
1121                                                                    payload_type_str, newtvb, pinfo, tree, NULL);
1122                                 /* If payload type string set from conversation and
1123                                  * no matching dissector found it's probably because no subdissector
1124                                  * exists. Don't call the dissectors based on payload number
1125                                  * as that'd probably be the wrong dissector in this case.
1126                                  * Just add it as data.
1127                                  */
1128                                 if(found_match==FALSE)
1129                                         proto_tree_add_item( rtp_tree, hf_rtp_data, newtvb, 0, -1, ENC_NA );
1130                                 return;
1131                         }
1132
1133                 }
1134         } else if (p_conv_data && p_conv_data->bta2dp_info) {
1135                 tvbuff_t  *nexttvb;
1136                 gint       suboffset = 0;
1137
1138                 found_match = TRUE;
1139
1140                 if (p_conv_data->bta2dp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
1141                         nexttvb = tvb_new_subset(newtvb, 0, 1, 1);
1142                          call_dissector(bta2dp_content_protection_header_scms_t, nexttvb, pinfo, tree);
1143                         suboffset = 1;
1144                 }
1145
1146                 nexttvb = tvb_new_subset_remaining(newtvb, suboffset);
1147                 if (p_conv_data->bta2dp_info->codec_dissector)
1148                         call_dissector(p_conv_data->bta2dp_info->codec_dissector, nexttvb, pinfo, tree);
1149                 else
1150                         call_dissector(data_handle, nexttvb, pinfo, tree);
1151         } else if (p_conv_data && p_conv_data->btvdp_info) {
1152                 tvbuff_t  *nexttvb;
1153                 gint       suboffset = 0;
1154
1155                 found_match = TRUE;
1156
1157                 if (p_conv_data->btvdp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
1158                         nexttvb = tvb_new_subset(newtvb, 0, 1, 1);
1159                         call_dissector(bta2dp_content_protection_header_scms_t, nexttvb, pinfo, tree);
1160                         suboffset = 1;
1161                 }
1162
1163                 nexttvb = tvb_new_subset_remaining(newtvb, suboffset);
1164                 if (p_conv_data->btvdp_info->codec_dissector)
1165                         call_dissector(p_conv_data->btvdp_info->codec_dissector, nexttvb, pinfo, tree);
1166                 else
1167                         call_dissector(data_handle, nexttvb, pinfo, tree);
1168         }
1169
1170         /* if we don't found, it is static OR could be set static from the preferences */
1171         if (!found_match && !dissector_try_uint(rtp_pt_dissector_table, payload_type, newtvb, pinfo, tree))
1172                 proto_tree_add_item( rtp_tree, hf_rtp_data, newtvb, 0, -1, ENC_NA );
1173
1174 }
1175
1176 /* Rtp payload reassembly
1177  *
1178  * This handles the reassembly of PDUs for higher-level protocols.
1179  *
1180  * We're a bit limited on how we can cope with out-of-order packets, because
1181  * we don't have any idea of where the datagram boundaries are. So if we see
1182  * packets A, C, B (all of which comprise a single datagram), we cannot know
1183  * that C should be added to the same datagram as A, until we come to B (which
1184  * may or may not actually be present...).
1185  *
1186  * What we end up doing in this case is passing A+B to the subdissector as one
1187  * datagram, and make out that a new one starts on C.
1188  */
1189 static void
1190 dissect_rtp_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
1191                  proto_tree *rtp_tree, int offset, unsigned int data_len,
1192                  unsigned int data_reported_len,
1193                  unsigned int payload_type)
1194 {
1195         tvbuff_t *newtvb;
1196         struct _rtp_conversation_info *p_conv_data= NULL;
1197         gboolean must_desegment = FALSE;
1198         rtp_private_conv_info *finfo = NULL;
1199         rtp_multisegment_pdu *msp = NULL;
1200         guint32 seqno;
1201
1202         /* Retrieve RTPs idea of a converation */
1203         p_conv_data = (struct _rtp_conversation_info *)p_get_proto_data(pinfo->fd, proto_rtp, 0);
1204
1205         if(p_conv_data != NULL)
1206                 finfo = p_conv_data->rtp_conv_info;
1207
1208         if(finfo == NULL || !desegment_rtp) {
1209                 /* Hand the whole lot off to the subdissector */
1210                 newtvb=tvb_new_subset(tvb,offset,data_len,data_reported_len);
1211                 process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type);
1212                 return;
1213         }
1214
1215         seqno = p_conv_data->extended_seqno;
1216
1217         pinfo->can_desegment = 2;
1218         pinfo->desegment_offset = 0;
1219         pinfo->desegment_len = 0;
1220
1221 #ifdef DEBUG_FRAGMENTS
1222         g_debug("%d: RTP Part of convo %d(%p); seqno %d",
1223                 pinfo->fd->num,
1224                 p_conv_data->frame_number, p_conv_data,
1225                 seqno
1226                 );
1227 #endif
1228
1229         /* look for a pdu which we might be extending */
1230         msp = (rtp_multisegment_pdu *)wmem_tree_lookup32_le(finfo->multisegment_pdus,seqno-1);
1231
1232         if(msp && msp->startseq < seqno && msp->endseq >= seqno) {
1233                 guint32 fid = msp->startseq;
1234                 fragment_head *fd_head;
1235
1236 #ifdef DEBUG_FRAGMENTS
1237                 g_debug("\tContinues fragment %d", fid);
1238 #endif
1239
1240                 /* we always assume the datagram is complete; if this is the
1241                  * first pass, that's our best guess, and if it's not, what we
1242                  * say gets ignored anyway.
1243                  */
1244                 fd_head = fragment_add_seq(&rtp_reassembly_table,
1245                                            tvb, offset, pinfo, fid, NULL,
1246                                            seqno-msp->startseq, data_len,
1247                                            FALSE, 0);
1248
1249                 newtvb = process_reassembled_data(tvb,offset, pinfo, "Reassembled RTP", fd_head,
1250                                                   &rtp_fragment_items, NULL, tree);
1251
1252 #ifdef DEBUG_FRAGMENTS
1253                 g_debug("\tFragment Coalesced; fd_head=%p, newtvb=%p (len %d)",fd_head, newtvb,
1254                         newtvb?tvb_reported_length(newtvb):0);
1255 #endif
1256
1257                 if(newtvb != NULL) {
1258                         /* Hand off to the subdissector */
1259                         process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type);
1260
1261                         /*
1262                          * Check to see if there were any complete fragments within the chunk
1263                          */
1264                         if( pinfo->desegment_len && pinfo->desegment_offset == 0 )
1265                         {
1266 #ifdef DEBUG_FRAGMENTS
1267                                 g_debug("\tNo complete pdus in payload" );
1268 #endif
1269                                 /* Mark the fragments and not complete yet */
1270                                 fragment_set_partial_reassembly(&rtp_reassembly_table,
1271                                                                 pinfo, fid, NULL);
1272
1273                                 /* we must need another segment */
1274                                 msp->endseq = MIN(msp->endseq,seqno) + 1;
1275                         }
1276                         else
1277                         {
1278                                 if(pinfo->desegment_len)
1279                                 {
1280                                         /* the higher-level dissector has asked for some more data - ie,
1281                                            the end of this segment does not coincide with the end of a
1282                                            higher-level PDU. */
1283                                         must_desegment = TRUE;
1284                                 }
1285                         }
1286
1287                 }
1288
1289         }
1290         else
1291         {
1292                 /*
1293                  * The segment is not the continuation of a fragmented segment
1294                  * so process it as normal
1295                  */
1296 #ifdef DEBUG_FRAGMENTS
1297                 g_debug("\tRTP non-fragment payload");
1298 #endif
1299                 newtvb = tvb_new_subset( tvb, offset, data_len, data_reported_len );
1300
1301                 /* Hand off to the subdissector */
1302                 process_rtp_payload(newtvb, pinfo, tree, rtp_tree, payload_type);
1303
1304                 if(pinfo->desegment_len) {
1305                         /* the higher-level dissector has asked for some more data - ie,
1306                            the end of this segment does not coincide with the end of a
1307                            higher-level PDU. */
1308                         must_desegment = TRUE;
1309                 }
1310         }
1311
1312         /*
1313          * There were bytes left over that the higher protocol couldn't dissect so save them
1314          */
1315         if(must_desegment)
1316         {
1317                 guint32 deseg_offset = pinfo->desegment_offset;
1318                 guint32 frag_len = tvb_reported_length_remaining(newtvb, deseg_offset);
1319                 fragment_head *fd_head = NULL;
1320
1321 #ifdef DEBUG_FRAGMENTS
1322                 g_debug("\tRTP Must Desegment: tvb_len=%d ds_len=%d %d frag_len=%d ds_off=%d",
1323                         tvb_reported_length(newtvb),
1324                         pinfo->desegment_len,
1325                         pinfo->fd->flags.visited,
1326                         frag_len,
1327                         deseg_offset);
1328 #endif
1329                 /* allocate a new msp for this pdu */
1330                 msp = wmem_new(wmem_file_scope(), rtp_multisegment_pdu);
1331                 msp->startseq = seqno;
1332                 msp->endseq = seqno+1;
1333                 wmem_tree_insert32(finfo->multisegment_pdus,seqno,msp);
1334
1335                 /*
1336                  * Add the fragment to the fragment table
1337                  */
1338                 fd_head = fragment_add_seq(&rtp_reassembly_table,
1339                                            newtvb, deseg_offset, pinfo, seqno, NULL, 0, frag_len,
1340                                            TRUE, 0);
1341
1342                 if(fd_head != NULL)
1343                 {
1344                         if( fd_head->reassembled_in != 0 && !(fd_head->flags & FD_PARTIAL_REASSEMBLY) )
1345                         {
1346                                 proto_item *rtp_tree_item;
1347                                 rtp_tree_item = proto_tree_add_uint( tree, hf_rtp_reassembled_in,
1348                                                                      newtvb, deseg_offset, tvb_reported_length_remaining(newtvb,deseg_offset),
1349                                                                      fd_head->reassembled_in);
1350                                 PROTO_ITEM_SET_GENERATED(rtp_tree_item);
1351 #ifdef DEBUG_FRAGMENTS
1352                                 g_debug("\tReassembled in %d", fd_head->reassembled_in);
1353 #endif
1354                         }
1355                         else
1356                         {
1357 #ifdef DEBUG_FRAGMENTS
1358                                 g_debug("\tUnfinished fragment");
1359 #endif
1360                                 /* this fragment is never reassembled */
1361                                 proto_tree_add_text( tree, tvb, deseg_offset, -1,"RTP fragment, unfinished");
1362                         }
1363                 }
1364                 else
1365                 {
1366                         /*
1367                          * This fragment was the first fragment in a new entry in the
1368                          * frag_table; we don't yet know where it is reassembled
1369                          */
1370 #ifdef DEBUG_FRAGMENTS
1371                         g_debug("\tnew pdu");
1372 #endif
1373                 }
1374
1375                 if( pinfo->desegment_offset == 0 )
1376                 {
1377                         col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTP");
1378                         col_set_str(pinfo->cinfo, COL_INFO, "[RTP segment of a reassembled PDU]");
1379                 }
1380         }
1381
1382         pinfo->can_desegment = 0;
1383         pinfo->desegment_offset = 0;
1384         pinfo->desegment_len = 0;
1385 }
1386
1387
1388
1389 static void
1390 dissect_rtp_rfc2198(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1391 {
1392         gint offset = 0;
1393         guint8 octet1;
1394         int cnt;
1395         gboolean hdr_follow = TRUE;
1396         proto_item *ti = NULL;
1397         proto_tree *rfc2198_tree = NULL;
1398         proto_tree *rfc2198_hdr_tree = NULL;
1399         rfc2198_hdr *hdr_last, *hdr_new;
1400         rfc2198_hdr *hdr_chain = NULL;
1401         struct _rtp_conversation_info *p_conv_data= NULL;
1402         gchar *payload_type_str;
1403
1404         /* Retrieve RTPs idea of a converation */
1405         p_conv_data = (struct _rtp_conversation_info *)p_get_proto_data(pinfo->fd, proto_rtp, 0);
1406
1407         /* Add try to RFC 2198 data */
1408         ti = proto_tree_add_text(tree, tvb, offset, -1, "RFC 2198: Redundant Audio Data");
1409         rfc2198_tree = proto_item_add_subtree(ti, ett_rtp_rfc2198);
1410
1411         hdr_last = NULL;
1412         cnt = 0;
1413         while (hdr_follow) {
1414                 cnt++;
1415                 payload_type_str = NULL;
1416
1417                 /* Allocate and fill in header */
1418                 hdr_new = wmem_new(wmem_packet_scope(), rfc2198_hdr);
1419                 hdr_new->next = NULL;
1420                 octet1 = tvb_get_guint8(tvb, offset);
1421                 hdr_new->pt = RTP_PAYLOAD_TYPE(octet1);
1422                 hdr_follow = (octet1 & 0x80);
1423
1424                 /* if it is dynamic payload, let use the conv data to see if it is defined */
1425                 if ((hdr_new->pt > 95) && (hdr_new->pt < 128)) {
1426                         if (p_conv_data && p_conv_data->rtp_dyn_payload){
1427                                 encoding_name_and_rate_t *encoding_name_and_rate_pt = NULL;
1428                                 encoding_name_and_rate_pt = (encoding_name_and_rate_t *)g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &hdr_new->pt);
1429                                 if (encoding_name_and_rate_pt) {
1430                                         payload_type_str = encoding_name_and_rate_pt->encoding_name;
1431                                 }
1432                         }
1433                 }
1434                 /* Add a subtree for this header and add items */
1435                 ti = proto_tree_add_text(rfc2198_tree, tvb, offset, (hdr_follow)?4:1, "Header %u", cnt);
1436                 rfc2198_hdr_tree = proto_item_add_subtree(ti, ett_rtp_rfc2198_hdr);
1437                 proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_follow, tvb, offset, 1, ENC_BIG_ENDIAN );
1438                 proto_tree_add_uint_format_value(rfc2198_hdr_tree, hf_rtp_payload_type, tvb,
1439                     offset, 1, octet1, "%s (%u)",
1440                         payload_type_str ? payload_type_str : val_to_str_ext_const(hdr_new->pt, &rtp_payload_type_vals_ext, "Unknown"),
1441                         hdr_new->pt);
1442                 proto_item_append_text(ti, ": PT=%s",
1443                                        payload_type_str ? payload_type_str :
1444                                                           val_to_str_ext(hdr_new->pt, &rtp_payload_type_vals_ext, "Unknown (%u)"));
1445                 offset += 1;
1446
1447                 /* Timestamp offset and block length don't apply to last header */
1448                 if (hdr_follow) {
1449                         proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_tm_off, tvb, offset, 2, ENC_BIG_ENDIAN );
1450                         proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_bl_len, tvb, offset + 1, 2, ENC_BIG_ENDIAN );
1451                         hdr_new->len = tvb_get_ntohs(tvb, offset + 1) & 0x03FF;
1452                         proto_item_append_text(ti, ", len=%u", hdr_new->len);
1453                         offset += 3;
1454                 } else {
1455                         hdr_new->len = -1;
1456                         hdr_follow = FALSE;
1457                 }
1458
1459                 if (hdr_last) {
1460                         hdr_last->next = hdr_new;
1461                 } else {
1462                         hdr_chain = hdr_new;
1463                 }
1464                 hdr_last = hdr_new;
1465         }
1466
1467         /* Dissect each data block according to the header info */
1468         hdr_last = hdr_chain;
1469         while (hdr_last) {
1470                 hdr_last->offset = offset;
1471                 if (!hdr_last->next) {
1472                         hdr_last->len = tvb_reported_length_remaining(tvb, offset);
1473                 }
1474                 dissect_rtp_data(tvb, pinfo, tree, rfc2198_tree, hdr_last->offset, hdr_last->len, hdr_last->len, hdr_last->pt);
1475                 offset += hdr_last->len;
1476                 hdr_last = hdr_last->next;
1477         }
1478 }
1479
1480 static void
1481 dissect_rtp_hext_rfc5215_onebyte( tvbuff_t *tvb, packet_info *pinfo,
1482                 proto_tree *rtp_hext_tree )
1483 {
1484         proto_item *ti = NULL;
1485         proto_tree *rtp_hext_rfc5285_tree = NULL;
1486         guint ext_offset = 0, start_ext_offset;
1487
1488         while (ext_offset < tvb_length (tvb)) {
1489                 guint8 ext_hdr_hdr;
1490                 guint8 ext_id;
1491                 guint8 ext_length;
1492                 tvbuff_t *subtvb = NULL;
1493
1494                 /* Skip bytes with the value 0, they are padding */
1495                 start_ext_offset = ext_offset;
1496                 while (tvb_get_guint8 (tvb, ext_offset) == 0) {
1497                         ext_offset ++;
1498                         if (ext_offset >= tvb_length (tvb))
1499                                 return;
1500                 }
1501
1502                 /* Add padding */
1503                 if (ext_offset > start_ext_offset)
1504                         proto_tree_add_item(rtp_hext_tree, hf_rtp_padding_data, tvb, ext_offset, ext_offset-start_ext_offset, ENC_NA );
1505
1506                 ext_hdr_hdr = tvb_get_guint8 (tvb, ext_offset);
1507                 ext_id = ext_hdr_hdr >> 4;
1508
1509                 /* 15 is for future extensibility, ignore length, etc and stop processing packet if it shows up */
1510                 if (ext_id == 15)
1511                         return;
1512
1513                 ext_length = (ext_hdr_hdr & 0x0F) + 1;
1514                 if (rtp_hext_tree) {
1515                         ti = proto_tree_add_text(rtp_hext_tree, tvb, ext_offset, ext_length + 1, "RFC 5285 Header Extension (One-Byte Header)");
1516                         rtp_hext_rfc5285_tree = proto_item_add_subtree( ti, ett_hdr_ext_rfc5285);
1517
1518                         proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_id, tvb, ext_offset, 1, ext_id);
1519                         proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_length, tvb, ext_offset, 1, ext_length);
1520                 }
1521                 ext_offset ++;
1522
1523                 subtvb = tvb_new_subset(tvb, ext_offset, ext_length, ext_length);
1524                 if (!dissector_try_uint (rtp_hdr_ext_rfc5285_dissector_table, ext_id, subtvb, pinfo, rtp_hext_rfc5285_tree)) {
1525                         if (rtp_hext_tree)
1526                                 proto_tree_add_item(rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_data, subtvb, 0, ext_length, ENC_NA );
1527                 }
1528
1529                 ext_offset += ext_length;
1530         }
1531 }
1532
1533
1534 static void
1535 dissect_rtp_hext_rfc5215_twobytes(tvbuff_t *parent_tvb, guint id_offset,
1536                 guint8 id, tvbuff_t *tvb, packet_info *pinfo, proto_tree *rtp_hext_tree)
1537 {
1538         proto_item *ti = NULL;
1539         proto_tree *rtp_hext_rfc5285_tree = NULL;
1540         guint ext_offset = 0, start_ext_offset;
1541
1542         while (ext_offset + 2 < tvb_length (tvb)) {
1543                 guint8 ext_id;
1544                 guint8 ext_length;
1545                 tvbuff_t *subtvb = NULL;
1546
1547                 /* Skip bytes with the value 0, they are padding */
1548                 start_ext_offset = ext_offset;
1549                 while (tvb_get_guint8 (tvb, ext_offset) == 0) {
1550                         if (ext_offset + 2 >= tvb_length (tvb))
1551                                 return;
1552                         ext_offset ++;
1553                 }
1554                 /* Add padding */
1555                 if (ext_offset > start_ext_offset)
1556                         proto_tree_add_item(rtp_hext_tree, hf_rtp_padding_data, tvb, ext_offset, ext_offset-start_ext_offset, ENC_NA );
1557
1558                 ext_id = tvb_get_guint8 (tvb, ext_offset);
1559                 ext_length = tvb_get_guint8 (tvb, ext_offset + 1);
1560
1561                 if (rtp_hext_tree) {
1562                         ti = proto_tree_add_text(rtp_hext_tree, tvb, ext_offset, ext_length + 2, "RFC 5285 Header Extension (Two-Byte Header)");
1563                         rtp_hext_rfc5285_tree = proto_item_add_subtree( ti, ett_hdr_ext_rfc5285);
1564
1565                         proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_appbits, parent_tvb, id_offset + 1, 1, id & 0x000F);
1566                         proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_id, tvb, ext_offset, 1, ext_id);
1567                         proto_tree_add_uint( rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_length, tvb, ext_offset + 1, 1, ext_length);
1568                 }
1569
1570                 ext_offset += 2;
1571
1572                 subtvb = tvb_new_subset(tvb, ext_offset, ext_length, ext_length);
1573                 if (ext_length && !dissector_try_uint (rtp_hdr_ext_rfc5285_dissector_table, ext_id, subtvb, pinfo, rtp_hext_rfc5285_tree)) {
1574                         proto_tree_add_item(rtp_hext_rfc5285_tree, hf_rtp_ext_rfc5285_data, subtvb, 0, ext_length, ENC_NA );
1575                 }
1576
1577                 ext_offset += ext_length;
1578         }
1579 }
1580
1581 static gint
1582 dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
1583 {
1584         proto_item *ti            = NULL;
1585         proto_tree *volatile rtp_tree = NULL;
1586         proto_tree *rtp_csrc_tree = NULL;
1587         proto_tree *rtp_hext_tree = NULL;
1588         guint8      octet1, octet2;
1589         unsigned int version;
1590         gboolean    padding_set;
1591         gboolean    extension_set;
1592         unsigned int csrc_count;
1593         gboolean    marker_set;
1594         unsigned int payload_type;
1595         gchar *payload_type_str = NULL;
1596         gboolean    is_srtp = FALSE;
1597         unsigned int i            = 0;
1598         unsigned int hdr_extension_len= 0;
1599         unsigned int hdr_extension_id = 0;
1600         volatile unsigned int padding_count;
1601         gint        length, reported_length;
1602         int         data_len;
1603         volatile unsigned int offset = 0;
1604         guint16     seq_num;
1605         guint32     timestamp;
1606         guint32     sync_src;
1607         guint32     csrc_item;
1608         struct _rtp_conversation_info *p_conv_data = NULL;
1609         /*struct srtp_info *srtp_info = NULL;*/
1610         /*unsigned int srtp_offset;*/
1611         unsigned int hdrext_offset = 0;
1612         tvbuff_t     *newtvb = NULL;
1613         const char   *pt = NULL;
1614         /* Can tap up to 4 RTP packets within same packet */
1615         static struct _rtp_info rtp_info_arr[4];
1616         static int rtp_info_current=0;
1617         struct _rtp_info *rtp_info;
1618
1619         rtp_info_current++;
1620         if (rtp_info_current==4) {
1621                 rtp_info_current=0;
1622         }
1623         rtp_info = &rtp_info_arr[rtp_info_current];
1624
1625         /* Get the fields in the first octet */
1626         octet1 = tvb_get_guint8( tvb, offset );
1627         version = RTP_VERSION( octet1 );
1628
1629         if (version == 0) {
1630                 switch (global_rtp_version0_type) {
1631                 case RTP0_STUN:
1632                         call_dissector(stun_handle, tvb, pinfo, tree);
1633                         return tvb_length(tvb);
1634                 case RTP0_CLASSICSTUN:
1635                         call_dissector(classicstun_handle, tvb, pinfo, tree);
1636                         return tvb_length(tvb);
1637
1638                 case RTP0_T38:
1639                         call_dissector(t38_handle, tvb, pinfo, tree);
1640                         return tvb_length(tvb);
1641
1642                 case RTP0_SPRT:
1643                         call_dissector(sprt_handle, tvb, pinfo, tree);
1644                         return tvb_length(tvb);
1645
1646                 case RTP0_INVALID:
1647                         if (!(tvb_memeql(tvb, 4, "ZRTP", 4)))
1648                         {
1649                                 call_dissector(zrtp_handle,tvb,pinfo,tree);
1650                                 return tvb_length(tvb);
1651                         }
1652                 default:
1653                         ; /* Unknown or unsupported version (let it fall through) */
1654                 }
1655         }
1656
1657         /* fill in the rtp_info structure */
1658         rtp_info->info_version = version;
1659         if (version != 2) {
1660                 /*
1661                  * Unknown or unsupported version.
1662                  */
1663                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTP");
1664
1665                 col_add_fstr( pinfo->cinfo, COL_INFO,
1666                     "Unknown RTP version %u", version);
1667
1668                 if ( tree ) {
1669                         ti = proto_tree_add_item( tree, proto_rtp, tvb, offset, -1, ENC_NA );
1670                         rtp_tree = proto_item_add_subtree( ti, ett_rtp );
1671
1672                         proto_tree_add_uint( rtp_tree, hf_rtp_version, tvb,
1673                             offset, 1, octet1);
1674                 }
1675                 return offset;
1676         }
1677
1678         padding_set = RTP_PADDING( octet1 );
1679         extension_set = RTP_EXTENSION( octet1 );
1680         csrc_count = RTP_CSRC_COUNT( octet1 );
1681
1682         /* Get the fields in the second octet */
1683         octet2 = tvb_get_guint8( tvb, offset + 1 );
1684         marker_set = RTP_MARKER( octet2 );
1685         payload_type = RTP_PAYLOAD_TYPE( octet2 );
1686
1687         /* Get the subsequent fields */
1688         seq_num = tvb_get_ntohs( tvb, offset + 2 );
1689         timestamp = tvb_get_ntohl( tvb, offset + 4 );
1690         sync_src = tvb_get_ntohl( tvb, offset + 8 );
1691
1692         /* fill in the rtp_info structure */
1693         rtp_info->info_padding_set = padding_set;
1694         rtp_info->info_padding_count = 0;
1695         rtp_info->info_marker_set = marker_set;
1696         rtp_info->info_is_video = FALSE;
1697         rtp_info->info_payload_type = payload_type;
1698         rtp_info->info_seq_num = seq_num;
1699         rtp_info->info_timestamp = timestamp;
1700         rtp_info->info_sync_src = sync_src;
1701         rtp_info->info_is_srtp = FALSE;
1702         rtp_info->info_setup_frame_num = 0;
1703         rtp_info->info_payload_type_str = NULL;
1704         rtp_info->info_payload_rate = 0;
1705
1706         /*
1707          * Do we have all the data?
1708          */
1709         length = tvb_length_remaining(tvb, offset);
1710         reported_length = tvb_reported_length_remaining(tvb, offset);
1711         if (reported_length >= 0 && length >= reported_length) {
1712                 /*
1713                  * Yes.
1714                  */
1715                 rtp_info->info_all_data_present = TRUE;
1716                 rtp_info->info_data_len = reported_length;
1717
1718                 /*
1719                  * Save the pointer to raw rtp data (header + payload incl.
1720                  * padding).
1721                  * That should be safe because the "epan_dissect_t"
1722                  * constructed for the packet has not yet been freed when
1723                  * the taps are called.
1724                  * (Destroying the "epan_dissect_t" will end up freeing
1725                  * all the tvbuffs and hence invalidating pointers to
1726                  * their data.)
1727                  * See "add_packet_to_packet_list()" for details.
1728                  */
1729                 rtp_info->info_data = tvb_get_ptr(tvb, 0, -1);
1730         } else {
1731                 /*
1732                  * No - packet was cut short at capture time.
1733                  */
1734                 rtp_info->info_all_data_present = FALSE;
1735                 rtp_info->info_data_len = 0;
1736                 rtp_info->info_data = NULL;
1737         }
1738
1739         /* Look for conv and add to the frame if found */
1740         get_conv_info(pinfo, rtp_info);
1741         p_conv_data = (struct _rtp_conversation_info *)p_get_proto_data(pinfo->fd, proto_rtp, 0);
1742
1743         if (p_conv_data)
1744                 rtp_info->info_is_video = p_conv_data->is_video;
1745
1746         if (p_conv_data && p_conv_data->srtp_info) is_srtp = TRUE;
1747         rtp_info->info_is_srtp = is_srtp;
1748
1749         col_set_str( pinfo->cinfo, COL_PROTOCOL, (is_srtp) ? "SRTP" : "RTP" );
1750
1751         /* check if this is added as an SRTP stream - if so, don't try to dissect the payload data for now */
1752         p_conv_data = (struct _rtp_conversation_info *)p_get_proto_data(pinfo->fd, proto_rtp, 0);
1753
1754 #if 0 /* XXX: srtp_offset never actually used ?? */
1755         if (p_conv_data && p_conv_data->srtp_info) {
1756                 srtp_info = p_conv_data->srtp_info;
1757                 if (rtp_info->info_all_data_present) {
1758                         srtp_offset = rtp_info->info_data_len - srtp_info->mki_len - srtp_info->auth_tag_len;
1759                 }
1760         }
1761 #endif
1762
1763         if (p_conv_data && p_conv_data->bta2dp_info && p_conv_data->bta2dp_info->codec_dissector) {
1764                 rtp_info->info_payload_type_str = (const char *) dissector_handle_get_short_name(p_conv_data->bta2dp_info->codec_dissector);
1765         } else if (p_conv_data && p_conv_data->btvdp_info && p_conv_data->btvdp_info->codec_dissector) {
1766                 rtp_info->info_payload_type_str = (const char *) dissector_handle_get_short_name(p_conv_data->btvdp_info->codec_dissector);
1767         }
1768
1769         /* if it is dynamic payload, let use the conv data to see if it is defined */
1770         if ( (payload_type>95) && (payload_type<128) ) {
1771                 if (p_conv_data && p_conv_data->rtp_dyn_payload){
1772                         encoding_name_and_rate_t *encoding_name_and_rate_pt = NULL;
1773                         encoding_name_and_rate_pt = (encoding_name_and_rate_t *)g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &payload_type);
1774                         if (encoding_name_and_rate_pt) {
1775                                 rtp_info->info_payload_type_str = payload_type_str = encoding_name_and_rate_pt->encoding_name;
1776                                 rtp_info->info_payload_rate = encoding_name_and_rate_pt->sample_rate;
1777                         }
1778                 }
1779         }
1780
1781         if (p_conv_data && p_conv_data->bta2dp_info) {
1782                 pt = (p_conv_data->bta2dp_info->codec_dissector) ? dissector_handle_get_short_name(p_conv_data->bta2dp_info->codec_dissector) : "Unknown";
1783         } else if (p_conv_data && p_conv_data->btvdp_info) {
1784                 pt = (p_conv_data->btvdp_info->codec_dissector) ? dissector_handle_get_short_name(p_conv_data->btvdp_info->codec_dissector) : "Unknown";
1785         } else {
1786                 pt = (payload_type_str ? payload_type_str : val_to_str_ext(payload_type, &rtp_payload_type_vals_ext,"Unknown (%u)"));
1787         }
1788
1789         col_add_fstr( pinfo->cinfo, COL_INFO,
1790             "PT=%s, SSRC=0x%X, Seq=%u, Time=%u%s",
1791                 pt,
1792             sync_src,
1793             seq_num,
1794             timestamp,
1795             marker_set ? ", Mark" : "");
1796
1797         if ( tree ) {
1798                 proto_tree *item;
1799                 /* Create RTP protocol tree */
1800                 ti = proto_tree_add_item(tree, proto_rtp, tvb, offset, -1, ENC_NA );
1801                 rtp_tree = proto_item_add_subtree(ti, ett_rtp );
1802
1803                 /* Conversation setup info */
1804                 if (global_rtp_show_setup_info)
1805                 {
1806                         show_setup_info(tvb, pinfo, rtp_tree);
1807                 }
1808
1809                 proto_tree_add_uint( rtp_tree, hf_rtp_version, tvb,
1810                     offset, 1, octet1 );
1811                 proto_tree_add_boolean( rtp_tree, hf_rtp_padding, tvb,
1812                     offset, 1, octet1 );
1813                 proto_tree_add_boolean( rtp_tree, hf_rtp_extension, tvb,
1814                     offset, 1, octet1 );
1815                 proto_tree_add_uint( rtp_tree, hf_rtp_csrc_count, tvb,
1816                     offset, 1, octet1 );
1817                 offset++;
1818
1819                 proto_tree_add_boolean( rtp_tree, hf_rtp_marker, tvb, offset,
1820                     1, octet2 );
1821
1822                 proto_tree_add_uint_format( rtp_tree, hf_rtp_payload_type, tvb,
1823                     offset, 1, octet2, "Payload type: %s (%u)", pt, payload_type);
1824
1825                 offset++;
1826
1827                 /* Sequence number 16 bits (2 octets) */
1828                 proto_tree_add_uint( rtp_tree, hf_rtp_seq_nr, tvb, offset, 2, seq_num );
1829                 if(p_conv_data != NULL) {
1830                         item = proto_tree_add_uint( rtp_tree, hf_rtp_ext_seq_nr, tvb, offset, 2, p_conv_data->extended_seqno );
1831                         PROTO_ITEM_SET_GENERATED(item);
1832                 }
1833                 offset += 2;
1834
1835                 /* Timestamp 32 bits (4 octets) */
1836                 proto_tree_add_uint( rtp_tree, hf_rtp_timestamp, tvb, offset, 4, timestamp );
1837                 offset += 4;
1838
1839                 /* Synchronization source identifier 32 bits (4 octets) */
1840                 proto_tree_add_uint( rtp_tree, hf_rtp_ssrc, tvb, offset, 4, sync_src );
1841                 offset += 4;
1842         } else {
1843                 offset += 12;
1844         }
1845         /* CSRC list*/
1846         if ( csrc_count > 0 ) {
1847                 ti = proto_tree_add_item(rtp_tree, hf_rtp_csrc_items, tvb, offset,
1848                                                  csrc_count * 4, ENC_NA);
1849                 proto_item_append_text(ti, " (%u items)", csrc_count);
1850                 rtp_csrc_tree = proto_item_add_subtree( ti, ett_csrc_list );
1851
1852                 for (i = 0; i < csrc_count; i++ ) {
1853                         csrc_item = tvb_get_ntohl( tvb, offset );
1854                         proto_tree_add_uint_format( rtp_csrc_tree,
1855                             hf_rtp_csrc_item, tvb, offset, 4,
1856                             csrc_item,
1857                             "CSRC item %d: 0x%X",
1858                             i, csrc_item );
1859                         offset += 4;
1860                 }
1861         }
1862
1863         /* Optional RTP header extension */
1864         if ( extension_set ) {
1865                 /* Defined by profile field is 16 bits (2 octets) */
1866                 hdr_extension_id = tvb_get_ntohs( tvb, offset );
1867                 if ( tree ) proto_tree_add_uint( rtp_tree, hf_rtp_prof_define, tvb, offset, 2, hdr_extension_id );
1868                 offset += 2;
1869
1870                 hdr_extension_len = tvb_get_ntohs( tvb, offset );
1871                 if ( tree ) proto_tree_add_uint( rtp_tree, hf_rtp_length, tvb, offset, 2, hdr_extension_len);
1872                 offset += 2;
1873                 if ( hdr_extension_len > 0 ) {
1874                         if ( tree ) {
1875                                 ti = proto_tree_add_item(rtp_tree, hf_rtp_hdr_exts, tvb, offset, hdr_extension_len * 4, ENC_NA);
1876                                 rtp_hext_tree = proto_item_add_subtree( ti, ett_hdr_ext );
1877                         }
1878
1879                         /* pass interpretation of header extension to a registered subdissector */
1880                         newtvb = tvb_new_subset(tvb, offset, hdr_extension_len * 4, hdr_extension_len * 4);
1881
1882                         if (hdr_extension_id == RTP_RFC5215_ONE_BYTE_SIG) {
1883                                 dissect_rtp_hext_rfc5215_onebyte (newtvb, pinfo, rtp_hext_tree);
1884                         }
1885                         else if ((hdr_extension_id & RTP_RFC5215_TWO_BYTE_MASK) == RTP_RFC5215_TWO_BYTE_SIG) {
1886                                 dissect_rtp_hext_rfc5215_twobytes(tvb,
1887                                         offset - 4, hdr_extension_id, newtvb,
1888                                         pinfo, rtp_hext_tree);
1889                         }
1890                         else {
1891                                 if ( !(dissector_try_uint(rtp_hdr_ext_dissector_table, hdr_extension_id, newtvb, pinfo, rtp_hext_tree)) ) {
1892                                         hdrext_offset = offset;
1893                                         for ( i = 0; i < hdr_extension_len; i++ ) {
1894                                                 if ( tree ) proto_tree_add_uint( rtp_hext_tree, hf_rtp_hdr_ext, tvb, hdrext_offset, 4, tvb_get_ntohl( tvb, hdrext_offset ) );
1895                                                 hdrext_offset += 4;
1896                                         }
1897                                 }
1898                         }
1899                 }
1900                 offset += hdr_extension_len * 4;
1901         }
1902
1903         if ( padding_set ) {
1904                 /*
1905                  * This RTP frame has padding - find it.
1906                  *
1907                  * The padding count is found in the LAST octet of
1908                  * the packet; it contains the number of octets
1909                  * that can be ignored at the end of the packet.
1910                  */
1911                 if (tvb_length(tvb) < tvb_reported_length(tvb)) {
1912                         /*
1913                          * We don't *have* the last octet of the
1914                          * packet, so we can't get the padding
1915                          * count.
1916                          *
1917                          * Put an indication of that into the
1918                          * tree, and just put in a raw data
1919                          * item.
1920                          */
1921                         if ( tree ) proto_tree_add_text(rtp_tree, tvb, 0, 0,
1922                             "Frame has padding, but not all the frame data was captured");
1923                         call_dissector(data_handle,
1924                             tvb_new_subset_remaining(tvb, offset),
1925                             pinfo, rtp_tree);
1926                         return tvb_length(tvb);;
1927                 }
1928
1929                 padding_count = tvb_get_guint8( tvb,
1930                     tvb_reported_length( tvb ) - 1 );
1931                 data_len =
1932                     tvb_reported_length_remaining( tvb, offset ) - padding_count;
1933
1934                 rtp_info->info_payload_offset = offset;
1935                 rtp_info->info_payload_len = tvb_length_remaining(tvb, offset);
1936                 rtp_info->info_padding_count = padding_count;
1937
1938                 if (p_conv_data && p_conv_data->bta2dp_info) {
1939                         if (p_conv_data->bta2dp_info->codec_dissector == sbc_handle) {
1940                                 rtp_info->info_payload_offset += 1;
1941                                 rtp_info->info_payload_len -= 1;
1942                         }
1943
1944                         if (p_conv_data->bta2dp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
1945                                 rtp_info->info_payload_offset += 1;
1946                                 rtp_info->info_payload_len -= 1;
1947                         }
1948                 }
1949
1950                 if (p_conv_data && p_conv_data->btvdp_info &&
1951                                 p_conv_data->bta2dp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
1952                         rtp_info->info_payload_offset += 1;
1953                         rtp_info->info_payload_len -= 1;
1954                 }
1955
1956                 if (data_len > 0) {
1957                         /*
1958                          * There's data left over when you take out
1959                          * the padding; dissect it.
1960                          */
1961                         /* Ensure that tap is called after packet dissection, even in case of exception */
1962                         TRY {
1963                                 dissect_rtp_data( tvb, pinfo, tree, rtp_tree,
1964                                     offset,
1965                                     data_len,
1966                                     data_len,
1967                                     payload_type);
1968                         } CATCH_ALL {
1969                                 if (!pinfo->flags.in_error_pkt)
1970                                         tap_queue_packet(rtp_tap, pinfo, rtp_info);
1971                                 RETHROW;
1972                         }
1973                         ENDTRY;
1974                         offset += data_len;
1975                 } else if (data_len < 0) {
1976                         /*
1977                          * The padding count is bigger than the
1978                          * amount of RTP payload in the packet!
1979                          * Clip the padding count.
1980                          *
1981                          * XXX - put an item in the tree to indicate
1982                          * that the padding count is bogus?
1983                          */
1984                         padding_count =
1985                             tvb_reported_length_remaining(tvb, offset);
1986                 }
1987                 if (padding_count > 1) {
1988                         /*
1989                          * There's more than one byte of padding;
1990                          * show all but the last byte as padding
1991                          * data.
1992                          */
1993                         if ( tree ) proto_tree_add_item( rtp_tree, hf_rtp_padding_data,
1994                             tvb, offset, padding_count - 1, ENC_NA );
1995                         offset += padding_count - 1;
1996                 }
1997                 /*
1998                  * Show the last byte in the PDU as the padding
1999                  * count.
2000                  */
2001                 if ( tree ) proto_tree_add_item( rtp_tree, hf_rtp_padding_count,
2002                     tvb, offset, 1, ENC_BIG_ENDIAN );
2003         }
2004         else {
2005                 /*
2006                  * No padding.
2007                  */
2008                 rtp_info->info_payload_offset = offset;
2009                 rtp_info->info_payload_len = tvb_length_remaining(tvb, offset);
2010
2011                 if (p_conv_data && p_conv_data->bta2dp_info) {
2012                         if (p_conv_data->bta2dp_info->codec_dissector == sbc_handle) {
2013                                 rtp_info->info_payload_offset += 1;
2014                                 rtp_info->info_payload_len -= 1;
2015                         }
2016
2017                         if (p_conv_data->bta2dp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
2018                                 rtp_info->info_payload_offset += 1;
2019                                 rtp_info->info_payload_len -= 1;
2020                         }
2021                 }
2022
2023                 if (p_conv_data && p_conv_data->btvdp_info &&
2024                                 p_conv_data->bta2dp_info->content_protection_type == BTAVDTP_CONTENT_PROTECTION_TYPE_SCMS_T) {
2025                         rtp_info->info_payload_offset += 1;
2026                         rtp_info->info_payload_len -= 1;
2027                 }
2028
2029                 if (tvb_reported_length_remaining(tvb, offset) > 0) {
2030                         /* Ensure that tap is called after packet dissection, even in case of exception */
2031                         TRY {
2032                                 dissect_rtp_data( tvb, pinfo, tree, rtp_tree, offset,
2033                                                   tvb_length_remaining( tvb, offset ),
2034                                                   tvb_reported_length_remaining( tvb, offset ),
2035                                                   payload_type);
2036                         } CATCH_ALL {
2037                                 if (!pinfo->flags.in_error_pkt)
2038                                         tap_queue_packet(rtp_tap, pinfo, rtp_info);
2039                                 RETHROW;
2040                         }
2041                         ENDTRY;
2042                 }
2043         }
2044         if (!pinfo->flags.in_error_pkt)
2045                 tap_queue_packet(rtp_tap, pinfo, rtp_info);
2046
2047         return offset;
2048 }
2049
2050 static void
2051 dissect_rtp_hdr_ext_ed137(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
2052 {
2053         unsigned int offset = 0;
2054         unsigned int hdr_extension_len = 0;
2055         proto_item *ti            = NULL;
2056         proto_item *ti2           = NULL;
2057         proto_tree *rtp_hext_tree = NULL;
2058         proto_tree *rtp_hext_tree2 = NULL;
2059         unsigned int i;
2060         guint32 ext_value;
2061         unsigned int ft_type = 0;
2062         unsigned int bss_qidx = 0;
2063         unsigned int bss_qidx_ml = 0;
2064
2065         hdr_extension_len = tvb_reported_length(tvb)/4;
2066
2067         if ( hdr_extension_len > 0 ) {
2068                 unsigned int hdrext_offset = 0;
2069
2070                 if ( tree ) {
2071                   ti = proto_tree_add_item(tree, hf_rtp_hdr_ed137s, tvb, offset, hdr_extension_len * 4, ENC_NA);
2072                   rtp_hext_tree = proto_item_add_subtree( ti, ett_hdr_ext_ed137s );
2073                 }
2074                 for(i=0; i<hdr_extension_len; i++) {
2075                         if ( tree ) {
2076                                 ti2 = proto_tree_add_item(rtp_hext_tree, hf_rtp_hdr_ed137, tvb, hdrext_offset, 4, ENC_NA);
2077                                 rtp_hext_tree2 = proto_item_add_subtree( ti2, ett_hdr_ext_ed137 );
2078                                 ext_value=tvb_get_ntohl( tvb, hdrext_offset );
2079
2080                                 if (RTP_ED137_ptt_mask(ext_value)) {
2081                                         col_append_str(pinfo->cinfo, COL_INFO, ", PTT");
2082                                 }
2083                                 if (RTP_ED137_squ_mask(ext_value)) {
2084                                         col_append_str(pinfo->cinfo, COL_INFO, ", SQU");
2085                                 }
2086
2087                                 /* Following bits are used from ED137 RTPRx/RTPTx Information field */
2088                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_ptt_type, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2089                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_squ, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2090                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_ptt_id, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2091                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_sct, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2092                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_x, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2093
2094                                 if (RTP_ED137_extended_information(ext_value)) {
2095                                 /* Extended information is used */
2096                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_ft_type, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2097                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_ft_len, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2098
2099                                         ft_type=RTP_ED137_feature_type(ext_value);
2100                                         switch (ft_type) {
2101                                                 case RTP_ED137_feature_bss_type:
2102                                                         bss_qidx=RTP_ED137_feature_bss_qidx(ext_value);
2103                                                         bss_qidx_ml=RTP_ED137_feature_bss_qidx_ml(ext_value);
2104                                                         if (0==bss_qidx_ml) {
2105                                                                 /* Special handling for RSSI method */
2106                                                                 if (bss_qidx<=15) {
2107                                                                         /* Correct range */
2108                                                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_ft_bss_rssi_qidx, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2109                                                                 }
2110                                                                 else {
2111                                                                         /* Handle as other method */
2112                                                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_ft_bss_qidx, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2113                                                                 }
2114                                                         }
2115                                                         else {
2116                                                                 /* Other BSS method handling */
2117                                                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_ft_bss_qidx, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2118                                                         }
2119                                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_ft_bss_qidx_ml, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2120                                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_ft_bss_nu, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2121                                                         break;
2122                                                 default:
2123                                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_ft_value, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2124                                                         break;
2125                                         }
2126                                 }
2127                                 else {
2128                                         /* Extended information is not used */
2129                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_x_nu, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2130                                 }
2131
2132                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137_vf, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2133                         }
2134                         hdrext_offset += 4;
2135                 }
2136         }
2137 }
2138
2139 static void
2140 dissect_rtp_hdr_ext_ed137a(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
2141 {
2142         unsigned int offset = 0;
2143         unsigned int hdr_extension_len = 0;
2144         proto_item *ti            = NULL;
2145         proto_item *ti2           = NULL;
2146         proto_tree *rtp_hext_tree = NULL;
2147         proto_tree *rtp_hext_tree2 = NULL;
2148         unsigned int i;
2149         guint32 ext_value;
2150         unsigned int ft_type = 0;
2151
2152         hdr_extension_len = tvb_reported_length(tvb)/4;
2153
2154         if ( hdr_extension_len > 0 ) {
2155                 unsigned int hdrext_offset = 0;
2156
2157                 if ( tree ) {
2158                         ti = proto_tree_add_item(tree, hf_rtp_hdr_ed137s, tvb, offset, hdr_extension_len * 4, ENC_NA);
2159                         rtp_hext_tree = proto_item_add_subtree( ti, ett_hdr_ext_ed137s );
2160                 }
2161                 for(i=0; i<hdr_extension_len; i++) {
2162                         if ( tree ) {
2163                                 ti2 = proto_tree_add_item(rtp_hext_tree, hf_rtp_hdr_ed137a, tvb, hdrext_offset, 4, ENC_NA);
2164                                 rtp_hext_tree2 = proto_item_add_subtree( ti2, ett_hdr_ext_ed137a );
2165                                 ext_value=tvb_get_ntohl( tvb, hdrext_offset );
2166
2167                                 if (RTP_ED137A_ptt_mask(ext_value)) {
2168                                         col_append_str(pinfo->cinfo, COL_INFO, ", PTT");
2169                                 }
2170                                 if (RTP_ED137A_squ_mask(ext_value)) {
2171                                         col_append_str(pinfo->cinfo, COL_INFO, ", SQU");
2172                                 }
2173
2174                                 /* Following bits are used from ED137A/B RTPRx Information field */
2175                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_ptt_type, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2176                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_squ, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2177                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_ptt_id, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2178                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_pm, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2179                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_ptts, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2180                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_sct, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2181                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_reserved, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2182                                 proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_x, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2183
2184                                 if (RTP_ED137A_extended_information(ext_value)) {
2185                                         /* Extended information is used */
2186                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_ft_type, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2187                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_ft_len, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2188
2189                                         ft_type=RTP_ED137A_feature_type(ext_value);
2190                                         switch (ft_type) {
2191                                                 default:
2192                                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_ft_value, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2193                                                         break;
2194                                         }
2195                                 }
2196                                 else {
2197                                         /* Extended information is not used */
2198                                         proto_tree_add_item( rtp_hext_tree2, hf_rtp_hdr_ed137a_x_nu, tvb, hdrext_offset, 4, ENC_BIG_ENDIAN);
2199                                 }
2200                         }
2201                         hdrext_offset += 4;
2202                 }
2203         }
2204 }
2205
2206 /* calculate the extended sequence number - top 16 bits of the previous sequence number,
2207  * plus our own; then correct for wrapping */
2208 static guint32
2209 calculate_extended_seqno(guint32 previous_seqno, guint16 raw_seqno)
2210 {
2211         guint32 seqno = (previous_seqno & 0xffff0000) | raw_seqno;
2212         if(seqno + 0x8000 < previous_seqno) {
2213                 seqno += 0x10000;
2214         } else if(previous_seqno + 0x8000 < seqno) {
2215                 /* we got an out-of-order packet which happened to go backwards over the
2216                  * wrap boundary */
2217                 seqno -= 0x10000;
2218         }
2219         return seqno;
2220 }
2221
2222 /* Look for conversation info */
2223 static void
2224 get_conv_info(packet_info *pinfo, struct _rtp_info *rtp_info)
2225 {
2226         /* Conversation and current data */
2227         conversation_t *p_conv = NULL;
2228         struct _rtp_conversation_info *p_conv_data = NULL;
2229
2230         /* Use existing packet info if available */
2231         p_conv_data = (struct _rtp_conversation_info *)p_get_proto_data(pinfo->fd, proto_rtp, 0);
2232
2233         if (!p_conv_data)
2234         {
2235                 /* First time, get info from conversation */
2236                 p_conv = find_conversation(pinfo->fd->num, &pinfo->net_dst, &pinfo->net_src,
2237                                            pinfo->ptype,
2238                                            pinfo->destport, pinfo->srcport, NO_ADDR_B);
2239                 if (p_conv)
2240                 {
2241                         /* Create space for packet info */
2242                         struct _rtp_conversation_info *p_conv_packet_data;
2243                         p_conv_data = (struct _rtp_conversation_info *)conversation_get_proto_data(p_conv, proto_rtp);
2244
2245                         if (p_conv_data) {
2246                                 guint32 seqno;
2247
2248                                 /* Save this conversation info into packet info */
2249                                 p_conv_packet_data = wmem_new(wmem_file_scope(), struct _rtp_conversation_info);
2250                                 g_strlcpy(p_conv_packet_data->method, p_conv_data->method, MAX_RTP_SETUP_METHOD_SIZE+1);
2251                                 p_conv_packet_data->frame_number = p_conv_data->frame_number;
2252                                 p_conv_packet_data->is_video = p_conv_data->is_video;
2253                                 p_conv_packet_data->rtp_dyn_payload = p_conv_data->rtp_dyn_payload;
2254                                 p_conv_packet_data->rtp_conv_info = p_conv_data->rtp_conv_info;
2255                                 p_conv_packet_data->srtp_info = p_conv_data->srtp_info;
2256                                 p_conv_packet_data->bta2dp_info = p_conv_data->bta2dp_info;
2257                                 p_conv_packet_data->btvdp_info = p_conv_data->btvdp_info;
2258                                 p_add_proto_data(pinfo->fd, proto_rtp, 0, p_conv_packet_data);
2259
2260                                 /* calculate extended sequence number */
2261                                 seqno = calculate_extended_seqno(p_conv_data->extended_seqno,
2262                                                                  rtp_info->info_seq_num);
2263
2264                                 p_conv_packet_data->extended_seqno = seqno;
2265                                 p_conv_data->extended_seqno = seqno;
2266                         }
2267                 }
2268         }
2269         if (p_conv_data) rtp_info->info_setup_frame_num = p_conv_data->frame_number;
2270 }
2271
2272
2273 /* Display setup info */
2274 static void
2275 show_setup_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2276 {
2277         /* Conversation and current data */
2278         struct _rtp_conversation_info *p_conv_data = NULL;
2279         proto_tree *rtp_setup_tree;
2280         proto_item *ti;
2281
2282         /* Use existing packet info if available */
2283         p_conv_data = (struct _rtp_conversation_info *)p_get_proto_data(pinfo->fd, proto_rtp, 0);
2284
2285         if (!p_conv_data) return;
2286
2287         /* Create setup info subtree with summary info. */
2288         ti =  proto_tree_add_string_format(tree, hf_rtp_setup, tvb, 0, 0,
2289                                            "", "Stream setup by %s (frame %u)",
2290                                            p_conv_data->method,
2291                                            p_conv_data->frame_number);
2292                 PROTO_ITEM_SET_GENERATED(ti);
2293                 rtp_setup_tree = proto_item_add_subtree(ti, ett_rtp_setup);
2294                 if (rtp_setup_tree)
2295                 {
2296                         /* Add details into subtree */
2297                         proto_item* item = proto_tree_add_uint(rtp_setup_tree, hf_rtp_setup_frame,
2298                                                                tvb, 0, 0, p_conv_data->frame_number);
2299                         PROTO_ITEM_SET_GENERATED(item);
2300                         item = proto_tree_add_string(rtp_setup_tree, hf_rtp_setup_method,
2301                                                      tvb, 0, 0, p_conv_data->method);
2302                         PROTO_ITEM_SET_GENERATED(item);
2303                 }
2304 }
2305
2306 /* Dissect PacketCable CCC header */
2307
2308 static int
2309 dissect_pkt_ccc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
2310 {
2311         proto_item *ti            = NULL;
2312         proto_tree *pkt_ccc_tree      = NULL;
2313
2314         if ( tree ) {
2315                 ti = proto_tree_add_item(tree, proto_pkt_ccc, tvb, 0, 12, ENC_NA);
2316                 pkt_ccc_tree = proto_item_add_subtree(ti, ett_pkt_ccc);
2317
2318                 proto_tree_add_item(pkt_ccc_tree, hf_pkt_ccc_id, tvb, 0, 4, ENC_BIG_ENDIAN);
2319                 proto_tree_add_item(pkt_ccc_tree, hf_pkt_ccc_ts, tvb, 4, 8,
2320                                     ENC_TIME_NTP|ENC_BIG_ENDIAN);
2321         }
2322
2323         return dissect_rtp(tvb, pinfo, tree, data);
2324 }
2325
2326
2327 /* Register PacketCable CCC */
2328
2329 void
2330 proto_register_pkt_ccc(void)
2331 {
2332         static hf_register_info hf[] =
2333         {
2334                 {
2335                         &hf_pkt_ccc_id,
2336                         {
2337                                 "PacketCable CCC Identifier",
2338                                 "pkt_ccc.ccc_id",
2339                                 FT_UINT32,
2340                                 BASE_DEC,
2341                                 NULL,
2342                                 0x0,
2343                                 NULL, HFILL
2344                         }
2345                 },
2346                 {
2347                         &hf_pkt_ccc_ts,
2348                         {
2349                                 "PacketCable CCC Timestamp",
2350                                 "pkt_ccc.ts",
2351                                 FT_ABSOLUTE_TIME,
2352                                 ABSOLUTE_TIME_UTC,
2353                                 NULL,
2354                                 0x0,
2355                                 NULL, HFILL
2356                         }
2357                 },
2358
2359         };
2360
2361         static gint *ett[] =
2362         {
2363                 &ett_pkt_ccc,
2364         };
2365
2366         module_t *pkt_ccc_module;
2367
2368         proto_pkt_ccc = proto_register_protocol("PacketCable Call Content Connection",
2369             "PKT CCC", "pkt_ccc");
2370         proto_register_field_array(proto_pkt_ccc, hf, array_length(hf));
2371         proto_register_subtree_array(ett, array_length(ett));
2372
2373         new_register_dissector("pkt_ccc", dissect_pkt_ccc, proto_pkt_ccc);
2374
2375         pkt_ccc_module = prefs_register_protocol(proto_pkt_ccc, proto_reg_handoff_pkt_ccc);
2376
2377         prefs_register_uint_preference(pkt_ccc_module, "udp_port",
2378                                        "UDP port",
2379                                        "Decode packets on this UDP port as PacketCable CCC",
2380                                        10, &global_pkt_ccc_udp_port);
2381 }
2382
2383 void
2384 proto_reg_handoff_pkt_ccc(void)
2385 {
2386         /*
2387          * Register this dissector as one that can be selected by a
2388          * UDP port number.
2389          */
2390         static gboolean initialized = FALSE;
2391         static dissector_handle_t pkt_ccc_handle;
2392         static guint saved_pkt_ccc_udp_port;
2393
2394         if (!initialized) {
2395                 pkt_ccc_handle = find_dissector("pkt_ccc");
2396                 dissector_add_handle("udp.port", pkt_ccc_handle);  /* for 'decode-as' */
2397                 initialized = TRUE;
2398         } else {
2399                 if (saved_pkt_ccc_udp_port != 0) {
2400                         dissector_delete_uint("udp.port", saved_pkt_ccc_udp_port, pkt_ccc_handle);
2401                 }
2402         }
2403
2404         if (global_pkt_ccc_udp_port != 0) {
2405                 dissector_add_uint("udp.port", global_pkt_ccc_udp_port, pkt_ccc_handle);
2406         }
2407         saved_pkt_ccc_udp_port = global_pkt_ccc_udp_port;
2408 }
2409
2410 /* Register RTP */
2411
2412 void
2413 proto_register_rtp(void)
2414 {
2415         static hf_register_info hf[] =
2416         {
2417                 {
2418                         &hf_rtp_version,
2419                         {
2420                                 "Version",
2421                                 "rtp.version",
2422                                 FT_UINT8,
2423                                 BASE_DEC,
2424                                 VALS(rtp_version_vals),
2425                                 0xC0,
2426                                 NULL, HFILL
2427                         }
2428                 },
2429                 {
2430                         &hf_rtp_padding,
2431                         {
2432                                 "Padding",
2433                                 "rtp.padding",
2434                                 FT_BOOLEAN,
2435                                 8,
2436                                 NULL,
2437                                 0x20,
2438                                 NULL, HFILL
2439                         }
2440                 },
2441                 {
2442                         &hf_rtp_extension,
2443                         {
2444                                 "Extension",
2445                                 "rtp.ext",
2446                                 FT_BOOLEAN,
2447                                 8,
2448                                 NULL,
2449                                 0x10,
2450                                 NULL, HFILL
2451                         }
2452                 },
2453                 {
2454                         &hf_rtp_csrc_count,
2455                         {
2456                                 "Contributing source identifiers count",
2457                                 "rtp.cc",
2458                                 FT_UINT8,
2459                                 BASE_DEC,
2460                                 NULL,
2461                                 0x0F,
2462                                 NULL, HFILL
2463                         }
2464                 },
2465                 {
2466                         &hf_rtp_marker,
2467                         {
2468                                 "Marker",
2469                                 "rtp.marker",
2470                                 FT_BOOLEAN,
2471                                 8,
2472                                 NULL,
2473                                 0x80,
2474                                 NULL, HFILL
2475                         }
2476                 },
2477                 {
2478                         &hf_rtp_payload_type,
2479                         {
2480                                 "Payload type",
2481                                 "rtp.p_type",
2482                                 FT_UINT8,
2483                                 BASE_DEC,
2484                                 NULL,
2485                                 0x7F,
2486                                 NULL, HFILL
2487                         }
2488                 },
2489                 {
2490                         &hf_rtp_seq_nr,
2491                         {
2492                                 "Sequence number",
2493                                 "rtp.seq",
2494                                 FT_UINT16,
2495                                 BASE_DEC,
2496                                 NULL,
2497                                 0x0,
2498                                 NULL, HFILL
2499                         }
2500                 },
2501                 {
2502                         &hf_rtp_ext_seq_nr,
2503                         {
2504                                 "Extended sequence number",
2505                                 "rtp.extseq",
2506                                 FT_UINT32,
2507                                 BASE_DEC,
2508                                 NULL,
2509                                 0x0,
2510                                 NULL, HFILL
2511                         }
2512                 },
2513                 {
2514                         &hf_rtp_timestamp,
2515                         {
2516                                 "Timestamp",
2517                                 "rtp.timestamp",
2518                                 FT_UINT32,
2519                                 BASE_DEC,
2520                                 NULL,
2521                                 0x0,
2522                                 NULL, HFILL
2523                         }
2524                 },
2525                 {
2526                         &hf_rtp_ssrc,
2527                         {
2528                                 "Synchronization Source identifier",
2529                                 "rtp.ssrc",
2530                                 FT_UINT32,
2531                                 BASE_HEX_DEC,
2532                                 NULL,
2533                                 0x0,
2534                                 NULL, HFILL
2535                         }
2536                 },
2537                 {
2538                         &hf_rtp_prof_define,
2539                         {
2540                                 "Defined by profile",
2541                                 "rtp.ext.profile",
2542                                 FT_UINT16,
2543                                 BASE_HEX_DEC,
2544                                 VALS(rtp_ext_profile_vals),
2545                                 0x0,
2546                                 NULL, HFILL
2547                         }
2548                 },
2549                 {
2550                         &hf_rtp_length,
2551                         {
2552                                 "Extension length",
2553                                 "rtp.ext.len",
2554                                 FT_UINT16,
2555                                 BASE_DEC,
2556                                 NULL,
2557                                 0x0,
2558                                 NULL, HFILL
2559                         }
2560                 },
2561                 {
2562                         &hf_rtp_csrc_items,
2563                         {
2564                                 "Contributing Source identifiers",
2565                                 "rtp.csrc.items",
2566                                 FT_NONE,
2567                                 BASE_NONE,
2568                                 NULL,
2569                                 0x0,
2570                                 NULL, HFILL
2571                         }
2572                 },
2573                 {
2574                         &hf_rtp_csrc_item,
2575                         {
2576                                 "CSRC item",
2577                                 "rtp.csrc.item",
2578                                 FT_UINT32,
2579                                 BASE_HEX_DEC,
2580                                 NULL,
2581                                 0x0,
2582                                 NULL, HFILL
2583                         }
2584                 },
2585                 {
2586                         &hf_rtp_hdr_exts,
2587                         {
2588                                 "Header extensions",
2589                                 "rtp.hdr_exts",
2590                                 FT_NONE,
2591                                 BASE_NONE,
2592                                 NULL,
2593                                 0x0,
2594                                 NULL, HFILL
2595                         }
2596                 },
2597 /* ED137 and ED137A common structures */
2598                 {
2599                         &hf_rtp_hdr_ed137s,
2600                         {
2601                                 "ED137 extensions",
2602                                 "rtp.ext.ed137s",
2603                                 FT_NONE,
2604                                 BASE_NONE,
2605                                 NULL,
2606                                 0x0,
2607                                 NULL, HFILL
2608                         }
2609                 },
2610 /* ED137 only structures */
2611                 {
2612                         &hf_rtp_hdr_ed137,
2613                         {
2614                                 "ED137 extension",
2615                                 "rtp.ext.ed137",
2616                                 FT_NONE,
2617                                 BASE_NONE,
2618                                 NULL,
2619                                 0x0,
2620                                 NULL, HFILL
2621                         }
2622                 },
2623                 {
2624                         &hf_rtp_hdr_ed137_ptt_type,
2625                         {
2626                                 "PTT Type",
2627                                 "rtp.ext.ed137.ptt_type",
2628                                 FT_UINT32,
2629                                 BASE_DEC,
2630                                 VALS(rtp_ext_ed137_ptt_type),
2631                                 0xE0000000,
2632                                 NULL, HFILL
2633                         }
2634                 },
2635                 {
2636                         &hf_rtp_hdr_ed137_squ,
2637                         {
2638                                 "SQU",
2639                                 "rtp.ext.ed137.squ",
2640                                 FT_UINT32,
2641                                 BASE_DEC,
2642                                 VALS(rtp_ext_ed137_squ),
2643                                 0x10000000,
2644                                 NULL, HFILL
2645                         }
2646                 },
2647                 {
2648                         &hf_rtp_hdr_ed137_ptt_id,
2649                         {
2650                                 "PTT-id",
2651                                 "rtp.ext.ed137.ptt_id",
2652                                 FT_UINT32,
2653                                 BASE_DEC,
2654                                 NULL,
2655                                 0x0F000000,
2656                                 NULL, HFILL
2657                         }
2658                 },
2659                 {
2660                         &hf_rtp_hdr_ed137_sct,
2661                         {
2662                                 "Simultaneous Call Transmissions",
2663                                 "rtp.ext.ed137.sct",
2664                                 FT_UINT32,
2665                                 BASE_DEC,
2666                                 NULL,
2667                                 0x00800000,
2668                                 NULL, HFILL
2669                         }
2670                 },
2671                 {
2672                         &hf_rtp_hdr_ed137_x,
2673                         {
2674                                 "X",
2675                                 "rtp.ext.ed137.x",
2676                                 FT_UINT32,
2677                                 BASE_DEC,
2678                                 NULL,
2679                                 0x00400000,
2680                                 NULL, HFILL
2681                         }
2682                 },
2683                 {
2684                         &hf_rtp_hdr_ed137_x_nu,
2685                         {
2686                                 "Not used",
2687                                 "rtp.ext.ed137.x-nu",
2688                                 FT_UINT32,
2689                                 BASE_DEC,
2690                                 NULL,
2691                                 0x003FFFFE,
2692                                 NULL, HFILL
2693                         }
2694                 },
2695                 {
2696                         &hf_rtp_hdr_ed137_ft_type,
2697                         {
2698                                 "Feature type",
2699                                 "rtp.ext.ed137.ft.type",
2700                                 FT_UINT32,
2701                                 BASE_HEX_DEC,
2702                                 VALS(rtp_ext_ed137_ft_type),
2703                                 0x003C0000,
2704                                 NULL, HFILL
2705                         }
2706                 },
2707                 {
2708                         &hf_rtp_hdr_ed137_ft_len,
2709                         {
2710                                 "Feature length",
2711                                 "rtp.ext.ed137.ft.len",
2712                                 FT_UINT32,
2713                                 BASE_DEC,
2714                                 NULL,
2715                                 0x0003C000,
2716                                 NULL, HFILL
2717                         }
2718                 },
2719                 {
2720                         &hf_rtp_hdr_ed137_ft_value,
2721                         {
2722                                 "Feature value",
2723                                 "rtp.ext.ed137.ft.value",
2724                                 FT_UINT32,
2725                                 BASE_HEX_DEC,
2726                                 NULL,
2727                                 0x00003FFE,
2728                                 NULL, HFILL
2729                         }
2730                 },
2731                 {
2732                         &hf_rtp_hdr_ed137_vf,
2733                         {
2734                                 "VF",
2735                                 "rtp.ext.ed137.vf",
2736                                 FT_UINT32,
2737                                 BASE_DEC,
2738                                 VALS(rtp_ext_ed137_vf),
2739                                 0x00000001,
2740                                 NULL, HFILL
2741                         }
2742                 },
2743                 {
2744                         &hf_rtp_hdr_ed137_ft_bss_qidx,
2745                         {
2746                                 "BSS Quality Index",
2747                                 "rtp.ext.ed137.ft.bss.qidx",
2748                                 FT_UINT32,
2749                                 BASE_DEC,
2750                                 NULL,
2751                                 0x00003FC0,
2752                                 NULL, HFILL
2753                         }
2754                 },
2755                 {
2756                         &hf_rtp_hdr_ed137_ft_bss_rssi_qidx,
2757                         {
2758                                 "BSS Quality Index",
2759                                 "rtp.ext.ed137.ft.bss.qidx",
2760                                 FT_UINT32,
2761                                 BASE_DEC,
2762                                 VALS(rtp_ext_ed137_ft_bss_rssi_qidx),
2763                                 0x00003FC0,
2764                                 NULL, HFILL
2765                         }
2766                 },
2767                 {
2768                         &hf_rtp_hdr_ed137_ft_bss_qidx_ml,
2769                         {
2770                                 "BSS Quality Index Method",
2771                                 "rtp.ext.ed137.ft.bss.qidx-ml",
2772                                 FT_UINT32,
2773                                 BASE_DEC,
2774                                 VALS(rtp_ext_ed137_ft_bss_qidx_ml),
2775                                 0x00000038,
2776                                 NULL, HFILL
2777                         }
2778                 },
2779                 {
2780                         &hf_rtp_hdr_ed137_ft_bss_nu,
2781                         {
2782                                 "Not used",
2783                                 "rtp.ext.ed137.ft.bss-nu",
2784                                 FT_UINT32,
2785                                 BASE_DEC,
2786                                 NULL,
2787                                 0x00000006,
2788                                 NULL, HFILL
2789                         }
2790                 },
2791 /* ED137A only structures */
2792                 {
2793                         &hf_rtp_hdr_ed137a,
2794                         {
2795                                 "ED137A extension",
2796                                 "rtp.ext.ed137A",
2797                                 FT_NONE,
2798                                 BASE_NONE,
2799                                 NULL,
2800                                 0x0,
2801                                 NULL, HFILL
2802                         }
2803                 },
2804                 {
2805                         &hf_rtp_hdr_ed137a_ptt_type,
2806                         {
2807                                 "PTT Type",
2808                                 "rtp.ext.ed137A.ptt_type",
2809                                 FT_UINT32,
2810                                 BASE_DEC,
2811                                 VALS(rtp_ext_ed137a_ptt_type),
2812                                 0xE0000000,
2813                                 NULL, HFILL
2814                         }
2815                 },
2816                 {
2817                         &hf_rtp_hdr_ed137a_squ,
2818                         {
2819                                 "SQU",
2820                                 "rtp.ext.ed137A.squ",
2821                                 FT_UINT32,
2822                                 BASE_DEC,
2823                                 VALS(rtp_ext_ed137a_squ),
2824                                 0x10000000,
2825                                 NULL, HFILL
2826                         }
2827                 },
2828                 {
2829                         &hf_rtp_hdr_ed137a_ptt_id,
2830                         {
2831                                 "PTT-id",
2832                                 "rtp.ext.ed137A.ptt_id",
2833                                 FT_UINT32,
2834                                 BASE_DEC,
2835                                 NULL,
2836                                 0x0FC00000,
2837                                 NULL, HFILL
2838                         }
2839                 },
2840                 {
2841                         &hf_rtp_hdr_ed137a_pm,
2842                         {
2843                                 "PTT Mute",
2844                                 "rtp.ext.ed137A.pm",
2845                                 FT_UINT32,
2846                                 BASE_DEC,
2847                                 NULL,
2848                                 0x00200000,
2849                                 NULL, HFILL
2850                         }
2851                 },
2852                 {
2853                         &hf_rtp_hdr_ed137a_ptts,
2854                         {
2855                                 "PTT Summation",
2856                                 "rtp.ext.ed137A.ptts",
2857                                 FT_UINT32,
2858                                 BASE_DEC,
2859                                 NULL,
2860                                 0x00100000,
2861                                 NULL, HFILL
2862                         }
2863                 },
2864                 {
2865                         &hf_rtp_hdr_ed137a_sct,
2866                         {
2867                                 "Simultaneous Call Transmissions",
2868                                 "rtp.ext.ed137a.sct",
2869                                 FT_UINT32,
2870                                 BASE_DEC,
2871                                 NULL,
2872                                 0x00080000,
2873                                 NULL, HFILL
2874                         }
2875                 },
2876                 {
2877                         &hf_rtp_hdr_ed137a_reserved,
2878                         {
2879                                 "Reserved",
2880                                 "rtp.ext.ed137A.reserved",
2881                                 FT_UINT32,
2882                                 BASE_HEX_DEC,
2883                                 NULL,
2884                                 0x00060000,
2885                                 NULL, HFILL
2886                         }
2887                 },
2888                 {
2889                         &hf_rtp_hdr_ed137a_x,
2890                         {
2891                                 "X",
2892                                 "rtp.ext.ed137A.x",
2893                                 FT_UINT32,
2894                                 BASE_DEC,
2895                                 NULL,
2896                                 0x00010000,
2897                                 NULL, HFILL
2898                         }
2899                 },
2900                 {
2901                         &hf_rtp_hdr_ed137a_x_nu,
2902                         {
2903                                 "Not used",
2904                                 "rtp.ext.ed137A.x-nu",
2905                                 FT_UINT32,
2906                                 BASE_DEC,
2907                                 NULL,
2908                                 0x0000FFFF,
2909                                 NULL, HFILL
2910                         }
2911                 },
2912                 {
2913                         &hf_rtp_hdr_ed137a_ft_type,
2914                         {
2915                                 "Feature type",
2916                                 "rtp.ext.ed137A.ft.type",
2917                                 FT_UINT32,
2918                                 BASE_HEX_DEC,
2919                                 VALS(rtp_ext_ed137a_ft_type),
2920                                 0x0000F000,
2921                                 NULL, HFILL
2922                         }
2923                 },
2924                 {
2925                         &hf_rtp_hdr_ed137a_ft_len,
2926                         {
2927                                 "Feature length",
2928                                 "rtp.ext.ed137A.ft.len",
2929                                 FT_UINT32,
2930                                 BASE_DEC,
2931                                 NULL,
2932                                 0x00000F00,
2933                                 NULL, HFILL
2934                         }
2935                 },
2936                 {
2937                         &hf_rtp_hdr_ed137a_ft_value,
2938                         {
2939                                 "Feature value",
2940                                 "rtp.ext.ed137A.ft.value",
2941                                 FT_UINT32,
2942                                 BASE_HEX_DEC,
2943                                 NULL,
2944                                 0x000000FF,
2945                                 NULL, HFILL
2946                         }
2947                 },
2948 /* Other RTP structures */
2949                 {
2950                         &hf_rtp_hdr_ext,
2951                         {
2952                                 "Header extension",
2953                                 "rtp.hdr_ext",
2954                                 FT_UINT32,
2955                                 BASE_HEX_DEC,
2956                                 NULL,
2957                                 0x0,
2958                                 NULL, HFILL
2959                         }
2960                 },
2961                 {
2962                         &hf_rtp_data,
2963                         {
2964                                 "Payload",
2965                                 "rtp.payload",
2966                                 FT_BYTES,
2967                                 BASE_NONE,
2968                                 NULL,
2969                                 0x0,
2970                                 NULL, HFILL
2971                         }
2972                 },
2973                 {
2974                         &hf_rtp_padding_data,
2975                         {
2976                                 "Padding data",
2977                                 "rtp.padding.data",
2978                                 FT_BYTES,
2979                                 BASE_NONE,
2980                                 NULL,
2981                                 0x0,
2982                                 NULL, HFILL
2983                         }
2984                 },
2985                 {
2986                         &hf_rtp_padding_count,
2987                         {
2988                                 "Padding count",
2989                                 "rtp.padding.count",
2990                                 FT_UINT8,
2991                                 BASE_DEC,
2992                                 NULL,
2993                                 0x0,
2994                                 NULL, HFILL
2995                         }
2996                 },
2997                 {
2998                         &hf_rtp_setup,
2999                         {
3000                                 "Stream setup",
3001                                 "rtp.setup",
3002                                 FT_STRING,
3003                                 BASE_NONE,
3004                                 NULL,
3005                                 0x0,
3006                                 "Stream setup, method and frame number", HFILL
3007                         }
3008                 },
3009                 {
3010                         &hf_rtp_setup_frame,
3011                         {
3012                                 "Setup frame",
3013                                 "rtp.setup-frame",
3014                                 FT_FRAMENUM,
3015                                 BASE_NONE,
3016                                 NULL,
3017                                 0x0,
3018                                 "Frame that set up this stream", HFILL
3019                         }
3020                 },
3021                 {
3022                         &hf_rtp_setup_method,
3023                         {
3024                                 "Setup Method",
3025                                 "rtp.setup-method",
3026                                 FT_STRING,
3027                                 BASE_NONE,
3028                                 NULL,
3029                                 0x0,
3030                                 "Method used to set up this stream", HFILL
3031                         }
3032                 },
3033                 {
3034                         &hf_rtp_rfc2198_follow,
3035                         {
3036                                 "Follow",
3037                                 "rtp.follow",
3038                                 FT_BOOLEAN,
3039                                 8,
3040                                 TFS(&tfs_set_notset),
3041                                 0x80,
3042                                 "Next header follows", HFILL
3043                         }
3044                 },
3045                 {
3046                         &hf_rtp_rfc2198_tm_off,
3047                         {
3048                                 "Timestamp offset",
3049                                 "rtp.timestamp-offset",
3050                                 FT_UINT16,
3051                                 BASE_DEC,
3052                                 NULL,
3053                                 0xFFFC,
3054                                 NULL, HFILL
3055                         }
3056                 },
3057                 {
3058                         &hf_rtp_rfc2198_bl_len,
3059                         {
3060                                 "Block length",
3061                                 "rtp.block-length",
3062                                 FT_UINT16,
3063                                 BASE_DEC,
3064                                 NULL,
3065                                 0x03FF,
3066                                 NULL, HFILL
3067                         }
3068                 },
3069                 {
3070                         &hf_rtp_ext_rfc5285_id,
3071                         {
3072                                 "Identifier",
3073                                 "rtp.ext.rfc5285.id",
3074                                 FT_UINT8,
3075                                 BASE_DEC,
3076                                 NULL,
3077                                 0x0,
3078                                 "RFC 5285 Header Extension Identifier",
3079                                 HFILL
3080                         }
3081                 },
3082                 {
3083                         &hf_rtp_ext_rfc5285_length,
3084                         {
3085                                 "Length",
3086                                 "rtp.ext.rfc5285.len",
3087                                 FT_UINT8,
3088                                 BASE_DEC,
3089                                 NULL,
3090                                 0x0,
3091                                 "RFC 5285 Header Extension length",
3092                                 HFILL
3093                         }
3094                 },
3095                 {
3096                         &hf_rtp_ext_rfc5285_appbits,
3097                         {
3098                                 "Application Bits",
3099                                 "rtp.ext.rfc5285.appbits",
3100                                 FT_UINT8,
3101                                 BASE_DEC,
3102                                 NULL,
3103                                 0x0,
3104                                 "RFC 5285 2-bytes header application bits",
3105                                 HFILL
3106                         }
3107                 },
3108                 {
3109                         &hf_rtp_ext_rfc5285_data,
3110                         {
3111                                 "Extension Data",
3112                                 "rtp.ext.rfc5285.data",
3113                                 FT_BYTES,
3114                                 BASE_NONE,
3115                                 NULL,
3116                                 0x0,
3117                                 "RFC 5285 Extension Data",
3118                                 HFILL
3119                         }
3120                 },
3121
3122                 /* reassembly stuff */
3123                 {&hf_rtp_fragments,
3124                  {"RTP Fragments", "rtp.fragments", FT_NONE, BASE_NONE, NULL, 0x0,
3125                   NULL, HFILL }
3126                 },
3127
3128                 {&hf_rtp_fragment,
3129                  {"RTP Fragment data", "rtp.fragment", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
3130                   NULL, HFILL }
3131                 },
3132
3133                 {&hf_rtp_fragment_overlap,
3134                  {"Fragment overlap", "rtp.fragment.overlap", FT_BOOLEAN, BASE_NONE,
3135                   NULL, 0x0, "Fragment overlaps with other fragments", HFILL }
3136                 },
3137
3138                 {&hf_rtp_fragment_overlap_conflict,
3139                  {"Conflicting data in fragment overlap", "rtp.fragment.overlap.conflict",
3140                   FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3141                   "Overlapping fragments contained conflicting data", HFILL }
3142                 },
3143
3144                 {&hf_rtp_fragment_multiple_tails,
3145                  {"Multiple tail fragments found", "rtp.fragment.multipletails",
3146                   FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3147                   "Several tails were found when defragmenting the packet", HFILL }
3148                 },
3149
3150                 {&hf_rtp_fragment_too_long_fragment,
3151                  {"Fragment too long", "rtp.fragment.toolongfragment",
3152                   FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3153                   "Fragment contained data past end of packet", HFILL }
3154                 },
3155
3156                 {&hf_rtp_fragment_error,
3157                  {"Defragmentation error", "rtp.fragment.error",
3158                   FT_FRAMENUM, BASE_NONE, NULL, 0x0,
3159                   "Defragmentation error due to illegal fragments", HFILL }
3160                 },
3161
3162                 {&hf_rtp_fragment_count,
3163                  {"Fragment count", "rtp.fragment.count",
3164                   FT_UINT32, BASE_DEC, NULL, 0x0,
3165                   NULL, HFILL }
3166                 },
3167
3168                 {&hf_rtp_reassembled_in,
3169                  {"RTP fragment, reassembled in frame", "rtp.reassembled_in",
3170                   FT_FRAMENUM, BASE_NONE, NULL, 0x0,
3171                   "This RTP packet is reassembled in this frame", HFILL }
3172                 },
3173                 {&hf_rtp_reassembled_length,
3174                  {"Reassembled RTP length", "rtp.reassembled.length",
3175                   FT_UINT32, BASE_DEC, NULL, 0x0,
3176                   "The total length of the reassembled payload", HFILL }
3177                 },
3178                 {&hf_srtp_encrypted_payload,
3179                  {"SRTP Encrypted Payload", "srtp.enc_payload",
3180                   FT_BYTES, BASE_NONE, NULL, 0x0,
3181                   NULL, HFILL }
3182                 },
3183                 {&hf_srtp_mki,
3184                  {"SRTP MKI", "srtp.mki",
3185                   FT_BYTES, BASE_NONE, NULL, 0x0,
3186                   "SRTP Master Key Index", HFILL }
3187                 },
3188                 {&hf_srtp_auth_tag,
3189                  {"SRTP Auth Tag", "srtp.auth_tag",
3190                   FT_BYTES, BASE_NONE, NULL, 0x0,
3191                   "SRTP Authentication Tag", HFILL }
3192                 }
3193
3194         };
3195
3196         static gint *ett[] =
3197         {
3198                 &ett_rtp,
3199                 &ett_csrc_list,
3200                 &ett_hdr_ext,
3201                 &ett_hdr_ext_rfc5285,
3202                 &ett_hdr_ext_ed137s,
3203                 &ett_hdr_ext_ed137,
3204                 &ett_hdr_ext_ed137a,
3205                 &ett_rtp_setup,
3206                 &ett_rtp_rfc2198,
3207                 &ett_rtp_rfc2198_hdr,
3208                 &ett_rtp_fragment,
3209                 &ett_rtp_fragments
3210         };
3211
3212         module_t *rtp_module;
3213
3214
3215         proto_rtp = proto_register_protocol("Real-Time Transport Protocol",
3216                                             "RTP", "rtp");
3217         proto_register_field_array(proto_rtp, hf, array_length(hf));
3218         proto_register_subtree_array(ett, array_length(ett));
3219
3220         new_register_dissector("rtp", dissect_rtp, proto_rtp);
3221         register_dissector("rtp.rfc2198", dissect_rtp_rfc2198, proto_rtp);
3222
3223         rtp_tap = register_tap("rtp");
3224
3225         rtp_pt_dissector_table = register_dissector_table("rtp.pt",
3226                                                                         "RTP payload type", FT_UINT8, BASE_DEC);
3227         rtp_dyn_pt_dissector_table = register_dissector_table("rtp_dyn_payload_type",
3228                                                                         "Dynamic RTP payload type", FT_STRING, BASE_NONE);
3229
3230
3231         rtp_hdr_ext_dissector_table = register_dissector_table("rtp.hdr_ext",
3232                                                                         "RTP header extension", FT_UINT32, BASE_HEX);
3233         rtp_hdr_ext_rfc5285_dissector_table = register_dissector_table("rtp.ext.rfc5285.id",
3234                                                                         "RTP Generic header extension (RFC 5285)", FT_UINT8, BASE_DEC);
3235
3236         register_dissector("rtp.ext.ed137", dissect_rtp_hdr_ext_ed137, proto_rtp);
3237         register_dissector("rtp.ext.ed137a", dissect_rtp_hdr_ext_ed137a, proto_rtp);
3238
3239         rtp_module = prefs_register_protocol(proto_rtp, proto_reg_handoff_rtp);
3240
3241         prefs_register_bool_preference(rtp_module, "show_setup_info",
3242                                                                         "Show stream setup information",
3243                                                                         "Where available, show which protocol and frame caused "
3244                                                                         "this RTP stream to be created",
3245                                                                         &global_rtp_show_setup_info);
3246
3247         prefs_register_bool_preference(rtp_module, "heuristic_rtp",
3248                                                                         "Try to decode RTP outside of conversations",
3249                                                                         "If call control SIP/H323/RTSP/.. messages are missing in the trace, "
3250                                                                         "RTP isn't decoded without this",
3251                                                                         &global_rtp_heur);
3252
3253         prefs_register_bool_preference(rtp_module, "desegment_rtp_streams",
3254                                                                         "Allow subdissector to reassemble RTP streams",
3255                                                                         "Whether subdissector can request RTP streams to be reassembled",
3256                                                                         &desegment_rtp);
3257
3258         prefs_register_enum_preference(rtp_module, "version0_type",
3259                                                                         "Treat RTP version 0 packets as",
3260                                                                         "If an RTP version 0 packet is encountered, it can be treated as "
3261                                                                         "an invalid or ZRTP packet, a CLASSIC-STUN packet, or a T.38 packet",
3262                                                                         &global_rtp_version0_type,
3263                                                                         rtp_version0_types, FALSE);
3264         prefs_register_uint_preference(rtp_module,
3265                                                                         "rfc2198_payload_type", "Payload Type for RFC2198",
3266                                                                         "Payload Type for RFC2198 Redundant Audio Data",
3267                                                                         10,
3268                                                                         &rtp_rfc2198_pt);
3269
3270         register_init_routine(rtp_fragment_init);
3271 }
3272
3273 void
3274 proto_reg_handoff_rtp(void)
3275 {
3276         static gboolean rtp_prefs_initialized = FALSE;
3277         static dissector_handle_t rtp_rfc2198_handle;
3278         static dissector_handle_t rtp_hdr_ext_ed137_handle;
3279         static dissector_handle_t rtp_hdr_ext_ed137a_handle;
3280         static guint rtp_saved_rfc2198_pt;
3281
3282         if (!rtp_prefs_initialized) {
3283                 rtp_handle = find_dissector("rtp");
3284                 rtp_rfc2198_handle = find_dissector("rtp.rfc2198");
3285
3286                 dissector_add_handle("udp.port", rtp_handle);  /* for 'decode-as' */
3287                 dissector_add_string("rtp_dyn_payload_type", "red", rtp_rfc2198_handle);
3288                 heur_dissector_add( "udp", dissect_rtp_heur_udp,  proto_rtp);
3289                 heur_dissector_add("stun", dissect_rtp_heur_stun, proto_rtp);
3290
3291                 rtp_hdr_ext_ed137_handle = find_dissector("rtp.ext.ed137");
3292                 rtp_hdr_ext_ed137a_handle = find_dissector("rtp.ext.ed137a");
3293                 dissector_add_uint("rtp.hdr_ext", RTP_ED137_SIG, rtp_hdr_ext_ed137_handle);
3294                 dissector_add_uint("rtp.hdr_ext", RTP_ED137A_SIG, rtp_hdr_ext_ed137a_handle);
3295
3296                 data_handle = find_dissector("data");
3297                 stun_handle = find_dissector("stun-udp");
3298                 classicstun_handle = find_dissector("classicstun");
3299                 classicstun_heur_handle = find_dissector("classicstun-heur");
3300                 stun_heur_handle = find_dissector("stun-heur");
3301                 t38_handle = find_dissector("t38");
3302                 zrtp_handle = find_dissector("zrtp");
3303
3304                 sprt_handle = find_dissector("sprt");
3305                 v150fw_handle = find_dissector("v150fw");
3306
3307                 bta2dp_content_protection_header_scms_t = find_dissector("bta2dp_content_protection_header_scms_t");
3308                 btvdp_content_protection_header_scms_t = find_dissector("btvdp_content_protection_header_scms_t");
3309                 bta2dp_handle = find_dissector("bta2dp");
3310                 btvdp_handle = find_dissector("btvdp");
3311                 sbc_handle = find_dissector("sbc");
3312
3313                 dissector_add_string("rtp_dyn_payload_type", "v150fw", v150fw_handle);
3314
3315                 dissector_add_handle("btl2cap.cid", rtp_handle);
3316
3317                 rtp_prefs_initialized = TRUE;
3318         } else {
3319                 dissector_delete_uint("rtp.pt", rtp_saved_rfc2198_pt, rtp_rfc2198_handle);
3320         }
3321         dissector_add_uint("rtp.pt", rtp_rfc2198_pt, rtp_rfc2198_handle);
3322         rtp_saved_rfc2198_pt = rtp_rfc2198_pt;
3323 }
3324
3325 /*
3326  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
3327  *
3328  * Local variables:
3329  * c-basic-offset: 8
3330  * tab-width: 8
3331  * indent-tabs-mode: t
3332  * End:
3333  *
3334  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
3335  * :indentSize=8:tabSize=8:noTabs=false:
3336  */