2 * Routines for Ether-S-Bus dissection
3 * Copyright 2006, Christian Durrer <christian.durrer@sensemail.ch>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include <epan/packet.h>
36 #include <epan/conversation.h>
38 /* Number of entries in the memeory chunk array (for conversation)*/
39 #define SBUS_MEMCHUNKSIZE 20
41 #define SBUS_REQUEST 0x00
42 #define SBUS_RESPONSE 0x01
43 #define SBUS_ACKNAK 0x02
45 /*SBus command codes*/
46 #define SBUS_RD_COUNTER 0x00
47 #define SBUS_RD_DISPLAY_REGISTER 0x01
48 #define SBUS_RD_FLAG 0x02
49 #define SBUS_RD_INPUT 0x03
50 #define SBUS_RD_RTC 0x04
51 #define SBUS_RD_OUTPUT 0x05
52 #define SBUS_RD_REGISTER 0x06
53 #define SBUS_RD_TIMER 0x07
54 #define SBUS_WR_COUNTER 0x0A
55 #define SBUS_WR_FLAG 0x0B
56 #define SBUS_WR_RTC 0x0C
57 #define SBUS_WR_OUTPUT 0x0D
58 #define SBUS_WR_REGISTER 0x0E
59 #define SBUS_WR_TIMER 0x0F
60 #define SBUS_RDWR_MULTI_MEDIAS 0x13
61 #define SBUS_RD_PCD_STATUS_CPU0 0x14
62 #define SBUS_RD_PCD_STATUS_CPU1 0x15
63 #define SBUS_RD_PCD_STATUS_CPU2 0x16
64 #define SBUS_RD_PCD_STATUS_CPU3 0x17
65 #define SBUS_RD_PCD_STATUS_CPU4 0x18
66 #define SBUS_RD_PCD_STATUS_CPU5 0x19
67 #define SBUS_RD_PCD_STATUS_CPU6 0x1A
68 #define SBUS_RD_PCD_STATUS_OWN 0x1B
69 #define SBUS_RD_SBUS_STN_NBR 0x1D
70 #define SBUS_RD_USER_MEMORY 0x1E
71 #define SBUS_RD_PROGRAM_LINE 0x1F
72 #define SBUS_RD_PROGRAM_VERSION 0x20
73 #define SBUS_RD_TEXT 0x21
74 #define SBUS_RD_ACTIVE_TRANSITION 0x22
75 #define SBUS_WR_USER_MEMORY 0x23
76 #define SBUS_WR_PROGRAM_LINE 0x24
77 #define SBUS_WR_TEXT 0x25
78 #define SBUS_RUN_PROCEDURE_CPU0 0x28
79 #define SBUS_RUN_PROCEDURE_CPU1 0x29
80 #define SBUS_RUN_PROCEDURE_CPU2 0x2A
81 #define SBUS_RUN_PROCEDURE_CPU3 0x2B
82 #define SBUS_RUN_PROCEDURE_CPU4 0x2C
83 #define SBUS_RUN_PROCEDURE_CPU5 0x2D
84 #define SBUS_RUN_PROCEDURE_CPU6 0x2E
85 #define SBUS_RUN_PROCEDURE_OWN 0x2F
86 #define SBUS_RUN_PROCEDURE_ALL 0x30
87 #define SBUS_RESTART_COLD_CPU1 0x32
88 #define SBUS_RESTART_COLD_CPU2 0x33
89 #define SBUS_RESTART_COLD_CPU3 0x34
90 #define SBUS_RESTART_COLD_CPU4 0x35
91 #define SBUS_RESTART_COLD_CPU5 0x36
92 #define SBUS_RESTART_COLD_CPU6 0x37
93 #define SBUS_RESTART_COLD_OWN 0x38
94 #define SBUS_RESTART_COLD_ALL 0x39
95 #define SBUS_STOP_PROCEDURE_CPU0 0x3C
96 #define SBUS_STOP_PROCEDURE_CPU1 0x3D
97 #define SBUS_STOP_PROCEDURE_CPU2 0x3E
98 #define SBUS_STOP_PROCEDURE_CPU3 0x3F
99 #define SBUS_STOP_PROCEDURE_CPU4 0x40
100 #define SBUS_STOP_PROCEDURE_CPU5 0x41
101 #define SBUS_STOP_PROCEDURE_CPU6 0x42
102 #define SBUS_STOP_PROCEDURE_OWN 0x43
103 #define SBUS_STOP_PROCEDURE_ALL 0x44
104 #define SBUS_RD_STATUSFLAG_ACCU 0x46
105 #define SBUS_RD_BYTE 0x47
106 #define SBUS_RD_HALT_FAILURE_REG 0x48
107 #define SBUS_RD_INDEX_REGISTER 0x49
108 #define SBUS_RD_INSTRUCTION_POINTER 0x4A
109 #define SBUS_FIND_HISTORY 0x4B
110 #define SBUS_WR_STATUSFLAG_ACCU 0x50
111 #define SBUS_WR_BYTE 0x51
112 #define SBUS_WR_INDEX_REGISTER 0x52
113 #define SBUS_WR_INSTRUCTION_POINTER 0x53
114 #define SBUS_CLEAR_ALL 0x5A
115 #define SBUS_CLEAR_FLAGS 0x5B
116 #define SBUS_CLEAR_OUTPUTS 0x5C
117 #define SBUS_CLEAR_REGISTERS 0x5D
118 #define SBUS_CLEAR_TIMERS 0x5E
119 #define SBUS_RESTART_WARM_CPU1 0x64
120 #define SBUS_RESTART_WARM_CPU2 0x65
121 #define SBUS_RESTART_WARM_CPU3 0x66
122 #define SBUS_RESTART_WARM_CPU4 0x67
123 #define SBUS_RESTART_WARM_CPU5 0x68
124 #define SBUS_RESTART_WARM_CPU6 0x69
125 #define SBUS_RESTART_WARM_OWN 0x6A
126 #define SBUS_RESTART_WARM_ALL 0x6B
127 #define SBUS_CHANGE_BLOCK 0x6E
128 #define SBUS_CLEAR_HISTORY_FAILURE 0x6F
129 #define SBUS_DELETE_PROGRAM_LINE 0x70
130 #define SBUS_GO_CONDITIONAL 0x71
131 #define SBUS_INSERT_PROGRAM_LINE 0x72
132 #define SBUS_LOCAL_CYCLE 0x73
133 #define SBUS_ALL_CYCLES 0x74
134 #define SBUS_MAKE_TEXT 0x75
135 #define SBUS_EXECUTE_SINGLE_INSTR 0x76
136 #define SBUS_SINGLE_STEP 0x77
137 #define SBUS_XOB_17_INTERRUPT 0x82
138 #define SBUS_XOB_18_INTERRUPT 0x83
139 #define SBUS_XOB_19_INTERRUPT 0x84
140 #define SBUS_RD_HANGUP_TIMEOUT 0x91
141 #define SBUS_RD_DATA_BLOCK 0x96
142 #define SBUS_WR_DATA_BLOCK 0x97
143 #define SBUS_MAKE_DATA_BLOCK 0x98
144 #define SBUS_CLEAR_DATA_BLOCK 0x99
145 #define SBUS_CLEAR_TEXT 0x9A
146 #define SBUS_RD_BLOCK_ADDRESSES 0x9B
147 #define SBUS_RD_BLOCK_SIZES 0x9C
148 #define SBUS_RD_CURRENT_BLOCK 0x9D
149 #define SBUS_RD_CALL_STACK 0x9E
150 #define SBUS_RD_DBX 0x9F
151 #define SBUS_RD_USER_EEPROM_REGISTER 0xA1
152 #define SBUS_WR_USER_EEPROM_REGISTER 0xA3
153 #define SBUS_ERASE_FLASH 0xA5
154 #define SBUS_RESTART_COLD_FLAG 0xA6
155 #define SBUS_WR_SYSTEM_BUFFER 0xA7
156 #define SBUS_RD_SYSTEM_BUFFER 0xA8
157 #define SBUS_RD_WR_PCD_BLOCK 0xA9
158 #define SBUS_GET_DIAGNOSTIC 0xAA
159 #define SBUS_RD_SYSTEM_INFORMATION 0xAB
160 #define SBUS_CHANGE_BLOCKS_ON_RUN 0xAC
161 #define SBUS_FLASHCARD_TELEGRAM 0xAD
162 #define SBUS_DOWNLOAD_FIRMWARE 0xAE
163 #define SBUS_WEB_SERVER_SERIAL_COMM 0xAF
165 /* Bitfield in the arithmetic flags and accu*/
166 #define F_ACCU (1<<0) /* Accumulator of PCD */
167 #define F_ERROR (1<<1) /* Error flag of PCD */
168 #define F_NEGATIVE (1<<2) /* Negative arithmetic status flag*/
169 #define F_ZERO (1<<3) /* Zero arithmetic status flag */
171 /* Bitfield in the system information*/
172 /*#define F_EMPTY (1<<0) always 0 */
173 #define F_MEMSIZE (1<<1) /* Memory size information*/
174 #define F_TRACE (1<<2) /* Trace buffer feature */
175 #define F_INFO_B1 (1<<3) /* EEPROM information of slot B1*/
176 #define F_INFO_B2 (1<<4) /* EEPROM information of slot B2*/
177 #define F_PGU_BAUD (1<<5) /* PGU baudrate can be switched*/
179 /* Initialize the protocol and registered fields */
180 static int proto_sbus = -1;
181 static int hf_sbus_length = -1;
182 static int hf_sbus_version = -1;
183 static int hf_sbus_protocol = -1;
184 static int hf_sbus_sequence = -1;
185 static int hf_sbus_attribut = -1;
186 static int hf_sbus_dest = -1;
187 static int hf_sbus_address = -1;
188 static int hf_sbus_command = -1;
189 static int hf_sbus_command_extension = -1;
190 static int hf_sbus_rcount = -1;
191 static int hf_sbus_wcount = -1;
192 static int hf_sbus_wcount_calculated = -1;
193 static int hf_sbus_fio_count = -1;
194 static int hf_sbus_addr_rtc = -1;
195 static int hf_sbus_addr_iof = -1;
196 static int hf_sbus_addr_eeprom = -1;
197 static int hf_sbus_addr_prog = -1;
198 static int hf_sbus_addr_68k = -1;
199 static int hf_sbus_block_type = -1;
200 static int hf_sbus_block_nr = -1;
201 static int hf_sbus_nbr_elements = -1;
202 static int hf_sbus_display_register = -1;
203 static int hf_sbus_data_rtc = -1;
204 static int hf_sbus_data_byte = -1;
205 static int hf_sbus_data_byte_hex = -1;
206 static int hf_sbus_data_iof = -1;
207 static int hf_sbus_cpu_type = -1;
208 static int hf_sbus_fw_version = -1;
209 static int hf_sbus_sysinfo_nr = -1;
210 static int hf_sbus_sysinfo0_1 = -1;
211 static int hf_sbus_sysinfo0_2 = -1;
212 static int hf_sbus_sysinfo0_3 = -1;
213 static int hf_sbus_sysinfo0_4 = -1;
214 static int hf_sbus_sysinfo0_5 = -1;
215 static int hf_sbus_sysinfo_length = -1;
216 static int hf_sbus_f_module_type = -1;
217 static int hf_sbus_harware_version = -1;
218 static int hf_sbus_hardware_modification = -1;
219 static int hf_sbus_various = -1;
220 static int hf_sbus_acknackcode = -1;
221 static int hf_sbus_cpu_status = -1;
222 static int hf_sbus_week_day = -1;
223 static int hf_sbus_date = -1;
224 static int hf_sbus_time = -1;
225 static int hf_sbus_crc = -1;
226 static int hf_sbus_crc_bad = -1;
227 static int hf_sbus_flags_accu = -1;
228 static int hf_sbus_flags_error = -1;
229 static int hf_sbus_flags_negative = -1;
230 static int hf_sbus_flags_zero = -1;
231 /* Web server telegram */
232 static int hf_sbus_web_size = -1;
233 static int hf_sbus_web_aid = -1;
234 static int hf_sbus_web_seq = -1;
236 /* Initialize the subtree pointers */
237 static gint ett_sbus = -1;
238 static gint ett_sbus_ether = -1;
239 static gint ett_sbus_data = -1;
241 /* True/False strings*/
242 static const true_false_string tfs_sbus_flags= {
247 static const true_false_string tfs_sbus_present= {
252 /* value to string definitions*/
254 static const value_string sbus_att_vals[] = {
261 static const value_string sbus_block_types[] = {
274 static const value_string sbus_CPU_status[] = {
280 {0x58, "X, Exceptional Intermediate Status (MODEMS+)"},
284 static const value_string sbus_ack_nak_vals[] = {
285 {0, "ACK (Acknowledged)"},
286 {1, "NAK, no reason specified"},
287 {2, "NAK, because of password"},
288 {3, "NAK, PGU port is in reduced protocol"},
289 {4, "NAK, PGU port is already used"},
293 static const value_string sbus_command_vals[] = {
294 {0x00, "Read counter(s)"},
295 {0x01, "Read display register"},
296 {0x02, "Read flag(s)"},
297 {0x03, "Read input(s)"},
298 {0x04, "Read real time clock"},
299 {0x05, "Read output(s)"},
300 {0x06, "Read register(s)"},
301 {0x07, "Read timer(s)"},
302 {0x0A, "Write counter(s)"},
303 {0x0B, "Write flag(s)"},
304 {0x0C, "Write real time clock"},
305 {0x0D, "Write output(s)"},
306 {0x0E, "Write register(s)"},
307 {0x0F, "Write timer(s)"},
308 {0x14, "Read PCD status, CPU 0"},
309 {0x15, "Read PCD status, CPU 1"},
310 {0x16, "Read PCD status, CPU 2"},
311 {0x17, "Read PCD status, CPU 3"},
312 {0x18, "Read PCD status, CPU 4"},
313 {0x19, "Read PCD status, CPU 5"},
314 {0x1A, "Read PCD status, CPU 6"},
315 {0x1B, "Read PCD status (own)"},
316 {0x1D, "Read S-Bus station number"},
317 {0x1E, "Read user memory*"},
318 {0x1F, "Read program line*"},
319 {0x20, "Read firmware version"},
320 {0x21, "Read text*"},
321 {0x22, "Read active transition*"},
322 {0x23, "Write user memeory*"},
323 {0x24, "Write program line*"},
324 {0x25, "Write text*"},
325 {0x28, "Run procedure*, CPU 0"},
326 {0x29, "Run procedure*, CPU 1"},
327 {0x2A, "Run procedure*, CPU 2"},
328 {0x2B, "Run procedure*, CPU 3"},
329 {0x2C, "Run procedure*, CPU 4"},
330 {0x2D, "Run procedure*, CPU 5"},
331 {0x2E, "Run procedure*, CPU 6"},
332 {0x2F, "Run procedure* (own CPU)"},
333 {0x30, "Run procedure* (All CPUs)"},
334 {0x32, "Restart cold CPU 1*"},
335 {0x33, "Restart cold CPU 2*"},
336 {0x34, "Restart cold CPU 3*"},
337 {0x35, "Restart cold CPU 4*"},
338 {0x36, "Restart cold CPU 5*"},
339 {0x37, "Restart cold CPU 6*"},
340 {0x38, "Restart cold own CPU*"},
341 {0x39, "Restart cold all CPUs*"},
342 {0x3C, "Stop procedure*, CPU 0"},
343 {0x3D, "Stop procedure*, CPU 1"},
344 {0x3E, "Stop procedure*, CPU 2"},
345 {0x3F, "Stop procedure*, CPU 3"},
346 {0x40, "Stop procedure*, CPU 4"},
347 {0x41, "Stop procedure*, CPU 5"},
348 {0x42, "Stop procedure*, CPU 6"},
349 {0x43, "Stop procedure*, (own CPU)"},
350 {0x44, "Stop procedure*, (All CPUs)"},
351 {0x46, "Read arithmetic status and ACCU*"},
353 {0x48, "Read halt failure register*"},
354 {0x49, "Read index register*"},
355 {0x4A, "Read instruction pointer*"},
356 {0x4B, "Find history*"},
357 {0x50, "Write arithmetic staus and ACCU*"},
358 {0x51, "Write byte*"},
359 {0x52, "Write index register"},
360 {0x53, "Write instruction pointer*"},
361 {0x5A, "Clear all (F, O, R, T)*"},
362 {0x5B, "Clear flags*"},
363 {0x5C, "Clear outputs*"},
364 {0x5D, "Clear registers*"},
365 {0x5E, "Clear timers*"},
366 {0x64, "Restart warm CPU 1*"},
367 {0x65, "Restart warm CPU 2*"},
368 {0x66, "Restart warm CPU 3*"},
369 {0x67, "Restart warm CPU 4*"},
370 {0x68, "Restart warm CPU 5*"},
371 {0x69, "Restart warm CPU 6*"},
372 {0x6A, "Restart warm (own CPU)*"},
373 {0x6B, "Restart warm (All CPUs)*"},
374 {0x6E, "Change block*"},
375 {0x6F, "Clear history failure*"},
376 {0x70, "Delete program line*"},
377 {0x71, "Go conditional*"},
378 {0x72, "Insert program line*"},
379 {0x73, "Local cycles*"},
380 {0x74, "All cycles*"},
381 {0x75, "Make text*"},
382 {0x76, "Execute single instruction*"},
383 {0x77, "Single step*"},
384 {0x82, "XOB 17 interrupt"},
385 {0x83, "XOB 18 interrupt"},
386 {0x84, "XOB 19 interrupt"},
387 {0x91, "Read hangup timeout"},
388 {0x96, "Read data block"},
389 {0x97, "Write data block"},
390 {0x98, "Make data block*"},
391 {0x99, "Clear data block*"},
392 {0x9A, "Clear text*"},
393 {0x9B, "Read block address"},
394 {0x9C, "Read block sizes"},
395 {0x9D, "Read current block*"},
396 {0x9E, "Read call stack*"},
398 {0xA1, "Read user EEPROM register"},
399 {0xA3, "Write user EEPROM register"},
400 {0xA5, "Erase flash*"},
401 {0xA6, "Restart cold flag*"},
402 {0xA7, "Write system buffer"},
403 {0xA8, "Read system buffer"},
404 {0xAA, "Get diagnostic*"},
405 {0xAB, "Read system information*"},
406 {0xAC, "Changes blocks on run*"},
407 {0xAD, "Flashcard telegram*"},
408 {0xAE, "Download FW*"},
409 {0xAF, "Web server serial communication*"},
413 static const value_string webserver_aid_vals[] = {
414 {0x01, "Partial request"},
415 {0x02, "Request end"},
417 {0x10, "Transfer OK"},
418 {0x11, "Partial answer"},
419 {0x12, "Last part of answer"},
420 {0x13, "Server not ready"},
424 static const guint crc_table[] = {
425 0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
426 0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
427 0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
428 0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
429 0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
430 0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
431 0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
432 0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
433 0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
434 0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
435 0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
436 0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
437 0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
438 0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
439 0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
440 0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
443 /* Conversion values passing structure*/
445 guint32 conversation; /*Conversation ID*/
446 guint16 sequence; /*Sequence number of request telegram*/
450 guint8 cmd_code; /*command code from request*/
451 guint8 count; /*rcount value*/
452 guint8 sysinfo; /*system information number (or command in other telegrams)*/
455 /* The GMemChunk base structure (for conversations)*/
456 static GHashTable *sbus_request_hash = NULL;
457 static GMemChunk *sbus_request_keys = NULL;
458 static GMemChunk *sbus_request_vals = NULL;
460 static guint crc_calc (guint crc, guint val)
465 index = (((crc >> 8) ^ val) & 0xff);
466 ncrc = crc_table[index] ^ ((crc << 8) & 0xffff);
472 static gint sbus_equal(gconstpointer v, gconstpointer w)
474 sbus_request_key *v1 = (sbus_request_key *)v;
475 sbus_request_key *v2 = (sbus_request_key *)w;
477 if (v1->conversation == v2->conversation &&
478 v1->sequence == v2->sequence) {
484 static guint sbus_hash(gconstpointer v)
486 sbus_request_key *key = (sbus_request_key *)v;
488 val = key->conversation + key->sequence;
492 /*Protocol initialisation*/
493 static void sbus_init_protocol(void){
494 if (sbus_request_hash){
495 g_hash_table_destroy(sbus_request_hash);
497 if (sbus_request_keys){
498 g_mem_chunk_destroy(sbus_request_keys);
500 if (sbus_request_vals){
501 g_mem_chunk_destroy(sbus_request_vals);
503 sbus_request_hash = g_hash_table_new(sbus_hash, sbus_equal);
504 sbus_request_keys = g_mem_chunk_new("sbus_request_keys",
505 sizeof(sbus_request_key),
506 SBUS_MEMCHUNKSIZE * sizeof(sbus_request_key),
508 sbus_request_vals = g_mem_chunk_new("sbus_request_vals",
509 sizeof(sbus_request_val),
510 SBUS_MEMCHUNKSIZE * sizeof(sbus_request_val),
514 /* check whether the packet looks like SBUS or not */
516 is_sbus_pdu(tvbuff_t *tvb)
520 /* we need at least 8 bytes to determine whether this is sbus or
523 if(tvb_length(tvb)<8){
527 /* the length must be >= 8 bytes to accomodate the header,
528 it also must be <65536 to fit inside a udp packet
530 length=tvb_get_ntohl(tvb, 0);
531 if ( (length<8) || (length>65535) ) {
534 if (tvb_reported_length(tvb) != length) {
539 /* We should also test version and protocol but that requires
540 someone to look at the specification for SBUS
546 /*Dissect the telegram*/
548 dissect_sbus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
551 /* Set up structures needed to add the protocol subtree and manage it */
552 proto_item *ti, *et, *dt, *hi;
553 proto_tree *sbus_tree, *ethsbus_tree, *sbusdata_tree;
555 gint i; /*for CRC calculation*/
556 gint j; /*for CRC calculation*/
561 guint8 sbus_attribut;
562 guint8 sbus_media_cnt;
564 guint8 sbus_cmd_code;
565 guint8 sbus_web_size;
568 guint8 sbus_sysinfo_number;
569 guint32 sbus_binarymasked;
570 guint32 sbus_binaries;
571 guint16 sbus_ack_code;
572 guint32 sbus_show_bin;
574 guint32 sbus_helper1;
575 guint32 sbus_helper2;
578 /* Set up conversations*/
579 conversation_t *conversation = NULL;
580 sbus_request_key request_key, *new_request_key;
581 sbus_request_val *request_val = NULL;
583 /* does this look like an sbus pdu? */
584 if(!is_sbus_pdu(tvb)){
588 conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
589 pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
592 /* create new conversation*/
593 conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
594 pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
597 request_key.conversation = conversation->index;
598 request_key.sequence = tvb_get_ntohs(tvb,6);
600 request_val = (sbus_request_val *) g_hash_table_lookup(sbus_request_hash,
602 /* Only allocate a new hash element when it's a request*/
603 sbus_attribut = tvb_get_guint8(tvb,8);
605 if ( !request_val && sbus_attribut == 0 ) {/* request telegram */
606 new_request_key = g_mem_chunk_alloc(sbus_request_keys);
607 *new_request_key = request_key;
609 request_val = g_mem_chunk_alloc(sbus_request_vals);
610 request_val->cmd_code=tvb_get_guint8(tvb,10);
612 if (((request_val->cmd_code) == SBUS_RD_USER_EEPROM_REGISTER) ||
613 ((request_val->cmd_code) == SBUS_WR_USER_EEPROM_REGISTER)) {
614 request_val->count=((tvb_get_guint8(tvb,12))+1);
616 request_val->count=((tvb_get_guint8(tvb,11))+1);
619 /*Enter system info*/
620 if ((request_val->cmd_code) == SBUS_RD_SYSTEM_INFORMATION) {
621 request_val->sysinfo=(tvb_get_guint8(tvb,12));
623 request_val->sysinfo=0x0;
626 g_hash_table_insert(sbus_request_hash, new_request_key, request_val);
628 /* End of attaching data to hash table*/
630 /* Make entries in Protocol column and Info column on summary display */
631 col_set_str(pinfo->cinfo, COL_PROTOCOL, "S-Bus");
633 if (check_col(pinfo->cinfo, COL_INFO))
634 col_clear(pinfo->cinfo, COL_INFO);
637 if (check_col(pinfo->cinfo, COL_INFO)) {
638 switch (sbus_attribut){
640 sbus_cmd_code = tvb_get_guint8(tvb,10);
642 /* Special treatment of web server request
643 * as is is very helpful to see more information in the packetlist */
644 if (sbus_cmd_code == SBUS_WEB_SERVER_SERIAL_COMM) {
645 sbus_web_aid = tvb_get_guint8(tvb,12);
646 sbus_web_seq = tvb_get_guint8(tvb,13);
648 col_add_fstr(pinfo->cinfo, COL_INFO,
649 "Web Server Request: %s (Seq No: %d)",
650 val_to_str(sbus_web_aid,
651 webserver_aid_vals, "Unknown Request!"),
654 /* All other requests */
655 col_add_fstr(pinfo->cinfo, COL_INFO,
656 "Request: %s", val_to_str(sbus_cmd_code,
657 sbus_command_vals, "Unknown Command!"));
662 /* Special treatment of web server request
663 * as is is very helpful to see more information in the packetlist */
664 if (request_val && ((request_val->cmd_code) == SBUS_WEB_SERVER_SERIAL_COMM)) {
665 sbus_web_size = tvb_get_guint8(tvb,9);
666 sbus_web_aid = tvb_get_guint8(tvb,10);
667 col_add_fstr(pinfo->cinfo, COL_INFO,
669 val_to_str(sbus_web_aid,
670 webserver_aid_vals, "Unknown Request!"));
671 if (sbus_web_size > 1) {
672 sbus_web_seq = tvb_get_guint8(tvb,11);
673 col_append_fstr(pinfo->cinfo, COL_INFO,
678 col_set_str(pinfo->cinfo, COL_INFO, "Response");
683 sbus_ack_code = tvb_get_ntohs(tvb,9);
684 col_add_fstr(pinfo->cinfo, COL_INFO,
685 "%s", val_to_str(sbus_ack_code,
687 "Unknown NAK response code!"));
691 col_set_str(pinfo->cinfo, COL_INFO, "Unknown attribute");
696 /* create display subtree for the protocol */
699 ti = proto_tree_add_item(tree, proto_sbus, tvb, offset, -1, FALSE);
700 sbus_tree = proto_item_add_subtree(ti, ett_sbus);
702 /*Add subtree for Ether-S-Bus header*/
703 et = proto_tree_add_text(sbus_tree, tvb, offset, 8, "Ether-S-Bus header");
704 ethsbus_tree = proto_item_add_subtree(et, ett_sbus_ether);
706 /* add an item to the subtree*/
707 sbus_eth_len = tvb_get_ntohl(tvb,offset);
708 proto_tree_add_item(ethsbus_tree,
709 hf_sbus_length, tvb, offset, 4, FALSE);
712 sbus_version = tvb_get_guint8(tvb,offset);
713 proto_tree_add_item(ethsbus_tree,
714 hf_sbus_version, tvb, offset, 1, FALSE);
717 proto_tree_add_item(ethsbus_tree,
718 hf_sbus_protocol, tvb, offset, 1, FALSE);
721 proto_tree_add_item(ethsbus_tree,
722 hf_sbus_sequence, tvb, offset, 2, FALSE);
725 /* Continue adding stuff to the main tree*/
726 sbus_attribut = tvb_get_guint8(tvb,offset);
727 proto_tree_add_item(sbus_tree,
728 hf_sbus_attribut, tvb, offset, 1, FALSE);
731 if (sbus_attribut == SBUS_REQUEST) {
732 proto_tree_add_item(sbus_tree,
733 hf_sbus_dest, tvb, offset, 1, FALSE);
735 sbus_cmd_code = tvb_get_guint8(tvb,offset);
736 proto_tree_add_item(sbus_tree,
737 hf_sbus_command, tvb, offset, 1, FALSE);
740 switch (sbus_cmd_code) {
741 /*Read Counter, Register or Timer*/
742 case SBUS_RD_COUNTER:
743 case SBUS_RD_REGISTER:
745 sbus_media_cnt = (tvb_get_guint8(tvb,offset))+1;
746 proto_tree_add_uint(sbus_tree,
747 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
749 proto_tree_add_item(sbus_tree,
750 hf_sbus_addr_rtc, tvb, offset, 2, FALSE);
754 /*Read Flag, Input or Output*/
758 sbus_media_cnt = (tvb_get_guint8(tvb,offset))+1;
759 proto_tree_add_uint(sbus_tree,
760 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
762 proto_tree_add_item(sbus_tree,
763 hf_sbus_addr_iof, tvb, offset, 2, FALSE);
767 /*Write Register Timer Counter*/
768 case SBUS_WR_COUNTER:
769 case SBUS_WR_REGISTER:
771 sbus_media_cnt = (tvb_get_guint8(tvb,offset));
772 sbus_media_cnt = ((sbus_media_cnt - 1)/4);
773 proto_tree_add_uint(sbus_tree,
774 hf_sbus_wcount_calculated, tvb, offset,
776 proto_tree_add_item(sbus_tree,
777 hf_sbus_wcount, tvb, offset, 1, FALSE);
779 proto_tree_add_item(sbus_tree,
780 hf_sbus_addr_rtc, tvb, offset, 2, FALSE);
782 /*Add subtree for Data*/
783 dt = proto_tree_add_text(sbus_tree, tvb, offset,
784 ((sbus_media_cnt) * 4),"Data");
786 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
787 for (i=((sbus_media_cnt)); i>0; i--) {
788 proto_tree_add_item(sbusdata_tree,
789 hf_sbus_data_rtc, tvb, offset,
795 /* Write flags and outputs*/
798 sbus_media_cnt = (tvb_get_guint8(tvb,offset));
799 sbus_media_cnt = (sbus_media_cnt - 2);
800 proto_tree_add_uint(sbus_tree,
801 hf_sbus_wcount_calculated, tvb, offset,
803 proto_tree_add_item(sbus_tree,
804 hf_sbus_wcount, tvb, offset, 1, FALSE);
806 proto_tree_add_item(sbus_tree,
807 hf_sbus_addr_iof, tvb, offset, 2, FALSE);
809 sbus_fio_cnt = (tvb_get_guint8(tvb,offset));
810 sbus_fio_cnt = ((sbus_fio_cnt + 1));
811 proto_tree_add_uint(sbus_tree,
812 hf_sbus_fio_count, tvb, offset, 1, sbus_fio_cnt);
814 /*Add subtree for Data*/
815 dt = proto_tree_add_text(sbus_tree, tvb, offset,
816 sbus_media_cnt,"Data");
818 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
819 for (i=sbus_media_cnt; i>0; i--) {
822 sbus_binarymasked = 0x01;
823 sbus_binaries = tvb_get_guint8(tvb, offset);
824 for (j=0; j<8; j++) {
825 if ((sbus_binarymasked & sbus_binaries) != 0) {
826 sbus_show_bin = (sbus_show_bin + sbus_helper);
828 sbus_binarymasked = sbus_binarymasked<<1;
829 sbus_helper = 10 * sbus_helper;
832 proto_tree_add_uint_format(sbusdata_tree,
833 hf_sbus_data_iof, tvb, offset, 1, sbus_show_bin,
834 "Binary data: %08u", sbus_show_bin);
839 /* Request: Write Real time clock*/
841 sbus_helper = tvb_get_guint8(tvb, (offset +5)); /*hours*/
842 sbus_helper1 = tvb_get_guint8(tvb, (offset +6)); /*minutes*/
843 sbus_helper2 = tvb_get_guint8(tvb, (offset +7)); /*seconds*/
844 proto_tree_add_text(sbus_tree, tvb, (offset +5), 3,
845 "Time (HH:MM:SS): %02x:%02x:%02x", sbus_helper, sbus_helper1, sbus_helper2);
846 sbus_helper = tvb_get_guint8(tvb, (offset +2)); /*year*/
847 sbus_helper1 = tvb_get_guint8(tvb, (offset +3)); /*month*/
848 sbus_helper2 = tvb_get_guint8(tvb, (offset +4)); /*day*/
849 proto_tree_add_text(sbus_tree, tvb, (offset +2), 3,
850 "Date (YY/MM/DD): %02x/%02x/%02x", sbus_helper, sbus_helper1, sbus_helper2);
851 sbus_helper = tvb_get_guint8(tvb, (offset)); /*year-week*/
852 sbus_helper1 = tvb_get_guint8(tvb, (offset +1)); /*week-day*/
853 proto_tree_add_text(sbus_tree, tvb, offset, 2,
854 "Calendar week: %x, Week day: %x", sbus_helper, sbus_helper1);
855 /*Add subtree for Data*/
856 dt = proto_tree_add_text(sbus_tree, tvb, offset,
858 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
860 proto_tree_add_item(sbusdata_tree,
861 hf_sbus_week_day, tvb, offset, 2, FALSE);
863 proto_tree_add_item(sbusdata_tree,
864 hf_sbus_date, tvb, offset, 3, FALSE);
866 proto_tree_add_item(sbusdata_tree,
867 hf_sbus_time, tvb, offset, 3, FALSE);
871 /* Read user memory or program line*/
872 case SBUS_RD_USER_MEMORY:
873 case SBUS_RD_PROGRAM_LINE:
874 sbus_media_cnt = (tvb_get_guint8(tvb,offset))+1;
875 proto_tree_add_uint(sbus_tree,
876 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
878 proto_tree_add_item(sbus_tree,
879 hf_sbus_addr_prog, tvb, offset, 3, FALSE);
883 /*Write user memory*/
884 case SBUS_WR_USER_MEMORY:
885 sbus_media_cnt = (tvb_get_guint8(tvb,offset));
886 sbus_media_cnt = ((sbus_media_cnt - 2)/4);
887 proto_tree_add_uint(sbus_tree,
888 hf_sbus_wcount_calculated, tvb, offset,
890 proto_tree_add_item(sbus_tree,
891 hf_sbus_wcount, tvb, offset, 1, FALSE);
893 proto_tree_add_item(sbus_tree,
894 hf_sbus_addr_68k, tvb, offset, 3, FALSE);
896 /*Add subtree for Data*/
897 dt = proto_tree_add_text(sbus_tree, tvb, offset,
898 ((sbus_media_cnt) * 4),"Program lines");
900 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
901 for (i=((sbus_media_cnt)); i>0; i--) {
902 proto_tree_add_item(sbusdata_tree,
903 hf_sbus_data_rtc, tvb, offset,
912 sbus_media_cnt = (tvb_get_guint8(tvb,offset))+1;
913 proto_tree_add_uint(sbus_tree,
914 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
916 proto_tree_add_item(sbus_tree,
917 hf_sbus_addr_68k, tvb, offset, 3, FALSE);
923 sbus_media_cnt = (tvb_get_guint8(tvb,offset));
924 sbus_media_cnt = (sbus_media_cnt - 2);
925 proto_tree_add_uint(sbus_tree,
926 hf_sbus_wcount_calculated, tvb, offset,
928 proto_tree_add_item(sbus_tree,
929 hf_sbus_wcount, tvb, offset, 1, FALSE);
931 proto_tree_add_item(sbus_tree,
932 hf_sbus_addr_68k, tvb, offset, 3, FALSE);
934 /*Add subtree for Data*/
935 dt = proto_tree_add_text(sbus_tree, tvb, offset,
936 ((sbus_media_cnt) * 4),"Data (bytes)");
938 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
939 for (i=sbus_media_cnt; i>0; i--) {
940 proto_tree_add_item(sbusdata_tree,
941 hf_sbus_data_byte, tvb, offset,
947 /*Read EEPROM register*/
948 case SBUS_RD_USER_EEPROM_REGISTER:
949 proto_tree_add_item(sbus_tree,
950 hf_sbus_command_extension, tvb, offset, 1, FALSE);
952 sbus_media_cnt = (tvb_get_guint8(tvb,offset))+1;
953 proto_tree_add_uint(sbus_tree,
954 hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt);
956 proto_tree_add_item(sbus_tree,
957 hf_sbus_addr_eeprom, tvb, offset, 2, FALSE);
961 /*Request for reading system info*/
962 /*Syinfo 05 is not implemented as no serial baud is possible*/
963 case SBUS_RD_SYSTEM_INFORMATION:
964 sbus_sysinfo_number = (tvb_get_guint8(tvb,13));
965 proto_tree_add_item(sbus_tree,
966 hf_sbus_sysinfo_nr, tvb, offset, 1, FALSE);
968 sbus_sysinfo_number = (tvb_get_guint8(tvb,14));
969 proto_tree_add_item(sbus_tree,
970 hf_sbus_sysinfo_nr, tvb, offset, 1, FALSE);
974 /* WebServer Request */
975 case SBUS_WEB_SERVER_SERIAL_COMM:
976 sbus_web_size = tvb_get_guint8(tvb,offset);
977 proto_tree_add_item(sbus_tree,
978 hf_sbus_web_size, tvb, offset,
982 sbus_web_aid = tvb_get_guint8(tvb,offset);
983 proto_tree_add_item(sbus_tree,
984 hf_sbus_web_aid, tvb, offset,
988 sbus_web_seq = tvb_get_guint8(tvb,offset);
989 proto_tree_add_item(sbus_tree,
990 hf_sbus_web_seq, tvb, offset,
994 if (sbus_web_size > 1) {
995 dt = proto_tree_add_text(sbus_tree, tvb, offset,
996 (sbus_web_size - 1),"Data (bytes)");
998 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
999 for (i=sbus_web_size -1 ; i>0; i--) {
1000 proto_tree_add_item(sbusdata_tree,
1001 hf_sbus_data_byte, tvb, offset,
1008 /*Inform that command was not dissected and add remaining length*/
1010 if (sbus_eth_len > 13) { /*13 bytes is the minimal length of a request telegram...*/
1011 sbus_helper = sbus_eth_len - (offset + 2);
1012 proto_tree_add_text(sbus_tree, tvb, offset, sbus_helper,
1013 "This telegram isn't implemented in the dissector.");
1014 offset = offset + sbus_helper;
1019 /* Response dissection*/
1020 if (sbus_attribut == SBUS_RESPONSE && request_val) {
1021 switch (request_val->cmd_code) {
1022 /* Response: 32 bit values*/
1023 case SBUS_RD_COUNTER:
1024 case SBUS_RD_REGISTER:
1026 case SBUS_RD_USER_MEMORY:
1027 case SBUS_RD_PROGRAM_LINE:
1028 case SBUS_RD_USER_EEPROM_REGISTER:
1029 /*Add subtree for Data*/
1030 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1031 ((request_val->count) * 4),"Data");
1032 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1033 for (i=(request_val->count); i>0; i--) {
1034 proto_tree_add_item(sbusdata_tree,
1035 hf_sbus_data_rtc, tvb, offset,
1041 /* Response: PCD Display register*/
1042 case SBUS_RD_DISPLAY_REGISTER:
1043 proto_tree_add_item(sbus_tree,
1044 hf_sbus_display_register, tvb, offset, 4, FALSE);
1048 /* Add binary data I, O, F*/
1051 case SBUS_RD_OUTPUT:
1052 /*Add subtree for Data*/
1053 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1054 (((request_val->count) + 7) / 8), "Data");
1055 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1057 for (i=(((request_val->count) + 7) / 8); i>0; i--) {
1060 sbus_binarymasked = 0x01;
1061 sbus_binaries = tvb_get_guint8(tvb, offset);
1062 for (j=0; j<8; j++){
1063 if ((sbus_binarymasked & sbus_binaries) != 0) {
1064 sbus_show_bin = (sbus_show_bin + sbus_helper);
1066 sbus_binarymasked = sbus_binarymasked<<1;
1067 sbus_helper = 10 * sbus_helper;
1070 proto_tree_add_uint_format(sbusdata_tree,
1071 hf_sbus_data_iof, tvb, offset, 1, sbus_show_bin,
1072 "Binary data: %08u", sbus_show_bin);
1077 /* Response: Real time clock value*/
1079 sbus_helper = tvb_get_guint8(tvb, (offset +5)); /*hours*/
1080 sbus_helper1 = tvb_get_guint8(tvb, (offset +6)); /*minutes*/
1081 sbus_helper2 = tvb_get_guint8(tvb, (offset +7)); /*seconds*/
1082 proto_tree_add_text(sbus_tree, tvb, (offset +5), 3,
1083 "Time (HH:MM:SS): %02x:%02x:%02x", sbus_helper, sbus_helper1, sbus_helper2);
1084 sbus_helper = tvb_get_guint8(tvb, (offset +2)); /*year*/
1085 sbus_helper1 = tvb_get_guint8(tvb, (offset +3)); /*month*/
1086 sbus_helper2 = tvb_get_guint8(tvb, (offset +4)); /*day*/
1087 proto_tree_add_text(sbus_tree, tvb, (offset +2), 3,
1088 "Date (YY/MM/DD): %02x/%02x/%02x", sbus_helper, sbus_helper1, sbus_helper2);
1089 sbus_helper = tvb_get_guint8(tvb, (offset)); /*year-week*/
1090 sbus_helper1 = tvb_get_guint8(tvb, (offset +1)); /*week-day*/
1091 proto_tree_add_text(sbus_tree, tvb, offset, 2,
1092 "Calendar week: %x, Week day: %x", sbus_helper, sbus_helper1);
1093 /*Add subtree for Data*/
1094 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1096 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1098 proto_tree_add_item(sbusdata_tree,
1099 hf_sbus_week_day, tvb, offset, 2, FALSE);
1101 proto_tree_add_item(sbusdata_tree,
1102 hf_sbus_date, tvb, offset, 3, FALSE);
1104 proto_tree_add_item(sbusdata_tree,
1105 hf_sbus_time, tvb, offset, 3, FALSE);
1109 /* Response: CPU status, the command codes 14..1B are concerned*/
1110 case SBUS_RD_PCD_STATUS_CPU0:
1111 case SBUS_RD_PCD_STATUS_CPU1:
1112 case SBUS_RD_PCD_STATUS_CPU2:
1113 case SBUS_RD_PCD_STATUS_CPU3:
1114 case SBUS_RD_PCD_STATUS_CPU4:
1115 case SBUS_RD_PCD_STATUS_CPU5:
1116 case SBUS_RD_PCD_STATUS_CPU6:
1117 case SBUS_RD_PCD_STATUS_OWN:
1118 proto_tree_add_item(sbus_tree,
1119 hf_sbus_cpu_status, tvb, offset, 1, FALSE);
1123 /* Response: Station address*/
1124 case SBUS_RD_SBUS_STN_NBR:
1125 proto_tree_add_item(sbus_tree,
1126 hf_sbus_address, tvb, offset, 1, FALSE);
1130 /* Response: Firmware version */
1131 case SBUS_RD_PROGRAM_VERSION:
1133 tmp_string = tvb_get_string(tvb, offset, 5);
1134 proto_tree_add_string(sbus_tree,
1135 hf_sbus_cpu_type, tvb, offset, 5, tmp_string);
1139 tmp_string = tvb_get_string(tvb , offset, 3);
1140 proto_tree_add_string(sbus_tree,
1141 hf_sbus_fw_version, tvb, offset, 3, tmp_string);
1146 /* Response for Status Flags*/
1147 case SBUS_RD_STATUSFLAG_ACCU:
1148 /*Add subtree for Data*/
1149 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1150 1,"ACCU and arithmetic status");
1151 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1153 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_accu,
1154 tvb, offset, 1, FALSE);
1155 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_error,
1156 tvb, offset, 1, FALSE);
1157 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_negative,
1158 tvb, offset, 1, FALSE);
1159 proto_tree_add_item(sbusdata_tree, hf_sbus_flags_zero,
1160 tvb, offset, 1, FALSE);
1164 /* Response for Read byte */
1166 /*Add subtree for Data*/
1167 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1168 (request_val->count),"Data (bytes)");
1170 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1171 for (i=(request_val->count); i>0; i--) {
1172 proto_tree_add_item(sbusdata_tree,
1173 hf_sbus_data_byte, tvb, offset,
1179 /* Response for Read Index register */
1180 case SBUS_RD_INDEX_REGISTER:
1181 /*Add subtree for Data*/
1182 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1183 2,"Data (hex bytes)");
1185 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1186 for (i=0; i<2; i++) { /*2 bytes*/
1187 proto_tree_add_item(sbusdata_tree,
1188 hf_sbus_data_byte_hex, tvb, offset,
1194 /* Response: Instruction pointer*/
1195 case SBUS_RD_INSTRUCTION_POINTER:
1196 proto_tree_add_item(sbus_tree,
1197 hf_sbus_addr_prog, tvb, offset, 3, FALSE);
1201 /*Response for Find History*/
1202 case SBUS_FIND_HISTORY:
1203 proto_tree_add_item(sbus_tree,
1204 hf_sbus_addr_68k, tvb, offset, 3, FALSE);
1206 proto_tree_add_item(sbus_tree,
1207 hf_sbus_nbr_elements, tvb, offset, 2, FALSE);
1211 /* Response: Read current block*/
1212 case SBUS_RD_CURRENT_BLOCK:
1213 proto_tree_add_item(sbus_tree,
1214 hf_sbus_block_type, tvb, offset, 1, FALSE);
1216 proto_tree_add_item(sbus_tree,
1217 hf_sbus_block_nr, tvb, offset, 2, FALSE);
1221 /* Response: Read system infomation (without interpretation of module info)*/
1222 case SBUS_RD_SYSTEM_INFORMATION:
1223 if (((request_val->sysinfo) == 0x00)){ /*sysinfo 0*/
1224 offset += 1; /* this byte is always 0x01*/
1225 /*Add subtree for Data*/
1226 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1228 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1230 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_1,
1231 tvb, offset, 1, FALSE);
1232 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_2,
1233 tvb, offset, 1, FALSE);
1234 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_3,
1235 tvb, offset, 1, FALSE);
1236 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_4,
1237 tvb, offset, 1, FALSE);
1238 proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_5,
1239 tvb, offset, 1, FALSE);
1244 /* Response: Webserver request */
1245 case SBUS_WEB_SERVER_SERIAL_COMM:
1246 sbus_web_size = tvb_get_guint8(tvb,offset);
1247 proto_tree_add_item(sbus_tree,
1248 hf_sbus_web_size, tvb, offset,
1252 sbus_web_aid = tvb_get_guint8(tvb,offset);
1253 proto_tree_add_item(sbus_tree,
1254 hf_sbus_web_aid, tvb, offset,
1258 if (sbus_web_size > 1) {
1259 sbus_web_seq = tvb_get_guint8(tvb,offset);
1260 proto_tree_add_item(sbus_tree,
1261 hf_sbus_web_seq, tvb, offset,
1265 dt = proto_tree_add_text(sbus_tree, tvb, offset,
1266 (sbus_web_size - 2),"Data (bytes)");
1268 sbusdata_tree = proto_item_add_subtree(dt, ett_sbus_data);
1269 for (i=sbus_web_size - 2; i>0; i--) {
1270 proto_tree_add_item(sbusdata_tree,
1271 hf_sbus_data_byte, tvb, offset,
1278 /*Inform that response was not dissected and add remaining length*/
1280 sbus_helper = sbus_eth_len - (offset + 2);
1281 proto_tree_add_text(sbus_tree, tvb, offset, sbus_helper,
1282 "This telegram isn't implemented in the dissector.");
1283 offset = offset + sbus_helper;
1288 if (sbus_attribut == SBUS_ACKNAK) {
1289 proto_tree_add_item(sbus_tree,
1290 hf_sbus_acknackcode, tvb, offset, 2, FALSE);
1294 /* Calclulate CRC */
1296 for (i = 0; i < sbus_eth_len - 2; i++)
1297 sbus_crc_calc = crc_calc (sbus_crc_calc, tvb_get_guint8(tvb, i));
1298 /*Show CRC and add hidden item for wrong CRC*/
1299 sbus_helper = tvb_get_ntohs(tvb, offset);
1300 if (sbus_helper == sbus_crc_calc) {
1301 proto_tree_add_uint_format(sbus_tree,
1302 hf_sbus_crc, tvb, offset, 2, sbus_helper,
1303 "Checksum: 0x%04x (correct)", sbus_helper);
1305 proto_tree_add_uint_format(sbus_tree,
1306 hf_sbus_crc, tvb, offset, 2, sbus_helper,
1307 "Checksum: 0x%04x (NOT correct)", sbus_helper);
1308 hi = proto_tree_add_boolean(sbus_tree,
1309 hf_sbus_crc_bad, tvb, offset + 2, 2, TRUE);
1310 PROTO_ITEM_SET_HIDDEN(hi);
1312 offset += 2; /*now at the end of the telegram*/
1314 return tvb_length(tvb);
1315 /*End of dissect_sbus*/
1318 /* Register the protocol with Wireshark */
1321 proto_register_sbus(void)
1324 /* Setup list of header fields See Section 1.6.1 for details*/
1325 static hf_register_info hf[] = {
1327 { "Length (bytes)", "sbus.len",
1328 FT_UINT32, BASE_DEC, NULL, 0,
1329 "SAIA Ether-S-Bus telegram length", HFILL }
1332 { "Version", "sbus.vers",
1333 FT_UINT8, BASE_DEC, NULL, 0,
1334 "SAIA Ether-S-Bus version", HFILL }
1336 { &hf_sbus_protocol,
1337 { "Protocol type", "sbus.proto",
1338 FT_UINT8, BASE_DEC, NULL, 0,
1339 "SAIA Ether-S-Bus protocol type", HFILL }
1341 { &hf_sbus_sequence,
1342 { "Sequence", "sbus.seq",
1343 FT_UINT16, BASE_DEC, NULL, 0,
1344 "SAIA Ether-S-Bus sequence number", HFILL }
1347 { &hf_sbus_attribut,
1348 { "Telegram attribute", "sbus.att",
1349 FT_UINT8, BASE_HEX, VALS(sbus_att_vals), 0,
1350 "SAIA Ether-S-Bus telegram attribute, indicating type of telegram", HFILL }
1354 { "Destination", "sbus.destination",
1355 FT_UINT8, BASE_DEC, NULL, 0,
1356 "SAIA S-Bus destination address", HFILL }
1360 { "S-Bus address", "sbus.address",
1361 FT_UINT8, BASE_DEC, NULL, 0,
1362 "SAIA S-Bus station address", HFILL }
1366 { "Command", "sbus.cmd",
1367 FT_UINT8, BASE_HEX, VALS(sbus_command_vals), 0,
1368 "SAIA S-Bus command", HFILL }
1371 { &hf_sbus_command_extension,
1372 { "Command extension", "sbus.cmd_extn",
1373 FT_UINT8, BASE_HEX, NULL, 0,
1374 "SAIA S-Bus command extension", HFILL }
1378 { "R-count", "sbus.rcount",
1379 FT_UINT8, BASE_DEC, NULL, 0,
1380 "Number of elements expected in response", HFILL }
1384 { "W-count (raw)", "sbus.wcount",
1385 FT_UINT8, BASE_DEC, NULL, 0,
1386 "Number of bytes to be written", HFILL }
1389 { &hf_sbus_wcount_calculated,
1390 { "W-count (32 bit values)", "sbus.wcount_calc",
1391 FT_UINT8, BASE_DEC, NULL, 0,
1392 "Number of elements to be written", HFILL }
1395 { &hf_sbus_fio_count,
1396 { "FIO Count (amount of bits)", "sbus.fio_count",
1397 FT_UINT8, BASE_DEC, NULL, 0,
1398 "Number of binary elements to be written", HFILL }
1401 { &hf_sbus_addr_rtc,
1402 { "Base address RTC", "sbus.addr_RTC",
1403 FT_UINT16, BASE_DEC, NULL, 0,
1404 "Base address of 32 bit elements to read", HFILL }
1407 { &hf_sbus_addr_iof,
1408 { "Base address IOF", "sbus.addr_IOF",
1409 FT_UINT16, BASE_DEC, NULL, 0,
1410 "Base address of binary elements to read", HFILL }
1413 { &hf_sbus_addr_eeprom,
1414 { "Base address of EEPROM register", "sbus.addr_EEPROM",
1415 FT_UINT16, BASE_DEC, NULL, 0,
1416 "Base address of 32 bit EEPROM register to read or write", HFILL }
1419 { &hf_sbus_addr_prog,
1420 { "Base address of user memory or program lines", "sbus.addr_prog",
1421 FT_UINT24, BASE_DEC, NULL, 0,
1422 "Base address of the user memory or program lines (read or write)", HFILL }
1425 { &hf_sbus_addr_68k,
1426 { "Base address of bytes", "sbus.addr_prog",
1427 FT_UINT24, BASE_HEX, NULL, 0,
1428 "Base address of bytes to read or write (68k address)", HFILL }
1431 { &hf_sbus_block_type,
1432 { "Block type", "sbus.block_type",
1433 FT_UINT8, BASE_HEX, VALS(sbus_block_types), 0,
1434 "Program block type read", HFILL }
1437 { &hf_sbus_block_nr,
1438 { "Block/Element nr", "sbus.block_nr",
1439 FT_UINT16, BASE_DEC, NULL, 0,
1440 "Program block / DatatBlock number", HFILL }
1443 { &hf_sbus_nbr_elements,
1444 { "Number of elements", "sbus.nbr_elements",
1445 FT_UINT16, BASE_DEC, NULL, 0,
1446 "Number of elements or characters", HFILL }
1449 { &hf_sbus_display_register,
1450 { "PCD Display register", "sbus.data_display_register",
1451 FT_UINT32, BASE_DEC, NULL, 0,
1452 "The PCD display register (32 bit value)", HFILL }
1455 { &hf_sbus_data_rtc,
1456 { "S-Bus 32-bit data", "sbus.data_rtc",
1457 FT_UINT32, BASE_DEC, NULL, 0,
1458 "One regiser/timer of counter (32 bit value)", HFILL }
1461 { &hf_sbus_data_byte,
1462 { "Data bytes", "sbus.data_byte",
1463 FT_UINT8, BASE_DEC, NULL, 0,
1464 "One byte from PCD", HFILL }
1467 { &hf_sbus_data_byte_hex,
1468 { "Data bytes (hex)", "sbus.data_byte_hex",
1469 FT_UINT8, BASE_HEX, NULL, 0,
1470 "One byte from PCD (hexadecimal)", HFILL }
1473 { &hf_sbus_data_iof,
1474 { "S-Bus binary data", "sbus.data_iof",
1475 FT_UINT32, BASE_DEC, NULL, 0,
1476 "8 binaries", HFILL }
1479 { &hf_sbus_cpu_type,
1480 { "PCD type", "sbus.pcd_type",
1481 FT_STRING, BASE_NONE, NULL, 0,
1482 "PCD type (short form)", HFILL }
1485 { &hf_sbus_fw_version,
1486 { "Firmware version", "sbus.fw_version",
1487 FT_STRING, BASE_NONE, NULL, 0,
1488 "Firmware version of the PCD or module", HFILL }
1491 { &hf_sbus_sysinfo_nr,
1492 { "System information number", "sbus.sysinfo",
1493 FT_UINT8, BASE_HEX, NULL, 0,
1494 "System information number (extension to command code)", HFILL }
1497 { &hf_sbus_sysinfo0_1,
1498 { "Mem size info", "sbus.sysinfo0.mem",
1499 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_MEMSIZE,
1500 "Availability of memory size information", HFILL }
1502 { &hf_sbus_sysinfo0_2,
1503 { "Trace buffer", "sbus.sysinfo0.trace",
1504 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_TRACE,
1505 "Availability of trace buffer feature", HFILL }
1507 { &hf_sbus_sysinfo0_3,
1508 { "Slot B1", "sbus.sysinfo0.b1",
1509 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_INFO_B1,
1510 "Presence of EEPROM information on slot B1", HFILL }
1512 { &hf_sbus_sysinfo0_4,
1513 { "Slot B2", "sbus.sysinfo0.b2",
1514 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_INFO_B2,
1515 "Presence of EEPROM information on slot B2", HFILL }
1517 { &hf_sbus_sysinfo0_5,
1518 { "PGU baud", "sbus.sysinfo0.pgubaud",
1519 FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_PGU_BAUD,
1520 "Availability of PGU baud switch feature", HFILL }
1523 { &hf_sbus_sysinfo_length,
1524 { "System information length", "sbus.sysinfo_length",
1525 FT_UINT8, BASE_HEX, NULL, 0,
1526 "System information length in response", HFILL }
1529 { &hf_sbus_f_module_type,
1530 { "F-module type", "sbus.fmodule_type",
1531 FT_STRING, BASE_NONE, NULL, 0,
1532 "Module type mounted on B1/2 slot", HFILL }
1535 { &hf_sbus_harware_version,
1536 { "Hardware version", "sbus.hw_version",
1537 FT_STRING, BASE_NONE, NULL, 0,
1538 "Hardware version of the PCD or the module", HFILL }
1541 { &hf_sbus_hardware_modification,
1542 { "Hardware modification", "sbus.hw_modification",
1543 FT_UINT8, BASE_DEC, NULL, 0,
1544 "Hardware modification of the PCD or module", HFILL }
1548 { "Various data", "sbus.various",
1549 FT_NONE, BASE_NONE, NULL, 0,
1550 "Various data contained in telegrams but nobody will search for it", HFILL }
1553 { &hf_sbus_acknackcode,
1554 { "ACK/NAK code", "sbus.nakcode",
1555 FT_UINT16, BASE_HEX, VALS(sbus_ack_nak_vals), 0,
1556 "SAIA S-Bus ACK/NAK response", HFILL }
1559 { &hf_sbus_cpu_status,
1560 { "CPU status", "sbus.CPU_status",
1561 FT_UINT8, BASE_HEX, VALS(sbus_CPU_status), 0,
1562 "SAIA PCD CPU status", HFILL }
1565 { &hf_sbus_week_day,
1566 { "RTC calendar week and week day", "sbus.rtc.week_day",
1567 FT_UINT16, BASE_HEX, NULL, 0,
1568 "Calendar week and week day number of the real time clock", HFILL }
1572 { "RTC date (YYMMDD)", "sbus.rtc.date",
1573 FT_UINT24, BASE_HEX, NULL, 0,
1574 "Year, month and day of the real time clock", HFILL }
1578 { "RTC time (HHMMSS)", "sbus.rtc.time",
1579 FT_UINT24, BASE_HEX, NULL, 0,
1580 "Time of the real time clock", HFILL }
1583 { &hf_sbus_web_size,
1584 { "Web server packet size", "sbus.web.size",
1585 FT_UINT8, BASE_HEX, NULL, 0,
1590 { "AID", "sbus.web.aid",
1591 FT_UINT8, BASE_HEX, NULL, 0,
1592 "Web server command/status code (AID)", HFILL }
1596 { "Sequence", "sbus.web.seq",
1597 FT_UINT8, BASE_HEX, NULL, 0,
1598 "Web server sequence nr (PACK_N)", HFILL }
1602 { "Checksum", "sbus.crc",
1603 FT_UINT16, BASE_HEX, NULL, 0,
1608 { "Bad Checksum", "sbus.crc_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1609 "A bad checksum in the telegram", HFILL }},
1611 { &hf_sbus_flags_accu,
1612 { "ACCU", "sbus.flags.accu",
1613 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ACCU,
1614 "PCD Accumulator", HFILL }
1617 { &hf_sbus_flags_error,
1618 { "Error flag", "sbus.flags.error",
1619 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ERROR,
1620 "PCD error flag", HFILL }
1623 { &hf_sbus_flags_negative,
1624 { "N-flag", "sbus.flags.nflag",
1625 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_NEGATIVE,
1626 "Negative status flag", HFILL }
1629 { &hf_sbus_flags_zero,
1630 { "Z-flag", "sbus.flags.zflag",
1631 FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ZERO,
1632 "Zero status flag", HFILL }
1636 /* Setup protocol subtree array */
1637 static gint *ett[] = {
1643 /* Register the protocol name and description */
1644 proto_sbus = proto_register_protocol("SAIA S-Bus", "SBUS", "sbus");
1646 /* Required function calls to register the header fields and subtrees used */
1647 proto_register_field_array(proto_sbus, hf, array_length(hf));
1648 proto_register_subtree_array(ett, array_length(ett));
1649 register_init_routine(&sbus_init_protocol);
1653 proto_reg_handoff_sbus(void)
1655 dissector_handle_t sbus_handle;
1657 sbus_handle = new_create_dissector_handle(dissect_sbus, proto_sbus);
1658 dissector_add("udp.port", 5050, sbus_handle);