Add a komment about the format of the MSRP path parameter.
[obnox/wireshark/wip.git] / epan / dissectors / packet-sdp.c
1 /* packet-sdp.c
2  * Routines for SDP packet disassembly (RFC 2327)
3  *
4  * Jason Lango <jal@netapp.com>
5  * Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
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.
17  *
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.
22  *
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.
26  * Ref http://www.ietf.org/rfc/rfc4566.txt?number=4566
27  */
28
29 #include "config.h"
30
31 #include <stdlib.h>
32 #include <string.h>
33 #include <ctype.h>
34
35 #ifdef HAVE_SYS_TYPES_H
36 #include <sys/types.h>
37 #endif
38 #ifdef HAVE_SYS_SOCKET_H
39 #include <sys/socket.h>
40 #endif
41 #ifdef HAVE_NETINET_IN_H
42 # include <netinet/in.h>
43 #endif
44 #ifdef HAVE_ARPA_INET_H
45 #include <arpa/inet.h>
46 #endif
47
48 #ifdef HAVE_WINSOCK2_H
49 #include <winsock2.h>           /* needed to define AF_ values on Windows */
50 #endif
51
52 #ifdef NEED_INET_V6DEFS_H
53 # include "wsutil/inet_v6defs.h"
54 #endif
55
56 #include <glib.h>
57 #include <epan/packet.h>
58 #include <epan/strutil.h>
59 #include <epan/emem.h>
60 #include <epan/base64.h>
61 #include <epan/asn1.h>
62
63 #include <epan/tap.h>
64 #include "packet-sdp.h"
65
66 #include "packet-rtp.h"
67 #include <epan/rtp_pt.h>
68
69 #include <epan/prefs.h>
70 #include <epan/expert.h>
71
72 #include "packet-rtcp.h"
73 #include "packet-t38.h"
74 #include "packet-msrp.h"
75 #include "packet-per.h"
76 #include "packet-h245.h"
77 #include "packet-h264.h"
78 #include "packet-mp4ves.h"
79
80 static dissector_handle_t rtp_handle    = NULL;
81 static dissector_handle_t rtcp_handle   = NULL;
82 static dissector_handle_t t38_handle    = NULL;
83 static dissector_handle_t msrp_handle   = NULL;
84 static dissector_handle_t h264_handle   = NULL;
85 static dissector_handle_t mp4ves_handle = NULL;
86
87 static int sdp_tap = -1;
88
89 static int proto_sdp = -1;
90
91 /* preference globals */
92 static gboolean global_sdp_establish_conversation = TRUE;
93
94 /* Top level fields */
95 static int hf_protocol_version = -1;
96 static int hf_owner = -1;
97 static int hf_session_name = -1;
98 static int hf_session_info = -1;
99 static int hf_uri = -1;
100 static int hf_email = -1;
101 static int hf_phone = -1;
102 static int hf_connection_info = -1;
103 static int hf_bandwidth = -1;
104 static int hf_timezone = -1;
105 static int hf_encryption_key = -1;
106 static int hf_session_attribute = -1;
107 static int hf_media_attribute = -1;
108 static int hf_time = -1;
109 static int hf_repeat_time = -1;
110 static int hf_media = -1;
111 static int hf_media_title = -1;
112 static int hf_unknown = -1;
113 static int hf_invalid = -1;
114 static int hf_ipbcp_version = -1;
115 static int hf_ipbcp_type = -1;
116
117 /* hf_owner subfields*/
118 static int hf_owner_username = -1;
119 static int hf_owner_sessionid = -1;
120 static int hf_owner_version = -1;
121 static int hf_owner_network_type = -1;
122 static int hf_owner_address_type = -1;
123 static int hf_owner_address = -1;
124
125 /* hf_connection_info subfields */
126 static int hf_connection_info_network_type = -1;
127 static int hf_connection_info_address_type = -1;
128 static int hf_connection_info_connection_address = -1;
129 static int hf_connection_info_ttl = -1;
130 static int hf_connection_info_num_addr = -1;
131
132 /* hf_bandwidth subfields */
133 static int hf_bandwidth_modifier = -1;
134 static int hf_bandwidth_value = -1;
135
136 /* hf_time subfields */
137 static int hf_time_start = -1;
138 static int hf_time_stop = -1;
139
140 /* hf_repeat_time subfield */
141 static int hf_repeat_time_interval = -1;
142 static int hf_repeat_time_duration = -1;
143 static int hf_repeat_time_offset = -1;
144
145 /* hf_timezone subfields */
146 static int hf_timezone_time = -1;
147 static int hf_timezone_offset = -1;
148
149 /* hf_encryption_key subfields */
150 static int hf_encryption_key_type = -1;
151 static int hf_encryption_key_data = -1;
152
153 /* hf_session_attribute subfields */
154 static int hf_session_attribute_field = -1;
155 static int hf_session_attribute_value = -1;
156
157 /* hf_media subfields */
158 static int hf_media_media = -1;
159 static int hf_media_port = -1;
160 static int hf_media_portcount = -1;
161 static int hf_media_proto = -1;
162 static int hf_media_format = -1;
163
164 /* hf_session_attribute subfields */
165 static int hf_media_attribute_field = -1;
166 static int hf_media_attribute_value = -1;
167 static int hf_media_encoding_name = -1;
168 static int hf_media_sample_rate = -1;
169 static int hf_media_format_specific_parameter = -1;
170 static int hf_sdp_fmtp_mpeg4_profile_level_id = -1;
171 static int hf_sdp_fmtp_h263_profile = -1;
172 static int hf_sdp_fmtp_h263_level = -1;
173 static int hf_sdp_h264_packetization_mode = -1;
174 static int hf_sdp_h264_sprop_parameter_sets = -1;
175 static int hf_SDPh223LogicalChannelParameters = -1;
176
177 /* hf_session_attribute hf_media_attribute subfields */
178 static int hf_key_mgmt_att_value = -1;
179 static int hf_key_mgmt_prtcl_id = -1;
180 static int hf_key_mgmt_data = -1;
181
182 /* trees */
183 static int ett_sdp = -1;
184 static int ett_sdp_owner = -1;
185 static int ett_sdp_connection_info = -1;
186 static int ett_sdp_bandwidth = -1;
187 static int ett_sdp_time = -1;
188 static int ett_sdp_repeat_time = -1;
189 static int ett_sdp_timezone = -1;
190 static int ett_sdp_encryption_key = -1;
191 static int ett_sdp_session_attribute = -1;
192 static int ett_sdp_media = -1;
193 static int ett_sdp_media_attribute = -1;
194 static int ett_sdp_fmtp = -1;
195 static int ett_sdp_key_mgmt = -1;
196
197
198 #define SDP_MAX_RTP_CHANNELS 4
199 #define SDP_MAX_RTP_PAYLOAD_TYPES 20
200 #define SDP_NO_OF_PT 128
201 typedef struct {
202   gint32 pt[SDP_MAX_RTP_PAYLOAD_TYPES];
203   gint8 pt_count;
204   GHashTable *rtp_dyn_payload;
205 } transport_media_pt_t;
206
207 typedef struct {
208   char *connection_address;
209   char *connection_type;
210   char *media_type;
211   char *encoding_name[SDP_NO_OF_PT];
212   int   sample_rate[SDP_NO_OF_PT];
213   char *media_port[SDP_MAX_RTP_CHANNELS];
214   char *media_proto[SDP_MAX_RTP_CHANNELS];
215   transport_media_pt_t media[SDP_MAX_RTP_CHANNELS];
216   gint8 media_count;
217 } transport_info_t;
218
219
220 /* MSRP transport info (as set while parsing path attribute) */
221 static gboolean msrp_transport_address_set = FALSE;
222 static guint32  msrp_ipaddr[4];
223 static guint16  msrp_port_number;
224
225 /* key-mgmt dissector
226  * IANA registry:
227  * http://www.iana.org/assignments/sdp-parameters
228  */
229 static dissector_table_t key_mgmt_dissector_table;
230
231
232 /* Protocol registration */
233 void proto_register_sdp(void);
234 void proto_reg_handoff_sdp(void);
235
236
237 /* static functions */
238
239 static void call_sdp_subdissector(tvbuff_t *tvb, packet_info *pinfo, int hf, proto_tree* ti, int lenght,
240                                   transport_info_t *transport_info);
241
242 /* Subdissector functions */
243 static void dissect_sdp_owner(tvbuff_t *tvb, proto_item* ti);
244 static void dissect_sdp_connection_info(tvbuff_t *tvb, proto_item* ti,
245                                         transport_info_t *transport_info);
246 static void dissect_sdp_bandwidth(tvbuff_t *tvb, proto_item *ti);
247 static void dissect_sdp_time(tvbuff_t *tvb, proto_item* ti);
248 static void dissect_sdp_repeat_time(tvbuff_t *tvb, proto_item* ti);
249 static void dissect_sdp_timezone(tvbuff_t *tvb, proto_item* ti);
250 static void dissect_sdp_encryption_key(tvbuff_t *tvb, proto_item * ti);
251 static void dissect_sdp_session_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_item *ti);
252 static void dissect_sdp_media(tvbuff_t *tvb, proto_item *ti,
253                               transport_info_t *transport_info);
254 static void dissect_sdp_media_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_item *ti, int length,transport_info_t *transport_info);
255
256 static void free_encoding_name_str (void *ptr)
257 {
258   encoding_name_and_rate_t *encoding_name_and_rate = (encoding_name_and_rate_t *)ptr;
259
260   if (encoding_name_and_rate->encoding_name) {
261     g_free(encoding_name_and_rate->encoding_name);
262   }
263 }
264
265 static void
266 dissect_sdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
267 {
268   proto_tree  *sdp_tree;
269   proto_item  *ti, *sub_ti;
270   gint        offset = 0;
271   gint        next_offset;
272   int         linelen;
273   gboolean    in_media_description;
274   guchar      type;
275   guchar      delim;
276   int         datalen;
277   int         tokenoffset;
278   int         hf = -1;
279   char        *string;
280
281   address     src_addr;
282
283   transport_info_t transport_info;
284
285   guint32     port=0;
286   gboolean    is_rtp=FALSE;
287   gboolean    is_srtp=FALSE;
288   gboolean    is_t38=FALSE;
289   gboolean    is_msrp=FALSE;
290   gboolean    set_rtp=FALSE;
291   gboolean    is_ipv4_addr=FALSE;
292   gboolean    is_ipv6_addr=FALSE;
293   gboolean    is_video=FALSE;
294   guint32     ipaddr[4];
295   gint        n,i;
296   sdp_packet_info *sdp_pi;
297   gchar       *unknown_encoding = ep_strdup("Unknown");
298
299   /* Initialise packet info for passing to tap */
300   sdp_pi = ep_alloc(sizeof(sdp_packet_info));
301   sdp_pi->summary_str[0] = '\0';
302
303   /* Initialise RTP channel info */
304   transport_info.connection_address=NULL;
305   transport_info.connection_type=NULL;
306   transport_info.media_type=NULL;
307   for (n=0; n < SDP_NO_OF_PT; n++){
308     transport_info.encoding_name[n]=unknown_encoding;
309     transport_info.sample_rate[n] = 0;
310   }
311   for (n=0; n < SDP_MAX_RTP_CHANNELS; n++)
312   {
313     transport_info.media_port[n]=NULL;
314     transport_info.media_proto[n]=NULL;
315     transport_info.media[n].pt_count = 0;
316     transport_info.media[n].rtp_dyn_payload =
317         g_hash_table_new_full( g_int_hash, g_int_equal, g_free, free_encoding_name_str);
318   }
319   transport_info.media_count = 0;
320
321   /*
322    * As RFC 2327 says, "SDP is purely a format for session
323    * description - it does not incorporate a transport protocol,
324    * and is intended to use different transport protocols as
325    * appropriate including the Session Announcement Protocol,
326    * Session Initiation Protocol, Real-Time Streaming Protocol,
327    * electronic mail using the MIME extensions, and the
328    * Hypertext Transport Protocol."
329    *
330    * We therefore don't set the protocol or info columns;
331    * instead, we append to them, so that we don't erase
332    * what the protocol inside which the SDP stuff resides
333    * put there.
334    */
335   col_append_str(pinfo->cinfo, COL_PROTOCOL, "/SDP");
336
337   /* XXX: Needs description. */
338   col_append_str(pinfo->cinfo, COL_INFO, ", with session description");
339
340   ti = proto_tree_add_item(tree, proto_sdp, tvb, offset, -1, FALSE);
341   sdp_tree = proto_item_add_subtree(ti, ett_sdp);
342
343   /*
344    * Show the SDP message a line at a time.
345    */
346   in_media_description = FALSE;
347
348   while (tvb_reported_length_remaining(tvb, offset) > 0) {
349     /*
350      * Find the end of the line.
351      */
352     linelen = tvb_find_line_end_unquoted(tvb, offset, -1, &next_offset);
353
354
355
356     /*
357      * Line must contain at least e.g. "v=".
358      */
359     if (linelen < 2)
360       break;
361
362     type = tvb_get_guint8(tvb,offset);
363     delim = tvb_get_guint8(tvb,offset + 1);
364     if (delim != '=') {
365       proto_item *ti2 = proto_tree_add_item(sdp_tree, hf_invalid, tvb, offset, linelen, FALSE);
366       expert_add_info_format(pinfo, ti2, PI_MALFORMED, PI_NOTE,
367                              "Invalid SDP line (no '=' delimiter)");
368       offset = next_offset;
369       continue;
370     }
371
372     /*
373      * Attributes.
374      */
375     switch (type) {
376     case 'v':
377       hf = hf_protocol_version;
378       break;
379     case 'o':
380       hf = hf_owner;
381       break;
382     case 's':
383       hf = hf_session_name;
384       break;
385     case 'i':
386       if (in_media_description) {
387         hf = hf_media_title;
388       }
389       else{
390         hf = hf_session_info;
391       }
392       break;
393     case 'u':
394       hf = hf_uri;
395       break;
396     case 'e':
397       hf = hf_email;
398       break;
399     case 'p':
400       hf = hf_phone;
401       break;
402     case 'c':
403       hf = hf_connection_info;
404       break;
405     case 'b':
406       hf = hf_bandwidth;
407       break;
408     case 't':
409       hf = hf_time;
410       break;
411     case 'r':
412       hf = hf_repeat_time;
413       break;
414     case 'm':
415       hf = hf_media;
416       in_media_description = TRUE;
417       break;
418     case 'k':
419       hf = hf_encryption_key;
420       break;
421     case 'a':
422       if (in_media_description) {
423         hf = hf_media_attribute;
424       }
425       else{
426         hf = hf_session_attribute;
427       }
428       break;
429     case 'z':
430       hf = hf_timezone;
431       break;
432     default:
433       hf = hf_unknown;
434       break;
435     }
436     tokenoffset = 2;
437     if (hf == hf_unknown)
438       tokenoffset = 0;
439     string = (char*)tvb_get_ephemeral_string(tvb, offset + tokenoffset,
440                                              linelen - tokenoffset);
441     sub_ti = proto_tree_add_string(sdp_tree, hf, tvb, offset, linelen,
442                                    string);
443     call_sdp_subdissector(tvb_new_subset(tvb,offset+tokenoffset,
444                                          linelen-tokenoffset,
445                                          linelen-tokenoffset),
446                                          pinfo,
447                                          hf,sub_ti,linelen-tokenoffset,&transport_info),
448     offset = next_offset;
449   }
450
451
452   /* Now look, if we have strings collected.
453    * Try to convert ipv4 addresses and ports into binary format,
454    * so we can use them to detect rtp and rtcp streams.
455    * Don't forget to free the strings!
456    */
457
458   for (n = 0; n < transport_info.media_count; n++)
459   {
460     if(transport_info.media_port[n]!=NULL) {
461       port = atol(transport_info.media_port[n]);
462     }
463     if(transport_info.media_proto[n]!=NULL) {
464       /* Check if media protocol is RTP
465        * and stream decoding is enabled in preferences
466        */
467        if(global_sdp_establish_conversation){
468          /* Check if media protocol is RTP */
469          is_rtp = (strcmp(transport_info.media_proto[n],"RTP/AVP")==0);
470          /* Check if media protocol is SRTP */
471          is_srtp = (strcmp(transport_info.media_proto[n],"RTP/SAVP")==0);
472          /* Check if media protocol is T38 */
473          is_t38 = ( (strcmp(transport_info.media_proto[n],"UDPTL")==0) ||
474                     (strcmp(transport_info.media_proto[n],"udptl")==0) );
475          /* Check if media protocol is MSRP/TCP */
476          is_msrp = (strcmp(transport_info.media_proto[n],"msrp/tcp")==0);
477        }
478     }
479
480
481     if(transport_info.connection_address!=NULL) {
482       if(transport_info.connection_type!=NULL) {
483         if (strcmp(transport_info.connection_type,"IP4")==0) {
484           if(inet_pton(AF_INET,transport_info.connection_address, &ipaddr)==1 ) {
485             /* connection_address could be converted to a valid ipv4 address*/
486             is_ipv4_addr=TRUE;
487             src_addr.type=AT_IPv4;
488             src_addr.len=4;
489           }
490         }
491         else if (strcmp(transport_info.connection_type,"IP6")==0){
492           if (inet_pton(AF_INET6, transport_info.connection_address, &ipaddr)==1){
493             /* connection_address could be converted to a valid ipv6 address*/
494             is_ipv6_addr=TRUE;
495             src_addr.type=AT_IPv6;
496             src_addr.len=16;
497           }
498         }
499       }
500     }
501     if (strcmp(transport_info.media_type,"video")==0){
502       is_video = TRUE;
503     }
504     set_rtp = FALSE;
505     /* Add (s)rtp and (s)rtcp conversation, if available (overrides t38 if conversation already set) */
506     if((!pinfo->fd->flags.visited) && port!=0 && (is_rtp||is_srtp) && (is_ipv4_addr || is_ipv6_addr)){
507       src_addr.data=(guint8*)&ipaddr;
508       if(rtp_handle){
509         if (is_srtp) {
510           struct srtp_info *dummy_srtp_info = se_alloc0(sizeof(struct srtp_info));
511           srtp_add_address(pinfo, &src_addr, port, 0, "SDP", pinfo->fd->num, is_video,
512                            transport_info.media[n].rtp_dyn_payload, dummy_srtp_info);
513         } else {
514           rtp_add_address(pinfo, &src_addr, port, 0, "SDP", pinfo->fd->num, is_video,
515                           transport_info.media[n].rtp_dyn_payload);
516         }
517         set_rtp = TRUE;
518       }
519       if(rtcp_handle){
520         port++;
521         rtcp_add_address(pinfo, &src_addr, port, 0, "SDP", pinfo->fd->num);
522       }
523     }
524
525     /* Add t38 conversation, if available and only if no rtp */
526     if((!pinfo->fd->flags.visited) && port!=0 && !set_rtp && is_t38 && is_ipv4_addr){
527       src_addr.data=(guint8*)&ipaddr;
528       if(t38_handle){
529         t38_add_address(pinfo, &src_addr, port, 0, "SDP", pinfo->fd->num);
530       }
531     }
532
533     /* Add MSRP conversation.  Uses addresses discovered in attribute
534        rather than connection information of media session line */
535     if (is_msrp ){
536       if ((!pinfo->fd->flags.visited) && msrp_transport_address_set){
537         if(msrp_handle){
538           src_addr.type=AT_IPv4;
539           src_addr.len=4;
540           src_addr.data=(guint8*)&msrp_ipaddr;
541           msrp_add_address(pinfo, &src_addr, msrp_port_number, "SDP", pinfo->fd->num);
542         }
543       }
544     }
545
546     /* Create the RTP summary str for the Voip Call analysis */
547     for (i = 0; i < transport_info.media[n].pt_count; i++)
548     {
549       /* if the payload type is dynamic (96 to 127), check the hash table to add the desc in the SDP summary */
550       if ( (transport_info.media[n].pt[i] >=96) && (transport_info.media[n].pt[i] <=127) ) {
551         encoding_name_and_rate_t *encoding_name_and_rate_pt = g_hash_table_lookup(transport_info.media[n].rtp_dyn_payload, &transport_info.media[n].pt[i]);
552         if (encoding_name_and_rate_pt)
553           g_snprintf(sdp_pi->summary_str, 50, "%s %s", sdp_pi->summary_str, encoding_name_and_rate_pt->encoding_name);
554         else
555           g_snprintf(sdp_pi->summary_str, 50, "%s %d", sdp_pi->summary_str, transport_info.media[n].pt[i]);
556       } else
557         g_snprintf(sdp_pi->summary_str, 50, "%s %s", sdp_pi->summary_str, val_to_str(transport_info.media[n].pt[i], rtp_payload_type_short_vals, "%u"));
558     }
559
560     /* Free the hash table if we did't assigned it to a conv use it */
561     if (set_rtp == FALSE)
562       rtp_free_hash_dyn_payload(transport_info.media[n].rtp_dyn_payload);
563
564     /* Create the T38 summary str for the Voip Call analysis */
565     if (is_t38) g_snprintf(sdp_pi->summary_str, 50, "%s t38", sdp_pi->summary_str);
566   }
567
568   /* Free the remainded hash tables not used */
569   for (n = transport_info.media_count; n < SDP_MAX_RTP_CHANNELS; n++)
570   {
571     rtp_free_hash_dyn_payload(transport_info.media[n].rtp_dyn_payload);
572   }
573
574
575   datalen = tvb_length_remaining(tvb, offset);
576   if (datalen > 0) {
577     proto_tree_add_text(sdp_tree, tvb, offset, datalen, "Data (%d bytes)",
578                         datalen);
579   }
580
581   /* Report this packet to the tap */
582   tap_queue_packet(sdp_tap, pinfo, sdp_pi);
583 }
584
585 static void
586 call_sdp_subdissector(tvbuff_t *tvb, packet_info *pinfo, int hf, proto_tree* ti, int length,transport_info_t *transport_info){
587   if(hf == hf_owner){
588     dissect_sdp_owner(tvb,ti);
589   } else if ( hf == hf_connection_info) {
590     dissect_sdp_connection_info(tvb,ti,transport_info);
591   } else if ( hf == hf_bandwidth) {
592     dissect_sdp_bandwidth(tvb,ti);
593   } else if ( hf == hf_time) {
594     dissect_sdp_time(tvb,ti);
595   } else if ( hf == hf_repeat_time ){
596     dissect_sdp_repeat_time(tvb,ti);
597   } else if ( hf == hf_timezone ) {
598     dissect_sdp_timezone(tvb,ti);
599   } else if ( hf == hf_encryption_key ) {
600     dissect_sdp_encryption_key(tvb,ti);
601   } else if ( hf == hf_session_attribute ){
602     dissect_sdp_session_attribute(tvb,pinfo,ti);
603   } else if ( hf == hf_media ) {
604     dissect_sdp_media(tvb,ti,transport_info);
605   } else if ( hf == hf_media_attribute ){
606     dissect_sdp_media_attribute(tvb,pinfo,ti, length, transport_info);
607   }
608 }
609
610 static void
611 dissect_sdp_owner(tvbuff_t *tvb, proto_item *ti){
612   proto_tree *sdp_owner_tree;
613   gint offset,next_offset,tokenlen;
614
615   offset = 0;
616   next_offset = 0;
617   tokenlen = 0;
618
619   sdp_owner_tree = proto_item_add_subtree(ti,ett_sdp_owner);
620
621   /* Find the username */
622   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
623   if( next_offset == -1 )
624     return;
625   tokenlen = next_offset - offset;
626
627   proto_tree_add_item(sdp_owner_tree, hf_owner_username, tvb, offset, tokenlen,
628                       FALSE);
629   offset = next_offset  + 1;
630
631   /* Find the session id */
632   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
633   if( next_offset == -1 )
634     return;
635   tokenlen = next_offset - offset;
636
637   proto_tree_add_item(sdp_owner_tree, hf_owner_sessionid, tvb, offset,
638                       tokenlen, FALSE);
639   offset = next_offset + 1;
640
641   /* Find the version */
642   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
643   if( next_offset == -1 )
644     return;
645   tokenlen = next_offset - offset;
646
647   proto_tree_add_item(sdp_owner_tree, hf_owner_version, tvb, offset, tokenlen,
648                       FALSE);
649   offset = next_offset + 1;
650
651   /* Find the network type */
652   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
653   if( next_offset == -1 )
654     return;
655   tokenlen = next_offset - offset;
656
657   proto_tree_add_item(sdp_owner_tree, hf_owner_network_type, tvb, offset,
658                       tokenlen, FALSE);
659   offset = next_offset + 1;
660
661   /* Find the address type */
662   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
663   if( next_offset == -1 )
664     return;
665   tokenlen = next_offset - offset;
666
667   proto_tree_add_item(sdp_owner_tree, hf_owner_address_type, tvb, offset,
668                       tokenlen, FALSE);
669   offset = next_offset + 1;
670
671   /* Find the address */
672   proto_tree_add_item(sdp_owner_tree,hf_owner_address, tvb, offset, -1, FALSE);
673 }
674
675 /*
676  * XXX - this can leak memory if an exception is thrown after we've fetched
677  * a string.
678  */
679 static void
680 dissect_sdp_connection_info(tvbuff_t *tvb, proto_item* ti,
681                             transport_info_t *transport_info){
682   proto_tree *sdp_connection_info_tree;
683   gint offset,next_offset,tokenlen;
684
685   offset = 0;
686   next_offset = 0;
687   tokenlen = 0;
688
689   sdp_connection_info_tree = proto_item_add_subtree(ti,
690                                                     ett_sdp_connection_info);
691
692   /* Find the network type */
693   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
694   if( next_offset == -1 )
695     return;
696   tokenlen = next_offset - offset;
697
698   proto_tree_add_item(sdp_connection_info_tree,
699                       hf_connection_info_network_type, tvb, offset, tokenlen,
700                       FALSE);
701   offset = next_offset + 1;
702
703   /* Find the address type */
704   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
705   if( next_offset == -1 )
706     return;
707   tokenlen = next_offset - offset;
708   /* Save connection address type */
709   transport_info->connection_type = (char*)tvb_get_ephemeral_string(tvb, offset, tokenlen);
710
711
712   proto_tree_add_item(sdp_connection_info_tree,
713                       hf_connection_info_address_type, tvb, offset, tokenlen,
714                       FALSE);
715   offset = next_offset + 1;
716
717   /* Find the connection address */
718   /* XXX - what if there's a <number of addresses> value? */
719   next_offset = tvb_find_guint8(tvb,offset,-1,'/');
720   if( next_offset == -1){
721     tokenlen = -1; /* end of tvbuff */
722     /* Save connection address */
723     transport_info->connection_address =
724         (char*)tvb_get_ephemeral_string(tvb, offset, tvb_length_remaining(tvb, offset));
725   } else {
726     tokenlen = next_offset - offset;
727     /* Save connection address */
728     transport_info->connection_address = (char*)tvb_get_ephemeral_string(tvb, offset, tokenlen);
729   }
730
731   proto_tree_add_item(sdp_connection_info_tree,
732                       hf_connection_info_connection_address, tvb, offset,
733                       tokenlen, FALSE);
734   if(next_offset != -1){
735     offset = next_offset + 1;
736     next_offset = tvb_find_guint8(tvb,offset,-1,'/');
737     if( next_offset == -1){
738       tokenlen = -1; /* end of tvbuff */
739     } else {
740       tokenlen = next_offset - offset;
741     }
742     proto_tree_add_item(sdp_connection_info_tree,
743                         hf_connection_info_ttl, tvb, offset, tokenlen, FALSE);
744     if(next_offset != -1){
745       offset = next_offset + 1;
746       proto_tree_add_item(sdp_connection_info_tree,
747                           hf_connection_info_num_addr, tvb, offset, -1, FALSE);
748     }
749   }
750 }
751
752 static void
753 dissect_sdp_bandwidth(tvbuff_t *tvb, proto_item *ti){
754   proto_tree * sdp_bandwidth_tree;
755   gint offset, next_offset, tokenlen;
756   proto_item *item;
757   gboolean unit_is_kbs = FALSE;
758   gboolean unit_is_bps = FALSE;
759
760   offset = 0;
761   next_offset = 0;
762   tokenlen = 0;
763
764   sdp_bandwidth_tree = proto_item_add_subtree(ti,ett_sdp_bandwidth);
765
766   /* find the modifier */
767   next_offset = tvb_find_guint8(tvb,offset,-1,':');
768
769   if( next_offset == -1)
770     return;
771
772   tokenlen = next_offset - offset;
773
774   item = proto_tree_add_item(sdp_bandwidth_tree, hf_bandwidth_modifier, tvb, offset,
775                       tokenlen, FALSE);
776   if (tvb_strneql(tvb, offset, "CT", 2) == 0){
777     proto_item_append_text(item, " [Conference Total(total bandwidth of all RTP sessions)]");
778     unit_is_kbs = TRUE;
779   }else if (tvb_strneql(tvb, offset, "AS", 2) == 0){
780     proto_item_append_text(item, " [Application Specific (RTP session bandwidth)]");
781     unit_is_kbs = TRUE;
782   }else if (tvb_strneql(tvb, offset, "TIAS", 4) == 0){
783     proto_item_append_text(item, " [Transport Independent Application Specific maximum]");
784     unit_is_bps = TRUE;
785   }
786
787
788   offset = next_offset + 1;
789
790   item = proto_tree_add_item(sdp_bandwidth_tree, hf_bandwidth_value, tvb, offset, -1,
791                       FALSE);
792   if (unit_is_kbs == TRUE)
793     proto_item_append_text(item, " kb/s");
794   if (unit_is_bps == TRUE)
795     proto_item_append_text(item, " b/s");
796 }
797
798 static void dissect_sdp_time(tvbuff_t *tvb, proto_item* ti){
799   proto_tree *sdp_time_tree;
800   gint offset,next_offset, tokenlen;
801
802   offset = 0;
803   next_offset = 0;
804   tokenlen = 0;
805
806   sdp_time_tree = proto_item_add_subtree(ti,ett_sdp_time);
807
808   /* get start time */
809   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
810   if( next_offset == -1 )
811     return;
812
813   tokenlen = next_offset - offset;
814   proto_tree_add_item(sdp_time_tree, hf_time_start, tvb, offset, tokenlen,
815                       FALSE);
816
817   /* get stop time */
818   offset = next_offset + 1;
819   proto_tree_add_item(sdp_time_tree, hf_time_stop, tvb, offset, -1, FALSE);
820 }
821
822 static void dissect_sdp_repeat_time(tvbuff_t *tvb, proto_item* ti){
823   proto_tree *sdp_repeat_time_tree;
824   gint offset,next_offset, tokenlen;
825
826   offset = 0;
827   next_offset = 0;
828   tokenlen = 0;
829
830   sdp_repeat_time_tree = proto_item_add_subtree(ti,ett_sdp_time);
831
832   /* get interval */
833   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
834   if( next_offset == -1 )
835     return;
836
837   tokenlen = next_offset - offset;
838   proto_tree_add_item(sdp_repeat_time_tree, hf_repeat_time_interval, tvb,
839                       offset, tokenlen, FALSE);
840
841   /* get duration */
842   offset = next_offset + 1;
843   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
844   if( next_offset == -1 )
845     return;
846
847   tokenlen = next_offset - offset;
848   proto_tree_add_item(sdp_repeat_time_tree,hf_repeat_time_duration, tvb,
849                       offset, tokenlen, FALSE);
850
851   /* get offsets */
852   do{
853     offset = next_offset +1;
854     next_offset = tvb_find_guint8(tvb,offset,-1,' ');
855     if(next_offset != -1){
856       tokenlen = next_offset - offset;
857     } else {
858       tokenlen = -1; /* end of tvbuff */
859     }
860     proto_tree_add_item(sdp_repeat_time_tree, hf_repeat_time_offset,
861                         tvb, offset, tokenlen, FALSE);
862   } while( next_offset != -1 );
863
864 }
865 static void
866 dissect_sdp_timezone(tvbuff_t *tvb, proto_item* ti){
867   proto_tree* sdp_timezone_tree;
868   gint offset, next_offset, tokenlen;
869   offset = 0;
870   next_offset = 0;
871   tokenlen = 0;
872
873   sdp_timezone_tree = proto_item_add_subtree(ti,ett_sdp_timezone);
874
875   do{
876     next_offset = tvb_find_guint8(tvb,offset,-1,' ');
877     if(next_offset == -1)
878       break;
879     tokenlen = next_offset - offset;
880
881     proto_tree_add_item(sdp_timezone_tree, hf_timezone_time, tvb, offset,
882                         tokenlen, FALSE);
883     offset = next_offset + 1;
884     next_offset = tvb_find_guint8(tvb,offset,-1,' ');
885     if(next_offset != -1){
886       tokenlen = next_offset - offset;
887     } else {
888       tokenlen = -1; /* end of tvbuff */
889     }
890     proto_tree_add_item(sdp_timezone_tree, hf_timezone_offset, tvb, offset,
891                         tokenlen, FALSE);
892     offset = next_offset + 1;
893   } while (next_offset != -1);
894
895 }
896
897
898 static void dissect_sdp_encryption_key(tvbuff_t *tvb, proto_item * ti){
899   proto_tree *sdp_encryption_key_tree;
900   gint offset, next_offset, tokenlen;
901
902   offset = 0;
903   next_offset = 0;
904   tokenlen = 0;
905
906   sdp_encryption_key_tree = proto_item_add_subtree(ti,ett_sdp_encryption_key);
907
908   next_offset = tvb_find_guint8(tvb,offset,-1,':');
909
910   if(next_offset == -1)
911     return;
912
913   tokenlen = next_offset - offset;
914
915   proto_tree_add_item(sdp_encryption_key_tree,hf_encryption_key_type,
916                       tvb, offset, tokenlen, FALSE);
917
918   offset = next_offset + 1;
919   proto_tree_add_item(sdp_encryption_key_tree,hf_encryption_key_data,
920                       tvb, offset, -1, FALSE);
921 }
922
923 static void dissect_key_mgmt(tvbuff_t *tvb, packet_info * pinfo, proto_item * ti){
924   gchar *data_p = NULL;
925   gchar *prtcl_id = NULL;
926   gint len;
927   tvbuff_t *keymgmt_tvb;
928   gboolean found_match = FALSE;
929   proto_tree *key_tree;
930   gint next_offset;
931   gint offset = 0;
932   gint tokenlen;
933
934   key_tree = proto_item_add_subtree(ti, ett_sdp_key_mgmt);
935
936   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
937
938   if (next_offset == -1)
939     return;
940
941   tokenlen = next_offset - offset;
942   prtcl_id = tvb_get_ephemeral_string(tvb, offset, tokenlen);
943
944   proto_tree_add_item(key_tree, hf_key_mgmt_prtcl_id, tvb, offset, tokenlen, FALSE);
945
946   offset = next_offset + 1;
947
948   len = tvb_length_remaining(tvb, offset);
949   if (len < 0)
950     return;
951
952   data_p = tvb_get_ephemeral_string(tvb, offset, len);
953   keymgmt_tvb = base64_to_tvb(tvb, data_p);
954   add_new_data_source(pinfo, keymgmt_tvb, "Key Management Data");
955
956   if ( prtcl_id != NULL && key_mgmt_dissector_table != NULL ) {
957     found_match = dissector_try_string(key_mgmt_dissector_table,
958                                        prtcl_id,
959                                        keymgmt_tvb, pinfo,
960                                        key_tree);
961   }
962
963   if (found_match) {
964     proto_item *ti2 = proto_tree_add_item(key_tree, hf_key_mgmt_data,
965                                          keymgmt_tvb, 0, -1, FALSE);
966     PROTO_ITEM_SET_HIDDEN(ti2);
967   }
968   else {
969     proto_tree_add_item(key_tree, hf_key_mgmt_data,
970                         keymgmt_tvb, 0, -1, FALSE);
971   }
972
973 }
974
975
976 static void dissect_sdp_session_attribute(tvbuff_t *tvb, packet_info * pinfo, proto_item * ti){
977   proto_tree *sdp_session_attribute_tree;
978   gint offset, next_offset, tokenlen;
979   guint8 *field_name;
980
981   offset = 0;
982   next_offset = 0;
983   tokenlen = 0;
984
985   sdp_session_attribute_tree = proto_item_add_subtree(ti,
986                                                       ett_sdp_session_attribute);
987
988   next_offset = tvb_find_guint8(tvb,offset,-1,':');
989
990   if(next_offset == -1)
991     return;
992
993   tokenlen = next_offset - offset;
994
995   proto_tree_add_item(sdp_session_attribute_tree, hf_session_attribute_field,
996                       tvb, offset, tokenlen, FALSE);
997
998   field_name = tvb_get_ephemeral_string(tvb, offset, tokenlen);
999
1000   offset = next_offset + 1;
1001
1002   if (strcmp((char*)field_name, "ipbcp") == 0) {
1003     offset = tvb_pbrk_guint8(tvb,offset,-1,(guint8 *)"0123456789", NULL);
1004
1005     if (offset == -1)
1006       return;
1007
1008     next_offset = tvb_find_guint8(tvb,offset,-1,' ');
1009
1010     if (next_offset == -1)
1011       return;
1012
1013     tokenlen = next_offset - offset;
1014
1015     proto_tree_add_item(sdp_session_attribute_tree,hf_ipbcp_version,tvb,offset,tokenlen,FALSE);
1016
1017     offset = tvb_pbrk_guint8(tvb,offset,-1,(guint8 *)"ABCDEFGHIJKLMNOPQRSTUVWXYZ", NULL);
1018
1019     if (offset == -1)
1020       return;
1021
1022     tokenlen = tvb_find_line_end(tvb,offset,-1, &next_offset, FALSE);
1023
1024     if (tokenlen == -1)
1025       return;
1026
1027     proto_tree_add_item(sdp_session_attribute_tree,hf_ipbcp_type,tvb,offset,tokenlen,FALSE);
1028   } else if (strcmp((char*)field_name, "key-mgmt") == 0) {
1029     tvbuff_t *key_tvb;
1030     proto_item *key_ti;
1031
1032     key_tvb = tvb_new_subset_remaining(tvb, offset);
1033     key_ti = proto_tree_add_item(sdp_session_attribute_tree, hf_key_mgmt_att_value, key_tvb, 0, -1, FALSE);
1034
1035     dissect_key_mgmt(key_tvb, pinfo, key_ti);
1036   } else {
1037     proto_tree_add_item(sdp_session_attribute_tree, hf_session_attribute_value,
1038                         tvb, offset, -1, FALSE);
1039   }
1040 }
1041
1042
1043 /* Dissect media description */
1044 static void
1045 dissect_sdp_media(tvbuff_t *tvb, proto_item *ti,
1046                   transport_info_t *transport_info){
1047   proto_tree *sdp_media_tree;
1048   gint offset, next_offset, tokenlen, idx;
1049   guint8 *media_format;
1050
1051   offset = 0;
1052   next_offset = 0;
1053   tokenlen = 0;
1054
1055   /* Re-initialise for a new media description */
1056   msrp_transport_address_set = FALSE;
1057
1058   /* Create tree for media session */
1059   sdp_media_tree = proto_item_add_subtree(ti,ett_sdp_media);
1060
1061   next_offset = tvb_find_guint8(tvb,offset, -1, ' ');
1062
1063   if(next_offset == -1)
1064     return;
1065
1066   tokenlen = next_offset - offset;
1067
1068   /* Type of media session */
1069   proto_tree_add_item(sdp_media_tree, hf_media_media, tvb, offset, tokenlen,
1070                       FALSE);
1071
1072   transport_info->media_type = (char*)tvb_get_ephemeral_string(tvb, offset, tokenlen);
1073
1074   offset = next_offset + 1;
1075
1076   next_offset = tvb_find_guint8(tvb,offset, -1, ' ');
1077   if(next_offset == -1)
1078     return;
1079   tokenlen = next_offset - offset;
1080   next_offset = tvb_find_guint8(tvb,offset, tokenlen, '/');
1081
1082   if(next_offset != -1){
1083     tokenlen = next_offset - offset;
1084     /* Save port info */
1085     transport_info->media_port[transport_info->media_count] = (char*)tvb_get_ephemeral_string(tvb, offset, tokenlen);
1086
1087     proto_tree_add_uint(sdp_media_tree, hf_media_port, tvb, offset, tokenlen,
1088                         atoi((char*)tvb_get_ephemeral_string(tvb, offset, tokenlen)));
1089     offset = next_offset + 1;
1090     next_offset = tvb_find_guint8(tvb,offset, -1, ' ');
1091     if(next_offset == -1)
1092       return;
1093     tokenlen = next_offset - offset;
1094     proto_tree_add_item(sdp_media_tree, hf_media_portcount, tvb, offset,
1095                         tokenlen, FALSE);
1096     offset = next_offset + 1;
1097   } else {
1098     next_offset = tvb_find_guint8(tvb,offset, -1, ' ');
1099
1100     if(next_offset == -1)
1101       return;
1102     tokenlen = next_offset - offset;
1103     /* Save port info */
1104     transport_info->media_port[transport_info->media_count] = (char*)tvb_get_ephemeral_string(tvb, offset, tokenlen);
1105
1106     /* XXX Remember Port */
1107     proto_tree_add_uint(sdp_media_tree, hf_media_port, tvb, offset, tokenlen,
1108                         atoi((char*)tvb_get_ephemeral_string(tvb, offset, tokenlen)));
1109     offset = next_offset + 1;
1110   }
1111
1112   next_offset = tvb_find_guint8(tvb,offset,-1,' ');
1113
1114   if( next_offset == -1)
1115     return;
1116
1117   tokenlen = next_offset - offset;
1118   /* Save port protocol */
1119   transport_info->media_proto[transport_info->media_count] = (char*)tvb_get_ephemeral_string(tvb, offset, tokenlen);
1120
1121   /* XXX Remember Protocol */
1122   proto_tree_add_item(sdp_media_tree, hf_media_proto, tvb, offset, tokenlen,
1123                       FALSE);
1124
1125   do {
1126     offset = next_offset + 1;
1127     next_offset = tvb_find_guint8(tvb,offset,-1,' ');
1128
1129     if(next_offset == -1){
1130       tokenlen = tvb_length_remaining(tvb, offset); /* End of tvbuff */
1131       if (tokenlen == 0)
1132         break; /* Nothing more left */
1133     } else {
1134       tokenlen = next_offset - offset;
1135     }
1136
1137     if (strcmp(transport_info->media_proto[transport_info->media_count],
1138                "RTP/AVP") == 0) {
1139       media_format = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1140       proto_tree_add_string(sdp_media_tree, hf_media_format, tvb, offset,
1141                             tokenlen, val_to_str(atol((char*)media_format), rtp_payload_type_vals, "%u"));
1142       idx = transport_info->media[transport_info->media_count].pt_count;
1143       transport_info->media[transport_info->media_count].pt[idx] = atol((char*)media_format);
1144       if (idx < (SDP_MAX_RTP_PAYLOAD_TYPES-1))
1145         transport_info->media[transport_info->media_count].pt_count++;
1146     } else {
1147       proto_tree_add_item(sdp_media_tree, hf_media_format, tvb, offset,
1148                           tokenlen, FALSE);
1149     }
1150   } while (next_offset != -1);
1151
1152   /* Increase the count of media channels, but don't walk off the end
1153      of the arrays. */
1154   if (transport_info->media_count < (SDP_MAX_RTP_CHANNELS-1)){
1155     transport_info->media_count++;
1156   }
1157
1158   /* XXX Dissect traffic to "Port" as "Protocol"
1159    *     Remember this Port/Protocol pair so we can tear it down again later
1160    *     Actually, it's harder than that:
1161    *         We need to find out the address of the other side first and it
1162    *         looks like that info can be found in SIP headers only.
1163    */
1164
1165 }
1166
1167 static tvbuff_t *
1168 ascii_bytes_to_tvb(tvbuff_t *tvb, packet_info *pinfo, gint len, gchar *msg)
1169 {
1170   guint8 *buf = g_malloc(10240);
1171
1172   /* arbitrary maximum length */
1173   if(len<20480){
1174     int i;
1175     tvbuff_t *bytes_tvb;
1176
1177     /* first, skip to where the encoded pdu starts, this is
1178        the first hex digit after the '=' char.
1179     */
1180     while(1){
1181       if((*msg==0)||(*msg=='\n')){
1182         return NULL;
1183       }
1184       if(*msg=='='){
1185         msg++;
1186         break;
1187       }
1188       msg++;
1189     }
1190     while(1){
1191       if((*msg==0)||(*msg=='\n')){
1192         return NULL;
1193       }
1194       if( ((*msg>='0')&&(*msg<='9'))
1195           ||  ((*msg>='a')&&(*msg<='f'))
1196           ||  ((*msg>='A')&&(*msg<='F'))){
1197         break;
1198       }
1199       msg++;
1200     }
1201     i=0;
1202     while( ((*msg>='0')&&(*msg<='9'))
1203            ||((*msg>='a')&&(*msg<='f'))
1204            ||((*msg>='A')&&(*msg<='F'))  ){
1205       int val;
1206       if((*msg>='0')&&(*msg<='9')){
1207         val=(*msg)-'0';
1208       } else if((*msg>='a')&&(*msg<='f')){
1209         val=(*msg)-'a'+10;
1210       } else if((*msg>='A')&&(*msg<='F')){
1211         val=(*msg)-'A'+10;
1212       } else {
1213         return NULL;
1214       }
1215       val<<=4;
1216       msg++;
1217       if((*msg>='0')&&(*msg<='9')){
1218         val|=(*msg)-'0';
1219       } else if((*msg>='a')&&(*msg<='f')){
1220         val|=(*msg)-'a'+10;
1221       } else if((*msg>='A')&&(*msg<='F')){
1222         val|=(*msg)-'A'+10;
1223       } else {
1224         return NULL;
1225       }
1226       msg++;
1227
1228       buf[i]=(guint8)val;
1229       i++;
1230     }
1231     if(i==0){
1232       return NULL;
1233     }
1234     bytes_tvb = tvb_new_child_real_data(tvb, buf,i,i);
1235     tvb_set_free_cb(bytes_tvb, g_free);
1236     add_new_data_source(pinfo, bytes_tvb, "ASCII bytes to tvb");
1237     return bytes_tvb;
1238   }
1239   return NULL;
1240 }
1241
1242 /* Annex X Profiles and levels definition */
1243 static const value_string h263_profile_vals[] =
1244 {
1245   { 0,    "Baseline Profile" },
1246   { 1,    "H.320 Coding Efficiency Version 2 Backward-Compatibility Profile" },
1247   { 2,    "Version 1 Backward-Compatibility Profile" },
1248   { 3,    "Version 2 Interactive and Streaming Wireless Profile" },
1249   { 4,    "Version 3 Interactive and Streaming Wireless Profile" },
1250   { 5,    "Conversational High Compression Profile" },
1251   { 6,    "Conversational Internet Profile" },
1252   { 7,    "Conversational Interlace Profile" },
1253   { 8,    "High Latency Profile" },
1254   { 0, NULL },
1255 };
1256
1257
1258 /* RFC 4629 The level are described in table X.2 of H.263 annex X */
1259 static const value_string h263_level_vals[] =
1260 {
1261   { 10,    "QCIF (176 x 144), 1 x 64Kb/s" },
1262   { 20,    "CIF (352 x 288), 2 x 64Kb/s" },
1263   { 30,    "CIF (352 x 288), 6 x 64Kb/s" },
1264   { 40,    "CIF (352 x 288), 32 x 64Kb/s" },
1265   { 45,    "QCIF (176 x144) support of CPFMT, 2 x 64Kb/s" },
1266   { 50,    "CIF (352 x 288) support of CPFMT, 64 x 64Kb/s" },
1267   { 60,    "CPFMT: 720 x 288 support of CPFMT, 128 x 64Kb/s" },
1268   { 70,    "CPFMT: 720 x 576 support of CPFMT, 256 x 64Kb/s" },
1269   { 0, NULL },
1270 };
1271
1272
1273 static const value_string h264_packetization_mode_vals[] =
1274 {
1275   { 0,    "Single NAL mode" },
1276   { 1,    "Non-interleaved mode" },
1277   { 2,    "Interleaved mode" },
1278   { 0, NULL },
1279 };
1280
1281 /*
1282  * TODO: Make this a more generic routine to dissect fmtp parameters depending on media types
1283  */
1284 static void
1285 decode_sdp_fmtp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint offset, gint tokenlen, char *mime_type){
1286   gint next_offset;
1287   gint end_offset;
1288   guint8 *field_name;
1289   gchar *format_specific_parameter;
1290   proto_item *item;
1291   tvbuff_t *data_tvb;
1292
1293   end_offset = offset + tokenlen;
1294
1295   /*
1296   proto_tree_add_text(tree, tvb, offset, tokenlen, "Debug; Analysed string: '%s'",
1297   tvb_get_ephemeral_string(tvb, offset, tokenlen));
1298   */
1299
1300   /* Look for an '=' within this value - this may indicate that there is a
1301      profile-level-id parameter to find if the MPEG4 media type is in use */
1302   next_offset = tvb_find_guint8(tvb,offset,-1,'=');
1303   if (next_offset == -1)
1304   {
1305     /* Give up (and avoid exception) if '=' not found */
1306     return;
1307   }
1308
1309   /* Find the name of the parameter */
1310   tokenlen = next_offset - offset;
1311   field_name = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1312   /*proto_tree_add_text(tree, tvb, offset, tokenlen, "Debug; MIMEtype '%s'Parameter name: '%s'", mime_type, field_name); */
1313
1314   offset = next_offset;
1315
1316   /* Dissect the MPEG4 profile-level-id parameter if present */
1317   if (mime_type != NULL && g_ascii_strcasecmp(mime_type, "MP4V-ES") == 0) {
1318     if (strcmp((char*)field_name, "profile-level-id") == 0) {
1319       offset++;
1320       tokenlen = end_offset - offset;
1321       format_specific_parameter = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1322       item = proto_tree_add_uint(tree, hf_sdp_fmtp_mpeg4_profile_level_id, tvb, offset, tokenlen,
1323                                  atol((char*)format_specific_parameter));
1324       PROTO_ITEM_SET_GENERATED(item);
1325     } else if (strcmp((char*)field_name, "config") == 0) {
1326       /* String including "=" */
1327       tokenlen = end_offset - offset;
1328       format_specific_parameter = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1329       /* ascii_bytes_to_tvb requires the "=" to be in the buffer */
1330       data_tvb = ascii_bytes_to_tvb(tvb, pinfo, tokenlen, format_specific_parameter);
1331       if(mp4ves_handle && data_tvb){
1332         dissect_mp4ves_config(data_tvb, pinfo, tree);
1333       }
1334     }
1335   }
1336
1337   /* Dissect the H263-2000 profile parameter if present */
1338   if ((mime_type != NULL && g_ascii_strcasecmp(mime_type, "H263-2000") == 0)||(mime_type != NULL && g_ascii_strcasecmp(mime_type, "H263-1998") == 0)) {
1339     if (strcmp((char*)field_name, "profile") == 0) {
1340       offset++;
1341       tokenlen = end_offset - offset;
1342       format_specific_parameter = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1343       item = proto_tree_add_uint(tree, hf_sdp_fmtp_h263_profile, tvb, offset, tokenlen,
1344                                  atol((char*)format_specific_parameter));
1345       PROTO_ITEM_SET_GENERATED(item);
1346     } else if(strcmp((char*)field_name, "level") == 0) {
1347       offset++;
1348       tokenlen = end_offset - offset;
1349       format_specific_parameter = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1350       item = proto_tree_add_uint(tree, hf_sdp_fmtp_h263_level, tvb, offset, tokenlen,
1351                                  atol((char*)format_specific_parameter));
1352       PROTO_ITEM_SET_GENERATED(item);
1353     }
1354   }
1355
1356
1357   /* Dissect the H264 profile-level-id parameter
1358    * RFC 3984:
1359    * A base16 [6] (hexadecimal) representation of
1360    * the following three bytes in the sequence
1361    * parameter set NAL unit specified in [1]: 1)
1362    * profile_idc, 2) a byte herein referred to as
1363    * profile-iop, composed of the values of
1364    * constraint_set0_flag, constraint_set1_flag,
1365    * constraint_set2_flag, and reserved_zero_5bits
1366    * in bit-significance order, starting from the
1367    * most significant bit, and 3) level_idc.
1368    */
1369   if (mime_type != NULL && g_ascii_strcasecmp(mime_type, "H264") == 0) {
1370     if (strcmp(field_name, "profile-level-id") == 0) {
1371       int length;
1372
1373       /* Length includes "=" as it's required by ascii_bytes_to_tvb()*/
1374       tokenlen = end_offset - offset;
1375       format_specific_parameter = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1376       data_tvb = ascii_bytes_to_tvb(tvb, pinfo, tokenlen, format_specific_parameter);
1377       length = tvb_length(data_tvb);
1378       if (length == 3){
1379         if(h264_handle && data_tvb){
1380           dissect_h264_profile(data_tvb, pinfo, tree);
1381         }
1382       }else{
1383         item = proto_tree_add_text(tree, tvb, offset, tokenlen, "Incorrectly coded, must be three bytes");
1384         PROTO_ITEM_SET_GENERATED(item);
1385       }
1386     }else if (strcmp(field_name, "packetization-mode") == 0) {
1387       offset++;
1388       tokenlen = end_offset - offset;
1389       format_specific_parameter = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1390       item = proto_tree_add_uint(tree, hf_sdp_h264_packetization_mode, tvb, offset, tokenlen,
1391                                  atol((char*)format_specific_parameter));
1392       PROTO_ITEM_SET_GENERATED(item);
1393
1394     }else if (strcmp(field_name, "sprop-parameter-sets") == 0) {
1395       /* The value of the parameter is the
1396          base64 [6] representation of the initial
1397          parameter set NAL units as specified in
1398          sections 7.3.2.1 and 7.3.2.2 of [1].  The
1399          parameter sets are conveyed in decoding order,
1400          and no framing of the parameter set NAL units
1401          takes place.  A comma is used to separate any
1402          pair of parameter sets in the list.
1403       */
1404       gchar *data_p = NULL;
1405       gint comma_offset;
1406
1407
1408       /* Move past '=' */
1409       offset++;
1410       comma_offset = tvb_find_guint8(tvb,offset,-1,',');
1411       if (comma_offset != -1){
1412         tokenlen = comma_offset - offset;
1413       }else{
1414         tokenlen = end_offset - offset;
1415       }
1416
1417       data_p = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1418       proto_tree_add_text(tree, tvb, offset, tokenlen, "NAL unit 1 string: %s", data_p);
1419
1420       /* proto_tree_add_text(tree, tvb, offset, tokenlen, "String %s",data_p); */
1421       data_tvb = base64_to_tvb(tvb, data_p);
1422       add_new_data_source(pinfo, data_tvb, "h264 prop-parameter-sets");
1423
1424       if(h264_handle && data_tvb){
1425         dissect_h264_nal_unit(data_tvb, pinfo, tree);
1426         if (comma_offset != -1){
1427           /* Second NAL unit */
1428           offset = comma_offset +1;
1429           tokenlen = end_offset - offset;
1430           data_p = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1431           proto_tree_add_text(tree, tvb, offset, tokenlen, "NAL unit 2 string: %s", data_p);
1432           data_tvb = base64_to_tvb(tvb, data_p);
1433           add_new_data_source(pinfo, data_tvb, "h264 prop-parameter-sets 2");
1434           dissect_h264_nal_unit(data_tvb, pinfo, tree);
1435         }
1436       }
1437     }
1438   }
1439
1440 }
1441
1442 typedef struct {
1443         const char *name;
1444 } sdp_names_t;
1445
1446 #define SDP_RTPMAP              1
1447 #define SDP_FMTP                2
1448 #define SDP_PATH                3
1449 #define SDP_H248_ITEM   4
1450
1451 static const sdp_names_t sdp_media_attribute_names[] = {
1452   { "Unknown-name"},    /* 0 Pad so that the real headers start at index 1 */
1453   { "rtpmap"},          /* 1 */
1454   { "fmtp"},            /* 2 */
1455   { "path"},            /* 3 */
1456   { "h248item"},        /* 4 */
1457 };
1458
1459 static gint find_sdp_media_attribute_names(tvbuff_t *tvb, int offset, guint len)
1460 {
1461   guint i;
1462
1463   for (i = 1; i < array_length(sdp_media_attribute_names); i++) {
1464     if (len == strlen(sdp_media_attribute_names[i].name) &&
1465         tvb_strncaseeql(tvb, offset, sdp_media_attribute_names[i].name, len) == 0)
1466       return i;
1467   }
1468
1469   return -1;
1470 }
1471
1472 static void dissect_sdp_media_attribute(tvbuff_t *tvb, packet_info *pinfo, proto_item * ti, int length, transport_info_t *transport_info){
1473   proto_tree *sdp_media_attribute_tree;
1474   proto_item *fmtp_item, *media_format_item;
1475   proto_tree *fmtp_tree;
1476   gint offset, next_offset, tokenlen, n, colon_offset;
1477   gint start_offset;
1478   guint8 *field_name;
1479   guint8 *payload_type;
1480   guint8 *attribute_value;
1481   gint   *key;
1482   guint8 pt;
1483   gint  sdp_media_attrbute_code;
1484   const char *msrp_res = "msrp://";
1485   const char *h324ext_h223lcparm = "h324ext/h223lcparm";
1486   gboolean has_more_pars = TRUE;
1487   tvbuff_t *h245_tvb;
1488   encoding_name_and_rate_t *encoding_name_and_rate;
1489
1490   offset = 0;
1491   next_offset = 0;
1492   tokenlen = 0;
1493
1494   /* Create attribute tree */
1495   sdp_media_attribute_tree = proto_item_add_subtree(ti,
1496                                                     ett_sdp_media_attribute);
1497   /* Find end of field */
1498   colon_offset = tvb_find_guint8(tvb,offset,-1,':');
1499
1500   if(colon_offset == -1)
1501     return;
1502
1503   /* Attribute field name is token before ':' */
1504   tokenlen = colon_offset - offset;
1505   proto_tree_add_item(sdp_media_attribute_tree,
1506                       hf_media_attribute_field,
1507                       tvb, offset, tokenlen, FALSE);
1508   field_name = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1509   sdp_media_attrbute_code = find_sdp_media_attribute_names(tvb, offset, tokenlen);
1510
1511   /* Skip colon */
1512   offset = colon_offset + 1;
1513   /* skip leading wsp */
1514   offset = tvb_skip_wsp(tvb,offset,tvb_length_remaining(tvb,offset));
1515
1516   /* Value is the remainder of the line */
1517   attribute_value = tvb_get_ephemeral_string(tvb, offset, tvb_length_remaining(tvb, offset));
1518
1519
1520
1521   /*********************************************/
1522   /* Special parsing for some field name types */
1523
1524   switch (sdp_media_attrbute_code){
1525   case SDP_RTPMAP:
1526     /* decode the rtpmap to see if it is DynamicPayload to dissect them automatic */
1527     next_offset = tvb_find_guint8(tvb,offset,-1,' ');
1528
1529     if(next_offset == -1)
1530       return;
1531
1532     tokenlen = next_offset - offset;
1533
1534     proto_tree_add_item(sdp_media_attribute_tree, hf_media_format, tvb,
1535                         offset, tokenlen, FALSE);
1536
1537     payload_type = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1538
1539     offset = next_offset + 1;
1540
1541     next_offset = tvb_find_guint8(tvb,offset,-1,'/');
1542
1543     if(next_offset == -1){
1544       return;
1545     }
1546
1547     tokenlen = next_offset - offset;
1548
1549     start_offset = offset;
1550     proto_tree_add_item(sdp_media_attribute_tree, hf_media_encoding_name, tvb,
1551                         offset, tokenlen, FALSE);
1552
1553     key=g_malloc( sizeof(gint) );
1554     *key=atol((char*)payload_type);
1555     pt = atoi((char*)payload_type);
1556     if (pt >= SDP_NO_OF_PT) {
1557       return;   /* Invalid */
1558     }
1559     transport_info->encoding_name[pt] = (char*)tvb_get_ephemeral_string(tvb, offset, tokenlen);
1560
1561     next_offset =  next_offset + 1;
1562     offset = next_offset;
1563     while (length-1 >= next_offset){
1564       if(!isdigit(tvb_get_guint8(tvb, next_offset)))
1565         break;
1566       next_offset++;
1567     }
1568     tokenlen = next_offset - offset;
1569     proto_tree_add_item(sdp_media_attribute_tree, hf_media_sample_rate, tvb,
1570                         offset, tokenlen, FALSE);
1571     transport_info->sample_rate[pt] = atoi(tvb_get_ephemeral_string(tvb, offset, tokenlen));
1572     /* As per RFC2327 it is possible to have multiple Media Descriptions ("m=").
1573        For example:
1574
1575        a=rtpmap:101 G726-32/8000
1576        m=audio 49170 RTP/AVP 0 97
1577        a=rtpmap:97 telephone-event/8000
1578        m=audio 49172 RTP/AVP 97 101
1579        a=rtpmap:97 G726-24/8000
1580
1581        The Media attributes ("a="s) after the "m=" only apply for that "m=".
1582        If there is an "a=" before the first "m=", that attribute applies for
1583        all the session (all the "m="s).
1584     */
1585
1586     /* so, if this "a=" appear before any "m=", we add it to all the dynamic
1587      * hash tables
1588      */
1589     if (transport_info->media_count == 0) {
1590       for (n=0; n < SDP_MAX_RTP_CHANNELS; n++) {
1591         encoding_name_and_rate = g_malloc( sizeof(encoding_name_and_rate_t));
1592         encoding_name_and_rate->encoding_name = g_strdup(transport_info->encoding_name[pt]);
1593         encoding_name_and_rate->sample_rate = transport_info->sample_rate[pt];
1594         if (n==0){
1595           g_hash_table_insert(transport_info->media[n].rtp_dyn_payload,
1596                               key, encoding_name_and_rate);
1597         }
1598         else {    /* we create a new key and encoding_name to assign to the other hash tables */
1599           gint *key2;
1600           key2=g_malloc( sizeof(gint) );
1601           *key2=atol((char*)payload_type);
1602           g_hash_table_insert(transport_info->media[n].rtp_dyn_payload,
1603                               key2, encoding_name_and_rate);
1604         }
1605       }
1606       return;
1607       /* if the "a=" is after an "m=", only apply to this "m=" */
1608     }else
1609       /* in case there is an overflow in SDP_MAX_RTP_CHANNELS, we keep always the last "m=" */
1610       encoding_name_and_rate = g_malloc( sizeof(encoding_name_and_rate_t));
1611
1612     encoding_name_and_rate->encoding_name = g_strdup(transport_info->encoding_name[pt]);
1613     encoding_name_and_rate->sample_rate = transport_info->sample_rate[pt];
1614     if (transport_info->media_count == SDP_MAX_RTP_CHANNELS-1)
1615       g_hash_table_insert(transport_info->media[ transport_info->media_count ].rtp_dyn_payload,
1616                           key, encoding_name_and_rate);
1617     else
1618       g_hash_table_insert(transport_info->media[ transport_info->media_count-1 ].rtp_dyn_payload,
1619                             key, encoding_name_and_rate);
1620     break;
1621   case SDP_FMTP:
1622     if(sdp_media_attribute_tree){
1623       guint8 media_format;
1624       /* Reading the Format parameter(fmtp) */
1625       /* Skip leading space, if any */
1626       offset = tvb_skip_wsp(tvb,offset,tvb_length_remaining(tvb,offset));
1627       /* Media format extends to the next space */
1628       next_offset = tvb_find_guint8(tvb,offset,-1,' ');
1629
1630       if(next_offset == -1)
1631         return;
1632
1633       tokenlen = next_offset - offset;
1634
1635
1636       media_format_item = proto_tree_add_item(sdp_media_attribute_tree,
1637                                               hf_media_format, tvb, offset,
1638                                               tokenlen, FALSE);
1639       media_format = atoi((char*)tvb_get_ephemeral_string(tvb, offset, tokenlen));
1640       if (media_format >= SDP_NO_OF_PT) {
1641         return;   /* Invalid */
1642       }
1643
1644       /* Append encoding name to format if known */
1645       proto_item_append_text(media_format_item, " [%s]",
1646                              transport_info->encoding_name[media_format]);
1647
1648       payload_type = tvb_get_ephemeral_string(tvb, offset, tokenlen);
1649       /* Move offset past the payload type */
1650       offset = next_offset + 1;
1651
1652       while(has_more_pars==TRUE){
1653         next_offset = tvb_find_guint8(tvb,offset,-1,';');
1654         offset = tvb_skip_wsp(tvb,offset,tvb_length_remaining(tvb,offset));
1655
1656         if(next_offset == -1){
1657           has_more_pars = FALSE;
1658           next_offset= tvb_length(tvb);
1659         }else{
1660
1661         }
1662
1663         /* There are at least 2 - add the first parameter */
1664         tokenlen = next_offset - offset;
1665         fmtp_item = proto_tree_add_item(sdp_media_attribute_tree,
1666                                         hf_media_format_specific_parameter, tvb,
1667                                         offset, tokenlen, FALSE);
1668
1669         fmtp_tree = proto_item_add_subtree(fmtp_item, ett_sdp_fmtp);
1670
1671         decode_sdp_fmtp(fmtp_tree, tvb, pinfo, offset, tokenlen,
1672                         transport_info->encoding_name[media_format]);
1673
1674         /* Move offset past "; " and onto firts char */
1675         offset = next_offset + 1;
1676       }
1677     }
1678     break;
1679   case SDP_PATH:
1680     /* msrp attributes that contain address needed for conversation */
1681     /*    RFC 4975
1682      *    path = path-label ":" path-list
1683      *    path-label = "path"
1684      *    path-list= MSRP-URI *(SP MSRP-URI)
1685      *    MSRP-URI = msrp-scheme "://" authority
1686      *       ["/" session-id] ";" transport *( ";" URI-parameter)
1687      *                        ; authority as defined in RFC3986
1688          *
1689          *    msrp-scheme = "msrp" / "msrps"
1690          * RFC 3986
1691          * The authority component is preceded by a double slash ("//") and is terminated by 
1692          * the next slash ("/"), question mark ("?"), or number sign ("#") character, or by 
1693          * the end of the URI. 
1694          */
1695
1696     /* Check for "msrp://" */
1697     if (strncmp((char*)attribute_value, msrp_res, strlen(msrp_res)) == 0){
1698       int address_offset, port_offset, port_end_offset;
1699
1700       /* Address starts here */
1701       address_offset = offset + (int)strlen(msrp_res);
1702
1703       /* Port is after next ':' */
1704       port_offset = tvb_find_guint8(tvb, address_offset, -1, ':');
1705           /* Check if port is present if not skipp */
1706           if(port_offset!= -1){
1707                   /* Port ends with '/' */
1708                   port_end_offset = tvb_find_guint8(tvb, port_offset, -1, '/');
1709
1710                   /* Attempt to convert address */
1711                   if (inet_pton(AF_INET, (char*)tvb_get_ephemeral_string(tvb, address_offset, port_offset-address_offset), &msrp_ipaddr) > 0) {
1712                         /* Get port number */
1713                         msrp_port_number = atoi((char*)tvb_get_ephemeral_string(tvb, port_offset+1, port_end_offset-port_offset-1));
1714                         /* Set flag so this info can be used */
1715                         msrp_transport_address_set = TRUE;
1716                   }
1717           }
1718     }
1719     break;
1720   case SDP_H248_ITEM:
1721     /* Decode h248 item ITU-T Rec. H.248.12 (2001)/Amd.1 (11/2002)*/
1722     if (strncmp((char*)attribute_value, h324ext_h223lcparm, strlen(msrp_res)) == 0){
1723       /* A.5.1.3 H.223 Logical channel parameters
1724        * This property indicates the H.245
1725        * H223LogicalChannelsParameters structure encoded by applying the PER specified in
1726        * ITU-T Rec. X.691. Value encoded as per A.5.1.2. For text encoding the mechanism defined
1727        * in ITU-T Rec. H.248.15 is used.
1728        */
1729       gint len;
1730       asn1_ctx_t actx;
1731
1732       len = (gint)strlen(attribute_value);
1733       h245_tvb = ascii_bytes_to_tvb(tvb, pinfo, len, attribute_value);
1734       /* arbitrary maximum length */
1735       /* should go through a handle, however,  the two h245 entry
1736          points are different, one is over tpkt and the other is raw
1737       */
1738       if (h245_tvb){
1739         asn1_ctx_init(&actx, ASN1_ENC_PER, TRUE, pinfo);
1740         dissect_h245_H223LogicalChannelParameters(h245_tvb, 0, &actx, sdp_media_attribute_tree, hf_SDPh223LogicalChannelParameters);
1741       }
1742     }
1743     break;
1744   default:
1745     /* No special treatment for values of this attribute type, just add as one item. */
1746     proto_tree_add_item(sdp_media_attribute_tree, hf_media_attribute_value,
1747                         tvb, offset, -1, FALSE);
1748     break;
1749   }
1750 }
1751
1752 void
1753 proto_register_sdp(void)
1754 {
1755   static hf_register_info hf[] = {
1756     { &hf_protocol_version,
1757       { "Session Description Protocol Version (v)",
1758         "sdp.version", FT_STRING, BASE_NONE,NULL,0x0,
1759         NULL, HFILL }},
1760     { &hf_owner,
1761       { "Owner/Creator, Session Id (o)",
1762         "sdp.owner", FT_STRING, BASE_NONE, NULL, 0x0,
1763         NULL, HFILL}},
1764     { &hf_session_name,
1765       { "Session Name (s)",
1766         "sdp.session_name", FT_STRING, BASE_NONE,NULL, 0x0,
1767         NULL, HFILL }},
1768     { &hf_session_info,
1769       { "Session Information (i)",
1770         "sdp.session_info", FT_STRING, BASE_NONE, NULL, 0x0,
1771         NULL, HFILL }},
1772     { &hf_uri,
1773       { "URI of Description (u)",
1774         "sdp.uri", FT_STRING, BASE_NONE,NULL, 0x0,
1775         NULL, HFILL }},
1776     { &hf_email,
1777       { "E-mail Address (e)",
1778         "sdp.email", FT_STRING, BASE_NONE, NULL, 0x0,
1779         "E-mail Address", HFILL }},
1780     { &hf_phone,
1781       { "Phone Number (p)",
1782         "sdp.phone", FT_STRING, BASE_NONE, NULL, 0x0,
1783         NULL, HFILL }},
1784     { &hf_connection_info,
1785       { "Connection Information (c)",
1786         "sdp.connection_info", FT_STRING, BASE_NONE, NULL, 0x0,
1787         NULL, HFILL }},
1788     { &hf_bandwidth,
1789       { "Bandwidth Information (b)",
1790         "sdp.bandwidth", FT_STRING, BASE_NONE, NULL, 0x0,
1791         NULL, HFILL }},
1792     { &hf_timezone,
1793       { "Time Zone Adjustments (z)",
1794         "sdp.timezone", FT_STRING, BASE_NONE, NULL, 0x0,
1795         NULL, HFILL }},
1796     { &hf_encryption_key,
1797       { "Encryption Key (k)",
1798         "sdp.encryption_key", FT_STRING, BASE_NONE, NULL, 0x0,
1799         NULL, HFILL }},
1800     { &hf_session_attribute,
1801       { "Session Attribute (a)",
1802         "sdp.session_attr", FT_STRING, BASE_NONE, NULL, 0x0,
1803         NULL, HFILL }},
1804     { &hf_media_attribute,
1805       { "Media Attribute (a)",
1806         "sdp.media_attr", FT_STRING, BASE_NONE, NULL, 0x0,
1807         NULL, HFILL }},
1808     { &hf_time,
1809       { "Time Description, active time (t)",
1810         "sdp.time", FT_STRING, BASE_NONE, NULL, 0x0,
1811         NULL, HFILL }},
1812     { &hf_repeat_time,
1813       { "Repeat Time (r)",
1814         "sdp.repeat_time", FT_STRING, BASE_NONE, NULL, 0x0,
1815         NULL, HFILL }},
1816     { &hf_media,
1817       { "Media Description, name and address (m)",
1818         "sdp.media", FT_STRING, BASE_NONE, NULL, 0x0,
1819         NULL, HFILL }},
1820     { &hf_media_title,
1821       { "Media Title (i)",
1822         "sdp.media_title",FT_STRING, BASE_NONE, NULL, 0x0,
1823         "Media Title", HFILL }},
1824     { &hf_unknown,
1825       { "Unknown",
1826         "sdp.unknown",FT_STRING, BASE_NONE, NULL, 0x0,
1827         NULL, HFILL }},
1828     { &hf_invalid,
1829       { "Invalid line",
1830         "sdp.invalid",FT_STRING, BASE_NONE, NULL, 0x0,
1831         NULL, HFILL }},
1832     { &hf_owner_username,
1833       { "Owner Username",
1834         "sdp.owner.username",FT_STRING, BASE_NONE, NULL, 0x0,
1835         NULL, HFILL }},
1836     { &hf_owner_sessionid,
1837       { "Session ID",
1838         "sdp.owner.sessionid",FT_STRING, BASE_NONE, NULL, 0x0,
1839         NULL, HFILL }},
1840     { &hf_owner_version,
1841       { "Session Version",
1842         "sdp.owner.version",FT_STRING, BASE_NONE, NULL, 0x0,
1843         NULL, HFILL }},
1844     { &hf_owner_network_type,
1845       { "Owner Network Type",
1846         "sdp.owner.network_type",FT_STRING, BASE_NONE, NULL, 0x0,
1847         NULL, HFILL }},
1848     { &hf_owner_address_type,
1849       { "Owner Address Type",
1850         "sdp.owner.address_type",FT_STRING, BASE_NONE, NULL, 0x0,
1851         NULL, HFILL }},
1852     { &hf_owner_address,
1853       { "Owner Address",
1854         "sdp.owner.address",FT_STRING, BASE_NONE, NULL, 0x0,
1855         NULL, HFILL }},
1856     { &hf_connection_info_network_type,
1857       { "Connection Network Type",
1858         "sdp.connection_info.network_type",FT_STRING, BASE_NONE, NULL, 0x0,
1859         NULL, HFILL }},
1860     { &hf_connection_info_address_type,
1861       { "Connection Address Type",
1862         "sdp.connection_info.address_type",FT_STRING, BASE_NONE, NULL, 0x0,
1863         NULL, HFILL }},
1864     { &hf_connection_info_connection_address,
1865       { "Connection Address",
1866         "sdp.connection_info.address",FT_STRING, BASE_NONE, NULL, 0x0,
1867         NULL, HFILL }},
1868     { &hf_connection_info_ttl,
1869       { "Connection TTL",
1870         "sdp.connection_info.ttl",FT_STRING, BASE_NONE, NULL, 0x0,
1871         NULL, HFILL }},
1872     { &hf_connection_info_num_addr,
1873       { "Connection Number of Addresses",
1874         "sdp.connection_info.num_addr",FT_STRING, BASE_NONE, NULL, 0x0,
1875         NULL, HFILL }},
1876     { &hf_bandwidth_modifier,
1877       { "Bandwidth Modifier",
1878         "sdp.bandwidth.modifier",FT_STRING, BASE_NONE, NULL, 0x0,
1879         NULL, HFILL }},
1880     { &hf_bandwidth_value,
1881       { "Bandwidth Value",
1882         "sdp.bandwidth.value",FT_STRING, BASE_NONE, NULL, 0x0,
1883         "Bandwidth Value (in kbits/s)", HFILL }},
1884     { &hf_time_start,
1885       { "Session Start Time",
1886         "sdp.time.start",FT_STRING, BASE_NONE, NULL, 0x0,
1887         NULL, HFILL }},
1888     { &hf_time_stop,
1889       { "Session Stop Time",
1890         "sdp.time.stop",FT_STRING, BASE_NONE, NULL, 0x0,
1891         NULL, HFILL }},
1892     { &hf_repeat_time_interval,
1893       { "Repeat Interval",
1894         "sdp.repeat_time.interval",FT_STRING, BASE_NONE, NULL, 0x0,
1895         NULL, HFILL }},
1896     { &hf_repeat_time_duration,
1897       { "Repeat Duration",
1898         "sdp.repeat_time.duration",FT_STRING, BASE_NONE, NULL, 0x0,
1899         NULL, HFILL }},
1900     { &hf_repeat_time_offset,
1901       { "Repeat Offset",
1902         "sdp.repeat_time.offset",FT_STRING, BASE_NONE, NULL, 0x0,
1903         NULL, HFILL }},
1904     { &hf_timezone_time,
1905       { "Timezone Time",
1906         "sdp.timezone.time",FT_STRING, BASE_NONE, NULL, 0x0,
1907         NULL, HFILL }},
1908     { &hf_timezone_offset,
1909       { "Timezone Offset",
1910         "sdp.timezone.offset",FT_STRING, BASE_NONE, NULL, 0x0,
1911         NULL, HFILL }},
1912     { &hf_encryption_key_type,
1913       { "Key Type",
1914         "sdp.encryption_key.type",FT_STRING, BASE_NONE, NULL, 0x0,
1915         NULL, HFILL }},
1916     { &hf_encryption_key_data,
1917       { "Key Data",
1918         "sdp.encryption_key.data",FT_STRING, BASE_NONE, NULL, 0x0,
1919         NULL, HFILL }},
1920     { &hf_session_attribute_field,
1921       { "Session Attribute Fieldname",
1922         "sdp.session_attr.field",FT_STRING, BASE_NONE, NULL, 0x0,
1923         NULL, HFILL }},
1924     { &hf_session_attribute_value,
1925       { "Session Attribute Value",
1926         "sdp.session_attr.value",FT_STRING, BASE_NONE, NULL, 0x0,
1927         NULL, HFILL }},
1928     { &hf_media_media,
1929       { "Media Type",
1930         "sdp.media.media",FT_STRING, BASE_NONE, NULL, 0x0,
1931         NULL, HFILL }},
1932     { &hf_media_port,
1933       { "Media Port",
1934         "sdp.media.port",FT_UINT16, BASE_DEC, NULL, 0x0,
1935         NULL, HFILL }},
1936     { &hf_media_portcount,
1937       { "Media Port Count",
1938         "sdp.media.portcount",FT_STRING, BASE_NONE, NULL, 0x0,
1939         NULL, HFILL }},
1940     { &hf_media_proto,
1941       { "Media Protocol",
1942         "sdp.media.proto",FT_STRING, BASE_NONE, NULL, 0x0,
1943         NULL, HFILL }},
1944     { &hf_media_format,
1945       { "Media Format",
1946         "sdp.media.format",FT_STRING, BASE_NONE, NULL, 0x0,
1947         NULL, HFILL }},
1948     { &hf_media_attribute_field,
1949       { "Media Attribute Fieldname",
1950         "sdp.media_attribute.field",FT_STRING, BASE_NONE, NULL, 0x0,
1951         NULL, HFILL }},
1952     { &hf_media_attribute_value,
1953       { "Media Attribute Value",
1954         "sdp.media_attribute.value",FT_STRING, BASE_NONE, NULL, 0x0,
1955         NULL, HFILL }},
1956     { &hf_media_encoding_name,
1957       { "MIME Type",
1958         "sdp.mime.type",FT_STRING, BASE_NONE, NULL, 0x0,
1959         "SDP MIME Type", HFILL }},
1960     { &hf_media_sample_rate,
1961       { "Sample Rate",
1962         "sdp.sample_rate",FT_STRING, BASE_NONE, NULL, 0x0,
1963         NULL, HFILL }},
1964     { &hf_media_format_specific_parameter,
1965       { "Media format specific parameters",
1966         "sdp.fmtp.parameter",FT_STRING, BASE_NONE, NULL, 0x0,
1967         "Format specific parameter(fmtp)", HFILL }},
1968     { &hf_ipbcp_version,
1969       { "IPBCP Protocol Version",
1970         "ipbcp.version",FT_STRING, BASE_NONE, NULL, 0x0,
1971         NULL, HFILL }},
1972     { &hf_ipbcp_type,
1973       { "IPBCP Command Type",
1974         "ipbcp.command",FT_STRING, BASE_NONE, NULL, 0x0,
1975         NULL, HFILL }},
1976     {&hf_sdp_fmtp_mpeg4_profile_level_id,
1977       { "Level Code",
1978         "sdp.fmtp.profile_level_id",FT_UINT32, BASE_DEC,VALS(mp4ves_level_indication_vals), 0x0,
1979         NULL, HFILL }},
1980     { &hf_sdp_fmtp_h263_profile,
1981       { "Profile",
1982         "sdp.fmtp.h263profile",FT_UINT32, BASE_DEC,VALS(h263_profile_vals), 0x0,
1983         NULL, HFILL }},
1984     { &hf_sdp_fmtp_h263_level,
1985       { "Level",
1986         "sdp.fmtp.h263level",FT_UINT32, BASE_DEC,VALS(h263_level_vals), 0x0,
1987         NULL, HFILL }},
1988     { &hf_sdp_h264_packetization_mode,
1989       { "Packetization mode",
1990         "sdp.fmtp.h264_packetization_mode",FT_UINT32, BASE_DEC,VALS(h264_packetization_mode_vals), 0x0,
1991         NULL, HFILL }},
1992     { &hf_sdp_h264_sprop_parameter_sets,
1993       { "Sprop_parameter_sets",
1994         "sdp.h264.sprop_parameter_sets", FT_BYTES, BASE_NONE, NULL, 0x0,
1995         NULL, HFILL }},
1996     { &hf_SDPh223LogicalChannelParameters,
1997       { "h223LogicalChannelParameters", "sdp.h223LogicalChannelParameters",
1998         FT_NONE, BASE_NONE, NULL, 0,
1999         NULL, HFILL }},
2000     { &hf_key_mgmt_att_value,
2001       { "Key Management",
2002         "sdp.key_mgmt", FT_STRING, BASE_NONE, NULL, 0x0,
2003         NULL, HFILL }},
2004     { &hf_key_mgmt_prtcl_id,
2005       { "Key Management Protocol (kmpid)",
2006         "sdp.key_mgmt.kmpid", FT_STRING, BASE_NONE, NULL, 0x0,
2007         NULL, HFILL }},
2008     { &hf_key_mgmt_data,
2009       { "Key Management Data",
2010         "sdp.key_mgmt.data", FT_BYTES, BASE_NONE, NULL, 0x0,
2011         NULL, HFILL }},
2012   };
2013   static gint *ett[] = {
2014     &ett_sdp,
2015     &ett_sdp_owner,
2016     &ett_sdp_connection_info,
2017     &ett_sdp_bandwidth,
2018     &ett_sdp_time,
2019     &ett_sdp_repeat_time,
2020     &ett_sdp_timezone,
2021     &ett_sdp_encryption_key,
2022     &ett_sdp_session_attribute,
2023     &ett_sdp_media,
2024     &ett_sdp_media_attribute,
2025     &ett_sdp_fmtp,
2026     &ett_sdp_key_mgmt,
2027   };
2028
2029   module_t *sdp_module;
2030
2031   proto_sdp = proto_register_protocol("Session Description Protocol",
2032                                       "SDP", "sdp");
2033   proto_register_field_array(proto_sdp, hf, array_length(hf));
2034   proto_register_subtree_array(ett, array_length(ett));
2035
2036   key_mgmt_dissector_table = register_dissector_table("key_mgmt",
2037                                                       "Key Management", FT_STRING, BASE_NONE);
2038
2039   /*
2040    * Preferences registration
2041    */
2042    sdp_module = prefs_register_protocol(proto_sdp, NULL);
2043    prefs_register_bool_preference(sdp_module, "establish_conversation",
2044        "Establish Media Conversation",
2045        "Specifies that RTP/RTCP/T.38/MSRP/etc streams are decoded based "
2046        "upon port numbers found in SDP payload",
2047        &global_sdp_establish_conversation);
2048
2049   /*
2050    * Register the dissector by name, so other dissectors can
2051    * grab it by name rather than just referring to it directly.
2052    */
2053   register_dissector("sdp", dissect_sdp, proto_sdp);
2054
2055   /* Register for tapping */
2056   sdp_tap = register_tap("sdp");
2057 }
2058
2059 void
2060 proto_reg_handoff_sdp(void)
2061 {
2062   dissector_handle_t sdp_handle;
2063
2064   rtp_handle = find_dissector("rtp");
2065   rtcp_handle = find_dissector("rtcp");
2066   msrp_handle = find_dissector("msrp");
2067   t38_handle = find_dissector("t38");
2068   h264_handle = find_dissector("h264");
2069   mp4ves_handle = find_dissector("mp4ves");
2070
2071   sdp_handle = find_dissector("sdp");
2072   dissector_add_string("media_type", "application/sdp", sdp_handle);
2073   dissector_add("bctp.tpi", 0x20, sdp_handle);
2074 }