Remove all $Id$ from top of file
[metze/wireshark/wip.git] / epan / dissectors / packet-adwin.c
1 /* packet-adwin.c
2  * Routines for ADwin 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  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include "config.h"
25
26 /* includes needed for wireshark */
27 #include <glib.h>
28 #include <epan/packet.h>
29 #include <epan/prefs.h>
30 #include <epan/conversation.h>
31 #include <epan/wmem/wmem.h>
32
33 void proto_reg_handoff_adwin(void);
34 void proto_register_adwin(void);
35
36 /* This is registered to a different protocol */
37 #define ADWIN_COMM_PORT 6543
38
39 /* lengths of valid packet structures */
40 #define UDPH1_OLD_LENGTH              52
41 #define UDPH1_NEW_LENGTH              56
42 #define UDPR1_LENGTH                  32
43 #define UDPH2_LENGTH                 412 /* AFAIK: unused */
44 #define UDPR2_LENGTH                1008
45 #define UDPR3_LENGTH                1408
46 #define UDPR4_LENGTH                1416
47 #define GetDataSHPacket_LENGTH      1356
48 #define GetDataSHRequest_LENGTH       64
49
50 /* operating systems */
51 #define OS_WINDOWS                  0x00
52 #define OS_LINUX                    0x10
53 #define OS_JAVA                     0x20
54 #define OS_DOT_NET                  0x40
55 #define OS_GENERIC                  0x80
56 static const value_string osys_mapping[] = {
57         { OS_WINDOWS, "Windows"},
58         { OS_LINUX,   "Linux"},
59         { OS_JAVA,    "Java"},
60         { OS_DOT_NET, ".Net"},
61         { OS_GENERIC, "Generic TCP/IP Driver"},
62         { 0,          NULL },
63 };
64 static value_string_ext osys_mapping_ext = VALUE_STRING_EXT_INIT(osys_mapping);
65
66 /* error codes */
67 #define EC_OK                          0
68 #define EC_TIMEOUT_TO_LINK             1
69 #define EC_TIMEOUT_FROM_LINK           2
70 #define EC_TIMEOUT_FAST_TO_LINK        3
71 #define EC_TIMEOUT_FAST_FROM_LINK      4
72 #define EC_TIMEOUT                     5
73 #define EC_MEMORY_ERROR             -100
74 #define EC_RETRY_UNKNOWN             -41
75 #define EC_ALREADY_PROCESSED         -40
76 #define EC_WRONG_BINARY_FILE         -35
77 #define EC_INVALID_PACKET_ORDER      -33
78 #define EC_FIFO_NOT_ENOUGH_DATA      -32
79 #define EC_DATA_TOO_SMALL            -31
80 #define EC_WRONG_VERSION             -30
81 #define EC_WRONG_SIZE                -26
82 #define EC_PACKET_TOO_LARGE          -25
83 #define EC_PACKET_ERROR              -20
84 #define EC_FILE_ERROR                -15
85 #define EC_TRY_LATER                 -10
86 #define EC_WRONG_PASSWORD             -5
87 #define EC_UDP_TIMEOUT                -1
88 static const value_string error_code_mapping[] = {
89         { EC_OK,                     "OK"},
90         { EC_TIMEOUT_TO_LINK,        "Timeout to link"},
91         { EC_TIMEOUT_FROM_LINK,      "Timeout from link"},
92         { EC_TIMEOUT_FAST_TO_LINK,   "Timeout fast to link"},
93         { EC_TIMEOUT_FAST_FROM_LINK, "Timeout fast from link"},
94         { EC_TIMEOUT,                "Timeout"},
95         { EC_MEMORY_ERROR,           "Memory error"},
96         { EC_RETRY_UNKNOWN,          "Retry unknown"},
97         { EC_ALREADY_PROCESSED,      "Already processed"},
98         { EC_WRONG_BINARY_FILE,      "Binary/Processor mismatch"},
99         { EC_INVALID_PACKET_ORDER,   "Invalid Packet order"},
100         { EC_FIFO_NOT_ENOUGH_DATA,   "Fifo has not enough data"},
101         { EC_DATA_TOO_SMALL,         "Data too small"},
102         { EC_WRONG_VERSION,          "Wrong version"},
103         { EC_WRONG_SIZE,             "Wrong size"},
104         { EC_PACKET_ERROR,           "Packet error"},
105         { EC_FILE_ERROR,             "File error"},
106         { EC_TRY_LATER,              "Try later"},
107         { EC_WRONG_PASSWORD,         "Wrong password"},
108         { EC_UDP_TIMEOUT,            "UDP timeout"},
109         { 0, NULL },
110 };
111 static value_string_ext error_code_mapping_ext = VALUE_STRING_EXT_INIT(error_code_mapping);
112
113 static const value_string data_type_mapping[] = {
114         { 2, "short / int"},
115         { 3, "int"},
116         { 4, "long"},
117         { 5, "float"},
118         { 6, "double"},
119         { 20, "variant"},
120         { 0, NULL },
121 };
122 static value_string_ext data_type_mapping_ext = VALUE_STRING_EXT_INIT(data_type_mapping);
123
124 #define I_3PLUS1                           0
125 #define I_LOAD_BIN_FILE                    4
126 #define I_GET_DATA                         7
127 #define I_SET_DATA                         8
128 #define I_CREATE_DATA                     10
129 #define I_GET_PAR_ALL                     13
130 #define I_GET_WORKLOAD                    20
131 #define I_GET_FIFO                        24
132 #define I_SET_FIFO                        25
133 #define I_BOOT                            50
134 #define I_GET_DATA_TYPE                  100
135 #define I_GET_DATA_SHIFTED_HANDSHAKE     107
136 #define I_SET_DATA_LAST_STATUS           108
137 #define I_GET_FIFO_RETRY                 124
138 #define I_SET_FIFO_RETRY                 125
139 #define I_GET_DATA_SMALL                 207
140 #define I_TEST_VERSION                   255
141 #define I_GET_ARM_VERSION               1000
142 #define I_GET_MEMORY                 1000000
143
144 static const value_string instruction_mapping[] = {
145         { I_3PLUS1,                     "3+1 instruction" },
146         { I_LOAD_BIN_FILE,              "Load binary file" },
147         { I_GET_DATA,                   "Get data" },
148         { I_SET_DATA,                   "Set data" },
149         { I_CREATE_DATA,                "Create data" },
150         { I_GET_PAR_ALL,                "Get all parameters" },
151         { I_GET_WORKLOAD,               "Get workload"},
152         { I_GET_FIFO,                   "Get fifo" },
153         { I_SET_FIFO,                   "Set fifo" },
154         { I_BOOT,                       "Boot" },
155         { I_GET_DATA_TYPE,              "Get data type" },
156         { I_GET_DATA_SHIFTED_HANDSHAKE, "Get data (shifted handshake)" },
157         { I_SET_DATA_LAST_STATUS,       "Get status of last set data" },
158         { I_GET_FIFO_RETRY,             "Get fifo - retry" },
159         { I_SET_FIFO_RETRY,             "Set fifo - retry" },
160         { I_GET_DATA_SMALL,             "Get data (small/fast)" },
161         { I_TEST_VERSION,               "Get/test version information" },
162         { I_GET_ARM_VERSION,            "Get ARM-Version" },
163         { I_GET_MEMORY,                 "Get memory DSP" },
164         { 0, NULL },
165 };
166 static value_string_ext instruction_mapping_ext = VALUE_STRING_EXT_INIT(instruction_mapping);
167
168 /* 3+1 instructions */
169 #define I_3P1_GET_PAR                     1
170 #define I_3P1_START                       2
171 #define I_3P1_STOP                        3
172 #define I_3P1_GET_MEMORY_INFO             5
173 #define I_3P1_SET_PAR                     6
174 #define I_3P1_CLEAR_DATA                  9
175 #define I_3P1_GET_DATA_LENGTH            11
176 #define I_3P1_GET_DETAILED_MEM_INFO      12
177 #define I_3P1_CLEAR_PROCESS              14
178 #define I_3P1_ADC                        15
179 #define I_3P1_DAC                        16
180 #define I_3P1_GET_DIGIN                  17
181 #define I_3P1_SET_DIGOUT                 18
182 #define I_3P1_GET_DIGOUT                 19
183 #define I_3P1_CLEAR_FIFO                 21
184 #define I_3P1_GET_FIFO_EMPTY             22
185 #define I_3P1_GET_FIFO_COUNT             23
186 static const value_string instruction_3plus1_mapping[] = {
187         { I_3P1_GET_PAR,               "Get parameter"},
188         { I_3P1_START,                 "Start process"},
189         { I_3P1_STOP,                  "Stop process"},
190         { I_3P1_GET_MEMORY_INFO,       "Get memory info"},
191         { I_3P1_SET_PAR,               "Set parameter"},
192         { I_3P1_CLEAR_DATA,            "Clear data"},
193         { I_3P1_GET_DATA_LENGTH,       "Get data length"},
194         { I_3P1_GET_DETAILED_MEM_INFO, "Get detailed memory info"},
195         { I_3P1_CLEAR_PROCESS,         "Clear process"},
196         { I_3P1_ADC,                   "Get ADC value"},
197         { I_3P1_DAC,                   "Set DAC value"},
198         { I_3P1_GET_DIGIN,             "Get digital in"},
199         { I_3P1_SET_DIGOUT,            "Set digital out"},
200         { I_3P1_GET_DIGOUT,            "Get digital out"},
201         { I_3P1_CLEAR_FIFO,            "Clear fifo"},
202         { I_3P1_GET_FIFO_EMPTY,        "Get fifo empty"},
203         { I_3P1_GET_FIFO_COUNT,        "Get fifo full/count"},
204         { 0,               NULL },
205 };
206 static value_string_ext instruction_3plus1_mapping_ext = VALUE_STRING_EXT_INIT(instruction_3plus1_mapping);
207
208 static const value_string parameter_mapping[] = {
209         { 901 , "Status of Process No. 01"},
210         { 902 , "Status of Process No. 02"},
211         { 903 , "Status of Process No. 03"},
212         { 904 , "Status of Process No. 04"},
213         { 905 , "Status of Process No. 05"},
214         { 906 , "Status of Process No. 06"},
215         { 907 , "Status of Process No. 07"},
216         { 908 , "Status of Process No. 08"},
217         { 909 , "Status of Process No. 09"},
218         { 910 , "Status of Process No. 10"},
219         { 911 , "GlobalDelay for Process No. 01"},
220         { 912 , "GlobalDelay for Process No. 02"},
221         { 913 , "GlobalDelay for Process No. 03"},
222         { 914 , "GlobalDelay for Process No. 04"},
223         { 915 , "GlobalDelay for Process No. 05"},
224         { 916 , "GlobalDelay for Process No. 06"},
225         { 917 , "GlobalDelay for Process No. 07"},
226         { 918 , "GlobalDelay for Process No. 08"},
227         { 919 , "GlobalDelay for Process No. 09"},
228         { 920 , "GlobalDelay for Process No. 10"},
229         { 921 , "GlobalDelay for Process No. 11"},
230         { 922 , "GlobalDelay for Process No. 12"},
231         { 923 , "GlobalDelay for Process No. 13"},
232         { 924 , "GlobalDelay for Process No. 14"},
233         { 925 , "GlobalDelay for Process No. 15"},
234         { 926 , "GlobalDelay for Process No. 16"},
235         { 951 , "Debug Information of Process No. 01"},
236         { 952 , "Debug Information of Process No. 02"},
237         { 953 , "Debug Information of Process No. 03"},
238         { 954 , "Debug Information of Process No. 04"},
239         { 955 , "Debug Information of Process No. 05"},
240         { 956 , "Debug Information of Process No. 06"},
241         { 957 , "Debug Information of Process No. 07"},
242         { 958 , "Debug Information of Process No. 08"},
243         { 959 , "Debug Information of Process No. 09"},
244         { 960 , "Debug Information of Process No. 10"},
245         { 961 , "Debug Information of Process No. 11"},
246         { 962 , "Debug Information of Process No. 12"},
247         { 963 , "Debug Information of Process No. 13"},
248         { 964 , "Debug Information of Process No. 14"},
249         { 965 , "Debug Information of Process No. 15"},
250         { 966 , "Debug Information of Process No. 16"},
251         { 1001 , "Parameter No. 01"},
252         { 1002 , "Parameter No. 02"},
253         { 1003 , "Parameter No. 03"},
254         { 1004 , "Parameter No. 04"},
255         { 1005 , "Parameter No. 05"},
256         { 1006 , "Parameter No. 06"},
257         { 1007 , "Parameter No. 07"},
258         { 1008 , "Parameter No. 08"},
259         { 1009 , "Parameter No. 09"},
260         { 1010 , "Parameter No. 10"},
261         { 1011 , "Parameter No. 11"},
262         { 1012 , "Parameter No. 12"},
263         { 1013 , "Parameter No. 13"},
264         { 1014 , "Parameter No. 14"},
265         { 1015 , "Parameter No. 15"},
266         { 1016 , "Parameter No. 16"},
267         { 1017 , "Parameter No. 17"},
268         { 1018 , "Parameter No. 18"},
269         { 1019 , "Parameter No. 19"},
270         { 1020 , "Parameter No. 20"},
271         { 1021 , "Parameter No. 21"},
272         { 1022 , "Parameter No. 22"},
273         { 1023 , "Parameter No. 23"},
274         { 1024 , "Parameter No. 24"},
275         { 1025 , "Parameter No. 25"},
276         { 1026 , "Parameter No. 26"},
277         { 1027 , "Parameter No. 27"},
278         { 1028 , "Parameter No. 28"},
279         { 1029 , "Parameter No. 29"},
280         { 1030 , "Parameter No. 30"},
281         { 1031 , "Parameter No. 31"},
282         { 1032 , "Parameter No. 32"},
283         { 1033 , "Parameter No. 33"},
284         { 1034 , "Parameter No. 34"},
285         { 1035 , "Parameter No. 35"},
286         { 1036 , "Parameter No. 36"},
287         { 1037 , "Parameter No. 37"},
288         { 1038 , "Parameter No. 38"},
289         { 1039 , "Parameter No. 39"},
290         { 1040 , "Parameter No. 40"},
291         { 1041 , "Parameter No. 41"},
292         { 1042 , "Parameter No. 42"},
293         { 1043 , "Parameter No. 43"},
294         { 1044 , "Parameter No. 44"},
295         { 1045 , "Parameter No. 45"},
296         { 1046 , "Parameter No. 46"},
297         { 1047 , "Parameter No. 47"},
298         { 1048 , "Parameter No. 48"},
299         { 1049 , "Parameter No. 49"},
300         { 1050 , "Parameter No. 50"},
301         { 1051 , "Parameter No. 51"},
302         { 1052 , "Parameter No. 52"},
303         { 1053 , "Parameter No. 53"},
304         { 1054 , "Parameter No. 54"},
305         { 1055 , "Parameter No. 55"},
306         { 1056 , "Parameter No. 56"},
307         { 1057 , "Parameter No. 57"},
308         { 1058 , "Parameter No. 58"},
309         { 1059 , "Parameter No. 59"},
310         { 1060 , "Parameter No. 60"},
311         { 1061 , "Parameter No. 61"},
312         { 1062 , "Parameter No. 62"},
313         { 1063 , "Parameter No. 63"},
314         { 1064 , "Parameter No. 64"},
315         { 1065 , "Parameter No. 65"},
316         { 1066 , "Parameter No. 66"},
317         { 1067 , "Parameter No. 67"},
318         { 1068 , "Parameter No. 68"},
319         { 1069 , "Parameter No. 69"},
320         { 1070 , "Parameter No. 70"},
321         { 1071 , "Parameter No. 71"},
322         { 1072 , "Parameter No. 72"},
323         { 1073 , "Parameter No. 73"},
324         { 1074 , "Parameter No. 74"},
325         { 1075 , "Parameter No. 75"},
326         { 1076 , "Parameter No. 76"},
327         { 1077 , "Parameter No. 77"},
328         { 1078 , "Parameter No. 78"},
329         { 1079 , "Parameter No. 79"},
330         { 1080 , "Parameter No. 80"},
331         { 1101 , "Float-Parameter No. 01"},
332         { 1102 , "Float-Parameter No. 02"},
333         { 1103 , "Float-Parameter No. 03"},
334         { 1104 , "Float-Parameter No. 04"},
335         { 1105 , "Float-Parameter No. 05"},
336         { 1106 , "Float-Parameter No. 06"},
337         { 1107 , "Float-Parameter No. 07"},
338         { 1108 , "Float-Parameter No. 08"},
339         { 1109 , "Float-Parameter No. 09"},
340         { 1110 , "Float-Parameter No. 10"},
341         { 1111 , "Float-Parameter No. 11"},
342         { 1112 , "Float-Parameter No. 12"},
343         { 1113 , "Float-Parameter No. 13"},
344         { 1114 , "Float-Parameter No. 14"},
345         { 1115 , "Float-Parameter No. 15"},
346         { 1116 , "Float-Parameter No. 16"},
347         { 1117 , "Float-Parameter No. 17"},
348         { 1118 , "Float-Parameter No. 18"},
349         { 1119 , "Float-Parameter No. 19"},
350         { 1120 , "Float-Parameter No. 20"},
351         { 1121 , "Float-Parameter No. 21"},
352         { 1122 , "Float-Parameter No. 22"},
353         { 1123 , "Float-Parameter No. 23"},
354         { 1124 , "Float-Parameter No. 24"},
355         { 1125 , "Float-Parameter No. 25"},
356         { 1126 , "Float-Parameter No. 26"},
357         { 1127 , "Float-Parameter No. 27"},
358         { 1128 , "Float-Parameter No. 28"},
359         { 1129 , "Float-Parameter No. 29"},
360         { 1130 , "Float-Parameter No. 30"},
361         { 1131 , "Float-Parameter No. 31"},
362         { 1132 , "Float-Parameter No. 32"},
363         { 1133 , "Float-Parameter No. 33"},
364         { 1134 , "Float-Parameter No. 34"},
365         { 1135 , "Float-Parameter No. 35"},
366         { 1136 , "Float-Parameter No. 36"},
367         { 1137 , "Float-Parameter No. 37"},
368         { 1138 , "Float-Parameter No. 38"},
369         { 1139 , "Float-Parameter No. 39"},
370         { 1140 , "Float-Parameter No. 40"},
371         { 1141 , "Float-Parameter No. 41"},
372         { 1142 , "Float-Parameter No. 42"},
373         { 1143 , "Float-Parameter No. 43"},
374         { 1144 , "Float-Parameter No. 44"},
375         { 1145 , "Float-Parameter No. 45"},
376         { 1146 , "Float-Parameter No. 46"},
377         { 1147 , "Float-Parameter No. 47"},
378         { 1148 , "Float-Parameter No. 48"},
379         { 1149 , "Float-Parameter No. 49"},
380         { 1150 , "Float-Parameter No. 50"},
381         { 1151 , "Float-Parameter No. 51"},
382         { 1152 , "Float-Parameter No. 52"},
383         { 1153 , "Float-Parameter No. 53"},
384         { 1154 , "Float-Parameter No. 54"},
385         { 1155 , "Float-Parameter No. 55"},
386         { 1156 , "Float-Parameter No. 56"},
387         { 1157 , "Float-Parameter No. 57"},
388         { 1158 , "Float-Parameter No. 58"},
389         { 1159 , "Float-Parameter No. 59"},
390         { 1160 , "Float-Parameter No. 60"},
391         { 1161 , "Float-Parameter No. 61"},
392         { 1162 , "Float-Parameter No. 62"},
393         { 1163 , "Float-Parameter No. 63"},
394         { 1164 , "Float-Parameter No. 64"},
395         { 1165 , "Float-Parameter No. 65"},
396         { 1166 , "Float-Parameter No. 66"},
397         { 1167 , "Float-Parameter No. 67"},
398         { 1168 , "Float-Parameter No. 68"},
399         { 1169 , "Float-Parameter No. 69"},
400         { 1170 , "Float-Parameter No. 70"},
401         { 1171 , "Float-Parameter No. 71"},
402         { 1172 , "Float-Parameter No. 72"},
403         { 1173 , "Float-Parameter No. 73"},
404         { 1174 , "Float-Parameter No. 74"},
405         { 1175 , "Float-Parameter No. 75"},
406         { 1176 , "Float-Parameter No. 76"},
407         { 1177 , "Float-Parameter No. 77"},
408         { 1178 , "Float-Parameter No. 78"},
409         { 1179 , "Float-Parameter No. 79"},
410         { 1180 , "Float-Parameter No. 80"},
411         { 4891 , "Status of Process No. 11"},
412         { 4892 , "Status of Process No. 12"},
413         { 4893 , "Status of Process No. 13"},
414         { 4894 , "Status of Process No. 14"},
415         { 4895 , "Status of Process No. 15"},
416         { 4896 , "Status of Process No. 16"},
417         {10000 , "Start Timing Analyzer"},
418         {10001 , "Stop Timing Analyzer"},
419         { 0, NULL },
420 };
421 static value_string_ext parameter_mapping_ext = VALUE_STRING_EXT_INIT(parameter_mapping);
422
423 typedef enum {
424         APT_UDPH1_old, APT_UDPH1_new, APT_UDPR1, APT_UDPR2, APT_UDPR3,
425         APT_UDPR4, APT_GDSHP, APT_GDSHR
426 } adwin_packet_types_t;
427
428 static const value_string packet_type_mapping[] = {
429         { APT_UDPH1_old, "UDPH1 old"},
430         { APT_UDPH1_new, "UDPH1 new"},
431         { APT_UDPR1, "UDPR1"},
432         { APT_UDPR2, "UDPR2"},
433         { APT_UDPR3, "UDPR3"},
434         { APT_UDPR4, "UDPR4"},
435         { APT_GDSHP, "GDSHP"},
436         { APT_GDSHR, "GDSHR"},
437         { 0, NULL },
438 };
439 static value_string_ext packet_type_mapping_ext = VALUE_STRING_EXT_INIT(packet_type_mapping);
440
441 #define SET_PACKET_TYPE(tree, type)                              \
442         proto_tree_add_int(tree, hf_adwin_packet_type, tvb, 0, tvb_length(tvb), type);
443
444
445 /* Initialize the protocol and registered fields */
446 static int proto_adwin                = -1;
447
448 static unsigned int global_adwin_udp_port = ADWIN_COMM_PORT;
449 static int global_adwin_dissect_data  = 1;
450
451 static int hf_adwin_address           = -1;
452 static int hf_adwin_armVersion        = -1;
453 static int hf_adwin_binfilesize       = -1;
454 static int hf_adwin_blocksize         = -1;
455 static int hf_adwin_count             = -1;
456 static int hf_adwin_complete_packets  = -1;
457 static int hf_adwin_data_int          = -1;
458 static int hf_adwin_data_float        = -1;
459 static int hf_adwin_data_hex          = -1;
460 static int hf_adwin_data_no16         = -1;
461 static int hf_adwin_data_no32         = -1;
462 static int hf_adwin_data_packet_index = -1;
463 static int hf_adwin_data_type         = -1;
464 static int hf_adwin_dll_version       = -1;
465 static int hf_adwin_fifo_no16         = -1;
466 static int hf_adwin_fifo_no32         = -1;
467 static int hf_adwin_instruction       = -1;
468 static int hf_adwin_is_range          = -1;
469 static int hf_adwin_i3plus1           = -1;
470 static int hf_adwin_link_addr         = -1;
471 static int hf_adwin_mem_type          = -1;
472 static int hf_adwin_memsize           = -1;
473 static int hf_adwin_osys              = -1;
474 static int hf_adwin_packet_index      = -1;
475 static int hf_adwin_packet_no         = -1;
476 static int hf_adwin_packet_start      = -1;
477 static int hf_adwin_packet_end        = -1;
478 static int hf_adwin_packet_type       = -1;
479 static int hf_adwin_parameter         = -1;
480 static int hf_adwin_password          = -1;
481 static int hf_adwin_process_no        = -1;
482 static int hf_adwin_processor         = -1;
483 static int hf_adwin_response_in       = -1;
484 static int hf_adwin_response_to       = -1;
485 static int hf_adwin_response_time     = -1;
486 static int hf_adwin_retry_packet_index= -1;
487 static int hf_adwin_request_no        = -1;
488 static int hf_adwin_start_index       = -1;
489 static int hf_adwin_status            = -1;
490 static int hf_adwin_timeout           = -1;
491 static int hf_adwin_unused            = -1;
492 static int hf_adwin_val1              = -1;
493 static int hf_adwin_val1f             = -1;
494 static int hf_adwin_val2              = -1;
495 static int hf_adwin_val3              = -1;
496 static int hf_adwin_val4              = -1;
497
498 /* Initialize the subtree pointers */
499 static gint ett_adwin                 = -1;
500 static gint ett_adwin_debug           = -1;
501
502 /* response/request tracking */
503 typedef struct _adwin_transaction_t {
504         guint32 req_frame;
505         guint32 rep_frame;
506         nstime_t req_time;
507 } adwin_transaction_t;
508
509 /* response/request tracking */
510 typedef struct _adwin_conv_info_t {
511         wmem_tree_t *pdus;
512 } adwin_conv_info_t;
513
514 typedef enum { ADWIN_REQUEST,
515                ADWIN_RESPONSE
516 } adwin_direction_t;
517
518 static void
519 adwin_request_response_handling(tvbuff_t *tvb, packet_info *pinfo,
520                                 proto_tree *adwin_tree, guint32 seq_num, adwin_direction_t direction)
521 {
522         conversation_t *conversation;
523         adwin_conv_info_t *adwin_info;
524         adwin_transaction_t *adwin_trans;
525
526         /*
527          * Find or create a conversation for this connection.
528          */
529         conversation = find_or_create_conversation(pinfo);
530
531         /*
532          * Do we already have a state structure for this conv
533          */
534         adwin_info = (adwin_conv_info_t *)conversation_get_proto_data(conversation, proto_adwin);
535         if (!adwin_info) {
536                 /*
537                  * No.  Attach that information to the conversation, and add
538                  * it to the list of information structures.
539                  */
540                 adwin_info = wmem_new(wmem_file_scope(), adwin_conv_info_t);
541                 adwin_info->pdus = wmem_tree_new(wmem_file_scope());
542
543                 conversation_add_proto_data(conversation, proto_adwin, adwin_info);
544         }
545         if (!pinfo->fd->flags.visited) {
546                 if (direction == ADWIN_REQUEST) {
547                         /* This is a request */
548                         adwin_trans = wmem_new(wmem_file_scope(), adwin_transaction_t);
549                         adwin_trans->req_frame = pinfo->fd->num;
550                         adwin_trans->rep_frame = 0;
551                         adwin_trans->req_time = pinfo->fd->abs_ts;
552                         wmem_tree_insert32(adwin_info->pdus, seq_num, (void *)adwin_trans);
553                 } else {
554                         adwin_trans = (adwin_transaction_t *)wmem_tree_lookup32(adwin_info->pdus, seq_num);
555                         if (adwin_trans) {
556                                 adwin_trans->rep_frame = pinfo->fd->num;
557                         }
558                 }
559         } else {
560                 adwin_trans = (adwin_transaction_t *)wmem_tree_lookup32(adwin_info->pdus, seq_num);
561         }
562         if (!adwin_trans) {
563                 /* create a "fake" adwin_trans structure */
564                 adwin_trans = wmem_new(wmem_packet_scope(), adwin_transaction_t);
565                 adwin_trans->req_frame = 0;
566                 adwin_trans->rep_frame = 0;
567                 adwin_trans->req_time = pinfo->fd->abs_ts;
568         }
569
570         /* print state tracking in the tree */
571         if (direction == ADWIN_REQUEST) {
572                 /* This is a request */
573                 if (adwin_trans->rep_frame) {
574                         proto_item *it;
575
576                         it = proto_tree_add_uint(adwin_tree, hf_adwin_response_in,
577                                         tvb, 0, 0, adwin_trans->rep_frame);
578                         PROTO_ITEM_SET_GENERATED(it);
579                 }
580         } else {
581                 /* This is a reply */
582                 if (adwin_trans->req_frame) {
583                         proto_item *it;
584                         nstime_t ns;
585
586                         it = proto_tree_add_uint(adwin_tree, hf_adwin_response_to,
587                                         tvb, 0, 0, adwin_trans->req_frame);
588                         PROTO_ITEM_SET_GENERATED(it);
589
590                         nstime_delta(&ns, &pinfo->fd->abs_ts, &adwin_trans->req_time);
591                         it = proto_tree_add_time(adwin_tree, hf_adwin_response_time, tvb, 0, 0, &ns);
592                         PROTO_ITEM_SET_GENERATED(it);
593                 }
594         }
595 }
596
597 static void
598 dissect_UDPH1_generic(tvbuff_t *tvb, packet_info *pinfo,
599                       proto_tree *adwin_tree, proto_tree *adwin_debug_tree, gchar** info_string, const gchar* packet_name)
600 {
601         guint32 i3plus1code =  0, instructionID, seq_num;
602
603         instructionID = tvb_get_letohl(tvb, 0);
604         *info_string = wmem_strdup_printf(wmem_packet_scope(), "%s: %s", packet_name,
605                                         val_to_str_ext(instructionID, &instruction_mapping_ext, "unknown instruction: %d"));
606
607         if (instructionID == I_3PLUS1) {
608                 gchar *tmp = *info_string;
609
610                 i3plus1code = tvb_get_letohl(tvb, 20);
611                 *info_string = wmem_strdup_printf(wmem_packet_scope(), "%s: %s", tmp, val_to_str_ext(i3plus1code, &instruction_3plus1_mapping_ext, "unknown 3+1 code: %d"));
612         }
613
614         /* Get the transaction identifier */
615         seq_num = tvb_get_letohl(tvb, 4);
616         adwin_request_response_handling(tvb, pinfo, adwin_tree, seq_num, ADWIN_REQUEST);
617
618         if (! adwin_tree)
619                 return;
620
621         SET_PACKET_TYPE(adwin_tree, APT_UDPH1_old);
622
623         proto_tree_add_item(adwin_tree, hf_adwin_instruction,          tvb, 0,  4, ENC_LITTLE_ENDIAN);
624         proto_tree_add_item(adwin_tree, hf_adwin_packet_index,         tvb, 4,  4, ENC_LITTLE_ENDIAN);
625         proto_tree_add_item(adwin_tree, hf_adwin_password,             tvb, 8, 10, ENC_BIG_ENDIAN);
626         proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,        tvb, 18,  2, ENC_LITTLE_ENDIAN);
627
628         switch(instructionID) {
629         case I_3PLUS1:
630                 proto_tree_add_item(adwin_tree, hf_adwin_i3plus1,      tvb, 20,  4, ENC_LITTLE_ENDIAN);
631                 switch (i3plus1code) {
632                 case I_3P1_SET_PAR:
633                         proto_tree_add_item(adwin_tree, hf_adwin_parameter,     tvb, 24,  4, ENC_LITTLE_ENDIAN);
634                         proto_tree_add_item(adwin_tree, hf_adwin_val1,          tvb, 28,  4, ENC_LITTLE_ENDIAN);
635                         proto_tree_add_item(adwin_tree, hf_adwin_val1f,         tvb, 28,  4, ENC_LITTLE_ENDIAN);
636                         proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 32,  4, ENC_LITTLE_ENDIAN);
637                         break;
638                 case I_3P1_GET_PAR:
639                         proto_tree_add_item(adwin_tree, hf_adwin_parameter,     tvb, 24,  4, ENC_LITTLE_ENDIAN);
640                         proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 28,  8, ENC_LITTLE_ENDIAN);
641                         break;
642                 case I_3P1_GET_MEMORY_INFO:
643                 case I_3P1_GET_DETAILED_MEM_INFO:
644                         proto_tree_add_item(adwin_tree, hf_adwin_mem_type,      tvb, 24,  4, ENC_LITTLE_ENDIAN);
645                         proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 28,  8, ENC_LITTLE_ENDIAN);
646                         break;
647                 case I_3P1_START:
648                 case I_3P1_STOP:
649                 case I_3P1_CLEAR_PROCESS:
650                         proto_tree_add_item(adwin_tree, hf_adwin_process_no,    tvb, 24,  4, ENC_LITTLE_ENDIAN);
651                         proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 28,  8, ENC_LITTLE_ENDIAN);
652                         break;
653                 case I_3P1_GET_DATA_LENGTH:
654                         proto_tree_add_item(adwin_tree, hf_adwin_data_no32,     tvb, 24,  4, ENC_LITTLE_ENDIAN);
655                         proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 28,  8, ENC_LITTLE_ENDIAN);
656                         break;
657                 case I_3P1_CLEAR_FIFO:
658                 case I_3P1_GET_FIFO_EMPTY:
659                 case I_3P1_GET_FIFO_COUNT:
660                         proto_tree_add_item(adwin_tree, hf_adwin_fifo_no32,     tvb, 24,  4, ENC_LITTLE_ENDIAN);
661                         proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 28,  8, ENC_LITTLE_ENDIAN);
662                         break;
663                 default: ; /* should not happen */
664                         /* illegal values should be displayed properly
665                            by 3plus1_mapping */
666                 }
667                 break;
668         case I_BOOT:
669                 proto_tree_add_item(adwin_tree, hf_adwin_memsize,       tvb, 20,  4, ENC_LITTLE_ENDIAN);
670                 proto_tree_add_item(adwin_tree, hf_adwin_blocksize,     tvb, 24,  2, ENC_LITTLE_ENDIAN);
671                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 26,  2, ENC_LITTLE_ENDIAN);
672                 proto_tree_add_item(adwin_tree, hf_adwin_processor,     tvb, 28,  4, ENC_LITTLE_ENDIAN);
673                 proto_tree_add_item(adwin_tree, hf_adwin_binfilesize,   tvb, 32,  4, ENC_LITTLE_ENDIAN);
674                 break;
675         case I_LOAD_BIN_FILE:
676                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 20,  6, ENC_LITTLE_ENDIAN);
677                 proto_tree_add_item(adwin_tree, hf_adwin_blocksize,     tvb, 26,  2, ENC_LITTLE_ENDIAN);
678                 proto_tree_add_item(adwin_tree, hf_adwin_processor,     tvb, 28,  4, ENC_LITTLE_ENDIAN);
679                 proto_tree_add_item(adwin_tree, hf_adwin_binfilesize,   tvb, 32,  4, ENC_LITTLE_ENDIAN);
680                 break;
681         case I_GET_WORKLOAD:
682                 proto_tree_add_item(adwin_tree, hf_adwin_instruction,   tvb, 20,  4, ENC_LITTLE_ENDIAN);
683                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 24, 12, ENC_LITTLE_ENDIAN);
684                 break;
685         case I_GET_DATA_TYPE:
686                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 20,  4, ENC_LITTLE_ENDIAN);
687                 proto_tree_add_item(adwin_tree, hf_adwin_data_no32,     tvb, 24,  4, ENC_LITTLE_ENDIAN);
688                 proto_tree_add_item(adwin_tree, hf_adwin_start_index,   tvb, 28,  4, ENC_LITTLE_ENDIAN);
689                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 32,  4, ENC_LITTLE_ENDIAN);
690                 break;
691         case I_GET_DATA:
692         case I_SET_DATA:
693                 proto_tree_add_item(adwin_tree, hf_adwin_data_type,     tvb, 20,  4, ENC_LITTLE_ENDIAN);
694                 proto_tree_add_item(adwin_tree, hf_adwin_data_no16,     tvb, 24,  2, ENC_LITTLE_ENDIAN);
695                 proto_tree_add_item(adwin_tree, hf_adwin_blocksize,     tvb, 26,  2, ENC_LITTLE_ENDIAN);
696                 proto_tree_add_item(adwin_tree, hf_adwin_start_index,   tvb, 28,  4, ENC_LITTLE_ENDIAN);
697                 proto_tree_add_item(adwin_tree, hf_adwin_count,         tvb, 32,  4, ENC_LITTLE_ENDIAN);
698                 break;
699         case I_GET_DATA_SHIFTED_HANDSHAKE:
700                 proto_tree_add_item(adwin_tree, hf_adwin_data_no16,     tvb, 20,  2, ENC_BIG_ENDIAN);
701                 proto_tree_add_item(adwin_tree, hf_adwin_blocksize,     tvb, 22,  2, ENC_BIG_ENDIAN);
702                 proto_tree_add_item(adwin_tree, hf_adwin_start_index,   tvb, 24,  4, ENC_BIG_ENDIAN);
703                 proto_tree_add_item(adwin_tree, hf_adwin_count,         tvb, 28,  4, ENC_BIG_ENDIAN);
704                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 32,  4, ENC_BIG_ENDIAN);
705                 break;
706         case I_GET_DATA_SMALL:
707                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 20,  4, ENC_LITTLE_ENDIAN);
708                 proto_tree_add_item(adwin_tree, hf_adwin_data_no16,     tvb, 24,  2, ENC_LITTLE_ENDIAN);
709                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 26,  2, ENC_LITTLE_ENDIAN);
710                 proto_tree_add_item(adwin_tree, hf_adwin_start_index,   tvb, 28,  4, ENC_LITTLE_ENDIAN);
711                 proto_tree_add_item(adwin_tree, hf_adwin_count,         tvb, 32,  4, ENC_LITTLE_ENDIAN);
712                 break;
713         case I_GET_PAR_ALL:
714                 proto_tree_add_item(adwin_tree, hf_adwin_start_index,   tvb, 20,  4, ENC_LITTLE_ENDIAN);
715                 proto_tree_add_item(adwin_tree, hf_adwin_count,         tvb, 24,  4, ENC_LITTLE_ENDIAN);
716                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 28,  8, ENC_LITTLE_ENDIAN);
717                 break;
718         case I_SET_DATA_LAST_STATUS:
719                 proto_tree_add_item(adwin_tree, hf_adwin_data_packet_index, tvb, 20,  4, ENC_LITTLE_ENDIAN);
720                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 24,  12, ENC_LITTLE_ENDIAN);
721                 break;
722         case I_GET_ARM_VERSION:
723                 proto_tree_add_item(adwin_tree, hf_adwin_armVersion,  tvb, 20,  4, ENC_LITTLE_ENDIAN);
724                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused, tvb, 24, 12, ENC_LITTLE_ENDIAN);
725                 break;
726         case I_GET_FIFO:
727         case I_SET_FIFO:
728                 proto_tree_add_item(adwin_tree, hf_adwin_data_type,     tvb, 20,  4, ENC_LITTLE_ENDIAN);
729                 proto_tree_add_item(adwin_tree, hf_adwin_fifo_no16,     tvb, 24,  2, ENC_LITTLE_ENDIAN);
730                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 26,  6, ENC_LITTLE_ENDIAN);
731                 proto_tree_add_item(adwin_tree, hf_adwin_count,         tvb, 32,  4, ENC_LITTLE_ENDIAN);
732                 break;
733         case I_GET_FIFO_RETRY:
734         case I_SET_FIFO_RETRY:
735                 proto_tree_add_item(adwin_tree, hf_adwin_data_type,     tvb, 20,  4, ENC_LITTLE_ENDIAN);
736                 proto_tree_add_item(adwin_tree, hf_adwin_fifo_no16,     tvb, 24,  2, ENC_LITTLE_ENDIAN);
737                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 26,  2, ENC_LITTLE_ENDIAN);
738                 proto_tree_add_item(adwin_tree, hf_adwin_retry_packet_index, tvb, 28,  4, ENC_LITTLE_ENDIAN);
739                 proto_tree_add_item(adwin_tree, hf_adwin_count,         tvb, 32,  4, ENC_LITTLE_ENDIAN);
740                 break;
741         case I_TEST_VERSION:
742                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 20,  16, ENC_LITTLE_ENDIAN);
743                 break;
744         case I_GET_MEMORY:
745                 proto_tree_add_item(adwin_tree, hf_adwin_address,       tvb, 20,  4, ENC_LITTLE_ENDIAN);
746                 proto_tree_add_item(adwin_tree, hf_adwin_count,         tvb, 24,  4, ENC_LITTLE_ENDIAN);
747                 proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 28,  8, ENC_LITTLE_ENDIAN);
748                 break;
749         default: ; /* should not happen */
750                 /* illegal values should be displayed properly by
751                    instruction_mapping */
752         }
753
754         proto_tree_add_item(adwin_debug_tree, hf_adwin_link_addr, tvb, 36,  4, ENC_LITTLE_ENDIAN);
755         proto_tree_add_item(adwin_tree, hf_adwin_timeout,        tvb, 40,  4, ENC_LITTLE_ENDIAN);
756         proto_tree_add_item(adwin_debug_tree, hf_adwin_osys,     tvb, 44,  4, ENC_LITTLE_ENDIAN);
757         proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,   tvb, 48,  4, ENC_LITTLE_ENDIAN);
758
759 }
760
761
762 static void
763 dissect_UDPH1_old(tvbuff_t *tvb, packet_info *pinfo,
764                   proto_tree *adwin_tree, proto_tree *adwin_debug_tree, gchar** info_string)
765 {
766         dissect_UDPH1_generic(tvb, pinfo, adwin_tree, adwin_debug_tree, info_string, "UDPH1 (old)");
767 }
768
769 static void
770 dissect_UDPH1_new(tvbuff_t *tvb, packet_info *pinfo,
771                   proto_tree *adwin_tree, proto_tree *adwin_debug_tree,
772                   gchar** info_string)
773 {
774         gchar* dll_version_s;
775         gint32 dll_i;
776
777         dissect_UDPH1_generic(tvb, pinfo, adwin_tree, adwin_debug_tree, info_string, "UDPH1 (new)");
778
779         if (! adwin_tree)
780                 return;
781
782         SET_PACKET_TYPE(adwin_tree, APT_UDPH1_new);
783         dll_i = tvb_get_letohl(tvb, 52);
784         dll_version_s = wmem_strdup_printf(wmem_packet_scope(), "%d.%d.%d",
785                                         dll_i / 1000000,
786                                         (dll_i - dll_i / 1000000 * 1000000) / 1000,
787                                         dll_i % 1000);
788
789         proto_tree_add_string(adwin_debug_tree, hf_adwin_dll_version,
790                               tvb, 52, 4, dll_version_s);
791 }
792
793 static void
794 dissect_UDPR1(tvbuff_t *tvb, packet_info *pinfo,
795               proto_tree *adwin_tree, proto_tree *adwin_debug_tree,
796               gchar** info_string)
797 {
798         const gchar *status_string;
799         guint32 seq_num, status;
800
801         status = tvb_get_letohl(tvb, 0);
802         status_string = try_val_to_str_ext(status, &error_code_mapping_ext);
803         if (status_string) {
804                 *info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR1 Status: %s", status_string);
805         } else {
806                 *info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR1 Undefined error code %d", status);
807         }
808
809         /* Get the transaction identifier */
810         seq_num = tvb_get_letohl(tvb, 4);
811         adwin_request_response_handling(tvb, pinfo, adwin_tree, seq_num, ADWIN_RESPONSE);
812
813         if (! adwin_tree)
814                 return;
815
816         SET_PACKET_TYPE(adwin_tree, APT_UDPR1);
817         proto_tree_add_item(adwin_tree, hf_adwin_status,         tvb, 0,  4, ENC_LITTLE_ENDIAN);
818         proto_tree_add_item(adwin_tree, hf_adwin_packet_index,   tvb, 4,  4, ENC_LITTLE_ENDIAN);
819         proto_tree_add_item(adwin_tree, hf_adwin_val1,           tvb, 8,  4, ENC_LITTLE_ENDIAN);
820         proto_tree_add_item(adwin_tree, hf_adwin_val1f,          tvb, 8,  4, ENC_LITTLE_ENDIAN);
821         proto_tree_add_item(adwin_tree, hf_adwin_val2,          tvb, 12,  4, ENC_LITTLE_ENDIAN);
822         proto_tree_add_item(adwin_tree, hf_adwin_val3,          tvb, 16,  4, ENC_LITTLE_ENDIAN);
823         proto_tree_add_item(adwin_tree, hf_adwin_val4,          tvb, 20,  4, ENC_LITTLE_ENDIAN);
824         proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,  tvb, 24,  8, ENC_LITTLE_ENDIAN);
825 }
826
827 static void
828 dissect_UDPR2(tvbuff_t *tvb, packet_info *pinfo,
829               proto_tree *adwin_tree, proto_tree *adwin_debug_tree,
830               gchar** info_string)
831 {
832         const gchar *status_string;
833         guint32 i, status, seq_num;
834
835         status = tvb_get_letohl(tvb, 0);
836         status_string = try_val_to_str_ext(status, &error_code_mapping_ext);
837         if (status_string) {
838                 *info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR2 Status: %s", status_string);
839         } else {
840                 *info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR2 Undefined error code %d", status);
841         }
842
843         /* Get the transaction identifier */
844         seq_num = tvb_get_letohl(tvb, 4);
845         adwin_request_response_handling(tvb, pinfo, adwin_tree, seq_num, ADWIN_RESPONSE);
846
847         if (! adwin_tree)
848                 return;
849
850         SET_PACKET_TYPE(adwin_tree, APT_UDPR2);
851         proto_tree_add_item(adwin_tree, hf_adwin_status,         tvb, 0,  4, ENC_LITTLE_ENDIAN);
852         proto_tree_add_item(adwin_tree, hf_adwin_packet_index,   tvb, 4,  4, ENC_LITTLE_ENDIAN);
853
854         if (! global_adwin_dissect_data) {
855                 proto_tree_add_text(adwin_debug_tree, tvb, 8, 250 * 4, "Data");
856                 return;
857         }
858
859         for (i = 0; i < 250; i++) {
860                 proto_item *item;
861                 guint32 offset = 8 + i * (int)sizeof(guint32);
862                 gint32 value = tvb_get_letohl(tvb, offset);
863                 void * fvalue = &value;
864                 proto_tree_add_text(adwin_debug_tree, tvb, offset, 4,
865                                     "Data[%3d]: %10d - %10f - 0x%08x",
866                                     i, value, *(float*)fvalue, value);
867                 item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_int,   tvb, offset, 4, ENC_LITTLE_ENDIAN);
868                 PROTO_ITEM_SET_HIDDEN(item);
869                 item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_float, tvb, offset, 4, ENC_LITTLE_ENDIAN);
870                 PROTO_ITEM_SET_HIDDEN(item);
871                 item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_hex,   tvb, offset, 4, ENC_LITTLE_ENDIAN);
872                 PROTO_ITEM_SET_HIDDEN(item);
873         }
874 }
875
876 static void
877 dissect_UDPR3(tvbuff_t *tvb, packet_info *pinfo,
878               proto_tree *adwin_tree, proto_tree *adwin_debug_tree)
879 {
880         guint32 i, seq_num;
881
882         /* Get the transaction identifier */
883         seq_num = tvb_get_letohl(tvb, 0);
884         adwin_request_response_handling(tvb, pinfo, adwin_tree, seq_num, ADWIN_RESPONSE);
885
886         if (! adwin_tree)
887                 return;
888
889         SET_PACKET_TYPE(adwin_tree, APT_UDPR3);
890         proto_tree_add_item(adwin_tree, hf_adwin_packet_index,   tvb, 0,  4, ENC_LITTLE_ENDIAN);
891         proto_tree_add_item(adwin_tree, hf_adwin_packet_no,      tvb, 4,  4, ENC_LITTLE_ENDIAN);
892
893         if (! global_adwin_dissect_data) {
894                 proto_tree_add_text(adwin_debug_tree, tvb, 8, 350 * 4, "Data");
895                 return;
896         }
897
898         for (i = 0; i < 350; i++) {
899                 proto_item *item;
900                 guint32 offset = 8 + i * (int)sizeof(guint32);
901                 gint32 value = tvb_get_letohl(tvb, offset);
902                 void * fvalue = &value;
903                 proto_tree_add_text(adwin_debug_tree, tvb, offset, 4,
904                                     "Data[%3d]: %10d - %10f - 0x%08x",
905                                     i, value, *(float*)fvalue, value);
906                 item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_int,   tvb, offset, 4, ENC_LITTLE_ENDIAN);
907                 PROTO_ITEM_SET_HIDDEN(item);
908                 item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_float, tvb, offset, 4, ENC_LITTLE_ENDIAN);
909                 PROTO_ITEM_SET_HIDDEN(item);
910                 item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_hex,   tvb, offset, 4, ENC_LITTLE_ENDIAN);
911                 PROTO_ITEM_SET_HIDDEN(item);
912         }
913 }
914
915 static void
916 dissect_UDPR4(tvbuff_t *tvb, packet_info *pinfo,
917               proto_tree *adwin_tree, proto_tree *adwin_debug_tree, gchar** info_string)
918 {
919         const gchar *status_string;
920         guint32 data_type, i, status, seq_num;
921
922         status = tvb_get_letohl(tvb, 0);
923         status_string = try_val_to_str_ext(status, &error_code_mapping_ext);
924         if (status_string) {
925                 *info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR4 Status: %s", status_string);
926         } else {
927                 *info_string = wmem_strdup_printf(wmem_packet_scope(), "UDPR4 Undefined error code %d", status);
928         }
929
930         /* Get the transaction identifier */
931         seq_num = tvb_get_letohl(tvb, 4);
932         adwin_request_response_handling(tvb, pinfo, adwin_tree, seq_num, ADWIN_RESPONSE);
933
934         if (! adwin_tree)
935                 return;
936
937         SET_PACKET_TYPE(adwin_tree, APT_UDPR4);
938         proto_tree_add_item(adwin_tree, hf_adwin_status,         tvb, 0,  4, ENC_LITTLE_ENDIAN);
939         proto_tree_add_item(adwin_tree, hf_adwin_packet_index,   tvb, 4,  4, ENC_LITTLE_ENDIAN);
940         proto_tree_add_item(adwin_tree, hf_adwin_packet_no,      tvb, 1408,  4, ENC_LITTLE_ENDIAN);
941         proto_tree_add_item(adwin_tree, hf_adwin_data_type,      tvb, 1412,  4, ENC_LITTLE_ENDIAN);
942
943         data_type = tvb_get_letohl(tvb, 1412);
944
945         if (! global_adwin_dissect_data) {
946                 proto_tree_add_text(adwin_debug_tree, tvb, 8, 350 * 4, "Data");
947                 return;
948         }
949
950         for (i = 0; i < 350; i++) {
951                 proto_item *item;
952                 guint32 offset = 8 + i * (int)sizeof(guint32);
953                 gint32 value = tvb_get_letohl(tvb, offset);
954                 void * fvalue = &value;
955                 switch (data_type) {
956                 case 2:
957                 case 3:
958                 case 4:  /* some kind of int, usually int/long */
959                         proto_tree_add_text(adwin_debug_tree, tvb, offset, 4,
960                                             "Data[%3d]: %10d - 0x%08x",
961                                             i, value, value);
962                         item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_int,   tvb, offset, 4, ENC_LITTLE_ENDIAN);
963                         PROTO_ITEM_SET_HIDDEN(item);
964                         item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_hex,   tvb, offset, 4, ENC_LITTLE_ENDIAN);
965                         PROTO_ITEM_SET_HIDDEN(item);
966                         break;
967                 case 5: /* float */
968                         proto_tree_add_text(adwin_debug_tree, tvb, offset, 4,
969                                             "Data[%3d]: %10f - 0x%08x",
970                                             i, *(float*)fvalue, value);
971                         item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_float, tvb, offset, 4, ENC_LITTLE_ENDIAN);
972                         PROTO_ITEM_SET_HIDDEN(item);
973                         item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_hex,   tvb, offset, 4, ENC_LITTLE_ENDIAN);
974                         PROTO_ITEM_SET_HIDDEN(item);
975                         break;
976                 default: /* string, double, variant, something funny... */
977                         proto_tree_add_text(adwin_debug_tree, tvb, offset, 4,
978                                             "Data[%3d]: 0x%08x",
979                                             i, value);
980                         item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_hex,   tvb, offset, 4, ENC_LITTLE_ENDIAN);
981                         PROTO_ITEM_SET_HIDDEN(item);
982                 }
983         }
984 }
985
986 static void
987 dissect_GDSHP(tvbuff_t *tvb, packet_info *pinfo,
988               proto_tree *adwin_tree, proto_tree *adwin_debug_tree)
989 {
990         guint32 i, seq_num;
991
992         /* Get the transaction identifier */
993         seq_num = tvb_get_ntohl(tvb, 0);
994         adwin_request_response_handling(tvb, pinfo, adwin_tree, seq_num, ADWIN_RESPONSE);
995
996         if (! adwin_tree)
997                 return;
998
999         SET_PACKET_TYPE(adwin_tree, APT_GDSHP);
1000         proto_tree_add_item(adwin_tree, hf_adwin_packet_index,   tvb, 0,  4, ENC_BIG_ENDIAN);
1001         proto_tree_add_item(adwin_tree, hf_adwin_packet_no,      tvb, 4,  4, ENC_BIG_ENDIAN);
1002         proto_tree_add_item(adwin_tree, hf_adwin_unused,         tvb, 8,  4, ENC_BIG_ENDIAN);
1003
1004         if (! global_adwin_dissect_data) {
1005                 proto_tree_add_text(adwin_debug_tree, tvb, 12, 336 * 4, "Data");
1006                 return;
1007         }
1008
1009         for (i = 0; i < 336; i++) {
1010                 proto_item *item;
1011                 guint32 offset = 12 + i * (int)sizeof(guint32);
1012                 gint32 value = tvb_get_letohl(tvb, offset);
1013                 void * fvalue = &value;
1014                 proto_tree_add_text(adwin_debug_tree, tvb, offset, 4,
1015                                     "Data[%3d]: %10d - %10f - 0x%08x",
1016                                     i, value, *(float*)fvalue, value);
1017                 item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_int,   tvb, offset, 4, ENC_LITTLE_ENDIAN);
1018                 PROTO_ITEM_SET_HIDDEN(item);
1019                 item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_float, tvb, offset, 4, ENC_LITTLE_ENDIAN);
1020                 PROTO_ITEM_SET_HIDDEN(item);
1021                 item = proto_tree_add_item(adwin_debug_tree, hf_adwin_data_hex,   tvb, offset, 4, ENC_LITTLE_ENDIAN);
1022                 PROTO_ITEM_SET_HIDDEN(item);
1023         }
1024 }
1025
1026 static void
1027 dissect_GDSHR(tvbuff_t *tvb, packet_info *pinfo,
1028               proto_tree *adwin_tree, proto_tree *adwin_debug_tree)
1029 {
1030         guint32 is_range, packet_start, packet_end, seq_num;
1031
1032         /* Get the transaction identifier */
1033         seq_num = tvb_get_ntohl(tvb, 0);
1034         adwin_request_response_handling(tvb, pinfo, adwin_tree, seq_num, ADWIN_RESPONSE);
1035
1036         if (! adwin_tree)
1037                 return;
1038
1039         SET_PACKET_TYPE(adwin_tree, APT_GDSHR);
1040         proto_tree_add_item(adwin_tree, hf_adwin_packet_index,        tvb, 0,  4, ENC_BIG_ENDIAN);
1041         proto_tree_add_item(adwin_tree, hf_adwin_request_no,          tvb, 4,  4, ENC_BIG_ENDIAN);
1042         proto_tree_add_item(adwin_tree, hf_adwin_complete_packets,    tvb, 8,  4, ENC_BIG_ENDIAN);
1043         proto_tree_add_item(adwin_debug_tree, hf_adwin_is_range,     tvb, 12,  4, ENC_BIG_ENDIAN);
1044         proto_tree_add_item(adwin_debug_tree, hf_adwin_packet_start, tvb, 16,  4, ENC_BIG_ENDIAN);
1045         proto_tree_add_item(adwin_debug_tree, hf_adwin_packet_end,   tvb, 20,  4, ENC_BIG_ENDIAN);
1046
1047         is_range = tvb_get_ntohl(tvb, 12);
1048         packet_start = tvb_get_ntohl(tvb, 16);
1049
1050         switch(is_range) {
1051         case 0: proto_tree_add_text(adwin_tree, tvb, 12, 12,
1052                                     "GDSH status: get single packet no %d",
1053                                     packet_start);
1054                 break;
1055         case 1: packet_end = tvb_get_ntohl(tvb, 20);
1056                 proto_tree_add_text(adwin_tree, tvb, 12, 12,
1057                                     "GDSH status: get packets %d - %d",
1058                                     packet_start, packet_end);
1059                 break;
1060         case 2: proto_tree_add_text(adwin_tree, tvb, 12, 12,
1061                                     "GDSH status: finished");
1062                 break;
1063         default: /* should not happen */
1064                 proto_tree_add_text(adwin_tree, tvb, 12, 12,
1065                                     "GDSH status: unknown code %d", is_range);
1066         }
1067         proto_tree_add_item(adwin_debug_tree, hf_adwin_unused,       tvb, 24, 40, ENC_BIG_ENDIAN);
1068 }
1069
1070 /* here we determine which type of packet is sent by looking at its
1071    size. That is safe since the main server application that processes
1072    these packets does it this way, too.
1073
1074    Depending on the packet type, the appropriate dissector is
1075    called. */
1076
1077 static int
1078 dissect_adwin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
1079 {
1080         proto_item *ti, *ti2;
1081         proto_tree *adwin_tree, *adwin_debug_tree;
1082         gchar *info_string;
1083         guint32 length;
1084
1085         length = tvb_reported_length(tvb);
1086
1087         /* First do some heuristics to see if this packet belongs to us */
1088         if(! (length == UDPH1_OLD_LENGTH
1089               || length == UDPH1_NEW_LENGTH
1090               || length == UDPR1_LENGTH
1091               || length == UDPH2_LENGTH
1092               || length == UDPR2_LENGTH
1093               || length == UDPR3_LENGTH
1094               || length == UDPR4_LENGTH
1095               || length == GetDataSHPacket_LENGTH
1096               || length == GetDataSHRequest_LENGTH))
1097                 return(0);
1098
1099         col_set_str(pinfo->cinfo, COL_PROTOCOL, "ADwin");
1100         col_clear(pinfo->cinfo, COL_INFO);
1101
1102         if (tree) {
1103                 ti = proto_tree_add_item(tree, proto_adwin, tvb, 0, -1, ENC_NA);
1104                 adwin_tree = proto_item_add_subtree(ti, ett_adwin);
1105
1106                 ti2 = proto_tree_add_item(adwin_tree, proto_adwin, tvb, 0, -1, ENC_NA);
1107                 adwin_debug_tree = proto_item_add_subtree(ti2, ett_adwin_debug);
1108                 proto_item_set_text(ti2, "ADwin Debug information");
1109         } else {
1110                 adwin_tree = NULL;
1111                 adwin_debug_tree = NULL;
1112         }
1113
1114         switch (length) {
1115         case UDPH1_OLD_LENGTH:
1116                 dissect_UDPH1_old(tvb, pinfo, adwin_tree, adwin_debug_tree, &info_string);
1117                 break;
1118         case UDPH1_NEW_LENGTH:
1119                 dissect_UDPH1_new(tvb, pinfo, adwin_tree, adwin_debug_tree, &info_string);
1120                 break;
1121         case UDPR1_LENGTH:
1122                 dissect_UDPR1(tvb, pinfo, adwin_tree, adwin_debug_tree, &info_string);
1123                 break;
1124         case UDPH2_LENGTH: /* to the best of my knowledge, this struct
1125                             * has never been used publically! */
1126                 /* dissect_UDPH2(tvb, pinfo, adwin_tree, adwin_debug_tree); */
1127                 info_string = wmem_strdup(wmem_packet_scope(), "UDPH2 - UNUSED");
1128                 break;
1129         case UDPR2_LENGTH:
1130                 dissect_UDPR2(tvb, pinfo, adwin_tree, adwin_debug_tree, &info_string);
1131                 break;
1132         case UDPR3_LENGTH:
1133                 dissect_UDPR3(tvb, pinfo, adwin_tree, adwin_debug_tree);
1134                 info_string = wmem_strdup(wmem_packet_scope(), "UDPR3");
1135                 break;
1136         case UDPR4_LENGTH:
1137                 dissect_UDPR4(tvb, pinfo, adwin_tree, adwin_debug_tree, &info_string);
1138                 break;
1139         case GetDataSHPacket_LENGTH:
1140                 dissect_GDSHP(tvb, pinfo, adwin_tree, adwin_debug_tree);
1141                 info_string = wmem_strdup(wmem_packet_scope(), "GDSHP");
1142                 break;
1143         case GetDataSHRequest_LENGTH:
1144                 dissect_GDSHR(tvb, pinfo, adwin_tree, adwin_debug_tree);
1145                 info_string = wmem_strdup(wmem_packet_scope(), "GDSHR");
1146                 break;
1147         default:
1148                 info_string = wmem_strdup_printf(wmem_packet_scope(), "Unknown ADwin packet, length: %d", length);
1149                 break;
1150         }
1151
1152         col_add_str(pinfo->cinfo, COL_INFO, info_string);
1153
1154         return (tvb_reported_length(tvb));
1155 }
1156
1157
1158 void
1159 proto_reg_handoff_adwin(void)
1160 {
1161         static int adwin_prefs_initialized = FALSE;
1162         static dissector_handle_t adwin_handle;
1163         static unsigned int udp_port;
1164
1165         if (! adwin_prefs_initialized) {
1166                 adwin_handle = new_create_dissector_handle(dissect_adwin, proto_adwin);
1167                 adwin_prefs_initialized = TRUE;
1168         } else {
1169                 dissector_delete_uint("udp.port", udp_port, adwin_handle);
1170         }
1171
1172         udp_port = global_adwin_udp_port;
1173         dissector_add_uint("udp.port", global_adwin_udp_port, adwin_handle);
1174 }
1175
1176 void
1177 proto_register_adwin(void)
1178 {
1179         static hf_register_info hf[] = {
1180                 { &hf_adwin_address,
1181                   { "memory address", "adwin.address",
1182                     FT_UINT32, BASE_HEX, NULL, 0x0,
1183                     "Memory address to read on DSP", HFILL }
1184                 },
1185                 { &hf_adwin_armVersion,
1186                   { "Get ARM Version", "adwin.armVersion",
1187                     FT_UINT32, BASE_DEC, NULL, 0x0,
1188                     NULL, HFILL }
1189                 },
1190                 { &hf_adwin_binfilesize,
1191                   { "File size", "adwin.binfilesize",
1192                     FT_UINT32, BASE_DEC, NULL, 0x0,
1193                     "Size of binary file", HFILL }
1194                 },
1195                 { &hf_adwin_blocksize,
1196                   { "Blocksize", "adwin.blocksize",
1197                     FT_UINT32, BASE_DEC, NULL, 0x0,
1198                     "Maximum number of unacknowledged packets", HFILL }
1199                 },
1200                 { &hf_adwin_complete_packets,
1201                   { "Complete packets", "adwin.complete_packets",
1202                     FT_UINT32, BASE_DEC, NULL, 0x0,
1203                     "Highest sequential package number", HFILL }
1204                 },
1205                 { &hf_adwin_count,
1206                   { "Count", "adwin.count",
1207                     FT_UINT32, BASE_DEC, NULL, 0x0,
1208                     "Number of longs", HFILL }
1209                 },
1210                 { &hf_adwin_data_int,
1211                   { "Data element int", "adwin.data_int",
1212                     FT_INT32, BASE_DEC, NULL, 0x0,
1213                     NULL, HFILL }
1214                 },
1215                 { &hf_adwin_data_float,
1216                   { "Data element float", "adwin.data_float",
1217                     FT_FLOAT, BASE_NONE, NULL, 0x0,
1218                     NULL, HFILL }
1219                 },
1220                 { &hf_adwin_data_hex,
1221                   { "Data element hex", "adwin.data_hex",
1222                     FT_UINT32, BASE_HEX, NULL, 0x0,
1223                     NULL, HFILL }
1224                 },
1225                 { &hf_adwin_data_no16,
1226                   { "Data No. (16bit)", "adwin.data",
1227                     FT_UINT16, BASE_DEC, NULL, 0x0,
1228                     NULL, HFILL }
1229                 },
1230                 { &hf_adwin_data_no32,
1231                   { "Data No. (32bit)", "adwin.data",
1232                     FT_UINT32, BASE_DEC, NULL, 0x0,
1233                     NULL, HFILL }
1234                 },
1235                 { &hf_adwin_data_type,
1236                   { "Data type", "adwin.data_type",
1237                     FT_UINT32, BASE_DEC|BASE_EXT_STRING, &data_type_mapping_ext, 0x0,
1238                     NULL, HFILL }
1239                 },
1240                 { &hf_adwin_data_packet_index,
1241                   { "Data packet index", "adwin.data_packet_index",
1242                     FT_UINT32, BASE_DEC, NULL, 0x0,
1243                     NULL, HFILL }
1244                 },
1245                 { &hf_adwin_dll_version,
1246                   { "DLL Version", "adwin.dll_version",
1247                     FT_STRINGZ, BASE_NONE, NULL, 0x0,
1248                     NULL, HFILL }
1249                 },
1250                 { &hf_adwin_fifo_no16,
1251                   { "FiFo No. (16bit)", "adwin.fifo_no",
1252                     FT_UINT32, BASE_DEC, NULL, 0x0,
1253                     NULL, HFILL }
1254                 },
1255                 { &hf_adwin_fifo_no32,
1256                   { "FiFo No. (32bit)", "adwin.fifo_no",
1257                     FT_UINT32, BASE_DEC, NULL, 0x0,
1258                     NULL, HFILL }
1259                 },
1260                 { &hf_adwin_instruction,
1261                   { "Instruction", "adwin.instruction",
1262                     FT_UINT32, BASE_DEC|BASE_EXT_STRING, &instruction_mapping_ext, 0x0,
1263                     NULL, HFILL }
1264                 },
1265                 { &hf_adwin_is_range,
1266                   { "packets are a range", "adwin.is_range",
1267                     FT_UINT32, BASE_DEC, NULL, 0x0,
1268                     NULL, HFILL }
1269                 },
1270                 { &hf_adwin_i3plus1,
1271                   { "3+1 Instruction", "adwin.i3plus1",
1272                     FT_UINT32, BASE_DEC|BASE_EXT_STRING, &instruction_3plus1_mapping_ext, 0x0,
1273                     NULL, HFILL }
1274                 },
1275                 { &hf_adwin_link_addr,
1276                   { "Link address", "adwin.link_addr",
1277                     FT_UINT32, BASE_HEX, NULL, 0x0,
1278                     "Link address (TCP/IP Server only)", HFILL }
1279                 },
1280                 { &hf_adwin_mem_type,
1281                   { "Memory type", "adwin.mem_type",
1282                     FT_UINT32, BASE_DEC, NULL, 0x0,
1283                     NULL, HFILL }
1284                 },
1285                 { &hf_adwin_memsize,
1286                   { "Memory size", "adwin.memsize",
1287                     FT_UINT32, BASE_DEC, NULL, 0x0,
1288                     NULL, HFILL }
1289                 },
1290                 { &hf_adwin_osys,
1291                   { "Operating system", "adwin.osys",
1292                     FT_UINT32, BASE_DEC|BASE_EXT_STRING, &osys_mapping_ext, 0x0,
1293                     "Operating system / environment", HFILL }
1294                 },
1295                 { &hf_adwin_packet_end,
1296                   { "End packet", "adwin.packet_end",
1297                     FT_UINT32, BASE_DEC, NULL, 0x0,
1298                     "GDSH: End Packet", HFILL }
1299                 },
1300                 { &hf_adwin_packet_index,
1301                   { "Packet index", "adwin.packet_index",
1302                     FT_UINT32, BASE_DEC, NULL, 0x0,
1303                     NULL, HFILL }
1304                 },
1305                 { &hf_adwin_packet_no,
1306                   { "Packet No.", "adwin.packet_no",
1307                     FT_UINT32, BASE_DEC, NULL, 0x0,
1308                     NULL, HFILL }
1309                 },
1310                 { &hf_adwin_packet_start,
1311                   { "Starting packet", "adwin.packet_start",
1312                     FT_UINT32, BASE_DEC, NULL, 0x0,
1313                     "GDSH: Starting Packet", HFILL }
1314                 },
1315                 { &hf_adwin_packet_type,
1316                   { "Packet type", "adwin.packet_type",
1317                     FT_INT32, BASE_DEC|BASE_EXT_STRING, &packet_type_mapping_ext, 0x0,
1318                     NULL, HFILL }
1319                 },
1320                 { &hf_adwin_parameter,
1321                   { "Parameter", "adwin.parameter",
1322                     FT_UINT32, BASE_DEC|BASE_EXT_STRING, &parameter_mapping_ext, 0x0,
1323                     NULL, HFILL }
1324                 },
1325                 { &hf_adwin_password,
1326                   { "Password", "adwin.password",
1327                     FT_STRING, BASE_NONE, NULL, 0x0,
1328                     "Password for ADwin system", HFILL }
1329                 },
1330                 { &hf_adwin_process_no,
1331                   { "Process No.", "adwin.process_no",
1332                     FT_UINT32, BASE_DEC, NULL, 0x0,
1333                     NULL, HFILL }
1334                 },
1335                 { &hf_adwin_processor,
1336                   { "Processor", "adwin.processor",
1337                     FT_UINT32, BASE_DEC, NULL, 0x0,
1338                     NULL, HFILL }
1339                 },
1340                 { &hf_adwin_response_in,
1341                   { "Response In", "adwin.response_in",
1342                     FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1343                     "The response to this ADwin request is in this frame", HFILL }
1344                 },
1345                 { &hf_adwin_response_to,
1346                   { "Request In", "adwin.response_to",
1347                     FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1348                     "This is a response to the ADwin request in this frame", HFILL }
1349                 },
1350                 { &hf_adwin_response_time,
1351                   { "Response time", "adwin.response_time",
1352                     FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
1353                     "The time between the Request and the Reply", HFILL }
1354                 },
1355                 { &hf_adwin_retry_packet_index,
1356                   { "Retry packet index", "adwin.retry_packet_index",
1357                     FT_UINT32, BASE_DEC, NULL, 0x0,
1358                     NULL, HFILL }
1359                 },
1360                 { &hf_adwin_request_no,
1361                   { "Request Number", "adwin.request_no",
1362                     FT_UINT32, BASE_DEC, NULL, 0x0,
1363                     "Request number index", HFILL }
1364                 },
1365                 { &hf_adwin_start_index,
1366                   { "Start index", "adwin.start_index",
1367                     FT_UINT32, BASE_DEC, NULL, 0x0,
1368                     NULL, HFILL }
1369                 },
1370                 { &hf_adwin_status,
1371                   { "Status", "adwin.status",
1372                     FT_INT32, BASE_DEC|BASE_EXT_STRING, &error_code_mapping_ext, 0x0,
1373                     NULL, HFILL }
1374                 },
1375                 { &hf_adwin_timeout,
1376                   { "Timeout", "adwin.timeout",
1377                     FT_UINT32, BASE_DEC, NULL, 0x0,
1378                     "Timeout in ms", HFILL }
1379                 },
1380                 { &hf_adwin_unused,
1381                   { "Unused", "adwin.unused",
1382                     FT_NONE, BASE_NONE, NULL, 0x0,
1383                     NULL, HFILL }
1384                 },
1385                 { &hf_adwin_val1,
1386                   { "Value 1 (as int)", "adwin.val1",
1387                     FT_INT32, BASE_DEC, NULL, 0x0,
1388                     "Generic return value 1 interpreted as integer (correct interpretation depends on request).", HFILL }
1389                 },
1390                 { &hf_adwin_val1f,
1391                   { "Value 1 (as float)", "adwin.val1f",
1392                     FT_FLOAT, BASE_NONE, NULL, 0x0,
1393                     "Generic return value 1 interpreted as float (correct interpretation depends on request).", HFILL }
1394                 },
1395                 { &hf_adwin_val2,
1396                   { "Value 2", "adwin.val2",
1397                     FT_INT32, BASE_DEC, NULL, 0x0,
1398                     "Generic return value 2 (interpretation depends on request).", HFILL }
1399                 },
1400                 { &hf_adwin_val3,
1401                   { "Value 3", "adwin.val3",
1402                     FT_INT32, BASE_DEC, NULL, 0x0,
1403                     "Generic return value 3 (interpretation depends on request).", HFILL }
1404                 },
1405                 { &hf_adwin_val4,
1406                   { "Value 4", "adwin.val4",
1407                     FT_INT32, BASE_DEC, NULL, 0x0,
1408                     "Generic return value 4 (interpretation depends on request).", HFILL }
1409                 },
1410         };
1411
1412         /* Setup protocol subtree array */
1413         static gint *ett[] = {
1414                 &ett_adwin,
1415                 &ett_adwin_debug,
1416         };
1417         module_t *adwin_module;
1418
1419         /* Register the protocol name and description */
1420         proto_adwin = proto_register_protocol("ADwin communication protocol",
1421                                               "ADwin", "adwin");
1422
1423         /* Required function calls to register the header fields and
1424            subtrees used */
1425         proto_register_field_array(proto_adwin, hf, array_length(hf));
1426         proto_register_subtree_array(ett, array_length(ett));
1427
1428         /* Register our configuration options for ADwin, particularly
1429            our port */
1430         adwin_module = prefs_register_protocol(proto_adwin, proto_reg_handoff_adwin);
1431
1432         prefs_register_uint_preference(adwin_module, "udp.port", "ADwin UDP Port",
1433                                        "Set the UDP port for ADwin packets (if other"
1434                                        " than the default of 6543)",
1435                                        10, &global_adwin_udp_port);
1436
1437         prefs_register_bool_preference(adwin_module, "dissect_data",
1438                                        "Dissect Data sections",
1439                                        "Specify if the Data sections of packets "
1440                                        "should be dissected or not",
1441                                        &global_adwin_dissect_data);
1442 }