2 * Routines for RTCP packet disassembly
4 * Jason Lango <jal@netapp.com>
6 * $Id: packet-rtcp.c,v 1.1 2000/04/21 01:45:56 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h>
36 #ifdef HAVE_NETINET_IN_H
37 #include <netinet/in.h>
45 #include "packet-rtcp.h"
47 static int proto_rtcp = -1;
49 static gint ett_rtcp = -1;
51 #define _RTCP_FLAG_BITS(hdr, s, n) \
52 ((u_int)(((hdr)->rtcp_flag_bits >> (8 - (s) - (n))) & ((1 << (n)) - 1)))
53 #define RTCP_VERSION(hdr) _RTCP_FLAG_BITS(hdr, 0, 2)
54 #define RTCP_PADDING(hdr) _RTCP_FLAG_BITS(hdr, 2, 1)
55 #define RTCP_COUNT(hdr) _RTCP_FLAG_BITS(hdr, 3, 5)
57 #define RTCP_TYPE_SR 200 /* Sender Report */
58 #define RTCP_TYPE_RR 201 /* Receiver Report */
59 #define RTCP_TYPE_SDES 202 /* Source Description */
60 #define RTCP_TYPE_BYE 203 /* Goodbye */
61 #define RTCP_TYPE_APP 204 /* Application-defined */
63 typedef struct rtcp_hdr {
64 guint8 rtcp_flag_bits;
65 guint8 rtcp_type; /* packet type */
66 guint16 rtcp_length; /* length in 32 bit words minus 1 */
69 typedef struct rtcp_report {
70 guint32 rtcp_rr_ssrc; /* SSRC of source */
71 guint8 rtcp_rr_flt; /* fraction lost */
72 guint8 rtcp_rr_cplthi; /* hi-byte of cplt */
73 guint16 rtcp_rr_cplt; /* cumulative packets lost */
74 guint32 rtcp_rr_xhiseq; /* extended highest seq num rcvd */
75 guint32 rtcp_rr_jitter; /* interarrival jitter */
76 guint32 rtcp_rr_lsr; /* middle bits of last SR timestamp */
77 guint32 rtcp_rr_dlsr; /* delay since last SR */
81 dissect_rtcp_report(rtcp_hdr_t *hdr, int sn, const u_char *pd, int offset,
82 int start_packet, int end_packet, proto_tree *rtcp_tree)
84 int end_offset = offset + END_OF_FRAME;
87 if (offset >= end_offset)
90 memcpy(&rep, &pd[offset], sizeof(rtcp_report_t) <= END_OF_FRAME ?
91 sizeof(rtcp_report_t) : END_OF_FRAME);
93 rep.rtcp_rr_ssrc = ntohl(rep.rtcp_rr_ssrc);
94 rep.rtcp_rr_cplt = ntohs(rep.rtcp_rr_cplt);
95 rep.rtcp_rr_xhiseq = ntohl(rep.rtcp_rr_xhiseq);
96 rep.rtcp_rr_jitter = ntohl(rep.rtcp_rr_jitter);
97 rep.rtcp_rr_lsr = ntohl(rep.rtcp_rr_lsr);
98 rep.rtcp_rr_dlsr = ntohl(rep.rtcp_rr_dlsr);
100 if ((offset + sizeof(rtcp_report_t)) > end_offset) {
101 proto_tree_add_text(rtcp_tree, offset, 0,
102 "Warning: Bad packet length -- "
103 "data might be incorrect");
106 proto_tree_add_text(rtcp_tree, offset, 4,
107 "Source %d SSRC: %u", sn + 1, rep.rtcp_rr_ssrc);
110 proto_tree_add_text(rtcp_tree, offset, 1,
111 "Fraction lost: %u / 256", (unsigned) rep.rtcp_rr_flt);
114 proto_tree_add_text(rtcp_tree, offset, 3,
115 "Cumulative Packets Lost: %lu",
116 (((unsigned long) rep.rtcp_rr_cplthi) << 16) +
117 (unsigned long) rep.rtcp_rr_cplt);
120 proto_tree_add_text(rtcp_tree, offset, 4,
121 "Extended Highest Seq #: %lu",
122 (unsigned long) rep.rtcp_rr_xhiseq);
125 proto_tree_add_text(rtcp_tree, offset, 4,
126 "Jitter: %lu", (unsigned long) rep.rtcp_rr_jitter);
129 proto_tree_add_text(rtcp_tree, offset, 4,
130 "Last SR timestamp (middle): %lu",
131 (unsigned long) rep.rtcp_rr_lsr);
134 proto_tree_add_text(rtcp_tree, offset, 4,
135 "Delay Since Last SR: %lu",
136 (unsigned long) rep.rtcp_rr_dlsr);
142 typedef struct rtcp_rr {
143 guint32 rtcp_rr_ssrc;
147 dissect_rtcp_rr(rtcp_hdr_t *hdr, const u_char *pd, int offset,
148 int start_packet, int end_packet, proto_tree *rtcp_tree)
150 int end_offset = offset + END_OF_FRAME;
154 memcpy(&rr, &pd[offset], sizeof(rtcp_rr_t) < END_OF_FRAME ?
155 sizeof(rtcp_rr_t) : END_OF_FRAME);
156 rr.rtcp_rr_ssrc = ntohl(rr.rtcp_rr_ssrc);
158 if ((offset + sizeof(rtcp_rr_t)) >= end_offset)
160 proto_tree_add_text(rtcp_tree, offset, 4, "Sender SSRC: %u",
164 for (sn = 0; sn < RTCP_COUNT(hdr); sn++) {
165 offset = dissect_rtcp_report(hdr, sn, pd, offset, start_packet,
166 end_packet, rtcp_tree);
172 typedef struct rtcp_sr {
173 guint32 rtcp_sr_ssrc;
174 guint32 rtcp_sr_ntp_hi; /* MSW of NTP timestamp */
175 guint32 rtcp_sr_ntp_lo; /* LSW of NTP timestamp */
176 guint32 rtcp_sr_rtp_time; /* RTP timestamp */
177 guint32 rtcp_sr_npackets; /* sender's packet count */
178 guint32 rtcp_sr_nbytes; /* sender's octet count */
182 dissect_rtcp_sr(rtcp_hdr_t *hdr, const u_char *pd, int offset,
183 int start_packet, int end_packet, proto_tree *rtcp_tree)
185 int end_offset = offset + END_OF_FRAME;
189 memcpy(&sr, &pd[offset], sizeof(rtcp_sr_t) < END_OF_FRAME ?
190 sizeof(rtcp_sr_t) : END_OF_FRAME);
191 sr.rtcp_sr_ssrc = ntohl(sr.rtcp_sr_ssrc);
192 sr.rtcp_sr_ntp_hi = ntohl(sr.rtcp_sr_ntp_hi);
193 sr.rtcp_sr_ntp_lo = ntohl(sr.rtcp_sr_ntp_lo);
194 sr.rtcp_sr_rtp_time = ntohl(sr.rtcp_sr_rtp_time);
195 sr.rtcp_sr_npackets = ntohl(sr.rtcp_sr_npackets);
196 sr.rtcp_sr_nbytes = ntohl(sr.rtcp_sr_nbytes);
198 if ((offset + sizeof(rtcp_sr_t)) > end_offset) {
199 proto_tree_add_text(rtcp_tree, offset, 0,
200 "Warning: Bad packet length -- "
201 "data might be incorrect");
204 proto_tree_add_text(rtcp_tree, offset, 4, "Sender's SSRC: %u",
207 proto_tree_add_text(rtcp_tree, offset, 4, "NTP timestamp, MSW: %u",
210 proto_tree_add_text(rtcp_tree, offset, 4, "NTP timestamp, LSW: %u",
213 proto_tree_add_text(rtcp_tree, offset, 4, "RTP timestamp: %u",
214 sr.rtcp_sr_rtp_time);
216 proto_tree_add_text(rtcp_tree, offset, 4, "Sender's packet count: %u",
217 sr.rtcp_sr_npackets);
219 proto_tree_add_text(rtcp_tree, offset, 4, "Sender's octet count: %u",
223 for (sn = 0; sn < RTCP_COUNT(hdr); sn++) {
224 offset = dissect_rtcp_report(hdr, sn, pd, offset, start_packet,
225 end_packet, rtcp_tree);
231 static struct rtcp_chunk_type {
234 } rtcp_chunk_types[] = {
235 { 1, "CNAME (user and domain)" },
236 { 2, "NAME (common name)" },
237 { 3, "EMAIL (e-mail address)" },
238 { 4, "PHONE (phone number)" },
239 { 5, "LOC (geographic location)" },
240 { 6, "TOOL (name/version of source app)" },
241 { 7, "NOTE (note about source)" },
242 { 8, "PRIV (private extensions)" },
246 static struct rtcp_chunk_type *
247 rtcp_find_chunk_type(int type)
249 struct rtcp_chunk_type *tt = rtcp_chunk_types;
250 static struct rtcp_chunk_type unk = { 0, "UNKNOWN" };
251 for (; tt->type; tt++) {
252 if (type == tt->type)
259 dissect_rtcp_sdes_chunk(rtcp_hdr_t *hdr, int cn, const u_char *pd, int offset,
260 int start_packet, int end_packet, proto_tree *rtcp_tree)
264 struct rtcp_chunk_type *ctype;
266 if ((offset + 4) > end_packet)
268 proto_tree_add_text(rtcp_tree, offset, 4, "Chunk %d SSRC: %u",
269 cn + 1, pntohl(&pd[offset]));
273 if ((offset + 1) > end_packet)
278 int pad_start = offset;
280 /* NULL terminator -- align to next 32 bit boundary */
281 if ((offset - start_packet) & 3) {
282 offset += 4 - ((offset - start_packet) & 3);
284 proto_tree_add_text(rtcp_tree, pad_start,
286 "(end of chunk and alignment padding)");
290 ctype = rtcp_find_chunk_type(type);
292 proto_tree_add_text(rtcp_tree, offset, 1, "Chunk type: %s",
296 if ((offset + 1) > end_packet)
300 proto_tree_add_text(rtcp_tree, offset, 1, "Chunk length: %u",
304 if ((offset + len) > end_packet)
307 proto_tree_add_text(rtcp_tree, offset, len, "Chunk string: %s",
308 format_text(&pd[offset], len));
315 dissect_rtcp_sdes(rtcp_hdr_t *hdr, const u_char *pd, int offset,
316 int start_packet, int end_packet, proto_tree *rtcp_tree)
320 for (cn = 0; cn < RTCP_COUNT(hdr); cn++) {
321 offset = dissect_rtcp_sdes_chunk(hdr, cn, pd, offset,
322 start_packet, end_packet, rtcp_tree);
328 dissect_one_rtcp(const u_char *pd, int offset, frame_data *fd,
331 proto_tree *rtcp_tree;
333 const u_char *data, *dataend;
341 dataend = data + END_OF_FRAME;
342 start_packet = offset;
343 end_offset = offset + END_OF_FRAME;
345 ti = proto_tree_add_item(tree, proto_rtcp, offset, END_OF_FRAME, NULL);
346 rtcp_tree = proto_item_add_subtree(ti, ett_rtcp);
348 memcpy(&hdr, data, END_OF_FRAME < sizeof(rtcp_hdr_t) ?
349 END_OF_FRAME : sizeof(rtcp_hdr_t));
350 hdr.rtcp_length = ntohs(hdr.rtcp_length);
352 if (offset >= end_offset)
354 proto_tree_add_text(rtcp_tree, offset, 1, "Version: %u (%s)",
356 RTCP_VERSION(&hdr) == 3 ? "New Unknown Version" :
357 RTCP_VERSION(&hdr) == 2 ? "RFC 1889 Version" :
358 RTCP_VERSION(&hdr) == 1 ? "First Draft Version" :
360 proto_tree_add_text(rtcp_tree, offset, 1, "Padding: %u",
362 proto_tree_add_text(rtcp_tree, offset, 1, "Count: %u",
366 if (offset >= end_offset)
368 switch (hdr.rtcp_type) {
369 case RTCP_TYPE_SR: ptype = "SR: Sender Report"; break;
370 case RTCP_TYPE_RR: ptype = "RR: Receiver Report"; break;
371 case RTCP_TYPE_SDES: ptype = "SDES: Source Description"; break;
372 case RTCP_TYPE_BYE: ptype = "BYE: Goodbye"; break;
373 case RTCP_TYPE_APP: ptype = "APP: Application-defined"; break;
374 default: ptype = "Unknown"; break;
376 proto_tree_add_text(rtcp_tree, offset, 1, "Type: %u (%s)",
377 (u_int) hdr.rtcp_type, ptype);
380 if (offset >= end_offset)
382 proto_tree_add_text(rtcp_tree, offset, 2, "Length / 4 - 1: %u",
383 (unsigned) hdr.rtcp_length);
387 * Don't add 1 to length, since it's accounted for above.
389 end_packet = offset + hdr.rtcp_length * 4;
391 switch (hdr.rtcp_type) {
393 offset = dissect_rtcp_rr(&hdr, pd, offset, start_packet,
394 end_packet, rtcp_tree);
397 offset = dissect_rtcp_sr(&hdr, pd, offset, start_packet,
398 end_packet, rtcp_tree);
401 offset = dissect_rtcp_sdes(&hdr, pd, offset, start_packet,
402 end_packet, rtcp_tree);
405 proto_tree_add_text(rtcp_tree, offset, END_OF_FRAME,
406 "TYPE NOT HANDLED YET");
411 if (offset > 0 && offset < end_packet) {
412 proto_tree_add_text(rtcp_tree, offset, end_packet - offset,
413 "Extra data (%d bytes)", end_packet - offset);
421 dissect_rtcp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
425 if (check_col(fd, COL_PROTOCOL))
426 col_add_str(fd, COL_PROTOCOL, "RTCP");
431 end_offset = offset + END_OF_FRAME;
432 while (offset > 0 && offset < end_offset) {
433 offset = dissect_one_rtcp(pd, offset, fd, tree);
436 proto_tree_add_text(tree, end_offset, 0,
437 "Unexpected end of packet");
442 proto_register_rtcp(void)
444 /* static hf_register_info hf[] = {
446 { "Name", "rtcp.abbreviation", TYPE, VALS_POINTER }},
448 static gint *ett[] = {
452 proto_rtcp = proto_register_protocol("RTP Control Protocol", "rtcp");
453 /* proto_register_field_array(proto_rtcp, hf, array_length(hf));*/
454 proto_register_subtree_array(ett, array_length(ett));