As the gtk2 directory is no longer needed (GTK1 and 2 are using the same sources...
[obnox/wireshark/wip.git] / epan / dissectors / packet-rmp.c
1 /* packet-rmp.c
2  * Routines for HP remote management protocol
3  * Gilbert Ramirez <jochen@scram.de>
4  *
5  * $Id$
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include "etypes.h"
33
34 #include "packet-hpext.h"
35
36 static dissector_handle_t data_handle;
37
38 static int proto_rmp = -1;
39
40 static int hf_rmp_type = -1;
41 static int hf_rmp_retcode = -1;
42 static int hf_rmp_seqnum = -1;
43 static int hf_rmp_sessionid = -1;
44 static int hf_rmp_version = -1;
45 static int hf_rmp_machtype = -1;
46 static int hf_rmp_filename = -1;
47 static int hf_rmp_offset = -1;
48 static int hf_rmp_size = -1;
49
50 static gint ett_rmp = -1;
51
52 /*
53  *  Possible values for "rmp_type" fields.
54  */
55
56 #define RMP_BOOT_REQ    1       /* boot request packet */
57 #define RMP_BOOT_REPL   129     /* boot reply packet */
58 #define RMP_READ_REQ    2       /* read request packet */
59 #define RMP_READ_REPL   130     /* read reply packet */
60 #define RMP_BOOT_DONE   3       /* boot complete packet */
61
62 /*
63  *  RMP error codes
64  */
65
66 #define RMP_E_OKAY      0
67 #define RMP_E_EOF       2       /* read reply: returned end of file */
68 #define RMP_E_ABORT     3       /* abort operation */
69 #define RMP_E_BUSY      4       /* boot reply: server busy */
70 #define RMP_E_TIMEOUT   5       /* lengthen time out (not implemented) */
71 #define RMP_E_NOFILE    16      /* boot reply: file does not exist */
72 #define RMP_E_OPENFILE  17      /* boot reply: file open failed */
73 #define RMP_E_NODFLT    18      /* boot reply: default file does not exist */
74 #define RMP_E_OPENDFLT  19      /* boot reply: default file open failed */
75 #define RMP_E_BADSID    25      /* read reply: bad session ID */
76 #define RMP_E_BADPACKET 27      /* Bad packet detected */
77
78 const value_string rmp_type_vals[] = {
79         { RMP_BOOT_REQ,       "Boot Request" },
80         { RMP_BOOT_REPL,      "Boot Reply" },
81         { RMP_READ_REQ,       "Read Request" },
82         { RMP_READ_REPL,      "Read Reply" },
83         { RMP_BOOT_DONE,      "Boot Done" },
84         { 0x00,               NULL }
85 };
86
87 const value_string rmp_error_vals[] = {
88         { RMP_E_OKAY,         "OK" },
89         { RMP_E_EOF,          "End Of File" },
90         { RMP_E_ABORT,        "Abort Operation" },
91         { RMP_E_BUSY,         "Server Busy" },
92         { RMP_E_TIMEOUT,      "Lengthen Time Out" },
93         { RMP_E_NOFILE,       "File Does Not Exist" },
94         { RMP_E_OPENFILE,     "File Open Failed" },
95         { RMP_E_NODFLT,       "Default File Does Not Exist" },
96         { RMP_E_OPENDFLT,     "Default File Open Failed" },
97         { RMP_E_BADSID,       "Bad Session Id" },
98         { RMP_E_OPENDFLT,     "Bad Packet Detected" },
99         { 0x00,               NULL }
100 };
101
102 static void
103 dissect_rmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
104 {
105         proto_tree      *rmp_tree = NULL;
106         proto_item      *ti = NULL;
107         guint8          type, len;
108
109         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
110                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RMP");
111         }
112
113         if (check_col(pinfo->cinfo, COL_INFO)) {
114                 col_clear(pinfo->cinfo, COL_INFO);
115         }
116
117         type = tvb_get_guint8(tvb, 0);
118
119         if (check_col(pinfo->cinfo, COL_INFO)) {
120                 col_set_str(pinfo->cinfo, COL_INFO,
121                     val_to_str(type, rmp_type_vals, "Unknown Type"));
122         }
123
124         if (tree) {
125                 ti = proto_tree_add_item(tree, proto_rmp, tvb, 0, -1, FALSE);
126                 rmp_tree = proto_item_add_subtree(ti, ett_rmp);
127                 proto_tree_add_uint(rmp_tree, hf_rmp_type, tvb, 0, 1, type);
128
129                 switch (type) {
130                         case RMP_BOOT_REQ:
131                                 proto_tree_add_item(rmp_tree, 
132                                     hf_rmp_retcode, tvb, 1, 1, FALSE);
133                                 proto_tree_add_item(rmp_tree, 
134                                     hf_rmp_seqnum, tvb, 2, 4, FALSE);
135                                 proto_tree_add_item(rmp_tree, 
136                                     hf_rmp_sessionid, tvb, 6, 2, FALSE);
137                                 proto_tree_add_item(rmp_tree, 
138                                     hf_rmp_version, tvb, 8, 2, FALSE);
139                                 proto_tree_add_item(rmp_tree, 
140                                     hf_rmp_machtype, tvb, 10, 20, FALSE);
141                                 /* The remaining fields are optional */
142                                 if(!tvb_offset_exists(tvb, 30))
143                                         return;
144                                 len = tvb_get_guint8(tvb, 30);
145                                 proto_tree_add_item(rmp_tree, 
146                                     hf_rmp_filename, tvb, 30, 1, FALSE);
147                                 if(tvb_offset_exists(tvb, len+31))
148                                         call_dissector(data_handle,
149                                             tvb_new_subset(tvb, len+31, -1, -1),
150                                             pinfo, tree);
151                                 break;
152
153                         case RMP_BOOT_REPL:
154                                 proto_tree_add_item(rmp_tree, 
155                                     hf_rmp_retcode, tvb, 1, 1, FALSE);
156                                 proto_tree_add_item(rmp_tree, 
157                                     hf_rmp_seqnum, tvb, 2, 4, FALSE);
158                                 proto_tree_add_item(rmp_tree, 
159                                     hf_rmp_sessionid, tvb, 6, 2, FALSE);
160                                 proto_tree_add_item(rmp_tree, 
161                                     hf_rmp_version, tvb, 8, 2, FALSE);
162                                 len = tvb_get_guint8(tvb, 10);
163                                 proto_tree_add_item(rmp_tree, 
164                                     hf_rmp_filename, tvb, 10, 1, FALSE);
165                                 if(tvb_offset_exists(tvb, len+11))
166                                         call_dissector(data_handle,
167                                             tvb_new_subset(tvb, len+11, -1, -1),
168                                             pinfo, tree);
169                                 break;
170
171                         case RMP_READ_REQ:
172                                 proto_tree_add_item(rmp_tree, 
173                                     hf_rmp_retcode, tvb, 1, 1, FALSE);
174                                 proto_tree_add_item(rmp_tree, 
175                                     hf_rmp_offset, tvb, 2, 4, FALSE);
176                                 proto_tree_add_item(rmp_tree, 
177                                     hf_rmp_sessionid, tvb, 6, 2, FALSE);
178                                 proto_tree_add_item(rmp_tree, 
179                                     hf_rmp_size, tvb, 8, 2, FALSE);
180                                 if(tvb_offset_exists(tvb, 10))
181                                         call_dissector(data_handle,
182                                             tvb_new_subset(tvb, 10, -1, -1),
183                                             pinfo, tree);
184                                 break;
185
186                         case RMP_READ_REPL:
187                                 proto_tree_add_item(rmp_tree, 
188                                     hf_rmp_retcode, tvb, 1, 1, FALSE);
189                                 proto_tree_add_item(rmp_tree, 
190                                     hf_rmp_offset, tvb, 2, 4, FALSE);
191                                 proto_tree_add_item(rmp_tree, 
192                                     hf_rmp_sessionid, tvb, 6, 2, FALSE);
193                                 call_dissector(data_handle, tvb_new_subset(tvb,
194                                     8, -1, -1), pinfo, rmp_tree);
195                                 break;
196
197                         case RMP_BOOT_DONE:
198                                 proto_tree_add_item(rmp_tree, 
199                                     hf_rmp_retcode, tvb, 1, 1, FALSE);
200                                 proto_tree_add_text(rmp_tree, 
201                                     tvb, 2, 4, "Reserved");
202                                 proto_tree_add_item(rmp_tree, 
203                                     hf_rmp_sessionid, tvb, 6, 2, FALSE);
204                                 if(tvb_offset_exists(tvb, 8))
205                                         call_dissector(data_handle,
206                                             tvb_new_subset(tvb, 6, -1, -1),
207                                             pinfo, tree);
208                                 break;
209                         default:
210                                 call_dissector(data_handle, tvb_new_subset(tvb,
211                                     1, -1, -1), pinfo, tree);
212                 }
213         }
214 }
215
216 void
217 proto_register_rmp(void)
218 {
219         static hf_register_info hf[] = {
220                 { &hf_rmp_type,
221                 { "Type", "rmp.type", FT_UINT8, BASE_HEX,
222                         VALS(rmp_type_vals), 0x0, "", HFILL }},
223                 { &hf_rmp_retcode,
224                 { "Returncode", "rmp.retcode", FT_UINT8, BASE_HEX,
225                         VALS(rmp_error_vals), 0x0, "", HFILL }},
226                 { &hf_rmp_seqnum,
227                 { "Sequence Number", "rmp.seqnum", FT_UINT32, BASE_HEX,
228                         NULL, 0x0, "", HFILL }},
229                 { &hf_rmp_sessionid,
230                 { "Session ID", "rmp.sessionid", FT_UINT16, BASE_HEX,
231                         NULL, 0x0, "", HFILL }},
232                 { &hf_rmp_version,
233                 { "Version", "rmp.version", FT_UINT16, BASE_DEC,
234                         NULL, 0x0, "", HFILL }},
235                 { &hf_rmp_machtype,
236                 { "Machine Type", "rmp.machtype", FT_STRING, BASE_DEC,
237                         NULL, 0x0, "", HFILL }},
238                 { &hf_rmp_filename,
239                 { "Filename", "rmp.filename", FT_UINT_STRING, BASE_DEC,
240                         NULL, 0x0, "", HFILL }},
241                 { &hf_rmp_offset,
242                 { "Offset", "rmp.offset", FT_UINT32, BASE_HEX,
243                         NULL, 0x0, "", HFILL }},
244                 { &hf_rmp_size,
245                 { "Size", "rmp.size", FT_UINT16, BASE_DEC,
246                         NULL, 0x0, "", HFILL }},
247         };
248         static gint *ett[] = {
249                 &ett_rmp,
250         };
251
252         proto_rmp = proto_register_protocol(
253             "HP Remote Maintenance Protocol", "RMP", "rmp");
254         proto_register_field_array(proto_rmp, hf, array_length(hf));
255         proto_register_subtree_array(ett, array_length(ett));
256
257         register_dissector("rmp", dissect_rmp, proto_rmp);
258 }
259
260 void
261 proto_reg_handoff_rmp(void)
262 {
263         dissector_handle_t rmp_handle;
264
265         data_handle = find_dissector("data");
266
267         rmp_handle = find_dissector("rmp");
268         dissector_add("hpext.dxsap", HPEXT_DXSAP, rmp_handle);
269         dissector_add("hpext.dxsap", HPEXT_SXSAP, rmp_handle);
270 }