MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / dissectors / packet-netdump.c
blobc2f572e6c0b86520a39165f555a79367adcf312c
1 /* packet-netdump.c
2 * Routines for Netdump dissection
3 * Copyright 2009, Neil Horman <nhorman@tuxdriver.com>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 * USA.
27 #include "config.h"
29 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
34 /* forward reference */
35 void proto_reg_handoff_netdump(void);
37 /* Initialize the protocol and registered fields */
38 static int proto_netdump = -1;
39 static int hf_netdump_magic_number = -1;
40 static int hf_netdump_seq_nr = -1;
41 static int hf_netdump_command = -1;
42 static int hf_netdump_from = -1;
43 static int hf_netdump_to = -1;
44 static int hf_netdump_payload = -1;
45 static int hf_netdump_code = -1;
46 static int hf_netdump_info = -1;
47 static int hf_netdump_version = -1;
49 /* Global sample port pref */
50 static guint gPORT_PREF = 0;
52 /* Initialize the subtree pointers */
53 static gint ett_netdump = -1;
55 static const value_string command_names[] = {
56 { 0, "COMM_NONE" },
57 { 1, "COMM_SEND_MEM" },
58 { 2, "COMM_EXIT" },
59 { 3, "COMM_REBOOT" },
60 { 4, "COMM_HELLO" },
61 { 5, "COMM_GET_NR_PAGES" },
62 { 6, "COMM_GET_PAGE_SIZE" },
63 { 7, "COMM_START_NETDUMP_ACK" },
64 { 8, "COMM_GET_REGS" },
65 { 9, "COMM_SHOW_STATE" },
66 { 0, NULL }
69 static const value_string reply_code_names[] = {
70 { 0, "REPLY_NONE" },
71 { 1, "REPLY_ERROR" },
72 { 2, "REPLY_LOG" },
73 { 3, "REPLY_MEM" },
74 { 4, "REPLY_RESERVED" },
75 { 5, "REPLY_HELLO" },
76 { 6, "REPLY_NR_PAGES" },
77 { 7, "REPLY_PAGE_SIZE" },
78 { 8, "REPLY_START_NETDUMP" },
79 { 9, "REPLY_END_NETDUMP" },
80 { 10, "REPLY_REGS" },
81 { 11, "REPLY_MAGIC" },
82 { 12, "REPLY_SHOW_STATE" },
83 { 0, NULL }
87 /* Code to actually dissect the packets */
88 static void
89 dissect_netdump(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
92 /* Check that there's enough data */
93 if (tvb_reported_length(tvb) == 0)
94 return;
96 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Netdump");
97 /* Clear out stuff in the info column */
98 col_clear(pinfo->cinfo, COL_INFO);
100 if (tree) { /* we are being asked for details */
101 proto_item *ti = NULL;
102 proto_tree *netdump_tree = NULL;
103 ti = proto_tree_add_item(tree, proto_netdump, tvb, 0, -1, ENC_NA);
104 netdump_tree = proto_item_add_subtree(ti, ett_netdump);
105 if (tvb_reported_length(tvb) == 24) {
106 /* Its a request format packet */
107 proto_tree_add_item(netdump_tree, hf_netdump_magic_number, tvb, 0, 8, ENC_BIG_ENDIAN);
108 proto_tree_add_item(netdump_tree, hf_netdump_seq_nr, tvb, 8, 4, ENC_BIG_ENDIAN);
109 proto_tree_add_item(netdump_tree, hf_netdump_command, tvb, 12, 4, ENC_BIG_ENDIAN);
110 proto_tree_add_item(netdump_tree, hf_netdump_from, tvb, 16, 4, ENC_BIG_ENDIAN);
111 proto_tree_add_item(netdump_tree, hf_netdump_to, tvb, 20, 4, ENC_BIG_ENDIAN);
112 } else {
113 /* Its a reply packet */
114 proto_tree_add_item(netdump_tree, hf_netdump_version, tvb, 0, 1, ENC_BIG_ENDIAN);
115 proto_tree_add_item(netdump_tree, hf_netdump_seq_nr, tvb, 1, 4, ENC_BIG_ENDIAN);
116 proto_tree_add_item(netdump_tree, hf_netdump_code, tvb, 5, 4, ENC_BIG_ENDIAN);
117 proto_tree_add_item(netdump_tree, hf_netdump_info, tvb, 9, 4, ENC_LITTLE_ENDIAN);
118 proto_tree_add_item(netdump_tree, hf_netdump_payload, tvb, 13, -1, ENC_NA);
123 void proto_register_netdump(void)
125 module_t *netdump_module;
127 /* Setup protocol subtree array */
128 static gint *ett[] = {
129 &ett_netdump
132 static hf_register_info hf[] = {
133 { &hf_netdump_magic_number,
134 { "Netdump Magic Number", "netdump.magic",
135 FT_UINT64, BASE_HEX,
136 NULL, 0x0,
137 NULL, HFILL }
139 { &hf_netdump_seq_nr,
140 {"Netdump seq number", "netdump.seq_nr",
141 FT_UINT32, BASE_HEX,
142 NULL, 0x0,
143 NULL, HFILL}
145 { &hf_netdump_command,
146 {"Netdump command", "netdump.command",
147 FT_UINT32, BASE_DEC,
148 VALS(command_names), 0x0,
149 NULL, HFILL}
151 { &hf_netdump_from,
152 {"Netdump from val", "netdump.from",
153 FT_UINT32, BASE_HEX,
154 NULL, 0x0,
155 NULL, HFILL}
157 { &hf_netdump_to,
158 {"Netdump to val", "netdump.to",
159 FT_UINT32, BASE_HEX,
160 NULL, 0x0,
161 NULL, HFILL}
163 { &hf_netdump_code,
164 {"Netdump code", "netdump.code",
165 FT_UINT32, BASE_DEC,
166 VALS(reply_code_names), 0x0,
167 NULL, HFILL}
169 { &hf_netdump_info,
170 {"Netdump info", "netdump.info",
171 FT_UINT32, BASE_HEX,
172 NULL, 0x0,
173 NULL, HFILL}
175 { &hf_netdump_payload,
176 {"Netdump payload", "netdump.payload",
177 FT_BYTES, BASE_NONE,
178 NULL, 0x0,
179 NULL, HFILL}
181 { &hf_netdump_version,
182 {"Netdump version", "netdump.version",
183 FT_UINT8, BASE_HEX,
184 NULL, 0x0,
185 NULL, HFILL}
189 proto_netdump = proto_register_protocol (
190 "Netdump Protocol", /* name */
191 "Netdump", /* short name */
192 "netdump" /* abbrev */
194 proto_register_field_array(proto_netdump, hf, array_length(hf));
195 proto_register_subtree_array(ett, array_length(ett));
197 netdump_module = prefs_register_protocol(proto_netdump,
198 proto_reg_handoff_netdump);
200 /* Register a sample port preference */
201 prefs_register_uint_preference(netdump_module, "udp.port",
202 "Netdump UDP port",
203 "port if other than the default",
204 10, &gPORT_PREF);
207 void proto_reg_handoff_netdump(void)
209 static gboolean initalized = FALSE;
210 static dissector_handle_t netdump_handle;
211 static int CurrentPort;
213 if (!initalized) {
214 netdump_handle = create_dissector_handle(dissect_netdump,
215 proto_netdump);
217 dissector_add_handle("udp.port", netdump_handle); /* For Decode As */
218 initalized = TRUE;
219 } else {
220 if (CurrentPort != 0)
221 dissector_delete_uint("udp.port", CurrentPort, netdump_handle);
224 CurrentPort = gPORT_PREF;
226 if (CurrentPort != 0)
227 dissector_add_uint("udp.port", CurrentPort, netdump_handle);