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