MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / dissectors / packet-sbus.c
bloba408d61e6f64d78bf9cf4e4c387ad5fae8f469b4
1 /* packet-sbus.c
2 * Routines for Ether-S-Bus dissection
3 * Copyright 2010, Christian Durrer <christian.durrer@sensemail.ch>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
29 #include <epan/packet.h>
30 #include <epan/conversation.h>
31 #include <epan/wmem/wmem.h>
32 #include <epan/expert.h>
34 /* Attribute values*/
35 #define SBUS_REQUEST 0x00
36 #define SBUS_RESPONSE 0x01
37 #define SBUS_ACKNAK 0x02
39 /*SBus command codes*/
40 #define SBUS_RD_COUNTER 0x00
41 #define SBUS_RD_DISPLAY_REGISTER 0x01
42 #define SBUS_RD_FLAG 0x02
43 #define SBUS_RD_INPUT 0x03
44 #define SBUS_RD_RTC 0x04
45 #define SBUS_RD_OUTPUT 0x05
46 #define SBUS_RD_REGISTER 0x06
47 #define SBUS_RD_TIMER 0x07
48 #define SBUS_WR_COUNTER 0x0A
49 #define SBUS_WR_FLAG 0x0B
50 #define SBUS_WR_RTC 0x0C
51 #define SBUS_WR_OUTPUT 0x0D
52 #define SBUS_WR_REGISTER 0x0E
53 #define SBUS_WR_TIMER 0x0F
54 #define SBUS_RDWR_MULTI_MEDIAS 0x13
55 #define SBUS_RD_PCD_STATUS_CPU0 0x14
56 #define SBUS_RD_PCD_STATUS_CPU1 0x15
57 #define SBUS_RD_PCD_STATUS_CPU2 0x16
58 #define SBUS_RD_PCD_STATUS_CPU3 0x17
59 #define SBUS_RD_PCD_STATUS_CPU4 0x18
60 #define SBUS_RD_PCD_STATUS_CPU5 0x19
61 #define SBUS_RD_PCD_STATUS_CPU6 0x1A
62 #define SBUS_RD_PCD_STATUS_OWN 0x1B
63 #define SBUS_RD_SBUS_STN_NBR 0x1D
64 #define SBUS_RD_USER_MEMORY 0x1E
65 #define SBUS_RD_PROGRAM_LINE 0x1F
66 #define SBUS_RD_PROGRAM_VERSION 0x20
67 #define SBUS_RD_TEXT 0x21
68 #define SBUS_RD_ACTIVE_TRANSITION 0x22
69 #define SBUS_WR_USER_MEMORY 0x23
70 #define SBUS_WR_PROGRAM_LINE 0x24
71 #define SBUS_WR_TEXT 0x25
72 #define SBUS_RUN_PROCEDURE_CPU0 0x28
73 #define SBUS_RUN_PROCEDURE_CPU1 0x29
74 #define SBUS_RUN_PROCEDURE_CPU2 0x2A
75 #define SBUS_RUN_PROCEDURE_CPU3 0x2B
76 #define SBUS_RUN_PROCEDURE_CPU4 0x2C
77 #define SBUS_RUN_PROCEDURE_CPU5 0x2D
78 #define SBUS_RUN_PROCEDURE_CPU6 0x2E
79 #define SBUS_RUN_PROCEDURE_OWN 0x2F
80 #define SBUS_RUN_PROCEDURE_ALL 0x30
81 #define SBUS_RESTART_COLD_CPU1 0x32
82 #define SBUS_RESTART_COLD_CPU2 0x33
83 #define SBUS_RESTART_COLD_CPU3 0x34
84 #define SBUS_RESTART_COLD_CPU4 0x35
85 #define SBUS_RESTART_COLD_CPU5 0x36
86 #define SBUS_RESTART_COLD_CPU6 0x37
87 #define SBUS_RESTART_COLD_OWN 0x38
88 #define SBUS_RESTART_COLD_ALL 0x39
89 #define SBUS_STOP_PROCEDURE_CPU0 0x3C
90 #define SBUS_STOP_PROCEDURE_CPU1 0x3D
91 #define SBUS_STOP_PROCEDURE_CPU2 0x3E
92 #define SBUS_STOP_PROCEDURE_CPU3 0x3F
93 #define SBUS_STOP_PROCEDURE_CPU4 0x40
94 #define SBUS_STOP_PROCEDURE_CPU5 0x41
95 #define SBUS_STOP_PROCEDURE_CPU6 0x42
96 #define SBUS_STOP_PROCEDURE_OWN 0x43
97 #define SBUS_STOP_PROCEDURE_ALL 0x44
98 #define SBUS_RD_STATUSFLAG_ACCU 0x46
99 #define SBUS_RD_BYTE 0x47
100 #define SBUS_RD_HALT_FAILURE_REG 0x48
101 #define SBUS_RD_INDEX_REGISTER 0x49
102 #define SBUS_RD_INSTRUCTION_POINTER 0x4A
103 #define SBUS_FIND_HISTORY 0x4B
104 #define SBUS_WR_STATUSFLAG_ACCU 0x50
105 #define SBUS_WR_BYTE 0x51
106 #define SBUS_WR_INDEX_REGISTER 0x52
107 #define SBUS_WR_INSTRUCTION_POINTER 0x53
108 #define SBUS_CLEAR_ALL 0x5A
109 #define SBUS_CLEAR_FLAGS 0x5B
110 #define SBUS_CLEAR_OUTPUTS 0x5C
111 #define SBUS_CLEAR_REGISTERS 0x5D
112 #define SBUS_CLEAR_TIMERS 0x5E
113 #define SBUS_RESTART_WARM_CPU1 0x64
114 #define SBUS_RESTART_WARM_CPU2 0x65
115 #define SBUS_RESTART_WARM_CPU3 0x66
116 #define SBUS_RESTART_WARM_CPU4 0x67
117 #define SBUS_RESTART_WARM_CPU5 0x68
118 #define SBUS_RESTART_WARM_CPU6 0x69
119 #define SBUS_RESTART_WARM_OWN 0x6A
120 #define SBUS_RESTART_WARM_ALL 0x6B
121 #define SBUS_CHANGE_BLOCK 0x6E
122 #define SBUS_CLEAR_HISTORY_FAILURE 0x6F
123 #define SBUS_DELETE_PROGRAM_LINE 0x70
124 #define SBUS_GO_CONDITIONAL 0x71
125 #define SBUS_INSERT_PROGRAM_LINE 0x72
126 #define SBUS_LOCAL_CYCLE 0x73
127 #define SBUS_ALL_CYCLES 0x74
128 #define SBUS_MAKE_TEXT 0x75
129 #define SBUS_EXECUTE_SINGLE_INSTR 0x76
130 #define SBUS_SINGLE_STEP 0x77
131 #define SBUS_XOB_17_INTERRUPT 0x82
132 #define SBUS_XOB_18_INTERRUPT 0x83
133 #define SBUS_XOB_19_INTERRUPT 0x84
134 #define SBUS_RD_HANGUP_TIMEOUT 0x91
135 #define SBUS_RD_DATA_BLOCK 0x96
136 #define SBUS_WR_DATA_BLOCK 0x97
137 #define SBUS_MAKE_DATA_BLOCK 0x98
138 #define SBUS_CLEAR_DATA_BLOCK 0x99
139 #define SBUS_CLEAR_TEXT 0x9A
140 #define SBUS_RD_BLOCK_ADDRESSES 0x9B
141 #define SBUS_RD_BLOCK_SIZES 0x9C
142 #define SBUS_RD_CURRENT_BLOCK 0x9D
143 #define SBUS_RD_CALL_STACK 0x9E
144 #define SBUS_RD_DBX 0x9F
145 #define SBUS_RD_USER_EEPROM_REGISTER 0xA1
146 #define SBUS_WR_USER_EEPROM_REGISTER 0xA3
147 #define SBUS_ERASE_FLASH 0xA5
148 #define SBUS_RESTART_COLD_FLAG 0xA6
149 #define SBUS_WR_SYSTEM_BUFFER 0xA7
150 #define SBUS_RD_SYSTEM_BUFFER 0xA8
151 #define SBUS_RD_WR_PCD_BLOCK 0xA9
152 #define SBUS_GET_DIAGNOSTIC 0xAA
153 #define SBUS_RD_SYSTEM_INFORMATION 0xAB
154 #define SBUS_CHANGE_BLOCKS_ON_RUN 0xAC
155 #define SBUS_FLASHCARD_TELEGRAM 0xAD
156 #define SBUS_DOWNLOAD_FIRMWARE 0xAE
157 #define SBUS_WEB_SERVER_SERIAL_COMM 0xAF
159 /* Bitfield in the arithmetic flags and accu*/
160 #define F_ACCU (1<<0) /* Accumulator of PCD */
161 #define F_ERROR (1<<1) /* Error flag of PCD */
162 #define F_NEGATIVE (1<<2) /* Negative arithmetic status flag */
163 #define F_ZERO (1<<3) /* Zero arithmetic status flag */
165 /* Bitfield in the system information*/
166 /*#define F_EMPTY (1<<0) always 0 */
167 #define F_MEMSIZE (1<<1) /* Memory size information */
168 #define F_TRACE (1<<2) /* Trace buffer feature */
169 #define F_INFO_B1 (1<<3) /* EEPROM information of slot B1 */
170 #define F_INFO_B2 (1<<4) /* EEPROM information of slot B2 */
171 #define F_PGU_BAUD (1<<5) /* PGU baudrate can be switched */
174 /* Read/write block command codes*/
175 #define SBUS_WR_START_OF_STREAM 0x00
176 #define SBUS_WR_BLOCK_DATA_STREAM 0x01
177 #define SBUS_WR_BLOCK_END_OF_STREAM 0x02
178 #define SBUS_WR_ABORT_BLOCK_STREAM 0x07
179 #define SBUS_WR_BLOCK_DATA_BYTES 0x08
180 #define SBUS_RD_BLOCK_START_OF_STREAM 0X10
181 #define SBUS_RD_BLOCK_DATA_STREAM 0x11
182 #define SBUS_RD_ABORT_BLOCK_STREAM 0x17
183 #define SBUS_RD_BLOCK_DATA_BYTES 0x18
184 #define SBUS_DELETE_BLOCK 0x20
185 #define SBUS_GET_BLOCK_SIZE 0x21
186 #define SBUS_GET_PROGRAM_BLOCK_LIST 0x22
188 /* Read/write block types*/
189 #define SBUS_RD_WR_CONFIGURATION_FILE 0x20
190 #define SBUS_RD_WR_PROGRAM_BLOCK_FILE 0x21
191 #define SBUS_RD_WR_UNKNOWN_BLOCK_TYPE 0x83
193 /* Read/write block error codes*/
194 #define SBUS_RD_WR_NAK 0x80
195 #define SBUS_RD_WR_NAK_INVALID_SIZE 0x8A
197 /* Initialize the protocol and registered fields */
198 static int proto_sbus = -1;
199 static int hf_sbus_length = -1;
200 static int hf_sbus_version = -1;
201 static int hf_sbus_protocol = -1;
202 static int hf_sbus_sequence = -1;
203 static int hf_sbus_attribut = -1;
204 static int hf_sbus_dest = -1;
205 static int hf_sbus_address = -1;
206 static int hf_sbus_command = -1;
207 static int hf_sbus_command_extension = -1;
208 static int hf_sbus_rcount = -1;
209 static int hf_sbus_wcount = -1;
210 static int hf_sbus_wcount_calculated = -1;
211 static int hf_sbus_fio_count = -1;
212 static int hf_sbus_addr_rtc = -1;
213 static int hf_sbus_addr_iof = -1;
214 static int hf_sbus_addr_eeprom = -1;
215 static int hf_sbus_addr_prog = -1;
216 static int hf_sbus_addr_68k = -1;
217 static int hf_sbus_block_type = -1;
218 static int hf_sbus_block_nr = -1;
219 static int hf_sbus_nbr_elements = -1;
220 static int hf_sbus_display_register = -1;
221 static int hf_sbus_data_rtc = -1;
222 static int hf_sbus_data_byte = -1;
223 static int hf_sbus_data_byte_hex = -1;
224 static int hf_sbus_data_iof = -1;
225 static int hf_sbus_cpu_type = -1;
226 static int hf_sbus_fw_version = -1;
227 static int hf_sbus_sysinfo_nr = -1;
228 static int hf_sbus_sysinfo0_1 = -1;
229 static int hf_sbus_sysinfo0_2 = -1;
230 static int hf_sbus_sysinfo0_3 = -1;
231 static int hf_sbus_sysinfo0_4 = -1;
232 static int hf_sbus_sysinfo0_5 = -1;
233 /* static int hf_sbus_sysinfo_length = -1; */
234 /* static int hf_sbus_f_module_type = -1; */
235 /* static int hf_sbus_harware_version = -1; */
236 /* static int hf_sbus_hardware_modification = -1; */
237 /* static int hf_sbus_various = -1; */
238 static int hf_sbus_acknackcode = -1;
239 static int hf_sbus_cpu_status = -1;
240 static int hf_sbus_week_day = -1;
241 static int hf_sbus_date = -1;
242 static int hf_sbus_time = -1;
243 static int hf_sbus_crc = -1;
244 static int hf_sbus_crc_bad = -1;
245 static int hf_sbus_flags_accu = -1;
246 static int hf_sbus_flags_error = -1;
247 static int hf_sbus_flags_negative = -1;
248 static int hf_sbus_flags_zero = -1;
249 /* Web server telegram */
250 static int hf_sbus_web_size = -1;
251 static int hf_sbus_web_aid = -1;
252 static int hf_sbus_web_seq = -1;
253 /* Read/Write block telegram*/
254 static int hf_sbus_rdwr_block_length = -1;
255 static int hf_sbus_rdwr_block_length_ext = -1;
256 static int hf_sbus_rdwr_telegram_type = -1;
257 static int hf_sbus_rdwr_telegram_sequence = -1;
258 static int hf_sbus_rdwr_block_size = -1;
259 static int hf_sbus_rdwr_block_addr = -1;
260 static int hf_sbus_rdwr_file_name = -1;
261 static int hf_sbus_rdwr_list_type = -1;
262 static int hf_sbus_rdwr_acknakcode = -1;
263 /* Request-Response tracking */
264 static int hf_sbus_response_in = -1;
265 static int hf_sbus_response_to = -1;
266 static int hf_sbus_response_time = -1;
267 static int hf_sbus_timeout = -1;
268 static int hf_sbus_request_in = -1;
270 /* Initialize the subtree pointers */
271 static gint ett_sbus = -1;
272 static gint ett_sbus_ether = -1;
273 static gint ett_sbus_data = -1;
275 static expert_field ei_sbus_retry = EI_INIT;
276 static expert_field ei_sbus_telegram_not_acked = EI_INIT;
277 static expert_field ei_sbus_crc_bad = EI_INIT;
279 /* True/False strings*/
280 static const true_false_string tfs_sbus_flags= {
281 "Is high",
282 "Is low"
285 static const true_false_string tfs_sbus_present= {
286 "Is present",
287 "Is not present"
290 /* value to string definitions*/
291 /* telegram types*/
292 static const value_string sbus_att_vals[] = {
293 {0, "Request"},
294 {1, "Response"},
295 {2, "ACK/NAK"},
296 {0, NULL}
298 /* Block types*/
299 static const value_string sbus_block_types[] = {
300 {0x00, "COB"}, /* Cyclic organization block */
301 {0x01, "XOB"}, /* Exception organization block */
302 {0x02, "PB"}, /* Program block */
303 {0x03, "FB"}, /* Function block */
304 {0x04, "ST"}, /* Step of Graftec structure*/
305 {0x05, "TR"}, /* Transition of Graftec structure*/
306 {0x04, "TEXT"}, /* Text*/
307 {0x05, "DB"}, /* Data Block*/
308 {0x08, "SB"}, /* Sequential Block (Graftec)*/
309 {0x09, "DBX"}, /* Special Data Block*/
310 {0x10, "BACnet"}, /* BACnet configuration block */
311 {0x11, "CANopen"}, /* CANopen configuration */
312 {0x12, "LONIP"}, /* LONIP configuration */
313 {0x20, "Configuration file"}, /* LONIP configuration */
314 {0x21, "Program block file"}, /* LONIP configuration */
315 {0xFE, "All configuration blocks"}, /* all configuration blocks (delete blocks only) */
316 {0xFF, "All blocks"}, /* all blocks (incl. program blocks) (delete blocks only) */
317 {0, NULL}
319 /* ACK NAK values*/
320 static const value_string sbus_CPU_status[] = {
321 {0x43, "C"},
322 {0x44, "D"},
323 {0x48, "Halt"},
324 {0x52, "Run"},
325 {0x53, "Stop"},
326 {0x58, "X, Exceptional Intermediate Status (MODEMS+)"},
327 {0, NULL}
329 /* CPU status*/
330 static const value_string sbus_ack_nak_vals[] = {
331 {0, "ACK (Acknowledged)"},
332 {1, "NAK, no reason specified"},
333 {2, "NAK, because of password"},
334 {3, "NAK, PGU port is in reduced protocol"},
335 {4, "NAK, PGU port is already used"},
336 {0, NULL}
338 /* S-Bus commands*/
339 static const value_string sbus_command_vals[] = {
340 {0x00, "Read counter(s)"},
341 {0x01, "Read display register"},
342 {0x02, "Read flag(s)"},
343 {0x03, "Read input(s)"},
344 {0x04, "Read real time clock"},
345 {0x05, "Read output(s)"},
346 {0x06, "Read register(s)"},
347 {0x07, "Read timer(s)"},
348 {0x0A, "Write counter(s)"},
349 {0x0B, "Write flag(s)"},
350 {0x0C, "Write real time clock"},
351 {0x0D, "Write output(s)"},
352 {0x0E, "Write register(s)"},
353 {0x0F, "Write timer(s)"},
354 {0x14, "Read PCD status, CPU 0"},
355 {0x15, "Read PCD status, CPU 1"},
356 {0x16, "Read PCD status, CPU 2"},
357 {0x17, "Read PCD status, CPU 3"},
358 {0x18, "Read PCD status, CPU 4"},
359 {0x19, "Read PCD status, CPU 5"},
360 {0x1A, "Read PCD status, CPU 6"},
361 {0x1B, "Read PCD status (own)"},
362 {0x1D, "Read S-Bus station number"},
363 {0x1E, "Read user memory*"},
364 {0x1F, "Read program line*"},
365 {0x20, "Read firmware version"},
366 {0x21, "Read text*"},
367 {0x22, "Read active transition*"},
368 {0x23, "Write user memory*"},
369 {0x24, "Write program line*"},
370 {0x25, "Write text*"},
371 {0x28, "Run procedure*, CPU 0"},
372 {0x29, "Run procedure*, CPU 1"},
373 {0x2A, "Run procedure*, CPU 2"},
374 {0x2B, "Run procedure*, CPU 3"},
375 {0x2C, "Run procedure*, CPU 4"},
376 {0x2D, "Run procedure*, CPU 5"},
377 {0x2E, "Run procedure*, CPU 6"},
378 {0x2F, "Run procedure* (own CPU)"},
379 {0x30, "Run procedure* (All CPUs)"},
380 {0x32, "Restart cold CPU 1*"},
381 {0x33, "Restart cold CPU 2*"},
382 {0x34, "Restart cold CPU 3*"},
383 {0x35, "Restart cold CPU 4*"},
384 {0x36, "Restart cold CPU 5*"},
385 {0x37, "Restart cold CPU 6*"},
386 {0x38, "Restart cold own CPU*"},
387 {0x39, "Restart cold all CPUs*"},
388 {0x3C, "Stop procedure*, CPU 0"},
389 {0x3D, "Stop procedure*, CPU 1"},
390 {0x3E, "Stop procedure*, CPU 2"},
391 {0x3F, "Stop procedure*, CPU 3"},
392 {0x40, "Stop procedure*, CPU 4"},
393 {0x41, "Stop procedure*, CPU 5"},
394 {0x42, "Stop procedure*, CPU 6"},
395 {0x43, "Stop procedure*, (own CPU)"},
396 {0x44, "Stop procedure*, (All CPUs)"},
397 {0x46, "Read arithmetic status and ACCU*"},
398 {0x47, "Read byte"},
399 {0x48, "Read halt failure register*"},
400 {0x49, "Read index register*"},
401 {0x4A, "Read instruction pointer*"},
402 {0x4B, "Find history*"},
403 {0x50, "Write arithmetic staus and ACCU*"},
404 {0x51, "Write byte*"},
405 {0x52, "Write index register"},
406 {0x53, "Write instruction pointer*"},
407 {0x5A, "Clear all (F, O, R, T)*"},
408 {0x5B, "Clear flags*"},
409 {0x5C, "Clear outputs*"},
410 {0x5D, "Clear registers*"},
411 {0x5E, "Clear timers*"},
412 {0x64, "Restart warm CPU 1*"},
413 {0x65, "Restart warm CPU 2*"},
414 {0x66, "Restart warm CPU 3*"},
415 {0x67, "Restart warm CPU 4*"},
416 {0x68, "Restart warm CPU 5*"},
417 {0x69, "Restart warm CPU 6*"},
418 {0x6A, "Restart warm (own CPU)*"},
419 {0x6B, "Restart warm (All CPUs)*"},
420 {0x6E, "Change block*"},
421 {0x6F, "Clear history failure*"},
422 {0x70, "Delete program line*"},
423 {0x71, "Go conditional*"},
424 {0x72, "Insert program line*"},
425 {0x73, "Local cycles*"},
426 {0x74, "All cycles*"},
427 {0x75, "Make text*"},
428 {0x76, "Execute single instruction*"},
429 {0x77, "Single step*"},
430 {0x82, "XOB 17 interrupt"},
431 {0x83, "XOB 18 interrupt"},
432 {0x84, "XOB 19 interrupt"},
433 {0x91, "Read hangup timeout"},
434 {0x96, "Read data block"},
435 {0x97, "Write data block"},
436 {0x98, "Make data block*"},
437 {0x99, "Clear data block*"},
438 {0x9A, "Clear text*"},
439 {0x9B, "Read block address"},
440 {0x9C, "Read block sizes"},
441 {0x9D, "Read current block*"},
442 {0x9E, "Read call stack*"},
443 {0x9F, "Read DBX"},
444 {0xA1, "Read user EEPROM register"},
445 {0xA3, "Write user EEPROM register"},
446 {0xA5, "Erase flash*"},
447 {0xA6, "Restart cold flag*"},
448 {0xA7, "Write system buffer"},
449 {0xA8, "Read system buffer"},
450 {0xA9, "Read/write block data*"},
451 {0xAA, "Get diagnostic*"},
452 {0xAB, "Read system information*"},
453 {0xAC, "Changes blocks on run*"},
454 {0xAD, "Flashcard telegram*"},
455 {0xAE, "Download FW*"},
456 {0xAF, "Web server serial communication*"},
457 {0, NULL}
460 static const value_string webserver_aid_vals[] = {
461 {0x01, "Partial request"},
462 {0x02, "Request end"},
463 {0x07, "Get Data"},
464 {0x10, "Transfer OK"},
465 {0x11, "Partial answer"},
466 {0x12, "Last part of answer"},
467 {0x13, "Server not ready"},
468 {0, NULL}
470 static const value_string rdwrblock_vals[] = {
471 {0x00, "WR block start of stream"},
472 {0x01, "WR block data stream"},
473 {0x02, "WR block end of stream"},
474 {0x07, "Abort block WR stream"},
475 {0x08, "WR block data"},
476 {0x10, "RD block start of stream"},
477 {0x11, "RD block data stream"},
478 {0x17, "Abort block RD stream"},
479 {0x18, "RD block data"},
480 {0x20, "Delete block"},
481 {0x21, "Get block size"},
482 {0x22, "Get program block list"},
483 {0, NULL}
486 static const value_string rdwrblock_sts[] = {
487 {0x00, "ACK (Acknowledged)"},
488 {0x01, "Data"},
489 {0x02, "Busy"},
490 {0x03, "End of stream"},
491 {0x04, "Data EOF reached"},
492 {0x80, "NAK"},
493 {0x81, "NAK, unknown Tlg_Type"},
494 {0x82, "NAK, not supported Tlg_Type"},
495 {0x83, "NAK, unknown Block Type"},
496 {0x84, "NAK, out of sequence"},
497 {0x85, "NAK, not supported Block number"},
498 {0x86, "NAK, Block Size invalid (to big)"},
499 {0x87, "NAK, Block Address invalid"},
500 {0x88, "NAK, CRC invalid"},
501 {0x89, "NAK, invalid status"},
502 {0x8A, "NAK, invalid command size (w-count)"},
503 {0xFF, "Abort (stream)"},
504 {0, NULL}
507 static const value_string rdwrblock_list_type_vals[] = {
508 {0x40, "Start request of program block"},
509 {0x41, "Get next program block"},
510 {0xFF, "Abort get list"},
511 {0, NULL}
514 static const guint crc_table[] = {
515 0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
516 0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
517 0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
518 0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
519 0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
520 0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
521 0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
522 0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
523 0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
524 0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
525 0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
526 0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
527 0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
528 0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
529 0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
530 0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
533 /* Conversion values passing structure*/
534 typedef struct {
535 guint32 conversation; /*Conversation ID*/
536 guint16 sequence; /*Sequence number of request telegram*/
537 } sbus_request_key;
539 typedef struct {
540 guint8 cmd_code; /*command code from request*/
541 guint8 count; /*rcount value*/
542 guint8 sysinfo; /*system information number*/
543 guint8 block_tlg; /*telegram type of RD/WR block telegrams*/
544 guint8 retry_count; /*number of retries*/
545 guint32 req_frame; /*frame number of last request*/
546 guint32 resp_frame; /*frame number of response*/
547 nstime_t req_time; /*time of the last request*/
548 } sbus_request_val;
550 /* The hash structure (for conversations)*/
551 static GHashTable *sbus_request_hash = NULL;
553 static guint crc_calc (guint crc, guint val)
555 int indx;
556 guint ncrc;
558 indx = (((crc >> 8) ^ val) & 0xff);
559 ncrc = crc_table[indx] ^ ((crc << 8) & 0xffff);
561 return ncrc;
564 /* Hash functions*/
565 static gint sbus_equal(gconstpointer v, gconstpointer w)
567 sbus_request_key *v1 = (sbus_request_key *)v;
568 sbus_request_key *v2 = (sbus_request_key *)w;
570 if (v1->conversation == v2->conversation &&
571 v1->sequence == v2->sequence) {
572 return 1;
574 return 0;
577 static guint sbus_hash(gconstpointer v)
579 sbus_request_key *key = (sbus_request_key *)v;
580 guint val;
581 val = key->conversation + key->sequence;
582 return val;
585 /*Protocol initialisation*/
586 static void sbus_init_protocol(void){
587 if (sbus_request_hash){
588 g_hash_table_destroy(sbus_request_hash);
590 sbus_request_hash = g_hash_table_new(sbus_hash, sbus_equal);
593 /* check whether the packet looks like SBUS or not */
594 static gboolean
595 is_sbus_pdu(tvbuff_t *tvb)
597 guint32 length;
599 /* we need at least 8 bytes to determine whether this is sbus or
600 not*/
601 if(tvb_length(tvb)<8){
602 return FALSE;
605 /* the length must be >= 8 bytes to accommodate the header,
606 it also must be <65536 to fit inside a udp packet
608 length=tvb_get_ntohl(tvb, 0);
609 if ( (length<8) || (length>65535) ) {
610 return FALSE;
612 if (tvb_reported_length(tvb) != length) {
613 return FALSE;
615 /* First four byte indicate the length which must be at least 12 bytes*/
616 if (tvb_get_ntohl(tvb, 0) < 12) {
617 return (FALSE);
619 /* Fifth byte indicates protocol version which can be 0 or 1*/
620 if (tvb_get_guint8(tvb, 4) > 0x01) {
621 return (FALSE);
623 /* Sixth byte indicates protocol type and must be 0*/
624 if ( tvb_get_guint8(tvb, 5) > 0x01 ) {
625 return (FALSE);
627 /* Seventh and eigth byte indicates the packet sequence number and can
628 be 0 to 65565 (--> check does not make sense)*/
629 /* Ninth byte the "attributes character" and must be either 0, 1 or 2
630 (request, response or ACK/NAK)*/
631 if (tvb_get_guint8(tvb, 8) > 0x02 ) {
632 return (FALSE);
634 return TRUE;
637 /*Dissect the telegram*/
638 static int
639 dissect_sbus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
642 /* Set up structures needed to add the protocol subtree and manage it */
643 proto_item *ti, *et, *dt, *hi, *cs;
644 proto_tree *sbus_tree, *ethsbus_tree, *sbusdata_tree;
646 gint i; /*for CRC calculation*/
647 gint j; /*for CRC calculation*/
648 gint offset;
649 gint sbus_eth_len;
650 guint sbus_crc_calc;
651 guint8 sbus_attribut;
652 guint8 sbus_media_cnt;
653 guint8 sbus_fio_cnt;
654 guint8 sbus_cmd_code;
655 guint8 sbus_web_size;
656 guint8 sbus_web_aid;
657 guint8 sbus_web_seq;
658 guint8 sbus_rdwr_type;
659 guint8 sbus_rdwr_sequence;
660 guint8 sbus_rdwr_block_tlg;
661 guint8 sbus_rdwr_block_type;
662 guint8 sbus_rdwr_ack_nak;
663 guint8 sbus_quint8_helper0;
664 guint32 sbus_binarymasked;
665 guint32 sbus_binaries;
666 guint16 sbus_ack_code;
667 guint32 sbus_show_bin;
668 guint32 sbus_rdwr_length;
669 guint32 sbus_helper;
670 guint32 sbus_helper1;
671 guint32 sbus_helper2;
672 char *tmp_string;
673 nstime_t ns; /*we use this for the response time*/
675 /* Set up conversations*/
676 conversation_t *conversation = NULL;
677 sbus_request_key request_key, *new_request_key;
678 sbus_request_val *request_val = NULL;
680 /* does this look like an sbus pdu? */
681 if(!is_sbus_pdu(tvb)){
682 return 0;
685 conversation = find_or_create_conversation(pinfo);
687 request_key.conversation = conversation->index;
688 request_key.sequence = tvb_get_ntohs(tvb,6);
690 request_val = (sbus_request_val *) g_hash_table_lookup(sbus_request_hash,
691 &request_key);
692 /*Get type of telegram for finding retries
693 *As we are storing the info in a hash table we need to update the info
694 *also in case this is no retry*/
695 sbus_attribut = tvb_get_guint8(tvb,8);
696 if (request_val && sbus_attribut == SBUS_REQUEST) {
697 if (request_val->req_frame < pinfo->fd->num){ /*a retry; req_frame smaller this frame*/
698 request_val->retry_count +=1;
700 else { /*we have a conversation but this is not a retry so we store the packet info*/
701 request_val->retry_count = 0;
702 request_val->req_frame = pinfo->fd->num; /*store actual frame nr.*/
703 request_val->req_time = pinfo->fd->abs_ts;
706 if (request_val && (sbus_attribut == SBUS_RESPONSE ||
707 sbus_attribut == SBUS_ACKNAK)) { /*a response*/
708 request_val->resp_frame = pinfo->fd->num; /*so store this frame nr.*/
710 /* Only allocate a new hash element when it's a request*/
711 sbus_attribut = tvb_get_guint8(tvb,8);
713 if ( !request_val && sbus_attribut == 0 ) {/* request telegram */
714 new_request_key = wmem_new(wmem_file_scope(), sbus_request_key);
715 *new_request_key = request_key;
717 request_val = wmem_new(wmem_file_scope(), sbus_request_val);
718 request_val->cmd_code=tvb_get_guint8(tvb,10);
719 request_val->retry_count=0;
720 request_val->req_frame = pinfo->fd->num; /*store actual frame nr.*/
721 request_val->req_time = pinfo->fd->abs_ts;
722 request_val->resp_frame = 0; /*response frame is not known yet*/
724 if (((request_val->cmd_code) == SBUS_RD_USER_EEPROM_REGISTER) ||
725 ((request_val->cmd_code) == SBUS_WR_USER_EEPROM_REGISTER)) {
726 request_val->count=((tvb_get_guint8(tvb,12))+1);
727 } else {
728 request_val->count=((tvb_get_guint8(tvb,11))+1);
731 /*Enter system info or telegram type (for rd/wr block telegrams)*/
732 if ((request_val->cmd_code) == SBUS_RD_SYSTEM_INFORMATION) {
733 request_val->sysinfo=(tvb_get_guint8(tvb,12));
734 request_val->block_tlg=0x0;
735 } else if ((request_val->cmd_code) == SBUS_RD_WR_PCD_BLOCK) {
736 request_val->sysinfo=0x0;
737 request_val->block_tlg=(tvb_get_guint8(tvb,12));
738 } else {
739 request_val->sysinfo=0x0;
740 request_val->block_tlg=0x0;
743 g_hash_table_insert(sbus_request_hash, new_request_key, request_val);
745 /* End of attaching data to hash table*/
747 /* Make entries in Protocol column and Info column on summary display */
748 col_set_str(pinfo->cinfo, COL_PROTOCOL, "S-Bus");
750 col_clear(pinfo->cinfo, COL_INFO);
751 offset = 0;
753 switch (sbus_attribut){
754 case SBUS_REQUEST:
755 sbus_cmd_code = tvb_get_guint8(tvb,10);
756 switch (sbus_cmd_code){
757 case SBUS_WEB_SERVER_SERIAL_COMM:
758 /* Special treatment of web server request
759 * as is is very helpful to see more information in the packetlist */
760 sbus_web_aid = tvb_get_guint8(tvb,12);
761 sbus_web_seq = tvb_get_guint8(tvb,13);
762 col_add_fstr(pinfo->cinfo, COL_INFO,
763 "Web Server Request: %s (Seq No: %d)",
764 val_to_str_const(sbus_web_aid,
765 webserver_aid_vals, "Unknown Request!"),
766 sbus_web_seq);
767 break;
768 case SBUS_RD_WR_PCD_BLOCK:
769 sbus_rdwr_type = tvb_get_guint8(tvb, 12);
770 col_add_fstr( pinfo->cinfo, COL_INFO,
771 "Request: %s", val_to_str_const( sbus_rdwr_type, rdwrblock_vals,
772 "This RD/WR block telegram is not implemented"));
773 /* Add name of file to be written in case of start of file stream */
774 if (sbus_rdwr_type == SBUS_WR_START_OF_STREAM) {
775 sbus_rdwr_block_type = tvb_get_guint8(tvb, 14);
776 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
777 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
778 sbus_quint8_helper0=0;
779 for (i=19; i<43; i++) { /*max length is 24 chars*/
780 /*find zero-termination of string*/
781 if ((tvb_get_guint8(tvb, i)) == 0x00) {
782 break;
784 sbus_quint8_helper0 += 1;
786 tmp_string = tvb_get_string(wmem_packet_scope(), tvb , 19,
787 sbus_quint8_helper0);
788 col_append_fstr(pinfo->cinfo, COL_INFO,
789 ": (File: %s)", tmp_string);
791 } else if (sbus_rdwr_type == SBUS_RD_BLOCK_START_OF_STREAM) {
792 sbus_rdwr_block_type = tvb_get_guint8(tvb, 14);
793 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
794 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
795 sbus_quint8_helper0=0;
796 for (i=15; i<39; i++) { /*max length is 24 chars*/
797 /*find zero-termination of string*/
798 if ((tvb_get_guint8(tvb, i)) == 0x00) {
799 break;
801 sbus_quint8_helper0 += 1;
803 tmp_string = tvb_get_string(wmem_packet_scope(), tvb , 15,
804 sbus_quint8_helper0);
805 col_append_fstr(pinfo->cinfo, COL_INFO,
806 ": (File: %s)", tmp_string);
810 break;
813 default:
814 /* All other requests */
815 col_add_fstr(pinfo->cinfo, COL_INFO,
816 "Request: %s", val_to_str_const(sbus_cmd_code,
817 sbus_command_vals, "Unknown Command!"));
818 break;
820 /*mark retries*/
821 if (request_val->retry_count>0) {
822 col_append_str(pinfo->cinfo, COL_INFO,
823 " (Retry)");
824 } /*no retry number as it is not always correctly calculated*/
825 break;
827 case SBUS_RESPONSE:
828 /* Special treatment of web server request
829 * as is is very helpful to see more information in the packetlist */
830 if (request_val && ((request_val->cmd_code) == SBUS_WEB_SERVER_SERIAL_COMM)) {
831 sbus_web_size = tvb_get_guint8(tvb,9);
832 sbus_web_aid = tvb_get_guint8(tvb,10);
833 col_add_fstr(pinfo->cinfo, COL_INFO,
834 "Response: %s",
835 val_to_str_const(sbus_web_aid,
836 webserver_aid_vals, "Unknown Request!"));
837 if (sbus_web_size > 1) {
838 sbus_web_seq = tvb_get_guint8(tvb,11);
839 col_append_fstr(pinfo->cinfo, COL_INFO,
840 " (Seq No: %d)",
841 sbus_web_seq);
843 } else if (request_val && ((request_val->cmd_code) == SBUS_RD_WR_PCD_BLOCK)) {
844 /* Treat the ACK/NAK telgrams in a special way*/
845 switch (request_val->block_tlg) {
846 case SBUS_WR_START_OF_STREAM:
847 case SBUS_WR_BLOCK_DATA_STREAM:
848 case SBUS_WR_BLOCK_END_OF_STREAM:
849 case SBUS_WR_ABORT_BLOCK_STREAM:
850 case SBUS_WR_BLOCK_DATA_BYTES:
851 case SBUS_DELETE_BLOCK:
852 case SBUS_RD_ABORT_BLOCK_STREAM:
853 sbus_rdwr_ack_nak = tvb_get_guint8(tvb, 10);
854 col_add_fstr( pinfo->cinfo, COL_INFO,
855 "Response: %s", val_to_str_const(sbus_rdwr_ack_nak,
856 rdwrblock_sts, "Unknown response!"));
857 break;
858 default:
859 sbus_rdwr_type = tvb_get_guint8(tvb, 9);
860 col_add_fstr( pinfo->cinfo, COL_INFO,
861 "Response: (%d byte)", sbus_rdwr_type);
862 break;
865 } else {
866 col_set_str(pinfo->cinfo, COL_INFO, "Response");
868 break;
870 case SBUS_ACKNAK:
871 sbus_ack_code = tvb_get_ntohs(tvb,9);
872 col_add_fstr(pinfo->cinfo, COL_INFO,
873 "%s", val_to_str_const(sbus_ack_code,
874 sbus_ack_nak_vals,
875 "Unknown NAK response code!"));
876 break;
878 default:
879 col_set_str(pinfo->cinfo, COL_INFO, "Unknown attribute");
880 break;
883 /* create display subtree for the protocol */
884 if (tree) {
886 ti = proto_tree_add_item(tree, proto_sbus, tvb, offset, -1, ENC_NA);
887 sbus_tree = proto_item_add_subtree(ti, ett_sbus);
889 /*Add subtree for Ether-S-Bus header*/
890 et = proto_tree_add_text(sbus_tree, tvb, offset, 8, "Ether-S-Bus header");
891 ethsbus_tree = proto_item_add_subtree(et, ett_sbus_ether);
893 /* add an item to the subtree*/
894 sbus_eth_len = tvb_get_ntohl(tvb,offset);
895 proto_tree_add_item(ethsbus_tree,
896 hf_sbus_length, tvb, offset, 4, ENC_BIG_ENDIAN);
897 offset += 4;
899 proto_tree_add_item(ethsbus_tree,
900 hf_sbus_version, tvb, offset, 1, ENC_BIG_ENDIAN);
901 offset += 1;
903 proto_tree_add_item(ethsbus_tree,
904 hf_sbus_protocol, tvb, offset, 1, ENC_BIG_ENDIAN);
905 offset += 1;
907 proto_tree_add_item(ethsbus_tree,
908 hf_sbus_sequence, tvb, offset, 2, ENC_BIG_ENDIAN);
909 offset += 2;
911 /* Continue adding stuff to the main tree*/
912 sbus_attribut = tvb_get_guint8(tvb,offset);
913 proto_tree_add_item(sbus_tree,
914 hf_sbus_attribut, tvb, offset, 1, ENC_BIG_ENDIAN);
915 offset += 1;
917 if (sbus_attribut == SBUS_REQUEST) {
918 proto_tree_add_item(sbus_tree,
919 hf_sbus_dest, tvb, offset, 1, ENC_BIG_ENDIAN);
920 offset += 1;
921 sbus_cmd_code = tvb_get_guint8(tvb,offset);
922 proto_tree_add_item(sbus_tree,
923 hf_sbus_command, tvb, offset, 1, ENC_BIG_ENDIAN);
924 offset += 1;
925 if (request_val && request_val->retry_count > 0) {/*this is a retry telegram*/
926 expert_add_info(pinfo, sbus_tree, &ei_sbus_retry);
927 nstime_delta(&ns, &pinfo->fd->abs_ts, &request_val->req_time);
928 proto_tree_add_time(sbus_tree, hf_sbus_timeout,
929 tvb, 0, 0, &ns);
930 proto_tree_add_uint(sbus_tree, hf_sbus_request_in, tvb, 0, 0,
931 request_val->req_frame);
933 if (request_val && request_val->resp_frame > pinfo->fd->num){
934 proto_tree_add_uint(sbus_tree, hf_sbus_response_in, tvb, 0, 0,
935 request_val->resp_frame);
937 switch (sbus_cmd_code) {
938 /*Read Counter, Register or Timer*/
939 case SBUS_RD_COUNTER:
940 case SBUS_RD_REGISTER:
941 case SBUS_RD_TIMER:
942 sbus_media_cnt = (tvb_get_guint8(tvb,offset))+1;
943 proto_tree_add_uint(sbus_tree,
944 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
945 offset += 1;
946 proto_tree_add_item(sbus_tree,
947 hf_sbus_addr_rtc, tvb, offset, 2, ENC_BIG_ENDIAN);
948 offset += 2;
949 break;
951 /*Read Flag, Input or Output*/
952 case SBUS_RD_FLAG:
953 case SBUS_RD_INPUT:
954 case SBUS_RD_OUTPUT:
955 sbus_media_cnt = (tvb_get_guint8(tvb,offset))+1;
956 proto_tree_add_uint(sbus_tree,
957 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
958 offset += 1;
959 proto_tree_add_item(sbus_tree,
960 hf_sbus_addr_iof, tvb, offset, 2, ENC_BIG_ENDIAN);
961 offset += 2;
962 break;
964 /*Write Register Timer Counter*/
965 case SBUS_WR_COUNTER:
966 case SBUS_WR_REGISTER:
967 case SBUS_WR_TIMER:
968 sbus_media_cnt = (tvb_get_guint8(tvb,offset));
969 sbus_media_cnt = ((sbus_media_cnt - 1)/4);
970 proto_tree_add_uint(sbus_tree,
971 hf_sbus_wcount_calculated, tvb, offset,
972 1, sbus_media_cnt);
973 proto_tree_add_item(sbus_tree,
974 hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
975 offset += 1;
976 proto_tree_add_item(sbus_tree,
977 hf_sbus_addr_rtc, tvb, offset, 2, ENC_BIG_ENDIAN);
978 offset += 2;
979 /*Add subtree for Data*/
980 dt = proto_tree_add_text(sbus_tree, tvb, offset,
981 ((sbus_media_cnt) * 4),"Data");
983 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
984 for (i=((sbus_media_cnt)); i>0; i--) {
985 proto_tree_add_item(sbusdata_tree,
986 hf_sbus_data_rtc, tvb, offset,
987 4, ENC_BIG_ENDIAN);
988 offset += 4;
990 break;
992 /* Write flags and outputs*/
993 case SBUS_WR_FLAG:
994 case SBUS_WR_OUTPUT:
995 sbus_media_cnt = (tvb_get_guint8(tvb,offset));
996 sbus_media_cnt = (sbus_media_cnt - 2);
997 proto_tree_add_uint(sbus_tree,
998 hf_sbus_wcount_calculated, tvb, offset,
999 1, sbus_media_cnt);
1000 proto_tree_add_item(sbus_tree,
1001 hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
1002 offset += 1;
1003 proto_tree_add_item(sbus_tree,
1004 hf_sbus_addr_iof, tvb, offset, 2, ENC_BIG_ENDIAN);
1005 offset += 2;
1006 sbus_fio_cnt = (tvb_get_guint8(tvb,offset));
1007 sbus_fio_cnt = ((sbus_fio_cnt + 1));
1008 proto_tree_add_uint(sbus_tree,
1009 hf_sbus_fio_count, tvb, offset, 1, sbus_fio_cnt);
1010 offset += 1;
1011 /*Add subtree for Data*/
1012 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1013 sbus_media_cnt,"Data");
1015 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1016 for (i=sbus_media_cnt; i>0; i--) {
1017 sbus_helper = 1;
1018 sbus_show_bin = 0;
1019 sbus_binarymasked = 0x01;
1020 sbus_binaries = tvb_get_guint8(tvb, offset);
1021 for (j=0; j<8; j++) {
1022 if ((sbus_binarymasked & sbus_binaries) != 0) {
1023 sbus_show_bin = (sbus_show_bin + sbus_helper);
1025 sbus_binarymasked = sbus_binarymasked<<1;
1026 sbus_helper = 10 * sbus_helper;
1029 proto_tree_add_uint_format(sbusdata_tree,
1030 hf_sbus_data_iof, tvb, offset, 1, sbus_show_bin,
1031 "Binary data: %08u", sbus_show_bin);
1032 offset += 1;
1034 break;
1036 /* Request: Write Real time clock*/
1037 case SBUS_WR_RTC:
1038 sbus_helper = tvb_get_guint8(tvb, (offset +5)); /*hours*/
1039 sbus_helper1 = tvb_get_guint8(tvb, (offset +6)); /*minutes*/
1040 sbus_helper2 = tvb_get_guint8(tvb, (offset +7)); /*seconds*/
1041 proto_tree_add_text(sbus_tree, tvb, (offset +5), 3,
1042 "Time (HH:MM:SS): %02x:%02x:%02x", sbus_helper, sbus_helper1, sbus_helper2);
1043 sbus_helper = tvb_get_guint8(tvb, (offset +2)); /*year*/
1044 sbus_helper1 = tvb_get_guint8(tvb, (offset +3)); /*month*/
1045 sbus_helper2 = tvb_get_guint8(tvb, (offset +4)); /*day*/
1046 proto_tree_add_text(sbus_tree, tvb, (offset +2), 3,
1047 "Date (YY/MM/DD): %02x/%02x/%02x", sbus_helper, sbus_helper1, sbus_helper2);
1048 sbus_helper = tvb_get_guint8(tvb, (offset)); /*year-week*/
1049 sbus_helper1 = tvb_get_guint8(tvb, (offset +1)); /*week-day*/
1050 proto_tree_add_text(sbus_tree, tvb, offset, 2,
1051 "Calendar week: %x, Week day: %x", sbus_helper, sbus_helper1);
1052 /*Add subtree for Data*/
1053 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1054 8, "Clock data");
1055 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1057 proto_tree_add_item(sbusdata_tree,
1058 hf_sbus_week_day, tvb, offset, 2, ENC_BIG_ENDIAN);
1059 offset += 2;
1060 proto_tree_add_item(sbusdata_tree,
1061 hf_sbus_date, tvb, offset, 3, ENC_BIG_ENDIAN);
1062 offset += 3;
1063 proto_tree_add_item(sbusdata_tree,
1064 hf_sbus_time, tvb, offset, 3, ENC_BIG_ENDIAN);
1065 offset += 3;
1066 break;
1068 /* Read user memory or program line*/
1069 case SBUS_RD_USER_MEMORY:
1070 case SBUS_RD_PROGRAM_LINE:
1071 sbus_media_cnt = (tvb_get_guint8(tvb,offset))+1;
1072 proto_tree_add_uint(sbus_tree,
1073 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
1074 offset += 1;
1075 proto_tree_add_item(sbus_tree,
1076 hf_sbus_addr_prog, tvb, offset, 3, ENC_BIG_ENDIAN);
1077 offset += 3;
1078 break;
1080 /*Write user memory*/
1081 case SBUS_WR_USER_MEMORY:
1082 sbus_media_cnt = (tvb_get_guint8(tvb,offset));
1083 sbus_media_cnt = ((sbus_media_cnt - 2)/4);
1084 proto_tree_add_uint(sbus_tree,
1085 hf_sbus_wcount_calculated, tvb, offset,
1086 1, sbus_media_cnt);
1087 proto_tree_add_item(sbus_tree,
1088 hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
1089 offset += 1;
1090 proto_tree_add_item(sbus_tree,
1091 hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
1092 offset += 3;
1093 /*Add subtree for Data*/
1094 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1095 ((sbus_media_cnt) * 4),"Program lines");
1097 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1098 for (i=((sbus_media_cnt)); i>0; i--) {
1099 proto_tree_add_item(sbusdata_tree,
1100 hf_sbus_data_rtc, tvb, offset,
1101 4, ENC_BIG_ENDIAN);
1102 offset += 4;
1105 break;
1107 /* Read byte*/
1108 case SBUS_RD_BYTE:
1109 sbus_media_cnt = (tvb_get_guint8(tvb,offset))+1;
1110 proto_tree_add_uint(sbus_tree,
1111 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
1112 offset += 1;
1113 proto_tree_add_item(sbus_tree,
1114 hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
1115 offset += 3;
1116 break;
1118 /* Write byte */
1119 case SBUS_WR_BYTE:
1120 sbus_media_cnt = (tvb_get_guint8(tvb,offset));
1121 sbus_media_cnt = (sbus_media_cnt - 2);
1122 proto_tree_add_uint(sbus_tree,
1123 hf_sbus_wcount_calculated, tvb, offset,
1124 1, sbus_media_cnt);
1125 proto_tree_add_item(sbus_tree,
1126 hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
1127 offset += 1;
1128 proto_tree_add_item(sbus_tree,
1129 hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
1130 offset += 3;
1131 /*Add subtree for Data*/
1132 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1133 ((sbus_media_cnt) * 4),"Data (bytes)");
1135 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1136 for (i=sbus_media_cnt; i>0; i--) {
1137 proto_tree_add_item(sbusdata_tree,
1138 hf_sbus_data_byte, tvb, offset,
1139 1, ENC_BIG_ENDIAN);
1140 offset += 1;
1142 break;
1144 /*Read EEPROM register*/
1145 case SBUS_RD_USER_EEPROM_REGISTER:
1146 proto_tree_add_item(sbus_tree,
1147 hf_sbus_command_extension, tvb, offset, 1, ENC_BIG_ENDIAN);
1148 offset += 1;
1149 sbus_media_cnt = (tvb_get_guint8(tvb,offset))+1;
1150 proto_tree_add_uint(sbus_tree,
1151 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
1152 offset += 1;
1153 proto_tree_add_item(sbus_tree,
1154 hf_sbus_addr_eeprom, tvb, offset, 2, ENC_BIG_ENDIAN);
1155 offset += 2;
1156 break;
1158 /*Request for reading system info*/
1159 /*Syinfo 05 is not implemented as no serial baud is possible*/
1160 case SBUS_RD_SYSTEM_INFORMATION:
1161 proto_tree_add_item(sbus_tree,
1162 hf_sbus_sysinfo_nr, tvb, offset, 1, ENC_BIG_ENDIAN);
1163 offset += 1;
1164 proto_tree_add_item(sbus_tree,
1165 hf_sbus_sysinfo_nr, tvb, offset, 1, ENC_BIG_ENDIAN);
1166 offset += 1;
1167 break;
1169 /* WebServer Request */
1170 case SBUS_WEB_SERVER_SERIAL_COMM:
1171 sbus_web_size = tvb_get_guint8(tvb,offset);
1172 proto_tree_add_uint(sbus_tree,
1173 hf_sbus_web_size, tvb, offset,
1174 1, sbus_web_size);
1175 offset += 1;
1177 sbus_web_aid = tvb_get_guint8(tvb,offset);
1178 proto_tree_add_uint(sbus_tree,
1179 hf_sbus_web_aid, tvb, offset,
1180 1, sbus_web_aid);
1181 offset += 1;
1183 sbus_web_seq = tvb_get_guint8(tvb,offset);
1184 proto_tree_add_uint(sbus_tree,
1185 hf_sbus_web_seq, tvb, offset,
1186 1, sbus_web_seq);
1187 offset += 1;
1189 if (sbus_web_size > 1) {
1190 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1191 (sbus_web_size - 1),"Data (bytes)");
1193 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1194 for (i=sbus_web_size -1 ; i>0; i--) {
1195 proto_tree_add_item(sbusdata_tree,
1196 hf_sbus_data_byte, tvb, offset,
1197 1, ENC_BIG_ENDIAN);
1198 offset += 1;
1201 break;
1202 /* Read/write block request */
1203 case SBUS_RD_WR_PCD_BLOCK:
1204 if (tvb_get_guint8(tvb,offset) == 0xff){
1205 sbus_rdwr_length = ((tvb_get_ntohl(tvb,0))-15);
1206 proto_tree_add_uint(sbus_tree,
1207 hf_sbus_rdwr_block_length_ext, tvb, 0, 4, sbus_rdwr_length);
1208 offset += 1;
1209 } else {
1210 sbus_rdwr_length = tvb_get_guint8(tvb,offset);
1211 proto_tree_add_uint(sbus_tree,
1212 hf_sbus_rdwr_block_length, tvb, offset,
1213 1, sbus_rdwr_length);
1214 offset += 1;
1216 sbus_rdwr_type = tvb_get_guint8(tvb,offset);
1217 proto_tree_add_uint(sbus_tree,
1218 hf_sbus_rdwr_telegram_type, tvb, offset,
1219 1, sbus_rdwr_type);
1220 offset += 1;
1221 switch(sbus_rdwr_type) {
1222 case SBUS_WR_START_OF_STREAM:
1223 sbus_rdwr_block_type = tvb_get_guint8(tvb, 14);
1224 proto_tree_add_item(sbus_tree,
1225 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1226 1, ENC_BIG_ENDIAN);
1227 offset += 1;
1228 proto_tree_add_item(sbus_tree,
1229 hf_sbus_block_type, tvb, offset,
1230 1, ENC_BIG_ENDIAN);
1231 offset += 1;
1233 /* Check for file or block download */
1234 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1235 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1236 proto_tree_add_item(sbus_tree,
1237 hf_sbus_rdwr_block_size, tvb, offset,
1238 4, ENC_BIG_ENDIAN);
1239 offset += 4;
1240 sbus_quint8_helper0=0;
1241 /*find zero-termination of string*/
1242 for (i=19; i<43; i++) { /*max length string is 24 char*/
1243 if ((tvb_get_guint8(tvb, i)) == 0x00) {
1244 break;
1246 sbus_quint8_helper0 += 1;
1248 tmp_string = tvb_get_string(wmem_packet_scope(), tvb , 19, sbus_quint8_helper0);
1249 proto_tree_add_string(sbus_tree,
1250 hf_sbus_rdwr_file_name, tvb, offset,
1251 sbus_quint8_helper0, tmp_string);
1252 offset += sbus_quint8_helper0;
1253 /*do not display a field for block data (skip)*/
1254 offset += (sbus_rdwr_length-6-sbus_quint8_helper0);
1255 } else { /* block write telegram, no file write*/
1256 proto_tree_add_item(sbus_tree,
1257 hf_sbus_block_nr, tvb, offset,
1258 2, ENC_BIG_ENDIAN);
1259 offset += 2;
1260 proto_tree_add_item(sbus_tree,
1261 hf_sbus_rdwr_block_size, tvb, offset,
1262 4, ENC_BIG_ENDIAN);
1263 offset += 4;
1264 /*do not display a field for block data (skip)*/
1265 offset += (sbus_rdwr_length-8);
1267 break;
1268 case SBUS_WR_BLOCK_DATA_STREAM:
1269 sbus_rdwr_sequence = tvb_get_guint8(tvb,offset);
1270 proto_tree_add_uint(sbus_tree,
1271 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1272 1, sbus_rdwr_sequence);
1273 offset += 1;
1274 /*do not display a field for block data (skip)*/
1275 offset += (sbus_rdwr_length-1);
1276 break;
1277 case SBUS_WR_BLOCK_END_OF_STREAM:
1278 sbus_rdwr_sequence = tvb_get_guint8(tvb,offset);
1279 proto_tree_add_uint(sbus_tree,
1280 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1281 1, sbus_rdwr_sequence);
1282 offset += 1;
1283 /*do not display a field for block data (skip it)*/
1284 offset += (sbus_rdwr_length-5);
1285 /*do not display a field for block CRC (skip it)*/
1286 offset += 4;
1287 break;
1288 case SBUS_WR_ABORT_BLOCK_STREAM:
1289 case SBUS_RD_ABORT_BLOCK_STREAM:
1290 break;
1291 case SBUS_WR_BLOCK_DATA_BYTES:
1292 sbus_rdwr_block_type = tvb_get_guint8(tvb, 14);
1293 proto_tree_add_item(sbus_tree,
1294 hf_sbus_block_type, tvb, offset,
1295 1, ENC_BIG_ENDIAN);
1296 offset += 1;
1298 /* Check for file or block download */
1299 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1300 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1301 proto_tree_add_item(sbus_tree,
1302 hf_sbus_rdwr_block_addr, tvb, offset,
1303 4, ENC_BIG_ENDIAN);
1304 offset += 4;
1305 sbus_quint8_helper0=0;
1306 /*find zero-termination of string*/
1307 for (i=19; i<43; i++) { /*max length string is 24 char*/
1308 if ((tvb_get_guint8(tvb, i)) == 0x00) {
1309 break;
1311 sbus_quint8_helper0 += 1;
1313 tmp_string = tvb_get_string(wmem_packet_scope(), tvb, 19, sbus_quint8_helper0);
1314 proto_tree_add_string(sbus_tree,
1315 hf_sbus_rdwr_file_name, tvb, offset,
1316 sbus_quint8_helper0, tmp_string);
1317 offset += sbus_quint8_helper0;
1318 /*do not display a field for block data (skip)*/
1319 offset += (sbus_rdwr_length-6-sbus_quint8_helper0);
1320 } else { /* block write telegram, no file write*/
1321 proto_tree_add_item(sbus_tree,
1322 hf_sbus_block_nr, tvb, offset,
1323 2, ENC_BIG_ENDIAN);
1324 offset += 2;
1325 proto_tree_add_item(sbus_tree,
1326 hf_sbus_rdwr_block_addr, tvb, offset,
1327 4, ENC_BIG_ENDIAN);
1328 offset += 4;
1329 /*do not display a field for block data (skip)*/
1330 offset += (sbus_rdwr_length-8);
1332 break;
1333 case SBUS_RD_BLOCK_START_OF_STREAM:
1334 sbus_rdwr_block_type = tvb_get_guint8(tvb, 14);
1335 proto_tree_add_item(sbus_tree,
1336 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1337 1, ENC_BIG_ENDIAN);
1338 offset += 1;
1339 proto_tree_add_item(sbus_tree,
1340 hf_sbus_block_type, tvb, offset,
1341 1, ENC_BIG_ENDIAN);
1342 offset += 1;
1344 /* Check for file or block download */
1345 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1346 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1347 sbus_quint8_helper0=0;
1348 /*find zero-termination of string*/
1349 for (i=14; i<38; i++) { /*max length string is 24 char*/
1350 if ((tvb_get_guint8(tvb, i)) == 0x00) {
1351 break;
1353 sbus_quint8_helper0 += 1;
1355 tmp_string = tvb_get_string(wmem_packet_scope(), tvb, 14, sbus_quint8_helper0);
1356 proto_tree_add_string(sbus_tree,
1357 hf_sbus_rdwr_file_name, tvb, offset,
1358 sbus_quint8_helper0, tmp_string);
1359 offset += sbus_quint8_helper0;
1360 } else { /* block write telegram, no file write*/
1361 proto_tree_add_item(sbus_tree,
1362 hf_sbus_block_nr, tvb, offset,
1363 2, ENC_BIG_ENDIAN);
1364 offset += 2;
1366 break;
1367 case SBUS_RD_BLOCK_DATA_STREAM:
1368 proto_tree_add_item(sbus_tree,
1369 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1370 1, ENC_BIG_ENDIAN);
1371 offset += 1;
1372 break;
1373 case SBUS_RD_BLOCK_DATA_BYTES:
1374 sbus_rdwr_block_type = tvb_get_guint8(tvb, 13);
1375 proto_tree_add_item(sbus_tree,
1376 hf_sbus_block_type, tvb, offset,
1377 1, ENC_BIG_ENDIAN);
1378 offset += 1;
1379 /* Check for file or block read */
1380 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1381 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1382 /*reading from a file*/
1383 proto_tree_add_item(sbus_tree,
1384 hf_sbus_rdwr_block_addr, tvb, offset,
1385 4, ENC_BIG_ENDIAN);
1386 offset += 4;
1387 proto_tree_add_item(sbus_tree,
1388 hf_sbus_rdwr_block_size, tvb, offset,
1389 4, ENC_BIG_ENDIAN);
1390 offset += 4;
1391 sbus_quint8_helper0=0;
1392 /*find zero-termination of string*/
1393 for (i=22; i<46; i++) { /*max length string is 24 char*/
1394 if ((tvb_get_guint8(tvb, i)) == 0x00) {
1395 break;
1397 sbus_quint8_helper0 += 1;
1399 tmp_string = tvb_get_string(wmem_packet_scope(), tvb, 22, sbus_quint8_helper0);
1400 proto_tree_add_string(sbus_tree,
1401 hf_sbus_rdwr_file_name, tvb, offset,
1402 sbus_quint8_helper0, tmp_string);
1403 offset += sbus_quint8_helper0 + 1;
1404 } else { /* block read telegram, no file read*/
1405 proto_tree_add_item(sbus_tree,
1406 hf_sbus_block_nr, tvb, offset,
1407 2, ENC_BIG_ENDIAN);
1408 offset += 2;
1409 proto_tree_add_item(sbus_tree,
1410 hf_sbus_rdwr_block_addr, tvb, offset,
1411 4, ENC_BIG_ENDIAN);
1412 offset += 4;
1413 proto_tree_add_item(sbus_tree,
1414 hf_sbus_rdwr_block_size, tvb, offset,
1415 4, ENC_BIG_ENDIAN);
1416 offset += 4;
1418 break;
1419 case SBUS_DELETE_BLOCK:
1420 case SBUS_GET_BLOCK_SIZE:
1421 sbus_rdwr_block_type = tvb_get_guint8(tvb, 13);
1422 proto_tree_add_item(sbus_tree,
1423 hf_sbus_block_type, tvb, offset,
1424 1, ENC_BIG_ENDIAN);
1425 offset += 1;
1426 /* Check for file or block deletion */
1427 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1428 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1429 /*delete a file*/
1430 sbus_quint8_helper0=0;
1431 /*find zero-termination of string*/
1432 for (i=14; i<38; i++) { /*max length string is 24 char*/
1433 if ((tvb_get_guint8(tvb, i)) == 0x00) {
1434 break;
1436 sbus_quint8_helper0 += 1;
1438 tmp_string = tvb_get_string(wmem_packet_scope(), tvb, 14, sbus_quint8_helper0);
1439 proto_tree_add_string(sbus_tree,
1440 hf_sbus_rdwr_file_name, tvb, offset,
1441 sbus_quint8_helper0, tmp_string);
1442 offset += sbus_quint8_helper0 + 1;
1443 } else { /* delete a block*/
1444 proto_tree_add_item(sbus_tree,
1445 hf_sbus_block_nr, tvb, offset,
1446 2, ENC_BIG_ENDIAN);
1447 offset += 2;
1449 break;
1450 case SBUS_GET_PROGRAM_BLOCK_LIST:
1451 proto_tree_add_item(sbus_tree,
1452 hf_sbus_rdwr_list_type, tvb, offset,
1453 1, ENC_BIG_ENDIAN);
1454 offset += 1;
1455 break;
1457 default:
1458 break;
1461 break;
1463 /*Inform that command was not dissected and add remaining length*/
1464 default:
1465 if (sbus_eth_len > 13) { /*13 bytes is the minimal length of a request telegram...*/
1466 sbus_helper = sbus_eth_len - (offset + 2);
1467 proto_tree_add_text(sbus_tree, tvb, offset, sbus_helper,
1468 "This telegram isn't implemented in the dissector.");
1469 offset = offset + sbus_helper;
1471 break;
1475 /* Response dissection*/
1476 if (sbus_attribut == SBUS_RESPONSE && request_val) {
1477 /*add response time*/
1478 nstime_delta(&ns, &pinfo->fd->abs_ts, &request_val->req_time);
1479 proto_tree_add_time(sbus_tree, hf_sbus_response_time,
1480 tvb, 0, 0, &ns);
1481 /*add reference to request telegram*/
1482 proto_tree_add_uint(sbus_tree, hf_sbus_response_to, tvb, 0, 0,
1483 request_val->req_frame);
1485 switch (request_val->cmd_code) {
1486 /* Response: 32 bit values*/
1487 case SBUS_RD_COUNTER:
1488 case SBUS_RD_REGISTER:
1489 case SBUS_RD_TIMER:
1490 case SBUS_RD_USER_MEMORY:
1491 case SBUS_RD_PROGRAM_LINE:
1492 case SBUS_RD_USER_EEPROM_REGISTER:
1493 /*Add subtree for Data*/
1494 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1495 ((request_val->count) * 4),"Data");
1496 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1497 for (i=(request_val->count); i>0; i--) {
1498 proto_tree_add_item(sbusdata_tree,
1499 hf_sbus_data_rtc, tvb, offset,
1500 4, ENC_BIG_ENDIAN);
1501 offset += 4;
1503 break;
1505 /* Response: PCD Display register*/
1506 case SBUS_RD_DISPLAY_REGISTER:
1507 proto_tree_add_item(sbus_tree,
1508 hf_sbus_display_register, tvb, offset, 4, ENC_BIG_ENDIAN);
1509 offset += 4;
1510 break;
1512 /* Add binary data I, O, F*/
1513 case SBUS_RD_FLAG:
1514 case SBUS_RD_INPUT:
1515 case SBUS_RD_OUTPUT:
1516 /*Add subtree for Data*/
1517 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1518 (((request_val->count) + 7) / 8), "Data");
1519 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1521 for (i=(((request_val->count) + 7) / 8); i>0; i--) {
1522 sbus_helper = 1;
1523 sbus_show_bin = 0;
1524 sbus_binarymasked = 0x01;
1525 sbus_binaries = tvb_get_guint8(tvb, offset);
1526 for (j=0; j<8; j++){
1527 if ((sbus_binarymasked & sbus_binaries) != 0) {
1528 sbus_show_bin = (sbus_show_bin + sbus_helper);
1530 sbus_binarymasked = sbus_binarymasked<<1;
1531 sbus_helper = 10 * sbus_helper;
1534 proto_tree_add_uint_format(sbusdata_tree,
1535 hf_sbus_data_iof, tvb, offset, 1, sbus_show_bin,
1536 "Binary data: %08u", sbus_show_bin);
1537 offset += 1;
1539 break;
1541 /* Response: Real time clock value*/
1542 case SBUS_RD_RTC:
1543 sbus_helper = tvb_get_guint8(tvb, (offset +5)); /*hours*/
1544 sbus_helper1 = tvb_get_guint8(tvb, (offset +6)); /*minutes*/
1545 sbus_helper2 = tvb_get_guint8(tvb, (offset +7)); /*seconds*/
1546 proto_tree_add_text(sbus_tree, tvb, (offset +5), 3,
1547 "Time (HH:MM:SS): %02x:%02x:%02x", sbus_helper, sbus_helper1, sbus_helper2);
1548 sbus_helper = tvb_get_guint8(tvb, (offset +2)); /*year*/
1549 sbus_helper1 = tvb_get_guint8(tvb, (offset +3)); /*month*/
1550 sbus_helper2 = tvb_get_guint8(tvb, (offset +4)); /*day*/
1551 proto_tree_add_text(sbus_tree, tvb, (offset +2), 3,
1552 "Date (YY/MM/DD): %02x/%02x/%02x", sbus_helper, sbus_helper1, sbus_helper2);
1553 sbus_helper = tvb_get_guint8(tvb, (offset)); /*year-week*/
1554 sbus_helper1 = tvb_get_guint8(tvb, (offset +1)); /*week-day*/
1555 proto_tree_add_text(sbus_tree, tvb, offset, 2,
1556 "Calendar week: %x, Week day: %x", sbus_helper, sbus_helper1);
1557 /*Add subtree for Data*/
1558 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1559 8, "Clock data");
1560 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1562 proto_tree_add_item(sbusdata_tree,
1563 hf_sbus_week_day, tvb, offset, 2, ENC_BIG_ENDIAN);
1564 offset += 2;
1565 proto_tree_add_item(sbusdata_tree,
1566 hf_sbus_date, tvb, offset, 3, ENC_BIG_ENDIAN);
1567 offset += 3;
1568 proto_tree_add_item(sbusdata_tree,
1569 hf_sbus_time, tvb, offset, 3, ENC_BIG_ENDIAN);
1570 offset += 3;
1571 break;
1573 /* Response: CPU status, the command codes 14..1B are concerned*/
1574 case SBUS_RD_PCD_STATUS_CPU0:
1575 case SBUS_RD_PCD_STATUS_CPU1:
1576 case SBUS_RD_PCD_STATUS_CPU2:
1577 case SBUS_RD_PCD_STATUS_CPU3:
1578 case SBUS_RD_PCD_STATUS_CPU4:
1579 case SBUS_RD_PCD_STATUS_CPU5:
1580 case SBUS_RD_PCD_STATUS_CPU6:
1581 case SBUS_RD_PCD_STATUS_OWN:
1582 proto_tree_add_item(sbus_tree,
1583 hf_sbus_cpu_status, tvb, offset, 1, ENC_BIG_ENDIAN);
1584 offset += 1;
1585 break;
1587 /* Response: Station address*/
1588 case SBUS_RD_SBUS_STN_NBR:
1589 proto_tree_add_item(sbus_tree,
1590 hf_sbus_address, tvb, offset, 1, ENC_BIG_ENDIAN);
1591 offset += 1;
1592 break;
1594 /* Response: Firmware version */
1595 case SBUS_RD_PROGRAM_VERSION:
1596 /*PCD type*/
1597 tmp_string = tvb_get_string(wmem_packet_scope(), tvb , offset, 5);
1598 proto_tree_add_string(sbus_tree,
1599 hf_sbus_cpu_type, tvb, offset, 5, tmp_string);
1600 offset += 5;
1601 /*FW version*/
1602 tmp_string = tvb_get_string(wmem_packet_scope(), tvb , offset, 3);
1603 proto_tree_add_string(sbus_tree,
1604 hf_sbus_fw_version, tvb, offset, 3, tmp_string);
1605 offset += 4;
1606 break;
1608 /* Response for Status Flags*/
1609 case SBUS_RD_STATUSFLAG_ACCU:
1610 /*Add subtree for Data*/
1611 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1612 1,"ACCU and arithmetic status");
1613 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1615 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_accu,
1616 tvb, offset, 1, ENC_BIG_ENDIAN);
1617 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_error,
1618 tvb, offset, 1, ENC_BIG_ENDIAN);
1619 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_negative,
1620 tvb, offset, 1, ENC_BIG_ENDIAN);
1621 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_zero,
1622 tvb, offset, 1, ENC_BIG_ENDIAN);
1623 offset +=1;
1624 break;
1626 /* Response for Read byte */
1627 case SBUS_RD_BYTE:
1628 /*Add subtree for Data*/
1629 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1630 (request_val->count),"Data (bytes)");
1632 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1633 for (i=(request_val->count); i>0; i--) {
1634 proto_tree_add_item(sbusdata_tree,
1635 hf_sbus_data_byte, tvb, offset,
1636 1, ENC_BIG_ENDIAN);
1637 offset += 1;
1639 break;
1641 /* Response for Read Index register */
1642 case SBUS_RD_INDEX_REGISTER:
1643 /*Add subtree for Data*/
1644 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1645 2,"Data (hex bytes)");
1647 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1648 for (i=0; i<2; i++) { /*2 bytes*/
1649 proto_tree_add_item(sbusdata_tree,
1650 hf_sbus_data_byte_hex, tvb, offset,
1651 1, ENC_BIG_ENDIAN);
1652 offset += 1;
1654 break;
1656 /* Response: Instruction pointer*/
1657 case SBUS_RD_INSTRUCTION_POINTER:
1658 proto_tree_add_item(sbus_tree,
1659 hf_sbus_addr_prog, tvb, offset, 3, ENC_BIG_ENDIAN);
1660 offset += 3;
1661 break;
1663 /*Response for Find History*/
1664 case SBUS_FIND_HISTORY:
1665 proto_tree_add_item(sbus_tree,
1666 hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
1667 offset += 3;
1668 proto_tree_add_item(sbus_tree,
1669 hf_sbus_nbr_elements, tvb, offset, 2, ENC_BIG_ENDIAN);
1670 offset += 2;
1671 break;
1673 /* Response: Read current block*/
1674 case SBUS_RD_CURRENT_BLOCK:
1675 proto_tree_add_item(sbus_tree,
1676 hf_sbus_block_type, tvb, offset, 1, ENC_BIG_ENDIAN);
1677 offset += 1;
1678 proto_tree_add_item(sbus_tree,
1679 hf_sbus_block_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
1680 offset += 2;
1681 break;
1683 /* Response: Read system infomation (without interpretation of module info)*/
1684 case SBUS_RD_SYSTEM_INFORMATION:
1685 if (request_val->sysinfo == 0x00){ /*sysinfo 0*/
1686 offset += 1; /* this byte is always 0x01*/
1687 /*Add subtree for Data*/
1688 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1689 1,"System info");
1690 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1692 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_1,
1693 tvb, offset, 1, ENC_BIG_ENDIAN);
1694 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_2,
1695 tvb, offset, 1, ENC_BIG_ENDIAN);
1696 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_3,
1697 tvb, offset, 1, ENC_BIG_ENDIAN);
1698 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_4,
1699 tvb, offset, 1, ENC_BIG_ENDIAN);
1700 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_5,
1701 tvb, offset, 1, ENC_BIG_ENDIAN);
1702 offset += 1;
1703 } else {
1704 /*do not dissect all system info telegrams as there is no need*/
1705 offset = (tvb_get_guint8(tvb,9) + 10);
1707 break;
1709 /* Response: Webserver request */
1710 case SBUS_WEB_SERVER_SERIAL_COMM:
1711 sbus_web_size = tvb_get_guint8(tvb,offset);
1712 proto_tree_add_uint(sbus_tree,
1713 hf_sbus_web_size, tvb, offset,
1714 1, sbus_web_size);
1715 offset += 1;
1717 sbus_web_aid = tvb_get_guint8(tvb,offset);
1718 proto_tree_add_uint(sbus_tree,
1719 hf_sbus_web_aid, tvb, offset,
1720 1, sbus_web_aid);
1721 offset += 1;
1723 if (sbus_web_size > 1) {
1724 sbus_web_seq = tvb_get_guint8(tvb,offset);
1725 proto_tree_add_uint(sbus_tree,
1726 hf_sbus_web_seq, tvb, offset,
1727 1, sbus_web_seq);
1728 offset += 1;
1730 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1731 (sbus_web_size - 2),"Data (bytes)");
1733 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1734 for (i=sbus_web_size - 2; i>0; i--) {
1735 proto_tree_add_item(sbusdata_tree,
1736 hf_sbus_data_byte, tvb, offset,
1737 1, ENC_BIG_ENDIAN);
1738 offset += 1;
1741 break;
1742 /* Response: Read/Write block data */
1743 case SBUS_RD_WR_PCD_BLOCK:
1744 sbus_rdwr_block_tlg = request_val->block_tlg;
1745 sbus_rdwr_length = tvb_get_guint8(tvb,offset);
1746 proto_tree_add_uint(sbus_tree,
1747 hf_sbus_rdwr_block_length, tvb, offset,
1748 1, sbus_rdwr_length);
1749 offset += 1;
1750 hi = proto_tree_add_item(sbus_tree,
1751 hf_sbus_rdwr_acknakcode, tvb, offset,
1752 1, ENC_BIG_ENDIAN);
1753 if ((tvb_get_guint8(tvb, offset) >= SBUS_RD_WR_NAK)&&
1754 (tvb_get_guint8(tvb, offset) <= SBUS_RD_WR_NAK_INVALID_SIZE)) {
1755 expert_add_info(pinfo, hi, &ei_sbus_telegram_not_acked);
1757 offset += 1;
1758 switch(sbus_rdwr_block_tlg) {
1759 case SBUS_WR_START_OF_STREAM:
1760 case SBUS_WR_BLOCK_DATA_STREAM:
1761 case SBUS_WR_BLOCK_END_OF_STREAM:
1762 proto_tree_add_item(sbus_tree,
1763 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1764 1, ENC_BIG_ENDIAN);
1765 offset += 1;
1766 break;
1767 case SBUS_WR_ABORT_BLOCK_STREAM:
1768 case SBUS_RD_ABORT_BLOCK_STREAM:
1769 case SBUS_WR_BLOCK_DATA_BYTES:
1770 case SBUS_DELETE_BLOCK:
1771 break;
1772 case SBUS_RD_BLOCK_START_OF_STREAM:
1773 proto_tree_add_item(sbus_tree,
1774 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1775 1, ENC_BIG_ENDIAN);
1776 offset += 1;
1777 proto_tree_add_item(sbus_tree,
1778 hf_sbus_rdwr_block_size, tvb, offset,
1779 4, ENC_BIG_ENDIAN);
1780 offset += 4;
1781 /*do not display a field for block data (skip)*/
1782 offset += (sbus_rdwr_length-6);
1783 break;
1784 case SBUS_RD_BLOCK_DATA_STREAM:
1785 proto_tree_add_item(sbus_tree,
1786 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1787 1, ENC_BIG_ENDIAN);
1788 offset += 1;
1789 /*do not display a field for block data (skip)*/
1790 offset += (sbus_rdwr_length-2);
1791 break;
1792 case SBUS_RD_BLOCK_DATA_BYTES:
1793 /*do not display a field for block data (skip)*/
1794 offset += (sbus_rdwr_length-1);
1795 break;
1796 case SBUS_GET_BLOCK_SIZE:
1797 sbus_rdwr_block_type = tvb_get_guint8(tvb, 10);
1798 /* Check for unknown block type */
1799 if (sbus_rdwr_block_type == SBUS_RD_WR_UNKNOWN_BLOCK_TYPE) {
1800 /*unknown block, no more data follows*/
1801 } else { /* add block size and CRC32 in case of known block*/
1802 proto_tree_add_item(sbus_tree,
1803 hf_sbus_rdwr_block_size, tvb, offset,
1804 4, ENC_BIG_ENDIAN);
1805 offset += 4;
1806 /*Now the CRC32 follows, but I don't bother calculating it*/
1807 offset += 4;
1809 break;
1810 case SBUS_GET_PROGRAM_BLOCK_LIST:
1811 proto_tree_add_item(sbus_tree,
1812 hf_sbus_block_type, tvb, offset,
1813 1, ENC_BIG_ENDIAN);
1814 offset += 1;
1815 proto_tree_add_item(sbus_tree,
1816 hf_sbus_block_nr, tvb, offset,
1817 2, ENC_BIG_ENDIAN);
1818 offset += 2;
1819 proto_tree_add_item(sbus_tree,
1820 hf_sbus_rdwr_block_size, tvb, offset,
1821 4, ENC_BIG_ENDIAN);
1822 offset += 4;
1823 /*do not display block_timestamp as no description is available*/
1824 offset += (sbus_rdwr_length-8);
1825 break;
1826 default:
1827 break;
1829 break;
1831 /*Inform that response was not dissected and add remaining length*/
1832 default:
1833 sbus_helper = sbus_eth_len - (offset + 2);
1834 proto_tree_add_text(sbus_tree, tvb, offset, sbus_helper,
1835 "This telegram isn't implemented in the dissector.");
1836 offset = offset + sbus_helper;
1837 break;
1839 } else if (sbus_attribut == SBUS_RESPONSE && (!request_val)) {
1840 /*calculate the offset in case the request telegram was not found or was broadcasted*/
1841 sbus_eth_len = tvb_get_ntohl(tvb,0);
1842 sbus_helper = sbus_eth_len - 11;
1843 proto_tree_add_text(sbus_tree, tvb, offset, sbus_helper,
1844 "Not dissected, could not find request telegram");
1845 offset = sbus_eth_len - 2;
1848 if (sbus_attribut == SBUS_ACKNAK) {
1849 /*Add response time if possible*/
1850 if (request_val) {
1851 nstime_delta(&ns, &pinfo->fd->abs_ts, &request_val->req_time);
1852 proto_tree_add_time(sbus_tree, hf_sbus_response_time,
1853 tvb, 0, 0, &ns);
1854 /*add reference to request telegram*/
1855 proto_tree_add_uint(sbus_tree, hf_sbus_response_to, tvb, 0, 0,
1856 request_val->req_frame);
1858 hi = proto_tree_add_item(sbus_tree,
1859 hf_sbus_acknackcode, tvb, offset, 2, ENC_BIG_ENDIAN);
1860 if (tvb_get_guint8(tvb, (offset+1)) > 0) {
1861 expert_add_info(pinfo, hi, &ei_sbus_telegram_not_acked);
1863 offset += 2;
1866 /* Calclulate CRC */
1867 sbus_crc_calc = 0;
1868 for (i = 0; i < sbus_eth_len - 2; i++)
1869 sbus_crc_calc = crc_calc (sbus_crc_calc, tvb_get_guint8(tvb, i));
1870 /*Show CRC and add hidden item for wrong CRC*/
1871 sbus_helper = tvb_get_ntohs(tvb, offset);
1872 if (sbus_helper == sbus_crc_calc) {
1873 proto_tree_add_uint_format_value(sbus_tree,
1874 hf_sbus_crc, tvb, offset, 2, sbus_helper,
1875 "0x%04x (correct)", sbus_helper);
1876 } else {
1877 cs = proto_tree_add_uint_format_value(sbus_tree,
1878 hf_sbus_crc, tvb, offset, 2, sbus_helper,
1879 "0x%04x (NOT correct)", sbus_helper);
1880 expert_add_info(pinfo, cs, &ei_sbus_crc_bad);
1881 hi = proto_tree_add_boolean(sbus_tree,
1882 hf_sbus_crc_bad, tvb, offset, 2, TRUE);
1883 PROTO_ITEM_SET_HIDDEN(hi);
1884 PROTO_ITEM_SET_GENERATED(hi);
1886 offset += 2; /*now at the end of the telegram*/
1888 return offset;
1889 /*End of dissect_sbus*/
1892 /* Register the protocol with Wireshark */
1894 void
1895 proto_register_sbus(void)
1898 /* Setup list of header fields See Section 1.6.1 for details*/
1899 static hf_register_info hf[] = {
1900 { &hf_sbus_length,
1901 { "Length (bytes)", "sbus.len",
1902 FT_UINT32, BASE_DEC, NULL, 0,
1903 "SAIA Ether-S-Bus telegram length", HFILL }
1905 { &hf_sbus_version,
1906 { "Version", "sbus.vers",
1907 FT_UINT8, BASE_DEC, NULL, 0,
1908 "SAIA Ether-S-Bus version", HFILL }
1910 { &hf_sbus_protocol,
1911 { "Protocol type", "sbus.proto",
1912 FT_UINT8, BASE_DEC, NULL, 0,
1913 "SAIA Ether-S-Bus protocol type", HFILL }
1915 { &hf_sbus_sequence,
1916 { "Sequence", "sbus.seq",
1917 FT_UINT16, BASE_DEC, NULL, 0,
1918 "SAIA Ether-S-Bus sequence number", HFILL }
1921 { &hf_sbus_attribut,
1922 { "Telegram attribute", "sbus.att",
1923 FT_UINT8, BASE_HEX, VALS(sbus_att_vals), 0,
1924 "SAIA Ether-S-Bus telegram attribute, indicating type of telegram", HFILL }
1927 { &hf_sbus_dest,
1928 { "Destination", "sbus.destination",
1929 FT_UINT8, BASE_DEC, NULL, 0,
1930 "SAIA S-Bus destination address", HFILL }
1933 { &hf_sbus_address,
1934 { "S-Bus address", "sbus.address",
1935 FT_UINT8, BASE_DEC, NULL, 0,
1936 "SAIA S-Bus station address", HFILL }
1939 { &hf_sbus_command,
1940 { "Command", "sbus.cmd",
1941 FT_UINT8, BASE_HEX, VALS(sbus_command_vals), 0,
1942 "SAIA S-Bus command", HFILL }
1945 { &hf_sbus_command_extension,
1946 { "Command extension", "sbus.cmd_extn",
1947 FT_UINT8, BASE_HEX, NULL, 0,
1948 "SAIA S-Bus command extension", HFILL }
1951 { &hf_sbus_rcount,
1952 { "R-count", "sbus.rcount",
1953 FT_UINT8, BASE_DEC, NULL, 0,
1954 "Number of elements expected in response", HFILL }
1957 { &hf_sbus_wcount,
1958 { "W-count (raw)", "sbus.wcount",
1959 FT_UINT8, BASE_DEC, NULL, 0,
1960 "Number of bytes to be written", HFILL }
1963 { &hf_sbus_wcount_calculated,
1964 { "W-count (32 bit values)", "sbus.wcount_calc",
1965 FT_UINT8, BASE_DEC, NULL, 0,
1966 "Number of elements to be written", HFILL }
1969 { &hf_sbus_fio_count,
1970 { "FIO Count (amount of bits)", "sbus.fio_count",
1971 FT_UINT8, BASE_DEC, NULL, 0,
1972 "Number of binary elements to be written", HFILL }
1975 { &hf_sbus_addr_rtc,
1976 { "Base address RTC", "sbus.addr_RTC",
1977 FT_UINT16, BASE_DEC, NULL, 0,
1978 "Base address of 32 bit elements to read", HFILL }
1981 { &hf_sbus_addr_iof,
1982 { "Base address IOF", "sbus.addr_IOF",
1983 FT_UINT16, BASE_DEC, NULL, 0,
1984 "Base address of binary elements to read", HFILL }
1987 { &hf_sbus_addr_eeprom,
1988 { "Base address of EEPROM register", "sbus.addr_EEPROM",
1989 FT_UINT16, BASE_DEC, NULL, 0,
1990 "Base address of 32 bit EEPROM register to read or write", HFILL }
1993 { &hf_sbus_addr_prog,
1994 { "Base address of user memory or program lines", "sbus.addr_prog",
1995 FT_UINT24, BASE_DEC, NULL, 0,
1996 "Base address of the user memory or program lines (read or write)", HFILL }
1999 { &hf_sbus_addr_68k,
2000 { "Base address of bytes", "sbus.addr_68k",
2001 FT_UINT24, BASE_HEX, NULL, 0,
2002 "Base address of bytes to read or write (68k address)", HFILL }
2005 { &hf_sbus_block_type,
2006 { "Block type", "sbus.block_type",
2007 FT_UINT8, BASE_HEX, VALS(sbus_block_types), 0,
2008 "Program block type", HFILL }
2011 { &hf_sbus_block_nr,
2012 { "Block/Element nr", "sbus.block_nr",
2013 FT_UINT16, BASE_DEC, NULL, 0,
2014 "Program block / DatatBlock number", HFILL }
2017 { &hf_sbus_nbr_elements,
2018 { "Number of elements", "sbus.nbr_elements",
2019 FT_UINT16, BASE_DEC, NULL, 0,
2020 "Number of elements or characters", HFILL }
2023 { &hf_sbus_display_register,
2024 { "PCD Display register", "sbus.data_display_register",
2025 FT_UINT32, BASE_DEC, NULL, 0,
2026 "The PCD display register (32 bit value)", HFILL }
2029 { &hf_sbus_data_rtc,
2030 { "S-Bus 32-bit data", "sbus.data_rtc",
2031 FT_UINT32, BASE_DEC, NULL, 0,
2032 "One regiser/timer of counter (32 bit value)", HFILL }
2035 { &hf_sbus_data_byte,
2036 { "Data bytes", "sbus.data_byte",
2037 FT_UINT8, BASE_DEC, NULL, 0,
2038 "One byte from PCD", HFILL }
2041 { &hf_sbus_data_byte_hex,
2042 { "Data bytes (hex)", "sbus.data_byte_hex",
2043 FT_UINT8, BASE_HEX, NULL, 0,
2044 "One byte from PCD (hexadecimal)", HFILL }
2047 { &hf_sbus_data_iof,
2048 { "S-Bus binary data", "sbus.data_iof",
2049 FT_UINT32, BASE_DEC, NULL, 0,
2050 "8 binaries", HFILL }
2053 { &hf_sbus_cpu_type,
2054 { "PCD type", "sbus.pcd_type",
2055 FT_STRING, BASE_NONE, NULL, 0,
2056 "PCD type (short form)", HFILL }
2059 { &hf_sbus_fw_version,
2060 { "Firmware version", "sbus.fw_version",
2061 FT_STRING, BASE_NONE, NULL, 0,
2062 "Firmware version of the PCD or module", HFILL }
2065 { &hf_sbus_sysinfo_nr,
2066 { "System information number", "sbus.sysinfo",
2067 FT_UINT8, BASE_HEX, NULL, 0,
2068 "System information number (extension to command code)", HFILL }
2071 { &hf_sbus_sysinfo0_1,
2072 { "Mem size info", "sbus.sysinfo0.mem",
2073 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_MEMSIZE,
2074 "Availability of memory size information", HFILL }
2076 { &hf_sbus_sysinfo0_2,
2077 { "Trace buffer", "sbus.sysinfo0.trace",
2078 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_TRACE,
2079 "Availability of trace buffer feature", HFILL }
2081 { &hf_sbus_sysinfo0_3,
2082 { "Slot B1", "sbus.sysinfo0.b1",
2083 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_INFO_B1,
2084 "Presence of EEPROM information on slot B1", HFILL }
2086 { &hf_sbus_sysinfo0_4,
2087 { "Slot B2", "sbus.sysinfo0.b2",
2088 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_INFO_B2,
2089 "Presence of EEPROM information on slot B2", HFILL }
2091 { &hf_sbus_sysinfo0_5,
2092 { "PGU baud", "sbus.sysinfo0.pgubaud",
2093 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_PGU_BAUD,
2094 "Availability of PGU baud switch feature", HFILL }
2097 #if 0
2098 { &hf_sbus_sysinfo_length,
2099 { "System information length", "sbus.sysinfo_length",
2100 FT_UINT8, BASE_HEX, NULL, 0,
2101 "System information length in response", HFILL }
2103 #endif
2105 #if 0
2106 { &hf_sbus_f_module_type,
2107 { "F-module type", "sbus.fmodule_type",
2108 FT_STRING, BASE_NONE, NULL, 0,
2109 "Module type mounted on B1/2 slot", HFILL }
2111 #endif
2113 #if 0
2114 { &hf_sbus_harware_version,
2115 { "Hardware version", "sbus.hw_version",
2116 FT_STRING, BASE_NONE, NULL, 0,
2117 "Hardware version of the PCD or the module", HFILL }
2119 #endif
2121 #if 0
2122 { &hf_sbus_hardware_modification,
2123 { "Hardware modification", "sbus.hw_modification",
2124 FT_UINT8, BASE_DEC, NULL, 0,
2125 "Hardware modification of the PCD or module", HFILL }
2127 #endif
2129 #if 0
2130 { &hf_sbus_various,
2131 { "Various data", "sbus.various",
2132 FT_NONE, BASE_NONE, NULL, 0,
2133 "Various data contained in telegrams but nobody will search for it", HFILL }
2135 #endif
2137 { &hf_sbus_acknackcode,
2138 { "ACK/NAK code", "sbus.nakcode",
2139 FT_UINT16, BASE_HEX, VALS(sbus_ack_nak_vals), 0,
2140 "SAIA S-Bus ACK/NAK response", HFILL }
2143 { &hf_sbus_cpu_status,
2144 { "CPU status", "sbus.CPU_status",
2145 FT_UINT8, BASE_HEX, VALS(sbus_CPU_status), 0,
2146 "SAIA PCD CPU status", HFILL }
2149 { &hf_sbus_week_day,
2150 { "RTC calendar week and week day", "sbus.rtc.week_day",
2151 FT_UINT16, BASE_HEX, NULL, 0,
2152 "Calendar week and week day number of the real time clock", HFILL }
2155 { &hf_sbus_date,
2156 { "RTC date (YYMMDD)", "sbus.rtc.date",
2157 FT_UINT24, BASE_HEX, NULL, 0,
2158 "Year, month and day of the real time clock", HFILL }
2161 { &hf_sbus_time,
2162 { "RTC time (HHMMSS)", "sbus.rtc.time",
2163 FT_UINT24, BASE_HEX, NULL, 0,
2164 "Time of the real time clock", HFILL }
2167 { &hf_sbus_web_size,
2168 { "Web server packet size", "sbus.web.size",
2169 FT_UINT8, BASE_HEX, NULL, 0,
2170 NULL, HFILL }
2173 { &hf_sbus_web_aid,
2174 { "AID", "sbus.web.aid",
2175 FT_UINT8, BASE_HEX, NULL, 0,
2176 "Web server command/status code (AID)", HFILL }
2179 { &hf_sbus_web_seq,
2180 { "Sequence", "sbus.web.seq",
2181 FT_UINT8, BASE_HEX, NULL, 0,
2182 "Web server sequence nr (PACK_N)", HFILL }
2185 { &hf_sbus_rdwr_block_length,
2186 { "Read/write block telegram length", "sbus.block.length",
2187 FT_UINT8, BASE_DEC, NULL, 0,
2188 NULL, HFILL }
2191 { &hf_sbus_rdwr_block_length_ext,
2192 { "Extended length (bytes)", "sbus.len_ext",
2193 FT_UINT32, BASE_DEC, NULL, 0,
2194 NULL, HFILL }
2197 { &hf_sbus_rdwr_telegram_type,
2198 { "Read/write block telegram type", "sbus.block.tlgtype",
2199 FT_UINT8, BASE_HEX, VALS(rdwrblock_vals), 0,
2200 "Type of RD/WR block telegram", HFILL }
2203 { &hf_sbus_rdwr_telegram_sequence,
2204 { "Sequence", "sbus.block.seq",
2205 FT_UINT8, BASE_DEC, NULL, 0,
2206 "Sequence number of block data stream telegram", HFILL }
2209 { &hf_sbus_rdwr_block_size,
2210 { "Block size in bytes", "sbus.block.size",
2211 FT_UINT32, BASE_DEC, NULL, 0,
2212 "The size of the block in bytes", HFILL }
2215 { &hf_sbus_rdwr_block_addr,
2216 { "Address inside block", "sbus.block.addr",
2217 FT_UINT32, BASE_DEC, NULL, 0,
2218 "The address inside a block", HFILL }
2222 { &hf_sbus_rdwr_file_name,
2223 { "File name", "sbus.block.filename",
2224 FT_STRING, BASE_NONE, NULL, 0,
2225 "Name of file to in RD/WR block telegram", HFILL }
2228 { &hf_sbus_rdwr_list_type,
2229 { "Get program block list, command type", "sbus.block.getlisttype",
2230 FT_UINT8, BASE_HEX, VALS(rdwrblock_list_type_vals), 0,
2231 "Type of the Get Program Block list request", HFILL }
2234 { &hf_sbus_rdwr_acknakcode,
2235 { "ACK/NAK code", "sbus.block.nakcode",
2236 FT_UINT8, BASE_HEX, VALS(rdwrblock_sts), 0,
2237 "ACK/NAK response for block write requests", HFILL }
2240 { &hf_sbus_crc,
2241 { "Checksum", "sbus.crc",
2242 FT_UINT16, BASE_HEX, NULL, 0,
2243 "CRC 16", HFILL }
2246 { &hf_sbus_crc_bad,
2247 { "Bad Checksum", "sbus.crc_bad",
2248 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
2249 "A bad checksum in the telegram", HFILL }},
2251 { &hf_sbus_flags_accu,
2252 { "ACCU", "sbus.flags.accu",
2253 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ACCU,
2254 "PCD Accumulator", HFILL }
2257 { &hf_sbus_flags_error,
2258 { "Error flag", "sbus.flags.error",
2259 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ERROR,
2260 "PCD error flag", HFILL }
2263 { &hf_sbus_flags_negative,
2264 { "N-flag", "sbus.flags.nflag",
2265 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_NEGATIVE,
2266 "Negative status flag", HFILL }
2269 { &hf_sbus_flags_zero,
2270 { "Z-flag", "sbus.flags.zflag",
2271 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ZERO,
2272 "Zero status flag", HFILL }
2275 { &hf_sbus_response_in,
2276 { "Response in frame nr.", "sbus.response_in",
2277 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2278 "The response to this Ether-S-Bus request is in this frame", HFILL }
2281 { &hf_sbus_response_to,
2282 { "Request in frame nr.", "sbus.response_to",
2283 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2284 "This is a response to the Ether-S-Bus request in this frame", HFILL }
2287 { &hf_sbus_response_time,
2288 { "Response time", "sbus.response_time",
2289 FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
2290 "The time between the request and the response", HFILL }
2293 { &hf_sbus_timeout,
2294 { "Time passed since first request", "sbus.timeout",
2295 FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
2296 "The time between the first (identical) request and the repetition", HFILL }
2299 { &hf_sbus_request_in,
2300 { "First request in frame nr.", "sbus.request_in",
2301 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2302 "The first request of this repeated request is in this frame", HFILL }
2307 /* Setup protocol subtree array */
2308 static gint *ett[] = {
2309 &ett_sbus,
2310 &ett_sbus_ether,
2311 &ett_sbus_data
2314 static ei_register_info ei[] = {
2315 { &ei_sbus_retry, { "sbus.retry", PI_SEQUENCE, PI_NOTE, "Repeated telegram (due to timeout?)", EXPFILL }},
2316 { &ei_sbus_telegram_not_acked, { "sbus.telegram_not_acked", PI_RESPONSE_CODE, PI_CHAT, "Telegram not acknowledged by PCD", EXPFILL }},
2317 { &ei_sbus_crc_bad, { "sbus.crc_bad.expert", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }},
2320 expert_module_t* expert_sbus;
2322 /* Register the protocol name and description */
2323 proto_sbus = proto_register_protocol("SAIA S-Bus", "SBUS", "sbus");
2325 /* Required function calls to register the header fields and subtrees used */
2326 proto_register_field_array(proto_sbus, hf, array_length(hf));
2327 proto_register_subtree_array(ett, array_length(ett));
2328 expert_sbus = expert_register_protocol(proto_sbus);
2329 expert_register_field_array(expert_sbus, ei, array_length(ei));
2330 register_init_routine(&sbus_init_protocol);
2333 void
2334 proto_reg_handoff_sbus(void)
2336 dissector_handle_t sbus_handle;
2338 sbus_handle = new_create_dissector_handle(dissect_sbus, proto_sbus);
2339 dissector_add_uint("udp.port", 5050, sbus_handle);
2343 * Editor modelines
2345 * Local Variables:
2346 * c-basic-offset: 7
2347 * tab-width: 8
2348 * indent-tabs-mode: nil
2349 * End:
2351 * ex: set shiftwidth=7 tabstop=8 expandtab:
2352 * :indentSize=7:tabSize=8:noTabs=true: