checkAPIs.pl: support for new-style dissectors in check_hf_entries
[metze/wireshark/wip.git] / epan / dissectors / packet-adwin-config.c
1 /* packet-adwin-config.c
2  * Routines for ADwin configuration protocol dissection
3  * Copyright 2010, Thomas Boehne <TBoehne[AT]ADwin.de>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11
12 #include "config.h"
13
14
15 #include <epan/packet.h>
16 #include "packet-tcp.h"
17
18 /* Forward declarations */
19 void proto_register_adwin_config(void);
20 void proto_reg_handoff_adwin_config(void);
21
22 /* This is registered to a different protocol */
23 #define ADWIN_CONFIGURATION_PORT 7000
24
25 #define UDPStatusLENGTH             52
26 #define UDPExtStatusLENGTH         432
27 #define UDPMessageLENGTH           100
28 #define UDPMessageLENGTH_wrong     104
29 #define UDPInitAckLENGTH            96
30 #define UDPIXP425FlashUpdateLENGTH  92
31 #define UDPOutLENGTH                22
32
33 #define STATUS_WITH_BOOTLOADER                  0x0001
34 #define STATUS_REPROGRAMMABLE                   0x0002
35 #define STATUS_CONFIGURABLE                     0x0004
36 #define STATUS_BOOTLOADER_BOOTS                 0x0008
37 #define STATUS_BOOTLOADER_REPROGRAMMABLE        0x0010
38 #define STATUS_BOOTLOADER_RECEIVES_DATA         0x0020
39 #define STATUS_BOOTLOADER_REPROGRAMMING_DONE    0x0040
40 #define STATUS_WITH_EEPROM_SUPPORT              0x0080
41
42 static const value_string pattern_mapping[] = {
43         { 0x12343210, "Reset reset/socket counters"},
44         { 0x73241291, "Scan Netarm + IXP"},
45         { 0x37241291, "Scan IXP"},
46         { 0, NULL },
47 };
48
49 static const value_string config_command_mapping[] = {
50         { 100, "Apply all config values except MAC if MAC matches."},
51         { 105, "Apply all config values including MAC if current MAC is 00:50:C2:0A:22:EE."},
52         { 110, "Apply all config values including MAC."},
53         { 120, "Enable/Disable bootloader if MAC matches."},
54         { 130, "Write extended hardware info to EEPROM."},
55         { 0, NULL },
56 };
57
58 static const string_string system_type_mapping[] = {
59         { "01", "Light 16"},
60         { "02", "Gold"},
61         { "03", "Pro I"},
62         { "04", "Pro II"},
63         { "05", "Gold II"},
64         { 0, NULL },
65 };
66
67 static const string_string processor_type_mapping[] = {
68         { "09", "T9"},
69         { "10", "T10"},
70         { "11", "T11"},
71         { 0, NULL },
72 };
73
74 /* Initialize the protocol and registered fields */
75 static int proto_adwin_config                     = -1;
76
77 static int hf_adwin_config_bootloader             = -1;
78 static int hf_adwin_config_command                = -1;
79 static int hf_adwin_config_data                   = -1;
80 static int hf_adwin_config_date                   = -1;
81 static int hf_adwin_config_description            = -1;
82 static int hf_adwin_config_dhcp                   = -1;
83 static int hf_adwin_config_filename               = -1;
84 static int hf_adwin_config_filesize               = -1;
85 static int hf_adwin_config_filetime               = -1;
86 static int hf_adwin_config_updatetime             = -1;
87 static int hf_adwin_config_gateway                = -1;
88 static int hf_adwin_config_mac                    = -1;
89 static int hf_adwin_config_netmask_count          = -1;
90 static int hf_adwin_config_netmask                = -1;
91 static int hf_adwin_config_password               = -1;
92 static int hf_adwin_config_path                   = -1;
93 static int hf_adwin_config_pattern                = -1;
94 static int hf_adwin_config_port16                 = -1;
95 static int hf_adwin_config_port32                 = -1;
96 static int hf_adwin_config_reboot                 = -1;
97 static int hf_adwin_config_scan_id                = -1;
98 static int hf_adwin_config_reply_broadcast        = -1;
99 static int hf_adwin_config_revision               = -1;
100 static int hf_adwin_config_processor_type_raw     = -1;
101 static int hf_adwin_config_system_type_raw        = -1;
102 static int hf_adwin_config_processor_type         = -1;
103 static int hf_adwin_config_system_type            = -1;
104 static int hf_adwin_config_server_ip              = -1;
105 static int hf_adwin_config_server_version         = -1;
106 static int hf_adwin_config_server_version_beta    = -1;
107 static int hf_adwin_config_socketshutdowns        = -1;
108 static int hf_adwin_config_status                 = -1;
109 static int hf_adwin_config_status_bootloader      = -1;
110 static int hf_adwin_config_status_reprogrammable  = -1;
111 static int hf_adwin_config_status_configurable    = -1;
112 static int hf_adwin_config_status_bootloader_boots = -1;
113 static int hf_adwin_config_status_bootloader_reprogrammable  = -1;
114 static int hf_adwin_config_status_bootloader_receive = -1;
115 static int hf_adwin_config_status_bootloader_reprogramming_done  = -1;
116 static int hf_adwin_config_status_eeprom_support  = -1;
117 static int hf_adwin_config_stream_length          = -1;
118 static int hf_adwin_config_eeprom_support         = -1;
119 static int hf_adwin_config_timeout                = -1;
120 static int hf_adwin_config_timerresets            = -1;
121 static int hf_adwin_config_disk_free              = -1;
122 static int hf_adwin_config_disk_size              = -1;
123 static int hf_adwin_config_unused                 = -1;
124 static int hf_adwin_config_version                = -1;
125 static int hf_adwin_config_xilinx_version         = -1;
126
127 /* Initialize the subtree pointers */
128 static gint ett_adwin_config          = -1;
129 static gint ett_adwin_config_status   = -1;
130 static gint ett_adwin_config_debug    = -1;
131
132 static void
133 dissect_UDPStatus(tvbuff_t *tvb, proto_tree *adwin_tree)
134 {
135         proto_tree *debug_tree;
136         proto_item *dt;
137
138         static const int * status_flags[] = {
139                 &hf_adwin_config_status_bootloader,
140                 &hf_adwin_config_status_reprogrammable,
141                 &hf_adwin_config_status_configurable,
142                 &hf_adwin_config_status_bootloader_boots,
143                 &hf_adwin_config_status_bootloader_reprogrammable,
144                 &hf_adwin_config_status_bootloader_receive,
145                 &hf_adwin_config_status_bootloader_reprogramming_done,
146                 &hf_adwin_config_status_eeprom_support,
147                 NULL
148         };
149
150         if (! adwin_tree)
151                 return;
152
153         dt = proto_tree_add_item(adwin_tree, proto_adwin_config, tvb, 0, -1, ENC_NA);
154         debug_tree = proto_item_add_subtree(dt, ett_adwin_config_debug);
155         proto_item_set_text(dt, "ADwin Debug information");
156
157         proto_tree_add_item(adwin_tree, hf_adwin_config_pattern, tvb, 0,  4, ENC_BIG_ENDIAN);
158         proto_tree_add_item(adwin_tree, hf_adwin_config_version, tvb, 4,  4, ENC_BIG_ENDIAN);
159
160         proto_tree_add_bitmask(adwin_tree, tvb, 8, hf_adwin_config_status, ett_adwin_config_status, status_flags, ENC_BIG_ENDIAN);
161
162         proto_tree_add_item(adwin_tree, hf_adwin_config_server_version_beta, tvb, 12,  2, ENC_BIG_ENDIAN);
163         proto_tree_add_item(adwin_tree, hf_adwin_config_server_version, tvb, 14,  2, ENC_BIG_ENDIAN);
164         proto_tree_add_item(adwin_tree, hf_adwin_config_xilinx_version, tvb, 16,  4, ENC_BIG_ENDIAN);
165         proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 20,  6, ENC_NA);
166         proto_tree_add_item(debug_tree, hf_adwin_config_unused, tvb, 26, 2, ENC_NA);
167         proto_tree_add_item(adwin_tree, hf_adwin_config_port16, tvb, 28,  2, ENC_BIG_ENDIAN);
168         proto_tree_add_item(adwin_tree, hf_adwin_config_dhcp, tvb, 30, 1, ENC_LITTLE_ENDIAN);
169         proto_tree_add_item(adwin_tree, hf_adwin_config_netmask_count, tvb, 31,  1, ENC_LITTLE_ENDIAN);
170         proto_tree_add_item(adwin_tree, hf_adwin_config_gateway, tvb, 32,  4, ENC_BIG_ENDIAN);
171         proto_tree_add_item(debug_tree, hf_adwin_config_unused, tvb, 36, 11, ENC_NA);
172         proto_tree_add_item(adwin_tree, hf_adwin_config_reply_broadcast, tvb, 47, 1, ENC_LITTLE_ENDIAN);
173         proto_tree_add_item(adwin_tree, hf_adwin_config_scan_id, tvb, 48, 4, ENC_LITTLE_ENDIAN);
174 }
175
176 static void
177 dissect_UDPExtStatus(tvbuff_t *tvb, proto_tree *adwin_tree)
178 {
179         const gchar *processor_type, *system_type;
180
181         if (! adwin_tree)
182                 return;
183
184         proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 0,  6, ENC_NA);
185         proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 6,  2, ENC_NA);
186         proto_tree_add_item(adwin_tree, hf_adwin_config_pattern, tvb, 8,  4, ENC_BIG_ENDIAN);
187         proto_tree_add_item(adwin_tree, hf_adwin_config_version, tvb, 12,  4, ENC_BIG_ENDIAN);
188         proto_tree_add_item(adwin_tree, hf_adwin_config_description, tvb, 16, 16, ENC_ASCII|ENC_NA);
189         proto_tree_add_item(adwin_tree, hf_adwin_config_timerresets, tvb, 32, 4, ENC_BIG_ENDIAN);
190         proto_tree_add_item(adwin_tree, hf_adwin_config_socketshutdowns, tvb, 36, 4, ENC_BIG_ENDIAN);
191         proto_tree_add_item(adwin_tree, hf_adwin_config_disk_free, tvb, 40, 4, ENC_BIG_ENDIAN);
192         proto_tree_add_item(adwin_tree, hf_adwin_config_disk_size, tvb, 44, 4, ENC_BIG_ENDIAN);
193         proto_tree_add_item(adwin_tree, hf_adwin_config_date, tvb, 48,  8, ENC_ASCII|ENC_NA);
194         proto_tree_add_item(adwin_tree, hf_adwin_config_revision, tvb, 56,  8, ENC_ASCII|ENC_NA);
195
196         /* add the processor type raw values to the tree, to allow filtering */
197         proto_tree_add_item(adwin_tree, hf_adwin_config_processor_type_raw, tvb, 64, 2, ENC_ASCII|ENC_NA);
198         /* add the processor type as a pretty printed string */
199         processor_type = tvb_get_string_enc(wmem_packet_scope(), tvb, 64, 2, ENC_ASCII|ENC_NA);
200         processor_type = str_to_str(processor_type, processor_type_mapping, "Unknown (%s)");
201         proto_tree_add_string(adwin_tree, hf_adwin_config_processor_type, tvb, 64, 2, processor_type);
202
203         /* add system type as raw value and pretty printed string */
204         proto_tree_add_item(adwin_tree, hf_adwin_config_system_type_raw, tvb, 66, 2, ENC_ASCII|ENC_NA);
205         system_type = tvb_get_string_enc(wmem_packet_scope(), tvb, 66, 2, ENC_ASCII|ENC_NA);
206         system_type = str_to_str(system_type, system_type_mapping, "Unknown (%s)");
207         proto_tree_add_string(adwin_tree, hf_adwin_config_system_type, tvb, 66, 2, system_type);
208
209         proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 68, 364, ENC_NA);
210 }
211
212 static void
213 dissect_UDPMessage(tvbuff_t *tvb, proto_tree *adwin_tree)
214 {
215         const gchar *processor_type, *system_type;
216
217         if (! adwin_tree)
218                 return;
219
220         proto_tree_add_item(adwin_tree, hf_adwin_config_command, tvb, 0,  4, ENC_LITTLE_ENDIAN);
221         proto_tree_add_item(adwin_tree, hf_adwin_config_version, tvb, 4,  4, ENC_LITTLE_ENDIAN);
222         proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 8,  6, ENC_NA);
223         proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 14,  2, ENC_NA);
224         proto_tree_add_item(adwin_tree, hf_adwin_config_server_ip, tvb, 16,  4, ENC_LITTLE_ENDIAN);
225         proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 20,  4, ENC_NA);
226         proto_tree_add_item(adwin_tree, hf_adwin_config_netmask, tvb, 24,  4, ENC_LITTLE_ENDIAN);
227         proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 28,  4, ENC_NA);
228         proto_tree_add_item(adwin_tree, hf_adwin_config_gateway, tvb, 32,  4, ENC_LITTLE_ENDIAN);
229         proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 36,  4, ENC_NA);
230         proto_tree_add_item(adwin_tree, hf_adwin_config_dhcp, tvb, 40,  4, ENC_LITTLE_ENDIAN);
231         proto_tree_add_item(adwin_tree, hf_adwin_config_port32, tvb, 44,  4, ENC_LITTLE_ENDIAN);
232         proto_tree_add_item(adwin_tree, hf_adwin_config_password, tvb, 48, 10, ENC_ASCII|ENC_NA);
233         proto_tree_add_item(adwin_tree, hf_adwin_config_bootloader, tvb, 58,  1, ENC_LITTLE_ENDIAN);
234         proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 59,  5, ENC_NA);
235         proto_tree_add_item(adwin_tree, hf_adwin_config_description, tvb, 64, 16, ENC_ASCII|ENC_NA);
236         proto_tree_add_item(adwin_tree, hf_adwin_config_date, tvb, 80,  8, ENC_ASCII|ENC_NA);
237         proto_tree_add_item(adwin_tree, hf_adwin_config_revision, tvb, 88,  8, ENC_ASCII|ENC_NA);
238
239         /* add the processor type raw values to the tree, to allow filtering */
240         proto_tree_add_item(adwin_tree, hf_adwin_config_processor_type_raw, tvb, 96,  2, ENC_ASCII|ENC_NA);
241         /* add the processor type as a pretty printed string */
242         processor_type = tvb_get_string_enc(wmem_packet_scope(), tvb, 96, 2, ENC_ASCII|ENC_NA);
243         processor_type = str_to_str(processor_type, processor_type_mapping, "Unknown");
244         proto_tree_add_string(adwin_tree, hf_adwin_config_processor_type, tvb, 96, 2, processor_type);
245
246         /* add system type as raw value and pretty printed string */
247         proto_tree_add_item(adwin_tree, hf_adwin_config_system_type_raw, tvb, 98,  2, ENC_ASCII|ENC_NA);
248         system_type = tvb_get_string_enc(wmem_packet_scope(), tvb, 98, 2, ENC_ASCII|ENC_NA);
249         system_type = str_to_str(system_type, system_type_mapping, "Unknown");
250         proto_tree_add_string(adwin_tree, hf_adwin_config_system_type, tvb, 98, 2, system_type);
251 }
252
253 static void
254 dissect_UDPInitAck(tvbuff_t *tvb, proto_tree *adwin_tree)
255 {
256
257         if (! adwin_tree)
258                 return;
259
260         proto_tree_add_item(adwin_tree, hf_adwin_config_pattern, tvb, 0,  4, ENC_BIG_ENDIAN);
261         proto_tree_add_item(adwin_tree, hf_adwin_config_reboot, tvb, 4, 4, ENC_LITTLE_ENDIAN);
262         proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 8,  6, ENC_NA);
263         proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 14, 2, ENC_NA);
264         proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 16, 80, ENC_NA);
265 }
266
267 static void
268 dissect_UDPIXP425FlashUpdate(tvbuff_t *tvb, proto_tree *adwin_tree)
269 {
270
271         if (! adwin_tree)
272                 return;
273
274         proto_tree_add_item(adwin_tree, hf_adwin_config_pattern, tvb, 0,  4, ENC_BIG_ENDIAN);
275         proto_tree_add_item(adwin_tree, hf_adwin_config_version, tvb, 4,  4, ENC_BIG_ENDIAN);
276         proto_tree_add_item(adwin_tree, hf_adwin_config_scan_id, tvb, 8,  4, ENC_BIG_ENDIAN);
277         proto_tree_add_item(adwin_tree, hf_adwin_config_status, tvb, 12,  4, ENC_BIG_ENDIAN);
278         proto_tree_add_item(adwin_tree, hf_adwin_config_timeout, tvb, 16,  4, ENC_BIG_ENDIAN);
279         proto_tree_add_item(adwin_tree, hf_adwin_config_filename, tvb, 20, 24, ENC_ASCII|ENC_NA);
280         proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 44,  6, ENC_NA);
281         proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, 50, 42, ENC_NA);
282 }
283
284 static void
285 dissect_UDPOut(tvbuff_t *tvb, proto_tree *adwin_tree)
286 {
287
288         if (! adwin_tree)
289                 return;
290
291         proto_tree_add_item(adwin_tree, hf_adwin_config_status, tvb, 0, 4, ENC_LITTLE_ENDIAN);
292         proto_tree_add_item(adwin_tree, hf_adwin_config_mac, tvb, 4,  6, ENC_NA);
293         proto_tree_add_item(adwin_tree, hf_adwin_config_netmask, tvb, 10, 4, ENC_LITTLE_ENDIAN);
294         proto_tree_add_item(adwin_tree, hf_adwin_config_gateway, tvb, 14,  4, ENC_BIG_ENDIAN);
295         proto_tree_add_item(adwin_tree, hf_adwin_config_dhcp, tvb, 18, 2, ENC_LITTLE_ENDIAN);
296         proto_tree_add_item(adwin_tree, hf_adwin_config_port16, tvb, 20,  2, ENC_BIG_ENDIAN);
297 }
298
299 static guint
300 get_adwin_TCPUpdate_len(packet_info *pinfo _U_, tvbuff_t *tvb,
301                         int offset, void *data _U_)
302 {
303         /*
304          * Return the length of the packet. (Doesn't include the length field itself)
305          */
306         return tvb_get_ntohl(tvb, offset);
307 }
308
309 static int
310 dissect_TCPFlashUpdate(tvbuff_t *tvb,  packet_info *pinfo, proto_tree *tree, void* data _U_)
311 {
312         proto_tree *adwin_tree;
313         proto_item *ti;
314         gint length, offset;
315         guint8 *filename;
316
317         col_set_str(pinfo->cinfo, COL_PROTOCOL, "ADwin Config");
318         col_set_str(pinfo->cinfo, COL_INFO, "TCPFlashUpdate");
319
320         ti = proto_tree_add_item(tree, proto_adwin_config, tvb, 0, -1, ENC_NA);
321         adwin_tree = proto_item_add_subtree(ti, ett_adwin_config);
322
323         proto_tree_add_item(adwin_tree, hf_adwin_config_stream_length, tvb, 0, 4, ENC_BIG_ENDIAN);
324         offset = 4;
325         length = tvb_strnlen(tvb, offset, -1) + 1;
326         filename = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, length, ENC_ASCII|ENC_NA);
327         if (strncmp(filename, "eeprom_on", length) == 0) {
328                 proto_tree_add_boolean(adwin_tree, hf_adwin_config_eeprom_support, tvb, offset, length, TRUE);
329                 return offset+length;
330         }
331         if (strncmp(filename, "eeprom_off", length) == 0) {
332                 proto_tree_add_boolean(adwin_tree, hf_adwin_config_eeprom_support, tvb, offset, length, FALSE);
333                 return offset+length;
334         }
335         proto_tree_add_item(adwin_tree, hf_adwin_config_filename, tvb, 4, length, ENC_ASCII|ENC_NA);
336         offset += length;
337         length = tvb_strnlen(tvb, 4 + length, -1) + 1;
338         proto_tree_add_item(adwin_tree, hf_adwin_config_path, tvb, offset, length, ENC_ASCII|ENC_NA);
339         offset += length;
340         proto_tree_add_item(adwin_tree, hf_adwin_config_filesize, tvb, offset, 4, ENC_BIG_ENDIAN);
341         offset += 4;
342         proto_tree_add_item(adwin_tree, hf_adwin_config_filetime, tvb, offset, 4, ENC_TIME_SECS|ENC_BIG_ENDIAN);
343         offset += 4;
344         proto_tree_add_item(adwin_tree, hf_adwin_config_updatetime, tvb, offset, 4, ENC_TIME_SECS|ENC_BIG_ENDIAN);
345         offset += 4;
346         proto_tree_add_item(adwin_tree, hf_adwin_config_unused, tvb, offset, 128, ENC_NA);
347         offset += 128;
348         length = tvb_captured_length_remaining(tvb, offset);
349         proto_tree_add_item(adwin_tree, hf_adwin_config_data, tvb, offset, length, ENC_NA);
350
351         return tvb_captured_length(tvb);
352 }
353
354 /* 00:50:c2:0a:2*:** */
355 static const unsigned char mac_iab_start[] = { 0x00, 0x50, 0xc2, 0x0a, 0x20, 0x00 };
356 static const unsigned char mac_iab_end[]   = { 0x00, 0x50, 0xc2, 0x0a, 0x2f, 0xff };
357
358 /* 00:22:71:**:**:** */
359 static const unsigned char mac_oui_start[] = { 0x00, 0x22, 0x71, 0x00, 0x00, 0x00 };
360 static const unsigned char mac_oui_end[]   = { 0x00, 0x22, 0x71, 0xff, 0xff, 0xff };
361
362 /* ff:ff:ff:ff:ff:ff */
363 static const unsigned char mac_broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
364
365 /* return TRUE if mac is in mac address range assigned to ADwin or if
366  * mac is broadcast */
367 static gboolean
368 is_adwin_mac_or_broadcast(address mac)
369 {
370         if (mac.type != AT_ETHER)
371                 return FALSE;
372
373         if (mac.len != 6) /* length of MAC address */
374                 return FALSE;
375
376         if ((memcmp(mac.data, mac_iab_start, mac.len) >= 0) &&
377             (memcmp(mac.data, mac_iab_end  , mac.len) <= 0))
378                 return TRUE;
379
380         if ((memcmp(mac.data, mac_oui_start, mac.len) >= 0) &&
381             (memcmp(mac.data, mac_oui_end, mac.len) <= 0))
382                 return TRUE;
383
384         /* adwin configuration protocol uses MAC broadcasts for
385            device discovery */
386         if (memcmp(mac.data, mac_broadcast, mac.len) == 0)
387                 return TRUE;
388
389         return FALSE;
390 }
391
392
393 /* Here we determine which type of packet is sent by looking at its
394    size. Let's hope that future ADwin packets always differ in size.
395    They probably will, since the server classifies the packets
396    according to their sizes, too. */
397
398 static const value_string length_mapping[] = {
399         { UDPStatusLENGTH,              "UDPStatus" },
400         { UDPExtStatusLENGTH,           "UDPExtStatus" },
401         { UDPMessageLENGTH,             "UDPMessage" },
402         { UDPMessageLENGTH_wrong,       "UDPMessage (broken - upgrade ADConfig!)" },
403         { UDPInitAckLENGTH,             "UDPInitAck" },
404         { UDPIXP425FlashUpdateLENGTH,   "UDPIXP425FlashUpdate" },
405         { UDPOutLENGTH,                 "UDPOut" },
406         { 0, NULL },
407 };
408
409 static int
410 dissect_adwin_config_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
411 {
412         proto_item *ti;
413         proto_tree *adwin_config_tree;
414         guint32 length;
415
416         length = tvb_reported_length(tvb);
417
418         if (!(length == UDPStatusLENGTH
419                || length == UDPExtStatusLENGTH
420                || length == UDPMessageLENGTH
421                || length == UDPMessageLENGTH_wrong
422                || length == UDPInitAckLENGTH
423                || length == UDPIXP425FlashUpdateLENGTH
424                || length == UDPOutLENGTH))
425                 return 0;
426
427         if (! (is_adwin_mac_or_broadcast(pinfo->dl_src) || is_adwin_mac_or_broadcast(pinfo->dl_dst)))
428                 return 0;
429
430         col_set_str(pinfo->cinfo, COL_PROTOCOL, "ADwin Config");
431         col_clear(pinfo->cinfo, COL_INFO);
432
433         ti = proto_tree_add_item(tree, proto_adwin_config, tvb, 0, -1, ENC_NA);
434         adwin_config_tree = proto_item_add_subtree(ti, ett_adwin_config);
435
436         switch (length) {
437         case UDPStatusLENGTH:
438                 dissect_UDPStatus(tvb, adwin_config_tree);
439                 break;
440         case UDPExtStatusLENGTH:
441                 dissect_UDPExtStatus(tvb, adwin_config_tree);
442                 break;
443         case UDPMessageLENGTH:
444                 dissect_UDPMessage(tvb, adwin_config_tree);
445                 break;
446         case UDPMessageLENGTH_wrong: /* incorrect packet length */
447                 /* formerly used by adconfig */
448                 dissect_UDPMessage(tvb, adwin_config_tree);
449                 break;
450         case UDPInitAckLENGTH:
451                 dissect_UDPInitAck(tvb, adwin_config_tree);
452                 break;
453         case UDPIXP425FlashUpdateLENGTH:
454                 dissect_UDPIXP425FlashUpdate(tvb, adwin_config_tree);
455                 break;
456         case UDPOutLENGTH:
457                 dissect_UDPOut(tvb, adwin_config_tree);
458                 break;
459         default:
460                 /* Heuristics above should mean we never get here */
461                 col_add_str(pinfo->cinfo, COL_INFO,
462                         val_to_str(length, length_mapping,
463                         "Unknown ADwin Configuration packet, length: %d"));
464         }
465
466         return (tvb_reported_length(tvb));
467 }
468
469 static int
470 dissect_adwin_config_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
471 {
472         if(!(pinfo->srcport == ADWIN_CONFIGURATION_PORT
473                 || pinfo->destport == ADWIN_CONFIGURATION_PORT))
474                 return 0;
475
476         /* XXX - Is this possible for TCP? */
477         if (! (is_adwin_mac_or_broadcast(pinfo->dl_src) || is_adwin_mac_or_broadcast(pinfo->dl_dst)))
478                 return 0;
479
480         tcp_dissect_pdus(tvb, pinfo, tree, 1, 4, get_adwin_TCPUpdate_len, dissect_TCPFlashUpdate, NULL);
481
482         return (tvb_reported_length(tvb));
483 }
484
485 void
486 proto_register_adwin_config(void)
487 {
488         static hf_register_info hf[] = {
489                 { &hf_adwin_config_bootloader,
490                   { "Enable Bootloader", "adwin_config.bootloader",
491                     FT_BOOLEAN, BASE_NONE, NULL, 0x0,
492                     NULL, HFILL }
493                 },
494                 { &hf_adwin_config_command,
495                   { "Command", "adwin_config.command",
496                     FT_UINT32, BASE_DEC, VALS(config_command_mapping), 0x0,
497                     NULL, HFILL }
498                 },
499                 { &hf_adwin_config_data,
500                   { "Data", "adwin_config.data",
501                     FT_NONE, BASE_NONE, NULL, 0x0,
502                     NULL, HFILL }
503                 },
504                 { &hf_adwin_config_date,
505                   { "Date", "adwin_config.date",
506                     FT_STRING, BASE_NONE, NULL, 0x0,
507                     NULL, HFILL }
508                 },
509                 { &hf_adwin_config_description,
510                   { "Description", "adwin_config.description",
511                     FT_STRING, BASE_NONE, NULL, 0x0,
512                     NULL, HFILL }
513                 },
514                 { &hf_adwin_config_dhcp,
515                   { "DHCP enabled", "adwin_config.dhcp",
516                     FT_BOOLEAN, BASE_NONE, NULL, 0x0,
517                     NULL, HFILL }
518                 },
519                 { &hf_adwin_config_filename,
520                   { "File name", "adwin_config.filename",
521                     FT_STRING, BASE_NONE, NULL, 0x0,
522                     NULL, HFILL }
523                 },
524                 { &hf_adwin_config_filesize,
525                   { "File size", "adwin_config.filesize",
526                     FT_INT32, BASE_DEC, NULL, 0x0,
527                     NULL, HFILL }
528                 },
529                 { &hf_adwin_config_filetime,
530                   { "File time", "adwin_config.filetime",
531                     FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0,
532                     NULL, HFILL }
533                 },
534                 { &hf_adwin_config_updatetime,
535                   { "Update time", "adwin_config.updatetime",
536                     FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0,
537                     NULL, HFILL }
538                 },
539                 { &hf_adwin_config_gateway,
540                   { "Gateway IP", "adwin_config.gateway",
541                     FT_IPv4, BASE_NONE, NULL, 0x0,
542                     NULL, HFILL }
543                 },
544                 { &hf_adwin_config_mac,
545                   { "MAC address", "adwin_config.mac",
546                     FT_ETHER, BASE_NONE, NULL, 0x0,
547                     NULL, HFILL }
548                 },
549                 { &hf_adwin_config_netmask,
550                   { "Netmask", "adwin_config.netmask",
551                     FT_IPv4, BASE_NETMASK, NULL, 0x0,
552                     NULL, HFILL }
553                 },
554                 { &hf_adwin_config_netmask_count,
555                   { "Netmask count", "adwin_config.netmask_count",
556                     FT_UINT8, BASE_DEC, NULL, 0x0,
557                     "The number of binary ones in the netmask.", HFILL }
558                 },
559                 { &hf_adwin_config_password,
560                   { "Password", "adwin_config.password",
561                     FT_STRING, BASE_NONE, NULL, 0x0,
562                     "Password to set for ADwin system.", HFILL }
563                 },
564                 { &hf_adwin_config_pattern,
565                   { "Pattern", "adwin_config.pattern",
566                     FT_UINT32, BASE_HEX, VALS(pattern_mapping), 0x0,
567                     NULL, HFILL }
568                 },
569                 { &hf_adwin_config_path,
570                   { "Path", "adwin_config.path",
571                     FT_STRING, BASE_NONE, NULL, 0x0,
572                     NULL, HFILL }
573                 },
574                 { &hf_adwin_config_port16,
575                   { "Port (16bit)", "adwin_config.port",
576                     FT_UINT16, BASE_DEC, NULL, 0x0,
577                     "The server port on which the ADwin system is listening on (16bit).", HFILL }
578                 },
579                 { &hf_adwin_config_port32,
580                   { "Port (32bit)", "adwin_config.port",
581                     FT_UINT32, BASE_DEC, NULL, 0x0,
582                     "The server port on which the ADwin system is listening on (32bit).", HFILL }
583                 },
584                 { &hf_adwin_config_reboot,
585                   { "Reboot", "adwin_config.reboot",
586                     FT_BOOLEAN, BASE_NONE, NULL, 0x0,
587                     "Number of system reboots.", HFILL }
588                 },
589                 { &hf_adwin_config_scan_id,
590                   { "Scan ID", "adwin_config.scan_id",
591                     FT_UINT32, BASE_HEX, NULL, 0x0,
592                     NULL, HFILL }
593                 },
594                 { &hf_adwin_config_reply_broadcast, /* send_normal in UDPStatus */
595                   { "Reply with broadcast", "adwin_config.reply_broadcast",
596                     FT_BOOLEAN, BASE_NONE, NULL, 0x0,
597                     "If this bit is set, the scanned system should reply with a broadcast.", HFILL }
598                 },
599                 { &hf_adwin_config_revision,
600                   { "Revision", "adwin_config.revision",
601                     FT_STRING, BASE_NONE, NULL, 0x0,
602                     NULL, HFILL }
603                 },
604                 { &hf_adwin_config_processor_type_raw,
605                   { "Processor Type (Raw value)", "adwin_config.processor_type_raw",
606                     FT_STRING, BASE_NONE, NULL, 0x0,
607                     "The DSP processor type of the ADwin system, e.g. T9, T10 or T11.", HFILL }
608                 },
609                 { &hf_adwin_config_system_type_raw,
610                   { "System Type (Raw value)", "adwin_config.system_type_raw",
611                     FT_STRING, BASE_NONE, NULL, 0x0,
612                     "The system type of the ADwin system, e.g. Gold, Pro or Light.", HFILL }
613                 },
614                 { &hf_adwin_config_processor_type,
615                   { "Processor Type", "adwin_config.processor_type",
616                     FT_STRING, BASE_NONE, NULL, 0x0,
617                     NULL, HFILL }
618                 },
619                 { &hf_adwin_config_system_type,
620                   { "System Type", "adwin_config.system_type",
621                     FT_STRING, BASE_NONE, NULL, 0x0,
622                     NULL, HFILL }
623                 },
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 }
628                 },
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 }
633                 },
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 }
638                 },
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 }
643                 },
644                 { &hf_adwin_config_status,
645                   { "Status", "adwin_config.status",
646                     FT_UINT32, BASE_HEX, NULL, 0x0,
647                     NULL, HFILL }
648                 },
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 }
653                 },
654                 { &hf_adwin_config_status_reprogrammable,
655                   { "Status Reprogrammable",
656                     "adwin_config.status_reprogrammable",
657                     FT_BOOLEAN, 32, NULL, STATUS_REPROGRAMMABLE,
658                     NULL, HFILL }
659                 },
660                 { &hf_adwin_config_status_configurable,
661                   { "Status Configurable", "adwin_config.status_configurable",
662                     FT_BOOLEAN, 32, NULL, STATUS_CONFIGURABLE,
663                     NULL, HFILL }
664                 },
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 }
670                 },
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 }
676                 },
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 }
682                 },
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 }
688                 },
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 }
694                 },
695                 { &hf_adwin_config_stream_length,
696                   { "Stream length", "adwin_config.stream_length",
697                     FT_INT32, BASE_DEC, NULL, 0x0,
698                     NULL, HFILL }
699                 },
700                 { &hf_adwin_config_eeprom_support,
701                   { "EEPROM Support", "adwin_config.eeprom_support",
702                     FT_BOOLEAN, BASE_NONE, TFS(&tfs_enabled_disabled), 0x0,
703                     NULL, HFILL }
704                 },
705                 { &hf_adwin_config_timeout,
706                   { "Timeout", "adwin_config.timeout",
707                     FT_UINT32, BASE_DEC, NULL, 0x0,
708                     NULL, HFILL }
709                 },
710                 { &hf_adwin_config_timerresets,
711                   { "Timer resets", "adwin_config.timerresets",
712                     FT_UINT32, BASE_DEC, NULL, 0x0,
713                     "Counter for resets of the timer (ethernet interface version 1 only).", HFILL }
714                 },
715                 { &hf_adwin_config_disk_free,
716                   { "Free disk space (kb)", "adwin_config.disk_free",
717                     FT_UINT32, BASE_DEC, NULL, 0x0,
718                     "Free disk space in kb on flash (ethernet interface version 2 only).", HFILL }
719                 },
720                 { &hf_adwin_config_disk_size,
721                   { "Disk size (kb)", "adwin_config.disk_size",
722                     FT_UINT32, BASE_DEC, NULL, 0x0,
723                     "Flash disk size in kb (ethernet interface version 2 only).", HFILL }
724                 },
725                 { &hf_adwin_config_unused,
726                   { "Unused", "adwin_config.unused",
727                     FT_NONE, BASE_NONE, NULL, 0x0,
728                     NULL, HFILL }
729                 },
730                 { &hf_adwin_config_version,
731                   { "Version", "adwin_config.version",
732                     FT_UINT32, BASE_DEC, NULL, 0x0,
733                     NULL, HFILL }
734                 },
735                 { &hf_adwin_config_xilinx_version,
736                   { "XILINX Version", "adwin_config.xilinx_version",
737                     FT_UINT32, BASE_HEX, NULL, 0x0,
738                     "Version of XILINX program", HFILL }
739                 },
740         };
741
742         /* Setup protocol subtree array */
743         static gint *ett[] = {
744                 &ett_adwin_config,
745                 &ett_adwin_config_status,
746                 &ett_adwin_config_debug,
747         };
748
749         /* Register the protocol name and description */
750         proto_adwin_config =
751                 proto_register_protocol("ADwin configuration protocol",
752                                         "ADwin-Config", "adwin_config");
753
754         /* Required function calls to register the header fields and
755            subtrees used */
756         proto_register_field_array(proto_adwin_config, hf, array_length(hf));
757         proto_register_subtree_array(ett, array_length(ett));
758 }
759
760 void
761 proto_reg_handoff_adwin_config(void)
762 {
763         heur_dissector_add("udp", dissect_adwin_config_udp, "ADwin-Config over UDP", "adwin_config_udp", proto_adwin_config, HEURISTIC_ENABLE);
764         heur_dissector_add("tcp", dissect_adwin_config_tcp, "ADwin-Config over TCP", "adwin_config_tcp", proto_adwin_config, HEURISTIC_ENABLE);
765 }
766
767
768 /*
769  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
770  *
771  * Local variables:
772  * c-basic-offset: 8
773  * tab-width: 8
774  * indent-tabs-mode: t
775  * End:
776  *
777  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
778  * :indentSize=8:tabSize=8:noTabs=false:
779  */