Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-sbus.c
blob5667910b3e2f5154f7f8c38fbeea0808692e019d
1 /* packet-sbus.c
2 * Routines for Ether-S-Bus dissection
3 * Copyright 2010, Christian Durrer <christian.durrer@sensemail.ch>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/conversation.h>
16 #include <epan/expert.h>
17 #include <epan/tfs.h>
18 #include <wsutil/array.h>
20 void proto_register_sbus(void);
21 void proto_reg_handoff_sbus(void);
23 static dissector_handle_t sbus_handle;
25 #define SBUS_UDP_PORT 5050 /* Not IANA registered */
27 /* Attribute values*/
28 #define SBUS_REQUEST 0x00
29 #define SBUS_RESPONSE 0x01
30 #define SBUS_ACKNAK 0x02
32 /*SBus command codes*/
33 #define SBUS_RD_COUNTER 0x00
34 #define SBUS_RD_DISPLAY_REGISTER 0x01
35 #define SBUS_RD_FLAG 0x02
36 #define SBUS_RD_INPUT 0x03
37 #define SBUS_RD_RTC 0x04
38 #define SBUS_RD_OUTPUT 0x05
39 #define SBUS_RD_REGISTER 0x06
40 #define SBUS_RD_TIMER 0x07
41 #define SBUS_WR_COUNTER 0x0A
42 #define SBUS_WR_FLAG 0x0B
43 #define SBUS_WR_RTC 0x0C
44 #define SBUS_WR_OUTPUT 0x0D
45 #define SBUS_WR_REGISTER 0x0E
46 #define SBUS_WR_TIMER 0x0F
47 #define SBUS_RDWR_MULTI_MEDIAS 0x13
48 #define SBUS_RD_PCD_STATUS_CPU0 0x14
49 #define SBUS_RD_PCD_STATUS_CPU1 0x15
50 #define SBUS_RD_PCD_STATUS_CPU2 0x16
51 #define SBUS_RD_PCD_STATUS_CPU3 0x17
52 #define SBUS_RD_PCD_STATUS_CPU4 0x18
53 #define SBUS_RD_PCD_STATUS_CPU5 0x19
54 #define SBUS_RD_PCD_STATUS_CPU6 0x1A
55 #define SBUS_RD_PCD_STATUS_OWN 0x1B
56 #define SBUS_RD_SBUS_STN_NBR 0x1D
57 #define SBUS_RD_USER_MEMORY 0x1E
58 #define SBUS_RD_PROGRAM_LINE 0x1F
59 #define SBUS_RD_PROGRAM_VERSION 0x20
60 #define SBUS_RD_TEXT 0x21
61 #define SBUS_RD_ACTIVE_TRANSITION 0x22
62 #define SBUS_WR_USER_MEMORY 0x23
63 #define SBUS_WR_PROGRAM_LINE 0x24
64 #define SBUS_WR_TEXT 0x25
65 #define SBUS_RUN_PROCEDURE_CPU0 0x28
66 #define SBUS_RUN_PROCEDURE_CPU1 0x29
67 #define SBUS_RUN_PROCEDURE_CPU2 0x2A
68 #define SBUS_RUN_PROCEDURE_CPU3 0x2B
69 #define SBUS_RUN_PROCEDURE_CPU4 0x2C
70 #define SBUS_RUN_PROCEDURE_CPU5 0x2D
71 #define SBUS_RUN_PROCEDURE_CPU6 0x2E
72 #define SBUS_RUN_PROCEDURE_OWN 0x2F
73 #define SBUS_RUN_PROCEDURE_ALL 0x30
74 #define SBUS_RESTART_COLD_CPU1 0x32
75 #define SBUS_RESTART_COLD_CPU2 0x33
76 #define SBUS_RESTART_COLD_CPU3 0x34
77 #define SBUS_RESTART_COLD_CPU4 0x35
78 #define SBUS_RESTART_COLD_CPU5 0x36
79 #define SBUS_RESTART_COLD_CPU6 0x37
80 #define SBUS_RESTART_COLD_OWN 0x38
81 #define SBUS_RESTART_COLD_ALL 0x39
82 #define SBUS_STOP_PROCEDURE_CPU0 0x3C
83 #define SBUS_STOP_PROCEDURE_CPU1 0x3D
84 #define SBUS_STOP_PROCEDURE_CPU2 0x3E
85 #define SBUS_STOP_PROCEDURE_CPU3 0x3F
86 #define SBUS_STOP_PROCEDURE_CPU4 0x40
87 #define SBUS_STOP_PROCEDURE_CPU5 0x41
88 #define SBUS_STOP_PROCEDURE_CPU6 0x42
89 #define SBUS_STOP_PROCEDURE_OWN 0x43
90 #define SBUS_STOP_PROCEDURE_ALL 0x44
91 #define SBUS_RD_STATUSFLAG_ACCU 0x46
92 #define SBUS_RD_BYTE 0x47
93 #define SBUS_RD_HALT_FAILURE_REG 0x48
94 #define SBUS_RD_INDEX_REGISTER 0x49
95 #define SBUS_RD_INSTRUCTION_POINTER 0x4A
96 #define SBUS_FIND_HISTORY 0x4B
97 #define SBUS_WR_STATUSFLAG_ACCU 0x50
98 #define SBUS_WR_BYTE 0x51
99 #define SBUS_WR_INDEX_REGISTER 0x52
100 #define SBUS_WR_INSTRUCTION_POINTER 0x53
101 #define SBUS_CLEAR_ALL 0x5A
102 #define SBUS_CLEAR_FLAGS 0x5B
103 #define SBUS_CLEAR_OUTPUTS 0x5C
104 #define SBUS_CLEAR_REGISTERS 0x5D
105 #define SBUS_CLEAR_TIMERS 0x5E
106 #define SBUS_RESTART_WARM_CPU1 0x64
107 #define SBUS_RESTART_WARM_CPU2 0x65
108 #define SBUS_RESTART_WARM_CPU3 0x66
109 #define SBUS_RESTART_WARM_CPU4 0x67
110 #define SBUS_RESTART_WARM_CPU5 0x68
111 #define SBUS_RESTART_WARM_CPU6 0x69
112 #define SBUS_RESTART_WARM_OWN 0x6A
113 #define SBUS_RESTART_WARM_ALL 0x6B
114 #define SBUS_CHANGE_BLOCK 0x6E
115 #define SBUS_CLEAR_HISTORY_FAILURE 0x6F
116 #define SBUS_DELETE_PROGRAM_LINE 0x70
117 #define SBUS_GO_CONDITIONAL 0x71
118 #define SBUS_INSERT_PROGRAM_LINE 0x72
119 #define SBUS_LOCAL_CYCLE 0x73
120 #define SBUS_ALL_CYCLES 0x74
121 #define SBUS_MAKE_TEXT 0x75
122 #define SBUS_EXECUTE_SINGLE_INSTR 0x76
123 #define SBUS_SINGLE_STEP 0x77
124 #define SBUS_XOB_17_INTERRUPT 0x82
125 #define SBUS_XOB_18_INTERRUPT 0x83
126 #define SBUS_XOB_19_INTERRUPT 0x84
127 #define SBUS_RD_HANGUP_TIMEOUT 0x91
128 #define SBUS_RD_DATA_BLOCK 0x96
129 #define SBUS_WR_DATA_BLOCK 0x97
130 #define SBUS_MAKE_DATA_BLOCK 0x98
131 #define SBUS_CLEAR_DATA_BLOCK 0x99
132 #define SBUS_CLEAR_TEXT 0x9A
133 #define SBUS_RD_BLOCK_ADDRESSES 0x9B
134 #define SBUS_RD_BLOCK_SIZES 0x9C
135 #define SBUS_RD_CURRENT_BLOCK 0x9D
136 #define SBUS_RD_CALL_STACK 0x9E
137 #define SBUS_RD_DBX 0x9F
138 #define SBUS_RD_USER_EEPROM_REGISTER 0xA1
139 #define SBUS_WR_USER_EEPROM_REGISTER 0xA3
140 #define SBUS_ERASE_FLASH 0xA5
141 #define SBUS_RESTART_COLD_FLAG 0xA6
142 #define SBUS_WR_SYSTEM_BUFFER 0xA7
143 #define SBUS_RD_SYSTEM_BUFFER 0xA8
144 #define SBUS_RD_WR_PCD_BLOCK 0xA9
145 #define SBUS_GET_DIAGNOSTIC 0xAA
146 #define SBUS_RD_SYSTEM_INFORMATION 0xAB
147 #define SBUS_CHANGE_BLOCKS_ON_RUN 0xAC
148 #define SBUS_FLASHCARD_TELEGRAM 0xAD
149 #define SBUS_DOWNLOAD_FIRMWARE 0xAE
150 #define SBUS_WEB_SERVER_SERIAL_COMM 0xAF
152 /* Bitfield in the arithmetic flags and accu*/
153 #define F_ACCU (1<<0) /* Accumulator of PCD */
154 #define F_ERROR (1<<1) /* Error flag of PCD */
155 #define F_NEGATIVE (1<<2) /* Negative arithmetic status flag */
156 #define F_ZERO (1<<3) /* Zero arithmetic status flag */
158 /* Bitfield in the system information*/
159 /*#define F_EMPTY (1<<0) always 0 */
160 #define F_MEMSIZE (1<<1) /* Memory size information */
161 #define F_TRACE (1<<2) /* Trace buffer feature */
162 #define F_INFO_B1 (1<<3) /* EEPROM information of slot B1 */
163 #define F_INFO_B2 (1<<4) /* EEPROM information of slot B2 */
164 #define F_PGU_BAUD (1<<5) /* PGU baudrate can be switched */
167 /* Read/write block command codes*/
168 #define SBUS_WR_START_OF_STREAM 0x00
169 #define SBUS_WR_BLOCK_DATA_STREAM 0x01
170 #define SBUS_WR_BLOCK_END_OF_STREAM 0x02
171 #define SBUS_WR_ABORT_BLOCK_STREAM 0x07
172 #define SBUS_WR_BLOCK_DATA_BYTES 0x08
173 #define SBUS_RD_BLOCK_START_OF_STREAM 0X10
174 #define SBUS_RD_BLOCK_DATA_STREAM 0x11
175 #define SBUS_RD_ABORT_BLOCK_STREAM 0x17
176 #define SBUS_RD_BLOCK_DATA_BYTES 0x18
177 #define SBUS_DELETE_BLOCK 0x20
178 #define SBUS_GET_BLOCK_SIZE 0x21
179 #define SBUS_GET_PROGRAM_BLOCK_LIST 0x22
181 /* Read/write block types*/
182 #define SBUS_RD_WR_CONFIGURATION_FILE 0x20
183 #define SBUS_RD_WR_PROGRAM_BLOCK_FILE 0x21
184 #define SBUS_RD_WR_UNKNOWN_BLOCK_TYPE 0x83
186 /* Read/write block error codes*/
187 #define SBUS_RD_WR_NAK 0x80
188 #define SBUS_RD_WR_NAK_INVALID_SIZE 0x8A
190 /* Initialize the protocol and registered fields */
191 static int proto_sbus;
192 static int hf_sbus_length;
193 static int hf_sbus_version;
194 static int hf_sbus_protocol;
195 static int hf_sbus_sequence;
196 static int hf_sbus_attribut;
197 static int hf_sbus_dest;
198 static int hf_sbus_address;
199 static int hf_sbus_command;
200 static int hf_sbus_command_extension;
201 static int hf_sbus_rcount;
202 static int hf_sbus_multimedia_length;
203 static int hf_sbus_sub_length;
204 static int hf_sbus_wcount;
205 static int hf_sbus_wcount_calculated;
206 static int hf_sbus_fio_count;
207 static int hf_sbus_addr_rtc;
208 static int hf_sbus_addr_iof;
209 static int hf_sbus_addr_db;
210 static int hf_sbus_addr_base_element;
211 static int hf_sbus_addr_eeprom;
212 static int hf_sbus_addr_prog;
213 static int hf_sbus_addr_68k;
214 static int hf_sbus_block_type;
215 static int hf_sbus_block_nr;
216 static int hf_sbus_nbr_elements;
217 static int hf_sbus_display_register;
218 static int hf_sbus_data_rtc;
219 static int hf_sbus_data_byte;
220 static int hf_sbus_data_byte_hex;
221 static int hf_sbus_data_iof;
222 static int hf_sbus_cpu_type;
223 static int hf_sbus_fw_version;
224 static int hf_sbus_sysinfo_nr;
225 static int hf_sbus_sysinfo0_1;
226 static int hf_sbus_sysinfo0_2;
227 static int hf_sbus_sysinfo0_3;
228 static int hf_sbus_sysinfo0_4;
229 static int hf_sbus_sysinfo0_5;
230 static int hf_sbus_acknackcode;
231 static int hf_sbus_cpu_status;
232 static int hf_sbus_week_day;
233 static int hf_sbus_date;
234 static int hf_sbus_time;
235 static int hf_sbus_crc;
236 static int hf_sbus_crc_status;
237 static int hf_sbus_flags_accu;
238 static int hf_sbus_flags_error;
239 static int hf_sbus_flags_negative;
240 static int hf_sbus_flags_zero;
241 /* Web server telegram */
242 static int hf_sbus_web_size;
243 static int hf_sbus_web_aid;
244 static int hf_sbus_web_seq;
245 /* Read/Write block telegram*/
246 static int hf_sbus_rdwr_block_length;
247 static int hf_sbus_rdwr_block_length_ext;
248 static int hf_sbus_rdwr_telegram_type;
249 static int hf_sbus_rdwr_telegram_sequence;
250 static int hf_sbus_rdwr_block_size;
251 static int hf_sbus_rdwr_block_addr;
252 static int hf_sbus_rdwr_file_name;
253 static int hf_sbus_rdwr_list_type;
254 static int hf_sbus_rdwr_acknakcode;
255 /* Request-Response tracking */
256 static int hf_sbus_response_in;
257 static int hf_sbus_response_to;
258 static int hf_sbus_response_time;
259 static int hf_sbus_timeout;
260 static int hf_sbus_request_in;
262 /* Initialize the subtree pointers */
263 static int ett_sbus;
264 static int ett_sbus_ether;
265 static int ett_sbus_data;
267 static expert_field ei_sbus_retry;
268 static expert_field ei_sbus_telegram_not_acked;
269 static expert_field ei_sbus_crc_bad;
270 static expert_field ei_sbus_telegram_not_implemented;
271 static expert_field ei_sbus_no_request_telegram;
273 /* True/False strings*/
274 static const true_false_string tfs_sbus_flags= {
275 "Is high",
276 "Is low"
279 static const true_false_string tfs_sbus_present= {
280 "Is present",
281 "Is not present"
284 /* value to string definitions*/
285 /* telegram types*/
286 static const value_string sbus_att_vals[] = {
287 {0, "Request"},
288 {1, "Response"},
289 {2, "ACK/NAK"},
290 {0, NULL}
292 /* Block types (6 and 7 corrected C. Durrer, 20.02.2019)*/
293 static const value_string sbus_block_types[] = {
294 {0x00, "COB"}, /* Cyclic organization block */
295 {0x01, "XOB"}, /* Exception organization block */
296 {0x02, "PB"}, /* Program block */
297 {0x03, "FB"}, /* Function block */
298 {0x04, "ST"}, /* Step of Graftec structure*/
299 {0x05, "TR"}, /* Transition of Graftec structure*/
300 {0x06, "TEXT"}, /* Text*/
301 {0x07, "DB"}, /* Data Block*/
302 {0x08, "SB"}, /* Sequential Block (Graftec)*/
303 {0x09, "DBX"}, /* Special Data Block*/
304 {0x10, "BACnet"}, /* BACnet configuration block */
305 {0x11, "CANopen"}, /* CANopen configuration */
306 {0x12, "LONIP"}, /* LONIP configuration */
307 {0x20, "Configuration file"}, /* LONIP configuration */
308 {0x21, "Program block file"}, /* LONIP configuration */
309 {0xFE, "All configuration blocks"}, /* all configuration blocks (delete blocks only) */
310 {0xFF, "All blocks"}, /* all blocks (incl. program blocks) (delete blocks only) */
311 {0, NULL}
313 static value_string_ext sbus_block_types_ext = VALUE_STRING_EXT_INIT(sbus_block_types);
315 /* ACK NAK values*/
316 static const value_string sbus_CPU_status[] = {
317 {0x43, "C"},
318 {0x44, "D"},
319 {0x48, "Halt"},
320 {0x52, "Run"},
321 {0x53, "Stop"},
322 {0x58, "X, Exceptional Intermediate Status (MODEMS+)"},
323 {0, NULL}
325 /* CPU status*/
326 static const value_string sbus_ack_nak_vals[] = {
327 {0, "ACK (Acknowledged)"},
328 {1, "NAK, no reason specified"},
329 {2, "NAK, because of password"},
330 {3, "NAK, PGU port is in reduced protocol"},
331 {4, "NAK, PGU port is already used"},
332 {0, NULL}
334 /* S-Bus commands*/
335 static const value_string sbus_command_vals[] = {
336 {0x00, "Read counter(s)"},
337 {0x01, "Read display register"},
338 {0x02, "Read flag(s)"},
339 {0x03, "Read input(s)"},
340 {0x04, "Read real time clock"},
341 {0x05, "Read output(s)"},
342 {0x06, "Read register(s)"},
343 {0x07, "Read timer(s)"},
344 {0x0A, "Write counter(s)"},
345 {0x0B, "Write flag(s)"},
346 {0x0C, "Write real time clock"},
347 {0x0D, "Write output(s)"},
348 {0x0E, "Write register(s)"},
349 {0x0F, "Write timer(s)"},
350 {0x13, "Read write multi-medias"},
351 {0x14, "Read PCD status, CPU 0"},
352 {0x15, "Read PCD status, CPU 1"},
353 {0x16, "Read PCD status, CPU 2"},
354 {0x17, "Read PCD status, CPU 3"},
355 {0x18, "Read PCD status, CPU 4"},
356 {0x19, "Read PCD status, CPU 5"},
357 {0x1A, "Read PCD status, CPU 6"},
358 {0x1B, "Read PCD status (own)"},
359 {0x1D, "Read S-Bus station number"},
360 {0x1E, "Read user memory*"},
361 {0x1F, "Read program line*"},
362 {0x20, "Read firmware version"},
363 {0x21, "Read text*"},
364 {0x22, "Read active transition*"},
365 {0x23, "Write user memory*"},
366 {0x24, "Write program line*"},
367 {0x25, "Write text*"},
368 {0x28, "Run procedure*, CPU 0"},
369 {0x29, "Run procedure*, CPU 1"},
370 {0x2A, "Run procedure*, CPU 2"},
371 {0x2B, "Run procedure*, CPU 3"},
372 {0x2C, "Run procedure*, CPU 4"},
373 {0x2D, "Run procedure*, CPU 5"},
374 {0x2E, "Run procedure*, CPU 6"},
375 {0x2F, "Run procedure* (own CPU)"},
376 {0x30, "Run procedure* (All CPUs)"},
377 {0x32, "Restart cold CPU 1*"},
378 {0x33, "Restart cold CPU 2*"},
379 {0x34, "Restart cold CPU 3*"},
380 {0x35, "Restart cold CPU 4*"},
381 {0x36, "Restart cold CPU 5*"},
382 {0x37, "Restart cold CPU 6*"},
383 {0x38, "Restart cold own CPU*"},
384 {0x39, "Restart cold all CPUs*"},
385 {0x3C, "Stop procedure*, CPU 0"},
386 {0x3D, "Stop procedure*, CPU 1"},
387 {0x3E, "Stop procedure*, CPU 2"},
388 {0x3F, "Stop procedure*, CPU 3"},
389 {0x40, "Stop procedure*, CPU 4"},
390 {0x41, "Stop procedure*, CPU 5"},
391 {0x42, "Stop procedure*, CPU 6"},
392 {0x43, "Stop procedure*, (own CPU)"},
393 {0x44, "Stop procedure*, (All CPUs)"},
394 {0x46, "Read arithmetic status and ACCU*"},
395 {0x47, "Read byte"},
396 {0x48, "Read halt failure register*"},
397 {0x49, "Read index register*"},
398 {0x4A, "Read instruction pointer*"},
399 {0x4B, "Find history*"},
400 {0x50, "Write arithmetic status and ACCU*"},
401 {0x51, "Write byte*"},
402 {0x52, "Write index register"},
403 {0x53, "Write instruction pointer*"},
404 {0x5A, "Clear all (F, O, R, T)*"},
405 {0x5B, "Clear flags*"},
406 {0x5C, "Clear outputs*"},
407 {0x5D, "Clear registers*"},
408 {0x5E, "Clear timers*"},
409 {0x64, "Restart warm CPU 1*"},
410 {0x65, "Restart warm CPU 2*"},
411 {0x66, "Restart warm CPU 3*"},
412 {0x67, "Restart warm CPU 4*"},
413 {0x68, "Restart warm CPU 5*"},
414 {0x69, "Restart warm CPU 6*"},
415 {0x6A, "Restart warm (own CPU)*"},
416 {0x6B, "Restart warm (All CPUs)*"},
417 {0x6E, "Change block*"},
418 {0x6F, "Clear history failure*"},
419 {0x70, "Delete program line*"},
420 {0x71, "Go conditional*"},
421 {0x72, "Insert program line*"},
422 {0x73, "Local cycles*"},
423 {0x74, "All cycles*"},
424 {0x75, "Make text*"},
425 {0x76, "Execute single instruction*"},
426 {0x77, "Single step*"},
427 {0x82, "XOB 17 interrupt"},
428 {0x83, "XOB 18 interrupt"},
429 {0x84, "XOB 19 interrupt"},
430 {0x91, "Read hangup timeout"},
431 {0x96, "Read data block"},
432 {0x97, "Write data block"},
433 {0x98, "Make data block*"},
434 {0x99, "Clear data block*"},
435 {0x9A, "Clear text*"},
436 {0x9B, "Read block address"},
437 {0x9C, "Read block sizes"},
438 {0x9D, "Read current block*"},
439 {0x9E, "Read call stack*"},
440 {0x9F, "Read DBX"},
441 {0xA1, "Read user EEPROM register"},
442 {0xA3, "Write user EEPROM register"},
443 {0xA5, "Erase flash*"},
444 {0xA6, "Restart cold flag*"},
445 {0xA7, "Write system buffer"},
446 {0xA8, "Read system buffer"},
447 {0xA9, "Read/write block data*"},
448 {0xAA, "Get diagnostic*"},
449 {0xAB, "Read system information*"},
450 {0xAC, "Changes blocks on run*"},
451 {0xAD, "Flashcard telegram*"},
452 {0xAE, "Download FW*"},
453 {0xAF, "Web server serial communication*"},
454 {0, NULL}
456 static value_string_ext sbus_command_vals_ext = VALUE_STRING_EXT_INIT(sbus_command_vals);
458 static const value_string webserver_aid_vals[] = {
459 {0x01, "Partial request"},
460 {0x02, "Request end"},
461 {0x07, "Get Data"},
462 {0x10, "Transfer OK"},
463 {0x11, "Partial answer"},
464 {0x12, "Last part of answer"},
465 {0x13, "Server not ready"},
466 {0, NULL}
468 static const value_string rdwrblock_vals[] = {
469 {0x00, "WR block start of stream"},
470 {0x01, "WR block data stream"},
471 {0x02, "WR block end of stream"},
472 {0x07, "Abort block WR stream"},
473 {0x08, "WR block data"},
474 {0x10, "RD block start of stream"},
475 {0x11, "RD block data stream"},
476 {0x17, "Abort block RD stream"},
477 {0x18, "RD block data"},
478 {0x20, "Delete block"},
479 {0x21, "Get block size"},
480 {0x22, "Get program block list"},
481 {0, NULL}
483 static value_string_ext rdwrblock_vals_ext = VALUE_STRING_EXT_INIT(rdwrblock_vals);
485 static const value_string rdwrblock_sts[] = {
486 {0x00, "ACK (Acknowledged)"},
487 {0x01, "Data"},
488 {0x02, "Busy"},
489 {0x03, "End of stream"},
490 {0x04, "Data EOF reached"},
491 {0x80, "NAK"},
492 {0x81, "NAK, unknown Tlg_Type"},
493 {0x82, "NAK, not supported Tlg_Type"},
494 {0x83, "NAK, unknown Block Type"},
495 {0x84, "NAK, out of sequence"},
496 {0x85, "NAK, not supported Block number"},
497 {0x86, "NAK, Block Size invalid (to big)"},
498 {0x87, "NAK, Block Address invalid"},
499 {0x88, "NAK, CRC invalid"},
500 {0x89, "NAK, invalid status"},
501 {0x8A, "NAK, invalid command size (w-count)"},
502 {0xFF, "Abort (stream)"},
503 {0, NULL}
505 static value_string_ext rdwrblock_sts_ext = VALUE_STRING_EXT_INIT(rdwrblock_sts);
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 unsigned 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 uint32_t conversation; /*Conversation ID*/
536 uint16_t sequence; /*Sequence number of request telegram*/
537 } sbus_request_key;
539 typedef struct {
540 uint8_t cmd_code; /*multimedia command code*/
541 uint8_t count; /*rcount of sub-request*/
542 } sbus_subrequest;
544 typedef struct {
545 uint8_t cmd_code; /*command code from request*/
546 uint8_t count; /*rcount value*/
547 uint8_t sysinfo; /*system information number*/
548 uint8_t block_tlg; /*telegram type of RD/WR block telegrams*/
549 uint8_t retry_count; /*number of retries*/
550 uint32_t req_frame; /*frame number of last request*/
551 uint32_t resp_frame; /*frame number of response*/
552 nstime_t req_time; /*time of the last request*/
553 uint8_t mm_request_count; /*multi-media subrequest count*/
554 wmem_list_t *sbus_subrequests; /*list containing sub requests of multi-media request*/
555 } sbus_request_val;
557 /* The hash structure (for conversations)*/
558 static wmem_map_t *sbus_request_hash;
560 static unsigned crc_calc (unsigned crc, unsigned val)
562 int indx;
563 unsigned ncrc;
565 indx = (((crc >> 8) ^ val) & 0xff);
566 ncrc = crc_table[indx] ^ ((crc << 8) & 0xffff);
568 return ncrc;
571 /* Hash functions*/
572 static int sbus_equal(const void *v, const void *w)
574 const sbus_request_key *v1 = (const sbus_request_key *)v;
575 const sbus_request_key *v2 = (const sbus_request_key *)w;
577 if (v1->conversation == v2->conversation &&
578 v1->sequence == v2->sequence) {
579 return 1;
581 return 0;
584 static unsigned sbus_hash(const void *v)
586 const sbus_request_key *key = (const sbus_request_key *)v;
587 unsigned val;
589 val = key->conversation + key->sequence;
590 return val;
593 /* check whether the packet looks like SBUS or not */
594 static bool
595 is_sbus_pdu(tvbuff_t *tvb)
597 uint32_t length;
599 /* we need at least 8 bytes to determine whether this is sbus or
600 not*/
601 if(tvb_captured_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_uint8(tvb, 4) > 0x01) {
621 return false;
623 /* Sixth byte indicates protocol type and must be 0*/
624 if ( tvb_get_uint8(tvb, 5) > 0x01 ) {
625 return false;
627 /* Seventh and eighth bytes indicate 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_uint8(tvb, 8) > 0x02 ) {
632 return false;
634 return true;
637 /*add the tree structure for one request media type to the tree*/
638 static int add_media_access_to_tree(int sbus_cmd_code, tvbuff_t *tvb, proto_tree *tree, int offset)
640 int i, j;
641 int sbus_media_cnt;
642 proto_tree *sub_tree;
643 uint8_t sbus_fio_cnt;
644 uint32_t sbus_binaries;
645 uint32_t sbus_binarymasked;
646 uint32_t sbus_show_bin;
647 uint32_t sbus_helper;
649 switch (sbus_cmd_code) {
650 /*Read Counter, Register or Timer*/
651 case SBUS_RD_COUNTER:
652 case SBUS_RD_REGISTER:
653 case SBUS_RD_TIMER:
654 sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
655 proto_tree_add_uint(tree,
656 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
657 offset += 1;
658 proto_tree_add_item(tree,
659 hf_sbus_addr_rtc, tvb, offset, 2, ENC_BIG_ENDIAN);
660 offset += 2;
661 break;
663 /*Read Flag, Input or Output*/
664 case SBUS_RD_FLAG:
665 case SBUS_RD_INPUT:
666 case SBUS_RD_OUTPUT:
667 sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
668 proto_tree_add_uint(tree,
669 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
670 offset += 1;
671 proto_tree_add_item(tree,
672 hf_sbus_addr_iof, tvb, offset, 2, ENC_BIG_ENDIAN);
673 offset += 2;
674 break;
676 /*Write Register Timer Counter*/
677 case SBUS_WR_COUNTER:
678 case SBUS_WR_REGISTER:
679 case SBUS_WR_TIMER:
680 sbus_media_cnt = (tvb_get_uint8(tvb,offset));
681 sbus_media_cnt = ((sbus_media_cnt - 1)/4);
682 proto_tree_add_uint(tree,
683 hf_sbus_wcount_calculated, tvb, offset,
684 1, sbus_media_cnt);
685 proto_tree_add_item(tree,
686 hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
687 offset += 1;
688 proto_tree_add_item(tree,
689 hf_sbus_addr_rtc, tvb, offset, 2, ENC_BIG_ENDIAN);
690 offset += 2;
691 /*Add subtree for Data*/
692 sub_tree = proto_tree_add_subtree(tree, tvb, offset,
693 ((sbus_media_cnt) * 4), ett_sbus_data, NULL, "Data");
694 for (i=((sbus_media_cnt)); i>0; i--) {
695 proto_tree_add_item(sub_tree,
696 hf_sbus_data_rtc, tvb, offset,
697 4, ENC_BIG_ENDIAN);
698 offset += 4;
700 break;
702 /* Write flags and outputs*/
703 case SBUS_WR_FLAG:
704 case SBUS_WR_OUTPUT:
705 sbus_media_cnt = (tvb_get_uint8(tvb,offset));
706 sbus_media_cnt = (sbus_media_cnt - 2);
707 proto_tree_add_uint(tree,
708 hf_sbus_wcount_calculated, tvb, offset,
709 1, sbus_media_cnt);
710 proto_tree_add_item(tree,
711 hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
712 offset += 1;
713 proto_tree_add_item(tree,
714 hf_sbus_addr_iof, tvb, offset, 2, ENC_BIG_ENDIAN);
715 offset += 2;
716 sbus_fio_cnt = (tvb_get_uint8(tvb,offset));
717 sbus_fio_cnt = ((sbus_fio_cnt + 1));
718 proto_tree_add_uint(tree,
719 hf_sbus_fio_count, tvb, offset, 1, sbus_fio_cnt);
720 offset += 1;
721 /*Add subtree for Data*/
722 sub_tree = proto_tree_add_subtree(tree, tvb, offset,
723 sbus_media_cnt, ett_sbus_data, NULL, "Data");
725 for (i=sbus_media_cnt; i>0; i--) {
726 sbus_helper = 1;
727 sbus_show_bin = 0;
728 sbus_binarymasked = 0x01;
729 sbus_binaries = tvb_get_uint8(tvb, offset);
730 for (j=0; j<8; j++) {
731 if ((sbus_binarymasked & sbus_binaries) != 0) {
732 sbus_show_bin = (sbus_show_bin + sbus_helper);
734 sbus_binarymasked = sbus_binarymasked<<1;
735 sbus_helper = 10 * sbus_helper;
738 proto_tree_add_uint_format(sub_tree,
739 hf_sbus_data_iof, tvb, offset, 1, sbus_show_bin,
740 "Binary data: %08u", sbus_show_bin);
741 offset += 1;
743 break;
744 case SBUS_RD_DATA_BLOCK:
745 sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
746 proto_tree_add_uint(tree,
747 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
748 offset += 1;
749 proto_tree_add_item(tree,
750 hf_sbus_addr_db, tvb, offset, 2, ENC_BIG_ENDIAN);
751 offset += 2;
752 /*add base element address*/
753 proto_tree_add_item(tree,
754 hf_sbus_addr_base_element, tvb, offset, 2, ENC_BIG_ENDIAN);
755 offset += 2;
756 break;
758 return offset;
763 /*add the tree structure for one response media type to the tree*/
764 static int add_media_response_to_tree(int cmd_code, int count, tvbuff_t *tvb, proto_tree *tree, int offset)
766 int i, j;
767 proto_tree *sub_tree;
768 uint32_t sbus_binaries;
769 uint32_t sbus_binarymasked;
770 uint32_t sbus_show_bin;
771 uint32_t sbus_helper;
773 switch (cmd_code) {
775 /*Add subtree for Data*/
776 case SBUS_RD_COUNTER:
777 case SBUS_RD_REGISTER:
778 case SBUS_RD_TIMER:
779 case SBUS_RD_USER_MEMORY:
780 case SBUS_RD_PROGRAM_LINE:
781 case SBUS_RD_USER_EEPROM_REGISTER:
782 case SBUS_RD_DATA_BLOCK:
783 sub_tree = proto_tree_add_subtree(tree, tvb, offset,
784 (count * 4), ett_sbus_data, NULL, "Data");
785 for (i=count; i>0; i--) {
786 proto_tree_add_item(sub_tree,
787 hf_sbus_data_rtc, tvb, offset,
788 4, ENC_BIG_ENDIAN);
789 offset += 4;
791 break;
793 /* Add binary data I, O, F*/
794 case SBUS_RD_FLAG:
795 case SBUS_RD_INPUT:
796 case SBUS_RD_OUTPUT:
797 /*Add subtree for Data*/
798 sub_tree = proto_tree_add_subtree(tree, tvb, offset,
799 (((count) + 7) / 8), ett_sbus_data, NULL, "Data");
801 for (i=(((count) + 7) / 8); i>0; i--) {
802 sbus_helper = 1;
803 sbus_show_bin = 0;
804 sbus_binarymasked = 0x01;
805 sbus_binaries = tvb_get_uint8(tvb, offset);
806 for (j=0; j<8; j++){
807 if ((sbus_binarymasked & sbus_binaries) != 0) {
808 sbus_show_bin = (sbus_show_bin + sbus_helper);
810 sbus_binarymasked = sbus_binarymasked<<1;
811 sbus_helper = 10 * sbus_helper;
814 proto_tree_add_uint_format(sub_tree,
815 hf_sbus_data_iof, tvb, offset, 1, sbus_show_bin,
816 "Binary data: %08u", sbus_show_bin);
817 offset += 1;
819 break;
821 return offset;
824 static int get_response_length(int cmd_code, int count)
827 int length;
828 length = 0;
830 switch (cmd_code) {
832 /*Get length of 32 bit data*/
833 case SBUS_RD_COUNTER:
834 case SBUS_RD_REGISTER:
835 case SBUS_RD_TIMER:
836 case SBUS_RD_USER_MEMORY:
837 case SBUS_RD_PROGRAM_LINE:
838 case SBUS_RD_USER_EEPROM_REGISTER:
839 case SBUS_RD_DATA_BLOCK:
840 length = count * 4;
841 break;
843 /* Get length of binary data I, O, F*/
844 case SBUS_RD_FLAG:
845 case SBUS_RD_INPUT:
846 case SBUS_RD_OUTPUT:
847 length = ((count) + 7) / 8;
848 break;
850 return length;
855 static int add_sbus_subrequest(tvbuff_t *tvb, wmem_list_t *request_list, int offset)
857 /*append subrequest info to requests lists and return number of sub-requests*/
858 int subrequest_count;
859 int internal_wcount;
860 int internal_subwcount;
861 int internal_offset;
862 int internal_last_offset;
864 internal_offset = offset;
865 subrequest_count = 0;
866 internal_wcount = tvb_get_uint8(tvb,internal_offset);
867 internal_last_offset = internal_wcount + offset + 1; /*check for new sub requests until this end offset*/
869 for(int i=0; i < 64; i +=1){ /*max sub-requests number is 64*/
870 if (internal_last_offset > internal_offset) {
871 sbus_subrequest *sub_req;
872 sub_req = wmem_new(wmem_file_scope(), sbus_subrequest);
874 internal_offset += 1; /*move to the next sub-request wcount*/
875 internal_subwcount = tvb_get_uint8(tvb,internal_offset);
876 internal_offset += 1;
877 sub_req->cmd_code = tvb_get_uint8(tvb,internal_offset);
878 internal_offset += 1;
879 sub_req->count = tvb_get_uint8(tvb,internal_offset) + 1;
880 internal_offset += internal_subwcount -1;
881 subrequest_count += 1;
883 wmem_list_append(request_list, sub_req);
886 return subrequest_count;
890 /*Dissect the telegram*/
891 static int
892 dissect_sbus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
895 /* Set up structures needed to add the protocol subtree and manage it */
896 proto_item *ti, *hi;
897 proto_tree *sbus_tree, *ethsbus_tree, *sbusdata_tree, *sbus_multimedia_tree;
899 int i; /*for CRC calculation*/
900 int offset;
901 int sbus_end_multimedia;
902 int sbus_eth_len;
903 unsigned sbus_crc_calc;
904 uint8_t sbus_attribut;
905 uint8_t sbus_media_cnt;
906 sbus_subrequest *mm_sub_req;
907 wmem_list_frame_t *frame;
908 uint8_t sbus_multimedia_total;
909 uint8_t sbus_multimedia_cnt;
910 uint8_t sbus_multimedia_cmd;
911 uint8_t sbus_multimedia_att;
912 uint8_t sbus_multimedia_bytes;
913 uint8_t sbus_cmd_code;
914 uint8_t sbus_web_size;
915 uint8_t sbus_web_aid;
916 uint8_t sbus_web_seq;
917 uint8_t sbus_rdwr_type;
918 uint8_t sbus_rdwr_sequence;
919 uint8_t sbus_rdwr_block_tlg;
920 uint8_t sbus_rdwr_block_type;
921 uint8_t sbus_rdwr_ack_nak;
922 uint8_t sbus_quint8_helper0;
923 uint16_t sbus_ack_code;
924 uint32_t sbus_rdwr_length;
925 uint32_t sbus_helper;
926 uint32_t sbus_helper1;
927 uint32_t sbus_helper2;
928 char *tmp_string;
929 nstime_t ns; /*we use this for the response time*/
931 /* Set up conversations*/
932 conversation_t *conversation;
933 sbus_request_key request_key, *new_request_key;
934 sbus_request_val *request_val;
935 /*sbus_multimedia_requests *multimedia_requests;*/
937 /* does this look like an sbus pdu? */
938 if(!is_sbus_pdu(tvb)){
939 return 0;
942 /* Make entries in Protocol column and Info column on summary display */
943 col_set_str(pinfo->cinfo, COL_PROTOCOL, "S-Bus");
944 col_clear(pinfo->cinfo, COL_INFO);
946 conversation = find_or_create_conversation(pinfo);
948 request_key.conversation = conversation->conv_index;
949 request_key.sequence = tvb_get_ntohs(tvb,6);
951 request_val = (sbus_request_val *) wmem_map_lookup(sbus_request_hash,
952 &request_key);
953 /*Get type of telegram for finding retries
954 *As we are storing the info in a hash table we need to update the info
955 *also in case this is no retry*/
956 sbus_attribut = tvb_get_uint8(tvb,8);
957 if (request_val && sbus_attribut == SBUS_REQUEST) {
958 if (request_val->req_frame < pinfo->num){ /*a retry; req_frame smaller this frame*/
959 request_val->retry_count +=1;
961 else { /*we have a conversation but this is not a retry so we store the packet info*/
962 request_val->retry_count = 0;
963 request_val->req_frame = pinfo->num; /*store actual frame nr.*/
964 request_val->req_time = pinfo->abs_ts;
967 if (request_val && (sbus_attribut == SBUS_RESPONSE ||
968 sbus_attribut == SBUS_ACKNAK)) { /*a response*/
969 request_val->resp_frame = pinfo->num; /*so store this frame nr.*/
971 /* Only allocate a new hash element when it's a request*/
972 sbus_attribut = tvb_get_uint8(tvb,8);
974 if ( !request_val && sbus_attribut == 0 ) {/* request telegram */
975 new_request_key = wmem_new(wmem_file_scope(), sbus_request_key);
976 *new_request_key = request_key;
978 request_val = wmem_new(wmem_file_scope(), sbus_request_val);
979 request_val->cmd_code=tvb_get_uint8(tvb,10);
980 request_val->retry_count=0;
981 request_val->req_frame = pinfo->num; /*store actual frame nr.*/
982 request_val->req_time = pinfo->abs_ts;
983 request_val->resp_frame = 0; /*response frame is not known yet*/
984 request_val->mm_request_count = 0; /*init to 0 in case it is no multi media request*/
986 if (((request_val->cmd_code) == SBUS_RD_USER_EEPROM_REGISTER) ||
987 ((request_val->cmd_code) == SBUS_WR_USER_EEPROM_REGISTER)) {
988 request_val->count=((tvb_get_uint8(tvb,12))+1);
989 } else if ((request_val->cmd_code) == SBUS_RDWR_MULTI_MEDIAS) {
990 request_val->count=tvb_get_uint8(tvb,11); /*length of all sub requests in bytes*/
991 /*create list for sub requests to be able to process response frame later on*/
992 request_val->sbus_subrequests = wmem_list_new(wmem_file_scope());
993 /*add the sub requests to the list*/
994 request_val->mm_request_count = add_sbus_subrequest(tvb, request_val->sbus_subrequests, 11);
996 } else {
997 request_val->count=((tvb_get_uint8(tvb,11))+1);
1000 /*Enter system info or telegram type (for rd/wr block telegrams)*/
1001 if ((request_val->cmd_code) == SBUS_RD_SYSTEM_INFORMATION) {
1002 request_val->sysinfo=(tvb_get_uint8(tvb,12));
1003 request_val->block_tlg=0x0;
1004 } else if ((request_val->cmd_code) == SBUS_RD_WR_PCD_BLOCK) {
1005 request_val->sysinfo=0x0;
1006 request_val->block_tlg=(tvb_get_uint8(tvb,12));
1007 } else {
1008 request_val->sysinfo = 0x0;
1009 request_val->block_tlg = 0x0;
1012 wmem_map_insert(sbus_request_hash, new_request_key, request_val);
1014 /* End of attaching data to hash table*/
1016 offset = 0;
1018 switch (sbus_attribut){
1019 case SBUS_REQUEST:
1020 sbus_cmd_code = tvb_get_uint8(tvb, 10);
1021 switch (sbus_cmd_code){
1022 case SBUS_WEB_SERVER_SERIAL_COMM:
1023 /* Special treatment of web server request
1024 * as this is very helpful to see more information in the packetlist */
1025 sbus_web_aid = tvb_get_uint8(tvb, 12);
1026 sbus_web_seq = tvb_get_uint8(tvb, 13);
1027 col_add_fstr(pinfo->cinfo, COL_INFO,
1028 "Web Server Request: %s (Seq No: %d)",
1029 val_to_str_const(sbus_web_aid,
1030 webserver_aid_vals,
1031 "Unknown Request!"),
1032 sbus_web_seq);
1033 break;
1034 case SBUS_RDWR_MULTI_MEDIAS:
1035 col_add_fstr( pinfo->cinfo, COL_INFO,
1036 "Request: Multi media telegram (%d sub requests)",
1037 request_val->mm_request_count);
1038 break;
1039 case SBUS_RD_WR_PCD_BLOCK:
1040 sbus_rdwr_type = tvb_get_uint8(tvb, 12);
1041 col_add_fstr( pinfo->cinfo, COL_INFO,
1042 "Request: %s",
1043 val_to_str_ext_const(sbus_rdwr_type,
1044 &rdwrblock_vals_ext,
1045 "This RD/WR block telegram is not implemented"));
1046 /* Add name of file to be written in case of start of file stream */
1047 if (sbus_rdwr_type == SBUS_WR_START_OF_STREAM) {
1048 sbus_rdwr_block_type = tvb_get_uint8(tvb, 14);
1049 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1050 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1051 sbus_quint8_helper0=0;
1052 for (i=19; i<43; i++) { /*max length is 24 chars*/
1053 /*find zero-termination of string*/
1054 if ((tvb_get_uint8(tvb, i)) == 0x00) {
1055 break;
1057 sbus_quint8_helper0 += 1;
1059 tmp_string = tvb_get_string_enc(pinfo->pool, tvb , 19,
1060 sbus_quint8_helper0, ENC_ASCII);
1061 col_append_fstr(pinfo->cinfo, COL_INFO,
1062 ": (File: %s)", tmp_string);
1064 } else if (sbus_rdwr_type == SBUS_RD_BLOCK_START_OF_STREAM) {
1065 sbus_rdwr_block_type = tvb_get_uint8(tvb, 14);
1066 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1067 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1068 sbus_quint8_helper0=0;
1069 for (i=15; i<39; i++) { /*max length is 24 chars*/
1070 /*find zero-termination of string*/
1071 if ((tvb_get_uint8(tvb, i)) == 0x00) {
1072 break;
1074 sbus_quint8_helper0 += 1;
1076 tmp_string = tvb_get_string_enc(pinfo->pool, tvb , 15,
1077 sbus_quint8_helper0, ENC_ASCII);
1078 col_append_fstr(pinfo->cinfo, COL_INFO,
1079 ": (File: %s)", tmp_string);
1082 break;
1084 default:
1085 /* All other requests */
1086 col_add_fstr(pinfo->cinfo, COL_INFO,
1087 "Request: %s",
1088 val_to_str_ext_const(sbus_cmd_code,
1089 &sbus_command_vals_ext,
1090 "Unknown Command!"));
1091 break;
1093 /*mark retries*/
1094 if (request_val->retry_count>0) {
1095 col_append_str(pinfo->cinfo, COL_INFO,
1096 " (Retry)");
1097 } /*no retry number as it is not always correctly calculated*/
1098 break;
1100 case SBUS_RESPONSE:
1101 /* Special treatment of web server request
1102 * as this is very helpful to see more information in the packetlist */
1103 if (request_val && ((request_val->cmd_code) == SBUS_WEB_SERVER_SERIAL_COMM)) {
1104 sbus_web_size = tvb_get_uint8(tvb,9);
1105 sbus_web_aid = tvb_get_uint8(tvb,10);
1106 col_add_fstr(pinfo->cinfo, COL_INFO,
1107 "Response: %s",
1108 val_to_str_const(sbus_web_aid,
1109 webserver_aid_vals, "Unknown Request!"));
1110 if (sbus_web_size > 1) {
1111 sbus_web_seq = tvb_get_uint8(tvb,11);
1112 col_append_fstr(pinfo->cinfo, COL_INFO,
1113 " (Seq No: %d)",
1114 sbus_web_seq);
1116 } else if (request_val && ((request_val->cmd_code) == SBUS_RDWR_MULTI_MEDIAS)) {
1117 /* Add some info for multi media response*/
1118 col_append_fstr(pinfo->cinfo, COL_INFO,
1119 "Response: Multi media (%d responses)",
1120 request_val->mm_request_count);
1122 } else if (request_val && ((request_val->cmd_code) == SBUS_RD_WR_PCD_BLOCK)) {
1123 /* Treat the ACK/NAK telgrams in a special way*/
1124 switch (request_val->block_tlg) {
1125 case SBUS_WR_START_OF_STREAM:
1126 case SBUS_WR_BLOCK_DATA_STREAM:
1127 case SBUS_WR_BLOCK_END_OF_STREAM:
1128 case SBUS_WR_ABORT_BLOCK_STREAM:
1129 case SBUS_WR_BLOCK_DATA_BYTES:
1130 case SBUS_DELETE_BLOCK:
1131 case SBUS_RD_ABORT_BLOCK_STREAM:
1132 sbus_rdwr_ack_nak = tvb_get_uint8(tvb, 10);
1133 col_add_fstr( pinfo->cinfo, COL_INFO,
1134 "Response: %s",
1135 val_to_str_ext_const(sbus_rdwr_ack_nak,
1136 &rdwrblock_sts_ext,
1137 "Unknown response!"));
1138 break;
1139 default:
1140 sbus_rdwr_type = tvb_get_uint8(tvb, 9);
1141 col_add_fstr( pinfo->cinfo, COL_INFO,
1142 "Response: (%d byte)", sbus_rdwr_type);
1143 break;
1146 } else {
1147 col_set_str(pinfo->cinfo, COL_INFO, "Response");
1149 break;
1151 case SBUS_ACKNAK:
1152 sbus_ack_code = tvb_get_ntohs(tvb,9);
1153 col_set_str(pinfo->cinfo, COL_INFO,
1154 val_to_str_const(sbus_ack_code,
1155 sbus_ack_nak_vals,
1156 "Unknown NAK response code!"));
1157 break;
1159 default:
1160 col_set_str(pinfo->cinfo, COL_INFO, "Unknown attribute");
1161 break;
1164 /* create display subtree for the protocol */
1165 if (tree) {
1167 ti = proto_tree_add_item(tree, proto_sbus, tvb, offset, -1, ENC_NA);
1168 sbus_tree = proto_item_add_subtree(ti, ett_sbus);
1170 /*Add subtree for Ether-S-Bus header*/
1171 ethsbus_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, 8, ett_sbus_ether, NULL, "Ether-S-Bus header");
1173 /* add an item to the subtree*/
1174 sbus_eth_len = tvb_get_ntohl(tvb,offset);
1175 proto_tree_add_item(ethsbus_tree,
1176 hf_sbus_length, tvb, offset, 4, ENC_BIG_ENDIAN);
1177 offset += 4;
1179 proto_tree_add_item(ethsbus_tree,
1180 hf_sbus_version, tvb, offset, 1, ENC_BIG_ENDIAN);
1181 offset += 1;
1183 proto_tree_add_item(ethsbus_tree,
1184 hf_sbus_protocol, tvb, offset, 1, ENC_BIG_ENDIAN);
1185 offset += 1;
1187 proto_tree_add_item(ethsbus_tree,
1188 hf_sbus_sequence, tvb, offset, 2, ENC_BIG_ENDIAN);
1189 offset += 2;
1191 /* Continue adding stuff to the main tree*/
1192 sbus_attribut = tvb_get_uint8(tvb,offset);
1193 proto_tree_add_item(sbus_tree,
1194 hf_sbus_attribut, tvb, offset, 1, ENC_BIG_ENDIAN);
1195 offset += 1;
1197 if (sbus_attribut == SBUS_REQUEST) {
1198 proto_tree_add_item(sbus_tree,
1199 hf_sbus_dest, tvb, offset, 1, ENC_BIG_ENDIAN);
1200 offset += 1;
1201 sbus_cmd_code = tvb_get_uint8(tvb,offset);
1202 proto_tree_add_item(sbus_tree,
1203 hf_sbus_command, tvb, offset, 1, ENC_BIG_ENDIAN);
1204 offset += 1;
1205 if (request_val && request_val->retry_count > 0) {/*this is a retry telegram*/
1206 expert_add_info(pinfo, sbus_tree, &ei_sbus_retry);
1207 nstime_delta(&ns, &pinfo->abs_ts, &request_val->req_time);
1208 proto_tree_add_time(sbus_tree, hf_sbus_timeout,
1209 tvb, 0, 0, &ns);
1210 proto_tree_add_uint(sbus_tree, hf_sbus_request_in, tvb, 0, 0,
1211 request_val->req_frame);
1213 if (request_val && request_val->resp_frame > pinfo->num){
1214 proto_tree_add_uint(sbus_tree, hf_sbus_response_in, tvb, 0, 0,
1215 request_val->resp_frame);
1217 switch (sbus_cmd_code) {
1218 /*Read Counter, Register or Timer*/
1219 case SBUS_RD_COUNTER:
1220 case SBUS_RD_REGISTER:
1221 case SBUS_RD_TIMER:
1222 offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset);
1223 break;
1225 /*Read Flag, Input or Output*/
1226 case SBUS_RD_FLAG:
1227 case SBUS_RD_INPUT:
1228 case SBUS_RD_OUTPUT:
1229 offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset);
1230 break;
1232 /*Write Register Timer Counter*/
1233 case SBUS_WR_COUNTER:
1234 case SBUS_WR_REGISTER:
1235 case SBUS_WR_TIMER:
1236 offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset);
1237 break;
1239 /* Write flags and outputs*/
1240 case SBUS_WR_FLAG:
1241 case SBUS_WR_OUTPUT:
1242 offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset);
1243 break;
1245 /* Request: Write Real time clock*/
1246 case SBUS_WR_RTC:
1247 /*Add subtree for Data*/
1248 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1249 8, ett_sbus_data, NULL, "Clock data");
1251 sbus_helper = tvb_get_uint8(tvb, (offset)); /*year-week*/
1252 sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*week-day*/
1253 proto_tree_add_uint_format_value(sbusdata_tree,
1254 hf_sbus_week_day, tvb, offset, 2, tvb_get_ntohs(tvb, offset),
1255 "%x, Week day: %x", sbus_helper, sbus_helper1);
1256 offset += 2;
1257 sbus_helper = tvb_get_uint8(tvb, (offset)); /*year*/
1258 sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*month*/
1259 sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*day*/
1260 proto_tree_add_uint_format_value(sbusdata_tree,
1261 hf_sbus_date, tvb, offset, 3, tvb_get_ntoh24(tvb, offset),
1262 "%02x/%02x/%02x", sbus_helper, sbus_helper1, sbus_helper2);
1263 offset += 3;
1264 sbus_helper = tvb_get_uint8(tvb, (offset)); /*hours*/
1265 sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*minutes*/
1266 sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*seconds*/
1267 proto_tree_add_uint_format_value(sbusdata_tree,
1268 hf_sbus_time, tvb, offset, 3, tvb_get_ntoh24(tvb, offset),
1269 "%02x:%02x:%02x", sbus_helper, sbus_helper1, sbus_helper2);
1270 offset += 3;
1271 break;
1272 /* Read/write multi media; multiple requests are transmitted within one single telegram*/
1273 case SBUS_RDWR_MULTI_MEDIAS:
1274 /*Add subtree for Sub-requests*/
1275 sbus_multimedia_total = tvb_get_uint8(tvb,offset) + 1;
1276 proto_tree_add_uint(sbus_tree,
1277 hf_sbus_multimedia_length, tvb, offset, 1, sbus_multimedia_total);
1278 offset += 1;
1279 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1280 sbus_multimedia_total, ett_sbus_data, NULL, "Sub requests");
1281 sbus_end_multimedia = offset + sbus_multimedia_total;
1282 /*Add subtree for each Subrequest*/
1283 for (i=0; i<64; i++) { /*max number of sub-requests is 64*/
1284 if(offset >= sbus_end_multimedia){
1285 break;
1287 sbus_multimedia_cnt = tvb_get_uint8(tvb,offset) + 1;
1288 sbus_multimedia_tree = proto_tree_add_subtree_format(sbusdata_tree, tvb, offset,
1289 sbus_multimedia_cnt + 1, ett_sbus_data, NULL, "Request %d", i);
1290 proto_tree_add_item(sbus_multimedia_tree,
1291 hf_sbus_sub_length, tvb, offset, 1, ENC_BIG_ENDIAN);
1292 offset +=1;
1293 sbus_cmd_code = tvb_get_uint8(tvb,offset);
1294 proto_tree_add_item(sbus_multimedia_tree,
1295 hf_sbus_command, tvb, offset, 1, ENC_BIG_ENDIAN);
1296 offset += 1;
1297 offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_multimedia_tree, offset);
1300 break;
1301 /* Read user memory or program line*/
1302 case SBUS_RD_USER_MEMORY:
1303 case SBUS_RD_PROGRAM_LINE:
1304 sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
1305 proto_tree_add_uint(sbus_tree,
1306 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
1307 offset += 1;
1308 proto_tree_add_item(sbus_tree,
1309 hf_sbus_addr_prog, tvb, offset, 3, ENC_BIG_ENDIAN);
1310 offset += 3;
1311 break;
1313 /*Write user memory*/
1314 case SBUS_WR_USER_MEMORY:
1315 sbus_media_cnt = (tvb_get_uint8(tvb,offset));
1316 sbus_media_cnt = ((sbus_media_cnt - 2)/4);
1317 proto_tree_add_uint(sbus_tree,
1318 hf_sbus_wcount_calculated, tvb, offset,
1319 1, sbus_media_cnt);
1320 proto_tree_add_item(sbus_tree,
1321 hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
1322 offset += 1;
1323 proto_tree_add_item(sbus_tree,
1324 hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
1325 offset += 3;
1326 /*Add subtree for Data*/
1327 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1328 ((sbus_media_cnt) * 4), ett_sbus_data, NULL, "Program lines");
1330 for (i=((sbus_media_cnt)); i>0; i--) {
1331 proto_tree_add_item(sbusdata_tree,
1332 hf_sbus_data_rtc, tvb, offset,
1333 4, ENC_BIG_ENDIAN);
1334 offset += 4;
1337 break;
1339 /* Read byte*/
1340 case SBUS_RD_BYTE:
1341 sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
1342 proto_tree_add_uint(sbus_tree,
1343 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
1344 offset += 1;
1345 proto_tree_add_item(sbus_tree,
1346 hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
1347 offset += 3;
1348 break;
1350 /* Write byte */
1351 case SBUS_WR_BYTE:
1352 sbus_media_cnt = (tvb_get_uint8(tvb,offset));
1353 sbus_media_cnt = (sbus_media_cnt - 2);
1354 proto_tree_add_uint(sbus_tree,
1355 hf_sbus_wcount_calculated, tvb, offset,
1356 1, sbus_media_cnt);
1357 proto_tree_add_item(sbus_tree,
1358 hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN);
1359 offset += 1;
1360 proto_tree_add_item(sbus_tree,
1361 hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
1362 offset += 3;
1363 /*Add subtree for Data*/
1364 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1365 ((sbus_media_cnt) * 4), ett_sbus_data, NULL, "Data (bytes)");
1367 for (i=sbus_media_cnt; i>0; i--) {
1368 proto_tree_add_item(sbusdata_tree,
1369 hf_sbus_data_byte, tvb, offset,
1370 1, ENC_BIG_ENDIAN);
1371 offset += 1;
1373 break;
1375 /*Read EEPROM register*/
1376 case SBUS_RD_USER_EEPROM_REGISTER:
1377 proto_tree_add_item(sbus_tree,
1378 hf_sbus_command_extension, tvb, offset, 1, ENC_BIG_ENDIAN);
1379 offset += 1;
1380 sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1;
1381 proto_tree_add_uint(sbus_tree,
1382 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
1383 offset += 1;
1384 proto_tree_add_item(sbus_tree,
1385 hf_sbus_addr_eeprom, tvb, offset, 2, ENC_BIG_ENDIAN);
1386 offset += 2;
1387 break;
1389 /*Request for reading system info*/
1390 /*Syinfo 05 is not implemented as no serial baud is possible*/
1391 case SBUS_RD_SYSTEM_INFORMATION:
1392 proto_tree_add_item(sbus_tree,
1393 hf_sbus_sysinfo_nr, tvb, offset, 1, ENC_BIG_ENDIAN);
1394 offset += 1;
1395 proto_tree_add_item(sbus_tree,
1396 hf_sbus_sysinfo_nr, tvb, offset, 1, ENC_BIG_ENDIAN);
1397 offset += 1;
1398 break;
1400 /* WebServer Request */
1401 case SBUS_WEB_SERVER_SERIAL_COMM:
1402 sbus_web_size = tvb_get_uint8(tvb,offset);
1403 proto_tree_add_uint(sbus_tree,
1404 hf_sbus_web_size, tvb, offset,
1405 1, sbus_web_size);
1406 offset += 1;
1408 sbus_web_aid = tvb_get_uint8(tvb,offset);
1409 proto_tree_add_uint(sbus_tree,
1410 hf_sbus_web_aid, tvb, offset,
1411 1, sbus_web_aid);
1412 offset += 1;
1414 sbus_web_seq = tvb_get_uint8(tvb,offset);
1415 proto_tree_add_uint(sbus_tree,
1416 hf_sbus_web_seq, tvb, offset,
1417 1, sbus_web_seq);
1418 offset += 1;
1420 if (sbus_web_size > 1) {
1421 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1422 (sbus_web_size - 1), ett_sbus_data, NULL, "Data (bytes)");
1424 for (i=sbus_web_size -1 ; i>0; i--) {
1425 proto_tree_add_item(sbusdata_tree,
1426 hf_sbus_data_byte, tvb, offset,
1427 1, ENC_BIG_ENDIAN);
1428 offset += 1;
1431 break;
1432 /* Read/write block request */
1433 case SBUS_RD_WR_PCD_BLOCK:
1434 if (tvb_get_uint8(tvb,offset) == 0xff){
1435 sbus_rdwr_length = ((tvb_get_ntohl(tvb,0))-15);
1436 proto_tree_add_uint(sbus_tree,
1437 hf_sbus_rdwr_block_length_ext, tvb, 0, 4, sbus_rdwr_length);
1438 offset += 1;
1439 } else {
1440 sbus_rdwr_length = tvb_get_uint8(tvb,offset);
1441 proto_tree_add_uint(sbus_tree,
1442 hf_sbus_rdwr_block_length, tvb, offset,
1443 1, sbus_rdwr_length);
1444 offset += 1;
1446 sbus_rdwr_type = tvb_get_uint8(tvb,offset);
1447 proto_tree_add_uint(sbus_tree,
1448 hf_sbus_rdwr_telegram_type, tvb, offset,
1449 1, sbus_rdwr_type);
1450 offset += 1;
1451 switch(sbus_rdwr_type) {
1452 case SBUS_WR_START_OF_STREAM:
1453 sbus_rdwr_block_type = tvb_get_uint8(tvb, 14);
1454 proto_tree_add_item(sbus_tree,
1455 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1456 1, ENC_BIG_ENDIAN);
1457 offset += 1;
1458 proto_tree_add_item(sbus_tree,
1459 hf_sbus_block_type, tvb, offset,
1460 1, ENC_BIG_ENDIAN);
1461 offset += 1;
1463 /* Check for file or block download */
1464 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1465 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1466 proto_tree_add_item(sbus_tree,
1467 hf_sbus_rdwr_block_size, tvb, offset,
1468 4, ENC_BIG_ENDIAN);
1469 offset += 4;
1470 sbus_quint8_helper0=0;
1471 /*find zero-termination of string*/
1472 for (i=19; i<43; i++) { /*max length string is 24 char*/
1473 if ((tvb_get_uint8(tvb, i)) == 0x00) {
1474 break;
1476 sbus_quint8_helper0 += 1;
1478 tmp_string = tvb_get_string_enc(pinfo->pool, tvb , 19, sbus_quint8_helper0, ENC_ASCII);
1479 proto_tree_add_string(sbus_tree,
1480 hf_sbus_rdwr_file_name, tvb, offset,
1481 sbus_quint8_helper0, tmp_string);
1482 offset += sbus_quint8_helper0;
1483 /*do not display a field for block data (skip)*/
1484 offset += (sbus_rdwr_length-6-sbus_quint8_helper0);
1485 } else { /* block write telegram, no file write*/
1486 proto_tree_add_item(sbus_tree,
1487 hf_sbus_block_nr, tvb, offset,
1488 2, ENC_BIG_ENDIAN);
1489 offset += 2;
1490 proto_tree_add_item(sbus_tree,
1491 hf_sbus_rdwr_block_size, tvb, offset,
1492 4, ENC_BIG_ENDIAN);
1493 offset += 4;
1494 /*do not display a field for block data (skip)*/
1495 offset += (sbus_rdwr_length-8);
1497 break;
1498 case SBUS_WR_BLOCK_DATA_STREAM:
1499 sbus_rdwr_sequence = tvb_get_uint8(tvb,offset);
1500 proto_tree_add_uint(sbus_tree,
1501 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1502 1, sbus_rdwr_sequence);
1503 offset += 1;
1504 /*do not display a field for block data (skip)*/
1505 offset += (sbus_rdwr_length-1);
1506 break;
1507 case SBUS_WR_BLOCK_END_OF_STREAM:
1508 sbus_rdwr_sequence = tvb_get_uint8(tvb,offset);
1509 proto_tree_add_uint(sbus_tree,
1510 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1511 1, sbus_rdwr_sequence);
1512 offset += 1;
1513 /*do not display a field for block data (skip it)*/
1514 offset += (sbus_rdwr_length-5);
1515 /*do not display a field for block CRC (skip it)*/
1516 offset += 4;
1517 break;
1518 case SBUS_WR_ABORT_BLOCK_STREAM:
1519 case SBUS_RD_ABORT_BLOCK_STREAM:
1520 break;
1521 case SBUS_WR_BLOCK_DATA_BYTES:
1522 sbus_rdwr_block_type = tvb_get_uint8(tvb, 14);
1523 proto_tree_add_item(sbus_tree,
1524 hf_sbus_block_type, tvb, offset,
1525 1, ENC_BIG_ENDIAN);
1526 offset += 1;
1528 /* Check for file or block download */
1529 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1530 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1531 proto_tree_add_item(sbus_tree,
1532 hf_sbus_rdwr_block_addr, tvb, offset,
1533 4, ENC_BIG_ENDIAN);
1534 offset += 4;
1535 sbus_quint8_helper0=0;
1536 /*find zero-termination of string*/
1537 for (i=19; i<43; i++) { /*max length string is 24 char*/
1538 if ((tvb_get_uint8(tvb, i)) == 0x00) {
1539 break;
1541 sbus_quint8_helper0 += 1;
1543 tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 19, sbus_quint8_helper0, ENC_ASCII);
1544 proto_tree_add_string(sbus_tree,
1545 hf_sbus_rdwr_file_name, tvb, offset,
1546 sbus_quint8_helper0, tmp_string);
1547 offset += sbus_quint8_helper0;
1548 /*do not display a field for block data (skip)*/
1549 offset += (sbus_rdwr_length-6-sbus_quint8_helper0);
1550 } else { /* block write telegram, no file write*/
1551 proto_tree_add_item(sbus_tree,
1552 hf_sbus_block_nr, tvb, offset,
1553 2, ENC_BIG_ENDIAN);
1554 offset += 2;
1555 proto_tree_add_item(sbus_tree,
1556 hf_sbus_rdwr_block_addr, tvb, offset,
1557 4, ENC_BIG_ENDIAN);
1558 offset += 4;
1559 /*do not display a field for block data (skip)*/
1560 offset += (sbus_rdwr_length-8);
1562 break;
1563 case SBUS_RD_BLOCK_START_OF_STREAM:
1564 sbus_rdwr_block_type = tvb_get_uint8(tvb, 14);
1565 proto_tree_add_item(sbus_tree,
1566 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1567 1, ENC_BIG_ENDIAN);
1568 offset += 1;
1569 proto_tree_add_item(sbus_tree,
1570 hf_sbus_block_type, tvb, offset,
1571 1, ENC_BIG_ENDIAN);
1572 offset += 1;
1574 /* Check for file or block download */
1575 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1576 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1577 sbus_quint8_helper0=0;
1578 /*find zero-termination of string*/
1579 for (i=14; i<38; i++) { /*max length string is 24 char*/
1580 if ((tvb_get_uint8(tvb, i)) == 0x00) {
1581 break;
1583 sbus_quint8_helper0 += 1;
1585 tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 14, sbus_quint8_helper0, ENC_ASCII);
1586 proto_tree_add_string(sbus_tree,
1587 hf_sbus_rdwr_file_name, tvb, offset,
1588 sbus_quint8_helper0, tmp_string);
1589 offset += sbus_quint8_helper0;
1590 } else { /* block write telegram, no file write*/
1591 proto_tree_add_item(sbus_tree,
1592 hf_sbus_block_nr, tvb, offset,
1593 2, ENC_BIG_ENDIAN);
1594 offset += 2;
1596 break;
1597 case SBUS_RD_BLOCK_DATA_STREAM:
1598 proto_tree_add_item(sbus_tree,
1599 hf_sbus_rdwr_telegram_sequence, tvb, offset,
1600 1, ENC_BIG_ENDIAN);
1601 offset += 1;
1602 break;
1603 case SBUS_RD_BLOCK_DATA_BYTES:
1604 sbus_rdwr_block_type = tvb_get_uint8(tvb, 13);
1605 proto_tree_add_item(sbus_tree,
1606 hf_sbus_block_type, tvb, offset,
1607 1, ENC_BIG_ENDIAN);
1608 offset += 1;
1609 /* Check for file or block read */
1610 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1611 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1612 /*reading from a file*/
1613 proto_tree_add_item(sbus_tree,
1614 hf_sbus_rdwr_block_addr, tvb, offset,
1615 4, ENC_BIG_ENDIAN);
1616 offset += 4;
1617 proto_tree_add_item(sbus_tree,
1618 hf_sbus_rdwr_block_size, tvb, offset,
1619 4, ENC_BIG_ENDIAN);
1620 offset += 4;
1621 sbus_quint8_helper0=0;
1622 /*find zero-termination of string*/
1623 for (i=22; i<46; i++) { /*max length string is 24 char*/
1624 if ((tvb_get_uint8(tvb, i)) == 0x00) {
1625 break;
1627 sbus_quint8_helper0 += 1;
1629 tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 22, sbus_quint8_helper0, ENC_ASCII);
1630 proto_tree_add_string(sbus_tree,
1631 hf_sbus_rdwr_file_name, tvb, offset,
1632 sbus_quint8_helper0, tmp_string);
1633 offset += sbus_quint8_helper0 + 1;
1634 } else { /* block read telegram, no file read*/
1635 proto_tree_add_item(sbus_tree,
1636 hf_sbus_block_nr, tvb, offset,
1637 2, ENC_BIG_ENDIAN);
1638 offset += 2;
1639 proto_tree_add_item(sbus_tree,
1640 hf_sbus_rdwr_block_addr, tvb, offset,
1641 4, ENC_BIG_ENDIAN);
1642 offset += 4;
1643 proto_tree_add_item(sbus_tree,
1644 hf_sbus_rdwr_block_size, tvb, offset,
1645 4, ENC_BIG_ENDIAN);
1646 offset += 4;
1648 break;
1649 case SBUS_DELETE_BLOCK:
1650 case SBUS_GET_BLOCK_SIZE:
1651 sbus_rdwr_block_type = tvb_get_uint8(tvb, 13);
1652 proto_tree_add_item(sbus_tree,
1653 hf_sbus_block_type, tvb, offset,
1654 1, ENC_BIG_ENDIAN);
1655 offset += 1;
1656 /* Check for file or block deletion */
1657 if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) ||
1658 (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) {
1659 /*delete a file*/
1660 sbus_quint8_helper0=0;
1661 /*find zero-termination of string*/
1662 for (i=14; i<38; i++) { /*max length string is 24 char*/
1663 if ((tvb_get_uint8(tvb, i)) == 0x00) {
1664 break;
1666 sbus_quint8_helper0 += 1;
1668 tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 14, sbus_quint8_helper0, ENC_ASCII);
1669 proto_tree_add_string(sbus_tree,
1670 hf_sbus_rdwr_file_name, tvb, offset,
1671 sbus_quint8_helper0, tmp_string);
1672 offset += sbus_quint8_helper0 + 1;
1673 } else { /* delete a block*/
1674 proto_tree_add_item(sbus_tree,
1675 hf_sbus_block_nr, tvb, offset,
1676 2, ENC_BIG_ENDIAN);
1677 offset += 2;
1679 break;
1680 case SBUS_GET_PROGRAM_BLOCK_LIST:
1681 proto_tree_add_item(sbus_tree,
1682 hf_sbus_rdwr_list_type, tvb, offset,
1683 1, ENC_BIG_ENDIAN);
1684 offset += 1;
1685 break;
1687 default:
1688 break;
1691 break;
1692 case SBUS_RD_DATA_BLOCK:
1693 offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset);
1695 break;
1697 /*Inform that command was not dissected and add remaining length*/
1698 default:
1699 if (sbus_eth_len > 13) { /*13 bytes is the minimal length of a request telegram...*/
1700 sbus_helper = sbus_eth_len - (offset + 2);
1701 proto_tree_add_expert(sbus_tree, pinfo, &ei_sbus_telegram_not_implemented, tvb, offset, sbus_helper);
1702 offset = offset + sbus_helper;
1704 break;
1708 /* Response dissection*/
1709 if (sbus_attribut == SBUS_RESPONSE && request_val) {
1710 /*add response time*/
1711 nstime_delta(&ns, &pinfo->abs_ts, &request_val->req_time);
1712 proto_tree_add_time(sbus_tree, hf_sbus_response_time,
1713 tvb, 0, 0, &ns);
1714 /*add reference to request telegram*/
1715 proto_tree_add_uint(sbus_tree, hf_sbus_response_to, tvb, 0, 0,
1716 request_val->req_frame);
1718 switch (request_val->cmd_code) {
1719 /* Response: 32 bit values*/
1720 case SBUS_RD_COUNTER:
1721 case SBUS_RD_REGISTER:
1722 case SBUS_RD_TIMER:
1723 case SBUS_RD_USER_MEMORY:
1724 case SBUS_RD_PROGRAM_LINE:
1725 case SBUS_RD_USER_EEPROM_REGISTER:
1726 case SBUS_RD_DATA_BLOCK:
1727 /*Add subtree for Data*/
1728 offset = add_media_response_to_tree(request_val->cmd_code, request_val->count, tvb, sbus_tree, offset);
1729 break;
1731 /* Response: PCD Display register*/
1732 case SBUS_RD_DISPLAY_REGISTER:
1733 proto_tree_add_item(sbus_tree,
1734 hf_sbus_display_register, tvb, offset, 4, ENC_BIG_ENDIAN);
1735 offset += 4;
1736 break;
1738 /* Add binary data I, O, F*/
1739 case SBUS_RD_FLAG:
1740 case SBUS_RD_INPUT:
1741 case SBUS_RD_OUTPUT:
1742 /*Add subtree for Data*/
1743 offset = add_media_response_to_tree(request_val->cmd_code, request_val->count, tvb, sbus_tree, offset);
1744 break;
1746 /* Response: Real time clock value*/
1747 case SBUS_RD_RTC:
1748 /*Add subtree for Data*/
1749 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1750 8, ett_sbus_data, NULL, "Clock data");
1752 sbus_helper = tvb_get_uint8(tvb, (offset)); /*year-week*/
1753 sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*week-day*/
1754 proto_tree_add_uint_format_value(sbusdata_tree,
1755 hf_sbus_week_day, tvb, offset, 2, tvb_get_ntohs(tvb, offset),
1756 "%x, Week day: %x", sbus_helper, sbus_helper1);
1757 offset += 2;
1758 sbus_helper = tvb_get_uint8(tvb, (offset)); /*year*/
1759 sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*month*/
1760 sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*day*/
1761 proto_tree_add_uint_format_value(sbusdata_tree,
1762 hf_sbus_date, tvb, offset, 3, tvb_get_ntoh24(tvb, offset),
1763 "%02x/%02x/%02x", sbus_helper, sbus_helper1, sbus_helper2);
1764 offset += 3;
1765 sbus_helper = tvb_get_uint8(tvb, (offset)); /*hours*/
1766 sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*minutes*/
1767 sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*seconds*/
1768 proto_tree_add_uint_format_value(sbusdata_tree,
1769 hf_sbus_time, tvb, offset, 3, tvb_get_ntoh24(tvb, offset),
1770 "%02x:%02x:%02x", sbus_helper, sbus_helper1, sbus_helper2);
1771 offset += 3;
1772 break;
1774 case SBUS_RDWR_MULTI_MEDIAS:
1775 /*Add subtree for Subrequests*/
1776 sbus_multimedia_total = tvb_get_uint8(tvb,offset);
1777 proto_tree_add_uint(sbus_tree,
1778 hf_sbus_multimedia_length, tvb, offset, 1, sbus_multimedia_total);
1779 offset += 1;
1780 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1781 sbus_multimedia_total, ett_sbus_data, NULL, "Sub responses");
1782 sbus_end_multimedia = offset + sbus_multimedia_total;
1783 i = 0;
1784 /* Start at front of list and cycle through possible sub-requests,
1785 until all bytes or all requests are processed */
1786 frame = wmem_list_head(request_val->sbus_subrequests);
1787 while (frame && (offset < sbus_end_multimedia)) {
1788 mm_sub_req = (sbus_subrequest *)wmem_list_frame_data(frame);
1789 sbus_multimedia_cmd = mm_sub_req->cmd_code;
1790 sbus_multimedia_cnt = mm_sub_req->count;
1792 /*get the attribute of the sub-response (1: response, 2: ACK/NACK)*/
1793 sbus_multimedia_att = tvb_get_uint8(tvb,offset + 1) ;
1795 if (sbus_multimedia_att == SBUS_ACKNAK) {
1796 sbus_multimedia_tree = proto_tree_add_subtree_format(sbusdata_tree, tvb, offset,
1797 4, ett_sbus_data, NULL, "Response %d", i);
1798 proto_tree_add_item(sbus_multimedia_tree,
1799 hf_sbus_sub_length, tvb, offset, 1, ENC_BIG_ENDIAN);
1800 offset +=1;
1801 proto_tree_add_item(sbus_multimedia_tree,
1802 hf_sbus_attribut, tvb, offset, 1, ENC_BIG_ENDIAN);
1803 offset +=1;
1804 hi = proto_tree_add_item(sbus_multimedia_tree,
1805 hf_sbus_acknackcode, tvb, offset, 2, ENC_BIG_ENDIAN);
1806 if (tvb_get_uint8(tvb, (offset+1)) > 0) {
1807 expert_add_info(pinfo, hi, &ei_sbus_telegram_not_acked);
1809 offset += 2;
1811 } else { /*response containing data*/
1812 sbus_multimedia_bytes = get_response_length(sbus_multimedia_cmd, sbus_multimedia_cnt);
1813 sbus_multimedia_tree = proto_tree_add_subtree_format(sbusdata_tree, tvb, offset,
1814 sbus_multimedia_bytes + 2, ett_sbus_data, NULL, "Response %d", i);
1815 proto_tree_add_item(sbus_multimedia_tree,
1816 hf_sbus_sub_length, tvb, offset, 1, ENC_BIG_ENDIAN);
1817 offset +=1;
1818 proto_tree_add_item(sbus_multimedia_tree,
1819 hf_sbus_attribut, tvb, offset, 1, ENC_BIG_ENDIAN);
1820 offset +=1;
1822 add_media_response_to_tree(sbus_multimedia_cmd, sbus_multimedia_cnt, tvb, sbus_multimedia_tree, offset);
1823 offset +=sbus_multimedia_bytes ;
1826 /* After processing this sub request, proceed to the next */
1827 frame = wmem_list_frame_next(frame);
1828 i++;
1831 break;
1833 /* Response: CPU status, the command codes 14..1B are concerned*/
1834 case SBUS_RD_PCD_STATUS_CPU0:
1835 case SBUS_RD_PCD_STATUS_CPU1:
1836 case SBUS_RD_PCD_STATUS_CPU2:
1837 case SBUS_RD_PCD_STATUS_CPU3:
1838 case SBUS_RD_PCD_STATUS_CPU4:
1839 case SBUS_RD_PCD_STATUS_CPU5:
1840 case SBUS_RD_PCD_STATUS_CPU6:
1841 case SBUS_RD_PCD_STATUS_OWN:
1842 proto_tree_add_item(sbus_tree,
1843 hf_sbus_cpu_status, tvb, offset, 1, ENC_BIG_ENDIAN);
1844 offset += 1;
1845 break;
1847 /* Response: Station address*/
1848 case SBUS_RD_SBUS_STN_NBR:
1849 proto_tree_add_item(sbus_tree,
1850 hf_sbus_address, tvb, offset, 1, ENC_BIG_ENDIAN);
1851 offset += 1;
1852 break;
1854 /* Response: Firmware version */
1855 case SBUS_RD_PROGRAM_VERSION:
1856 /*PCD type*/
1857 proto_tree_add_item(sbus_tree, hf_sbus_cpu_type, tvb, offset, 5, ENC_ASCII);
1858 offset += 5;
1859 /*FW version*/
1860 proto_tree_add_item(sbus_tree, hf_sbus_fw_version, tvb, offset, 3, ENC_ASCII);
1861 offset += 4;
1862 break;
1864 /* Response for Status Flags*/
1865 case SBUS_RD_STATUSFLAG_ACCU:
1866 /*Add subtree for Data*/
1867 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1868 1, ett_sbus_data, NULL, "ACCU and arithmetic status");
1870 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_accu,
1871 tvb, offset, 1, ENC_BIG_ENDIAN);
1872 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_error,
1873 tvb, offset, 1, ENC_BIG_ENDIAN);
1874 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_negative,
1875 tvb, offset, 1, ENC_BIG_ENDIAN);
1876 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_zero,
1877 tvb, offset, 1, ENC_BIG_ENDIAN);
1878 offset +=1;
1879 break;
1881 /* Response for Read byte */
1882 case SBUS_RD_BYTE:
1883 /*Add subtree for Data*/
1884 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1885 (request_val->count), ett_sbus_data, NULL, "Data (bytes)");
1887 for (i=(request_val->count); i>0; i--) {
1888 proto_tree_add_item(sbusdata_tree,
1889 hf_sbus_data_byte, tvb, offset,
1890 1, ENC_BIG_ENDIAN);
1891 offset += 1;
1893 break;
1895 /* Response for Read Index register */
1896 case SBUS_RD_INDEX_REGISTER:
1897 /*Add subtree for Data*/
1898 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1899 2, ett_sbus_data, NULL, "Data (hex bytes)");
1901 for (i=0; i<2; i++) { /*2 bytes*/
1902 proto_tree_add_item(sbusdata_tree,
1903 hf_sbus_data_byte_hex, tvb, offset,
1904 1, ENC_BIG_ENDIAN);
1905 offset += 1;
1907 break;
1909 /* Response: Instruction pointer*/
1910 case SBUS_RD_INSTRUCTION_POINTER:
1911 proto_tree_add_item(sbus_tree,
1912 hf_sbus_addr_prog, tvb, offset, 3, ENC_BIG_ENDIAN);
1913 offset += 3;
1914 break;
1916 /*Response for Find History*/
1917 case SBUS_FIND_HISTORY:
1918 proto_tree_add_item(sbus_tree,
1919 hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN);
1920 offset += 3;
1921 proto_tree_add_item(sbus_tree,
1922 hf_sbus_nbr_elements, tvb, offset, 2, ENC_BIG_ENDIAN);
1923 offset += 2;
1924 break;
1926 /* Response: Read current block*/
1927 case SBUS_RD_CURRENT_BLOCK:
1928 proto_tree_add_item(sbus_tree,
1929 hf_sbus_block_type, tvb, offset, 1, ENC_BIG_ENDIAN);
1930 offset += 1;
1931 proto_tree_add_item(sbus_tree,
1932 hf_sbus_block_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
1933 offset += 2;
1934 break;
1936 /* Response: Read system information (without interpretation of module info)*/
1937 case SBUS_RD_SYSTEM_INFORMATION:
1938 if (request_val->sysinfo == 0x00){ /*sysinfo 0*/
1939 offset += 1; /* this byte is always 0x01*/
1940 /*Add subtree for Data*/
1941 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1942 1, ett_sbus_data, NULL, "System info");
1944 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_1,
1945 tvb, offset, 1, ENC_BIG_ENDIAN);
1946 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_2,
1947 tvb, offset, 1, ENC_BIG_ENDIAN);
1948 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_3,
1949 tvb, offset, 1, ENC_BIG_ENDIAN);
1950 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_4,
1951 tvb, offset, 1, ENC_BIG_ENDIAN);
1952 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_5,
1953 tvb, offset, 1, ENC_BIG_ENDIAN);
1954 offset += 1;
1955 } else {
1956 /*do not dissect all system info telegrams as there is no need*/
1957 offset = (tvb_get_uint8(tvb,9) + 10);
1959 break;
1961 /* Response: Webserver request */
1962 case SBUS_WEB_SERVER_SERIAL_COMM:
1963 sbus_web_size = tvb_get_uint8(tvb,offset);
1964 proto_tree_add_uint(sbus_tree,
1965 hf_sbus_web_size, tvb, offset,
1966 1, sbus_web_size);
1967 offset += 1;
1969 sbus_web_aid = tvb_get_uint8(tvb,offset);
1970 proto_tree_add_uint(sbus_tree,
1971 hf_sbus_web_aid, tvb, offset,
1972 1, sbus_web_aid);
1973 offset += 1;
1975 if (sbus_web_size > 1) {
1976 sbus_web_seq = tvb_get_uint8(tvb,offset);
1977 proto_tree_add_uint(sbus_tree,
1978 hf_sbus_web_seq, tvb, offset,
1979 1, sbus_web_seq);
1980 offset += 1;
1982 sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset,
1983 (sbus_web_size - 2), ett_sbus_data, NULL, "Data (bytes)");
1985 for (i=sbus_web_size - 2; i>0; i--) {
1986 proto_tree_add_item(sbusdata_tree,
1987 hf_sbus_data_byte, tvb, offset,
1988 1, ENC_BIG_ENDIAN);
1989 offset += 1;
1992 break;
1993 /* Response: Read/Write block data */
1994 case SBUS_RD_WR_PCD_BLOCK:
1995 sbus_rdwr_block_tlg = request_val->block_tlg;
1996 sbus_rdwr_length = tvb_get_uint8(tvb,offset);
1997 proto_tree_add_uint(sbus_tree,
1998 hf_sbus_rdwr_block_length, tvb, offset,
1999 1, sbus_rdwr_length);
2000 offset += 1;
2001 hi = proto_tree_add_item(sbus_tree,
2002 hf_sbus_rdwr_acknakcode, tvb, offset,
2003 1, ENC_BIG_ENDIAN);
2004 if ((tvb_get_uint8(tvb, offset) >= SBUS_RD_WR_NAK)&&
2005 (tvb_get_uint8(tvb, offset) <= SBUS_RD_WR_NAK_INVALID_SIZE)) {
2006 expert_add_info(pinfo, hi, &ei_sbus_telegram_not_acked);
2008 offset += 1;
2009 switch(sbus_rdwr_block_tlg) {
2010 case SBUS_WR_START_OF_STREAM:
2011 case SBUS_WR_BLOCK_DATA_STREAM:
2012 case SBUS_WR_BLOCK_END_OF_STREAM:
2013 proto_tree_add_item(sbus_tree,
2014 hf_sbus_rdwr_telegram_sequence, tvb, offset,
2015 1, ENC_BIG_ENDIAN);
2016 offset += 1;
2017 break;
2018 case SBUS_WR_ABORT_BLOCK_STREAM:
2019 case SBUS_RD_ABORT_BLOCK_STREAM:
2020 case SBUS_WR_BLOCK_DATA_BYTES:
2021 case SBUS_DELETE_BLOCK:
2022 break;
2023 case SBUS_RD_BLOCK_START_OF_STREAM:
2024 proto_tree_add_item(sbus_tree,
2025 hf_sbus_rdwr_telegram_sequence, tvb, offset,
2026 1, ENC_BIG_ENDIAN);
2027 offset += 1;
2028 proto_tree_add_item(sbus_tree,
2029 hf_sbus_rdwr_block_size, tvb, offset,
2030 4, ENC_BIG_ENDIAN);
2031 offset += 4;
2032 /*do not display a field for block data (skip)*/
2033 offset += (sbus_rdwr_length-6);
2034 break;
2035 case SBUS_RD_BLOCK_DATA_STREAM:
2036 proto_tree_add_item(sbus_tree,
2037 hf_sbus_rdwr_telegram_sequence, tvb, offset,
2038 1, ENC_BIG_ENDIAN);
2039 offset += 1;
2040 /*do not display a field for block data (skip)*/
2041 offset += (sbus_rdwr_length-2);
2042 break;
2043 case SBUS_RD_BLOCK_DATA_BYTES:
2044 /*do not display a field for block data (skip)*/
2045 offset += (sbus_rdwr_length-1);
2046 break;
2047 case SBUS_GET_BLOCK_SIZE:
2048 sbus_rdwr_block_type = tvb_get_uint8(tvb, 10);
2049 /* Check for unknown block type */
2050 if (sbus_rdwr_block_type == SBUS_RD_WR_UNKNOWN_BLOCK_TYPE) {
2051 /*unknown block, no more data follows*/
2052 } else { /* add block size and CRC32 in case of known block*/
2053 proto_tree_add_item(sbus_tree,
2054 hf_sbus_rdwr_block_size, tvb, offset,
2055 4, ENC_BIG_ENDIAN);
2056 offset += 4;
2057 /*Now the CRC32 follows, but I don't bother calculating it*/
2058 offset += 4;
2060 break;
2061 case SBUS_GET_PROGRAM_BLOCK_LIST:
2062 proto_tree_add_item(sbus_tree,
2063 hf_sbus_block_type, tvb, offset,
2064 1, ENC_BIG_ENDIAN);
2065 offset += 1;
2066 proto_tree_add_item(sbus_tree,
2067 hf_sbus_block_nr, tvb, offset,
2068 2, ENC_BIG_ENDIAN);
2069 offset += 2;
2070 proto_tree_add_item(sbus_tree,
2071 hf_sbus_rdwr_block_size, tvb, offset,
2072 4, ENC_BIG_ENDIAN);
2073 offset += 4;
2074 /*do not display block_timestamp as no description is available*/
2075 offset += (sbus_rdwr_length-8);
2076 break;
2077 default:
2078 break;
2080 break;
2082 /*Inform that response was not dissected and add remaining length*/
2083 default:
2084 sbus_helper = sbus_eth_len - (offset + 2);
2085 proto_tree_add_expert(sbus_tree, pinfo, &ei_sbus_telegram_not_implemented, tvb, offset, sbus_helper);
2086 offset = offset + sbus_helper;
2087 break;
2089 } else if (sbus_attribut == SBUS_RESPONSE && (!request_val)) {
2090 /*calculate the offset in case the request telegram was not found or was broadcasted*/
2091 sbus_eth_len = tvb_get_ntohl(tvb,0);
2092 sbus_helper = sbus_eth_len - 11;
2093 proto_tree_add_expert(sbus_tree, pinfo, &ei_sbus_no_request_telegram, tvb, offset, sbus_helper);
2094 offset = sbus_eth_len - 2;
2097 if (sbus_attribut == SBUS_ACKNAK) {
2098 /*Add response time if possible*/
2099 if (request_val) {
2100 nstime_delta(&ns, &pinfo->abs_ts, &request_val->req_time);
2101 proto_tree_add_time(sbus_tree, hf_sbus_response_time,
2102 tvb, 0, 0, &ns);
2103 /*add reference to request telegram*/
2104 proto_tree_add_uint(sbus_tree, hf_sbus_response_to, tvb, 0, 0,
2105 request_val->req_frame);
2107 hi = proto_tree_add_item(sbus_tree,
2108 hf_sbus_acknackcode, tvb, offset, 2, ENC_BIG_ENDIAN);
2109 if (tvb_get_uint8(tvb, (offset+1)) > 0) {
2110 expert_add_info(pinfo, hi, &ei_sbus_telegram_not_acked);
2112 offset += 2;
2115 /* Calculate CRC */
2116 sbus_crc_calc = 0;
2117 for (i = 0; i < sbus_eth_len - 2; i++)
2118 sbus_crc_calc = crc_calc (sbus_crc_calc, tvb_get_uint8(tvb, i));
2120 proto_tree_add_checksum(sbus_tree, tvb, offset, hf_sbus_crc, hf_sbus_crc_status, &ei_sbus_crc_bad, pinfo, sbus_crc_calc,
2121 ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY);
2122 offset += 2; /*now at the end of the telegram*/
2124 return offset;
2125 /*End of dissect_sbus*/
2128 /* Register the protocol with Wireshark */
2130 void
2131 proto_register_sbus(void)
2134 /* Setup list of header fields See Section 1.6.1 for details*/
2135 static hf_register_info hf[] = {
2136 { &hf_sbus_length,
2137 { "Length (bytes)", "sbus.len",
2138 FT_UINT32, BASE_DEC, NULL, 0,
2139 "SAIA Ether-S-Bus telegram length", HFILL }
2141 { &hf_sbus_version,
2142 { "Version", "sbus.vers",
2143 FT_UINT8, BASE_DEC, NULL, 0,
2144 "SAIA Ether-S-Bus version", HFILL }
2146 { &hf_sbus_protocol,
2147 { "Protocol type", "sbus.proto",
2148 FT_UINT8, BASE_DEC, NULL, 0,
2149 "SAIA Ether-S-Bus protocol type", HFILL }
2151 { &hf_sbus_sequence,
2152 { "Sequence", "sbus.seq",
2153 FT_UINT16, BASE_DEC, NULL, 0,
2154 "SAIA Ether-S-Bus sequence number", HFILL }
2157 { &hf_sbus_attribut,
2158 { "Telegram attribute", "sbus.att",
2159 FT_UINT8, BASE_HEX, VALS(sbus_att_vals), 0,
2160 "SAIA Ether-S-Bus telegram attribute, indicating type of telegram", HFILL }
2163 { &hf_sbus_dest,
2164 { "Destination", "sbus.destination",
2165 FT_UINT8, BASE_DEC, NULL, 0,
2166 "SAIA S-Bus destination address", HFILL }
2169 { &hf_sbus_address,
2170 { "S-Bus address", "sbus.address",
2171 FT_UINT8, BASE_DEC, NULL, 0,
2172 "SAIA S-Bus station address", HFILL }
2175 { &hf_sbus_command,
2176 { "Command", "sbus.cmd",
2177 FT_UINT8, BASE_HEX | BASE_EXT_STRING, &sbus_command_vals_ext, 0,
2178 "SAIA S-Bus command", HFILL }
2181 { &hf_sbus_command_extension,
2182 { "Command extension", "sbus.cmd_extn",
2183 FT_UINT8, BASE_HEX, NULL, 0,
2184 "SAIA S-Bus command extension", HFILL }
2187 { &hf_sbus_rcount,
2188 { "R-count", "sbus.rcount",
2189 FT_UINT8, BASE_DEC, NULL, 0,
2190 "Number of elements expected in response", HFILL }
2193 { &hf_sbus_sub_length,
2194 { "Sub length", "sbus.sublength",
2195 FT_UINT8, BASE_DEC, NULL, 0,
2196 "Length of multi-media response or request in bytes, length and command code fields not included", HFILL }
2199 { &hf_sbus_multimedia_length,
2200 { "Multi-media length", "sbus.mmlength",
2201 FT_UINT8, BASE_DEC, NULL, 0,
2202 "Length of all multi-media request or responses in bytes", HFILL }
2205 { &hf_sbus_wcount,
2206 { "W-count (raw)", "sbus.wcount",
2207 FT_UINT8, BASE_DEC, NULL, 0,
2208 "Number of bytes to be written", HFILL }
2211 { &hf_sbus_wcount_calculated,
2212 { "W-count (32 bit values)", "sbus.wcount_calc",
2213 FT_UINT8, BASE_DEC, NULL, 0,
2214 "Number of elements to be written", HFILL }
2217 { &hf_sbus_fio_count,
2218 { "FIO Count (amount of bits)", "sbus.fio_count",
2219 FT_UINT8, BASE_DEC, NULL, 0,
2220 "Number of binary elements to be written", HFILL }
2223 { &hf_sbus_addr_rtc,
2224 { "Base address RTC", "sbus.addr_RTC",
2225 FT_UINT16, BASE_DEC, NULL, 0,
2226 "Base address of 32 bit elements to read", HFILL }
2229 { &hf_sbus_addr_iof,
2230 { "Base address IOF", "sbus.addr_IOF",
2231 FT_UINT16, BASE_DEC, NULL, 0,
2232 "Base address of binary elements to read", HFILL }
2235 { &hf_sbus_addr_db,
2236 { "DB address", "sbus.addr_db",
2237 FT_UINT16, BASE_DEC, NULL, 0,
2238 "Datablock address to read from", HFILL }
2241 { &hf_sbus_addr_base_element,
2242 { "Base DB element address", "sbus.db_base_element",
2243 FT_UINT16, BASE_DEC, NULL, 0,
2244 "Base Datablock element address of 32 bit values to read", HFILL }
2247 { &hf_sbus_addr_eeprom,
2248 { "Base address of EEPROM register", "sbus.addr_EEPROM",
2249 FT_UINT16, BASE_DEC, NULL, 0,
2250 "Base address of 32 bit EEPROM register to read or write", HFILL }
2253 { &hf_sbus_addr_prog,
2254 { "Base address of user memory or program lines", "sbus.addr_prog",
2255 FT_UINT24, BASE_DEC, NULL, 0,
2256 "Base address of the user memory or program lines (read or write)", HFILL }
2259 { &hf_sbus_addr_68k,
2260 { "Base address of bytes", "sbus.addr_68k",
2261 FT_UINT24, BASE_HEX, NULL, 0,
2262 "Base address of bytes to read or write (68k address)", HFILL }
2265 { &hf_sbus_block_type,
2266 { "Block type", "sbus.block_type",
2267 FT_UINT8, BASE_HEX | BASE_EXT_STRING, &sbus_block_types_ext, 0,
2268 "Program block type", HFILL }
2271 { &hf_sbus_block_nr,
2272 { "Block/Element nr", "sbus.block_nr",
2273 FT_UINT16, BASE_DEC, NULL, 0,
2274 "Program block / DataBlock number", HFILL }
2277 { &hf_sbus_nbr_elements,
2278 { "Number of elements", "sbus.nbr_elements",
2279 FT_UINT16, BASE_DEC, NULL, 0,
2280 "Number of elements or characters", HFILL }
2283 { &hf_sbus_display_register,
2284 { "PCD Display register", "sbus.data_display_register",
2285 FT_UINT32, BASE_DEC, NULL, 0,
2286 "The PCD display register (32 bit value)", HFILL }
2289 { &hf_sbus_data_rtc,
2290 { "S-Bus 32-bit data", "sbus.data_rtc",
2291 FT_UINT32, BASE_DEC, NULL, 0,
2292 "One register/timer of counter (32 bit value)", HFILL }
2295 { &hf_sbus_data_byte,
2296 { "Data bytes", "sbus.data_byte",
2297 FT_UINT8, BASE_DEC, NULL, 0,
2298 "One byte from PCD", HFILL }
2301 { &hf_sbus_data_byte_hex,
2302 { "Data bytes (hex)", "sbus.data_byte_hex",
2303 FT_UINT8, BASE_HEX, NULL, 0,
2304 "One byte from PCD (hexadecimal)", HFILL }
2307 { &hf_sbus_data_iof,
2308 { "S-Bus binary data", "sbus.data_iof",
2309 FT_UINT32, BASE_DEC, NULL, 0,
2310 "8 binaries", HFILL }
2313 { &hf_sbus_cpu_type,
2314 { "PCD type", "sbus.pcd_type",
2315 FT_STRING, BASE_NONE, NULL, 0,
2316 "PCD type (short form)", HFILL }
2319 { &hf_sbus_fw_version,
2320 { "Firmware version", "sbus.fw_version",
2321 FT_STRING, BASE_NONE, NULL, 0,
2322 "Firmware version of the PCD or module", HFILL }
2325 { &hf_sbus_sysinfo_nr,
2326 { "System information number", "sbus.sysinfo",
2327 FT_UINT8, BASE_HEX, NULL, 0,
2328 "System information number (extension to command code)", HFILL }
2331 { &hf_sbus_sysinfo0_1,
2332 { "Mem size info", "sbus.sysinfo0.mem",
2333 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_MEMSIZE,
2334 "Availability of memory size information", HFILL }
2336 { &hf_sbus_sysinfo0_2,
2337 { "Trace buffer", "sbus.sysinfo0.trace",
2338 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_TRACE,
2339 "Availability of trace buffer feature", HFILL }
2341 { &hf_sbus_sysinfo0_3,
2342 { "Slot B1", "sbus.sysinfo0.b1",
2343 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_INFO_B1,
2344 "Presence of EEPROM information on slot B1", HFILL }
2346 { &hf_sbus_sysinfo0_4,
2347 { "Slot B2", "sbus.sysinfo0.b2",
2348 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_INFO_B2,
2349 "Presence of EEPROM information on slot B2", HFILL }
2351 { &hf_sbus_sysinfo0_5,
2352 { "PGU baud", "sbus.sysinfo0.pgubaud",
2353 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_PGU_BAUD,
2354 "Availability of PGU baud switch feature", HFILL }
2357 #if 0
2358 { &hf_sbus_sysinfo_length,
2359 { "System information length", "sbus.sysinfo_length",
2360 FT_UINT8, BASE_HEX, NULL, 0,
2361 "System information length in response", HFILL }
2363 #endif
2365 #if 0
2366 { &hf_sbus_f_module_type,
2367 { "F-module type", "sbus.fmodule_type",
2368 FT_STRING, BASE_NONE, NULL, 0,
2369 "Module type mounted on B1/2 slot", HFILL }
2371 #endif
2373 #if 0
2374 { &hf_sbus_harware_version,
2375 { "Hardware version", "sbus.hw_version",
2376 FT_STRING, BASE_NONE, NULL, 0,
2377 "Hardware version of the PCD or the module", HFILL }
2379 #endif
2381 #if 0
2382 { &hf_sbus_hardware_modification,
2383 { "Hardware modification", "sbus.hw_modification",
2384 FT_UINT8, BASE_DEC, NULL, 0,
2385 "Hardware modification of the PCD or module", HFILL }
2387 #endif
2389 #if 0
2390 { &hf_sbus_various,
2391 { "Various data", "sbus.various",
2392 FT_NONE, BASE_NONE, NULL, 0,
2393 "Various data contained in telegrams but nobody will search for it", HFILL }
2395 #endif
2397 { &hf_sbus_acknackcode,
2398 { "ACK/NAK code", "sbus.nakcode",
2399 FT_UINT16, BASE_HEX, VALS(sbus_ack_nak_vals), 0,
2400 "SAIA S-Bus ACK/NAK response", HFILL }
2403 { &hf_sbus_cpu_status,
2404 { "CPU status", "sbus.CPU_status",
2405 FT_UINT8, BASE_HEX, VALS(sbus_CPU_status), 0,
2406 "SAIA PCD CPU status", HFILL }
2409 { &hf_sbus_week_day,
2410 { "Calendar week", "sbus.rtc.week_day",
2411 FT_UINT16, BASE_HEX, NULL, 0,
2412 "Calendar week and week day number of the real time clock", HFILL }
2415 { &hf_sbus_date,
2416 { "RTC date (YYMMDD)", "sbus.rtc.date",
2417 FT_UINT24, BASE_HEX, NULL, 0,
2418 "Year, month and day of the real time clock", HFILL }
2421 { &hf_sbus_time,
2422 { "RTC time (HHMMSS)", "sbus.rtc.time",
2423 FT_UINT24, BASE_HEX, NULL, 0,
2424 "Time of the real time clock", HFILL }
2427 { &hf_sbus_web_size,
2428 { "Web server packet size", "sbus.web.size",
2429 FT_UINT8, BASE_HEX, NULL, 0,
2430 NULL, HFILL }
2433 { &hf_sbus_web_aid,
2434 { "AID", "sbus.web.aid",
2435 FT_UINT8, BASE_HEX, NULL, 0,
2436 "Web server command/status code (AID)", HFILL }
2439 { &hf_sbus_web_seq,
2440 { "Sequence", "sbus.web.seq",
2441 FT_UINT8, BASE_HEX, NULL, 0,
2442 "Web server sequence nr (PACK_N)", HFILL }
2445 { &hf_sbus_rdwr_block_length,
2446 { "Read/write block telegram length", "sbus.block.length",
2447 FT_UINT8, BASE_DEC, NULL, 0,
2448 NULL, HFILL }
2451 { &hf_sbus_rdwr_block_length_ext,
2452 { "Extended length (bytes)", "sbus.len_ext",
2453 FT_UINT32, BASE_DEC, NULL, 0,
2454 NULL, HFILL }
2457 { &hf_sbus_rdwr_telegram_type,
2458 { "Read/write block telegram type", "sbus.block.tlgtype",
2459 FT_UINT8, BASE_HEX | BASE_EXT_STRING, &rdwrblock_vals_ext, 0,
2460 "Type of RD/WR block telegram", HFILL }
2463 { &hf_sbus_rdwr_telegram_sequence,
2464 { "Sequence", "sbus.block.seq",
2465 FT_UINT8, BASE_DEC, NULL, 0,
2466 "Sequence number of block data stream telegram", HFILL }
2469 { &hf_sbus_rdwr_block_size,
2470 { "Block size in bytes", "sbus.block.size",
2471 FT_UINT32, BASE_DEC, NULL, 0,
2472 "The size of the block in bytes", HFILL }
2475 { &hf_sbus_rdwr_block_addr,
2476 { "Address inside block", "sbus.block.addr",
2477 FT_UINT32, BASE_DEC, NULL, 0,
2478 "The address inside a block", HFILL }
2482 { &hf_sbus_rdwr_file_name,
2483 { "File name", "sbus.block.filename",
2484 FT_STRING, BASE_NONE, NULL, 0,
2485 "Name of file to in RD/WR block telegram", HFILL }
2488 { &hf_sbus_rdwr_list_type,
2489 { "Get program block list, command type", "sbus.block.getlisttype",
2490 FT_UINT8, BASE_HEX, VALS(rdwrblock_list_type_vals), 0,
2491 "Type of the Get Program Block list request", HFILL }
2494 { &hf_sbus_rdwr_acknakcode,
2495 { "ACK/NAK code", "sbus.block.nakcode",
2496 FT_UINT8, BASE_HEX | BASE_EXT_STRING, &rdwrblock_sts_ext, 0,
2497 "ACK/NAK response for block write requests", HFILL }
2500 { &hf_sbus_crc,
2501 { "Checksum", "sbus.crc",
2502 FT_UINT16, BASE_HEX, NULL, 0,
2503 "CRC 16", HFILL }
2506 { &hf_sbus_crc_status,
2507 { "Checksum Status", "sbus.crc.status",
2508 FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0,
2509 NULL, HFILL }},
2511 { &hf_sbus_flags_accu,
2512 { "ACCU", "sbus.flags.accu",
2513 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ACCU,
2514 "PCD Accumulator", HFILL }
2517 { &hf_sbus_flags_error,
2518 { "Error flag", "sbus.flags.error",
2519 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ERROR,
2520 "PCD error flag", HFILL }
2523 { &hf_sbus_flags_negative,
2524 { "N-flag", "sbus.flags.nflag",
2525 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_NEGATIVE,
2526 "Negative status flag", HFILL }
2529 { &hf_sbus_flags_zero,
2530 { "Z-flag", "sbus.flags.zflag",
2531 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ZERO,
2532 "Zero status flag", HFILL }
2535 { &hf_sbus_response_in,
2536 { "Response in frame nr.", "sbus.response_in",
2537 FT_FRAMENUM, BASE_NONE, FRAMENUM_TYPE(FT_FRAMENUM_RESPONSE), 0x0,
2538 "The response to this Ether-S-Bus request is in this frame", HFILL }
2541 { &hf_sbus_response_to,
2542 { "Request in frame nr.", "sbus.response_to",
2543 FT_FRAMENUM, BASE_NONE, FRAMENUM_TYPE(FT_FRAMENUM_REQUEST), 0x0,
2544 "This is a response to the Ether-S-Bus request in this frame", HFILL }
2547 { &hf_sbus_response_time,
2548 { "Response time", "sbus.response_time",
2549 FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
2550 "The time between the request and the response", HFILL }
2553 { &hf_sbus_timeout,
2554 { "Time passed since first request", "sbus.timeout",
2555 FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
2556 "The time between the first (identical) request and the repetition", HFILL }
2559 { &hf_sbus_request_in,
2560 { "First request in frame nr.", "sbus.request_in",
2561 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
2562 "The first request of this repeated request is in this frame", HFILL }
2567 /* Setup protocol subtree array */
2568 static int *ett[] = {
2569 &ett_sbus,
2570 &ett_sbus_ether,
2571 &ett_sbus_data
2574 static ei_register_info ei[] = {
2575 { &ei_sbus_retry, { "sbus.retry", PI_SEQUENCE, PI_NOTE, "Repeated telegram (due to timeout?)", EXPFILL }},
2576 { &ei_sbus_telegram_not_acked, { "sbus.telegram_not_acked", PI_RESPONSE_CODE, PI_CHAT, "Telegram not acknowledged by PCD", EXPFILL }},
2577 { &ei_sbus_crc_bad, { "sbus.crc_bad.expert", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }},
2578 { &ei_sbus_telegram_not_implemented, { "sbus.telegram_not_implemented", PI_UNDECODED, PI_WARN, "This telegram isn't implemented in the dissector", EXPFILL }},
2579 { &ei_sbus_no_request_telegram, { "sbus.no_request_telegram", PI_UNDECODED, PI_WARN, "Not dissected, could not find request telegram", EXPFILL }},
2582 expert_module_t* expert_sbus;
2584 /* Register the protocol name and description */
2585 proto_sbus = proto_register_protocol("SAIA S-Bus", "SBUS", "sbus");
2587 /* Required function calls to register the header fields and subtrees used */
2588 proto_register_field_array(proto_sbus, hf, array_length(hf));
2589 proto_register_subtree_array(ett, array_length(ett));
2590 expert_sbus = expert_register_protocol(proto_sbus);
2591 expert_register_field_array(expert_sbus, ei, array_length(ei));
2592 sbus_request_hash = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), sbus_hash, sbus_equal);
2594 /* Register the dissector handle */
2595 sbus_handle = register_dissector("sbus", dissect_sbus, proto_sbus);
2598 void
2599 proto_reg_handoff_sbus(void)
2601 dissector_add_uint_with_preference("udp.port", SBUS_UDP_PORT, sbus_handle);
2605 * Editor modelines
2607 * Local Variables:
2608 * c-basic-offset: 7
2609 * tab-width: 8
2610 * indent-tabs-mode: nil
2611 * End:
2613 * ex: set shiftwidth=7 tabstop=8 expandtab:
2614 * :indentSize=7:tabSize=8:noTabs=true: