Define some fcns & vars as static ...
[obnox/wireshark/wip.git] / epan / dissectors / packet-omron-fins.c
1 /* packet-omron-fins.c
2  * Routines for OMRON FINS UDP dissection
3  * Copyright Sourcefire, Inc. 2008-2009, Matthew Watchinski <mwatchinski@sourcefire.com>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * Reference for OMRON-FINS W227_E1_02_FINS_Command_Reference_Manual
12  * Hopefully google will find it for you.
13  *
14  * Special thanks to the guys who wrote the README.developer its great.
15  *
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
29  * USA.
30  */
31
32
33 #ifdef HAVE_CONFIG_H
34 # include "config.h"
35 #endif
36
37 #include <glib.h>
38
39 #include <epan/packet.h>
40 #include <epan/prefs.h>
41 #include <epan/expert.h>
42
43 #define OMRON_FINS_UDP_PORT 9600
44
45 static int proto_omron_fins = -1;
46 static gint ett_omron = -1;
47 static gint ett_omron_header = -1;
48 static gint ett_omron_icf_fields = -1;
49 static gint ett_omron_command_data = -1;
50 static gint ett_area_data = -1;
51 static gint ett_cpu_bus = -1;
52 static gint ett_io_data = -1;
53 static gint ett_pc_status_fields = -1;
54 static gint ett_fatal_fields = -1;
55 static gint ett_non_fatal_fields = -1;
56 static gint ett_message_fields = -1;
57 static gint ett_omron_error_log_data = -1;
58 static gint ett_omron_disk_data = -1;
59 static gint ett_omron_file_data = -1;
60 static gint ett_omron_data_type = -1;
61 static gint ett_omron_block_record = -1;
62 static gint ett_omron_status_block = -1;
63 static gint ett_omron_cyclic_fields = -1;
64 static gint ett_omron_netw_nodes_sts = -1;
65 static gint ett_omron_netw_node_sts = -1;
66 static gint ett_omron_netw_nodes_non_fatal_err_sts = -1;
67 static gint ett_omron_netw_nodes_cyclic_err_ctrs = -1;
68 static gint ett_omron_data_link_status_tree = -1;
69
70 #if 0
71 static gboolean gPREF_HEX = FALSE;
72 #endif
73
74 /* Omron-FINS Header fields */
75 static int hf_omron_icf = -1;
76
77 static int hf_omron_icf_gwb = -1; /* Gateway usage (0: don't use; 1: use) should be 1 */
78 static int hf_omron_icf_dtb = -1; /* Data type (0: command 1: response) */
79 static int hf_omron_icf_rb0 = -1; /* Reserved should be 0 */
80 static int hf_omron_icf_rb1 = -1; /* Reserved should be 0 */
81 static int hf_omron_icf_rb2 = -1; /* Reserved should be 0 */
82 static int hf_omron_icf_rb3 = -1; /* Reserved should be 0 */
83 static int hf_omron_icf_rb4 = -1; /* Reserved should be 0 */
84 static int hf_omron_icf_rsb = -1; /* Response setting (0: response required; 1: response not required) */
85
86 static int hf_omron_rsv = -1;
87 static int hf_omron_gct = -1;
88 static int hf_omron_dna = -1;
89 static int hf_omron_da1 = -1;
90 static int hf_omron_da2 = -1;
91 static int hf_omron_sna = -1;
92 static int hf_omron_sa1 = -1;
93 static int hf_omron_sa2 = -1;
94 static int hf_omron_sid = -1;
95
96 static int hf_omron_command                  = -1;
97 static int hf_omron_command_data             = -1;
98 static int hf_omron_command_memory_area_code = -1;
99 static int hf_omron_response_code            = -1;
100
101 static int hf_omron_address      = -1;
102 static int hf_omron_address_bits = -1;
103 static int hf_omron_num_items    = -1;
104
105 static int hf_omron_response_data       = -1;
106 static int hf_omron_parameter_area_code = -1;
107
108 static int hf_omron_beginning_word = -1;
109 static int hf_omron_num_words = -1;
110
111 static int hf_omron_program_number = -1;
112 static int hf_omron_protect_code   = -1;
113 static int hf_omron_begin_word     = -1;
114 static int hf_omron_last_word      = -1;
115 static int hf_omron_password       = -1;
116
117 static int hf_omron_clear_code    = -1;
118 static int hf_omron_mode_code     = -1;
119 static int hf_omron_monitor_label = -1;
120
121 static int hf_omron_controller_model   = -1;
122 static int hf_omron_controller_version = -1;
123 static int hf_omron_for_system_use     = -1;
124
125 static int hf_omron_program_area_size    = -1;
126 static int hf_omron_iom_size             = -1;
127 static int hf_omron_num_dm_words         = -1;
128 static int hf_omron_timer_counter_size   = -1;
129 static int hf_omron_expansion_dm_size    = -1;
130 static int hf_omron_num_step_transitions = -1;
131 static int hf_omron_kind_memory_card     = -1;
132 static int hf_omron_memory_card_size     = -1;
133
134 static int hf_omron_cpu_bus_unit_0   = -1;
135 static int hf_omron_cpu_bus_unit_1   = -1;
136 static int hf_omron_cpu_bus_unit_2   = -1;
137 static int hf_omron_cpu_bus_unit_3   = -1;
138 static int hf_omron_cpu_bus_unit_4   = -1;
139 static int hf_omron_cpu_bus_unit_5   = -1;
140 static int hf_omron_cpu_bus_unit_6   = -1;
141 static int hf_omron_cpu_bus_unit_7   = -1;
142 static int hf_omron_cpu_bus_unit_8   = -1;
143 static int hf_omron_cpu_bus_unit_9   = -1;
144 static int hf_omron_cpu_bus_unit_10  = -1;
145 static int hf_omron_cpu_bus_unit_11  = -1;
146 static int hf_omron_cpu_bus_unit_12  = -1;
147 static int hf_omron_cpu_bus_unit_13  = -1;
148 static int hf_omron_cpu_bus_unit_14  = -1;
149 static int hf_omron_cpu_bus_unit_15  = -1;
150 static int hf_omron_cpu_bus_reserved = -1;
151
152 static int hf_omron_io_data_num_sysmac_1 = -1;
153 static int hf_omron_io_data_num_sysmac_2 = -1;
154
155 static int hf_omron_pc_status          = -1;
156 static int hf_omron_pc_status_pdc      = -1;
157 static int hf_omron_pc_status_hi       = -1;
158 static int hf_omron_pc_status_r1       = -1;
159 static int hf_omron_pc_status_r2       = -1;
160 static int hf_omron_pc_status_rack_num = -1;
161
162 static int hf_omron_unit_address = -1;
163 static int hf_omron_num_units    = -1;
164 static int hf_omron_model_number = -1;
165
166 static int hf_omron_status                      = -1;
167 static int hf_omron_fatal_error_data            = -1;
168 static int hf_omron_fatal_fals_error            = -1;
169 static int hf_omron_fatal_sfc_error             = -1;
170 static int hf_omron_fatal_cycle_time_over       = -1;
171 static int hf_omron_fatal_program_error         = -1;
172 static int hf_omron_fatal_io_setting_error      = -1;
173 static int hf_omron_fatal_io_point_overflow     = -1;
174 static int hf_omron_fatal_cpu_bus_error         = -1;
175 static int hf_omron_fatal_duplication_error     = -1;
176 static int hf_omron_fatal_io_bus_error          = -1;
177 static int hf_omron_fatal_memory_error          = -1;
178 static int hf_omron_fatal_rv_1                  = -1;
179 static int hf_omron_fatal_rv_2                  = -1;
180 static int hf_omron_fatal_rv_3                  = -1;
181 static int hf_omron_fatal_rv_4                  = -1;
182 static int hf_omron_fatal_rv_5                  = -1;
183 static int hf_omron_fatal_watch_dog_timer_error = -1;
184
185 static int hf_omron_non_fatal_error_data                 = -1;
186 static int hf_omron_non_fatal_rv1                        = -1;
187 static int hf_omron_non_fatal_rv2                        = -1;
188 static int hf_omron_non_fatal_power_interruption         = -1;
189 static int hf_omron_non_fatal_cpu_bus_unit_setting_error = -1;
190 static int hf_omron_non_fatal_battery_error              = -1;
191 static int hf_omron_non_fatal_sysmac_bus_error           = -1;
192 static int hf_omron_non_fatal_sysmac_bus2_error          = -1;
193 static int hf_omron_non_fatal_cpu_bus_unit_error         = -1;
194 static int hf_omron_non_fatal_rv3                        = -1;
195 static int hf_omron_non_fatal_io_verification_error      = -1;
196 static int hf_omron_non_fatal_rv4                        = -1;
197 static int hf_omron_non_fatal_sfc_error                  = -1;
198 static int hf_omron_non_fatal_indirect_dm_error          = -1;
199 static int hf_omron_non_fatal_jmp_error                  = -1;
200 static int hf_omron_non_fatal_rv5                        = -1;
201 static int hf_omron_non_fatal_fal_error                  = -1;
202
203 static int hf_omron_message = -1;
204 static int hf_omron_message_no_0 = -1;
205 static int hf_omron_message_no_1 = -1;
206 static int hf_omron_message_no_2 = -1;
207 static int hf_omron_message_no_3 = -1;
208 static int hf_omron_message_no_4 = -1;
209 static int hf_omron_message_no_5 = -1;
210 static int hf_omron_message_no_6 = -1;
211 static int hf_omron_message_no_7 = -1;
212 static int hf_omron_message_rv_0 = -1;
213 static int hf_omron_message_rv_1 = -1;
214 static int hf_omron_message_rv_2 = -1;
215 static int hf_omron_message_rv_3 = -1;
216 static int hf_omron_message_rv_4 = -1;
217 static int hf_omron_message_rv_5 = -1;
218 static int hf_omron_message_rv_6 = -1;
219 static int hf_omron_message_rv_7 = -1;
220
221 static int hf_omron_fals          = -1;
222 static int hf_omron_error_message = -1;
223
224 static int hf_omron_parameter      = -1;
225 static int hf_omron_avg_cycle_time = -1;
226 static int hf_omron_max_cycle_time = -1;
227 static int hf_omron_min_cycle_time = -1;
228
229 static int hf_omron_year   = -1;
230 static int hf_omron_month  = -1;
231 static int hf_omron_date   = -1;
232 static int hf_omron_hour   = -1;
233 static int hf_omron_minute = -1;
234 static int hf_omron_second = -1;
235 static int hf_omron_day    = -1;
236
237 static int hf_omron_read_message = -1;
238
239 static int hf_omron_node_number     = -1;
240 static int hf_omron_network_address = -1;
241
242 static int hf_omron_error_reset_fals_no = -1;
243
244 static int hf_omron_beginning_record_no      = -1;
245 static int hf_omron_no_of_records            = -1;
246 static int hf_omron_max_no_of_stored_records = -1;
247 static int hf_omron_no_of_stored_records     = -1;
248
249 static int hf_omron_disk_no                 = -1;
250 static int hf_omron_beginning_file_position = -1;
251 static int hf_omron_no_of_files             = -1;
252
253 static int hf_omron_volume_label    = -1;
254 static int hf_omron_date_year       = -1;
255 static int hf_omron_date_month      = -1;
256 static int hf_omron_date_day        = -1;
257 static int hf_omron_date_hour       = -1;
258 static int hf_omron_date_minute     = -1;
259 static int hf_omron_date_second     = -1;
260 static int hf_omron_total_capacity  = -1;
261 static int hf_omron_unused_capacity = -1;
262 static int hf_omron_total_no_files  = -1;
263 static int hf_omron_no_files        = -1;
264 static int hf_omron_filename        = -1;
265 static int hf_omron_file_capacity   = -1;
266
267 static int hf_omron_file_position       = -1;
268 static int hf_omron_data_length         = -1;
269 static int hf_omron_file_data           = -1;
270 static int hf_omron_file_parameter_code = -1;
271
272 static int hf_omron_volume_parameter_code   = -1;
273 static int hf_omron_transfer_parameter_code = -1;
274
275 static int hf_omron_transfer_beginning_address = -1;
276 static int hf_omron_number_of_bytes            = -1;
277
278 static int hf_omron_number_of_bits_flags    = -1;
279 static int hf_omron_set_reset_specification = -1;
280 static int hf_omron_bit_flag                = -1;
281
282 static int hf_omron_data = -1;
283
284 static int hf_omron_beginning_block_num  = -1;
285 static int hf_omron_num_blocks           = -1;
286 static int hf_omron_num_blocks_remaining = -1;
287 static int hf_omron_total_num_blocks     = -1;
288 static int hf_omron_type                 = -1;
289 static int hf_omron_data_type            = -1;
290 static int hf_omron_data_type_type       = -1;
291 static int hf_omron_data_type_rv         = -1;
292 static int hf_omron_data_type_protected  = -1;
293 static int hf_omron_data_type_end        = -1;
294 static int hf_omron_control_data         = -1;
295
296 static int hf_omron_block_num       = -1;
297 static int hf_omron_num_unit_uint16 = -1;
298
299 static int hf_omron_fixed                           = -1;
300 static int hf_omron_intelligent_id_no               = -1;
301 static int hf_omron_first_word                      = -1;
302 static int hf_omron_read_len                        = -1;
303 static int hf_omron_no_of_link_nodes                = -1;
304 static int hf_omron_block_record_node_num_status    = -1;
305 static int hf_omron_block_record_node_num_num_nodes = -1;
306 static int hf_omron_block_record_cio_area           = -1;
307 static int hf_omron_block_record_kind_of_dm         = -1;
308 static int hf_omron_block_record_dm_area_first_word = -1;
309 static int hf_omron_block_record_no_of_total_words  = -1;
310
311 static int hf_omron_status_flags              = -1;
312 static int hf_omron_status_flags_slave_master = -1;
313 static int hf_omron_status_flags_data_link    = -1;
314 static int hf_omron_master_node_number        = -1;
315 static int hf_omron_status_node_0             = -1;
316 static int hf_omron_status_node_1             = -1;
317 static int hf_omron_status_node_2             = -1;
318 static int hf_omron_status_node_3             = -1;
319 static int hf_omron_status_node_4             = -1;
320 static int hf_omron_status_node_5             = -1;
321 static int hf_omron_status_node_6             = -1;
322 static int hf_omron_status_node_7             = -1;
323 static int hf_omron_status_1_node_0           = -1;
324 static int hf_omron_status_1_node_1           = -1;
325 static int hf_omron_status_1_node_2           = -1;
326 static int hf_omron_status_1_node_3           = -1;
327 static int hf_omron_status_1_node_4           = -1;
328 static int hf_omron_status_1_node_5           = -1;
329 static int hf_omron_status_1_node_6           = -1;
330 static int hf_omron_status_1_node_7           = -1;
331 static int hf_omron_status_2_node_0           = -1;
332 static int hf_omron_status_2_node_1           = -1;
333 static int hf_omron_status_2_node_2           = -1;
334 static int hf_omron_status_2_node_3           = -1;
335 static int hf_omron_status_2_node_4           = -1;
336 static int hf_omron_status_2_node_5           = -1;
337 static int hf_omron_status_2_node_6           = -1;
338 static int hf_omron_status_2_node_7           = -1;
339
340 static int hf_omron_name_data = -1;
341
342 static int hf_omron_num_receptions = -1;
343
344 static int hf_omron_netw_node_sts_low_0   = -1;
345 static int hf_omron_netw_node_sts_low_1   = -1;
346 static int hf_omron_netw_node_sts_low_2   = -1;
347 static int hf_omron_netw_node_sts_low_3   = -1;
348 static int hf_omron_netw_node_sts_high_0  = -1;
349 static int hf_omron_netw_node_sts_high_1  = -1;
350 static int hf_omron_netw_node_sts_high_2  = -1;
351 static int hf_omron_netw_node_sts_high_3  = -1;
352 static int hf_omron_com_cycle_time        = -1;
353 static int hf_omron_polling_unit_node_num = -1;
354 static int hf_omron_cyclic_operation      = -1;
355 static int hf_omron_cyclic_trans_status   = -1;
356
357 static int hf_omron_cyclic_label_1   = -1;
358 static int hf_omron_cyclic_7         = -1;
359 static int hf_omron_cyclic_6         = -1;
360 static int hf_omron_cyclic_5         = -1;
361 static int hf_omron_cyclic_4         = -1;
362 static int hf_omron_cyclic_3         = -1;
363 static int hf_omron_cyclic_2         = -1;
364 static int hf_omron_cyclic_1         = -1;
365 static int hf_omron_cyclic_label_2   = -1;
366 static int hf_omron_cyclic_15        = -1;
367 static int hf_omron_cyclic_14        = -1;
368 static int hf_omron_cyclic_13        = -1;
369 static int hf_omron_cyclic_12        = -1;
370 static int hf_omron_cyclic_11        = -1;
371 static int hf_omron_cyclic_10        = -1;
372 static int hf_omron_cyclic_9         = -1;
373 static int hf_omron_cyclic_8         = -1;
374 static int hf_omron_cyclic_label_3   = -1;
375 static int hf_omron_cyclic_23        = -1;
376 static int hf_omron_cyclic_22        = -1;
377 static int hf_omron_cyclic_21        = -1;
378 static int hf_omron_cyclic_20        = -1;
379 static int hf_omron_cyclic_19        = -1;
380 static int hf_omron_cyclic_18        = -1;
381 static int hf_omron_cyclic_17        = -1;
382 static int hf_omron_cyclic_16        = -1;
383 static int hf_omron_cyclic_label_4   = -1;
384 static int hf_omron_cyclic_31        = -1;
385 static int hf_omron_cyclic_30        = -1;
386 static int hf_omron_cyclic_29        = -1;
387 static int hf_omron_cyclic_28        = -1;
388 static int hf_omron_cyclic_27        = -1;
389 static int hf_omron_cyclic_26        = -1;
390 static int hf_omron_cyclic_25        = -1;
391 static int hf_omron_cyclic_24        = -1;
392 static int hf_omron_cyclic_label_5   = -1;
393 static int hf_omron_cyclic_39        = -1;
394 static int hf_omron_cyclic_38        = -1;
395 static int hf_omron_cyclic_37        = -1;
396 static int hf_omron_cyclic_36        = -1;
397 static int hf_omron_cyclic_35        = -1;
398 static int hf_omron_cyclic_34        = -1;
399 static int hf_omron_cyclic_33        = -1;
400 static int hf_omron_cyclic_32        = -1;
401 static int hf_omron_cyclic_label_6   = -1;
402 static int hf_omron_cyclic_47        = -1;
403 static int hf_omron_cyclic_46        = -1;
404 static int hf_omron_cyclic_45        = -1;
405 static int hf_omron_cyclic_44        = -1;
406 static int hf_omron_cyclic_43        = -1;
407 static int hf_omron_cyclic_42        = -1;
408 static int hf_omron_cyclic_41        = -1;
409 static int hf_omron_cyclic_40        = -1;
410 static int hf_omron_cyclic_label_7   = -1;
411 static int hf_omron_cyclic_55        = -1;
412 static int hf_omron_cyclic_54        = -1;
413 static int hf_omron_cyclic_53        = -1;
414 static int hf_omron_cyclic_52        = -1;
415 static int hf_omron_cyclic_51        = -1;
416 static int hf_omron_cyclic_50        = -1;
417 static int hf_omron_cyclic_49        = -1;
418 static int hf_omron_cyclic_48        = -1;
419 static int hf_omron_cyclic_label_8   = -1;
420 static int hf_omron_cyclic_62        = -1;
421 static int hf_omron_cyclic_61        = -1;
422 static int hf_omron_cyclic_60        = -1;
423 static int hf_omron_cyclic_59        = -1;
424 static int hf_omron_cyclic_58        = -1;
425 static int hf_omron_cyclic_57        = -1;
426 static int hf_omron_cyclic_56        = -1;
427 static int hf_omron_node_error_count = -1;
428
429
430
431 /* Defines */
432 #define ICF_GW_MASK  0x80
433 #define ICF_GW_DUSE  0x00
434 #define ICF_GW_USE   0x01
435
436 #define ICF_DTB_MASK 0x40
437 #define ICF_DTB_CMD  0x00
438 #define ICF_DTB_RESP 0x01
439
440 #define ICF_RB0_MASK 0x20
441 #define ICF_RB1_MASK 0x10
442 #define ICF_RB2_MASK 0x08
443 #define ICF_RB3_MASK 0x04
444 #define ICF_RB4_MASK 0x02
445
446 #define ICF_RSB_MASK 0x01
447 #define ICF_RSB_DUSE 0x00
448 #define ICF_RSB_USE  0x01
449
450 #define INT_DNA_MIN1 0x00
451 #define INT_DNA_MAX1 0x00
452 #define INT_DNA_MIN2 0x01
453 #define INT_DNA_MAX2 0x7F
454
455 #define INT_DA1_MIN1 0x00
456 #define INT_DA1_MAX1 0x3E
457 #define INT_DA1_MIN2 0x3F
458 #define INT_DA1_MAX2 0x7E
459 #define INT_DA1_MIN3 0xFF
460 #define INT_DA1_MAX3 0xFF
461
462 #define INT_DA2_MIN1 0x00
463 #define INT_DA2_MAX1 0x00
464 #define INT_DA2_MIN2 0xFE
465 #define INT_DA2_MAX2 0xFE
466 #define INT_DA2_MIN3 0x10
467 #define INT_DA2_MAX3 0x1F
468
469 #define INT_SNA_MIN1 0x00
470 #define INT_SNA_MAX1 0x00
471 #define INT_SNA_MIN2 0x01
472 #define INT_SNA_MAX2 0x7F
473
474 #define INT_SA1_MIN1 0x00
475 #define INT_SA1_MAX1 0x3E
476 #define INT_SA1_MIN2 0x3F
477 #define INT_SA1_MAX2 0x7E
478 #define INT_SA1_MIN3 0xFF
479 #define INT_SA1_MAX3 0xFF
480
481 #define INT_SA2_MIN1 0x00
482 #define INT_SA2_MAX1 0x00
483 #define INT_SA2_MIN2 0xFE
484 #define INT_SA2_MAX2 0xFE
485 #define INT_SA2_MIN3 0x10
486 #define INT_SA2_MAX3 0x1F
487
488
489 /* Constants used for display */
490 static const value_string icf_gw_vals[] = {
491     { ICF_GW_DUSE, "Don't use Gateway"   },
492     { ICF_GW_USE,  "Use Gateway"         },
493     { 0,           NULL                  } };
494
495 static const value_string icf_dtb_vals[] = {
496     { ICF_DTB_CMD,  "Command"   },
497     { ICF_DTB_RESP, "Response"  },
498     { 0,            NULL        } };
499
500 static const value_string icf_rsb_vals[] = {
501     { ICF_RSB_DUSE, "Response Required"     },
502     { ICF_RSB_USE,  "Response Not Required" },
503     { 0,            NULL                    } };
504
505 static const range_string omron_dna_range[] = {
506     { INT_DNA_MIN1, INT_DNA_MAX1,   "Local network"  },
507     { INT_DNA_MIN2, INT_DNA_MAX2,   "Remote network" },
508     { 0,            0,              NULL             } };
509
510 static const range_string omron_da1_range[] = {
511     { INT_DA1_MIN1, INT_DA1_MAX1,   "SYSMAC NET / LINK" },
512     { INT_DA1_MIN2, INT_DA1_MAX2,   "SYSMAC NET"        },
513     { INT_DA1_MIN3, INT_DA1_MAX3,   "Broadcast"         },
514     { 0,            0,              NULL                } };
515
516 static const range_string omron_da2_range[] = {
517     { INT_DA2_MIN1, INT_DA2_MAX1,   "PC (CPU)"                                     },
518     { INT_DA2_MIN2, INT_DA2_MAX2,   "SYSMAC NET or LINK Unit connected to network" },
519     { INT_DA2_MIN3, INT_DA2_MAX3,   "CPU BUS Unit"                                 },
520     { 0,            0,              NULL                                           } };
521
522 static const range_string omron_sna_range[] = {
523     { INT_SNA_MIN1, INT_SNA_MAX1,   "Local network"             },
524     { INT_SNA_MIN2, INT_SNA_MAX2,   "Remote network"            },
525     { 0,            0,              NULL                        } };
526
527 static const range_string omron_sa1_range[] = {
528     { INT_SA1_MIN1, INT_SA1_MAX1,   "SYSMAC NET / LINK" },
529     { INT_SA1_MIN2, INT_SA1_MAX2,   "SYSMAC NET"        },
530     { INT_SA1_MIN3, INT_SA1_MAX3,   "Broadcast"         },
531     { 0,            0,              NULL                } };
532
533 static const range_string omron_sa2_range[] = {
534     { INT_SA2_MIN1, INT_SA2_MAX1,   "PC (CPU)" },
535     { INT_SA2_MIN2, INT_SA2_MAX2,   "SYSMAC NET or LINK Unit connected to network" },
536     { INT_SA2_MIN3, INT_SA2_MAX3,   "CPU BUS Unit"                                 },
537     { 0,            0,              NULL                                           } };
538
539 static const range_string omron_error_reset_range[] = {
540     { 0xFFFE, 0xFFFE, "Present error cleared" },
541     { 0x0002, 0x0002, "Power interruption error" },
542     { 0x00A0, 0x00A7, "SYSMAC BUS error" },
543     { 0x00B0, 0x00B3, "SYSMAC BUS/2 error" },
544     { 0x00E7, 0x00E7, "I/O verification error" },
545     { 0x00F4, 0x00F4, "Non-fatal SFC error" },
546     { 0x00F7, 0x00F7, "Batter error" },
547     { 0x00F8, 0x00F8, "Indirect DM error" },
548     { 0x00F9, 0x00F9, "JMP error" },
549     { 0x0200, 0x0215, "CPU Bus Unit error" },
550     { 0x0400, 0x0415, "CPU Bus Unit setting error" },
551     { 0x4101, 0x42FF, "FALL (006) executed in user program" },
552     { 0xFFFF, 0xFFFF, "All errors cleared" },
553     { 0x809F, 0x809F, "Cycle time too long" },
554     { 0x80C0, 0x80C7, "I/O bus error" },
555     { 0x80E0, 0x80E0, "I/O setting error" },
556     { 0x80E1, 0x80E1, "I/O points overflow" },
557     { 0x80E9, 0x80E9, "Duplication error" },
558     { 0x80F0, 0x80F0, "Program error" },
559     { 0x80F1, 0x80F1, "Memory error" },
560     { 0x80F3, 0x80F3, "Fatal SFC error" },
561     { 0x80FF, 0x80FF, "System error" },
562     { 0x8100, 0x8115, "CPU bus error" },
563     { 0xC101, 0xC2FF, "FALS(007) executed" },
564     { 0,0, NULL }
565 };
566
567 static const value_string command_code_cv[] = {
568     { 0x0101, "Memory Area Read" },
569     { 0x0102, "Memory Area Write" },
570     { 0x0103, "Memory Area Fill" },
571     { 0x0104, "Multiple Memory Area Read" },
572     { 0x0105, "Memory Area Transfer" },
573     { 0x0201, "Parameter Area Read" },
574     { 0x0202, "Parameter Area Write" },
575     { 0x0203, "Parameter Area Clear" },
576     { 0x0220, "Data Link Table Read" },
577     { 0x0221, "Data Link Table Write" },
578     { 0x0304, "Program Area Protect" },
579     { 0x0305, "Program Area Protect Clear" },
580     { 0x0306, "Program Area Read" },
581     { 0x0307, "Program Area Write" },
582     { 0x0308, "Program Area Clear" },
583     { 0x0401, "Run" },
584     { 0x0402, "Stop" },
585     { 0x0403, "Reset" },
586     { 0x0501, "Controller Data Read" },
587     { 0x0502, "Connection Data Read" },
588     { 0x0601, "Controller Status Read" },
589     { 0x0602, "Network Status Read" },
590     { 0x0603, "Data Link Status Read" },
591     { 0x0620, "Cycle Time Read" },
592     { 0x0701, "Clock Read" },
593     { 0x0702, "Clock Write" },
594     { 0x0801, "LOOP-BACK Test" },
595     { 0x0802, "Broadcast Test Results Read" },
596     { 0x0803, "Broadcast Test Data Send" },
597     { 0x0920, "Message Read | Message Clear | FAL/FALS Read" },
598     { 0x0C01, "Access Right Acquire" },
599     { 0x0C02, "Access Right Forced Acquire" },
600     { 0x0C03, "Access Right Release" },
601     { 0x2101, "Error Clear" },
602     { 0x2102, "Error Log Read" },
603     { 0x2103, "Error Log Clear" },
604     { 0x2201, "File Name Read" },
605     { 0x2202, "Single File Read" },
606     { 0x2203, "Single File Write" },
607     { 0x2204, "Memory Card Format" },
608     { 0x2205, "File Delete" },
609     { 0x2206, "Volume Label Create/Delete" },
610     { 0x2207, "File Copy" },
611     { 0x2208, "File Name Change" },
612     { 0x2209, "File Data Check" },
613     { 0x220A, "Memory Area File Transfer" },
614     { 0x220B, "Parameter Area File Transfer" },
615     { 0x220C, "Program Area File Transfer" },
616     { 0x220F, "File Memory Index Read" },
617     { 0x2210, "File Memory Read" },
618     { 0x2211, "File Memory Write" },
619     { 0x2301, "Forced Set/Reset" },
620     { 0x2302, "Forced Set/Reset Cancel" },
621     { 0x230A, "Multiple Forced Status Read" },
622     { 0x2601, "Name Set" },
623     { 0x2602, "Name Delete" },
624     { 0x2603, "Name Read" },
625     { 0,    NULL                } };
626
627 static const value_string memory_area_code_cv[] = {
628     { 0x00, "CIO, TR, CPU Bus Link, and Auxiliary : Bit status" },
629     { 0x40, "CIO, TR, CPU Bus Link, and Auxiliary : Bit status (with forced status)" },
630     { 0x80, "CIO, TR, CPU Bus Link, and Auxiliary : Word contents" },
631     { 0xC0, "CIO, TR, CPU Bus Link, and Auxiliary : Word contents (with forced status)" },
632     { 0x01, "Timer/Counter : Completion Flag status" },
633     { 0x41, "Timer/Counter : Completion Flag status (with forced status)" },
634     { 0x81, "Timer/Counter : PV" },
635     { 0x82, "DM : Word contents" },
636     { 0x03, "Transition : Flag status" },
637     { 0x43, "Transition : Flag status (with forced status)" },
638     { 0x04, "Step : Flag status" },
639     { 0x44, "Step : Status" },
640     { 0x84, "Step : Step timer PV" },
641     { 0x05, "Forced status : Bit status" },
642     { 0x85, "Forced status : Word contents" },
643     { 0x90, "Expansion DM : Word contents, specified bank" },
644     { 0x91, "Expansion DM : Word contents, specified bank" },
645     { 0x92, "Expansion DM : Word contents, specified bank" },
646     { 0x93, "Expansion DM : Word contents, specified bank" },
647     { 0x94, "Expansion DM : Word contents, specified bank" },
648     { 0x95, "Expansion DM : Word contents, specified bank" },
649     { 0x96, "Expansion DM : Word contents, specified bank" },
650     { 0x97, "Expansion DM : Word contents, specified bank" },
651     { 0x98, "Expansion DM : Word contents, current bank" },
652     { 0x9C, "Register : Register contents / Current bank no. of expansion DM" },
653     { 0x1B, "Action : Flag status" },
654     { 0xDD, "Interrupt status : Scheduled interrupt interval" },
655     { 0,    NULL    } };
656
657 static const value_string response_codes[] = {
658     { 0x0000, "Normal completion" },
659     { 0x0001, "Service was interrupted" },
660     { 0x0101, "Local node not part of Network" },
661     { 0x0102, "Token time-out, node number to large" },
662     { 0x0103, "Number of transmit retries exceeded" },
663     { 0x0104, "Maximum number of frames exceeded" },
664     { 0x0105, "Node number setting error (range)" },
665     { 0x0106, "Node number duplication error" },
666     { 0x0201, "Destination node not part of Network" },
667     { 0x0202, "No node with the specified node number" },
668     { 0x0203, "Third node not part of Network : Broadcasting was specified" },
669     { 0x0204, "Busy error, destination node busy" },
670     { 0x0205, "Response time-out" },
671     { 0x0301, "Error occurred : ERC indicator is lit" },
672     { 0x0302, "CPU error occurred in the PC at the destination node" },
673     { 0x0303, "A controller error has prevented a normal response" },
674     { 0x0304, "Node number setting error" },
675     { 0x0401, "An undefined command has been used" },
676     { 0x0402, "Cannot process command because the specified unit model or version is wrong" },
677     { 0x0501, "Destination node number is not set in the routing table" },
678     { 0x0502, "Routing table isn't registered" },
679     { 0x0503, "Routing table error" },
680     { 0x0504, "Max relay nodes (2) was exceeded" },
681     { 0x1001, "The command is longer than the max permissible length" },
682     { 0x1002, "The command is shorter than the min permissible length" },
683     { 0x1003, "The designated number od data items differs from the actual number" },
684     { 0x1004, "An incorrect command format has been used" },
685     { 0x1005, "An incorrect header has been used" },
686     { 0x1101, "Memory area code invalid or DM is not available" },
687     { 0x1102, "Access size is wrong in command" },
688     { 0x1103, "First address in inaccessible area" },
689     { 0x1104, "The end of specified word range exceeds acceptable range" },
690     { 0x1106, "A non-existent program number" },
691     { 0x1109, "The size of data items in command block are wrong" },
692     { 0x110A, "The IOM break function cannot be executed" },
693     { 0x110B, "The response block is longer than the max length" },
694     { 0x110C, "An incorrect parameter code has been specified" },
695     { 0x2002, "The data is protected" },
696     { 0x2003, "Registered table does not exist" },
697     { 0x2004, "Search data does not exist" },
698     { 0x2005, "Non-existent program number" },
699     { 0x2006, "Non-existent file" },
700     { 0x2007, "Verification error" },
701     { 0x2101, "Specified area is read-only" },
702     { 0x2102, "The data is protected" },
703     { 0x2103, "Too many files open" },
704     { 0x2105, "Non-existent program number" },
705     { 0x2106, "Non-existent file" },
706     { 0x2107, "File already exists" },
707     { 0x2108, "Data cannot be changed" },
708     { 0x2201, "The mode is wrong (executing)" },
709     { 0x2202, "The mode is wrong (stopped)" },
710     { 0x2203, "The PC is in the PROGRAM mode" },
711     { 0x2204, "The PC is in the DEBUG mode" },
712     { 0x2205, "The PC is in the MONITOR mode" },
713     { 0x2206, "The PC is in the RUN mode" },
714     { 0x2207, "The specified node is not the control node" },
715     { 0x2208, "The mode is wrong and the step cannot be executed" },
716     { 0x2301, "The file device does not exist where specified" },
717     { 0x2302, "The specified memory does not exist" },
718     { 0x2303, "No clock exists" },
719     { 0x2401, "Data link table is incorrect" },
720     { 0x2502, "Parity / checksum error occurred" },
721     { 0x2503, "I/O setting error" },
722     { 0x2504, "Too many I/O points" },
723     { 0x2505, "CPU bus error" },
724     { 0x2506, "I/O duplication error" },
725     { 0x2507, "I/O bus error" },
726     { 0x2509, "SYSMAC BUS/2 error" },
727     { 0x250A, "Special I/O Unit error" },
728     { 0x250D, "Duplication in SYSMAC BUS word allocation" },
729     { 0x250F, "A memmory error has occurred" },
730     { 0x2510, "Terminator not connected in SYSMAC BUS system" },
731     { 0x2601, "The specified area is not protected" },
732     { 0x2602, "An incorrect password has been specified" },
733     { 0x2604, "The specified area is protected" },
734     { 0x2605, "The service is being executed" },
735     { 0x2606, "The service is not being executed" },
736     { 0x2607, "Service cannot be execute from local node" },
737     { 0x2608, "Service cannot be executed settings are incorrect" },
738     { 0x2609, "Service cannot be executed incorrect settings in command data" },
739     { 0x260A, "The specified action has already been registered" },
740     { 0x260B, "Cannot clear error, error still exists" },
741     { 0x3001, "The access right is held by another device" },
742     { 0x4001, "Command aborted with ABORT command" },
743     { 0,    NULL    } };
744
745 static const value_string parameter_area_codes[] = {
746     { 0x8010, "PC Setup" },
747     { 0x8011, "Peripheral Device settings" },
748     { 0x8012, "I/O table" },
749     { 0x8013, "Routing tables" },
750     { 0x8002, "CPU Bus Unit settings" },
751     { 0,      NULL } };
752
753 static const value_string mode_codes[] = {
754     { 0x00, "PROGRAM mode" },
755     { 0x01, "DEBUG mode" },
756     { 0x02, "MONITOR mode" },
757     { 0x04, "RUN mode" },
758     { 0,    NULL } };
759
760 static const value_string status_codes[] = {
761     { 0x00, "Stop" },
762     { 0x01, "Run" },
763     { 0x80, "CPU on standby" },
764     { 0,    NULL    } };
765
766 static const value_string memory_card_codes[] = {
767     { 0x00, "No memory card" },
768     { 0x01, "SPRAM" },
769     { 0x02, "EPROM" },
770     { 0x03, "EEPROM" },
771     { 0,    NULL } };
772
773 static const value_string parameter_codes[] = {
774     { 0x00, "Initializes the cycle time." },
775     { 0x01, "Read the cycle time" },
776     { 0,    NULL } };
777
778 static const value_string omron_days[] = {
779     { 0x00, "Sun"  },
780     { 0x01, "Mon"  },
781     { 0x02, "Tues" },
782     { 0x03, "Wed"  },
783     { 0x04, "Thur" },
784     { 0x05, "Fri"  },
785     { 0x06, "Sat"  },
786     { 0,    NULL   } };
787
788 static const value_string omron_file_parameter_codes[] = {
789     { 0x0000, "Write new file, do not overwrite" },
790     { 0x0001, "Write new file, overwrite" },
791     { 0x0002, "Appened to file " },
792     { 0x0003, "Overwite file" },
793     { 0,      NULL  } };
794
795 static const value_string omron_volume_parameter_codes[] = {
796     { 0x0000, "Create new volume label, do not overwrite" },
797     { 0x0001, "Create new volume label, overwrite" },
798     { 0x0002, "Delete existing volume label" },
799     { 0,    NULL } };
800
801 static const value_string omron_transfer_parameter_codes[] = {
802     { 0x0000, "Data transfer from the PC memory area to the file device" },
803     { 0x0001, "Data transfer from the file device to the PC emory area" },
804     { 0x0002, "Data compared" },
805     { 0,         NULL } };
806
807 static const value_string omron_set_reset_specifications[] = {
808     { 0x0000, "Force-reset (OFF)" },
809     { 0x0001, "Force-set (ON)" },
810     { 0x8000, "Forced status released and bit turned OFF (0)" },
811     { 0x8001, "Forced status released and bit turned ON (1)" },
812     { 0xFFFF, "Forced status released" },
813     { 0,    NULL } };
814
815 static const value_string omron_type_codes[] = {
816     { 0x00, "RAM" },
817     { 0x01, "First half RAM; second half ROM" },
818     { 0,    NULL } };
819
820 static const value_string omron_data_type_bits[] = {
821     { 0x00, "Empty" },
822     { 0x01, "I/O data" },
823     { 0x02, "User program" },
824     { 0x03, "Comments" },
825     { 0,    NULL } };
826
827 static const value_string omron_cyclic_ops_codes[] = {
828     { 0x00, "Stopped" },
829     { 0x01, "Active" },
830     { 0,    NULL } };
831
832 static const value_string omron_cyclic_trans_codes[] = {
833     { 0x00, "No transmission" },
834     { 0x01, "Transmission" },
835     { 0,    NULL } };
836
837 static const int *omron_icf_fields[] = {
838     &hf_omron_icf_gwb,
839     &hf_omron_icf_dtb,
840     &hf_omron_icf_rb0,
841     &hf_omron_icf_rb1,
842     &hf_omron_icf_rb2,
843     &hf_omron_icf_rb3,
844     &hf_omron_icf_rb4,
845     &hf_omron_icf_rsb,
846     NULL
847 };
848
849 static const int *pc_status_fields[] = {
850     &hf_omron_pc_status_pdc,
851     &hf_omron_pc_status_hi,
852     &hf_omron_pc_status_r1,
853     &hf_omron_pc_status_r2,
854     &hf_omron_pc_status_rack_num,
855     NULL
856 };
857
858 static const int *fatal_error_fields[] = {
859     &hf_omron_fatal_fals_error,
860     &hf_omron_fatal_sfc_error,
861     &hf_omron_fatal_cycle_time_over,
862     &hf_omron_fatal_program_error,
863     &hf_omron_fatal_io_setting_error,
864     &hf_omron_fatal_io_point_overflow,
865     &hf_omron_fatal_cpu_bus_error,
866     &hf_omron_fatal_duplication_error,
867     &hf_omron_fatal_io_bus_error,
868     &hf_omron_fatal_memory_error,
869     &hf_omron_fatal_rv_1,
870     &hf_omron_fatal_rv_2,
871     &hf_omron_fatal_rv_3,
872     &hf_omron_fatal_rv_4,
873     &hf_omron_fatal_rv_5,
874     &hf_omron_fatal_watch_dog_timer_error,
875     NULL
876 };
877
878 static const int *non_fatal_error_fields[] = {
879     &hf_omron_non_fatal_rv1,
880     &hf_omron_non_fatal_rv2,
881     &hf_omron_non_fatal_power_interruption,
882     &hf_omron_non_fatal_cpu_bus_unit_setting_error,
883     &hf_omron_non_fatal_battery_error,
884     &hf_omron_non_fatal_sysmac_bus_error,
885     &hf_omron_non_fatal_sysmac_bus2_error,
886     &hf_omron_non_fatal_cpu_bus_unit_error,
887     &hf_omron_non_fatal_rv3,
888     &hf_omron_non_fatal_io_verification_error,
889     &hf_omron_non_fatal_rv4,
890     &hf_omron_non_fatal_sfc_error,
891     &hf_omron_non_fatal_indirect_dm_error,
892     &hf_omron_non_fatal_jmp_error,
893     &hf_omron_non_fatal_rv5,
894     &hf_omron_non_fatal_fal_error,
895     NULL
896 };
897
898 static const int *message_fields[] = {
899     &hf_omron_message_no_0,
900     &hf_omron_message_no_1,
901     &hf_omron_message_no_2,
902     &hf_omron_message_no_3,
903     &hf_omron_message_no_4,
904     &hf_omron_message_no_5,
905     &hf_omron_message_no_6,
906     &hf_omron_message_no_7,
907     &hf_omron_message_rv_0,
908     &hf_omron_message_rv_1,
909     &hf_omron_message_rv_2,
910     &hf_omron_message_rv_3,
911     &hf_omron_message_rv_4,
912     &hf_omron_message_rv_5,
913     &hf_omron_message_rv_6,
914     &hf_omron_message_rv_7,
915     NULL
916 };
917
918 static const int *message_yes_no_fields[] = {
919     &hf_omron_message_rv_1,
920     &hf_omron_message_rv_2,
921     &hf_omron_message_rv_3,
922     &hf_omron_message_rv_4,
923     &hf_omron_message_rv_5,
924     &hf_omron_message_rv_6,
925     &hf_omron_message_rv_7,
926     NULL
927 };
928
929 static const int *data_type_fields[] = {
930     &hf_omron_data_type_type,
931     &hf_omron_data_type_rv,
932     &hf_omron_data_type_protected,
933     &hf_omron_data_type_end,
934     NULL
935 };
936
937 static const int *cyclic_non_fatal_1_fields[] = {
938     &hf_omron_cyclic_1,
939     &hf_omron_cyclic_2,
940     &hf_omron_cyclic_3,
941     &hf_omron_cyclic_4,
942     &hf_omron_cyclic_5,
943     &hf_omron_cyclic_6,
944     &hf_omron_cyclic_7,
945     NULL
946 };
947
948 static const int *cyclic_non_fatal_2_fields[] = {
949     &hf_omron_cyclic_8,
950     &hf_omron_cyclic_9,
951     &hf_omron_cyclic_10,
952     &hf_omron_cyclic_11,
953     &hf_omron_cyclic_12,
954     &hf_omron_cyclic_13,
955     &hf_omron_cyclic_14,
956     &hf_omron_cyclic_15,
957     NULL
958 };
959
960 static const int *cyclic_non_fatal_3_fields[] = {
961     &hf_omron_cyclic_16,
962     &hf_omron_cyclic_17,
963     &hf_omron_cyclic_18,
964     &hf_omron_cyclic_19,
965     &hf_omron_cyclic_20,
966     &hf_omron_cyclic_21,
967     &hf_omron_cyclic_22,
968     &hf_omron_cyclic_23,
969     NULL
970 };
971
972 static const int *cyclic_non_fatal_4_fields[] = {
973     &hf_omron_cyclic_24,
974     &hf_omron_cyclic_25,
975     &hf_omron_cyclic_26,
976     &hf_omron_cyclic_27,
977     &hf_omron_cyclic_28,
978     &hf_omron_cyclic_29,
979     &hf_omron_cyclic_30,
980     &hf_omron_cyclic_31,
981     NULL
982 };
983
984 static const int *cyclic_non_fatal_5_fields[] = {
985     &hf_omron_cyclic_32,
986     &hf_omron_cyclic_33,
987     &hf_omron_cyclic_34,
988     &hf_omron_cyclic_35,
989     &hf_omron_cyclic_36,
990     &hf_omron_cyclic_37,
991     &hf_omron_cyclic_38,
992     &hf_omron_cyclic_39,
993     NULL
994 };
995
996 static const int *cyclic_non_fatal_6_fields[] = {
997     &hf_omron_cyclic_40,
998     &hf_omron_cyclic_41,
999     &hf_omron_cyclic_42,
1000     &hf_omron_cyclic_43,
1001     &hf_omron_cyclic_44,
1002     &hf_omron_cyclic_45,
1003     &hf_omron_cyclic_46,
1004     &hf_omron_cyclic_47,
1005     NULL
1006 };
1007
1008 static const int *cyclic_non_fatal_7_fields[] = {
1009     &hf_omron_cyclic_48,
1010     &hf_omron_cyclic_49,
1011     &hf_omron_cyclic_50,
1012     &hf_omron_cyclic_51,
1013     &hf_omron_cyclic_52,
1014     &hf_omron_cyclic_53,
1015     &hf_omron_cyclic_54,
1016     &hf_omron_cyclic_55,
1017     NULL
1018 };
1019
1020 static const int *cyclic_non_fatal_8_fields[] = {
1021     &hf_omron_cyclic_56,
1022     &hf_omron_cyclic_57,
1023     &hf_omron_cyclic_58,
1024     &hf_omron_cyclic_59,
1025     &hf_omron_cyclic_60,
1026     &hf_omron_cyclic_61,
1027     &hf_omron_cyclic_62,
1028     NULL
1029 };
1030
1031 static const true_false_string boolean_data_type_protected = {
1032     "Protected",
1033     "Not Protected"
1034 };
1035
1036 static const true_false_string boolean_data_type_end = {
1037     "Last Block",
1038     "Not Last Block"
1039 };
1040
1041 static const true_false_string boolean_node_num_status = {
1042     "Normal",
1043     "Warning"
1044 };
1045
1046 static const true_false_string boolean_status_flag_status = {
1047     "Error",
1048     "Normal"
1049 };
1050
1051 static const true_false_string boolean_status_flags_slave_master = {
1052     "Master",
1053     "Slave"
1054 };
1055
1056 static const true_false_string boolean_status_flags_data_link = {
1057     "Active",
1058     "Not Active"
1059 };
1060
1061 static const true_false_string boolean_status_block_stop_run = {
1062     "Run",
1063     "Stop"
1064 };
1065
1066 static const true_false_string boolean_status_flag_status_2 = {
1067     "Warning",
1068     "Normal"
1069 };
1070
1071 static const true_false_string boolean_member_network = {
1072     "In network",
1073     "Not in network"
1074 };
1075
1076 static const true_false_string boolean_member_polling = {
1077     "Unit does not respond to polling",
1078     "Unit responds to polling"
1079 };
1080
1081
1082 /* CODE */
1083
1084 static int
1085 dissect_omron_fins(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1086 {
1087     proto_item  *ti = NULL;
1088     proto_tree  *omron_tree = NULL;
1089     proto_tree  *omron_header_tree, *field_tree, *command_tree, *area_data_tree, *cpu_bus_tree;
1090     proto_tree  *io_data_tree, *error_log_tree, *omron_disk_data_tree, *omron_file_data_tree;
1091     proto_tree  *omron_block_record_tree, *omron_status_tree;
1092     const gchar *cmd_str;
1093     gint     cmd_str_idx;
1094     gint     reported_length_remaining;
1095     int      offset = 0;
1096     guint8   icf_flags;
1097     guint8   omron_byte;
1098     gboolean is_response = FALSE;
1099     gboolean is_command  = FALSE;
1100     guint16  command_code;
1101
1102     /* Make sure we have enough actual data to do the heuristics checks */
1103     if(tvb_length(tvb) < 12 ) {
1104         return 0;
1105     }
1106     /* Check some bytes to see if it's OMRON */
1107     omron_byte = tvb_get_guint8(tvb, 1);
1108     if(omron_byte != 0x00) {
1109         return 0;
1110     }
1111     omron_byte = tvb_get_guint8(tvb, 2);
1112     if(omron_byte != 0x02) {
1113         return 0;
1114     }
1115     /* get the command code: we need it later */
1116     command_code = tvb_get_ntohs(tvb,10);
1117
1118     /* Set the protocol column */
1119     col_set_str(pinfo->cinfo, COL_PROTOCOL, "OMRON");
1120
1121
1122     cmd_str = match_strval_idx(command_code, command_code_cv, &cmd_str_idx);
1123     if (cmd_str_idx == -1)
1124         cmd_str = ep_strdup_printf("Unknown (%d)", command_code);
1125
1126     /* Setup and fill in the INFO column if it's there */
1127     icf_flags = tvb_get_guint8(tvb, offset);
1128     if (icf_flags & 0x40) {
1129         is_response = TRUE;
1130         if (check_col(pinfo->cinfo, COL_INFO)) {
1131             col_add_fstr(pinfo->cinfo, COL_INFO, "Response : %s", cmd_str);
1132         }
1133     }
1134     else
1135     {
1136         is_command = TRUE;
1137         if (check_col(pinfo->cinfo, COL_INFO)) {
1138             col_add_fstr(pinfo->cinfo, COL_INFO, "Command  : %s", cmd_str);
1139         }
1140     }
1141
1142     if (tree) { /* we are being asked for details */
1143         ti = proto_tree_add_item(tree, proto_omron_fins, tvb, 0, -1, FALSE);
1144         omron_tree = proto_item_add_subtree(ti, ett_omron);
1145
1146         ti = proto_tree_add_text(omron_tree, tvb, 0, 12, "Omron Header");
1147         omron_header_tree = proto_item_add_subtree(ti, ett_omron_header);
1148
1149         proto_tree_add_bitmask(omron_header_tree, tvb, offset, hf_omron_icf,
1150                                ett_omron_icf_fields, omron_icf_fields, FALSE);
1151
1152         /* Byte 2 RSV */
1153         offset = offset + 1;
1154         proto_tree_add_item(omron_header_tree, hf_omron_rsv, tvb, offset, 1, FALSE);
1155
1156         /* Byte 3 GCT */
1157         offset = offset + 1;
1158         proto_tree_add_item(omron_header_tree, hf_omron_gct, tvb, offset, 1, FALSE);
1159
1160         /* Byte 4 DNA */
1161         offset = offset + 1;
1162         proto_tree_add_item(omron_header_tree, hf_omron_dna, tvb, offset, 1, FALSE);
1163
1164         /* Byte 5 DA1 */
1165         offset = offset + 1;
1166         proto_tree_add_item(omron_header_tree, hf_omron_da1, tvb, offset, 1, FALSE);
1167
1168         /* Byte 6 DA2 */
1169         offset = offset + 1;
1170         proto_tree_add_item(omron_header_tree, hf_omron_da2, tvb, offset, 1, FALSE);
1171
1172         /* Byte 7 SNA */
1173         offset = offset + 1;
1174         proto_tree_add_item(omron_header_tree, hf_omron_sna, tvb, offset, 1, FALSE);
1175
1176         /* Byte 8 SA1 */
1177         offset = offset + 1;
1178         proto_tree_add_item(omron_header_tree, hf_omron_sa1, tvb, offset, 1, FALSE);
1179
1180         /* Byte 9 SA2 */
1181         offset = offset + 1;
1182         proto_tree_add_item(omron_header_tree, hf_omron_sa2, tvb, offset, 1, FALSE);
1183
1184         /* Byte 10 SID */
1185         offset = offset + 1;
1186         proto_tree_add_item(omron_header_tree, hf_omron_sid, tvb, offset, 1, FALSE);
1187
1188         /* Byte 11 and 12 Command Code */
1189         offset = offset + 1;
1190         ti = proto_tree_add_item(omron_header_tree, hf_omron_command, tvb, offset, 2, FALSE);
1191
1192         offset = offset + 2;
1193
1194         reported_length_remaining = tvb_reported_length_remaining(tvb, offset);
1195
1196         if (cmd_str_idx == -1) {
1197             /* Unknown command-code */
1198             expert_add_info_format(pinfo, ti, PI_UNDECODED, PI_WARN, "Unknown Command-Code");
1199             return tvb_length(tvb);
1200         }
1201
1202         /* Handle  special cases wherein the data length for a command and/or a response can be 0 */
1203         switch(command_code) {
1204         case 0x0402:
1205         case 0x0601:
1206         case 0x0602:
1207         case 0x0603:
1208         case 0x0701:
1209         case 0x0802:
1210         case 0x2103:
1211         case 0x2302:
1212         case 0x2602:
1213         case 0x2603:
1214             /* command data length > 0 is NG;  response data lengths are > 0  */
1215             if (is_command) {
1216                 if (reported_length_remaining != 0) {
1217                     expert_add_info_format(pinfo, omron_tree, PI_MALFORMED, PI_WARN, "Unexpected Length (Should be 0)");
1218                 }
1219                 return tvb_length(tvb);
1220             }
1221             break;
1222
1223         case 0x0403:
1224             /* command data length should be 0 */
1225             if (is_command) {
1226                 if(reported_length_remaining != 0) {
1227                     expert_add_info_format(pinfo, omron_tree, PI_MALFORMED, PI_WARN, "Unexpected Length (Should be 0)");
1228                 }
1229             }
1230             /* There's no response */
1231             if (is_response)
1232             {
1233                 expert_add_info_format(pinfo, ti, PI_UNDECODED, PI_WARN, "Unknown Response Command-Code");
1234             }
1235             return tvb_length(tvb);
1236             break;
1237
1238         case 0x0801:
1239             /* command data length = 0 or > 0 is OK;  */
1240             if (is_command) {
1241                 if (reported_length_remaining == 0)
1242                     return tvb_length(tvb);
1243             }
1244             break;
1245
1246         case 0x0803:
1247             /* command data length = 0 or > 0 is OK;  */
1248             if (is_command) {
1249                 if (reported_length_remaining == 0)
1250                     return tvb_length(tvb);
1251             }
1252             /* There's no response */
1253             if (is_response)
1254             {
1255                 expert_add_info_format(pinfo, ti, PI_UNDECODED, PI_WARN, "Unknown Response Command-Code");
1256                 return tvb_length(tvb);
1257             }
1258             break;
1259
1260         default:
1261             break;
1262         }
1263
1264         /* Add command data tree */
1265         /* Note: A "malformed" will be thrown if data length = 0 at this point */
1266         ti = proto_tree_add_text(omron_tree, tvb, offset, -1, "Command Data");
1267         command_tree = proto_item_add_subtree(ti, ett_omron_command_data);
1268
1269         /* Start parsing individual commands */
1270         switch(command_code) {
1271
1272         case 0x0101:
1273         {
1274             /* check for enough data */
1275             if(is_command)
1276             {
1277                 if(reported_length_remaining == 6)
1278                 {
1279                     proto_tree_add_item(command_tree, hf_omron_command_memory_area_code,
1280                                         tvb, offset, 1, FALSE);
1281
1282                     proto_tree_add_item(command_tree, hf_omron_address, tvb, (offset+1), 2, FALSE);
1283                     proto_tree_add_item(command_tree, hf_omron_address_bits, tvb, (offset+3), 1, FALSE);
1284                     proto_tree_add_item(command_tree, hf_omron_num_items, tvb, (offset+4), 2, FALSE);
1285                     offset = offset + 6;
1286                 }
1287             }
1288
1289             if(is_response)
1290             {
1291                 if(reported_length_remaining >= 2)
1292                 {
1293                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset,
1294                                         2, FALSE);
1295
1296                     if(reported_length_remaining > 2)
1297                     {
1298                         proto_tree_add_item(command_tree, hf_omron_response_data, tvb,
1299                                             (offset+2), -1, FALSE);
1300                     }
1301                     offset = offset + reported_length_remaining;
1302                 }
1303             }
1304         }
1305         break;
1306
1307         case 0x0102:
1308         {
1309             if(is_command)
1310             {
1311                 if(reported_length_remaining >= 6)
1312                 {
1313                     proto_tree_add_item(command_tree, hf_omron_command_memory_area_code,
1314                         tvb, offset, 1, FALSE);
1315
1316                     proto_tree_add_item(command_tree, hf_omron_address, tvb, (offset+1), 2, FALSE);
1317                     proto_tree_add_item(command_tree, hf_omron_address_bits, tvb, (offset+3), 1, FALSE);
1318                     proto_tree_add_item(command_tree, hf_omron_num_items, tvb, (offset+4), 2, FALSE);
1319
1320                     proto_tree_add_item(command_tree, hf_omron_command_data, tvb, (offset+6), -1, FALSE);
1321                     offset = offset + reported_length_remaining;
1322                 }
1323             }
1324
1325             if(is_response)
1326             {
1327                 if(reported_length_remaining == 2)
1328                 {
1329                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset,
1330                         2, FALSE);
1331                     offset = offset + 2;
1332                 }
1333             }
1334         }
1335         break;
1336
1337         case 0x0103:
1338         {
1339             if(is_command)
1340             {
1341                 if(reported_length_remaining == 8)
1342                 {
1343                     proto_tree_add_item(command_tree, hf_omron_command_memory_area_code,
1344                         tvb, offset, 1, FALSE);
1345
1346                     proto_tree_add_item(command_tree, hf_omron_address, tvb, (offset+1), 2, FALSE);
1347                     proto_tree_add_item(command_tree, hf_omron_address_bits, tvb, (offset+3), 1, FALSE);
1348                     proto_tree_add_item(command_tree, hf_omron_num_items, tvb, (offset+4), 2, FALSE);
1349
1350                     proto_tree_add_item(command_tree, hf_omron_command_data, tvb, (offset+6), 2, FALSE);
1351                     offset = offset + 8;
1352                 }
1353             }
1354
1355             if(is_response)
1356             {
1357                 if(reported_length_remaining == 2)
1358                 {
1359                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset,
1360                         2, FALSE);
1361                     offset = offset + 2;
1362                 }
1363             }
1364         }
1365         break;
1366
1367         case 0x0104:
1368         {
1369             if(is_command)
1370             {
1371                 while(reported_length_remaining >= 4)
1372                 {
1373                     proto_tree_add_item(command_tree, hf_omron_command_memory_area_code, tvb, offset, 1, FALSE);
1374                     proto_tree_add_item(command_tree, hf_omron_transfer_beginning_address, tvb, (offset+1), 3, FALSE);
1375                     offset = offset + 4;
1376                     reported_length_remaining = reported_length_remaining - 4;
1377                 }
1378             }
1379
1380             if(is_response)
1381             {
1382                 if(reported_length_remaining >= 3)
1383                 {
1384                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1385                     offset = offset + 2;
1386                     reported_length_remaining = reported_length_remaining - 2;
1387
1388                     while(reported_length_remaining >= 2)
1389                     {
1390                         guint8 memory_area_code;
1391                         guint8 memory_code_len;
1392
1393                         ti = proto_tree_add_item(command_tree, hf_omron_command_memory_area_code, tvb, offset, 1, FALSE);
1394                         memory_area_code  = tvb_get_guint8(tvb, offset);
1395                         switch(memory_area_code) {
1396                             case 0x00:
1397                                 memory_code_len = 1;
1398                                 break;
1399                             case 0x40:
1400                                 memory_code_len = 1;
1401                                 break;
1402                             case 0x80:
1403                                 memory_code_len = 2;
1404                                 break;
1405                             case 0xC0:
1406                                 memory_code_len = 4;
1407                                 break;
1408                             case 0x01:
1409                                 memory_code_len = 1;
1410                                 break;
1411                             case 0x41:
1412                                 memory_code_len = 1;
1413                                 break;
1414                             case 0x81:
1415                                 memory_code_len = 2;
1416                                 break;
1417                             case 0x82:
1418                                 memory_code_len = 2;
1419                                 break;
1420                             case 0x03:
1421                                 memory_code_len = 1;
1422                                 break;
1423                             case 0x43:
1424                                 memory_code_len = 1;
1425                                 break;
1426                             case 0x04:
1427                                 memory_code_len = 1;
1428                                 break;
1429                             case 0x44:
1430                                 memory_code_len = 1;
1431                                 break;
1432                             case 0x84:
1433                                 memory_code_len = 2;
1434                                 break;
1435                             case 0x05:
1436                                 memory_code_len = 1;
1437                                 break;
1438                             case 0x85:
1439                                 memory_code_len = 2;
1440                                 break;
1441                             case 0x90:
1442                                 memory_code_len = 2;
1443                                 break;
1444                             case 0x91:
1445                                 memory_code_len = 2;
1446                                 break;
1447                             case 0x92:
1448                                 memory_code_len = 2;
1449                                 break;
1450                             case 0x93:
1451                                 memory_code_len = 2;
1452                                 break;
1453                             case 0x94:
1454                                 memory_code_len = 2;
1455                                 break;
1456                             case 0x95:
1457                                 memory_code_len = 2;
1458                                 break;
1459                             case 0x96:
1460                                 memory_code_len = 2;
1461                                 break;
1462                             case 0x97:
1463                                 memory_code_len = 2;
1464                                 break;
1465                             case 0x98:
1466                                 memory_code_len = 2;
1467                                 break;
1468                             case 0x1B:
1469                                 memory_code_len = 1;
1470                                 break;
1471                             case 0x9C:
1472                                 memory_code_len = 2;
1473                                 break;
1474                             case 0xDD:
1475                                 memory_code_len = 4;
1476                                 break;
1477                             default:
1478                                 memory_code_len = 0;
1479                         } /* switch */
1480
1481                         offset = offset + 1;
1482                         reported_length_remaining = reported_length_remaining - 1;
1483
1484                         if(memory_code_len == 0) {
1485                             expert_add_info_format(pinfo, ti, PI_UNDECODED, PI_WARN,
1486                                                    "Unknown Memory-Area-Code (%u)", memory_area_code);
1487                             return tvb_length(tvb); /* Bail out .... */
1488                         }
1489                         proto_tree_add_item(command_tree, hf_omron_data, tvb, offset, memory_code_len, FALSE);
1490                         offset = offset + memory_code_len;
1491                         reported_length_remaining = reported_length_remaining - memory_code_len;
1492
1493                     } /* while ( ... >= 2) */
1494                 } /* if(reported_length_remaining >= 3) */
1495             }
1496         }
1497         break;
1498
1499         case 0x0105:
1500         {
1501             if(is_command)
1502             {
1503                 if(reported_length_remaining == 10)
1504                 {
1505                     proto_tree_add_item(command_tree, hf_omron_command_memory_area_code,
1506                         tvb, offset, 1, FALSE);
1507                     proto_tree_add_item(command_tree, hf_omron_address, tvb, (offset+1), 2, FALSE);
1508                     proto_tree_add_item(command_tree, hf_omron_address_bits, tvb, (offset+3), 1, FALSE);
1509
1510                     proto_tree_add_item(command_tree, hf_omron_command_memory_area_code,
1511                         tvb, (offset+4), 1, FALSE);
1512                     proto_tree_add_item(command_tree, hf_omron_address, tvb, (offset+5), 2, FALSE);
1513                     proto_tree_add_item(command_tree, hf_omron_address_bits, tvb, (offset+7), 1, FALSE);
1514
1515                     proto_tree_add_item(command_tree, hf_omron_num_items, tvb, (offset+8), 2, FALSE);
1516                     offset = offset + 10;
1517                 }
1518             }
1519
1520             if(is_response)
1521             {
1522                 if(reported_length_remaining == 2)
1523                 {
1524                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset,
1525                                         2, FALSE);
1526                     offset = offset + 2;
1527                 }
1528             }
1529         }
1530         break;
1531
1532         case 0x0201:
1533         {
1534
1535             if(is_command)
1536             {
1537                 if(reported_length_remaining == 6)
1538                 {
1539                     proto_tree_add_item(command_tree, hf_omron_parameter_area_code, tvb, offset, 2, FALSE);
1540                     proto_tree_add_item(command_tree, hf_omron_beginning_word, tvb, (offset+2), 2, FALSE);
1541                     proto_tree_add_item(command_tree, hf_omron_num_words, tvb, (offset+4), 2, FALSE);
1542                     offset = offset + 6;
1543                 }
1544             }
1545
1546             if(is_response)
1547             {
1548                 if(reported_length_remaining >= 8)
1549                 {
1550                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset,
1551                         2, FALSE);
1552                     proto_tree_add_item(command_tree, hf_omron_parameter_area_code, tvb, (offset+2), 2, FALSE);
1553                     proto_tree_add_item(command_tree, hf_omron_beginning_word, tvb, (offset+4), 2, FALSE);
1554                     proto_tree_add_item(command_tree, hf_omron_num_words, tvb, (offset+6), 2, FALSE);
1555
1556                     if(reported_length_remaining > 8)
1557                     {
1558                         proto_tree_add_item(command_tree, hf_omron_response_data, tvb,
1559                               (offset+8), -1, FALSE);
1560                     }
1561                     offset = offset + reported_length_remaining;
1562                 }
1563             }
1564         }
1565         break;
1566
1567         case 0x0202:
1568         case 0x0203:
1569         {
1570
1571             if(is_command)
1572             {
1573                 if(reported_length_remaining >= 6)
1574                 {
1575                     proto_tree_add_item(command_tree, hf_omron_parameter_area_code, tvb, offset, 2, FALSE);
1576                     proto_tree_add_item(command_tree, hf_omron_beginning_word, tvb, (offset+2), 2, FALSE);
1577                     proto_tree_add_item(command_tree, hf_omron_num_words, tvb, (offset+4), 2, FALSE);
1578
1579                     if(reported_length_remaining > 6)
1580                     {
1581                         proto_tree_add_item(command_tree, hf_omron_command_data, tvb,
1582                               (offset+6), -1, FALSE);
1583                     }
1584                     offset = offset + reported_length_remaining;
1585                 }
1586             }
1587
1588             if(is_response)
1589             {
1590                 if(reported_length_remaining == 2)
1591                 {
1592                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset,
1593                         2, FALSE);
1594                     offset = offset + 2;
1595                 }
1596             }
1597         }
1598         break;
1599
1600         case 0x0220:
1601         {
1602             if(is_command)
1603             {
1604                 if(reported_length_remaining == 8)
1605                 {
1606                     proto_tree_add_item(command_tree, hf_omron_fixed, tvb, offset, 2, FALSE);
1607                     proto_tree_add_item(command_tree, hf_omron_intelligent_id_no, tvb, (offset+2), 2, FALSE);
1608                     proto_tree_add_item(command_tree, hf_omron_first_word, tvb, (offset+4), 2, FALSE);
1609                     proto_tree_add_item(command_tree, hf_omron_read_len, tvb, (offset+6), 2, FALSE);
1610                     offset = offset + 8;
1611                 }
1612             }
1613
1614             if(is_response)
1615             {
1616                 if(reported_length_remaining >= 3)
1617                 {
1618                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1619                     proto_tree_add_item(command_tree, hf_omron_no_of_link_nodes, tvb, (offset+2), 1, FALSE);
1620
1621                     offset = offset + 3;
1622                     reported_length_remaining = reported_length_remaining - 3;
1623
1624                     /* add block record tree for each record */
1625                     while(reported_length_remaining >= 8)
1626                     {
1627                         ti = proto_tree_add_text(command_tree, tvb, offset, 8, "Block Record");
1628                         omron_block_record_tree = proto_item_add_subtree(ti, ett_omron_block_record);
1629                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_node_num_status, tvb, offset, 1, FALSE);
1630                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_node_num_num_nodes, tvb, offset, 1, FALSE);
1631                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_cio_area, tvb, (offset+1), 2, FALSE);
1632                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_kind_of_dm, tvb, (offset+3), 1, FALSE);
1633                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_dm_area_first_word, tvb, (offset+4), 2, FALSE);
1634                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_no_of_total_words, tvb, (offset+6), 2, FALSE);
1635                         offset = offset + 8;
1636                         reported_length_remaining = reported_length_remaining - 8;
1637                     }
1638                 }
1639             } /* if (is_response) */
1640         }
1641         break;
1642
1643         case 0x0221:
1644         {
1645             if(is_command)
1646             {
1647                 if(reported_length_remaining >= 9)
1648                 {
1649                     proto_tree_add_item(command_tree, hf_omron_fixed, tvb, offset, 2, FALSE);
1650                     proto_tree_add_item(command_tree, hf_omron_intelligent_id_no, tvb, (offset+2), 2, FALSE);
1651                     proto_tree_add_item(command_tree, hf_omron_first_word, tvb, (offset+4), 2, FALSE);
1652                     proto_tree_add_item(command_tree, hf_omron_read_len, tvb, (offset+6), 2, FALSE);
1653                     proto_tree_add_item(command_tree, hf_omron_no_of_link_nodes, tvb, (offset+8), 1, FALSE);
1654
1655                     offset = offset + 9;
1656                     reported_length_remaining = reported_length_remaining - 9;
1657
1658                     while(reported_length_remaining >= 8)
1659                     {
1660                         ti = proto_tree_add_text(command_tree, tvb, offset, 8, "Block Record");
1661                         omron_block_record_tree = proto_item_add_subtree(ti, ett_omron_block_record);
1662                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_node_num_status, tvb, offset, 1, FALSE);
1663                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_node_num_num_nodes, tvb, offset, 1, FALSE);
1664                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_cio_area, tvb, (offset+1), 2, FALSE);
1665                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_kind_of_dm, tvb, (offset+3), 1, FALSE);
1666                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_dm_area_first_word, tvb, (offset+4), 2, FALSE);
1667                         proto_tree_add_item(omron_block_record_tree, hf_omron_block_record_no_of_total_words, tvb, (offset+6), 2, FALSE);
1668                         offset = offset + 8;
1669                         reported_length_remaining = reported_length_remaining - 8;
1670                     }
1671                 }
1672             }
1673
1674             if(is_response)
1675             {
1676                 if(reported_length_remaining == 2)
1677                 {
1678                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1679                     offset = offset + 2;
1680                 }
1681             }
1682         }
1683         break;
1684
1685         case 0x0304:
1686         case 0x0305:
1687         {
1688             if(is_command)
1689             {
1690                 if(reported_length_remaining == 15)
1691                 {
1692                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, offset, 2, FALSE);
1693                     proto_tree_add_item(command_tree, hf_omron_protect_code, tvb, (offset+2), 1, FALSE);
1694                     proto_tree_add_item(command_tree, hf_omron_begin_word, tvb, (offset+3),4,FALSE);
1695                     proto_tree_add_item(command_tree, hf_omron_last_word, tvb, (offset+7),4,FALSE);
1696                     proto_tree_add_item(command_tree, hf_omron_password, tvb, (offset+11),4,FALSE);
1697                     offset = offset + 15;
1698                 }
1699             }
1700
1701             if(is_response)
1702             {
1703                 if(reported_length_remaining == 2)
1704                 {
1705                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1706                     offset = offset + 2;
1707                 }
1708             }
1709         }
1710         break;
1711
1712         case 0x0306:
1713         {
1714             if(is_command)
1715             {
1716                 if(reported_length_remaining == 8)
1717                 {
1718                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, offset, 2, FALSE);
1719                     proto_tree_add_item(command_tree, hf_omron_begin_word, tvb, (offset+2), 4, FALSE);
1720                     proto_tree_add_item(command_tree, hf_omron_num_words, tvb, (offset+6), 2, FALSE);
1721                     offset = offset + 8;
1722                 }
1723             }
1724
1725             if(is_response)
1726             {
1727                 if(reported_length_remaining >= 10)
1728                 {
1729                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1730                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, (offset+2), 2, FALSE);
1731                     proto_tree_add_item(command_tree, hf_omron_begin_word, tvb, (offset+4), 4, FALSE);
1732                     proto_tree_add_item(command_tree, hf_omron_num_words, tvb, (offset+8), 2, FALSE);
1733
1734                     if(reported_length_remaining > 10)
1735                     {
1736                         proto_tree_add_item(command_tree, hf_omron_response_data, tvb, (offset+10), -1, FALSE);
1737                     }
1738                     offset = offset + reported_length_remaining;
1739                 }
1740             }
1741         }
1742         break;
1743
1744         case 0x0307:
1745         {
1746             if(is_command)
1747             {
1748                 if(reported_length_remaining >= 8)
1749                 {
1750                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, offset, 2, FALSE);
1751                     proto_tree_add_item(command_tree, hf_omron_begin_word, tvb, (offset+2), 4, FALSE);
1752                     proto_tree_add_item(command_tree, hf_omron_num_words, tvb, (offset+6), 2, FALSE);
1753
1754                     if(reported_length_remaining > 8)
1755                     {
1756                         proto_tree_add_item(command_tree, hf_omron_command_data, tvb, (offset+8), -1, FALSE);
1757                     }
1758                     offset = offset + reported_length_remaining;
1759                 }
1760             }
1761             if(is_response)
1762             {
1763                 if(reported_length_remaining == 10)
1764                 {
1765                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1766                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, (offset+2), 2, FALSE);
1767                     proto_tree_add_item(command_tree, hf_omron_begin_word, tvb, (offset+4), 4, FALSE);
1768                     proto_tree_add_item(command_tree, hf_omron_num_words, tvb, (offset+8), 2, FALSE);
1769                     offset = offset + 10;
1770                 }
1771             }
1772         }
1773         break;
1774
1775         case 0x0308:
1776         {
1777             if(is_command)
1778             {
1779                 if(reported_length_remaining == 3)
1780                 {
1781                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, offset, 2, FALSE);
1782                     proto_tree_add_item(command_tree, hf_omron_clear_code, tvb, (offset+2), 1, FALSE);
1783                     offset = offset + 3;
1784                 }
1785             }
1786             if(is_response)
1787             {
1788                 if(reported_length_remaining == 2)
1789                 {
1790                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1791                     offset = offset + 2;
1792                 }
1793             }
1794         }
1795         break;
1796
1797         case 0x0401:
1798         {
1799             if(is_command)
1800             {
1801                 if(reported_length_remaining == 3)
1802                 {
1803                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, offset, 2, FALSE);
1804                     proto_tree_add_item(command_tree, hf_omron_mode_code, tvb, (offset+2), 1, FALSE);
1805                     offset = offset + 3;
1806                 }
1807                 else if (reported_length_remaining == 2)
1808                 {
1809                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, offset, 2, FALSE);
1810                     proto_tree_add_item(command_tree, hf_omron_monitor_label, tvb, offset, 0, FALSE);
1811                     offset = offset + 2;
1812                 }
1813             }
1814             if(is_response)
1815             {
1816                 if(reported_length_remaining == 2)
1817                 {
1818                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1819                     offset = offset + 2;
1820                 }
1821             }
1822         }
1823         break;
1824
1825         case 0x0402:
1826         {
1827             /* command data length is 0 */
1828
1829             if(is_response)
1830             {
1831                 if(reported_length_remaining == 2)
1832                 {
1833                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1834                     offset = offset + 2;
1835                 }
1836             }
1837         }
1838         break;
1839
1840         case 0x0501:
1841         {
1842             if(is_command)
1843             {
1844                 if(reported_length_remaining == 1)
1845                 {
1846                     proto_tree_add_item(command_tree, hf_omron_command_data, tvb,
1847                               offset, -1, FALSE);
1848                     offset = offset + 1;
1849                 }
1850             }
1851
1852             if(is_response)
1853             {
1854                 if(reported_length_remaining == 94)
1855                 {
1856                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1857                     proto_tree_add_item(command_tree, hf_omron_controller_model, tvb, (offset+2), 20, FALSE);
1858                     proto_tree_add_item(command_tree, hf_omron_controller_version, tvb, (offset+22), 20, FALSE);
1859                     proto_tree_add_item(command_tree, hf_omron_for_system_use, tvb, (offset+42), 40, FALSE);
1860                     /* add area data sub tree */
1861                     ti = proto_tree_add_text(command_tree, tvb, (offset+82), 12, "Area Data");
1862                     area_data_tree = proto_item_add_subtree(ti, ett_area_data);
1863                     proto_tree_add_item(area_data_tree, hf_omron_program_area_size, tvb, (offset+82), 2, FALSE);
1864                     proto_tree_add_item(area_data_tree, hf_omron_iom_size, tvb, (offset+84), 1, FALSE);
1865                     proto_tree_add_item(area_data_tree, hf_omron_num_dm_words, tvb, (offset+85), 2, FALSE);
1866                     proto_tree_add_item(area_data_tree, hf_omron_timer_counter_size, tvb, (offset+87), 1, FALSE);
1867                     proto_tree_add_item(area_data_tree, hf_omron_expansion_dm_size, tvb, (offset+88), 1, FALSE);
1868                     proto_tree_add_item(area_data_tree, hf_omron_num_step_transitions, tvb, (offset+89), 2, FALSE);
1869                     proto_tree_add_item(area_data_tree, hf_omron_kind_memory_card, tvb, (offset+91), 1, FALSE);
1870                     proto_tree_add_item(area_data_tree, hf_omron_memory_card_size, tvb, (offset+92), 2, FALSE);
1871                     offset = offset + 94;
1872                 }
1873
1874                 else if(reported_length_remaining == 69)
1875                 {
1876                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1877                     ti = proto_tree_add_text(command_tree, tvb, (offset+2), 64, "CPU Bus Unit Conf");
1878                     cpu_bus_tree = proto_item_add_subtree(ti, ett_cpu_bus);
1879                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_0, tvb, (offset+2), 2, FALSE);
1880                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_1, tvb, (offset+4), 2, FALSE);
1881                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_2, tvb, (offset+6), 2, FALSE);
1882                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_3, tvb, (offset+8), 2, FALSE);
1883                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_4, tvb, (offset+10), 2, FALSE);
1884                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_5, tvb, (offset+12), 2, FALSE);
1885                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_6, tvb, (offset+14), 2, FALSE);
1886                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_7, tvb, (offset+16), 2, FALSE);
1887                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_8, tvb, (offset+18), 2, FALSE);
1888                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_9, tvb, (offset+20), 2, FALSE);
1889                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_10, tvb, (offset+22), 2, FALSE);
1890                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_11, tvb, (offset+24), 2, FALSE);
1891                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_12, tvb, (offset+26), 2, FALSE);
1892                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_13, tvb, (offset+28), 2, FALSE);
1893                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_14, tvb, (offset+30), 2, FALSE);
1894                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_15, tvb, (offset+32), 2, FALSE);
1895                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_reserved, tvb, (offset+34), 32, FALSE);
1896                     /* Remote IO Data tree */
1897                     ti = proto_tree_add_text(command_tree, tvb, (offset+66), 2, "Remote I/O data");
1898                     io_data_tree = proto_item_add_subtree(ti, ett_io_data);
1899                     proto_tree_add_item(io_data_tree, hf_omron_io_data_num_sysmac_1, tvb, (offset+66), 1, FALSE);
1900                     proto_tree_add_item(io_data_tree, hf_omron_io_data_num_sysmac_2, tvb, (offset+67), 1, FALSE);
1901                     /* PC status */
1902                     proto_tree_add_bitmask(command_tree, tvb, (offset+68), hf_omron_pc_status,
1903                         ett_pc_status_fields, pc_status_fields, FALSE);
1904                     offset = offset + 69;
1905                 }
1906
1907                 else if(reported_length_remaining == 161)
1908                 {
1909                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1910                     proto_tree_add_item(command_tree, hf_omron_controller_model, tvb, (offset+2), 20, FALSE);
1911                     proto_tree_add_item(command_tree, hf_omron_controller_version, tvb, (offset+22), 20, FALSE);
1912                     proto_tree_add_item(command_tree, hf_omron_for_system_use, tvb, (offset+42), 40, FALSE);
1913                     /* add area data sub tree */
1914                     ti = proto_tree_add_text(command_tree, tvb, (offset+82), 12, "Area Data");
1915                     area_data_tree = proto_item_add_subtree(ti, ett_area_data);
1916                     proto_tree_add_item(area_data_tree, hf_omron_program_area_size, tvb, (offset+82), 2, FALSE);
1917                     proto_tree_add_item(area_data_tree, hf_omron_iom_size, tvb, (offset+84), 1, FALSE);
1918                     proto_tree_add_item(area_data_tree, hf_omron_num_dm_words, tvb, (offset+85), 2, FALSE);
1919                     proto_tree_add_item(area_data_tree, hf_omron_timer_counter_size, tvb, (offset+87), 1, FALSE);
1920                     proto_tree_add_item(area_data_tree, hf_omron_expansion_dm_size, tvb, (offset+88), 1, FALSE);
1921                     proto_tree_add_item(area_data_tree, hf_omron_num_step_transitions, tvb, (offset+89), 2, FALSE);
1922                     proto_tree_add_item(area_data_tree, hf_omron_kind_memory_card, tvb, (offset+91), 1, FALSE);
1923                     proto_tree_add_item(area_data_tree, hf_omron_memory_card_size, tvb, (offset+92), 2, FALSE);
1924                     /* cpu bus unit configuration */
1925                     ti = proto_tree_add_text(command_tree, tvb, (offset+94), 64, "CPU Bus Unit Conf");
1926                     cpu_bus_tree = proto_item_add_subtree(ti, ett_cpu_bus);
1927                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_0, tvb, (offset+94), 2, FALSE);
1928                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_1, tvb, (offset+96), 2, FALSE);
1929                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_2, tvb, (offset+98), 2, FALSE);
1930                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_3, tvb, (offset+100), 2, FALSE);
1931                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_4, tvb, (offset+102), 2, FALSE);
1932                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_5, tvb, (offset+104), 2, FALSE);
1933                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_6, tvb, (offset+106), 2, FALSE);
1934                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_7, tvb, (offset+108), 2, FALSE);
1935                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_8, tvb, (offset+110), 2, FALSE);
1936                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_9, tvb, (offset+112), 2, FALSE);
1937                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_10, tvb, (offset+114), 2, FALSE);
1938                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_11, tvb, (offset+116), 2, FALSE);
1939                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_12, tvb, (offset+118), 2, FALSE);
1940                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_13, tvb, (offset+120), 2, FALSE);
1941                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_14, tvb, (offset+122), 2, FALSE);
1942                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_unit_15, tvb, (offset+124), 2, FALSE);
1943                     proto_tree_add_item(cpu_bus_tree, hf_omron_cpu_bus_reserved, tvb, (offset+126), 32, FALSE);
1944                     /* Remote IO Data tree */
1945                     ti = proto_tree_add_text(command_tree, tvb, (offset+158), 2, "Remote I/O data");
1946                     io_data_tree = proto_item_add_subtree(ti, ett_io_data);
1947                     proto_tree_add_item(io_data_tree, hf_omron_io_data_num_sysmac_1, tvb, (offset+158), 1, FALSE);
1948                     proto_tree_add_item(io_data_tree, hf_omron_io_data_num_sysmac_2, tvb, (offset+159), 1, FALSE);
1949                     /* PC status */
1950                     proto_tree_add_bitmask(command_tree, tvb, (offset+160), hf_omron_pc_status,
1951                         ett_pc_status_fields, pc_status_fields, FALSE);
1952                     offset = offset + 161;
1953                 }
1954             }
1955         }
1956         break;
1957
1958         case 0x0502:
1959         {
1960             if(is_command)
1961             {
1962                 if(reported_length_remaining >= 1)
1963                 {
1964                     proto_tree_add_item(command_tree, hf_omron_unit_address, tvb, offset, 1, FALSE);
1965                     if (reported_length_remaining == 2)
1966                     {
1967                         proto_tree_add_item(command_tree, hf_omron_num_units, tvb, (offset+1), 1, FALSE);
1968                         offset = offset + 1;
1969                     }
1970                     offset = offset + 1;
1971                 }
1972             }
1973
1974             if(is_response)
1975             {
1976                 if(reported_length_remaining >= 24)
1977                 {
1978                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
1979                     proto_tree_add_item(command_tree, hf_omron_num_units, tvb, offset+2, 1, FALSE);
1980                     offset = offset + 3;
1981                     reported_length_remaining = reported_length_remaining - 3;
1982
1983                     while(reported_length_remaining >= 21)
1984                     {
1985                         proto_tree_add_item(command_tree, hf_omron_unit_address, tvb, offset, 1, FALSE);
1986                         proto_tree_add_item(command_tree, hf_omron_model_number, tvb, offset+1, 20, FALSE);
1987                         offset = offset + 21;
1988                         reported_length_remaining = reported_length_remaining - 21;
1989                     }
1990                 }
1991             }
1992         }
1993         break;
1994
1995         case 0x0601:
1996         {
1997             /* command data length is 0 */
1998
1999             if(is_response)
2000             {
2001                 if(reported_length_remaining == 28)
2002                 {
2003                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2004                     proto_tree_add_item(command_tree, hf_omron_status, tvb, (offset+2), 1, FALSE);
2005                     proto_tree_add_item(command_tree, hf_omron_mode_code, tvb, (offset+3), 1, FALSE);
2006                     /* Add bitmask for Fatal error data */
2007                     proto_tree_add_bitmask(command_tree, tvb, (offset+4), hf_omron_fatal_error_data,
2008                         ett_fatal_fields, fatal_error_fields, FALSE);
2009                     /* Add bitmask for non fatal error data */
2010                     proto_tree_add_bitmask(command_tree, tvb, (offset+6), hf_omron_non_fatal_error_data,
2011                         ett_non_fatal_fields, non_fatal_error_fields, FALSE);
2012                     /* add bitmask for message yes/no data */
2013                     proto_tree_add_bitmask(command_tree, tvb, (offset+8), hf_omron_message,
2014                         ett_message_fields, message_fields, FALSE);
2015                     /* Add rest of fields */
2016                     proto_tree_add_item(command_tree, hf_omron_fals, tvb, (offset+10), 2, FALSE);
2017                     proto_tree_add_item(command_tree, hf_omron_error_message, tvb, (offset+12), 16, FALSE);
2018                     offset = offset + 28;
2019                 }
2020             }
2021         }
2022         break;
2023
2024         case 0x0602:
2025         {
2026             /* command data length is 0 */
2027
2028             if(is_response)
2029             {
2030                 if(reported_length_remaining == 108)
2031                 {
2032                     proto_item *netw_nodes_sts;
2033                     proto_tree *netw_nodes_sts_tree;
2034                     proto_item *netw_nodes_non_fatal_err_sts;
2035                     proto_tree *netw_nodes_non_fatal_err_sts_tree;
2036                     proto_item *netw_nodes_cyclic_err_ctrs;
2037                     proto_tree *netw_nodes_cyclic_err_ctrs_tree;
2038                     guint8 i;
2039                     guint8 node_num;
2040
2041                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2042                     offset = offset + 2;
2043
2044                     /* parsing 31 bytes of foo */
2045                     netw_nodes_sts = proto_tree_add_text(command_tree, tvb, offset, 31, "Network Nodes Status");
2046                     netw_nodes_sts_tree = proto_item_add_subtree(netw_nodes_sts, ett_omron_netw_nodes_sts);
2047                     node_num = 1;
2048                     for(i = 0; i < 31; i++)
2049                     {
2050                         ti = proto_tree_add_text(netw_nodes_sts_tree, tvb, offset, 1, "Node Number %d", node_num);
2051                         field_tree = proto_item_add_subtree(ti, ett_omron_netw_node_sts);
2052                         proto_tree_add_item(field_tree, hf_omron_netw_node_sts_low_3, tvb, offset, 1, FALSE);
2053                         proto_tree_add_item(field_tree, hf_omron_netw_node_sts_low_2, tvb, offset, 1, FALSE);
2054                         proto_tree_add_item(field_tree, hf_omron_netw_node_sts_low_1, tvb, offset, 1, FALSE);
2055                         proto_tree_add_item(field_tree, hf_omron_netw_node_sts_low_0, tvb, offset, 1, FALSE);
2056                         node_num = node_num + 1;
2057
2058                         ti = proto_tree_add_text(netw_nodes_sts_tree, tvb, offset, 1, "Node Number %d", node_num);
2059                         field_tree = proto_item_add_subtree(ti, ett_omron_netw_node_sts);
2060                         proto_tree_add_item(field_tree, hf_omron_netw_node_sts_high_3, tvb, offset, 1, FALSE);
2061                         proto_tree_add_item(field_tree, hf_omron_netw_node_sts_high_2, tvb, offset, 1, FALSE);
2062                         proto_tree_add_item(field_tree, hf_omron_netw_node_sts_high_1, tvb, offset, 1, FALSE);
2063                         proto_tree_add_item(field_tree, hf_omron_netw_node_sts_high_0, tvb, offset, 1, FALSE);
2064                         node_num = node_num + 1;
2065
2066                         offset = offset + 1;
2067                     }
2068
2069                     proto_tree_add_item(command_tree, hf_omron_com_cycle_time, tvb, offset, 2, FALSE);
2070                     proto_tree_add_item(command_tree, hf_omron_polling_unit_node_num, tvb, (offset+2), 1, FALSE);
2071                     proto_tree_add_item(command_tree, hf_omron_cyclic_operation, tvb, (offset+3), 1, FALSE);
2072                     proto_tree_add_item(command_tree, hf_omron_cyclic_trans_status, tvb, (offset+4), 1, FALSE);
2073                     offset =offset + 5;
2074
2075                     netw_nodes_non_fatal_err_sts =
2076                         proto_tree_add_text(command_tree, tvb, offset, 8, "Network Nodes Non-Fatal Error Status");
2077                     netw_nodes_non_fatal_err_sts_tree =
2078                         proto_item_add_subtree(netw_nodes_non_fatal_err_sts, ett_omron_netw_nodes_non_fatal_err_sts);
2079
2080                     proto_tree_add_bitmask(netw_nodes_non_fatal_err_sts_tree, tvb, (offset+0), hf_omron_cyclic_label_1,
2081                         ett_omron_cyclic_fields, cyclic_non_fatal_1_fields, FALSE);
2082                     proto_tree_add_bitmask(netw_nodes_non_fatal_err_sts_tree, tvb, (offset+1), hf_omron_cyclic_label_2,
2083                         ett_omron_cyclic_fields, cyclic_non_fatal_2_fields, FALSE);
2084                     proto_tree_add_bitmask(netw_nodes_non_fatal_err_sts_tree, tvb, (offset+2), hf_omron_cyclic_label_3,
2085                         ett_omron_cyclic_fields, cyclic_non_fatal_3_fields, FALSE);
2086                     proto_tree_add_bitmask(netw_nodes_non_fatal_err_sts_tree, tvb, (offset+3), hf_omron_cyclic_label_4,
2087                         ett_omron_cyclic_fields, cyclic_non_fatal_4_fields, FALSE);
2088                     proto_tree_add_bitmask(netw_nodes_non_fatal_err_sts_tree, tvb, (offset+4), hf_omron_cyclic_label_5,
2089                         ett_omron_cyclic_fields, cyclic_non_fatal_5_fields, FALSE);
2090                     proto_tree_add_bitmask(netw_nodes_non_fatal_err_sts_tree, tvb, (offset+5), hf_omron_cyclic_label_6,
2091                         ett_omron_cyclic_fields, cyclic_non_fatal_6_fields, FALSE);
2092                     proto_tree_add_bitmask(netw_nodes_non_fatal_err_sts_tree, tvb, (offset+6), hf_omron_cyclic_label_7,
2093                         ett_omron_cyclic_fields, cyclic_non_fatal_7_fields, FALSE);
2094                     proto_tree_add_bitmask(netw_nodes_non_fatal_err_sts_tree, tvb, (offset+7), hf_omron_cyclic_label_8,
2095                         ett_omron_cyclic_fields, cyclic_non_fatal_8_fields, FALSE);
2096
2097                     offset = offset + 8;
2098
2099                     netw_nodes_cyclic_err_ctrs = proto_tree_add_text(command_tree, tvb, offset, 62, "Network Nodes Cyclic Error Counters");
2100                     netw_nodes_cyclic_err_ctrs_tree = proto_item_add_subtree(netw_nodes_cyclic_err_ctrs, ett_omron_netw_nodes_cyclic_err_ctrs);
2101                     node_num = 1;
2102                     for(i = 0; i < 62; i++)
2103                     {
2104                         guint8 ctr = tvb_get_guint8(tvb, offset);
2105                         proto_tree_add_uint_format(netw_nodes_cyclic_err_ctrs_tree, hf_omron_node_error_count,
2106                                                    tvb, offset, 1, ctr, "Node Number %2d: %3d", node_num, ctr);
2107                         node_num = node_num + 1;
2108                         offset = offset + 1;
2109                     }
2110                 }
2111             }
2112         }
2113         break;
2114
2115         case 0x0603:
2116         {
2117             /* command data length is 0 */
2118
2119             if(is_response)
2120             {
2121                 if(reported_length_remaining == 16)
2122                 {
2123                     proto_item *status_flags;
2124                     proto_tree *status_flags_tree;
2125
2126                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2127
2128                     /* add status flag tree */
2129                     ti = proto_tree_add_item(command_tree, hf_omron_status_flags, tvb, (offset+2), 1, FALSE);
2130                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2131                     proto_tree_add_item(omron_status_tree, hf_omron_status_flags_slave_master, tvb, (offset+2), 1, FALSE);
2132                     proto_tree_add_item(omron_status_tree, hf_omron_status_flags_data_link, tvb, (offset+2), 1, FALSE);
2133
2134                     /* command_tree for master node */
2135                     proto_tree_add_item(command_tree, hf_omron_master_node_number, tvb, (offset+3), 1, FALSE);
2136                     offset = offset + 4;
2137
2138                     /* Status flag blocks */
2139                     status_flags = proto_tree_add_text(command_tree, tvb, offset, 96, "Status flag blocks");
2140                     status_flags_tree = proto_item_add_subtree(status_flags, ett_omron_data_link_status_tree);
2141
2142                     /* Status block 1 */
2143                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+0), 3, FALSE);
2144                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2145                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_0, tvb, (offset+0), 1, FALSE);
2146                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_1, tvb, (offset+0), 1, FALSE);
2147                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_2, tvb, (offset+0), 1, FALSE);
2148                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_3, tvb, (offset+0), 1, FALSE);
2149                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_4, tvb, (offset+0), 1, FALSE);
2150                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_5, tvb, (offset+0), 1, FALSE);
2151                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_6, tvb, (offset+0), 1, FALSE);
2152                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_7, tvb, (offset+0), 1, FALSE);
2153
2154                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+0), 3, FALSE);
2155                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2156                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_0, tvb, (offset+1), 1, FALSE);
2157                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_1, tvb, (offset+1), 1, FALSE);
2158                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_2, tvb, (offset+1), 1, FALSE);
2159                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_3, tvb, (offset+1), 1, FALSE);
2160                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_4, tvb, (offset+1), 1, FALSE);
2161                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_5, tvb, (offset+1), 1, FALSE);
2162                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_6, tvb, (offset+1), 1, FALSE);
2163                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_7, tvb, (offset+1), 1, FALSE);
2164
2165                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+0), 3, FALSE);
2166                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2167                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_0, tvb, (offset+2), 1, FALSE);
2168                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_1, tvb, (offset+2), 1, FALSE);
2169                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_2, tvb, (offset+2), 1, FALSE);
2170                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_3, tvb, (offset+2), 1, FALSE);
2171                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_4, tvb, (offset+2), 1, FALSE);
2172                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_5, tvb, (offset+2), 1, FALSE);
2173                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_6, tvb, (offset+2), 1, FALSE);
2174                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_7, tvb, (offset+2), 1, FALSE);
2175
2176                     /* status block 2 */
2177                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+3), 3, FALSE);
2178                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2179                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_0, tvb, (offset+3), 1, FALSE);
2180                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_1, tvb, (offset+3), 1, FALSE);
2181                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_2, tvb, (offset+3), 1, FALSE);
2182                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_3, tvb, (offset+3), 1, FALSE);
2183                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_4, tvb, (offset+3), 1, FALSE);
2184                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_5, tvb, (offset+3), 1, FALSE);
2185                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_6, tvb, (offset+3), 1, FALSE);
2186                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_7, tvb, (offset+3), 1, FALSE);
2187
2188                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+3), 3, FALSE);
2189                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2190                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_0, tvb, (offset+4), 1, FALSE);
2191                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_1, tvb, (offset+4), 1, FALSE);
2192                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_2, tvb, (offset+4), 1, FALSE);
2193                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_3, tvb, (offset+4), 1, FALSE);
2194                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_4, tvb, (offset+4), 1, FALSE);
2195                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_5, tvb, (offset+4), 1, FALSE);
2196                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_6, tvb, (offset+4), 1, FALSE);
2197                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_7, tvb, (offset+4), 1, FALSE);
2198
2199                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+3), 3, FALSE);
2200                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2201                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_0, tvb, (offset+5), 1, FALSE);
2202                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_1, tvb, (offset+5), 1, FALSE);
2203                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_2, tvb, (offset+5), 1, FALSE);
2204                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_3, tvb, (offset+5), 1, FALSE);
2205                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_4, tvb, (offset+5), 1, FALSE);
2206                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_5, tvb, (offset+5), 1, FALSE);
2207                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_6, tvb, (offset+5), 1, FALSE);
2208                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_7, tvb, (offset+5), 1, FALSE);
2209
2210                     /* status block 3 */
2211                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+6), 3, FALSE);
2212                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2213                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_0, tvb, (offset+6), 1, FALSE);
2214                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_1, tvb, (offset+6), 1, FALSE);
2215                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_2, tvb, (offset+6), 1, FALSE);
2216                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_3, tvb, (offset+6), 1, FALSE);
2217                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_4, tvb, (offset+6), 1, FALSE);
2218                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_5, tvb, (offset+6), 1, FALSE);
2219                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_6, tvb, (offset+6), 1, FALSE);
2220                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_7, tvb, (offset+6), 1, FALSE);
2221
2222                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+6), 3, FALSE);
2223                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2224                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_0, tvb, (offset+7), 1, FALSE);
2225                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_1, tvb, (offset+7), 1, FALSE);
2226                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_2, tvb, (offset+7), 1, FALSE);
2227                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_3, tvb, (offset+7), 1, FALSE);
2228                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_4, tvb, (offset+7), 1, FALSE);
2229                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_5, tvb, (offset+7), 1, FALSE);
2230                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_6, tvb, (offset+7), 1, FALSE);
2231                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_7, tvb, (offset+7), 1, FALSE);
2232
2233                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+6), 3, FALSE);
2234                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2235                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_0, tvb, (offset+8), 1, FALSE);
2236                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_1, tvb, (offset+8), 1, FALSE);
2237                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_2, tvb, (offset+8), 1, FALSE);
2238                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_3, tvb, (offset+8), 1, FALSE);
2239                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_4, tvb, (offset+8), 1, FALSE);
2240                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_5, tvb, (offset+8), 1, FALSE);
2241                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_6, tvb, (offset+8), 1, FALSE);
2242                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_7, tvb, (offset+8), 1, FALSE);
2243
2244                     /* status block 4 */
2245                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+9), 3, FALSE);
2246                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2247                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_0, tvb, (offset+9), 1, FALSE);
2248                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_1, tvb, (offset+9), 1, FALSE);
2249                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_2, tvb, (offset+9), 1, FALSE);
2250                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_3, tvb, (offset+9), 1, FALSE);
2251                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_4, tvb, (offset+9), 1, FALSE);
2252                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_5, tvb, (offset+9), 1, FALSE);
2253                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_6, tvb, (offset+9), 1, FALSE);
2254                     proto_tree_add_item(omron_status_tree, hf_omron_status_node_7, tvb, (offset+9), 1, FALSE);
2255
2256                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+9), 3, FALSE);
2257                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2258                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_0, tvb, (offset+10), 1, FALSE);
2259                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_1, tvb, (offset+10), 1, FALSE);
2260                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_2, tvb, (offset+10), 1, FALSE);
2261                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_3, tvb, (offset+10), 1, FALSE);
2262                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_4, tvb, (offset+10), 1, FALSE);
2263                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_5, tvb, (offset+10), 1, FALSE);
2264                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_6, tvb, (offset+10), 1, FALSE);
2265                     proto_tree_add_item(omron_status_tree, hf_omron_status_1_node_7, tvb, (offset+10), 1, FALSE);
2266
2267                     ti = proto_tree_add_item(status_flags_tree, hf_omron_status_flags, tvb, (offset+9), 3, FALSE);
2268                     omron_status_tree = proto_item_add_subtree(ti, ett_omron_status_block);
2269                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_0, tvb, (offset+11), 1, FALSE);
2270                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_1, tvb, (offset+11), 1, FALSE);
2271                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_2, tvb, (offset+11), 1, FALSE);
2272                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_3, tvb, (offset+11), 1, FALSE);
2273                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_4, tvb, (offset+11), 1, FALSE);
2274                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_5, tvb, (offset+11), 1, FALSE);
2275                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_6, tvb, (offset+11), 1, FALSE);
2276                     proto_tree_add_item(omron_status_tree, hf_omron_status_2_node_7, tvb, (offset+11), 1, FALSE);
2277
2278                     offset = offset + 12;
2279                 }
2280             }
2281         }
2282         break;
2283
2284         case 0x0620:
2285         {
2286             if(is_command)
2287             {
2288                 if(reported_length_remaining == 1)
2289                 {
2290                     proto_tree_add_item(command_tree, hf_omron_parameter, tvb, offset, 1, FALSE);
2291                     offset = offset + 1;
2292                 }
2293             }
2294
2295             if(is_response)
2296             {
2297                 if(reported_length_remaining == 2)
2298                 {
2299                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2300                     offset = offset + 2;
2301                 }
2302
2303                 else if(reported_length_remaining == 14)
2304                 {
2305                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2306                     proto_tree_add_item(command_tree, hf_omron_avg_cycle_time, tvb, (offset+2), 4, FALSE);
2307                     proto_tree_add_item(command_tree, hf_omron_max_cycle_time, tvb, (offset+6), 4, FALSE);
2308                     proto_tree_add_item(command_tree, hf_omron_min_cycle_time, tvb, (offset+10), 4, FALSE);
2309                     offset = offset + 14;
2310                 }
2311             }
2312         }
2313         break;
2314
2315         case 0x0701:
2316         {
2317             /* command data length is 0 */
2318
2319             if(is_response)
2320             {
2321                 if(reported_length_remaining == 9)
2322                 {
2323                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2324                     proto_tree_add_item(command_tree, hf_omron_year, tvb, (offset+2), 1, FALSE);
2325                     proto_tree_add_item(command_tree, hf_omron_month, tvb, (offset+3), 1, FALSE);
2326                     proto_tree_add_item(command_tree, hf_omron_date, tvb, (offset+4), 1, FALSE);
2327                     proto_tree_add_item(command_tree, hf_omron_hour, tvb, (offset+5), 1, FALSE);
2328                     proto_tree_add_item(command_tree, hf_omron_minute, tvb, (offset+6), 1, FALSE);
2329                     proto_tree_add_item(command_tree, hf_omron_second, tvb, (offset+7), 1, FALSE);
2330                     proto_tree_add_item(command_tree, hf_omron_day, tvb, (offset+8), 1, FALSE);
2331                     offset = offset + 9;
2332                 }
2333             }
2334         }
2335         break;
2336
2337         case 0x0702:
2338         {
2339             if(is_command)
2340             {
2341                 if(reported_length_remaining >= 5)
2342                 {
2343                     proto_tree_add_item(command_tree, hf_omron_year, tvb, (offset), 1, FALSE);
2344                     proto_tree_add_item(command_tree, hf_omron_month, tvb, (offset+1), 1, FALSE);
2345                     proto_tree_add_item(command_tree, hf_omron_date, tvb, (offset+2), 1, FALSE);
2346                     proto_tree_add_item(command_tree, hf_omron_hour, tvb, (offset+3), 1, FALSE);
2347                     proto_tree_add_item(command_tree, hf_omron_minute, tvb, (offset+4), 1, FALSE);
2348
2349                     if(reported_length_remaining == 7)
2350                     {
2351                         proto_tree_add_item(command_tree, hf_omron_second, tvb, (offset+5), 1, FALSE);
2352                         proto_tree_add_item(command_tree, hf_omron_day, tvb, (offset+6), 1, FALSE);
2353                         offset = offset + 2;
2354                     }
2355                     offset = offset + 5;
2356                 }
2357             }
2358
2359             if(is_response)
2360             {
2361                 if(reported_length_remaining == 2)
2362                 {
2363                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2364                     offset = offset + 2;
2365                 }
2366             }
2367         }
2368         break;
2369
2370         case 0x0801:
2371         {
2372             if(is_command)
2373             {
2374                 /* zero-length case handled in previous switch statement */
2375                 if(reported_length_remaining > 0)
2376                 {
2377                     proto_tree_add_item(command_tree, hf_omron_data, tvb, offset, -1, FALSE);
2378                     offset = offset + reported_length_remaining;
2379                 }
2380             }
2381
2382             if(is_response)
2383             {
2384                 if(reported_length_remaining > 2)
2385                 {
2386                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2387                     proto_tree_add_item(command_tree, hf_omron_data, tvb, (offset+2), -1, FALSE);
2388                     offset = offset + reported_length_remaining;
2389                 }
2390             }
2391         }
2392         break;
2393
2394         case 0x0802:
2395         {
2396             if(is_response)
2397             {
2398                 if(reported_length_remaining == 4)
2399                 {
2400                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2401                     proto_tree_add_item(command_tree, hf_omron_num_receptions, tvb, (offset+2), 2, FALSE);
2402                     offset = offset + 4;
2403                }
2404             }
2405         }
2406         break;
2407
2408         case 0x0803:
2409         {
2410             if(is_command)
2411             {
2412                 /* zero-length case handled in previous switch statement */
2413                 if(reported_length_remaining > 0)
2414                 {
2415                     proto_tree_add_item(command_tree, hf_omron_data, tvb, offset, -1, FALSE);
2416                     offset = offset + reported_length_remaining;
2417                 }
2418             }
2419         }
2420         break;
2421
2422         case 0x0920:
2423         {
2424             if(is_command)
2425             {
2426                 if(reported_length_remaining == 2)
2427                 {
2428                     if((tvb_get_ntohs(tvb, offset) & 0xC000) == 0x8000)
2429                     {
2430                         /* "FAL/FALS READ" */
2431                         proto_tree_add_item(command_tree, hf_omron_fals, tvb, offset, 2, FALSE);
2432                     }
2433                     else
2434                     {
2435                         /* "MESSAGE READ" / "MESSAGE CLEAR" */
2436                         /* add bitmask for message yes/no data */
2437                         proto_tree_add_bitmask(command_tree, tvb, offset, hf_omron_message,
2438                                                ett_message_fields, message_yes_no_fields, FALSE);
2439                     }
2440                     offset = offset + 2;
2441                 }
2442             }
2443
2444             if(is_response)
2445             {
2446                 if(reported_length_remaining == 2)
2447                 {
2448                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2449                     offset = offset + 2;
2450                 }
2451                 else if(reported_length_remaining == 20)
2452                 {
2453                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2454                     proto_tree_add_item(command_tree, hf_omron_fals, tvb, (offset+2), 2, FALSE);
2455                     proto_tree_add_item(command_tree, hf_omron_error_message, tvb, (offset+4), 16, FALSE);
2456                     offset = offset + 20;
2457                 }
2458                 else if(reported_length_remaining >= 4)
2459                 {
2460                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2461                     /* add bitmask for message yes/no data */
2462                     proto_tree_add_bitmask(command_tree, tvb, (offset+2), hf_omron_message,
2463                                            ett_message_fields, message_yes_no_fields, FALSE);
2464
2465                     offset = offset + 4;
2466                     reported_length_remaining = reported_length_remaining - 4;
2467
2468                     while (reported_length_remaining >= 32)
2469                     {
2470                         proto_tree_add_item(command_tree, hf_omron_read_message, tvb, offset, 32, FALSE);
2471                         offset = offset + 32;
2472                         reported_length_remaining = reported_length_remaining - 32;
2473                     }
2474                 }
2475             }
2476         }
2477         break;
2478
2479         case 0x0C01:
2480         {
2481             if(is_command)
2482             {
2483                 if(reported_length_remaining == 2)
2484                 {
2485                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, offset, 2, FALSE);
2486                     offset = offset + 2;
2487                 }
2488             }
2489
2490             if(is_response)
2491             {
2492                 if(reported_length_remaining == 2)
2493                 {
2494                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2495                     offset = offset + 2;
2496                 }
2497                 else if(reported_length_remaining == 5)
2498                 {
2499                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2500                     proto_tree_add_item(command_tree, hf_omron_unit_address, tvb, (offset+2), 1, FALSE);
2501                     proto_tree_add_item(command_tree, hf_omron_node_number, tvb, (offset+3), 1, FALSE);
2502                     proto_tree_add_item(command_tree, hf_omron_network_address, tvb, (offset+4), 1, FALSE);
2503                     offset = offset + 5;
2504                 }
2505
2506             }
2507         }
2508         break;
2509
2510         case 0x0C02:
2511         {
2512             if(is_command)
2513             {
2514                 if(reported_length_remaining == 2)
2515                 {
2516                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, offset, 2, FALSE);
2517                     offset = offset + 2;
2518                 }
2519             }
2520
2521             if(is_response)
2522             {
2523                 if(reported_length_remaining == 2)
2524                 {
2525                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2526                     offset = offset + 2;
2527                 }
2528             }
2529
2530         }
2531         break;
2532
2533         case 0x0C03:
2534         {
2535             if(is_command)
2536             {
2537                 if(reported_length_remaining == 2)
2538                 {
2539                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, offset, 2, FALSE);
2540                     offset = offset + 2;
2541                 }
2542             }
2543
2544             if(is_response)
2545             {
2546                 if(reported_length_remaining == 2)
2547                 {
2548                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2549                     offset = offset + 2;
2550                 }
2551             }
2552
2553         }
2554         break;
2555
2556         case 0x2101:
2557         {
2558             if(is_command)
2559             {
2560                 if(reported_length_remaining == 2)
2561                 {
2562                     proto_tree_add_item(command_tree, hf_omron_error_reset_fals_no, tvb, offset, 2, FALSE);
2563                     offset = offset + 2;
2564                 }
2565             }
2566
2567             if(is_response)
2568             {
2569                 if(reported_length_remaining == 2)
2570                 {
2571                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2572                     offset = offset + 2;
2573                 }
2574             }
2575
2576         }
2577         break;
2578
2579         case 0x2102:
2580         {
2581             if(is_command)
2582             {
2583                 if(reported_length_remaining == 4)
2584                 {
2585                     proto_tree_add_item(command_tree, hf_omron_beginning_record_no, tvb, offset, 2, FALSE);
2586                     proto_tree_add_item(command_tree, hf_omron_no_of_records, tvb, (offset+2), 2, FALSE);
2587                     offset = offset + 4;
2588                 }
2589             }
2590
2591             if(is_response)
2592             {
2593                 if(reported_length_remaining >= 8)
2594                 {
2595                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2596                     proto_tree_add_item(command_tree, hf_omron_max_no_of_stored_records, tvb, (offset+2), 2, FALSE);
2597                     proto_tree_add_item(command_tree, hf_omron_no_of_stored_records, tvb, (offset+4), 2, FALSE);
2598                     proto_tree_add_item(command_tree, hf_omron_no_of_records, tvb, (offset+6), 2, FALSE);
2599                     offset = offset + 8;
2600                     reported_length_remaining = reported_length_remaining - 8;
2601
2602                     while(reported_length_remaining >= 10)
2603                     {
2604                         ti = proto_tree_add_text(command_tree, tvb, offset, 10, "Error log data");
2605                         error_log_tree = proto_item_add_subtree(ti, ett_omron_error_log_data);
2606
2607                         proto_tree_add_item(error_log_tree, hf_omron_error_reset_fals_no, tvb, offset, 2, FALSE);
2608                         proto_tree_add_item(error_log_tree, hf_omron_error_reset_fals_no, tvb, (offset+2), 2, FALSE);
2609                         proto_tree_add_item(error_log_tree, hf_omron_minute, tvb, (offset+4), 1, FALSE);
2610                         proto_tree_add_item(error_log_tree, hf_omron_second, tvb, (offset+5), 1, FALSE);
2611                         proto_tree_add_item(error_log_tree, hf_omron_day, tvb, (offset+6), 1, FALSE);
2612                         proto_tree_add_item(error_log_tree, hf_omron_hour, tvb, (offset+7), 1, FALSE);
2613                         proto_tree_add_item(error_log_tree, hf_omron_year, tvb, (offset+8), 1, FALSE);
2614                         proto_tree_add_item(error_log_tree, hf_omron_month, tvb, (offset+9), 1, FALSE);
2615
2616                         offset = offset + 10;
2617                         reported_length_remaining = reported_length_remaining - 10;
2618                     }
2619                 }
2620             }
2621         }
2622         break;
2623
2624         case 0x2103:
2625         {
2626             /* command data length is 0 */
2627
2628             if(is_response)
2629             {
2630                 if(reported_length_remaining == 2)
2631                 {
2632                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2633                     offset = offset + 2;
2634                 }
2635             }
2636         }
2637         break;
2638
2639         case 0x2201:
2640         {
2641             if(is_command)
2642             {
2643                 if(reported_length_remaining == 6)
2644                 {
2645                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, offset, 2, FALSE);
2646                     proto_tree_add_item(command_tree, hf_omron_beginning_file_position, tvb, (offset+2), 2, FALSE);
2647                     proto_tree_add_item(command_tree, hf_omron_no_of_files, tvb, (offset+4), 2, FALSE);
2648                     offset = offset + 6;
2649                 }
2650             }
2651
2652             if(is_response)
2653             {
2654                 if(reported_length_remaining >= 50)
2655                 {
2656                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2657
2658                     ti = proto_tree_add_text(command_tree, tvb, (offset+2), 26, "Disk data");
2659                     omron_disk_data_tree = proto_item_add_subtree(ti, ett_omron_disk_data);
2660                     proto_tree_add_item(omron_disk_data_tree, hf_omron_volume_label, tvb, (offset+2), 12, FALSE);
2661
2662                     omron_byte = tvb_get_guint8(tvb, (offset+14));
2663                     proto_tree_add_uint_format(omron_disk_data_tree, hf_omron_date_year, tvb, (offset+14), 1, omron_byte,
2664                         "Year: %d", ((omron_byte>>1)+1980));
2665
2666                     proto_tree_add_item(omron_disk_data_tree, hf_omron_date_month, tvb, (offset+14), 4, FALSE);
2667                     proto_tree_add_item(omron_disk_data_tree, hf_omron_date_day, tvb, (offset+14), 4, FALSE);
2668                     proto_tree_add_item(omron_disk_data_tree, hf_omron_date_hour, tvb, (offset+14), 4, FALSE);
2669                     proto_tree_add_item(omron_disk_data_tree, hf_omron_date_minute, tvb, (offset+14), 4, FALSE);
2670
2671                     omron_byte = tvb_get_guint8(tvb, (offset+17));
2672                     proto_tree_add_uint_format(omron_disk_data_tree, hf_omron_date_second, tvb, (offset+17), 1, omron_byte,
2673                         "Second: %d", ((omron_byte&0x1F)*2));
2674
2675                     proto_tree_add_item(omron_disk_data_tree, hf_omron_total_capacity, tvb, (offset+18), 4, FALSE);
2676                     proto_tree_add_item(omron_disk_data_tree, hf_omron_unused_capacity, tvb, (offset+22), 4, FALSE);
2677                     proto_tree_add_item(omron_disk_data_tree, hf_omron_total_no_files, tvb, (offset+26), 2, FALSE);
2678                     proto_tree_add_item(omron_disk_data_tree, hf_omron_no_files, tvb, (offset+28), 2, FALSE);
2679
2680                     offset = offset + 30;
2681                     reported_length_remaining = reported_length_remaining - 30;
2682
2683                     while(reported_length_remaining >= 20)
2684                     {
2685                         ti = proto_tree_add_text(command_tree, tvb, offset, 20, "File data");
2686                         omron_file_data_tree = proto_item_add_subtree(ti, ett_omron_file_data);
2687
2688                         proto_tree_add_item(omron_file_data_tree, hf_omron_filename, tvb, offset, 12, FALSE);
2689
2690                         omron_byte = tvb_get_guint8(tvb, (offset+12));
2691                         proto_tree_add_uint_format(omron_file_data_tree, hf_omron_date_year, tvb, (offset+12), 1, omron_byte,
2692                                                    "Year: %d", ((omron_byte>>1)+1980));
2693
2694                         proto_tree_add_item(omron_file_data_tree, hf_omron_date_month, tvb, (offset+12), 4, FALSE);
2695                         proto_tree_add_item(omron_file_data_tree, hf_omron_date_day, tvb, (offset+12), 4, FALSE);
2696                         proto_tree_add_item(omron_file_data_tree, hf_omron_date_hour, tvb, (offset+12), 4, FALSE);
2697                         proto_tree_add_item(omron_file_data_tree, hf_omron_date_minute, tvb, (offset+12), 4, FALSE);
2698
2699                         omron_byte = tvb_get_guint8(tvb, (offset+15));
2700                         proto_tree_add_uint_format(omron_file_data_tree, hf_omron_date_second, tvb, (offset+15), 1, omron_byte,
2701                                                    "Second: %d", ((omron_byte&0x1F)*2));
2702
2703                         proto_tree_add_item(omron_file_data_tree, hf_omron_file_capacity, tvb, (offset+16), 4, FALSE);
2704
2705                         offset = offset + 20;
2706                         reported_length_remaining = reported_length_remaining - 20;
2707                     } /* while */
2708                 } /* if(reported_length_remaining >= 50) */
2709             }
2710         }
2711         break;
2712
2713         case 0x2202:
2714         {
2715             if(is_command)
2716             {
2717                 if(reported_length_remaining == 20)
2718                 {
2719                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, offset, 2, FALSE);
2720                     proto_tree_add_item(command_tree, hf_omron_filename, tvb, (offset+2), 12, FALSE);
2721                     proto_tree_add_item(command_tree, hf_omron_file_position, tvb, (offset+14), 4, FALSE);
2722                     proto_tree_add_item(command_tree, hf_omron_data_length, tvb, (offset+18), 2, FALSE);
2723                     offset = offset + 20;
2724                 }
2725             }
2726
2727             if(is_response)
2728             {
2729                 if(reported_length_remaining >= 12)
2730                 {
2731                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2732                     proto_tree_add_item(command_tree, hf_omron_file_capacity, tvb, (offset+2), 4, FALSE);
2733                     proto_tree_add_item(command_tree, hf_omron_file_position, tvb, (offset+6), 4, FALSE);
2734                     proto_tree_add_item(command_tree, hf_omron_data_length, tvb, (offset+10), 2, FALSE);
2735
2736                     if(reported_length_remaining > 12)
2737                     {
2738                         proto_tree_add_item(command_tree, hf_omron_file_data, tvb, (offset+12), -1, FALSE);
2739                     }
2740                     offset = offset + reported_length_remaining;
2741                 }
2742             }
2743         }
2744         break;
2745
2746         case 0x2203:
2747         {
2748             if(is_command)
2749             {
2750                 if(reported_length_remaining >= 22)
2751                 {
2752                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, offset, 2, FALSE);
2753                     proto_tree_add_item(command_tree, hf_omron_file_parameter_code, tvb, (offset+2), 2, FALSE);
2754                     proto_tree_add_item(command_tree, hf_omron_filename, tvb, (offset+4), 12, FALSE);
2755                     proto_tree_add_item(command_tree, hf_omron_file_position, tvb, (offset+16), 4, FALSE);
2756                     proto_tree_add_item(command_tree, hf_omron_data_length, tvb, (offset+20), 2, FALSE);
2757                     if(reported_length_remaining > 22)
2758                     {
2759                         proto_tree_add_item(command_tree, hf_omron_file_data, tvb, (offset+22), -1, FALSE);
2760                     }
2761                     offset = offset + reported_length_remaining;
2762                 }
2763             }
2764
2765             if(is_response)
2766             {
2767                 if(reported_length_remaining == 2)
2768                 {
2769                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2770                     offset = offset + 2;
2771                 }
2772             }
2773         }
2774         break;
2775
2776         case 0x2204:
2777         {
2778             if(is_command)
2779             {
2780                 if(reported_length_remaining == 2)
2781                 {
2782                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, offset, 2, FALSE);
2783                     offset = offset + 2;
2784                 }
2785             }
2786             if(is_response)
2787             {
2788                 if(reported_length_remaining == 2)
2789                 {
2790                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2791                     offset = offset + 2;
2792                 }
2793             }
2794         }
2795         break;
2796
2797         case 0x2205:
2798         {
2799             if(is_command)
2800             {
2801                 if(reported_length_remaining >= 16)
2802                 {
2803                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, offset, 2, FALSE);
2804                     proto_tree_add_item(command_tree, hf_omron_no_files, tvb, (offset+2), 2, FALSE);
2805                     offset = offset + 4;
2806                     reported_length_remaining = reported_length_remaining - 4;
2807
2808                     while(reported_length_remaining >= 12)
2809                     {
2810                         proto_tree_add_item(command_tree, hf_omron_filename, tvb, offset, 12, FALSE);
2811                         offset = offset + 12;
2812                         reported_length_remaining = reported_length_remaining - 12;
2813                     }
2814                 }
2815             }
2816
2817             if(is_response)
2818             {
2819                 if(reported_length_remaining == 4)
2820                 {
2821                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2822                     proto_tree_add_item(command_tree, hf_omron_no_files, tvb, (offset+2), 2, FALSE);
2823                     offset = offset + 4;
2824                 }
2825             }
2826         }
2827         break;
2828
2829         case 0x2206:
2830         {
2831             if(is_command)
2832             {
2833                 if(reported_length_remaining >= 4)
2834                 {
2835                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, offset, 2, FALSE);
2836                     proto_tree_add_item(command_tree, hf_omron_volume_parameter_code, tvb, (offset+2), 2, FALSE);
2837
2838                     if(reported_length_remaining == 16)
2839                     {
2840                         proto_tree_add_item(command_tree, hf_omron_volume_label, tvb, (offset+4), 12, FALSE);
2841                         offset = offset + 12;
2842                     }
2843                     offset = offset + 4;
2844                 }
2845             }
2846
2847             if(is_response)
2848             {
2849                 if(reported_length_remaining == 2)
2850                 {
2851                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2852                     offset = offset + 2;
2853                 }
2854             }
2855         }
2856         break;
2857
2858         case 0x2207:
2859         {
2860             if(is_command)
2861             {
2862                 if(reported_length_remaining == 28)
2863                 {
2864                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, offset, 2, FALSE);
2865                     proto_tree_add_item(command_tree, hf_omron_filename, tvb, (offset+2), 12, FALSE);
2866                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, (offset+14), 2, FALSE);
2867                     proto_tree_add_item(command_tree, hf_omron_filename, tvb, (offset+16), 12, FALSE);
2868                     offset = offset + 28;
2869                 }
2870             }
2871
2872             if(is_response)
2873             {
2874                 if(reported_length_remaining == 2)
2875                 {
2876                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2877                     offset = offset + 2;
2878                 }
2879             }
2880         }
2881         break;
2882
2883         case 0x2208:
2884         {
2885             if(is_command)
2886             {
2887                 if(reported_length_remaining == 26)
2888                 {
2889                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, offset, 2, FALSE);
2890                     proto_tree_add_item(command_tree, hf_omron_filename, tvb, (offset+2), 12, FALSE);
2891                     proto_tree_add_item(command_tree, hf_omron_filename, tvb, (offset+14), 12, FALSE);
2892                     offset = offset + 26;
2893                 }
2894             }
2895
2896             if(is_response)
2897             {
2898                 if(reported_length_remaining == 2)
2899                 {
2900                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2901                     offset = offset + 2;
2902                 }
2903             }
2904         }
2905         break;
2906
2907         case 0x2209:
2908         {
2909             if(is_command)
2910             {
2911                 if(reported_length_remaining == 14)
2912                 {
2913                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, offset, 2, FALSE);
2914                     proto_tree_add_item(command_tree, hf_omron_filename, tvb, (offset+2), 12, FALSE);
2915                     offset = offset + 14;
2916                 }
2917             }
2918
2919             if(is_response)
2920             {
2921                 if(reported_length_remaining == 2)
2922                 {
2923                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2924                     offset = offset + 2;
2925                 }
2926             }
2927         }
2928         break;
2929
2930         case 0x220A:
2931         {
2932             if(is_command)
2933             {
2934                 if(reported_length_remaining == 22)
2935                 {
2936                     proto_tree_add_item(command_tree, hf_omron_transfer_parameter_code, tvb, offset, 2, FALSE);
2937                     proto_tree_add_item(command_tree, hf_omron_command_memory_area_code, tvb, (offset+2), 1, FALSE);
2938                     proto_tree_add_item(command_tree, hf_omron_transfer_beginning_address, tvb, (offset+3), 3, FALSE);
2939                     proto_tree_add_item(command_tree, hf_omron_num_items, tvb, (offset+6), 2, FALSE);
2940                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, (offset+8), 2, FALSE);
2941                     proto_tree_add_item(command_tree, hf_omron_filename, tvb, (offset+10), 12, FALSE);
2942                     offset = offset + 22;
2943                 }
2944             }
2945
2946             if(is_response)
2947             {
2948                 if(reported_length_remaining == 4)
2949                 {
2950                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2951                     proto_tree_add_item(command_tree, hf_omron_num_items, tvb, (offset+2), 2, FALSE);
2952                     offset = offset + 4;
2953                 }
2954             }
2955         }
2956         break;
2957
2958         case 0x220B:
2959         {
2960             if(is_command)
2961             {
2962                 if(reported_length_remaining == 22)
2963                 {
2964                     proto_tree_add_item(command_tree, hf_omron_transfer_parameter_code, tvb, offset, 2, FALSE);
2965                     proto_tree_add_item(command_tree, hf_omron_parameter_area_code, tvb, (offset+2), 2, FALSE);
2966                     proto_tree_add_item(command_tree, hf_omron_address, tvb, (offset+4), 2, FALSE);
2967                     proto_tree_add_item(command_tree, hf_omron_num_words, tvb, (offset+6), 2, FALSE);
2968                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, (offset+8), 2, FALSE);
2969                     proto_tree_add_item(command_tree, hf_omron_filename, tvb, (offset+10), 12, FALSE);
2970                     offset = offset + 22;
2971                 }
2972             }
2973
2974             if(is_response)
2975             {
2976                 if(reported_length_remaining == 4)
2977                 {
2978                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
2979                     proto_tree_add_item(command_tree, hf_omron_num_words, tvb, (offset+2), 2, FALSE);
2980                     offset = offset + 4;
2981                 }
2982             }
2983         }
2984         break;
2985
2986         case 0x220C:
2987         {
2988             if(is_command)
2989             {
2990                 if(reported_length_remaining == 26)
2991                 {
2992                     proto_tree_add_item(command_tree, hf_omron_transfer_parameter_code, tvb, offset, 2, FALSE);
2993                     proto_tree_add_item(command_tree, hf_omron_program_number, tvb, (offset+2), 2, FALSE);
2994                     proto_tree_add_item(command_tree, hf_omron_begin_word, tvb, (offset+4), 4, FALSE);
2995                     proto_tree_add_item(command_tree, hf_omron_number_of_bytes, tvb, (offset+8), 4, FALSE);
2996                     proto_tree_add_item(command_tree, hf_omron_disk_no, tvb, (offset+12), 2, FALSE);
2997                     proto_tree_add_item(command_tree, hf_omron_filename, tvb, (offset+14), 12, FALSE);
2998                     offset = offset + 26;
2999                 }
3000             }
3001
3002             if(is_response)
3003             {
3004                 if(reported_length_remaining == 6)
3005                 {
3006                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
3007                     proto_tree_add_item(command_tree, hf_omron_number_of_bytes, tvb, (offset+2), 4, FALSE);
3008                     offset = offset + 6;
3009                 }
3010             }
3011         }
3012         break;
3013
3014         case 0x220F:
3015         {
3016             if(is_command)
3017             {
3018                 if(reported_length_remaining == 3)
3019                 {
3020                     proto_tree_add_item(command_tree, hf_omron_beginning_block_num, tvb, offset, 2, FALSE);
3021                     proto_tree_add_item(command_tree, hf_omron_num_blocks, tvb, (offset+2), 1, FALSE);
3022                     offset = offset + 3;
3023                 }
3024             }
3025
3026             if(is_response)
3027             {
3028                 if(reported_length_remaining >= 9)
3029                 {
3030                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
3031                     proto_tree_add_item(command_tree, hf_omron_num_blocks_remaining, tvb, (offset+2), 2, FALSE);
3032                     proto_tree_add_item(command_tree, hf_omron_total_num_blocks, tvb, (offset+4), 2, FALSE);
3033                     proto_tree_add_item(command_tree, hf_omron_type, tvb, (offset+6), 1, FALSE);
3034                     offset = offset + 7;
3035                     reported_length_remaining = reported_length_remaining - 7;
3036
3037                     while(reported_length_remaining >= 2)
3038                     {
3039                         proto_tree_add_bitmask(command_tree, tvb, offset, hf_omron_data_type,
3040                             ett_omron_data_type, data_type_fields, FALSE);
3041                         proto_tree_add_item(command_tree, hf_omron_control_data, tvb, (offset+1), 1, FALSE);
3042                         offset = offset + 2;
3043                         reported_length_remaining = reported_length_remaining - 2;
3044                     }
3045                 }
3046             }
3047         }
3048         break;
3049
3050         case 0x2210:
3051         {
3052             if(is_command)
3053             {
3054                 if(reported_length_remaining == 2)
3055                 {
3056                     proto_tree_add_item(command_tree, hf_omron_block_num, tvb, offset, 2, FALSE);
3057                     offset = offset + 2;
3058                 }
3059             }
3060
3061             if(is_response)
3062             {
3063                 if(reported_length_remaining >= 4)
3064                 {
3065                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
3066                     proto_tree_add_bitmask(command_tree, tvb, (offset+2), hf_omron_data_type,
3067                         ett_omron_data_type, data_type_fields, FALSE);
3068                     proto_tree_add_item(command_tree, hf_omron_control_data, tvb, (offset+3), 1, FALSE);
3069                     proto_tree_add_item(command_tree, hf_omron_data, tvb, (offset+4), -1, FALSE);
3070                     offset = offset + reported_length_remaining;
3071                 }
3072             }
3073         }
3074         break;
3075
3076         case 0x2211:
3077         {
3078             if(is_command)
3079             {
3080                 if(reported_length_remaining >= 4)
3081                 {
3082                     proto_tree_add_bitmask(command_tree, tvb, offset, hf_omron_data_type,
3083                         ett_omron_data_type, data_type_fields, FALSE);
3084                     proto_tree_add_item(command_tree, hf_omron_control_data, tvb, (offset+1), 1, FALSE);
3085                     proto_tree_add_item(command_tree, hf_omron_block_num, tvb, (offset+2), 2, FALSE);
3086                     proto_tree_add_item(command_tree, hf_omron_data, tvb, (offset+4), -1, FALSE);
3087                     offset = offset + reported_length_remaining;
3088                 }
3089             }
3090
3091             if(is_response)
3092             {
3093                 if(reported_length_remaining == 2)
3094                 {
3095                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
3096                     offset = offset + 2;
3097                 }
3098             }
3099         }
3100
3101         break;
3102
3103         case 0x2301:
3104         {
3105             if(is_command)
3106             {
3107                 if(reported_length_remaining >= 8)
3108                 {
3109                     proto_tree_add_item(command_tree, hf_omron_number_of_bits_flags, tvb, offset, 2, FALSE);
3110                     offset = offset + 2;
3111                     reported_length_remaining = reported_length_remaining - 2;
3112
3113                     while (reported_length_remaining >= 6)
3114                     {
3115                         proto_tree_add_item(command_tree, hf_omron_set_reset_specification, tvb, offset, 2, FALSE);
3116                         proto_tree_add_item(command_tree, hf_omron_command_memory_area_code, tvb, (offset+2), 1, FALSE);
3117                         proto_tree_add_item(command_tree, hf_omron_bit_flag, tvb, (offset+3), 3, FALSE);
3118
3119                         offset = offset + 6;
3120                         reported_length_remaining = reported_length_remaining - 6;
3121                     }
3122                 }
3123             }
3124
3125             if(is_response)
3126             {
3127                 if(reported_length_remaining == 2)
3128                 {
3129                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
3130                     offset = offset + 2;
3131                 }
3132             }
3133         }
3134         break;
3135
3136         case 0x2302:
3137         {
3138             /* command data length is 0 */
3139
3140             if(is_response)
3141             {
3142                 if(reported_length_remaining == 2)
3143                 {
3144                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
3145                     offset = offset + 2;
3146                 }
3147             }
3148
3149         }
3150         break;
3151
3152         case 0x230A:
3153         {
3154             if(is_command)
3155             {
3156                 if(reported_length_remaining == 6)
3157                 {
3158                     proto_tree_add_item(command_tree, hf_omron_command_memory_area_code, tvb, offset, 1, FALSE);
3159                     proto_tree_add_item(command_tree, hf_omron_transfer_beginning_address, tvb, (offset+1), 3, FALSE);
3160                     proto_tree_add_item(command_tree, hf_omron_num_unit_uint16, tvb, (offset+4), 2, FALSE);
3161                     offset = offset + 6;
3162                 }
3163             }
3164
3165             if(is_response)
3166             {
3167                 if(reported_length_remaining >= 8)
3168                 {
3169                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
3170                     proto_tree_add_item(command_tree, hf_omron_command_memory_area_code, tvb, (offset+2), 1, FALSE);
3171                     proto_tree_add_item(command_tree, hf_omron_transfer_beginning_address, tvb, (offset+3), 3, FALSE);
3172                     proto_tree_add_item(command_tree, hf_omron_num_unit_uint16, tvb, (offset+6), 2, FALSE);
3173                     proto_tree_add_item(command_tree, hf_omron_data, tvb, (offset+8), -1, FALSE);
3174                     offset = offset + reported_length_remaining;
3175                 }
3176             }
3177         }
3178         break;
3179
3180         case 0x2601:
3181         {
3182             if(is_command)
3183             {
3184                 if((reported_length_remaining > 0) && (reported_length_remaining <= 8))
3185                 {
3186                     proto_tree_add_item(command_tree, hf_omron_name_data, tvb, offset, -1, FALSE);
3187                     offset = offset + reported_length_remaining;
3188                 }
3189             }
3190
3191             if(is_response)
3192             {
3193                 if(reported_length_remaining == 2)
3194                 {
3195                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
3196                     offset = offset + 2;
3197                 }
3198             }
3199         }
3200         break;
3201
3202         case 0x2602:
3203         {
3204             /* command data length is 0 */
3205
3206             if(is_response)
3207             {
3208                 if(reported_length_remaining == 2)
3209                 {
3210                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
3211                     offset = offset + 2;
3212                 }
3213             }
3214         }
3215         break;
3216
3217         case 0x2603:
3218         {
3219             /* command data length is 0 */
3220
3221             if(is_response)
3222             {
3223                 if((reported_length_remaining > 2) && (reported_length_remaining <= (2+8)))
3224                 {
3225                     proto_tree_add_item(command_tree, hf_omron_response_code, tvb, offset, 2, FALSE);
3226                     proto_tree_add_item(command_tree, hf_omron_name_data, tvb, offset, -1, FALSE);
3227                     offset = offset + reported_length_remaining;
3228                }
3229             }
3230         }
3231         break;
3232
3233         default:
3234         { /* invalid command ?? */
3235             ;/* ??? dissector_bug ??*/
3236         }
3237         break;
3238
3239         } /* switch(command_code) */
3240
3241         if ((guint)offset != tvb_reported_length(tvb)) {
3242             expert_add_info_format(pinfo, omron_tree, PI_MALFORMED, PI_WARN, "Unexpected Length");
3243         }
3244
3245     } /* if(tree) */
3246
3247     return tvb_length(tvb);
3248 }
3249
3250 void
3251 proto_register_omron_fins(void)
3252 {
3253 #if 0
3254     module_t *omron_fins_module;
3255 #endif
3256
3257     /* Setup list of header fields */
3258
3259     static hf_register_info hf[] = {
3260         { &hf_omron_icf,
3261         { "OMRON ICF Field", "omron.icf", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
3262
3263         { &hf_omron_icf_gwb,
3264         { "Gateway bit", "omron.icf.gwb", FT_UINT8, BASE_HEX, VALS(icf_gw_vals), ICF_GW_MASK, NULL, HFILL }},
3265
3266         { &hf_omron_icf_dtb,
3267         { "Data Type bit", "omron.icf.dtb", FT_UINT8, BASE_HEX, VALS(icf_dtb_vals), ICF_DTB_MASK, NULL, HFILL }},
3268
3269         { &hf_omron_icf_rb0,
3270         { "Reserved bit 0", "omron.icf.rb0", FT_UINT8, BASE_HEX, NULL, ICF_RB0_MASK, NULL, HFILL }},
3271
3272         { &hf_omron_icf_rb1,
3273         { "Reserved bit 1", "omron.icf.rb1", FT_UINT8, BASE_HEX, NULL, ICF_RB1_MASK, NULL, HFILL }},
3274
3275         { &hf_omron_icf_rb2,
3276         { "Reserved bit 2", "omron.icf.rb2", FT_UINT8, BASE_HEX, NULL, ICF_RB2_MASK, NULL, HFILL }},
3277
3278         { &hf_omron_icf_rb3,
3279         { "Reserved bit 3", "omron.icf.rb3", FT_UINT8, BASE_HEX, NULL, ICF_RB3_MASK, NULL, HFILL }},
3280
3281         { &hf_omron_icf_rb4,
3282         { "Reserved bit 4", "omron.icf.rb4", FT_UINT8, BASE_HEX, NULL, ICF_RB4_MASK, NULL, HFILL }},
3283
3284         { &hf_omron_icf_rsb,
3285         { "Response setting bit", "omron.icf.rsb", FT_UINT8, BASE_HEX, VALS(icf_rsb_vals), ICF_RSB_MASK, NULL, HFILL }},
3286
3287         { &hf_omron_rsv,
3288         { "Reserved", "omron.rsv", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
3289
3290         { &hf_omron_gct,
3291         { "Gateway Count", "omron.gct", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
3292
3293         { &hf_omron_dna,
3294         { "Destination network address", "omron.dna", FT_UINT8, BASE_RANGE_STRING|BASE_HEX, RVALS(&omron_dna_range), 0x0, NULL, HFILL }},
3295
3296         { &hf_omron_da1,
3297         { "Destination node number", "omron.da1", FT_UINT8, BASE_RANGE_STRING|BASE_HEX, RVALS(&omron_da1_range), 0x0, NULL, HFILL }},
3298
3299         { &hf_omron_da2,
3300         { "Destination unit address", "omron.da2", FT_UINT8, BASE_RANGE_STRING|BASE_HEX, RVALS(&omron_da2_range), 0x0, NULL, HFILL }},
3301
3302         { &hf_omron_sna,
3303         { "Source network address", "omron.sna", FT_UINT8, BASE_RANGE_STRING|BASE_HEX, RVALS(&omron_sna_range), 0x0, NULL, HFILL }},
3304
3305         { &hf_omron_sa1,
3306         { "Source node number", "omron.sa1", FT_UINT8, BASE_RANGE_STRING|BASE_HEX, RVALS(&omron_sa1_range), 0x0, NULL, HFILL }},
3307
3308         { &hf_omron_sa2,
3309         { "Source unit address", "omron.sa2", FT_UINT8, BASE_RANGE_STRING|BASE_HEX, RVALS(&omron_sa2_range), 0x0, NULL, HFILL }},
3310
3311         { &hf_omron_sid,
3312         { "Service ID", "omron.sid", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
3313
3314         { &hf_omron_command,
3315         { "Command CODE", "omron.command", FT_UINT16, BASE_HEX, VALS(command_code_cv), 0x0, NULL, HFILL }},
3316
3317         { &hf_omron_command_memory_area_code,
3318         { "Memory Area Code", "omron.memory.area.read", FT_UINT8, BASE_HEX, VALS(memory_area_code_cv), 0x0, NULL, HFILL }},
3319
3320         { &hf_omron_response_code,
3321         { "Response code", "omron.response.code", FT_UINT16, BASE_HEX, VALS(response_codes), 0x0, NULL, HFILL }},