Note that for THE3GPP_IPV6_DNS_SERVERS we probably *do* need to handle
[obnox/wireshark/wip.git] / packet-rtp-events.c
1 /* packet-rtp-events.c
2  *
3  * Routines for RFC 2833 RTP Events dissection
4  * Copyright 2003, Kevin A. Noll <knoll[AT]poss.com>
5  *
6  * $Id: packet-rtp-events.c,v 1.3 2003/11/27 21:20:46 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 /*
28  * This dissector tries to dissect RTP Events.
29  */
30
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <glib.h>
37 #include <epan/packet.h>
38 #include "prefs.h"
39
40 #include <stdio.h>
41 #include <string.h>
42 #include "packet-rtp-events.h"
43
44 /*  rtp_event_payload_type_value is the value used globally
45         to set the appropriate payload type
46     saved_pt_value is a temporary place to save the value
47         so we can properly reinitialize when the settings
48         get changed
49 */
50 static guint rtp_event_payload_type_value = 101;
51 static guint saved_payload_type_value;
52
53
54 /* RTP Event Fields */
55
56 static int proto_rtp_events          = -1;
57
58 static int hf_rtp_events_event = -1; /* one byte */
59 static int hf_rtp_events_end = -1; /* one bit */
60 static int hf_rtp_events_reserved = -1; /* one bit */
61 static int hf_rtp_events_volume = -1; /* six bits */
62 static int hf_rtp_events_duration = -1; /* sixteen bits */
63
64
65 /* RTP Events fields defining a subtree */
66
67 static gint ett_rtp_events           = -1;
68
69 void
70 proto_reg_handoff_rtp_events(void);
71
72 static void
73 dissect_rtp_events( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
74 {
75         proto_item *ti            = NULL;
76         proto_tree *rtp_events_tree     = NULL;
77         unsigned int offset       = 0;
78
79         guint8      rtp_evt;
80         guint8      octet;
81
82         if ( check_col( pinfo->cinfo, COL_PROTOCOL ) )
83           {
84             col_set_str( pinfo->cinfo, COL_PROTOCOL, "RTP EVENT" );
85           }
86         if (check_col(pinfo->cinfo, COL_INFO))
87                 col_clear(pinfo->cinfo, COL_INFO);
88
89
90         /* Get event fields */
91
92         rtp_evt = tvb_get_guint8(tvb, offset );
93
94         if ( check_col( pinfo->cinfo, COL_INFO) )
95           {
96                 col_add_fstr( pinfo->cinfo, COL_INFO,
97                     "Payload type=RTP Event, %s",
98                     val_to_str( rtp_evt, rtp_event_type_values, "Unknown (%u)" ));
99
100
101           }
102
103         if ( tree )
104           {
105             ti = proto_tree_add_item( tree, proto_rtp_events, tvb, offset, -1, FALSE );
106             rtp_events_tree = proto_item_add_subtree( ti, ett_rtp_events );
107
108             proto_tree_add_uint ( rtp_events_tree, hf_rtp_events_event, tvb, offset, 1, rtp_evt);
109
110             octet = tvb_get_guint8(tvb, offset +1 );
111             proto_tree_add_boolean (rtp_events_tree, hf_rtp_events_end, tvb, offset+1, 1, octet);
112             proto_tree_add_boolean (rtp_events_tree, hf_rtp_events_reserved, tvb, offset+1, 1, octet);
113             proto_tree_add_uint ( rtp_events_tree, hf_rtp_events_volume, tvb, offset+1, 1, octet);
114
115             proto_tree_add_item ( rtp_events_tree, hf_rtp_events_duration, tvb, offset+2, 2, FALSE);
116           }
117 }
118
119
120 void
121 proto_register_rtp_events(void)
122 {
123
124         module_t *rtp_events_module;
125
126         static hf_register_info hf[] =
127         {
128                 {
129                         &hf_rtp_events_event,
130                         {
131                                 "Event ID",
132                                 "rtpevent.event_id",
133                                 FT_UINT8,
134                                 BASE_DEC,
135                                 VALS(rtp_event_type_values),
136                                 0x0,
137                                 "", HFILL
138                         }
139                 },
140                 {
141                         &hf_rtp_events_end,
142                         {
143                                 "End of Event",
144                                 "rtpevent.end_of_event",
145                                 FT_BOOLEAN,
146                                 8,
147                                 NULL,
148                                 0x80,
149                                 "", HFILL
150                         }
151                 },
152                 {
153                         &hf_rtp_events_reserved,
154                         {
155                                 "Reserved",
156                                 "rtpevent.reserved",
157                                 FT_BOOLEAN,
158                                 8,
159                                 NULL,
160                                 0x40,
161                                 "", HFILL
162                         }
163                 },
164                 {
165                         &hf_rtp_events_volume,
166                         {
167                                 "Volume",
168                                 "rtpevent.volume",
169                                 FT_UINT8,
170                                 BASE_DEC,
171                                 NULL,
172                                 0x3F,
173                                 "", HFILL
174                         }
175                 },
176
177                 {
178                         &hf_rtp_events_duration,
179                         {
180                                 "Event Duration",
181                                 "rtpevent.duration",
182                                 FT_UINT16,
183                                 BASE_DEC,
184                                 NULL,
185                                 0x0,
186                                 "", HFILL
187                         }
188                 },
189
190         };
191
192         static gint *ett[] =
193         {
194                 &ett_rtp_events,
195         };
196
197
198         proto_rtp_events = proto_register_protocol("RFC 2833 RTP Event", "RTP Event", "rtpevent");
199         proto_register_field_array(proto_rtp_events, hf, array_length(hf));
200         proto_register_subtree_array(ett, array_length(ett));
201
202
203     /* Register preferences */
204     rtp_events_module = prefs_register_protocol (proto_rtp_events, proto_reg_handoff_rtp_events);
205     prefs_register_uint_preference (rtp_events_module,
206                                     "event_payload_type_value", "Payload Type for RFC2833 RTP Events",
207                                     "This is the value of the Payload Type field"
208                                     "that specifies RTP Events", 10,
209                                     &rtp_event_payload_type_value);
210 }
211
212
213
214 void
215 proto_reg_handoff_rtp_events(void)
216 {
217         static dissector_handle_t rtp_events_handle;
218         static int rtp_events_prefs_initialized = FALSE;
219
220         if (!rtp_events_prefs_initialized) {
221                 rtp_events_handle = create_dissector_handle(dissect_rtp_events, proto_rtp_events);
222                 rtp_events_prefs_initialized = TRUE;
223         }
224         else {
225                 dissector_delete("rtp.pt", saved_payload_type_value, rtp_events_handle);
226         }
227
228         saved_payload_type_value = rtp_event_payload_type_value;
229         /* rtp_event_payload_type_value is set from preferences */
230
231         dissector_add("rtp.pt", saved_payload_type_value, rtp_events_handle);
232
233 }