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