aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-rtp-events.c
blob: 9e37214baf84055141786597ddbee071163a4922 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/* packet-rtp-events.c
 *
 * Routines for RFC 2833 RTP Events dissection
 * Copyright 2003, Kevin A. Noll <knoll[AT]poss.com>
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * Ref http://www.ietf.org/rfc/rfc4733.txt?number=4733
 */

/*
 * This dissector tries to dissect RTP Events.
 *
 * Cisco NSE is now supported, additions by
 *                Gonzalo Salgueiro <gsalguei@cisco.com>
 *          Chidambaram Arunachalam <carunach@cisco.com>
 * Copyright 2008, Cisco Systems, Inc.
 */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <glib.h>
#include <epan/packet.h>
#include <epan/prefs.h>

#include "packet-rtp-events.h"
#include "packet-rtp.h"
#include <epan/tap.h>

/*  rtp_event_payload_type_value is the value used globally
	to set the appropriate payload type
*/
static guint rtp_event_payload_type_value = 101;

/*  cisco_nse_pt_value is used globally
	to set the appropriate Cisco NSE payload type value
 */
static guint cisco_nse_pt_value = 100;


/* RTP Event Fields */

static int proto_rtp_events          = -1;
static int rtp_event_tap = -1;

static int hf_rtp_events_event = -1; /* one byte */
static int hf_rtp_events_end = -1; /* one bit */
static int hf_rtp_events_reserved = -1; /* one bit */
static int hf_rtp_events_volume = -1; /* six bits */
static int hf_rtp_events_duration = -1; /* sixteen bits */


/* RTP Events fields defining a subtree */

static gint ett_rtp_events           = -1;

void
proto_reg_handoff_rtp_events(void);

static struct _rtp_event_info rtp_event_info;

static void
dissect_rtp_events( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
{
	proto_item *ti            = NULL;
	proto_tree *rtp_events_tree     = NULL;
	unsigned int offset       = 0;
	struct _rtp_conversation_info *p_conv_data = NULL;

	guint8      rtp_evt;
	guint8      octet;

	col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTP EVENT");
	col_clear(pinfo->cinfo, COL_INFO);


	/* Get event fields */

	rtp_evt = tvb_get_guint8(tvb, offset );

	/* get tap info */
	rtp_event_info.info_rtp_evt = rtp_evt;

	p_conv_data = p_get_proto_data(pinfo->fd, proto_get_id_by_filter_name("rtp"));
	if (p_conv_data)
		rtp_event_info.info_setup_frame_num = p_conv_data->frame_number;
	else
		rtp_event_info.info_setup_frame_num = 0;


	if ( check_col( pinfo->cinfo, COL_INFO) )
	{
		col_add_fstr( pinfo->cinfo, COL_INFO,
		    "Payload type=RTP Event, %s",
		    val_to_str( rtp_evt, rtp_event_type_values, "Unknown (%u)" ));
	}

	ti = proto_tree_add_item( tree, proto_rtp_events, tvb, offset, -1, FALSE );
	rtp_events_tree = proto_item_add_subtree( ti, ett_rtp_events );

	proto_tree_add_uint ( rtp_events_tree, hf_rtp_events_event, tvb, offset, 1, rtp_evt);
	offset++;
	octet = tvb_get_guint8(tvb, offset);
	proto_tree_add_boolean (rtp_events_tree, hf_rtp_events_end, tvb, offset, 1, octet);
	proto_tree_add_boolean (rtp_events_tree, hf_rtp_events_reserved, tvb, offset, 1, octet);
	proto_tree_add_uint ( rtp_events_tree, hf_rtp_events_volume, tvb, offset, 1, octet);
	offset++;

	/* The duration field indicates the duration of the event or segment
	 * being reported, in timestamp units.
	 */
	rtp_event_info.info_duration = tvb_get_ntohs(tvb, offset); 
	proto_tree_add_item ( rtp_events_tree, hf_rtp_events_duration, tvb, offset, 2, FALSE);

	/* set the end info for the tap */
	if (octet & 0x80)
	{
		rtp_event_info.info_end = TRUE;
	} else
	{
		rtp_event_info.info_end = FALSE;
	}

	/* Make end-of-event packets obvious in the info column */
	if ((octet & 0x80))
	{
		col_append_str(pinfo->cinfo, COL_INFO, " (end)");
	}

	tap_queue_packet(rtp_event_tap, pinfo, &rtp_event_info);
}


void
proto_register_rtp_events(void)
{

	module_t *rtp_events_module;

	static hf_register_info hf[] =
	{
		{
			&hf_rtp_events_event,
			{
				"Event ID",
				"rtpevent.event_id",
				FT_UINT8,
				BASE_DEC,
				VALS(rtp_event_type_values),
				0x0,
				NULL, HFILL
			}
		},
		{
			&hf_rtp_events_end,
			{
				"End of Event",
				"rtpevent.end_of_event",
				FT_BOOLEAN,
				8,
				NULL,
				0x80,
				NULL, HFILL
			}
		},
		{
			&hf_rtp_events_reserved,
			{
				"Reserved",
				"rtpevent.reserved",
				FT_BOOLEAN,
				8,
				NULL,
				0x40,
				NULL, HFILL
			}
		},
		{
			&hf_rtp_events_volume,
			{
				"Volume",
				"rtpevent.volume",
				FT_UINT8,
				BASE_DEC,
				NULL,
				0x3F,
				NULL, HFILL
			}
		},

		{
			&hf_rtp_events_duration,
			{
				"Event Duration",
				"rtpevent.duration",
				FT_UINT16,
				BASE_DEC,
				NULL,
				0x0,
				NULL, HFILL
			}
		},

	};

	static gint *ett[] =
	{
		&ett_rtp_events,
	};


	proto_rtp_events = proto_register_protocol("RFC 2833 RTP Event", "RTP Event", "rtpevent");
	proto_register_field_array(proto_rtp_events, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));


	/* Register preferences */
	rtp_events_module = prefs_register_protocol (proto_rtp_events, proto_reg_handoff_rtp_events);
	prefs_register_uint_preference (rtp_events_module,
                                    "event_payload_type_value", "Payload Type for RFC2833 RTP Events",
                                    "This is the value of the Payload Type field"
                                    " that specifies RTP Events", 10,
                                    &rtp_event_payload_type_value);


	prefs_register_uint_preference (rtp_events_module,
                                    "cisco_nse_payload_type_value", "Payload Type for Cisco Named Signaling Events",
                                    "This is the value of the Payload Type field"
                                    " that specifies Cisco Named Signaling Events", 10,
                                    &cisco_nse_pt_value);

	register_dissector("rtpevent", dissect_rtp_events, proto_rtp_events);
	rtp_event_tap = register_tap("rtpevent");
}



void
proto_reg_handoff_rtp_events(void)
{
	static dissector_handle_t rtp_events_handle;
	/* saved_payload_type_value is a temporary place to save */
	/* the value so we can properly reinitialize when the    */
	/* settings get changed.                                 */
	static guint saved_payload_type_value;
	static guint saved_cisco_nse_pt_value;
	static gboolean rtp_events_prefs_initialized = FALSE;

	if (!rtp_events_prefs_initialized) {
		rtp_events_handle = find_dissector("rtpevent");
		dissector_add_string("rtp_dyn_payload_type", "telephone-event", rtp_events_handle);
		dissector_add_string("rtp_dyn_payload_type", "X-NSE", rtp_events_handle);
		rtp_events_prefs_initialized = TRUE;
	}
	else {
		dissector_delete_uint("rtp.pt", saved_payload_type_value, rtp_events_handle);
		dissector_delete_uint("rtp.pt", saved_cisco_nse_pt_value, rtp_events_handle);
	}

	saved_payload_type_value = rtp_event_payload_type_value;
	/* rtp_event_payload_type_value is set from preferences */
	saved_cisco_nse_pt_value = cisco_nse_pt_value;
	/* cisco_nse_pt_value is set from preferences */

	dissector_add_uint("rtp.pt", saved_payload_type_value, rtp_events_handle);
	dissector_add_uint("rtp.pt", saved_cisco_nse_pt_value, rtp_events_handle);
}