aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-asf.c
blob: e42a0c263a230378b43af37135efde0fda86b4aa (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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/* packet-asf.c
 * Routines for ASF packet dissection
 *
 * Duncan Laurie <duncan@sun.com>
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-rmcp.c
 *
 * 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.
 */

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

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

/*
 * See
 *	http://www.dmtf.org/standards/standard_alert.php
 *	http://www.dmtf.org/standards/documents/ASF/DSP0136.pdf
 */

#define RMCP_CLASS_ASF 0x06

static int proto_asf = -1;
static int hf_asf_iana = -1;
static int hf_asf_type = -1;
static int hf_asf_tag = -1;
static int hf_asf_len = -1;
static int hf_asf_rssp_status_code = -1;
static int hf_asf_mgt_console_id = -1;
static int hf_asf_client_id = -1;
static int hf_asf_payload = -1;
static int hf_asf_payload_type = -1;
static int hf_asf_payload_len = -1;
static int hf_asf_payload_data = -1;
static int hf_asf_auth_alg = -1;
static int hf_asf_integrity_alg = -1;
static int hf_asf_reserved = -1;

static dissector_handle_t data_handle;
static gint ett_asf = -1;
static gint ett_asf_payload = -1;
static gint ett_asf_alg_payload = -1;

#define ASF_TYPE_RESET				0x10
#define ASF_TYPE_PWR_UP				0x11
#define ASF_TYPE_PWR_DOWN			0x12
#define ASF_TYPE_PWR_CYCLE			0x13
#define ASF_TYPE_PRES_PONG			0x40
#define ASF_TYPE_CAP_RESP			0x41
#define ASF_TYPE_SYS_STATE_RESP		0x42
#define ASF_TYPE_OPEN_SESS_RESP		0x43
#define ASF_TYPE_CLOSE_SESS_RESP	0x44
#define ASF_TYPE_PRES_PING			0x80
#define ASF_TYPE_CAP_RQST			0x81
#define ASF_TYPE_SYS_STATE_RQST		0x82
#define ASF_TYPE_OPEN_SESS_RQST		0x83
#define ASF_TYPE_CLOSE_SESS_RQST	0x84
#define ASF_TYPE_RAKP_MSG_1			0xC0
#define ASF_TYPE_RAKP_MSG_2			0xC1
#define ASF_TYPE_RAKP_MSG_3			0xC2

static const value_string asf_type_vals[] = {
	{ ASF_TYPE_RESET, "Reset" },
	{ ASF_TYPE_PWR_UP, "Power-up" },
	{ ASF_TYPE_PWR_DOWN, "Unconditional Power-down" },
	{ ASF_TYPE_PWR_CYCLE, "Power Cycle" },
	{ ASF_TYPE_PRES_PONG, "Presence Pong" },
	{ ASF_TYPE_CAP_RESP, "Capabilities Response" },
	{ ASF_TYPE_SYS_STATE_RESP, "System State Response" },
	{ ASF_TYPE_OPEN_SESS_RESP, "Open Session Response" },
	{ ASF_TYPE_CLOSE_SESS_RESP, "Close Session Response" },
	{ ASF_TYPE_PRES_PING, "Presence Ping" },
	{ ASF_TYPE_CAP_RQST, "Capabilities Request" },
	{ ASF_TYPE_SYS_STATE_RQST, "System State Request" },
	{ ASF_TYPE_OPEN_SESS_RQST, "Open Session Request" },
	{ ASF_TYPE_CLOSE_SESS_RQST, "Close Session Request" },
	{ ASF_TYPE_RAKP_MSG_1, "RAKP Message 1" },
	{ ASF_TYPE_RAKP_MSG_2, "RAKP Message 2" },
	{ ASF_TYPE_RAKP_MSG_3, "RAKP Message 3" },
	{ 0x00, NULL }
};

static const value_string asf_rssp_status_code_vals[] = {
	{ 0x00, "No errors" },
	{ 0x01, "Insufficient resources to create a session" },
	{ 0x02, "Invalid session ID" },
	{ 0x03, "Invalid payload type" },
	{ 0x04, "Invalid authentication algorithm" },
	{ 0x05, "Invalid integrity algorithm" },
	{ 0x06, "No matching authentication payload" },
	{ 0x07, "No matching integrity payload" },
	{ 0x00, NULL }
};

#define ASF_PAYLOAD_TYPE_NONE			0x00
#define ASF_PAYLOAD_TYPE_AUTHENTICATION	0x01
#define ASF_PAYLOAD_TYPE_INTEGRITY		0x02

static const value_string asf_payload_type_vals[] = {
	{ ASF_PAYLOAD_TYPE_NONE, "No payload present (end of list)" },
	{ ASF_PAYLOAD_TYPE_AUTHENTICATION, "Authentication algorithm payload" },
	{ ASF_PAYLOAD_TYPE_INTEGRITY, "Integrity algorithm payload" },
	{ 0x00, NULL }
};

static const value_string asf_authentication_type_vals[] = {
	{ 0x01, "RAKP-HMAC-SHA1" },
	{ 0x00, NULL }
};

static const value_string asf_integrity_type_vals[] = {
	{ 0x01, "HMAC-SHA1-96" },
	{ 0x00, NULL }
};

static void dissect_asf_open_session_request(tvbuff_t *tvb, proto_tree *tree,
	gint offset, gint len);
static void dissect_asf_open_session_response(tvbuff_t *tvb, proto_tree *tree,
	gint offset, gint len);
static void dissect_asf_payloads(tvbuff_t *tvb, proto_tree *tree,
	gint offset, gint len);
static void dissect_asf_payload_authentication(tvbuff_t *tvb, proto_tree *tree,
	gint offset, gint len);
static void dissect_asf_payload_integrity(tvbuff_t *tvb, proto_tree *tree,
	gint offset, gint len);

static int
dissect_asf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	proto_tree	*asf_tree = NULL;
	proto_item	*ti;
	guint8		type;
	guint8		len;
	tvbuff_t	*next_tvb;

	col_set_str(pinfo->cinfo, COL_PROTOCOL, "ASF");

	col_clear(pinfo->cinfo, COL_INFO);

	type = tvb_get_guint8(tvb, 4);
	len = tvb_get_guint8(tvb, 7);

	if (check_col(pinfo->cinfo, COL_INFO))
		col_add_str(pinfo->cinfo, COL_INFO,
			val_to_str(type, asf_type_vals, "Unknown (0x%02x)"));

	if (tree) {
		ti = proto_tree_add_item(tree, proto_asf, tvb, 0, 8, FALSE);
		asf_tree = proto_item_add_subtree(ti, ett_asf);
		proto_tree_add_item(asf_tree, hf_asf_iana, tvb, 0, 4, FALSE);
		proto_tree_add_item(asf_tree, hf_asf_type, tvb, 4, 1, FALSE);
		proto_tree_add_item(asf_tree, hf_asf_tag, tvb, 5, 1, FALSE);
		proto_tree_add_item(asf_tree, hf_asf_len, tvb, 7, 1, FALSE);
	}

	if (len) {
		switch(type) {
		case ASF_TYPE_OPEN_SESS_RQST:
			dissect_asf_open_session_request(tvb, asf_tree, 8, len);
			break;
		case ASF_TYPE_OPEN_SESS_RESP:
			dissect_asf_open_session_response(tvb, asf_tree, 8, len);
			break;
		
		/* TODO: Add the rest as captures become available to test. */
		
		default:
			next_tvb = tvb_new_subset(tvb, 8, len, len);
			call_dissector(data_handle, next_tvb, pinfo, tree);
			break;
		}
	}
	return 8 + len;
}

static void dissect_asf_open_session_request(tvbuff_t *tvb, proto_tree *tree,
	gint offset, gint len)
{
	proto_tree_add_item(tree, hf_asf_mgt_console_id, tvb, offset, 4, FALSE);
	offset += 4;
	len -= 4;
	dissect_asf_payloads(tvb, tree, offset, len);
}

static void dissect_asf_open_session_response(tvbuff_t *tvb, proto_tree *tree,
	gint offset, gint len)
{
	proto_tree_add_item(tree, hf_asf_rssp_status_code, tvb, offset, 1, FALSE);
	proto_tree_add_item(tree, hf_asf_mgt_console_id, tvb, offset + 4, 4, FALSE);
	proto_tree_add_item(tree, hf_asf_client_id, tvb, offset + 8, 4, FALSE);
	offset += 12;
	len -= 12;
	dissect_asf_payloads(tvb, tree, offset, len);
}	

static void dissect_asf_payloads(tvbuff_t *tvb, proto_tree *tree,
	gint offset, gint len)
{
	guint8 ptype;
	guint16 plen;
	proto_item *ti;
	proto_tree *ptree;

	while ( len >= 4 )
	{
		ptype = tvb_get_guint8(tvb, offset);
		plen = tvb_get_ntohs(tvb, offset + 2);
		
		ti = proto_tree_add_none_format(tree, hf_asf_payload, tvb, offset,
			plen, "%s: %u bytes",
			val_to_str(ptype, asf_payload_type_vals, "Unknown (%u)"), plen);
		ptree = proto_item_add_subtree(ti, ett_asf_payload);
		proto_tree_add_item(ptree, hf_asf_payload_type, tvb, offset, 1, FALSE);
		proto_tree_add_item(ptree, hf_asf_payload_len, tvb, offset + 2, 2, FALSE);
		if ( ptype && (plen > 4) )
		{
			switch ( ptype )
			{
				case ASF_PAYLOAD_TYPE_AUTHENTICATION:
					dissect_asf_payload_authentication(tvb, ptree,
						offset + 4, plen - 4);
					break;
				case ASF_PAYLOAD_TYPE_INTEGRITY:
					dissect_asf_payload_integrity(tvb, ptree,
						offset + 4, plen - 4);
					break;
				default:
					proto_tree_add_item(ptree, hf_asf_payload_data, tvb,
						offset + 4, plen - 4, FALSE);
					break;
			}
		}
		offset += plen;
		len -= plen;
	}
}

static void dissect_asf_payload_authentication(tvbuff_t *tvb, proto_tree *tree,
	gint offset, gint len)
{
	guint8 alg;
	proto_item *ti;
	proto_tree *atree;

	alg = tvb_get_guint8(tvb, offset);
	ti = proto_tree_add_none_format(tree, hf_asf_payload_data, tvb, offset,
		len, "Authentication Algorithm: %s",
		val_to_str(alg, asf_authentication_type_vals, "Unknown (%u)"));
	atree = proto_item_add_subtree(ti, ett_asf_alg_payload);
	proto_tree_add_item(atree, hf_asf_auth_alg, tvb, offset, 1, FALSE);
	proto_tree_add_item(atree, hf_asf_reserved, tvb, offset + 1, len - 1, FALSE);
}

static void dissect_asf_payload_integrity(tvbuff_t *tvb, proto_tree *tree,
	gint offset, gint len)
{
	guint8 alg;
	proto_item *ti;
	proto_tree *atree;

	alg = tvb_get_guint8(tvb, offset);
	ti = proto_tree_add_none_format(tree, hf_asf_payload_data, tvb, offset,
		len, "Integrity Algorithm: %s",
		val_to_str(alg, asf_integrity_type_vals, "Unknown (%u)"));
	atree = proto_item_add_subtree(ti, ett_asf_alg_payload);
	proto_tree_add_item(atree, hf_asf_integrity_alg, tvb, offset, 1, FALSE);
	proto_tree_add_item(atree, hf_asf_reserved, tvb, offset + 1, len - 1, FALSE);
}

void
proto_register_asf(void)
{
	static hf_register_info hf[] = {
		{ &hf_asf_iana, {
			"IANA Enterprise Number", "asf.iana",
			FT_UINT32, BASE_DEC|BASE_EXT_STRING, &sminmpec_values_ext, 0,
			"IANA Enterprise Number", HFILL }},
		{ &hf_asf_type, {
			"Message Type", "asf.type",
			FT_UINT8, BASE_HEX, VALS(asf_type_vals), 0,
			"ASF Message Type", HFILL }},
		{ &hf_asf_tag, {
			"Message Tag", "asf.tag",
			FT_UINT8, BASE_HEX, NULL, 0,
			"ASF Message Tag", HFILL }},
		{ &hf_asf_len, {
			"Data Length", "asf.len",
			FT_UINT8, BASE_DEC, NULL, 0,
			"ASF Data Length", HFILL }},
		{ &hf_asf_rssp_status_code, {
			"Status Code", "asf.rssp_status_code",
			FT_UINT8, BASE_DEC, VALS(asf_rssp_status_code_vals), 0,
			"Identifies the status of the previous message", HFILL }},
		{ &hf_asf_mgt_console_id, {
			"Mgt Console Session ID", "asf.mgt_console_id",
			FT_UINT32, BASE_DEC, NULL, 0,
			NULL, HFILL }},
		{ &hf_asf_client_id, {
			"Managed Client Session ID", "asf.client_id",
			FT_UINT32, BASE_DEC, NULL, 0,
			NULL, HFILL }},
		{ &hf_asf_payload, {
			"Payload", "asf.payload",
			FT_NONE, BASE_NONE, NULL, 0,
			NULL, HFILL }},
		{ &hf_asf_payload_type, {
			"Payload Type", "asf.payload.type",
			FT_UINT8, BASE_DEC, VALS(asf_payload_type_vals), 0,
			"Identifies the type of payload that follows", HFILL }},
		{ &hf_asf_payload_len, {
			"Payload Length", "asf.payload.len",
			FT_UINT16, BASE_DEC, NULL, 0,
			"The total length in bytes of the payload including the header",
			HFILL }},
		{ &hf_asf_payload_data, {
			"Data", "asf.payload.data",
			FT_NONE, BASE_NONE, NULL, 0,
			NULL, HFILL }},
		{ &hf_asf_auth_alg, {
			"Authentication Algorithm", "asf.auth_alg",
			FT_UINT8, BASE_DEC, VALS(asf_authentication_type_vals), 0,
			NULL, HFILL }},
		{ &hf_asf_integrity_alg, {
			"Integrity Algorithm", "asf.integrity_alg",
			FT_UINT8, BASE_DEC, VALS(asf_integrity_type_vals), 0,
			NULL, HFILL }},
		{ &hf_asf_reserved, {
			"Reserved", "asf.reserved",
			FT_NONE, BASE_NONE, NULL, 0,
			NULL, HFILL }},
	};
	static gint *ett[] = {
		&ett_asf,
		&ett_asf_payload,
		&ett_asf_alg_payload
	};

	proto_asf = proto_register_protocol(
		"Alert Standard Forum", "ASF", "asf");

	proto_register_field_array(proto_asf, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_asf(void)
{
	dissector_handle_t asf_handle;

	data_handle = find_dissector("data");

	asf_handle = create_dissector_handle(dissect_asf, proto_asf);
	dissector_add("rmcp.class", RMCP_CLASS_ASF, asf_handle);
}