Don't guard col_set_str (COL_PROTOCOL) with col_check
[obnox/wireshark/wip.git] / epan / dissectors / packet-mq-pcf.c
1 /* packet-mq-pcf.c
2  * Routines for IBM WebSphere MQ PCF packet dissection
3  *
4  * metatech <metatech@flashmail.com>
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 /*  MQ PCF in a nutshell
28 *
29 *   The MQ Programmable Command Formats API allows remotely configuring a queue manager.
30 *   
31 *   MQ PCF documentation is called "WebSphere MQ Programmable Command Formats and Administration Interface" 
32 */
33
34 #ifdef HAVE_CONFIG_H
35 # include "config.h"
36 #endif
37
38 #include <string.h>
39
40 #include <glib.h>
41 #include <epan/packet.h>
42 #include "packet-mq.h"
43
44 static int proto_mqpcf = -1;
45 static int hf_mqpcf_cfh_type = -1;
46 static int hf_mqpcf_cfh_length = -1;
47 static int hf_mqpcf_cfh_version = -1;
48 static int hf_mqpcf_cfh_command = -1;
49 static int hf_mqpcf_cfh_msgseqnumber = -1;
50 static int hf_mqpcf_cfh_control = -1;
51 static int hf_mqpcf_cfh_compcode = -1;
52 static int hf_mqpcf_cfh_reason = -1;
53 static int hf_mqpcf_cfh_paramcount = -1;
54
55 static gint ett_mqpcf = -1;
56 static gint ett_mqpcf_cfh = -1;
57
58 #define MQ_FMT_ADMIN    "MQADMIN "
59 #define MQ_FMT_EVENT    "MQEVENT "
60 #define MQ_FMT_PCF      "MQPCF   "
61
62 #define MQ_ENC_INTEGER_NORMAL    0x00000001
63 #define MQ_ENC_INTEGER_REVERSED  0x00000002
64
65 #define MQ_CMD_NONE                     0
66 #define MQ_CMD_CHANGE_Q_MGR             1 
67 #define MQ_CMD_INQUIRE_Q_MGR            2 
68 #define MQ_CMD_CHANGE_PROCESS           3 
69 #define MQ_CMD_COPY_PROCESS             4 
70 #define MQ_CMD_CREATE_PROCESS           5 
71 #define MQ_CMD_DELETE_PROCESS           6 
72 #define MQ_CMD_INQUIRE_PROCESS          7 
73 #define MQ_CMD_CHANGE_Q                 8 
74 #define MQ_CMD_CLEAR_Q                  9 
75 #define MQ_CMD_COPY_Q                  10 
76 #define MQ_CMD_CREATE_Q                11 
77 #define MQ_CMD_DELETE_Q                12 
78 #define MQ_CMD_INQUIRE_Q               13 
79 #define MQ_CMD_RESET_Q_STATS           17 
80 #define MQ_CMD_INQUIRE_Q_NAMES         18 
81 #define MQ_CMD_INQUIRE_PROCESS_NAMES   19 
82 #define MQ_CMD_INQUIRE_CHANNEL_NAMES   20 
83 #define MQ_CMD_CHANGE_CHANNEL          21 
84 #define MQ_CMD_COPY_CHANNEL            22 
85 #define MQ_CMD_CREATE_CHANNEL          23 
86 #define MQ_CMD_DELETE_CHANNEL          24 
87 #define MQ_CMD_INQUIRE_CHANNEL         25 
88 #define MQ_CMD_PING_CHANNEL            26 
89 #define MQ_CMD_RESET_CHANNEL           27 
90 #define MQ_CMD_START_CHANNEL           28 
91 #define MQ_CMD_STOP_CHANNEL            29 
92 #define MQ_CMD_START_CHANNEL_INIT      30 
93 #define MQ_CMD_START_CHANNEL_LISTENER  31 
94 #define MQ_CMD_CHANGE_NAMELIST         32 
95 #define MQ_CMD_COPY_NAMELIST           33 
96 #define MQ_CMD_CREATE_NAMELIST         34 
97 #define MQ_CMD_DELETE_NAMELIST         35 
98 #define MQ_CMD_INQUIRE_NAMELIST        36 
99 #define MQ_CMD_INQUIRE_NAMELIST_NAMES  37 
100 #define MQ_CMD_ESCAPE                  38 
101 #define MQ_CMD_RESOLVE_CHANNEL         39 
102 #define MQ_CMD_PING_Q_MGR              40 
103 #define MQ_CMD_INQUIRE_Q_STATUS        41 
104 #define MQ_CMD_INQUIRE_CHANNEL_STATUS  42 
105 #define MQ_CMD_CONFIG_EVENT            43 
106 #define MQ_CMD_Q_MGR_EVENT             44 
107 #define MQ_CMD_PERFM_EVENT             45 
108 #define MQ_CMD_CHANNEL_EVENT           46 
109 #define MQ_CMD_DELETE_PUBLICATION      60
110 #define MQ_CMD_DEREGISTER_PUBLISHER    61
111 #define MQ_CMD_DEREGISTER_SUBSCRIBER   62
112 #define MQ_CMD_PUBLISH                 63
113 #define MQ_CMD_REGISTER_PUBLISHER      64
114 #define MQ_CMD_REGISTER_SUBSCRIBER     65
115 #define MQ_CMD_REQUEST_UPDATE          66
116 #define MQ_CMD_BROKER_INTERNAL         67
117 #define MQ_CMD_INQUIRE_CLUSTER_Q_MGR   70 
118 #define MQ_CMD_RESUME_Q_MGR_CLUSTER    71 
119 #define MQ_CMD_SUSPEND_Q_MGR_CLUSTER   72 
120 #define MQ_CMD_REFRESH_CLUSTER         73 
121 #define MQ_CMD_RESET_CLUSTER           74 
122 #define MQ_CMD_REFRESH_SECURITY        78 
123 #define MQ_CMD_CHANGE_AUTH_INFO        79 
124 #define MQ_CMD_COPY_AUTH_INFO          80 
125 #define MQ_CMD_CREATE_AUTH_INFO        81 
126 #define MQ_CMD_DELETE_AUTH_INFO        82 
127 #define MQ_CMD_INQUIRE_AUTH_INFO       83 
128 #define MQ_CMD_INQUIRE_AUTH_INFO_NAMES 84 
129
130 #define MQ_TEXT_CFH   "MQ Command Format Header"
131
132 static const value_string mqpcf_opcode_vals[] = {
133   { MQ_CMD_NONE,                            "NONE" },
134   { MQ_CMD_CHANGE_Q_MGR,                    "CHANGE_Q_MGR" },
135   { MQ_CMD_INQUIRE_Q_MGR,                   "INQUIRE_Q_MGR" },
136   { MQ_CMD_CHANGE_PROCESS,                  "CHANGE_PROCESS" },
137   { MQ_CMD_COPY_PROCESS,                    "COPY_PROCESS" },
138   { MQ_CMD_CREATE_PROCESS,                  "CREATE_PROCESS" },
139   { MQ_CMD_DELETE_PROCESS,                  "DELETE_PROCESS" },
140   { MQ_CMD_INQUIRE_PROCESS,                 "INQUIRE_PROCESS" },
141   { MQ_CMD_CHANGE_Q,                        "CHANGE_Q" },
142   { MQ_CMD_CLEAR_Q,                         "CLEAR_Q" },
143   { MQ_CMD_COPY_Q,                          "COPY_Q" },
144   { MQ_CMD_CREATE_Q,                        "CREATE_Q" },
145   { MQ_CMD_DELETE_Q,                        "DELETE_Q" },
146   { MQ_CMD_INQUIRE_Q,                       "INQUIRE_Q" },
147   { MQ_CMD_RESET_Q_STATS,                   "RESET_Q_STATS" },
148   { MQ_CMD_INQUIRE_Q_NAMES,                 "INQUIRE_Q_NAMES" },
149   { MQ_CMD_INQUIRE_PROCESS_NAMES,           "INQUIRE_PROCESS_NAMES" },
150   { MQ_CMD_INQUIRE_CHANNEL_NAMES,           "INQUIRE_CHANNEL_NAMES" },
151   { MQ_CMD_CHANGE_CHANNEL,                  "CHANGE_CHANNEL" },
152   { MQ_CMD_COPY_CHANNEL,                    "COPY_CHANNEL" },
153   { MQ_CMD_CREATE_CHANNEL,                  "CREATE_CHANNEL" },
154   { MQ_CMD_DELETE_CHANNEL,                  "DELETE_CHANNEL" },
155   { MQ_CMD_INQUIRE_CHANNEL,                 "INQUIRE_CHANNEL" },
156   { MQ_CMD_PING_CHANNEL,                    "PING_CHANNEL" },
157   { MQ_CMD_RESET_CHANNEL,                   "RESET_CHANNEL" },
158   { MQ_CMD_START_CHANNEL,                   "START_CHANNEL" },
159   { MQ_CMD_STOP_CHANNEL,                    "STOP_CHANNEL" },
160   { MQ_CMD_START_CHANNEL_INIT,              "START_CHANNEL_INIT" },
161   { MQ_CMD_START_CHANNEL_LISTENER,          "START_CHANNEL_LISTENER" },
162   { MQ_CMD_CHANGE_NAMELIST,                 "CHANGE_NAMELIST" },
163   { MQ_CMD_CREATE_NAMELIST,                 "CREATE_NAMELIST" },
164   { MQ_CMD_DELETE_NAMELIST,                 "DELETE_NAMELIST" },
165   { MQ_CMD_INQUIRE_NAMELIST,                "INQUIRE_NAMELIST" },
166   { MQ_CMD_INQUIRE_NAMELIST_NAMES,          "INQUIRE_NAMELIST_NAMES" },
167   { MQ_CMD_ESCAPE,                          "ESCAPE" },
168   { MQ_CMD_RESOLVE_CHANNEL,                 "RESOLVE_CHANNEL" },
169   { MQ_CMD_PING_Q_MGR,                      "PING_Q_MGR" },
170   { MQ_CMD_INQUIRE_Q_STATUS,                "INQUIRE_Q_STATUS" },
171   { MQ_CMD_INQUIRE_CHANNEL_STATUS,          "INQUIRE_CHANNEL_STATUS" },
172   { MQ_CMD_CONFIG_EVENT,                    "CONFIG_EVENT" },
173   { MQ_CMD_Q_MGR_EVENT,                     "Q_MGR_EVENT" },
174   { MQ_CMD_PERFM_EVENT,                     "PERFM_EVENT" },
175   { MQ_CMD_CHANNEL_EVENT,                   "CHANNEL_EVENT" },
176   { MQ_CMD_DELETE_PUBLICATION,              "DELETE_PUBLICATION" },
177   { MQ_CMD_DEREGISTER_PUBLISHER,            "DEREGISTER_PUBLISHER" },
178   { MQ_CMD_DEREGISTER_SUBSCRIBER,           "DEREGISTER_SUBSCRIBER" },
179   { MQ_CMD_PUBLISH,                         "PUBLISH" },
180   { MQ_CMD_REGISTER_PUBLISHER,              "REGISTER_PUBLISHER" },
181   { MQ_CMD_REGISTER_SUBSCRIBER,             "REGISTER_SUBSCRIBER" },
182   { MQ_CMD_REQUEST_UPDATE,                  "REQUEST_UPDATE" },
183   { MQ_CMD_BROKER_INTERNAL,                 "BROKER_INTERNAL" },
184   { MQ_CMD_INQUIRE_CLUSTER_Q_MGR,           "INQUIRE_CLUSTER_Q_MGR" },
185   { MQ_CMD_RESUME_Q_MGR_CLUSTER,            "RESUME_Q_MGR_CLUSTER" },
186   { MQ_CMD_SUSPEND_Q_MGR_CLUSTER,           "SUSPEND_Q_MGR_CLUSTER" },
187   { MQ_CMD_REFRESH_CLUSTER,                 "REFRESH_CLUSTER" },
188   { MQ_CMD_REFRESH_SECURITY,                "REFRESH_SECURITY" },
189   { MQ_CMD_CHANGE_AUTH_INFO,                "CHANGE_AUTH_INFO" },
190   { MQ_CMD_COPY_AUTH_INFO,                  "COPY_AUTH_INFO" },
191   { MQ_CMD_CREATE_AUTH_INFO,                "CREATE_AUTH_INFO" },
192   { MQ_CMD_DELETE_AUTH_INFO,                "DELETE_AUTH_INFO" },
193   { MQ_CMD_INQUIRE_AUTH_INFO,               "INQUIRE_AUTH_INFO" },
194   { MQ_CMD_INQUIRE_AUTH_INFO_NAMES,         "INQUIRE_AUTH_INFO_NAMES" },
195   { 0,          NULL }
196 };
197
198 static guint32 tvb_get_guint32_endian(tvbuff_t *a_tvb, gint a_iOffset, gboolean a_bLittleEndian)
199 {
200         guint32 iResult;
201         if (a_bLittleEndian)
202                 iResult = tvb_get_letohl(a_tvb, a_iOffset);
203         else
204                 iResult =  tvb_get_ntohl(a_tvb, a_iOffset);
205         return iResult;
206 }
207
208 static void
209 dissect_mqpcf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
210 {
211         proto_tree      *mq_tree = NULL;
212         proto_tree      *mqroot_tree = NULL;
213         proto_item      *ti = NULL;
214         gint offset = 0;
215         struct mqinfo* mqinfo = pinfo->private_data;
216         gboolean bLittleEndian;
217         bLittleEndian = ((mqinfo->encoding & MQ_ENC_INTEGER_REVERSED) != 0) ? TRUE : FALSE;
218
219         col_set_str(pinfo->cinfo, COL_PROTOCOL, "MQ PCF");        
220         if (check_col(pinfo->cinfo, COL_INFO)) col_clear(pinfo->cinfo, COL_INFO);         
221         if (tvb_length(tvb) >= 36)
222         {
223                 gint iSizeMQCFH = 36;
224                 guint32 iCommand = tvb_get_guint32_endian(tvb, offset + 12, bLittleEndian);
225
226                 if (check_col(pinfo->cinfo, COL_INFO)) 
227                 {
228                         col_append_str(pinfo->cinfo, COL_INFO, val_to_str(iCommand, mqpcf_opcode_vals, "Unknown (0x%02x)"));
229                 }
230
231                 if (tree)
232                 {
233                         ti = proto_tree_add_item(tree, proto_mqpcf, tvb, offset, -1, FALSE);
234                         proto_item_append_text(ti, " (%s)", val_to_str(iCommand, mqpcf_opcode_vals, "Unknown (0x%02x)"));
235                         mqroot_tree = proto_item_add_subtree(ti, ett_mqpcf);
236
237                         ti = proto_tree_add_text(mqroot_tree, tvb, offset, iSizeMQCFH, MQ_TEXT_CFH);
238                         mq_tree = proto_item_add_subtree(ti, ett_mqpcf_cfh);
239
240                         proto_tree_add_item(mq_tree, hf_mqpcf_cfh_type, tvb, offset + 0, 4, bLittleEndian);
241                         proto_tree_add_item(mq_tree, hf_mqpcf_cfh_length, tvb, offset + 4, 4, bLittleEndian);
242                         proto_tree_add_item(mq_tree, hf_mqpcf_cfh_version, tvb, offset + 8, 4, bLittleEndian);
243                         proto_tree_add_item(mq_tree, hf_mqpcf_cfh_command, tvb, offset + 12, 4, bLittleEndian);
244                         proto_tree_add_item(mq_tree, hf_mqpcf_cfh_msgseqnumber, tvb, offset + 16, 4, bLittleEndian);
245                         proto_tree_add_item(mq_tree, hf_mqpcf_cfh_control, tvb, offset + 20, 4, bLittleEndian);
246                         proto_tree_add_item(mq_tree, hf_mqpcf_cfh_compcode, tvb, offset + 24, 4, bLittleEndian);
247                         proto_tree_add_item(mq_tree, hf_mqpcf_cfh_reason, tvb, offset + 28, 4, bLittleEndian);
248                         proto_tree_add_item(mq_tree, hf_mqpcf_cfh_paramcount, tvb, offset + 32, 4, bLittleEndian);
249                 }
250                 offset += iSizeMQCFH;
251         }
252 }
253
254 static gboolean
255 dissect_mqpcf_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
256 {
257         if (tvb_length(tvb) >= 36)
258         {
259                 struct mqinfo* mqinfo = pinfo->private_data;
260                 if (strncmp((const char*)mqinfo->format, MQ_FMT_ADMIN, 8) == 0
261                         || strncmp((const char*)mqinfo->format, MQ_FMT_EVENT, 8) == 0
262                         || strncmp((const char*)mqinfo->format, MQ_FMT_PCF, 8) == 0)
263                 {
264                         /* Dissect the packet */
265                         dissect_mqpcf(tvb, pinfo, tree);
266                         return TRUE;
267                 }
268         }
269         return FALSE;
270 }
271
272 void
273 proto_register_mqpcf(void)
274 {
275   static hf_register_info hf[] = {
276    { &hf_mqpcf_cfh_type,
277       { "Type", "mqpcf.cfh.type", FT_UINT32, BASE_DEC, NULL, 0x0, "CFH type", HFILL }},
278
279    { &hf_mqpcf_cfh_length,
280       { "Length", "mqpcf.cfh.length", FT_UINT32, BASE_DEC, NULL, 0x0, "CFH length", HFILL }},
281
282    { &hf_mqpcf_cfh_version,
283       { "Version", "mqpcf.cfh.version", FT_UINT32, BASE_DEC, NULL, 0x0, "CFH version", HFILL }},
284
285    { &hf_mqpcf_cfh_command,
286       { "Command", "mqpcf.cfh.command", FT_UINT32, BASE_DEC, NULL, 0x0, "CFH command", HFILL }},
287
288    { &hf_mqpcf_cfh_msgseqnumber,
289       { "Message sequence number", "mqpcf.cfh.msgseqnumber", FT_UINT32, BASE_DEC, NULL, 0x0, "CFH message sequence number", HFILL }},
290
291    { &hf_mqpcf_cfh_control,
292       { "Control", "mqpcf.cfh.control", FT_UINT32, BASE_DEC, NULL, 0x0, "CFH control", HFILL }},
293
294    { &hf_mqpcf_cfh_compcode,
295       { "Completion code", "mqpcf.cfh.compcode", FT_UINT32, BASE_DEC, NULL, 0x0, "CFH completion code", HFILL }},
296
297    { &hf_mqpcf_cfh_reason,
298       { "Reason code", "mqpcf.cfh.reasoncode", FT_UINT32, BASE_DEC, NULL, 0x0, "CFH reason code", HFILL }},
299
300    { &hf_mqpcf_cfh_paramcount,
301       { "Parameter count", "mqpcf.cfh.paramcount", FT_UINT32, BASE_DEC, NULL, 0x0, "CFH parameter count", HFILL }}
302   };
303   static gint *ett[] = {
304     &ett_mqpcf,
305     &ett_mqpcf_cfh,
306   };
307
308   proto_mqpcf = proto_register_protocol("WebSphere MQ Programmable Command Formats", "MQ PCF", "mqpcf");
309   proto_register_field_array(proto_mqpcf, hf, array_length(hf));
310   proto_register_subtree_array(ett, array_length(ett));
311 }
312
313 void
314 proto_reg_handoff_mqpcf(void)
315 {
316         heur_dissector_add("mq", dissect_mqpcf_heur, proto_mqpcf);
317 }