FIXUP: WIP: verification_trailer
[wireshark-wip.git] / epan / dissectors / packet-adwin-config.c
blobde786052e956a254215ff88c03ec323f3e76150e
1 /* packet-adwin-config.c
2 * Routines for ADwin configuration protocol dissection
3 * Copyright 2010, Thomas Boehne <TBoehne[AT]ADwin.de>
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 USA.
26 #include "config.h"
28 #include <string.h>
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/emem.h>
33 #include <epan/dissectors/packet-tcp.h>
34 #include <epan/ipproto.h>
35 #include <epan/to_str.h>
37 /* Forward declarations */
38 void proto_register_adwin_config(void);
39 void proto_reg_handoff_adwin_config(void);
41 /* This is registered to a different protocol */
42 #define ADWIN_CONFIGURATION_PORT 7000
44 #define UDPStatusLENGTH 52
45 #define UDPExtStatusLENGTH 432
46 #define UDPMessageLENGTH 100
47 #define UDPMessageLENGTH_wrong 104
48 #define UDPInitAckLENGTH 96
49 #define UDPIXP425FlashUpdateLENGTH 92
50 #define UDPOutLENGTH 22
52 #define STATUS_WITH_BOOTLOADER 0x0001
53 #define STATUS_REPROGRAMMABLE 0x0002
54 #define STATUS_CONFIGURABLE 0x0004
55 #define STATUS_BOOTLOADER_BOOTS 0x0008
56 #define STATUS_BOOTLOADER_REPROGRAMMABLE 0x0010
57 #define STATUS_BOOTLOADER_RECEIVES_DATA 0x0020
58 #define STATUS_BOOTLOADER_REPROGRAMMING_DONE 0x0040
59 #define STATUS_WITH_EEPROM_SUPPORT 0x0080
61 static const value_string pattern_mapping[] = {
62 { 0x12343210, "Reset reset/socket counters"},
63 { 0x73241291, "Scan Netarm + IXP"},
64 { 0x37241291, "Scan IXP"},
65 { 0, NULL },
68 static const value_string config_command_mapping[] = {
69 { 100, "Apply all config values except MAC if MAC matches."},
70 { 105, "Apply all config values including MAC if current MAC is 00:50:C2:0A:22:EE."},
71 { 110, "Apply all config values including MAC."},
72 { 120, "Enable/Disable bootloader if MAC matches."},
73 { 130, "Write extended hardware info to EEPROM."},
74 { 0, NULL },
77 static const string_string system_type_mapping[] = {
78 { "01", "Light 16"},
79 { "02", "Gold"},
80 { "03", "Pro I"},
81 { "04", "Pro II"},
82 { "05", "Gold II"},
83 { 0, NULL },
86 static const string_string processor_type_mapping[] = {
87 { "09", "T9"},
88 { "10", "T10"},
89 { "11", "T11"},
90 { 0, NULL },
93 /* Initialize the protocol and registered fields */
94 static int proto_adwin_config = -1;
96 static int hf_adwin_config_bootloader = -1;
97 static int hf_adwin_config_command = -1;
98 static int hf_adwin_config_data = -1;
99 static int hf_adwin_config_date = -1;
100 static int hf_adwin_config_description = -1;
101 static int hf_adwin_config_dhcp = -1;
102 static int hf_adwin_config_filename = -1;
103 static int hf_adwin_config_filesize = -1;
104 static int hf_adwin_config_gateway = -1;
105 static int hf_adwin_config_mac = -1;
106 static int hf_adwin_config_netmask_count = -1;
107 static int hf_adwin_config_netmask = -1;
108 static int hf_adwin_config_password = -1;
109 static int hf_adwin_config_path = -1;
110 static int hf_adwin_config_pattern = -1;
111 static int hf_adwin_config_port16 = -1;
112 static int hf_adwin_config_port32 = -1;
113 static int hf_adwin_config_reboot = -1;
114 static int hf_adwin_config_scan_id = -1;
115 static int hf_adwin_config_reply_broadcast = -1;
116 static int hf_adwin_config_revision = -1;
117 static int hf_adwin_config_processor_type = -1;
118 static int hf_adwin_config_system_type = -1;
119 static int hf_adwin_config_server_ip = -1;
120 static int hf_adwin_config_server_version = -1;
121 static int hf_adwin_config_server_version_beta = -1;
122 static int hf_adwin_config_socketshutdowns = -1;
123 static int hf_adwin_config_status = -1;
124 static int hf_adwin_config_status_bootloader = -1;
125 static int hf_adwin_config_status_reprogrammable = -1;
126 static int hf_adwin_config_status_configurable = -1;
127 static int hf_adwin_config_status_bootloader_boots = -1;
128 static int hf_adwin_config_status_bootloader_reprogrammable = -1;
129 static int hf_adwin_config_status_bootloader_receive = -1;
130 static int hf_adwin_config_status_bootloader_reprogramming_done = -1;
131 static int hf_adwin_config_status_eeprom_support = -1;
132 static int hf_adwin_config_stream_length = -1;
133 static int hf_adwin_config_timeout = -1;
134 static int hf_adwin_config_timerresets = -1;
135 static int hf_adwin_config_disk_free = -1;
136 static int hf_adwin_config_disk_size = -1;
137 static int hf_adwin_config_unused = -1;
138 static int hf_adwin_config_version = -1;
139 static int hf_adwin_config_xilinx_version = -1;
141 /* Initialize the subtree pointers */
142 static gint ett_adwin_config = -1;
143 static gint ett_adwin_config_status = -1;
144 static gint ett_adwin_config_debug = -1;
146 static void
147 dissect_UDPStatus(tvbuff_t *tvb, proto_tree *adwin_tree)
149 proto_tree *status_tree;
150 proto_tree *debug_tree;
151 proto_item *st, *dt;
153 if (! adwin_tree)
154 return;
156 dt = proto_tree_add_item(adwin_tree, proto_adwin_config, tvb, 0, -1, ENC_NA);
157 debug_tree = proto_item_add_subtree(dt, ett_adwin_config_debug);
158 proto_item_set_text(dt, "ADwin Debug information");
160 proto_tree_add_item(adwin_tree, hf_adwin_config_pattern, tvb, 0, 4, ENC_BIG_ENDIAN);
161 proto_tree_add_item(adwin_tree, hf_adwin_config_version, tvb, 4, 4, ENC_BIG_ENDIAN);
163 st = proto_tree_add_item(adwin_tree, hf_adwin_config_status, tvb, 8, 4, ENC_BIG_ENDIAN);
164 status_tree = proto_item_add_subtree(st, ett_adwin_config_status);
165 proto_tree_add_item(status_tree, hf_adwin_config_status_bootloader, tvb, 8, 4, ENC_BIG_ENDIAN);
166 proto_tree_add_item(status_tree, hf_adwin_config_status_reprogrammable, tvb, 8, 4, ENC_BIG_ENDIAN);
167 proto_tree_add_item(status_tree, hf_adwin_config_status_configurable, tvb, 8, 4, ENC_BIG_ENDIAN);
168 proto_tree_add_item(status_tree, hf_adwin_config_status_bootloader_boots, tvb, 8, 4, ENC_BIG_ENDIAN);
169 proto_tree_add_item(status_tree, hf_adwin_config_status_bootloader_reprogrammable, tvb, 8, 4, ENC_BIG_ENDIAN);
170 proto_tree_add_item(status_tree, hf_adwin_config_status_bootloader_receive, tvb, 8, 4, ENC_BIG_ENDIAN);
171 proto_tree_add_item(status_tree, hf_adwin_config_status_bootloader_reprogramming_done, tvb, 8, 4, ENC_BIG_ENDIAN);
172 proto_tree_add_item(status_tree, hf_adwin_config_status_eeprom_support, tvb, 8, 4, ENC_BIG_ENDIAN);
174 proto_tree_add_item(adwin_tree, hf_adwin_config_server_version_beta, tvb, 12, 2, ENC_BIG_ENDIAN);
175 proto_tree_add_item(adwin_tree, hf_adwin_config_server_version, tvb, 14, 2, ENC_BIG_ENDIAN);
176 proto_tree_add_item(adwin_tree, hf_adwin_config_xilinx_version, tvb, 16, 4, ENC_BIG_ENDIAN);
177 proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 20, 6, ENC_BIG_ENDIAN);
178 proto_tree_add_item(debug_tree, hf_adwin_config_unused, tvb, 26, 2, ENC_LITTLE_ENDIAN);
179 proto_tree_add_item(adwin_tree, hf_adwin_config_port16, tvb, 28, 2, ENC_BIG_ENDIAN);
180 proto_tree_add_item(adwin_tree, hf_adwin_config_dhcp, tvb, 30, 1, ENC_LITTLE_ENDIAN);
181 proto_tree_add_item(adwin_tree, hf_adwin_config_netmask_count, tvb, 31, 1, ENC_LITTLE_ENDIAN);
182 proto_tree_add_item(adwin_tree, hf_adwin_config_gateway, tvb, 32, 4, ENC_BIG_ENDIAN);
183 proto_tree_add_item(debug_tree, hf_adwin_config_unused, tvb, 36, 11, ENC_LITTLE_ENDIAN);
184 proto_tree_add_item(adwin_tree, hf_adwin_config_reply_broadcast, tvb, 47, 1, ENC_LITTLE_ENDIAN);
185 proto_tree_add_item(adwin_tree, hf_adwin_config_scan_id, tvb, 48, 4, ENC_LITTLE_ENDIAN);
188 static void
189 dissect_UDPExtStatus(tvbuff_t *tvb, proto_tree *adwin_tree)
191 const gchar *processor_type, *system_type;
193 if (! adwin_tree)
194 return;
196 proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 0, 6, ENC_BIG_ENDIAN);
197 proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 6, 2, ENC_LITTLE_ENDIAN);
198 proto_tree_add_item(adwin_tree, hf_adwin_config_pattern, tvb, 8, 4, ENC_BIG_ENDIAN);
199 proto_tree_add_item(adwin_tree, hf_adwin_config_version, tvb, 12, 4, ENC_BIG_ENDIAN);
200 proto_tree_add_item(adwin_tree, hf_adwin_config_description, tvb, 16, 16, ENC_LITTLE_ENDIAN);
201 proto_tree_add_item(adwin_tree, hf_adwin_config_timerresets, tvb, 32, 4, ENC_BIG_ENDIAN);
202 proto_tree_add_item(adwin_tree, hf_adwin_config_socketshutdowns, tvb, 36, 4, ENC_BIG_ENDIAN);
203 proto_tree_add_item(adwin_tree, hf_adwin_config_disk_free, tvb, 40, 4, ENC_BIG_ENDIAN);
204 proto_tree_add_item(adwin_tree, hf_adwin_config_disk_size, tvb, 44, 4, ENC_BIG_ENDIAN);
205 proto_tree_add_item(adwin_tree, hf_adwin_config_date, tvb, 48, 8, ENC_LITTLE_ENDIAN);
206 proto_tree_add_item(adwin_tree, hf_adwin_config_revision, tvb, 56, 8, ENC_LITTLE_ENDIAN);
208 /* add the processor type raw values to the tree, to allow filtering */
209 proto_tree_add_item(adwin_tree, hf_adwin_config_processor_type, tvb, 64, 2, ENC_LITTLE_ENDIAN);
210 /* add the processor type as a pretty printed string */
211 processor_type = tvb_get_string(wmem_packet_scope(), tvb, 64, 2);
212 processor_type = str_to_str(processor_type, processor_type_mapping, "Unknown (%s)");
213 proto_tree_add_text(adwin_tree, tvb, 64, 2, "Processor Type: %s", processor_type);
215 /* add system type as raw value and pretty printed string */
216 proto_tree_add_item(adwin_tree, hf_adwin_config_system_type, tvb, 66, 2, ENC_LITTLE_ENDIAN);
217 system_type = tvb_get_string(wmem_packet_scope(), tvb, 66, 2);
218 system_type = str_to_str(system_type, system_type_mapping, "Unknown (%s)");
219 proto_tree_add_text(adwin_tree, tvb, 66, 2, "System Type: %s", system_type);
221 proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 68, 364, ENC_LITTLE_ENDIAN);
224 static void
225 dissect_UDPMessage(tvbuff_t *tvb, proto_tree *adwin_tree)
227 const gchar *processor_type, *system_type;
229 if (! adwin_tree)
230 return;
232 proto_tree_add_item(adwin_tree, hf_adwin_config_command, tvb, 0, 4, ENC_LITTLE_ENDIAN);
233 proto_tree_add_item(adwin_tree, hf_adwin_config_version, tvb, 4, 4, ENC_LITTLE_ENDIAN);
234 proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 8, 6, ENC_LITTLE_ENDIAN);
235 proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 14, 2, ENC_LITTLE_ENDIAN);
236 proto_tree_add_item(adwin_tree, hf_adwin_config_server_ip, tvb, 16, 4, ENC_LITTLE_ENDIAN);
237 proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 20, 4, ENC_LITTLE_ENDIAN);
238 proto_tree_add_item(adwin_tree, hf_adwin_config_netmask, tvb, 24, 4, ENC_LITTLE_ENDIAN);
239 proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 28, 4, ENC_LITTLE_ENDIAN);
240 proto_tree_add_item(adwin_tree, hf_adwin_config_gateway, tvb, 32, 4, ENC_LITTLE_ENDIAN);
241 proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 36, 4, ENC_LITTLE_ENDIAN);
242 proto_tree_add_item(adwin_tree, hf_adwin_config_dhcp, tvb, 40, 4, ENC_LITTLE_ENDIAN);
243 proto_tree_add_item(adwin_tree, hf_adwin_config_port32, tvb, 44, 4, ENC_LITTLE_ENDIAN);
244 proto_tree_add_item(adwin_tree, hf_adwin_config_password, tvb, 48, 10, ENC_LITTLE_ENDIAN);
245 proto_tree_add_item(adwin_tree, hf_adwin_config_bootloader, tvb, 58, 1, ENC_LITTLE_ENDIAN);
246 proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 59, 5, ENC_LITTLE_ENDIAN);
247 proto_tree_add_item(adwin_tree, hf_adwin_config_description, tvb, 64, 16, ENC_LITTLE_ENDIAN);
248 proto_tree_add_item(adwin_tree, hf_adwin_config_date, tvb, 80, 8, ENC_LITTLE_ENDIAN);
249 proto_tree_add_item(adwin_tree, hf_adwin_config_revision, tvb, 88, 8, ENC_LITTLE_ENDIAN);
251 /* add the processor type raw values to the tree, to allow filtering */
252 proto_tree_add_item(adwin_tree, hf_adwin_config_processor_type, tvb, 96, 2, ENC_LITTLE_ENDIAN);
253 /* add the processor type as a pretty printed string */
254 processor_type = tvb_get_string(wmem_packet_scope(), tvb, 96, 2);
255 processor_type = str_to_str(processor_type, processor_type_mapping, "Unknown");
256 proto_tree_add_text(adwin_tree, tvb, 96, 2, "Processor Type: %s", processor_type);
258 /* add system type as raw value and pretty printed string */
259 proto_tree_add_item(adwin_tree, hf_adwin_config_system_type, tvb, 98, 2, ENC_LITTLE_ENDIAN);
260 system_type = tvb_get_string(wmem_packet_scope(), tvb, 98, 2);
261 system_type = str_to_str(system_type, system_type_mapping, "Unknown");
262 proto_tree_add_text(adwin_tree, tvb, 98, 2, "System Type: %s", system_type);
265 static void
266 dissect_UDPInitAck(tvbuff_t *tvb, proto_tree *adwin_tree)
269 if (! adwin_tree)
270 return;
272 proto_tree_add_item(adwin_tree, hf_adwin_config_pattern, tvb, 0, 4, ENC_BIG_ENDIAN);
273 proto_tree_add_item(adwin_tree, hf_adwin_config_reboot, tvb, 4, 4, ENC_LITTLE_ENDIAN);
274 proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 8, 6, ENC_BIG_ENDIAN);
275 proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 14, 2, ENC_LITTLE_ENDIAN);
276 proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 16, 80, ENC_LITTLE_ENDIAN);
279 static void
280 dissect_UDPIXP425FlashUpdate(tvbuff_t *tvb, proto_tree *adwin_tree)
283 if (! adwin_tree)
284 return;
286 proto_tree_add_item(adwin_tree, hf_adwin_config_pattern, tvb, 0, 4, ENC_BIG_ENDIAN);
287 proto_tree_add_item(adwin_tree, hf_adwin_config_version, tvb, 4, 4, ENC_BIG_ENDIAN);
288 proto_tree_add_item(adwin_tree, hf_adwin_config_scan_id, tvb, 8, 4, ENC_BIG_ENDIAN);
289 proto_tree_add_item(adwin_tree, hf_adwin_config_status, tvb, 12, 4, ENC_BIG_ENDIAN);
290 proto_tree_add_item(adwin_tree, hf_adwin_config_timeout, tvb, 16, 4, ENC_BIG_ENDIAN);
291 proto_tree_add_item(adwin_tree, hf_adwin_config_filename, tvb, 20, 24, ENC_BIG_ENDIAN);
292 proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 44, 6, ENC_BIG_ENDIAN);
293 proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 50, 42, ENC_BIG_ENDIAN);
296 static void
297 dissect_UDPOut(tvbuff_t *tvb, proto_tree *adwin_tree)
300 if (! adwin_tree)
301 return;
303 proto_tree_add_item(adwin_tree, hf_adwin_config_status, tvb, 0, 4, ENC_LITTLE_ENDIAN);
304 proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 4, 6, ENC_BIG_ENDIAN);
305 proto_tree_add_item(adwin_tree, hf_adwin_config_netmask, tvb, 10, 4, ENC_LITTLE_ENDIAN);
306 proto_tree_add_item(adwin_tree, hf_adwin_config_gateway, tvb, 14, 4, ENC_BIG_ENDIAN);
307 proto_tree_add_item(adwin_tree, hf_adwin_config_dhcp, tvb, 18, 2, ENC_LITTLE_ENDIAN);
308 proto_tree_add_item(adwin_tree, hf_adwin_config_port16, tvb, 20, 2, ENC_BIG_ENDIAN);
311 static guint
312 get_adwin_TCPUpdate_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
315 * Return the length of the packet. (Doesn't include the length field itself)
317 return tvb_get_ntohl(tvb, offset);
320 static int
321 dissect_TCPFlashUpdate(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
323 proto_tree *adwin_tree;
324 proto_item *ti;
325 gint length, offset;
326 guint8 *filename;
327 nstime_t tmp_time;
329 tmp_time.nsecs = 0;
331 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ADwin Config");
332 col_set_str(pinfo->cinfo, COL_INFO, "TCPFlashUpdate");
334 ti = proto_tree_add_item(tree, proto_adwin_config, tvb, 0, -1, ENC_NA);
335 adwin_tree = proto_item_add_subtree(ti, ett_adwin_config);
337 proto_tree_add_item(adwin_tree, hf_adwin_config_stream_length, tvb, 0, 4, ENC_BIG_ENDIAN);
338 offset = 4;
339 length = tvb_strnlen(tvb, offset, -1) + 1;
340 filename = tvb_get_string(wmem_packet_scope(), tvb, offset, length);
341 if (strncmp(filename, "eeprom_on", length) == 0) {
342 proto_tree_add_text(adwin_tree, tvb, offset, length,
343 "Enable EEPROM Support");
344 return offset+length;
346 if (strncmp(filename, "eeprom_off", length) == 0) {
347 proto_tree_add_text(adwin_tree, tvb, offset, length,
348 "Disable EEPROM Support");
349 return offset+length;
351 proto_tree_add_item(adwin_tree, hf_adwin_config_filename, tvb, 4, length, ENC_BIG_ENDIAN);
352 offset += length;
353 length = tvb_strnlen(tvb, 4 + length, -1) + 1;
354 proto_tree_add_item(adwin_tree, hf_adwin_config_path, tvb, offset, length, ENC_BIG_ENDIAN);
355 offset += length;
356 proto_tree_add_item(adwin_tree, hf_adwin_config_filesize, tvb, offset, 4, ENC_BIG_ENDIAN);
357 offset += 4;
358 tmp_time.secs = tvb_get_ntohl(tvb, offset);
359 proto_tree_add_text(adwin_tree, tvb, offset, 4,
360 "File time: %s", abs_time_to_str(&tmp_time, ABSOLUTE_TIME_LOCAL, TRUE));
361 offset += 4;
362 tmp_time.secs = tvb_get_ntohl(tvb, offset);
363 proto_tree_add_text(adwin_tree, tvb, offset, 4,
364 "Update time: %s", abs_time_to_str(&tmp_time, ABSOLUTE_TIME_LOCAL, TRUE));
365 offset += 4;
366 proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, offset, 128, ENC_BIG_ENDIAN);
367 offset += 128;
368 length = tvb_length(tvb) - offset;
369 proto_tree_add_item(adwin_tree, hf_adwin_config_data, tvb, offset, length, ENC_BIG_ENDIAN);
371 return tvb_length(tvb);
374 /* 00:50:c2:0a:2*:** */
375 static const unsigned char mac_iab_start[] = { 0x00, 0x50, 0xc2, 0x0a, 0x20, 0x00 };
376 static const unsigned char mac_iab_end[] = { 0x00, 0x50, 0xc2, 0x0a, 0x2f, 0xff };
378 /* 00:22:71:**:**:** */
379 static const unsigned char mac_oui_start[] = { 0x00, 0x22, 0x71, 0x00, 0x00, 0x00 };
380 static const unsigned char mac_oui_end[] = { 0x00, 0x22, 0x71, 0xff, 0xff, 0xff };
382 /* ff:ff:ff:ff:ff:ff */
383 static const unsigned char mac_broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
385 /* return TRUE if mac is in mac address range assigned to ADwin or if
386 * mac is broadcast */
387 static gboolean
388 is_adwin_mac_or_broadcast(address mac)
390 if (mac.type != AT_ETHER)
391 return FALSE;
393 if (mac.len != 6) /* length of MAC address */
394 return FALSE;
396 if ((memcmp(mac.data, mac_iab_start, mac.len) >= 0) &&
397 (memcmp(mac.data, mac_iab_end , mac.len) <= 0))
398 return TRUE;
400 if ((memcmp(mac.data, mac_oui_start, mac.len) >= 0) &&
401 (memcmp(mac.data, mac_oui_end, mac.len) <= 0))
402 return TRUE;
404 /* adwin configuration protocol uses MAC broadcasts for
405 device discovery */
406 if (memcmp(mac.data, mac_broadcast, mac.len) == 0)
407 return TRUE;
409 return FALSE;
413 /* Here we determine which type of packet is sent by looking at its
414 size. Let's hope that future ADwin packets always differ in size.
415 They probably will, since the server classifies the packets
416 according to their sizes, too. */
418 static const value_string length_mapping[] = {
419 { UDPStatusLENGTH, "UDPStatus" },
420 { UDPExtStatusLENGTH, "UDPExtStatus" },
421 { UDPMessageLENGTH, "UDPMessage" },
422 { UDPMessageLENGTH_wrong, "UDPMessage (broken - upgrade ADConfig!)" },
423 { UDPInitAckLENGTH, "UDPInitAck" },
424 { UDPIXP425FlashUpdateLENGTH, "UDPIXP425FlashUpdate" },
425 { UDPOutLENGTH, "UDPOut" },
426 { 0, NULL },
429 static int
430 dissect_adwin_config_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
432 proto_item *ti;
433 proto_tree *adwin_config_tree;
434 guint32 length;
436 length = tvb_reported_length(tvb);
438 if (!(length == UDPStatusLENGTH
439 || length == UDPExtStatusLENGTH
440 || length == UDPMessageLENGTH
441 || length == UDPMessageLENGTH_wrong
442 || length == UDPInitAckLENGTH
443 || length == UDPIXP425FlashUpdateLENGTH
444 || length == UDPOutLENGTH))
445 return 0;
447 if (! (is_adwin_mac_or_broadcast(pinfo->dl_src) || is_adwin_mac_or_broadcast(pinfo->dl_dst)))
448 return 0;
450 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ADwin Config");
451 col_clear(pinfo->cinfo, COL_INFO);
453 ti = proto_tree_add_item(tree, proto_adwin_config, tvb, 0, -1, ENC_NA);
454 adwin_config_tree = proto_item_add_subtree(ti, ett_adwin_config);
456 switch (length) {
457 case UDPStatusLENGTH:
458 dissect_UDPStatus(tvb, adwin_config_tree);
459 break;
460 case UDPExtStatusLENGTH:
461 dissect_UDPExtStatus(tvb, adwin_config_tree);
462 break;
463 case UDPMessageLENGTH:
464 dissect_UDPMessage(tvb, adwin_config_tree);
465 break;
466 case UDPMessageLENGTH_wrong: /* incorrect packet length */
467 /* formerly used by adconfig */
468 dissect_UDPMessage(tvb, adwin_config_tree);
469 break;
470 case UDPInitAckLENGTH:
471 dissect_UDPInitAck(tvb, adwin_config_tree);
472 break;
473 case UDPIXP425FlashUpdateLENGTH:
474 dissect_UDPIXP425FlashUpdate(tvb, adwin_config_tree);
475 break;
476 case UDPOutLENGTH:
477 dissect_UDPOut(tvb, adwin_config_tree);
478 break;
479 default:
480 /* Heuristics above should mean we never get here */
481 col_add_str(pinfo->cinfo, COL_INFO,
482 val_to_str(length, length_mapping,
483 "Unknown ADwin Configuration packet, length: %d"));
486 return (tvb_reported_length(tvb));
489 static int
490 dissect_adwin_config_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
492 if(!(pinfo->srcport == ADWIN_CONFIGURATION_PORT
493 || pinfo->destport == ADWIN_CONFIGURATION_PORT))
494 return 0;
496 /* XXX - Is this possible for TCP? */
497 if (! (is_adwin_mac_or_broadcast(pinfo->dl_src) || is_adwin_mac_or_broadcast(pinfo->dl_dst)))
498 return 0;
500 tcp_dissect_pdus(tvb, pinfo, tree, 1, 4, get_adwin_TCPUpdate_len, dissect_TCPFlashUpdate, NULL);
502 return (tvb_reported_length(tvb));
505 void
506 proto_register_adwin_config(void)
508 static hf_register_info hf[] = {
509 { &hf_adwin_config_bootloader,
510 { "Enable Bootloader", "adwin_config.bootloader",
511 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
512 NULL, HFILL }
514 { &hf_adwin_config_command,
515 { "Command", "adwin_config.command",
516 FT_UINT32, BASE_DEC, config_command_mapping, 0x0,
517 NULL, HFILL }
519 { &hf_adwin_config_data,
520 { "Data", "adwin_config.data",
521 FT_NONE, BASE_NONE, NULL, 0x0,
522 NULL, HFILL }
524 { &hf_adwin_config_date,
525 { "Date", "adwin_config.date",
526 FT_STRING, BASE_NONE, NULL, 0x0,
527 NULL, HFILL }
529 { &hf_adwin_config_description,
530 { "Description", "adwin_config.description",
531 FT_STRING, BASE_NONE, NULL, 0x0,
532 NULL, HFILL }
534 { &hf_adwin_config_dhcp,
535 { "DHCP enabled", "adwin_config.dhcp",
536 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
537 NULL, HFILL }
539 { &hf_adwin_config_filename,
540 { "File name", "adwin_config.filename",
541 FT_STRING, BASE_NONE, NULL, 0x0,
542 NULL, HFILL }
544 { &hf_adwin_config_filesize,
545 { "File size", "adwin_config.filesize",
546 FT_INT32, BASE_DEC, NULL, 0x0,
547 NULL, HFILL }
549 { &hf_adwin_config_gateway,
550 { "Gateway IP", "adwin_config.gateway",
551 FT_IPv4, BASE_NONE, NULL, 0x0,
552 NULL, HFILL }
554 { &hf_adwin_config_mac,
555 { "MAC address", "adwin_config.mac",
556 FT_ETHER, BASE_NONE, NULL, 0x0,
557 NULL, HFILL }
559 { &hf_adwin_config_netmask,
560 { "Netmask", "adwin_config.netmask",
561 FT_IPv4, BASE_NONE, NULL, 0x0,
562 NULL, HFILL }
564 { &hf_adwin_config_netmask_count,
565 { "Netmask count", "adwin_config.netmask_count",
566 FT_UINT8, BASE_DEC, NULL, 0x0,
567 "The number of binary ones in the netmask.", HFILL }
569 { &hf_adwin_config_password,
570 { "Password", "adwin_config.password",
571 FT_STRING, BASE_NONE, NULL, 0x0,
572 "Password to set for ADwin system.", HFILL }
574 { &hf_adwin_config_pattern,
575 { "Pattern", "adwin_config.pattern",
576 FT_UINT32, BASE_HEX, pattern_mapping, 0x0,
577 NULL, HFILL }
579 { &hf_adwin_config_path,
580 { "Path", "adwin_config.path",
581 FT_STRING, BASE_NONE, NULL, 0x0,
582 NULL, HFILL }
584 { &hf_adwin_config_port16,
585 { "Port (16bit)", "adwin_config.port",
586 FT_UINT16, BASE_DEC, NULL, 0x0,
587 "The server port on which the ADwin system is listening on (16bit).", HFILL }
589 { &hf_adwin_config_port32,
590 { "Port (32bit)", "adwin_config.port",
591 FT_UINT32, BASE_DEC, NULL, 0x0,
592 "The server port on which the ADwin system is listening on (32bit).", HFILL }
594 { &hf_adwin_config_reboot,
595 { "Reboot", "adwin_config.reboot",
596 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
597 "Number of system reboots.", HFILL }
599 { &hf_adwin_config_scan_id,
600 { "Scan ID", "adwin_config.scan_id",
601 FT_UINT32, BASE_HEX, NULL, 0x0,
602 NULL, HFILL }
604 { &hf_adwin_config_reply_broadcast, /* send_normal in UDPStatus */
605 { "Reply with broadcast", "adwin_config.reply_broadcast",
606 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
607 "If this bit is set, the scanned system should reply with a broadcast.", HFILL }
609 { &hf_adwin_config_revision,
610 { "Revision", "adwin_config.revision",
611 FT_STRING, BASE_NONE, NULL, 0x0,
612 NULL, HFILL }
614 { &hf_adwin_config_processor_type,
615 { "Processor Type (Raw value)", "adwin_config.processor_type",
616 FT_STRING, BASE_NONE, NULL, 0x0,
617 "The DSP processor type of the ADwin system, e.g. T9, T10 or T11.", HFILL }
619 { &hf_adwin_config_system_type,
620 { "System Type (Raw value)", "adwin_config.system_type",
621 FT_STRING, BASE_NONE, NULL, 0x0,
622 "The system type of the ADwin system, e.g. Gold, Pro or Light.", HFILL }
624 { &hf_adwin_config_server_ip,
625 { "Server IP", "adwin_config.server_ip",
626 FT_IPv4, BASE_NONE, NULL, 0x0,
627 "In scan replies, this is the current IP address of the ADwin system. In configuration packets, this is the new IP to be used by the ADwin system.", HFILL }
629 { &hf_adwin_config_server_version,
630 { "Server version", "adwin_config.server_version",
631 FT_UINT32, BASE_DEC, NULL, 0x0,
632 "The version number of the server program. This number represents the complete firmware version, e.g. 2.74.", HFILL }
634 { &hf_adwin_config_server_version_beta,
635 { "server version (beta part)", "adwin_config.server_version_beta",
636 FT_UINT32, BASE_DEC, NULL, 0x0,
637 "A non-zero value of this field indicates a beta firmware version, where this number represents the current revision.", HFILL }
639 { &hf_adwin_config_socketshutdowns,
640 { "Socket shutdowns", "adwin_config.socketshutdowns",
641 FT_UINT32, BASE_DEC, NULL, 0x0,
642 "Number of socket errors that lead to a recreation of the socket (ethernet interface version 1 only).", HFILL }
644 { &hf_adwin_config_status,
645 { "Status", "adwin_config.status",
646 FT_UINT32, BASE_HEX, NULL, 0x0,
647 NULL, HFILL }
649 { &hf_adwin_config_status_bootloader,
650 { "Status Bootloader", "adwin_config.status_bootloader",
651 FT_BOOLEAN, 32, NULL, STATUS_WITH_BOOTLOADER,
652 "Indicates if the ADwin system has bootloader capabilities.", HFILL }
654 { &hf_adwin_config_status_reprogrammable,
655 { "Status Reprogrammable",
656 "adwin_config.status_reprogrammable",
657 FT_BOOLEAN, 32, NULL, STATUS_REPROGRAMMABLE,
658 NULL, HFILL }
660 { &hf_adwin_config_status_configurable,
661 { "Status Configurable", "adwin_config.status_configurable",
662 FT_BOOLEAN, 32, NULL, STATUS_CONFIGURABLE,
663 NULL, HFILL }
665 { &hf_adwin_config_status_bootloader_boots,
666 { "Status Bootloader boots",
667 "adwin_config.status_bootloader_boots",
668 FT_BOOLEAN, 32, NULL, STATUS_BOOTLOADER_BOOTS,
669 NULL, HFILL }
671 { &hf_adwin_config_status_bootloader_reprogrammable,
672 { "Status Bootloader reprogrammable",
673 "adwin_config.status_bootloader_reprogrammable",
674 FT_BOOLEAN, 32, NULL, STATUS_BOOTLOADER_REPROGRAMMABLE,
675 NULL, HFILL }
677 { &hf_adwin_config_status_bootloader_receive,
678 { "Status Bootloader receive",
679 "adwin_config.status_bootloader_receive",
680 FT_BOOLEAN, 32, NULL, STATUS_BOOTLOADER_RECEIVES_DATA,
681 NULL, HFILL }
683 { &hf_adwin_config_status_bootloader_reprogramming_done,
684 { "Status Bootloader reprogramming done",
685 "adwin_config.status_bootloader_reprogramming_done",
686 FT_BOOLEAN, 32, NULL, STATUS_BOOTLOADER_REPROGRAMMING_DONE,
687 NULL, HFILL }
689 { &hf_adwin_config_status_eeprom_support,
690 { "Status EEPROM Support",
691 "adwin_config.status_eeprom_support",
692 FT_BOOLEAN, 32, NULL, STATUS_WITH_EEPROM_SUPPORT,
693 NULL, HFILL }
695 { &hf_adwin_config_stream_length,
696 { "Stream length", "adwin_config.stream_length",
697 FT_INT32, BASE_DEC, NULL, 0x0,
698 NULL, HFILL }
700 { &hf_adwin_config_timeout,
701 { "Timeout", "adwin_config.timeout",
702 FT_UINT32, BASE_DEC, NULL, 0x0,
703 NULL, HFILL }
705 { &hf_adwin_config_timerresets,
706 { "Timer resets", "adwin_config.timerresets",
707 FT_UINT32, BASE_DEC, NULL, 0x0,
708 "Counter for resets of the timer (ethernet interface version 1 only).", HFILL }
710 { &hf_adwin_config_disk_free,
711 { "Free disk space (kb)", "adwin_config.disk_free",
712 FT_UINT32, BASE_DEC, NULL, 0x0,
713 "Free disk space in kb on flash (ethernet interface version 2 only).", HFILL }
715 { &hf_adwin_config_disk_size,
716 { "Disk size (kb)", "adwin_config.disk_size",
717 FT_UINT32, BASE_DEC, NULL, 0x0,
718 "Flash disk size in kb (ethernet interface version 2 only).", HFILL }
720 { &hf_adwin_config_unused,
721 { "Unused", "adwin_config.unused",
722 FT_NONE, BASE_NONE, NULL, 0x0,
723 NULL, HFILL }
725 { &hf_adwin_config_version,
726 { "Version", "adwin_config.version",
727 FT_UINT32, BASE_DEC, NULL, 0x0,
728 NULL, HFILL }
730 { &hf_adwin_config_xilinx_version,
731 { "XILINX Version", "adwin_config.xilinx_version",
732 FT_UINT32, BASE_HEX, NULL, 0x0,
733 "Version of XILINX program", HFILL }
737 /* Setup protocol subtree array */
738 static gint *ett[] = {
739 &ett_adwin_config,
740 &ett_adwin_config_status,
741 &ett_adwin_config_debug,
744 /* Register the protocol name and description */
745 proto_adwin_config =
746 proto_register_protocol("ADwin configuration protocol",
747 "ADwin-Config", "adwin_config");
749 /* Required function calls to register the header fields and
750 subtrees used */
751 proto_register_field_array(proto_adwin_config, hf, array_length(hf));
752 proto_register_subtree_array(ett, array_length(ett));
755 void
756 proto_reg_handoff_adwin_config(void)
758 heur_dissector_add("udp", dissect_adwin_config_udp, proto_adwin_config);
759 heur_dissector_add("tcp", dissect_adwin_config_tcp, proto_adwin_config);