Coverage Report

Created: 2026-06-30 07:22

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