aboutsummaryrefslogtreecommitdiffstats
path: root/packet-rmp.c
blob: 333b62baf6bd5c9a0d93d47fc8dc28815dfa8364 (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
/* packet-rmp.c
 * Routines for HP remote management protocol
 * Gilbert Ramirez <jochen@scram.de>
 *
 * $Id: packet-rmp.c,v 1.2 2003/03/03 14:08:39 jmayer Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * 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.
 */

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

#include <glib.h>
#include <epan/packet.h>
#include "etypes.h"

#include "packet-hpext.h"

static dissector_handle_t data_handle;

static int proto_rmp = -1;

static int hf_rmp_type = -1;
static int hf_rmp_retcode = -1;
static int hf_rmp_seqnum = -1;
static int hf_rmp_sessionid = -1;
static int hf_rmp_version = -1;
static int hf_rmp_machtype = -1;
static int hf_rmp_filename = -1;
static int hf_rmp_offset = -1;
static int hf_rmp_size = -1;

static gint ett_rmp = -1;

/*
 *  Possible values for "rmp_type" fields.
 */

#define RMP_BOOT_REQ    1       /* boot request packet */
#define RMP_BOOT_REPL   129     /* boot reply packet */
#define RMP_READ_REQ    2       /* read request packet */
#define RMP_READ_REPL   130     /* read reply packet */
#define RMP_BOOT_DONE   3       /* boot complete packet */

/*
 *  RMP error codes
 */

#define RMP_E_OKAY      0
#define RMP_E_EOF       2       /* read reply: returned end of file */
#define RMP_E_ABORT     3       /* abort operation */
#define RMP_E_BUSY      4       /* boot reply: server busy */
#define RMP_E_TIMEOUT   5       /* lengthen time out (not implemented) */
#define RMP_E_NOFILE    16      /* boot reply: file does not exist */
#define RMP_E_OPENFILE  17      /* boot reply: file open failed */
#define RMP_E_NODFLT    18      /* boot reply: default file does not exist */
#define RMP_E_OPENDFLT  19      /* boot reply: default file open failed */
#define RMP_E_BADSID    25      /* read reply: bad session ID */
#define RMP_E_BADPACKET 27      /* Bad packet detected */

const value_string rmp_type_vals[] = {
	{ RMP_BOOT_REQ,       "Boot Request" },
	{ RMP_BOOT_REPL,      "Boot Reply" },
	{ RMP_READ_REQ,       "Read Request" },
	{ RMP_READ_REPL,      "Read Reply" },
	{ RMP_BOOT_DONE,      "Boot Done" },
	{ 0x00,               NULL }
};

const value_string rmp_error_vals[] = {
	{ RMP_E_OKAY,         "OK" },
	{ RMP_E_EOF,          "End Of File" },
	{ RMP_E_ABORT,        "Abort Operation" },
	{ RMP_E_BUSY,         "Server Busy" },
	{ RMP_E_TIMEOUT,      "Lengthen Time Out" },
	{ RMP_E_NOFILE,       "File Does Not Exist" },
	{ RMP_E_OPENFILE,     "File Open Failed" },
	{ RMP_E_NODFLT,       "Default File Does Not Exist" },
	{ RMP_E_OPENDFLT,     "Default File Open Failed" },
	{ RMP_E_BADSID,       "Bad Session Id" },
	{ RMP_E_OPENDFLT,     "Bad Packet Detected" },
	{ 0x00,               NULL }
};

static void
dissect_rmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	proto_tree	*rmp_tree = NULL;
	proto_item	*ti = NULL;
	guint8		type, len;

	if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
		col_set_str(pinfo->cinfo, COL_PROTOCOL, "RMP");
	}

	if (check_col(pinfo->cinfo, COL_INFO)) {
		col_clear(pinfo->cinfo, COL_INFO);
	}

	type = tvb_get_guint8(tvb, 0);

	if (check_col(pinfo->cinfo, COL_INFO)) {
		col_set_str(pinfo->cinfo, COL_INFO,
		    val_to_str(type, rmp_type_vals, "Unknown Type"));
	}

	if (tree) {
		ti = proto_tree_add_item(tree, proto_rmp, tvb, 0, -1, FALSE);
		rmp_tree = proto_item_add_subtree(ti, ett_rmp);
		proto_tree_add_uint(rmp_tree, hf_rmp_type, tvb, 0, 1, type);

		switch (type) {
			case RMP_BOOT_REQ:
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_retcode, tvb, 1, 1, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_seqnum, tvb, 2, 4, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_sessionid, tvb, 6, 2, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_version, tvb, 8, 2, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_machtype, tvb, 10, 20, FALSE);
				/* The remaining fields are optional */
				if(!tvb_offset_exists(tvb, 30))
					return;
				len = tvb_get_guint8(tvb, 30);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_filename, tvb, 30, 1, FALSE);
				if(tvb_offset_exists(tvb, len+31))
					call_dissector(data_handle,
					    tvb_new_subset(tvb, len+31, -1, -1),
					    pinfo, tree);
				break;

			case RMP_BOOT_REPL:
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_retcode, tvb, 1, 1, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_seqnum, tvb, 2, 4, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_sessionid, tvb, 6, 2, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_version, tvb, 8, 2, FALSE);
				len = tvb_get_guint8(tvb, 10);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_filename, tvb, 10, 1, FALSE);
				if(tvb_offset_exists(tvb, len+11))
					call_dissector(data_handle,
					    tvb_new_subset(tvb, len+11, -1, -1),
					    pinfo, tree);
				break;

			case RMP_READ_REQ:
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_retcode, tvb, 1, 1, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_offset, tvb, 2, 4, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_sessionid, tvb, 6, 2, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_size, tvb, 8, 2, FALSE);
				if(tvb_offset_exists(tvb, 10))
					call_dissector(data_handle,
					    tvb_new_subset(tvb, 10, -1, -1),
					    pinfo, tree);
				break;

			case RMP_READ_REPL:
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_retcode, tvb, 1, 1, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_offset, tvb, 2, 4, FALSE);
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_sessionid, tvb, 6, 2, FALSE);
				call_dissector(data_handle, tvb_new_subset(tvb,
				    8, -1, -1), pinfo, rmp_tree);
				break;

			case RMP_BOOT_DONE:
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_retcode, tvb, 1, 1, FALSE);
				proto_tree_add_text(rmp_tree, 
				    tvb, 2, 4, "Reserved");
				proto_tree_add_item(rmp_tree, 
				    hf_rmp_sessionid, tvb, 6, 2, FALSE);
				if(tvb_offset_exists(tvb, 8))
					call_dissector(data_handle,
					    tvb_new_subset(tvb, 6, -1, -1),
					    pinfo, tree);
				break;
			default:
				call_dissector(data_handle, tvb_new_subset(tvb,
				    1, -1, -1), pinfo, tree);
		}
	}
}

void
proto_register_rmp(void)
{
	static hf_register_info hf[] = {
		{ &hf_rmp_type,
		{ "Type", "rmp.type", FT_UINT8, BASE_HEX,
			VALS(rmp_type_vals), 0x0, "", HFILL }},
		{ &hf_rmp_retcode,
		{ "Returncode", "rmp.retcode", FT_UINT8, BASE_HEX,
			VALS(rmp_error_vals), 0x0, "", HFILL }},
		{ &hf_rmp_seqnum,
		{ "Sequence Number", "rmp.seqnum", FT_UINT32, BASE_HEX,
			NULL, 0x0, "", HFILL }},
		{ &hf_rmp_sessionid,
		{ "Session ID", "rmp.sessionid", FT_UINT16, BASE_HEX,
			NULL, 0x0, "", HFILL }},
		{ &hf_rmp_version,
		{ "Version", "rmp.version", FT_UINT16, BASE_DEC,
			NULL, 0x0, "", HFILL }},
		{ &hf_rmp_machtype,
		{ "Machine Type", "rmp.machtype", FT_STRING, BASE_DEC,
			NULL, 0x0, "", HFILL }},
		{ &hf_rmp_filename,
		{ "Filename", "rmp.filename", FT_UINT_STRING, BASE_DEC,
			NULL, 0x0, "", HFILL }},
		{ &hf_rmp_offset,
		{ "Offset", "rmp.offset", FT_UINT32, BASE_HEX,
			NULL, 0x0, "", HFILL }},
		{ &hf_rmp_size,
		{ "Size", "rmp.size", FT_UINT16, BASE_DEC,
			NULL, 0x0, "", HFILL }},
	};
	static gint *ett[] = {
		&ett_rmp,
	};

	proto_rmp = proto_register_protocol(
	    "HP Remote Maintenance Protocol", "RMP", "rmp");
	proto_register_field_array(proto_rmp, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));

	register_dissector("rmp", dissect_rmp, proto_rmp);
}

void
proto_reg_handoff_rmp(void)
{
	dissector_handle_t rmp_handle;

	data_handle = find_dissector("data");

	rmp_handle = find_dissector("rmp");
	dissector_add("hpext.dxsap", HPEXT_DXSAP, rmp_handle);
	dissector_add("hpext.dxsap", HPEXT_SXSAP, rmp_handle);
}