2 * Routines for RTSP packet disassembly (RFC 2326)
4 * Jason Lango <jal@netapp.com>
5 * Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * 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.
28 * RTSP is defined in RFC 2326, http://www.ietf.org/rfc/rfc2326.txt?number=2326
29 * http://www.iana.org/assignments/rsvp-parameters
38 #include <epan/prefs.h>
42 #include <wsutil/str_util.h>
44 #include <epan/packet.h>
45 #include <epan/req_resp_hdrs.h>
46 #include "packet-rtp.h"
47 #include "packet-rtcp.h"
48 #include "packet-rdt.h"
49 #include <epan/conversation.h>
50 #include <epan/strutil.h>
51 #include "packet-e164.h"
52 #include <epan/emem.h>
54 #include <epan/tap-voip.h>
56 static int proto_rtsp = -1;
58 static gint ett_rtsp = -1;
59 static gint ett_rtspframe = -1;
60 static gint ett_rtsp_method = -1;
62 static int hf_rtsp_request = -1;
63 static int hf_rtsp_response = -1;
64 static int hf_rtsp_content_type = -1;
65 static int hf_rtsp_content_length = -1;
66 static int hf_rtsp_method = -1;
67 static int hf_rtsp_url = -1;
68 static int hf_rtsp_status = -1;
69 static int hf_rtsp_session = -1;
70 static int hf_rtsp_transport = -1;
71 static int hf_rtsp_rdtfeaturelevel = -1;
72 static int hf_rtsp_X_Vig_Msisdn = -1;
74 static int voip_tap = -1;
76 static dissector_handle_t rtp_handle;
77 static dissector_handle_t rtcp_handle;
78 static dissector_handle_t rdt_handle;
79 static dissector_table_t media_type_dissector_table;
81 void proto_reg_handoff_rtsp(void);
84 * desegmentation of RTSP headers
85 * (when we are over TCP or another protocol providing the desegmentation API)
87 static gboolean rtsp_desegment_headers = TRUE;
90 * desegmentation of RTSP bodies
91 * (when we are over TCP or another protocol providing the desegmentation API)
92 * TODO let the user filter on content-type the bodies he wants desegmented
94 static gboolean rtsp_desegment_body = TRUE;
96 /* http://www.iana.org/assignments/port-numberslists two rtsp ports */
97 #define TCP_PORT_RTSP 554
98 #define TCP_ALTERNATE_PORT_RTSP 8554
99 static guint global_rtsp_tcp_port = TCP_PORT_RTSP;
100 static guint global_rtsp_tcp_alternate_port = TCP_ALTERNATE_PORT_RTSP;
102 * Takes an array of bytes, assumed to contain a null-terminated
103 * string, as an argument, and returns the length of the string -
104 * i.e., the size of the array, minus 1 for the null terminator.
106 #define STRLEN_CONST(str) (sizeof (str) - 1)
108 #define RTSP_FRAMEHDR ('$')
111 dissector_handle_t dissector;
112 } rtsp_interleaved_t;
114 #define RTSP_MAX_INTERLEAVED (256)
117 * Careful about dynamically allocating memory in this structure (say
118 * for dynamically increasing the size of the 'interleaved' array) -
119 * the containing structure is garbage collected and contained
120 * pointers will not be freed.
123 rtsp_interleaved_t interleaved[RTSP_MAX_INTERLEAVED];
124 } rtsp_conversation_data_t;
127 dissect_rtspinterleaved(tvbuff_t *tvb, int offset, packet_info *pinfo,
130 guint length_remaining;
132 proto_tree *rtspframe_tree = NULL;
134 guint8 rf_start; /* always RTSP_FRAMEHDR */
135 guint8 rf_chan; /* interleaved channel id */
136 guint16 rf_len; /* packet length */
138 conversation_t *conv;
139 rtsp_conversation_data_t *data;
140 dissector_handle_t dissector;
143 * This will throw an exception if we don't have any data left.
144 * That's what we want. (See "tcp_dissect_pdus()", which is
147 length_remaining = tvb_ensure_length_remaining(tvb, offset);
150 * Can we do reassembly?
152 if (rtsp_desegment_headers && pinfo->can_desegment) {
154 * Yes - would an RTSP multiplexed header starting at
155 * this offset be split across segment boundaries?
157 if (length_remaining < 4) {
159 * Yes. Tell the TCP dissector where the data
160 * for this message starts in the data it handed
161 * us, and how many more bytes we need, and return.
163 pinfo->desegment_offset = offset;
164 pinfo->desegment_len = 4 - length_remaining;
170 * Get the "$", channel, and length from the header.
172 orig_offset = offset;
173 rf_start = tvb_get_guint8(tvb, offset);
174 rf_chan = tvb_get_guint8(tvb, offset+1);
175 rf_len = tvb_get_ntohs(tvb, offset+2);
178 * Can we do reassembly?
180 if (rtsp_desegment_body && pinfo->can_desegment) {
182 * Yes - is the header + encapsulated packet split
183 * across segment boundaries?
185 if (length_remaining < 4U + rf_len) {
187 * Yes. Tell the TCP dissector where the data
188 * for this message starts in the data it handed
189 * us, and how many more bytes we need, and return.
191 pinfo->desegment_offset = offset;
192 pinfo->desegment_len = 4U + rf_len - length_remaining;
197 if (check_col(pinfo->cinfo, COL_INFO))
198 col_add_fstr(pinfo->cinfo, COL_INFO,
199 "Interleaved channel 0x%02x, %u bytes",
203 ti = proto_tree_add_protocol_format(tree, proto_rtsp, tvb,
205 "RTSP Interleaved Frame, Channel: 0x%02x, %u bytes",
207 rtspframe_tree = proto_item_add_subtree(ti, ett_rtspframe);
209 proto_tree_add_text(rtspframe_tree, tvb, offset, 1,
216 proto_tree_add_text(rtspframe_tree, tvb, offset, 1,
223 proto_tree_add_text(rtspframe_tree, tvb, offset, 2,
230 * We set the actual length of the tvbuff for the interleaved
231 * stuff to the minimum of what's left in the tvbuff and the
232 * length in the header.
234 * XXX - what if there's nothing left in the tvbuff?
235 * We'd want a BoundsError exception to be thrown, so
236 * that a Short Frame would be reported.
238 if (length_remaining > rf_len)
239 length_remaining = rf_len;
240 next_tvb = tvb_new_subset(tvb, offset, length_remaining, rf_len);
242 conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,
243 pinfo->srcport, pinfo->destport, 0);
246 (data = conversation_get_proto_data(conv, proto_rtsp)) &&
247 /* Add the following condition if it is not always true.
248 rf_chan < RTSP_MAX_INTERLEAVED &&
250 (dissector = data->interleaved[rf_chan].dissector)) {
251 call_dissector(dissector, next_tvb, pinfo, tree);
253 proto_tree_add_text(rtspframe_tree, tvb, offset, rf_len,
254 "Data (%u bytes)", rf_len);
259 return offset - orig_offset;
262 static void process_rtsp_request(tvbuff_t *tvb, int offset, const guchar *data,
263 size_t linelen, size_t next_line_offset,
266 static void process_rtsp_reply(tvbuff_t *tvb, int offset, const guchar *data,
267 size_t linelen, size_t next_line_offset,
276 static const char *rtsp_methods[] = {
290 #define RTSP_NMETHODS (sizeof rtsp_methods / sizeof rtsp_methods[0])
293 is_rtsp_request_or_reply(const guchar *line, size_t linelen, rtsp_type_t *type)
297 /* Is this an RTSP reply? */
298 if (linelen >= 5 && g_ascii_strncasecmp("RTSP/", line, 5) == 0) {
307 * Is this an RTSP request?
308 * Check whether the line begins with one of the RTSP request
311 for (ii = 0; ii < RTSP_NMETHODS; ii++) {
312 size_t len = strlen(rtsp_methods[ii]);
313 if (linelen >= len &&
314 g_ascii_strncasecmp(rtsp_methods[ii], line, len) == 0 &&
315 (len == linelen || isspace(line[len])))
317 *type = RTSP_REQUEST;
322 /* Wasn't a request or a response */
323 *type = RTSP_NOT_FIRST_LINE;
327 static const char rtsp_content_type[] = "Content-Type:";
328 static const char rtsp_transport[] = "Transport:";
329 static const char rtsp_sps[] = "server_port=";
330 static const char rtsp_cps[] = "client_port=";
331 static const char rtsp_rtp[] = "rtp/";
332 static const char rtsp_rdt_feature_level[] = "RDTFeatureLevel";
333 static const char rtsp_real_rdt[] = "x-real-rdt/";
334 static const char rtsp_real_tng[] = "x-pn-tng/"; /* synonym for x-real-rdt */
335 static const char rtsp_inter[] = "interleaved=";
338 rtsp_create_conversation(packet_info *pinfo, const guchar *line_begin,
339 size_t line_len, gint rdt_feature_level)
341 conversation_t *conv;
344 gboolean rtp_transport = FALSE;
345 gboolean rdt_transport = FALSE;
346 guint c_data_port, c_mon_port;
347 guint s_data_port, s_mon_port;
348 gboolean is_video = FALSE; /* FIX ME - need to indicate video or not */
350 /* Copy line into buf */
351 if (line_len > sizeof(buf) - 1)
353 /* Don't overflow the buffer. */
354 line_len = sizeof(buf) - 1;
356 memcpy(buf, line_begin, line_len);
357 buf[line_len] = '\0';
359 /* Get past "Transport:" and spaces */
360 tmp = buf + STRLEN_CONST(rtsp_transport);
361 while (*tmp && isspace(*tmp))
364 /* Work out which transport type is here */
365 if (g_ascii_strncasecmp(tmp, rtsp_rtp, strlen(rtsp_rtp)) == 0)
366 rtp_transport = TRUE;
368 if (g_ascii_strncasecmp(tmp, rtsp_real_rdt, strlen(rtsp_real_rdt)) == 0 ||
369 g_ascii_strncasecmp(tmp, rtsp_real_tng, strlen(rtsp_real_tng)) == 0)
370 rdt_transport = TRUE;
373 /* Give up on unknown transport types */
377 c_data_port = c_mon_port = 0;
378 s_data_port = s_mon_port = 0;
380 /* Look for server port */
381 if ((tmp = strstr(buf, rtsp_sps))) {
382 tmp += strlen(rtsp_sps);
383 if (sscanf(tmp, "%u-%u", &s_data_port, &s_mon_port) < 1) {
384 g_warning("Frame %u: rtsp: bad server_port",
389 /* Look for client port */
390 if ((tmp = strstr(buf, rtsp_cps))) {
391 tmp += strlen(rtsp_cps);
392 if (sscanf(tmp, "%u-%u", &c_data_port, &c_mon_port) < 1) {
393 g_warning("Frame %u: rtsp: bad client_port",
400 /* Deal with RTSP TCP-interleaved conversations. */
402 rtsp_conversation_data_t *data;
403 guint s_data_chan, s_mon_chan;
406 /* Search tranport line for interleaved string */
407 if ((tmp = strstr(buf, rtsp_inter)) == NULL) {
409 * No interleaved or server_port - probably a
410 * SETUP request, rather than reply.
415 /* Move tmp to beyone interleaved string */
416 tmp += strlen(rtsp_inter);
417 /* Look for channel number(s) */
418 i = sscanf(tmp, "%u-%u", &s_data_chan, &s_mon_chan);
421 g_warning("Frame %u: rtsp: bad interleaved", pinfo->fd->num);
425 /* At least data channel present, look for conversation (presumably TCP) */
426 conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,
427 pinfo->srcport, pinfo->destport, 0);
429 /* Create new conversation if necessary */
432 conv = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
433 pinfo->ptype, pinfo->srcport, pinfo->destport,
437 /* Look for previous data */
438 data = conversation_get_proto_data(conv, proto_rtsp);
440 /* Create new data if necessary */
443 data = se_alloc(sizeof(rtsp_conversation_data_t));
444 conversation_add_proto_data(conv, proto_rtsp, data);
447 /* Now set the dissector handle of the interleaved channel
448 according to the transport protocol used */
451 if (s_data_chan < RTSP_MAX_INTERLEAVED) {
452 data->interleaved[s_data_chan].dissector =
455 if (i > 1 && s_mon_chan < RTSP_MAX_INTERLEAVED) {
456 data->interleaved[s_mon_chan].dissector =
460 else if (rdt_transport)
462 if (s_data_chan < RTSP_MAX_INTERLEAVED) {
463 data->interleaved[s_data_chan].dissector =
471 * We only want to match on the destination address, not the
472 * source address, because the server might send back a packet
473 * from an address other than the address to which its client
474 * sent the packet, so we construct a conversation with no
479 /* There is always data for RTP */
480 rtp_add_address(pinfo, &pinfo->dst, c_data_port, s_data_port,
481 "RTSP", pinfo->fd->num, is_video, NULL);
483 /* RTCP only if indicated */
486 rtcp_add_address(pinfo, &pinfo->dst, c_mon_port, s_mon_port,
487 "RTSP", pinfo->fd->num);
493 /* Real Data Transport */
494 rdt_add_address(pinfo, &pinfo->dst, c_data_port, s_data_port,
495 "RTSP", rdt_feature_level);
499 static const char rtsp_content_length[] = "Content-Length:";
502 rtsp_get_content_length(const guchar *line_begin, size_t line_len)
510 if (line_len > sizeof(buf) - 1) {
512 * Don't overflow the buffer.
514 line_len = sizeof(buf) - 1;
516 memcpy(buf, line_begin, line_len);
517 buf[line_len] = '\0';
519 tmp = buf + STRLEN_CONST(rtsp_content_length);
520 while (*tmp && isspace(*tmp))
522 content_length = strtol(tmp, &p, 10);
524 if (up == tmp || (*up != '\0' && !isspace(*up)))
525 return -1; /* not a valid number */
526 return content_length;
529 static const char rtsp_Session[] = "Session:";
530 static const char rtsp_X_Vig_Msisdn[] = "X-Vig-Msisdn";
533 dissect_rtspmessage(tvbuff_t *tvb, int offset, packet_info *pinfo,
536 proto_tree *rtsp_tree = NULL;
537 proto_tree *sub_tree = NULL;
538 proto_item *ti = NULL;
541 const guchar *linep, *lineend;
543 int first_linelen, linelen;
546 gboolean is_request_or_reply;
547 gboolean body_requires_content_len;
548 gboolean saw_req_resp_or_header;
550 rtsp_type_t rtsp_type;
554 int reported_datalen;
557 e164_info_t e164_info;
558 gint rdt_feature_level = 0;
559 gchar *media_type_str_lower_case = NULL;
560 int semi_colon_offset;
562 gchar *frame_label = NULL;
563 gchar *session_id = NULL;
564 voip_packet_info_t *stat_info = NULL;
567 * Is this a request or response?
569 * Note that "tvb_find_line_end()" will return a value that
570 * is not longer than what's in the buffer, so the
571 * "tvb_get_ptr()" call won't throw an exception.
573 first_linelen = tvb_find_line_end(tvb, offset,
574 tvb_ensure_length_remaining(tvb, offset), &next_offset,
578 * Is the first line a request or response?
580 line = tvb_get_ptr(tvb, offset, first_linelen);
581 is_request_or_reply = is_rtsp_request_or_reply(line, first_linelen,
583 if (is_request_or_reply) {
585 * Yes, it's a request or response.
586 * Do header desegmentation if we've been told to,
587 * and do body desegmentation if we've been told to and
588 * we find a Content-Length header.
590 if (!req_resp_hdrs_do_reassembly(tvb, offset, pinfo,
591 rtsp_desegment_headers, rtsp_desegment_body)) {
593 * More data needed for desegmentation.
600 * RFC 2326 says that a content length must be specified
601 * in requests that have a body, although section 4.4 speaks
602 * of a server closing the connection indicating the end of
605 * We assume that an absent content length in a request means
606 * that we don't have a body, and that an absent content length
607 * in a reply means that the reply body runs to the end of
608 * the connection. If the first line is neither, we assume
609 * that whatever follows a blank line should be treated as a
610 * body; there's not much else we can do, as we're jumping
611 * into the message in the middle.
613 * XXX - if there was no Content-Length entity header, we should
614 * accumulate all data until the end of the connection.
615 * That'd require that the TCP dissector call subdissectors
616 * for all frames with FIN, even if they contain no data,
617 * which would require subdissectors to deal intelligently
618 * with empty segments.
620 if (rtsp_type == RTSP_REQUEST)
621 body_requires_content_len = TRUE;
623 body_requires_content_len = FALSE;
625 line = tvb_get_ptr(tvb, offset, first_linelen);
626 if (is_request_or_reply) {
627 if ( rtsp_type == RTSP_REPLY ) {
628 frame_label = ep_strdup_printf("Reply: %s", format_text(line, first_linelen));
631 frame_label = ep_strdup(format_text(line, first_linelen));
635 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTSP");
636 if (check_col(pinfo->cinfo, COL_INFO)) {
638 * Put the first line from the buffer into the summary
639 * if it's an RTSP request or reply (but leave out the
641 * Otherwise, just call it a continuation.
643 * Note that "tvb_find_line_end()" will return a value that
644 * is not longer than what's in the buffer, so the
645 * "tvb_get_ptr()" call won't throw an exception.
647 if (is_request_or_reply)
648 if ( rtsp_type == RTSP_REPLY ) {
649 col_set_str(pinfo->cinfo, COL_INFO, "Reply: ");
650 col_append_str(pinfo->cinfo, COL_INFO,
651 format_text(line, first_linelen));
654 col_add_str(pinfo->cinfo, COL_INFO,
655 format_text(line, first_linelen));
659 col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
663 orig_offset = offset;
665 ti = proto_tree_add_item(tree, proto_rtsp, tvb, offset, -1,
667 rtsp_tree = proto_item_add_subtree(ti, ett_rtsp);
671 * We haven't yet seen a Content-Length header.
676 * Process the packet data, a line at a time.
678 saw_req_resp_or_header = FALSE; /* haven't seen anything yet */
679 while (tvb_reported_length_remaining(tvb, offset) != 0) {
681 * We haven't yet concluded that this is a header.
686 * Find the end of the line.
688 linelen = tvb_find_line_end(tvb, offset,
689 tvb_ensure_length_remaining(tvb, offset), &next_offset,
693 line_end_offset = offset + linelen;
695 * colon_offset may be -1
697 colon_offset = tvb_find_guint8(tvb, offset, linelen, ':');
701 * Get a buffer that refers to the line.
703 line = tvb_get_ptr(tvb, offset, linelen);
704 lineend = line + linelen;
707 * OK, does it look like an RTSP request or response?
709 is_request_or_reply = is_rtsp_request_or_reply(line, linelen, &rtsp_type);
710 if (is_request_or_reply)
714 * No. Does it look like a blank line (as would appear
715 * at the end of an RTSP request)?
718 goto is_rtsp; /* Yes. */
721 * No. Does it look like a header?
724 while (linep < lineend) {
728 * This must be a CHAR to be part of a token; that
729 * means it must be ASCII.
732 break; /* not ASCII, thus not a CHAR */
735 * This mustn't be a CTL to be part of a token.
737 * XXX - what about leading LWS on continuation
741 break; /* CTL, not part of a header */
762 * It's a tspecial, so it's not
763 * part of a token, so it's not
764 * a field name for the beginning
771 * This ends the token; we consider
772 * this to be a header.
780 * LWS (RFC-2616, 4.2); continue the previous
788 * We haven't seen the colon, but everything else looks
789 * OK for a header line.
791 * If we've already seen an RTSP request or response
792 * line, or a header line, and we're at the end of
793 * the tvbuff, we assume this is an incomplete header
794 * line. (We quit this loop after seeing a blank line,
795 * so if we've seen a request or response line, or a
796 * header line, this is probably more of the request
797 * or response we're presumably seeing. There is some
798 * risk of false positives, but the same applies for
799 * full request or response lines or header lines,
800 * although that's less likely.)
802 * We throw an exception in that case, by checking for
803 * the existence of the next byte after the last one
804 * in the line. If it exists, "tvb_ensure_bytes_exist()"
805 * throws no exception, and we fall through to the
806 * "not RTSP" case. If it doesn't exist,
807 * "tvb_ensure_bytes_exist()" will throw the appropriate
810 if (saw_req_resp_or_header)
811 tvb_ensure_bytes_exist(tvb, offset, linelen + 1);
815 * We don't consider this part of an RTSP request or
816 * reply, so we don't display it.
826 * This is a blank line, which means that
827 * whatever follows it isn't part of this
830 proto_tree_add_text(rtsp_tree, tvb, offset,
831 next_offset - offset, "%s",
832 tvb_format_text(tvb, offset, next_offset - offset));
833 offset = next_offset;
838 * Not a blank line - either a request, a reply, or a header
841 saw_req_resp_or_header = TRUE;
847 process_rtsp_request(tvb, offset, line, linelen, next_offset, rtsp_tree);
851 process_rtsp_reply(tvb, offset, line, linelen, next_offset, rtsp_tree);
854 case RTSP_NOT_FIRST_LINE:
855 /* Drop through, it may well be a header line */
862 /* We know that colon_offset must be set */
864 /* Skip whitespace after the colon. */
865 value_offset = colon_offset + 1;
866 while ((value_offset < line_end_offset) &&
867 ((c = tvb_get_guint8(tvb, value_offset)) == ' ' || c == '\t'))
871 value_len = line_end_offset - value_offset;
874 * Process some headers specially.
876 #define HDR_MATCHES(header) \
877 ( (size_t)linelen > STRLEN_CONST(header) && \
878 g_ascii_strncasecmp(line, (header), STRLEN_CONST(header)) == 0)
880 if (HDR_MATCHES(rtsp_transport))
882 proto_tree_add_string(rtsp_tree, hf_rtsp_transport, tvb,
884 tvb_format_text(tvb, value_offset,
888 * Based on the port numbers specified
889 * in the Transport: header, set up
890 * a conversation that will be dissected
891 * with the appropriate dissector.
893 rtsp_create_conversation(pinfo, line, linelen, rdt_feature_level);
894 } else if (HDR_MATCHES(rtsp_content_type))
896 proto_tree_add_string(rtsp_tree, hf_rtsp_content_type,
897 tvb, offset, linelen,
898 tvb_format_text(tvb, value_offset,
901 offset = offset + STRLEN_CONST(rtsp_content_type);
903 offset = tvb_skip_wsp(tvb, offset, value_len);
904 semi_colon_offset = tvb_find_guint8(tvb, value_offset, value_len, ';');
905 if ( semi_colon_offset != -1) {
906 /* m-parameter present */
907 par_end_offset = tvb_skip_wsp_return(tvb, semi_colon_offset-1);
908 value_len = par_end_offset - offset;
911 media_type_str_lower_case = ascii_strdown_inplace(
912 (gchar *)tvb_get_ephemeral_string(tvb, offset, value_len));
914 } else if (HDR_MATCHES(rtsp_content_length))
916 proto_tree_add_uint(rtsp_tree, hf_rtsp_content_length,
917 tvb, offset, linelen,
918 atoi(tvb_format_text(tvb, value_offset,
922 * Only the amount specified by the
923 * Content-Length: header should be treated
926 content_length = rtsp_get_content_length(line, linelen);
928 } else if (HDR_MATCHES(rtsp_Session))
930 session_id = tvb_format_text(tvb, value_offset, value_len);
931 /* Put the value into the protocol tree */
932 proto_tree_add_string(rtsp_tree, hf_rtsp_session, tvb,
936 } else if (HDR_MATCHES(rtsp_X_Vig_Msisdn)) {
938 * Extract the X_Vig_Msisdn string
940 if (colon_offset != -1)
942 /* Put the value into the protocol tree */
943 ti = proto_tree_add_string(rtsp_tree, hf_rtsp_X_Vig_Msisdn,tvb,
945 tvb_format_text(tvb, value_offset, value_len));
946 sub_tree = proto_item_add_subtree(ti, ett_rtsp_method);
948 e164_info.e164_number_type = CALLING_PARTY_NUMBER;
949 e164_info.nature_of_address = 0;
951 e164_info.E164_number_str = tvb_get_ephemeral_string(tvb, value_offset,
953 e164_info.E164_number_length = value_len;
954 dissect_e164_number(tvb, sub_tree, value_offset,
955 value_len, e164_info);
957 } else if (HDR_MATCHES(rtsp_rdt_feature_level))
959 rdt_feature_level = atoi(tvb_format_text(tvb, value_offset,
961 proto_tree_add_uint(rtsp_tree, hf_rtsp_rdtfeaturelevel,
962 tvb, offset, linelen,
963 atoi(tvb_format_text(tvb, value_offset,
968 /* Default case for headers. Show line as text */
969 proto_tree_add_text(rtsp_tree, tvb, offset,
970 next_offset - offset, "%s",
971 tvb_format_text(tvb, offset, next_offset - offset));
974 else if (rtsp_type == RTSP_NOT_FIRST_LINE)
976 /* Catch-all for all other lines... Show line as text.
977 TODO: should these be shown as errors? */
978 proto_tree_add_text(rtsp_tree, tvb, offset,
979 next_offset - offset, "%s",
980 tvb_format_text(tvb, offset, next_offset - offset));
983 offset = next_offset;
987 stat_info = ep_alloc0(sizeof(voip_packet_info_t));
988 stat_info->protocol_name = ep_strdup("RTSP");
989 stat_info->call_id = session_id;
990 stat_info->frame_label = frame_label;
991 stat_info->call_state = VOIP_CALL_SETUP;
992 stat_info->call_active_state = VOIP_NO_STATE;
993 stat_info->frame_comment = frame_label;
994 tap_queue_packet(voip_tap, pinfo, stat_info);
998 * Have now read all of the lines of this message.
1000 * If a content length was supplied, the amount of data to be
1001 * processed as RTSP payload is the minimum of the content
1002 * length and the amount of data remaining in the frame.
1004 * If no content length was supplied (or if a bad content length
1005 * was supplied), the amount of data to be processed is the amount
1006 * of data remaining in the frame.
1008 datalen = tvb_length_remaining(tvb, offset);
1009 reported_datalen = tvb_reported_length_remaining(tvb, offset);
1010 if (content_length != -1) {
1012 * Content length specified; display only that amount
1015 if (datalen > content_length)
1016 datalen = content_length;
1019 * XXX - limit the reported length in the tvbuff we'll
1020 * hand to a subdissector to be no greater than the
1023 * We really need both unreassembled and "how long it'd
1024 * be if it were reassembled" lengths for tvbuffs, so
1025 * that we throw the appropriate exceptions for
1026 * "not enough data captured" (running past the length),
1027 * "packet needed reassembly" (within the length but
1028 * running past the unreassembled length), and
1029 * "packet is malformed" (running past the reassembled
1032 if (reported_datalen > content_length)
1033 reported_datalen = content_length;
1036 * No content length specified; if this message doesn't
1037 * have a body if no content length is specified, process
1038 * nothing as payload.
1040 if (body_requires_content_len)
1046 * There's stuff left over; process it.
1051 * Now create a tvbuff for the Content-type stuff and
1054 * The amount of data to be processed that's
1055 * available in the tvbuff is "datalen", which
1056 * is the minimum of the amount of data left in
1057 * the tvbuff and any specified content length.
1059 * The amount of data to be processed that's in
1060 * this frame, regardless of whether it was
1061 * captured or not, is "reported_datalen",
1062 * which, if no content length was specified,
1063 * is -1, i.e. "to the end of the frame.
1065 new_tvb = tvb_new_subset(tvb, offset, datalen,
1068 if (media_type_str_lower_case &&
1069 dissector_try_string(media_type_dissector_table,
1070 media_type_str_lower_case,
1071 new_tvb, pinfo, rtsp_tree)){
1075 * Fix up the top-level item so that it doesn't
1076 * include the SDP stuff.
1079 proto_item_set_len(ti, offset);
1081 if (tvb_get_guint8(tvb, offset) == RTSP_FRAMEHDR) {
1083 * This is interleaved stuff; don't
1084 * treat it as raw data - set "datalen"
1085 * to 0, so we won't skip the offset
1086 * past it, which will cause our
1087 * caller to process that stuff itself.
1091 proto_tree_add_text(rtsp_tree, tvb, offset,
1092 datalen, "Data (%d bytes)",
1098 * We've processed "datalen" bytes worth of data
1099 * (which may be no data at all); advance the
1100 * offset past whatever data we've processed.
1104 return offset - orig_offset;
1108 process_rtsp_request(tvbuff_t *tvb, int offset, const guchar *data,
1109 size_t linelen, size_t next_line_offset, proto_tree *tree)
1111 proto_tree *sub_tree = NULL;
1112 proto_item *ti = NULL;
1113 const guchar *lineend = data + linelen;
1116 const guchar *url_start;
1119 /* Request Methods */
1120 for (ii = 0; ii < RTSP_NMETHODS; ii++) {
1121 size_t len = strlen(rtsp_methods[ii]);
1122 if (linelen >= len &&
1123 g_ascii_strncasecmp(rtsp_methods[ii], data, len) == 0 &&
1124 (len == linelen || isspace(data[len])))
1127 if (ii == RTSP_NMETHODS) {
1129 * We got here because "is_rtsp_request_or_reply()" returned
1130 * RTSP_REQUEST, so we know one of the request methods
1131 * matched, so we "can't get here".
1133 DISSECTOR_ASSERT_NOT_REACHED();
1136 /* Add a tree for this request */
1137 ti = proto_tree_add_string(tree, hf_rtsp_request, tvb, offset,
1138 (gint) (next_line_offset - offset),
1139 tvb_format_text(tvb, offset, (gint) (next_line_offset - offset)));
1140 sub_tree = proto_item_add_subtree(ti, ett_rtsp_method);
1143 /* Add method name to tree */
1144 proto_tree_add_string(sub_tree, hf_rtsp_method, tvb, offset,
1145 (gint) strlen(rtsp_methods[ii]), rtsp_methods[ii]);
1149 /* Skip method name again */
1150 while (url < lineend && !isspace(*url))
1153 while (url < lineend && isspace(*url))
1155 /* URL starts here */
1157 /* Scan to end of URL */
1158 while (url < lineend && !isspace(*url))
1160 /* Create a URL-sized buffer and copy contents */
1161 tmp_url = ep_strndup(url_start, url - url_start);
1163 /* Add URL to tree */
1164 proto_tree_add_string(sub_tree, hf_rtsp_url, tvb,
1165 offset + (gint) (url_start - data), (gint) (url - url_start), tmp_url);
1168 /* Read first line of a reply message */
1170 process_rtsp_reply(tvbuff_t *tvb, int offset, const guchar *data,
1171 size_t linelen, size_t next_line_offset, proto_tree *tree)
1173 proto_tree *sub_tree = NULL;
1174 proto_item *ti = NULL;
1175 const guchar *lineend = data + linelen;
1176 const guchar *status = data;
1177 const guchar *status_start;
1178 unsigned int status_i;
1180 /* Add a tree for this request */
1181 ti = proto_tree_add_string(tree, hf_rtsp_response, tvb, offset,
1182 (gint) (next_line_offset - offset),
1183 tvb_format_text(tvb, offset, (gint) (next_line_offset - offset)));
1184 sub_tree = proto_item_add_subtree(ti, ett_rtsp_method);
1189 /* Skip protocol/version */
1190 while (status < lineend && !isspace(*status))
1193 while (status < lineend && isspace(*status))
1196 /* Actual code number now */
1197 status_start = status;
1199 while (status < lineend && isdigit(*status))
1200 status_i = status_i * 10 + *status++ - '0';
1202 /* Add field to tree */
1203 proto_tree_add_uint(sub_tree, hf_rtsp_status, tvb,
1204 offset + (gint) (status_start - data),
1205 (gint) (status - status_start), status_i);
1209 dissect_rtsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1214 while (tvb_reported_length_remaining(tvb, offset) != 0) {
1215 len = (tvb_get_guint8(tvb, offset) == RTSP_FRAMEHDR)
1216 ? dissect_rtspinterleaved(tvb, offset, pinfo, tree)
1217 : dissect_rtspmessage(tvb, offset, pinfo, tree);
1223 * OK, we've set the Protocol and Info columns for the
1224 * first RTSP message; make the columns non-writable,
1225 * so that we don't change it for subsequent RTSP messages.
1227 col_set_writable(pinfo->cinfo, FALSE);
1232 proto_register_rtsp(void)
1234 static gint *ett[] = {
1239 static hf_register_info hf[] = {
1241 { "Request", "rtsp.request", FT_STRING, BASE_NONE, NULL, 0,
1243 { &hf_rtsp_response,
1244 { "Response", "rtsp.response", FT_STRING, BASE_NONE, NULL, 0,
1247 { "Method", "rtsp.method", FT_STRING, BASE_NONE, NULL, 0,
1249 { &hf_rtsp_content_type,
1250 { "Content-type", "rtsp.content-type", FT_STRING, BASE_NONE, NULL, 0,
1252 { &hf_rtsp_content_length,
1253 { "Content-length", "rtsp.content-length", FT_UINT32, BASE_DEC, NULL, 0,
1256 { "URL", "rtsp.url", FT_STRING, BASE_NONE, NULL, 0,
1259 { "Status", "rtsp.status", FT_UINT32, BASE_DEC, NULL, 0,
1262 { "Session", "rtsp.session", FT_STRING, BASE_NONE, NULL, 0,
1264 { &hf_rtsp_transport,
1265 { "Transport", "rtsp.transport", FT_STRING, BASE_NONE, NULL, 0,
1267 { &hf_rtsp_rdtfeaturelevel,
1268 { "RDTFeatureLevel", "rtsp.rdt-feature-level", FT_UINT32, BASE_DEC, NULL, 0,
1270 { &hf_rtsp_X_Vig_Msisdn,
1271 { "X-Vig-Msisdn", "X_Vig_Msisdn", FT_STRING, BASE_NONE, NULL, 0,
1276 module_t *rtsp_module;
1278 proto_rtsp = proto_register_protocol("Real Time Streaming Protocol",
1281 proto_register_field_array(proto_rtsp, hf, array_length(hf));
1282 proto_register_subtree_array(ett, array_length(ett));
1284 /* Make this dissector findable by name */
1285 register_dissector("rtsp", dissect_rtsp, proto_rtsp);
1287 /* Register our configuration options, particularly our ports */
1289 rtsp_module = prefs_register_protocol(proto_rtsp, proto_reg_handoff_rtsp);
1290 prefs_register_uint_preference(rtsp_module, "tcp.port",
1292 "Set the TCP port for RTSP messages",
1293 10, &global_rtsp_tcp_port);
1294 prefs_register_uint_preference(rtsp_module, "tcp.alternate_port",
1295 "Alternate RTSP TCP Port",
1296 "Set the alternate TCP port for RTSP messages",
1297 10, &global_rtsp_tcp_alternate_port);
1298 prefs_register_bool_preference(rtsp_module, "desegment_headers",
1299 "Reassemble RTSP headers spanning multiple TCP segments",
1300 "Whether the RTSP dissector should reassemble headers "
1301 "of a request spanning multiple TCP segments. "
1302 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
1303 &rtsp_desegment_headers);
1304 prefs_register_bool_preference(rtsp_module, "desegment_body",
1305 "Trust the \"Content-length:\" header and\ndesegment RTSP "
1306 "bodies\nspanning multiple TCP segments",
1307 "Whether the RTSP dissector should use the "
1308 "\"Content-length:\" value to desegment the body "
1309 "of a request spanning multiple TCP segments",
1310 &rtsp_desegment_body);
1315 proto_reg_handoff_rtsp(void)
1317 static dissector_handle_t rtsp_handle;
1318 static gboolean rtsp_prefs_initialized = FALSE;
1320 * Variables to allow for proper deletion of dissector registration when
1321 * the user changes port from the gui.
1323 static guint saved_rtsp_tcp_port;
1324 static guint saved_rtsp_tcp_alternate_port;
1326 if (!rtsp_prefs_initialized) {
1327 rtsp_handle = find_dissector("rtsp");
1328 rtp_handle = find_dissector("rtp");
1329 rtcp_handle = find_dissector("rtcp");
1330 rdt_handle = find_dissector("rdt");
1331 media_type_dissector_table = find_dissector_table("media_type");
1332 voip_tap = find_tap_id("voip");
1333 rtsp_prefs_initialized = TRUE;
1336 dissector_delete("tcp.port", saved_rtsp_tcp_port, rtsp_handle);
1337 dissector_delete("tcp.port", saved_rtsp_tcp_alternate_port, rtsp_handle);
1339 /* Set our port number for future use */
1340 dissector_add("tcp.port", global_rtsp_tcp_port, rtsp_handle);
1341 dissector_add("tcp.port", global_rtsp_tcp_alternate_port, rtsp_handle);
1343 saved_rtsp_tcp_port = global_rtsp_tcp_port;
1344 saved_rtsp_tcp_alternate_port = global_rtsp_tcp_alternate_port;