Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-rmp.c
blob59d90431e57f344cb0005826a553c8beb95c56c3
1 /* packet-rmp.c
2 * Routines for HP remote management protocol
3 * Gilbert Ramirez <jochen@scram.de>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
16 #include "packet-hpext.h"
18 void proto_register_rmp(void);
19 void proto_reg_handoff_rmp(void);
21 static int proto_rmp;
23 static int hf_rmp_type;
24 static int hf_rmp_retcode;
25 static int hf_rmp_seqnum;
26 static int hf_rmp_sessionid;
27 static int hf_rmp_version;
28 static int hf_rmp_machtype;
29 static int hf_rmp_filename;
30 static int hf_rmp_offset;
31 static int hf_rmp_size;
32 static int hf_rmp_reserved;
34 static int ett_rmp;
36 static dissector_handle_t rmp_handle;
39 * Possible values for "rmp_type" fields.
42 #define RMP_BOOT_REQ 1 /* boot request packet */
43 #define RMP_BOOT_REPL 129 /* boot reply packet */
44 #define RMP_READ_REQ 2 /* read request packet */
45 #define RMP_READ_REPL 130 /* read reply packet */
46 #define RMP_BOOT_DONE 3 /* boot complete packet */
49 * RMP error codes
52 #define RMP_E_OKAY 0
53 #define RMP_E_EOF 2 /* read reply: returned end of file */
54 #define RMP_E_ABORT 3 /* abort operation */
55 #define RMP_E_BUSY 4 /* boot reply: server busy */
56 #define RMP_E_TIMEOUT 5 /* lengthen time out (not implemented) */
57 #define RMP_E_NOFILE 16 /* boot reply: file does not exist */
58 #define RMP_E_OPENFILE 17 /* boot reply: file open failed */
59 #define RMP_E_NODFLT 18 /* boot reply: default file does not exist */
60 #define RMP_E_OPENDFLT 19 /* boot reply: default file open failed */
61 #define RMP_E_BADSID 25 /* read reply: bad session ID */
62 #define RMP_E_BADPACKET 27 /* Bad packet detected */
64 static const value_string rmp_type_vals[] = {
65 { RMP_BOOT_REQ, "Boot Request" },
66 { RMP_BOOT_REPL, "Boot Reply" },
67 { RMP_READ_REQ, "Read Request" },
68 { RMP_READ_REPL, "Read Reply" },
69 { RMP_BOOT_DONE, "Boot Done" },
70 { 0x00, NULL }
73 static const value_string rmp_error_vals[] = {
74 { RMP_E_OKAY, "OK" },
75 { RMP_E_EOF, "End Of File" },
76 { RMP_E_ABORT, "Abort Operation" },
77 { RMP_E_BUSY, "Server Busy" },
78 { RMP_E_TIMEOUT, "Lengthen Time Out" },
79 { RMP_E_NOFILE, "File Does Not Exist" },
80 { RMP_E_OPENFILE, "File Open Failed" },
81 { RMP_E_NODFLT, "Default File Does Not Exist" },
82 { RMP_E_OPENDFLT, "Default File Open Failed" },
83 { RMP_E_BADSID, "Bad Session Id" },
84 { RMP_E_BADPACKET, "Bad Packet Detected" },
85 { 0x00, NULL }
88 static int
89 dissect_rmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
91 proto_tree *rmp_tree = NULL;
92 proto_item *ti = NULL;
93 uint8_t type, len;
95 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RMP");
97 col_clear(pinfo->cinfo, COL_INFO);
99 type = tvb_get_uint8(tvb, 0);
101 col_set_str(pinfo->cinfo, COL_INFO,
102 val_to_str_const(type, rmp_type_vals, "Unknown Type"));
104 ti = proto_tree_add_item(tree, proto_rmp, tvb, 0, -1, ENC_NA);
105 rmp_tree = proto_item_add_subtree(ti, ett_rmp);
106 proto_tree_add_uint(rmp_tree, hf_rmp_type, tvb, 0, 1, type);
108 switch (type) {
109 case RMP_BOOT_REQ:
110 proto_tree_add_item(rmp_tree,
111 hf_rmp_retcode, tvb, 1, 1, ENC_BIG_ENDIAN);
112 proto_tree_add_item(rmp_tree,
113 hf_rmp_seqnum, tvb, 2, 4, ENC_BIG_ENDIAN);
114 proto_tree_add_item(rmp_tree,
115 hf_rmp_sessionid, tvb, 6, 2, ENC_BIG_ENDIAN);
116 proto_tree_add_item(rmp_tree,
117 hf_rmp_version, tvb, 8, 2, ENC_BIG_ENDIAN);
118 proto_tree_add_item(rmp_tree,
119 hf_rmp_machtype, tvb, 10, 20, ENC_ASCII);
120 /* The remaining fields are optional */
121 if(!tvb_offset_exists(tvb, 30))
122 return 30;
123 len = tvb_get_uint8(tvb, 30);
124 proto_tree_add_item(rmp_tree,
125 hf_rmp_filename, tvb, 30, 1, ENC_ASCII|ENC_BIG_ENDIAN);
126 if(tvb_offset_exists(tvb, len+31))
127 call_data_dissector(tvb_new_subset_remaining(tvb, len+31),
128 pinfo, tree);
129 break;
131 case RMP_BOOT_REPL:
132 proto_tree_add_item(rmp_tree,
133 hf_rmp_retcode, tvb, 1, 1, ENC_BIG_ENDIAN);
134 proto_tree_add_item(rmp_tree,
135 hf_rmp_seqnum, tvb, 2, 4, ENC_BIG_ENDIAN);
136 proto_tree_add_item(rmp_tree,
137 hf_rmp_sessionid, tvb, 6, 2, ENC_BIG_ENDIAN);
138 proto_tree_add_item(rmp_tree,
139 hf_rmp_version, tvb, 8, 2, ENC_BIG_ENDIAN);
140 len = tvb_get_uint8(tvb, 10);
141 proto_tree_add_item(rmp_tree,
142 hf_rmp_filename, tvb, 10, 1, ENC_ASCII|ENC_BIG_ENDIAN);
143 if(tvb_offset_exists(tvb, len+11))
144 call_data_dissector(tvb_new_subset_remaining(tvb, len+11),
145 pinfo, tree);
146 break;
148 case RMP_READ_REQ:
149 proto_tree_add_item(rmp_tree,
150 hf_rmp_retcode, tvb, 1, 1, ENC_BIG_ENDIAN);
151 proto_tree_add_item(rmp_tree,
152 hf_rmp_offset, tvb, 2, 4, ENC_BIG_ENDIAN);
153 proto_tree_add_item(rmp_tree,
154 hf_rmp_sessionid, tvb, 6, 2, ENC_BIG_ENDIAN);
155 proto_tree_add_item(rmp_tree,
156 hf_rmp_size, tvb, 8, 2, ENC_BIG_ENDIAN);
157 if(tvb_offset_exists(tvb, 10))
158 call_data_dissector(tvb_new_subset_remaining(tvb, 10),
159 pinfo, tree);
160 break;
162 case RMP_READ_REPL:
163 proto_tree_add_item(rmp_tree,
164 hf_rmp_retcode, tvb, 1, 1, ENC_BIG_ENDIAN);
165 proto_tree_add_item(rmp_tree,
166 hf_rmp_offset, tvb, 2, 4, ENC_BIG_ENDIAN);
167 proto_tree_add_item(rmp_tree,
168 hf_rmp_sessionid, tvb, 6, 2, ENC_BIG_ENDIAN);
169 call_data_dissector(tvb_new_subset_remaining(tvb,
170 8), pinfo, rmp_tree);
171 break;
173 case RMP_BOOT_DONE:
174 proto_tree_add_item(rmp_tree,
175 hf_rmp_retcode, tvb, 1, 1, ENC_BIG_ENDIAN);
176 proto_tree_add_item(rmp_tree,
177 hf_rmp_reserved, tvb, 2, 4, ENC_BIG_ENDIAN);
178 proto_tree_add_item(rmp_tree,
179 hf_rmp_sessionid, tvb, 6, 2, ENC_BIG_ENDIAN);
180 if(tvb_offset_exists(tvb, 8))
181 call_data_dissector(tvb_new_subset_remaining(tvb, 6),
182 pinfo, tree);
183 break;
184 default:
185 call_data_dissector(tvb_new_subset_remaining(tvb, 1), pinfo, tree);
187 return tvb_captured_length(tvb);
190 void
191 proto_register_rmp(void)
193 static hf_register_info hf[] = {
194 { &hf_rmp_type,
195 { "Type", "rmp.type", FT_UINT8, BASE_HEX,
196 VALS(rmp_type_vals), 0x0, NULL, HFILL }},
197 { &hf_rmp_retcode,
198 { "Returncode", "rmp.retcode", FT_UINT8, BASE_HEX,
199 VALS(rmp_error_vals), 0x0, NULL, HFILL }},
200 { &hf_rmp_seqnum,
201 { "Sequence Number", "rmp.seqnum", FT_UINT32, BASE_HEX,
202 NULL, 0x0, NULL, HFILL }},
203 { &hf_rmp_sessionid,
204 { "Session ID", "rmp.sessionid", FT_UINT16, BASE_HEX,
205 NULL, 0x0, NULL, HFILL }},
206 { &hf_rmp_version,
207 { "Version", "rmp.version", FT_UINT16, BASE_DEC,
208 NULL, 0x0, NULL, HFILL }},
209 { &hf_rmp_machtype,
210 { "Machine Type", "rmp.machtype", FT_STRING, BASE_NONE,
211 NULL, 0x0, NULL, HFILL }},
212 { &hf_rmp_filename,
213 { "Filename", "rmp.filename", FT_UINT_STRING, BASE_NONE,
214 NULL, 0x0, NULL, HFILL }},
215 { &hf_rmp_offset,
216 { "Offset", "rmp.offset", FT_UINT32, BASE_HEX,
217 NULL, 0x0, NULL, HFILL }},
218 { &hf_rmp_size,
219 { "Size", "rmp.size", FT_UINT16, BASE_DEC,
220 NULL, 0x0, NULL, HFILL }},
221 { &hf_rmp_reserved,
222 { "Reserved", "rmp.reserved", FT_UINT32, BASE_HEX,
223 NULL, 0x0, NULL, HFILL }},
226 static int *ett[] = {
227 &ett_rmp,
230 proto_rmp = proto_register_protocol("HP Remote Maintenance Protocol", "RMP", "rmp");
231 proto_register_field_array(proto_rmp, hf, array_length(hf));
232 proto_register_subtree_array(ett, array_length(ett));
234 rmp_handle = register_dissector("rmp", dissect_rmp, proto_rmp);
237 void
238 proto_reg_handoff_rmp(void)
240 dissector_add_uint("hpext.dxsap", HPEXT_DXSAP, rmp_handle);
241 dissector_add_uint("hpext.dxsap", HPEXT_SXSAP, rmp_handle);
245 * Editor modelines - https://www.wireshark.org/tools/modelines.html
247 * Local variables:
248 * c-basic-offset: 8
249 * tab-width: 8
250 * indent-tabs-mode: t
251 * End:
253 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
254 * :indentSize=8:tabSize=8:noTabs=false: