summaryrefslogtreecommitdiff
path: root/epan/dissectors/packet-bfcp.c
blob: 67be2f3d319df20589bba072159e85277f86d62d (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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/* packet-bfcp.c
 * Routines for Binary Floor Control Protocol(BFCP) dissection
 * Copyright 2012, Nitinkumar Yemul <nitinkumaryemul@gmail.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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * BFCP Message structure is defined in RFC 4582.
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <glib.h>

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

/* Initialize protocol and registered fields */
static int proto_bfcp = -1;
static gboolean  bfcp_enable_heuristic_dissection = FALSE;


static int hf_bfcp_transaction_initiator = -1;
static int hf_bfcp_primitive = -1;
static int hf_bfcp_payload_length = -1;
static int hf_bfcp_conference_id = -1;
static int hf_bfcp_transaction_id = -1;
static int hf_bfcp_user_id = -1;
static int hf_bfcp_payload = -1;
static int hf_bfcp_attribute_types = -1;
static int hf_bfcp_attribute_length = -1;
static int hf_bfcp_request_status = -1;

/* Initialize subtree pointers */
static gint ett_bfcp = -1;

/* Initialize BFCP primitives */
static const value_string map_bfcp_primitive[] = {
	{ 0,  "<Invalid Primitive>"},
	{ 1,  "FloorRequest"},
	{ 2,  "FloorRelease"},
	{ 3,  "FloorRequestQuery"},
	{ 4,  "FloorRequestStatus"},
	{ 5,  "UserQuery"},
	{ 6,  "UserStatus"},
	{ 7,  "FloorQuery"},
	{ 8,  "FloorStatus"},
	{ 9,  "ChairAction"},
	{ 10, "ChairActionAck"},
	{ 11, "Hello"},
	{ 12, "HelloAck"},
	{ 13, "Error"},
	{ 14, "FloorRequestStatusAck"},
	{ 15, "ErrorAck"},
	{ 16, "FloorStatusAck"},
	{ 17, "Goodbye"},
	{ 18, "GoodbyeAck"},
	{ 0,  NULL},
};

static const value_string map_bfcp_attribute_types[] = {
	{ 0,  "<Invalid Primitive>"},
	{ 1,  "BeneficiaryID"},
	{ 2,  "FloorID"},
	{ 3,  "FloorRequestID"},
	{ 4,  "Priority"},
	{ 5,  "RequestStatus"},
	{ 6,  "ErrorCode"},
	{ 7,  "ErrorInfo"},
	{ 8,  "ParticipantProvidedInfo"},
	{ 9,  "StatusInfo"},
	{ 10, "SupportedAttributes"},
	{ 11, "SupportedPrimitives"},
	{ 12, "UserDisplayName"},
	{ 13, "UserURI"},
	{ 14, "BeneficiaryInformation"},
	{ 15, "FloorRequestInformation"},
	{ 16, "RequestedByInformation"},
	{ 17, "FloorRequestStatus"},
	{ 18, "OverallRequestStatus"},
	{ 0,  NULL},
};

static const value_string map_bfcp_request_status[] = {
	{ 0,  "<Invalid Primitive>"},
	{ 1,  "Pending"},
	{ 2,  "Accepted"},
	{ 3,  "Granted"},
	{ 4,  "Denied"},
	{ 5,  "Cancelled"},
	{ 6,  "Released"},
	{ 7,  "Revoked"},
	{ 0,  NULL},
};

/*Define offset for fields in BFCP packet */
#define BFCP_OFFSET_TRANSACTION_INITIATOR  0
#define BFCP_OFFSET_PRIMITIVE              1
#define BFCP_OFFSET_PAYLOAD_LENGTH         2
#define BFCP_OFFSET_CONFERENCE_ID          4
#define BFCP_OFFSET_TRANSACTION_ID         8
#define BFCP_OFFSET_USER_ID               10
#define BFCP_OFFSET_PAYLOAD               12

/* Code to actually dissect BFCP packets */
static gboolean dissect_bfcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	guint8       first_byte;
	guint8       primitive;
	const gchar *str;
	gint         bfcp_payload_length;
	gint         read_attr = 0;
	proto_tree  *bfcp_tree = NULL;


	/* Size of smallest BFCP packet: 12 octets */
	if (tvb_length(tvb) < 12)
		return FALSE;

	/* Check version and reserved bits in first byte */
	first_byte = tvb_get_guint8(tvb, 0);

	/* If first_byte of bfcp_packet is a combination of the
	 * version and the I bit. The value must be either 0x20 or 0x30
	 * if the bit is set, otherwise it is not BFCP.
	 */
	if ((first_byte != 0x20) && (first_byte != 0x30))
		return FALSE;

	primitive = tvb_get_guint8(tvb, 1);

	if ((primitive < 1) || (primitive > 18))
		return FALSE;

	str = match_strval(primitive, map_bfcp_primitive);
	if (NULL == str)
		return FALSE;

	/* Make entries in Protocol column and Info column on summary display*/
	col_set_str(pinfo->cinfo, COL_PROTOCOL, "BFCP");
	col_add_str(pinfo->cinfo, COL_INFO, str);

	if (tree) {
		proto_item	*ti;
		ti = proto_tree_add_item(tree, proto_bfcp, tvb, 0, -1, ENC_NA);
		bfcp_tree = proto_item_add_subtree(ti, ett_bfcp);

		/* Add items to BFCP tree */
		proto_tree_add_item(bfcp_tree, hf_bfcp_transaction_initiator, tvb,
				    BFCP_OFFSET_TRANSACTION_INITIATOR, 1, ENC_BIG_ENDIAN);
		proto_tree_add_item(bfcp_tree, hf_bfcp_primitive, tvb,
				    BFCP_OFFSET_PRIMITIVE, 1, ENC_BIG_ENDIAN);
		proto_tree_add_item(bfcp_tree, hf_bfcp_payload_length, tvb,
				    BFCP_OFFSET_PAYLOAD_LENGTH, 2, ENC_BIG_ENDIAN);
		proto_tree_add_item(bfcp_tree, hf_bfcp_conference_id, tvb,
				    BFCP_OFFSET_CONFERENCE_ID, 4, ENC_BIG_ENDIAN);
		proto_tree_add_item(bfcp_tree, hf_bfcp_transaction_id, tvb,
				    BFCP_OFFSET_TRANSACTION_ID, 2, ENC_BIG_ENDIAN);
		proto_tree_add_item(bfcp_tree, hf_bfcp_user_id, tvb,
				    BFCP_OFFSET_USER_ID, 2, ENC_BIG_ENDIAN);
	}

	bfcp_payload_length = tvb_get_ntohs(tvb,
					    BFCP_OFFSET_PAYLOAD_LENGTH) * 4;

	while ((tvb_reported_length_remaining(tvb, BFCP_OFFSET_PAYLOAD + read_attr) >= 2) &&
	       ((bfcp_payload_length - read_attr) >= 2))
	{
		proto_item *ti;
		gint        read = 0;
		gint        length;
		guint8      attribute_type;

		first_byte = tvb_get_guint8(tvb, BFCP_OFFSET_PAYLOAD + read_attr);

		/* Padding so continue to next attribute */
		if (first_byte == 0)
		{
			read_attr++;
			continue;
		}

		proto_tree_add_item(bfcp_tree, hf_bfcp_attribute_types, tvb,
				    BFCP_OFFSET_PAYLOAD + read_attr,1, ENC_BIG_ENDIAN);
		attribute_type = (first_byte & 0xFE) >> 1;
		read++;

		ti = proto_tree_add_item(bfcp_tree, hf_bfcp_attribute_length, tvb,
					 BFCP_OFFSET_PAYLOAD + read_attr + read,1, ENC_BIG_ENDIAN);
		length = tvb_get_guint8(tvb, BFCP_OFFSET_PAYLOAD  + read_attr + read);
		read++;

		/* If RequestStatus then show what type of status it is... */
		if (attribute_type == 5)
		{
			proto_tree_add_item(bfcp_tree, hf_bfcp_request_status, tvb,
					    BFCP_OFFSET_PAYLOAD + read_attr + read,1, ENC_BIG_ENDIAN);
			read++;
		}
		if (length >= read)
		{
			proto_tree_add_item(bfcp_tree, hf_bfcp_payload, tvb,
					    BFCP_OFFSET_PAYLOAD + read_attr + read, length-read, ENC_NA);
		}
		else
		{
			expert_add_info_format(pinfo, ti, PI_MALFORMED, PI_ERROR,
					       "Attribute length is too small (%d bytes)", length);
			break;
		}
		read_attr = read_attr + length;
	}
	return TRUE;
}

void proto_reg_handoff_bfcp(void);

void proto_register_bfcp(void)
{
	module_t *bfcp_module;

	static hf_register_info hf[] = {
		{
			&hf_bfcp_transaction_initiator,
			{ "Transaction Initiator", "bfcp.transaction_initiator",
			  FT_BOOLEAN, 8,
			  NULL, 0x10,
			  NULL, HFILL }
		},
		{
			&hf_bfcp_primitive,
			{ "Primitive", "bfcp.primitive",
			  FT_UINT8, BASE_DEC,
			  VALS(map_bfcp_primitive), 0x0,
			  NULL, HFILL }
		},
		{
			&hf_bfcp_payload_length,
			{ "Payload Length", "bfcp.payload_length",
			  FT_UINT16, BASE_DEC,
			  NULL, 0x0,
			  NULL, HFILL }
		},
		{
			&hf_bfcp_conference_id,
			{ "Conference ID", "bfcp.conference_id",
			  FT_UINT32, BASE_DEC,
			  NULL, 0x0,
			  NULL, HFILL }
		},
		{
			&hf_bfcp_transaction_id,
			{ "Transaction ID", "bfcp.transaction_id",
			  FT_UINT16, BASE_DEC,
			  NULL, 0x0,
			  NULL, HFILL }
		},
		{
			&hf_bfcp_user_id,
			{ "User ID", "bfcp.user_id",
			  FT_UINT16, BASE_DEC,
			  NULL, 0x0,
			  NULL, HFILL }
		},
		{
			&hf_bfcp_payload,
			{ "Payload", "bfcp.payload",
			  FT_BYTES, BASE_NONE,
			  NULL, 0x0, NULL,
			  HFILL }
		},
		{
			&hf_bfcp_attribute_types,
			{ "Attribute Type", "bfcp.attribute_type",
			  FT_UINT8, BASE_DEC,
			  VALS(map_bfcp_attribute_types), 0xFE,
			  NULL, HFILL }
		},
		{
			&hf_bfcp_attribute_length,
			{ "Attribute Length", "bfcp.attribute_length",
			  FT_UINT16, BASE_DEC,
			  NULL, 0x0,
			  NULL, HFILL }
		},
		{
			&hf_bfcp_request_status,
			{ "Request Status", "bfcp.request_status",
			  FT_UINT8, BASE_DEC,
			  VALS(map_bfcp_request_status), 0x0,
			  NULL, HFILL }
		}
	};

	static gint *ett[] = {
		&ett_bfcp
	};

	/* Register protocol name and description */
	proto_bfcp = proto_register_protocol("Binary Floor Control Protocol",
				"BFCP", "bfcp");

	bfcp_module = prefs_register_protocol(proto_bfcp,
				proto_reg_handoff_bfcp);

	prefs_register_bool_preference(bfcp_module, "enable",
		      "Enable BFCP heuristic dissection",
		      "Enable BFCP heuristic dissection (default is disabled)",
		      &bfcp_enable_heuristic_dissection);

	/* Register field and subtree array */
	proto_register_field_array(proto_bfcp, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));
}

void proto_reg_handoff_bfcp(void)
{
	static gboolean prefs_initialized = FALSE;

	/* "Decode As" is always available;
	 *  Heuristic dissection in disabled by default since
	 *  the heuristic is quite weak.
	 */
	if (!prefs_initialized)
	{
		dissector_handle_t bfcp_handle;

		heur_dissector_add("tcp", dissect_bfcp, proto_bfcp);
		heur_dissector_add("udp", dissect_bfcp, proto_bfcp);
		bfcp_handle = new_create_dissector_handle(dissect_bfcp, proto_bfcp);
		dissector_add_handle("tcp.port", bfcp_handle);
		dissector_add_handle("udp.port", bfcp_handle);
		prefs_initialized = TRUE;
	}

	heur_dissector_set_enabled("tcp", dissect_bfcp, proto_bfcp,
				   bfcp_enable_heuristic_dissection);

	heur_dissector_set_enabled("udp", dissect_bfcp, proto_bfcp,
				   bfcp_enable_heuristic_dissection);
}