3 * Routines for RTP dissection
4 * RTP = Real time Transport Protocol
6 * Copyright 2000, Philips Electronics N.V.
7 * Written by Andreas Sikkema <andreas.sikkema@philips.com>
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@zing.org>
11 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 * This dissector tries to dissect the RTP protocol according to Annex A
31 * of ITU-T Recommendation H.225.0 (02/98) or RFC 1889
33 * RTP traffic is handled by an even UDP portnumber. This can be any
34 * port number, but there is a registered port available, port 5004
35 * See Annex B of ITU-T Recommendation H.225.0, section B.7
46 #ifdef HAVE_SYS_TYPES_H
47 # include <sys/types.h>
50 #ifdef HAVE_NETINET_IN_H
51 # include <netinet/in.h>
57 #include "packet-rtp.h"
58 #include "packet-h261.h"
59 #include "conversation.h"
61 /* RTP header fields */
62 static int proto_rtp = -1;
63 static int hf_rtp_version = -1;
64 static int hf_rtp_padding = -1;
65 static int hf_rtp_extension = -1;
66 static int hf_rtp_csrc_count = -1;
67 static int hf_rtp_marker = -1;
68 static int hf_rtp_payload_type = -1;
69 static int hf_rtp_seq_nr = -1;
70 static int hf_rtp_timestamp = -1;
71 static int hf_rtp_ssrc = -1;
72 static int hf_rtp_csrc_item = -1;
73 static int hf_rtp_data = -1;
74 static int hf_rtp_padding_data = -1;
75 static int hf_rtp_padding_count= -1;
77 /* RTP header extension fields */
78 static int hf_rtp_prof_define = -1;
79 static int hf_rtp_length = -1;
80 static int hf_rtp_hdr_ext = -1;
82 /* RTP fields defining a sub tree */
83 static gint ett_rtp = -1;
84 static gint ett_csrc_list = -1;
85 static gint ett_hdr_ext = -1;
88 * Fields in the first octet of the RTP header.
91 /* Version is the first 2 bits of the first octet*/
92 #define RTP_VERSION(octet) ((octet) >> 6)
94 /* Padding is the third bit; No need to shift, because true is any value
96 #define RTP_PADDING(octet) ((octet) & 0x20)
98 /* Extension bit is the fourth bit */
99 #define RTP_EXTENSION(octet) ((octet) & 0x10)
101 /* CSRC count is the last four bits */
102 #define RTP_CSRC_COUNT(octet) ((octet) & 0xF)
104 static const value_string rtp_version_vals[] =
106 { 0, "Old VAT Version" },
107 { 1, "First Draft Version" },
108 { 2, "RFC 1889 Version" },
113 * Fields in the second octet of the RTP header.
116 /* Marker is the first bit of the second octet */
117 #define RTP_MARKER(octet) ((octet) & 0x80)
119 /* Payload type is the last 7 bits */
120 #define RTP_PAYLOAD_TYPE(octet) ((octet) & 0x7F)
124 * Table B.2 / H.225.0
132 #define PT_DVI4_8000 5
133 #define PT_DVI4_16000 6
137 #define PT_L16_STEREO 10
138 #define PT_L16_MONO 11
150 static const value_string rtp_payload_type_vals[] =
152 { PT_PCMU, "ITU-T G.711 PCMU" },
153 { PT_1016, "USA Federal Standard FS-1016" },
154 { PT_G721, "ITU-T G.721" },
155 { PT_GSM, "GSM 06.10" },
156 { PT_G723, "ITU-T G.723" },
157 { PT_DVI4_8000, "DVI4 8000 samples/s" },
158 { PT_DVI4_16000, "DVI4 16000 samples/s" },
160 { PT_PCMA, "ITU-T G.711 PCMA" },
161 { PT_G722, "ITU-T G.722" },
162 { PT_L16_STEREO, "16-bit uncompressed audio, stereo" },
163 { PT_L16_MONO, "16-bit uncompressed audio, monaural" },
164 { PT_MPA, "MPEG-I/II Audeo"},
165 { PT_G728, "ITU-T G.728" },
166 { PT_G729, "ITU-T G.729" },
167 { PT_CELB, "Sun CELL-B" },
169 { PT_NV, "'nv' program" },
170 { PT_H261, "ITU-T H.261" },
171 { PT_MPV, "MPEG-I/II Video"},
172 { PT_MP2T, "MPEG-II transport streams"},
173 { PT_H263, "ITU-T H.263" },
177 static address fake_addr;
178 static int heur_init = FALSE;
180 static const char rtp_proto[] = "RTP";
182 void rtp_add_address( const unsigned char* ip_addr, int prt )
185 conversation_t* pconv = ( conversation_t* ) NULL;
187 src_addr.type = AT_IPv4;
189 src_addr.data = ip_addr;
192 * The first time the function is called let the tcp dissector
193 * know that we're interested in traffic
196 heur_dissector_add( "udp", dissect_rtp_heur, proto_rtp );
201 * Check if the ip address an dport combination is not
204 pconv = find_conversation( &src_addr, &fake_addr, PT_UDP, prt, 0, 0 );
210 conversation_new( &src_addr, &fake_addr, PT_UDP, (guint32) prt,
211 (guint32) 0, ( void * ) rtp_proto, 0 );
217 static void rtp_init( void )
219 unsigned char* tmp_data;
222 /* Create a fake adddress... */
223 fake_addr.type = AT_IPv4;
226 tmp_data = malloc( fake_addr.len );
227 for ( i = 0; i < fake_addr.len; i++) {
230 fake_addr.data = tmp_data;
235 dissect_rtp_heur( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
237 conversation_t* pconv;
239 if (!proto_is_protocol_enabled(proto_rtp))
240 return FALSE; /* RTP has been disabled */
242 /* This is a heuristic dissector, which means we get all the TCP
243 * traffic not sent to a known dissector and not claimed by
244 * a heuristic dissector called before us!
245 * So we first check if the frame is really meant for us.
247 if ( ( pconv = find_conversation( &pi.src, &fake_addr, pi.ptype,
248 pi.srcport, 0, 0 ) ) == NULL ) {
250 * The source ip:port combination was not what we were
251 * looking for, check the destination
253 if ( ( pconv = find_conversation( &pi.dst, &fake_addr,
254 pi.ptype, pi.destport, 0, 0 ) ) == NULL ) {
260 * An RTP conversation always contains data
262 if ( pconv->data == NULL )
266 * An RTP conversation data always contains "RTP"
268 if ( strcmp( pconv->data, rtp_proto ) != 0 )
271 dissect_rtp( tvb, pinfo, tree );
277 dissect_rtp_data( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree *rtp_tree, int offset, unsigned int data_len, unsigned int payload_type )
281 switch( payload_type ) {
284 * What does reported length DO?
286 newtvb = tvb_new_subset( tvb, offset, data_len, -1 );
287 dissect_h261(newtvb, pinfo, tree);
290 proto_tree_add_bytes( rtp_tree, hf_rtp_data, tvb, offset, data_len, tvb_get_ptr( tvb, offset, data_len ) );
296 dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
298 proto_item *ti = NULL;
299 proto_tree *rtp_tree = NULL;
300 proto_tree *rtp_csrc_tree = NULL;
302 unsigned int version;
303 gboolean padding_set;
304 gboolean extension_set;
305 unsigned int csrc_count;
307 unsigned int payload_type;
309 unsigned int hdr_extension= 0;
310 unsigned int padding_count= 0;
311 unsigned int offset = 0;
317 CHECK_DISPLAY_AS_DATA(proto_rtp, tvb, pinfo, tree);
319 pinfo->current_proto = "RTP";
321 /* Get the fields in the first octet */
322 octet = tvb_get_guint8( tvb, offset );
323 version = RTP_VERSION( octet );
324 padding_set = RTP_PADDING( octet );
325 extension_set = RTP_EXTENSION( octet );
326 csrc_count = RTP_CSRC_COUNT( octet );
328 /* Get the fields in the second octet */
329 octet = tvb_get_guint8( tvb, offset + 1 );
330 marker_set = RTP_MARKER( octet );
331 payload_type = RTP_PAYLOAD_TYPE( octet );
333 /* Get the subsequent fields */
334 seq_num = tvb_get_ntohs( tvb, offset + 2 );
335 timestamp = tvb_get_ntohl( tvb, offset + 4 );
336 sync_src = tvb_get_ntohl( tvb, offset + 8 );
338 if ( check_col( pinfo->fd, COL_PROTOCOL ) ) {
339 col_set_str( pinfo->fd, COL_PROTOCOL, "RTP" );
342 if ( check_col( pinfo->fd, COL_INFO) ) {
343 col_add_fstr( pinfo->fd, COL_INFO,
344 "Payload type=%s, SSRC=%u, Seq=%u, Time=%u%s",
345 val_to_str( payload_type, rtp_payload_type_vals,
350 marker_set ? ", Mark" : "");
354 ti = proto_tree_add_item( tree, proto_rtp, tvb, offset, tvb_length_remaining( tvb, offset ), FALSE );
355 rtp_tree = proto_item_add_subtree( ti, ett_rtp );
357 proto_tree_add_uint( rtp_tree, hf_rtp_version, tvb,
358 offset, 1, version );
359 proto_tree_add_boolean( rtp_tree, hf_rtp_padding, tvb,
360 offset, 1, padding_set );
361 proto_tree_add_boolean( rtp_tree, hf_rtp_extension, tvb,
362 offset, 1, extension_set );
363 proto_tree_add_uint( rtp_tree, hf_rtp_csrc_count, tvb,
364 offset, 1, csrc_count );
367 proto_tree_add_boolean( rtp_tree, hf_rtp_marker, tvb, offset,
369 proto_tree_add_uint( rtp_tree, hf_rtp_payload_type, tvb,
370 offset, 1, payload_type );
373 /* Sequence number 16 bits (2 octets) */
374 proto_tree_add_uint( rtp_tree, hf_rtp_seq_nr, tvb, offset, 2, seq_num );
377 /* Timestamp 32 bits (4 octets) */
378 proto_tree_add_uint( rtp_tree, hf_rtp_timestamp, tvb, offset, 4, timestamp );
381 /* Synchronization source identifier 32 bits (4 octets) */
382 proto_tree_add_uint( rtp_tree, hf_rtp_ssrc, tvb, offset, 4, sync_src );
386 if ( csrc_count > 0 ) {
387 ti = proto_tree_add_text(rtp_tree, tvb, offset, csrc_count * 4, "Contributing Source identifiers");
388 rtp_csrc_tree = proto_item_add_subtree( ti, ett_csrc_list );
389 for (i = 0; i < csrc_count; i++ ) {
390 csrc_item = tvb_get_ntohl( tvb, offset );
391 proto_tree_add_uint_format( rtp_csrc_tree,
392 hf_rtp_csrc_item, tvb, offset, 4,
400 /* Optional RTP header extension */
401 if ( extension_set ) {
402 /* Defined by profile field is 16 bits (2 octets) */
403 proto_tree_add_uint( rtp_tree, hf_rtp_prof_define, tvb, offset, 2, tvb_get_ntohs( tvb, offset ) );
406 hdr_extension = tvb_get_ntohs( tvb, offset );
407 proto_tree_add_uint( rtp_tree, hf_rtp_length, tvb,
408 offset, 2, hdr_extension);
409 if ( hdr_extension > 0 ) {
410 ti = proto_tree_add_text(rtp_tree, tvb, offset, csrc_count * 4, "Header extensions");
411 /* I'm re-using the old tree variable here
412 from the CSRC list!*/
413 rtp_csrc_tree = proto_item_add_subtree( ti,
415 for (i = 0; i < hdr_extension; i++ ) {
416 proto_tree_add_uint( rtp_csrc_tree, hf_rtp_hdr_ext, tvb, offset, 4, tvb_get_ntohl( tvb, offset ) );
422 * The padding count is found in the LAST octet of the packet
423 * This contains the number of octets that can be ignored at
424 * the end of the packet
427 padding_count = tvb_get_guint8( tvb, tvb_length( tvb ) - 1 );
428 if ( padding_count > 0 ) {
429 dissect_rtp_data( tvb, pinfo, tree, rtp_tree, offset, tvb_length( tvb ) - padding_count, payload_type );
430 offset = tvb_length( tvb ) - padding_count;
431 proto_tree_add_item( rtp_tree, hf_rtp_padding_data, tvb, offset, padding_count - 1, FALSE );
432 offset += padding_count - 1;
433 proto_tree_add_item( rtp_tree, hf_rtp_padding_count, tvb, offset, 1, FALSE );
436 proto_tree_add_item( rtp_tree, hf_rtp_padding_count, tvb, tvb_length( tvb ) - 1, 1, FALSE );
440 dissect_rtp_data( tvb, pinfo, tree, rtp_tree, offset, tvb_length_remaining( tvb, offset ) - padding_count, payload_type );
446 proto_register_rtp(void)
448 static hf_register_info hf[] =
457 VALS(rtp_version_vals),
489 "Contributing source identifiers count",
511 &hf_rtp_payload_type,
517 VALS(rtp_payload_type_vals),
549 "Synchronization Source identifier",
561 "Defined by profile",
619 &hf_rtp_padding_data,
631 &hf_rtp_padding_count,
652 proto_rtp = proto_register_protocol("Real-Time Transport Protocol",
654 proto_register_field_array(proto_rtp, hf, array_length(hf));
655 proto_register_subtree_array(ett, array_length(ett));
658 register_init_routine( &rtp_init );
663 proto_reg_handoff_rtp(void)
666 * Register this dissector as one that can be assigned to a
669 conv_dissector_add("udp", dissect_rtp, proto_rtp);