/src/wireshark/epan/dissectors/packet-sbus.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* packet-sbus.c |
2 | | * Routines for Ether-S-Bus dissection |
3 | | * Copyright 2010, Christian Durrer <christian.durrer@sensemail.ch> |
4 | | * |
5 | | * Wireshark - Network traffic analyzer |
6 | | * By Gerald Combs <gerald@wireshark.org> |
7 | | * Copyright 1998 Gerald Combs |
8 | | * |
9 | | * SPDX-License-Identifier: GPL-2.0-or-later |
10 | | */ |
11 | | |
12 | | #include "config.h" |
13 | | |
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> |
19 | | |
20 | | void proto_register_sbus(void); |
21 | | void proto_reg_handoff_sbus(void); |
22 | | |
23 | | static dissector_handle_t sbus_handle; |
24 | | |
25 | 14 | #define SBUS_UDP_PORT 5050 /* Not IANA registered */ |
26 | | |
27 | | /* Attribute values*/ |
28 | 0 | #define SBUS_REQUEST 0x00 |
29 | 0 | #define SBUS_RESPONSE 0x01 |
30 | 0 | #define SBUS_ACKNAK 0x02 |
31 | | |
32 | | /*SBus command codes*/ |
33 | 0 | #define SBUS_RD_COUNTER 0x00 |
34 | 0 | #define SBUS_RD_DISPLAY_REGISTER 0x01 |
35 | 0 | #define SBUS_RD_FLAG 0x02 |
36 | 0 | #define SBUS_RD_INPUT 0x03 |
37 | 0 | #define SBUS_RD_RTC 0x04 |
38 | 0 | #define SBUS_RD_OUTPUT 0x05 |
39 | 0 | #define SBUS_RD_REGISTER 0x06 |
40 | 0 | #define SBUS_RD_TIMER 0x07 |
41 | 0 | #define SBUS_WR_COUNTER 0x0A |
42 | 0 | #define SBUS_WR_FLAG 0x0B |
43 | 0 | #define SBUS_WR_RTC 0x0C |
44 | 0 | #define SBUS_WR_OUTPUT 0x0D |
45 | 0 | #define SBUS_WR_REGISTER 0x0E |
46 | 0 | #define SBUS_WR_TIMER 0x0F |
47 | 0 | #define SBUS_RDWR_MULTI_MEDIAS 0x13 |
48 | 0 | #define SBUS_RD_PCD_STATUS_CPU0 0x14 |
49 | 0 | #define SBUS_RD_PCD_STATUS_CPU1 0x15 |
50 | 0 | #define SBUS_RD_PCD_STATUS_CPU2 0x16 |
51 | 0 | #define SBUS_RD_PCD_STATUS_CPU3 0x17 |
52 | 0 | #define SBUS_RD_PCD_STATUS_CPU4 0x18 |
53 | 0 | #define SBUS_RD_PCD_STATUS_CPU5 0x19 |
54 | 0 | #define SBUS_RD_PCD_STATUS_CPU6 0x1A |
55 | 0 | #define SBUS_RD_PCD_STATUS_OWN 0x1B |
56 | 0 | #define SBUS_RD_SBUS_STN_NBR 0x1D |
57 | 0 | #define SBUS_RD_USER_MEMORY 0x1E |
58 | 0 | #define SBUS_RD_PROGRAM_LINE 0x1F |
59 | 0 | #define SBUS_RD_PROGRAM_VERSION 0x20 |
60 | | #define SBUS_RD_TEXT 0x21 |
61 | | #define SBUS_RD_ACTIVE_TRANSITION 0x22 |
62 | 0 | #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 | 0 | #define SBUS_RD_STATUSFLAG_ACCU 0x46 |
92 | 0 | #define SBUS_RD_BYTE 0x47 |
93 | | #define SBUS_RD_HALT_FAILURE_REG 0x48 |
94 | 0 | #define SBUS_RD_INDEX_REGISTER 0x49 |
95 | 0 | #define SBUS_RD_INSTRUCTION_POINTER 0x4A |
96 | 0 | #define SBUS_FIND_HISTORY 0x4B |
97 | | #define SBUS_WR_STATUSFLAG_ACCU 0x50 |
98 | 0 | #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 | 0 | #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 | 0 | #define SBUS_RD_CURRENT_BLOCK 0x9D |
136 | | #define SBUS_RD_CALL_STACK 0x9E |
137 | | #define SBUS_RD_DBX 0x9F |
138 | 0 | #define SBUS_RD_USER_EEPROM_REGISTER 0xA1 |
139 | 0 | #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 | 0 | #define SBUS_RD_WR_PCD_BLOCK 0xA9 |
145 | | #define SBUS_GET_DIAGNOSTIC 0xAA |
146 | 0 | #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 | 0 | #define SBUS_WEB_SERVER_SERIAL_COMM 0xAF |
151 | | |
152 | | /* Bitfield in the arithmetic flags and accu*/ |
153 | 14 | #define F_ACCU (1<<0) /* Accumulator of PCD */ |
154 | 14 | #define F_ERROR (1<<1) /* Error flag of PCD */ |
155 | 14 | #define F_NEGATIVE (1<<2) /* Negative arithmetic status flag */ |
156 | 14 | #define F_ZERO (1<<3) /* Zero arithmetic status flag */ |
157 | | |
158 | | /* Bitfield in the system information*/ |
159 | | /*#define F_EMPTY (1<<0) always 0 */ |
160 | 14 | #define F_MEMSIZE (1<<1) /* Memory size information */ |
161 | 14 | #define F_TRACE (1<<2) /* Trace buffer feature */ |
162 | 14 | #define F_INFO_B1 (1<<3) /* EEPROM information of slot B1 */ |
163 | 14 | #define F_INFO_B2 (1<<4) /* EEPROM information of slot B2 */ |
164 | 14 | #define F_PGU_BAUD (1<<5) /* PGU baudrate can be switched */ |
165 | | |
166 | | |
167 | | /* Read/write block command codes*/ |
168 | 0 | #define SBUS_WR_START_OF_STREAM 0x00 |
169 | 0 | #define SBUS_WR_BLOCK_DATA_STREAM 0x01 |
170 | 0 | #define SBUS_WR_BLOCK_END_OF_STREAM 0x02 |
171 | 0 | #define SBUS_WR_ABORT_BLOCK_STREAM 0x07 |
172 | 0 | #define SBUS_WR_BLOCK_DATA_BYTES 0x08 |
173 | 0 | #define SBUS_RD_BLOCK_START_OF_STREAM 0X10 |
174 | 0 | #define SBUS_RD_BLOCK_DATA_STREAM 0x11 |
175 | 0 | #define SBUS_RD_ABORT_BLOCK_STREAM 0x17 |
176 | 0 | #define SBUS_RD_BLOCK_DATA_BYTES 0x18 |
177 | 0 | #define SBUS_DELETE_BLOCK 0x20 |
178 | 0 | #define SBUS_GET_BLOCK_SIZE 0x21 |
179 | 0 | #define SBUS_GET_PROGRAM_BLOCK_LIST 0x22 |
180 | | |
181 | | /* Read/write block types*/ |
182 | 0 | #define SBUS_RD_WR_CONFIGURATION_FILE 0x20 |
183 | 0 | #define SBUS_RD_WR_PROGRAM_BLOCK_FILE 0x21 |
184 | 0 | #define SBUS_RD_WR_UNKNOWN_BLOCK_TYPE 0x83 |
185 | | |
186 | | /* Read/write block error codes*/ |
187 | 0 | #define SBUS_RD_WR_NAK 0x80 |
188 | 0 | #define SBUS_RD_WR_NAK_INVALID_SIZE 0x8A |
189 | | |
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; |
261 | | |
262 | | /* Initialize the subtree pointers */ |
263 | | static int ett_sbus; |
264 | | static int ett_sbus_ether; |
265 | | static int ett_sbus_data; |
266 | | |
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; |
272 | | |
273 | | /* True/False strings*/ |
274 | | static const true_false_string tfs_sbus_flags= { |
275 | | "Is high", |
276 | | "Is low" |
277 | | }; |
278 | | |
279 | | static const true_false_string tfs_sbus_present= { |
280 | | "Is present", |
281 | | "Is not present" |
282 | | }; |
283 | | |
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} |
291 | | }; |
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} |
312 | | }; |
313 | | static value_string_ext sbus_block_types_ext = VALUE_STRING_EXT_INIT(sbus_block_types); |
314 | | |
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} |
324 | | }; |
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} |
333 | | }; |
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} |
455 | | }; |
456 | | static value_string_ext sbus_command_vals_ext = VALUE_STRING_EXT_INIT(sbus_command_vals); |
457 | | |
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} |
467 | | }; |
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} |
482 | | }; |
483 | | static value_string_ext rdwrblock_vals_ext = VALUE_STRING_EXT_INIT(rdwrblock_vals); |
484 | | |
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} |
504 | | }; |
505 | | static value_string_ext rdwrblock_sts_ext = VALUE_STRING_EXT_INIT(rdwrblock_sts); |
506 | | |
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} |
512 | | }; |
513 | | |
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 |
531 | | }; |
532 | | |
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; |
538 | | |
539 | | typedef struct { |
540 | | uint8_t cmd_code; /*multimedia command code*/ |
541 | | uint8_t count; /*rcount of sub-request*/ |
542 | | } sbus_subrequest; |
543 | | |
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; |
556 | | |
557 | | /* The hash structure (for conversations)*/ |
558 | | static wmem_map_t *sbus_request_hash; |
559 | | |
560 | | static unsigned crc_calc (unsigned crc, unsigned val) |
561 | 0 | { |
562 | 0 | int indx; |
563 | 0 | unsigned ncrc; |
564 | |
|
565 | 0 | indx = (((crc >> 8) ^ val) & 0xff); |
566 | 0 | ncrc = crc_table[indx] ^ ((crc << 8) & 0xffff); |
567 | |
|
568 | 0 | return ncrc; |
569 | 0 | } |
570 | | |
571 | | /* Hash functions*/ |
572 | | static int sbus_equal(const void *v, const void *w) |
573 | 0 | { |
574 | 0 | const sbus_request_key *v1 = (const sbus_request_key *)v; |
575 | 0 | const sbus_request_key *v2 = (const sbus_request_key *)w; |
576 | |
|
577 | 0 | if (v1->conversation == v2->conversation && |
578 | 0 | v1->sequence == v2->sequence) { |
579 | 0 | return 1; |
580 | 0 | } |
581 | 0 | return 0; |
582 | 0 | } |
583 | | |
584 | | static unsigned sbus_hash(const void *v) |
585 | 0 | { |
586 | 0 | const sbus_request_key *key = (const sbus_request_key *)v; |
587 | 0 | unsigned val; |
588 | |
|
589 | 0 | val = key->conversation + key->sequence; |
590 | 0 | return val; |
591 | 0 | } |
592 | | |
593 | | /* check whether the packet looks like SBUS or not */ |
594 | | static bool |
595 | | is_sbus_pdu(tvbuff_t *tvb) |
596 | 3 | { |
597 | 3 | uint32_t length; |
598 | | |
599 | | /* we need at least 8 bytes to determine whether this is sbus or |
600 | | not*/ |
601 | 3 | if(tvb_captured_length(tvb)<8){ |
602 | 0 | return false; |
603 | 0 | } |
604 | | |
605 | | /* the length must be >= 8 bytes to accommodate the header, |
606 | | it also must be <65536 to fit inside a udp packet |
607 | | */ |
608 | 3 | length=tvb_get_ntohl(tvb, 0); |
609 | 3 | if ( (length<8) || (length>65535) ) { |
610 | 2 | return false; |
611 | 2 | } |
612 | 1 | if (tvb_reported_length(tvb) != length) { |
613 | 1 | return false; |
614 | 1 | } |
615 | | /* First four byte indicate the length which must be at least 12 bytes*/ |
616 | 0 | if (tvb_get_ntohl(tvb, 0) < 12) { |
617 | 0 | return false; |
618 | 0 | } |
619 | | /* Fifth byte indicates protocol version which can be 0 or 1*/ |
620 | 0 | if (tvb_get_uint8(tvb, 4) > 0x01) { |
621 | 0 | return false; |
622 | 0 | } |
623 | | /* Sixth byte indicates protocol type and must be 0*/ |
624 | 0 | if ( tvb_get_uint8(tvb, 5) > 0x01 ) { |
625 | 0 | return false; |
626 | 0 | } |
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 | 0 | if (tvb_get_uint8(tvb, 8) > 0x02 ) { |
632 | 0 | return false; |
633 | 0 | } |
634 | 0 | return true; |
635 | 0 | } |
636 | | |
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) |
639 | 0 | { |
640 | 0 | int i, j; |
641 | 0 | int sbus_media_cnt; |
642 | 0 | proto_tree *sub_tree; |
643 | 0 | uint8_t sbus_fio_cnt; |
644 | 0 | uint32_t sbus_binaries; |
645 | 0 | uint32_t sbus_binarymasked; |
646 | 0 | uint32_t sbus_show_bin; |
647 | 0 | uint32_t sbus_helper; |
648 | |
|
649 | 0 | switch (sbus_cmd_code) { |
650 | | /*Read Counter, Register or Timer*/ |
651 | 0 | case SBUS_RD_COUNTER: |
652 | 0 | case SBUS_RD_REGISTER: |
653 | 0 | case SBUS_RD_TIMER: |
654 | 0 | sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1; |
655 | 0 | proto_tree_add_uint(tree, |
656 | 0 | hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt); |
657 | 0 | offset += 1; |
658 | 0 | proto_tree_add_item(tree, |
659 | 0 | hf_sbus_addr_rtc, tvb, offset, 2, ENC_BIG_ENDIAN); |
660 | 0 | offset += 2; |
661 | 0 | break; |
662 | | |
663 | | /*Read Flag, Input or Output*/ |
664 | 0 | case SBUS_RD_FLAG: |
665 | 0 | case SBUS_RD_INPUT: |
666 | 0 | case SBUS_RD_OUTPUT: |
667 | 0 | sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1; |
668 | 0 | proto_tree_add_uint(tree, |
669 | 0 | hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt); |
670 | 0 | offset += 1; |
671 | 0 | proto_tree_add_item(tree, |
672 | 0 | hf_sbus_addr_iof, tvb, offset, 2, ENC_BIG_ENDIAN); |
673 | 0 | offset += 2; |
674 | 0 | break; |
675 | | |
676 | | /*Write Register Timer Counter*/ |
677 | 0 | case SBUS_WR_COUNTER: |
678 | 0 | case SBUS_WR_REGISTER: |
679 | 0 | case SBUS_WR_TIMER: |
680 | 0 | sbus_media_cnt = (tvb_get_uint8(tvb,offset)); |
681 | 0 | sbus_media_cnt = ((sbus_media_cnt - 1)/4); |
682 | 0 | proto_tree_add_uint(tree, |
683 | 0 | hf_sbus_wcount_calculated, tvb, offset, |
684 | 0 | 1, sbus_media_cnt); |
685 | 0 | proto_tree_add_item(tree, |
686 | 0 | hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN); |
687 | 0 | offset += 1; |
688 | 0 | proto_tree_add_item(tree, |
689 | 0 | hf_sbus_addr_rtc, tvb, offset, 2, ENC_BIG_ENDIAN); |
690 | 0 | offset += 2; |
691 | | /*Add subtree for Data*/ |
692 | 0 | sub_tree = proto_tree_add_subtree(tree, tvb, offset, |
693 | 0 | ((sbus_media_cnt) * 4), ett_sbus_data, NULL, "Data"); |
694 | 0 | for (i=((sbus_media_cnt)); i>0; i--) { |
695 | 0 | proto_tree_add_item(sub_tree, |
696 | 0 | hf_sbus_data_rtc, tvb, offset, |
697 | 0 | 4, ENC_BIG_ENDIAN); |
698 | 0 | offset += 4; |
699 | 0 | } |
700 | 0 | break; |
701 | | |
702 | | /* Write flags and outputs*/ |
703 | 0 | case SBUS_WR_FLAG: |
704 | 0 | case SBUS_WR_OUTPUT: |
705 | 0 | sbus_media_cnt = (tvb_get_uint8(tvb,offset)); |
706 | 0 | sbus_media_cnt = (sbus_media_cnt - 2); |
707 | 0 | proto_tree_add_uint(tree, |
708 | 0 | hf_sbus_wcount_calculated, tvb, offset, |
709 | 0 | 1, sbus_media_cnt); |
710 | 0 | proto_tree_add_item(tree, |
711 | 0 | hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN); |
712 | 0 | offset += 1; |
713 | 0 | proto_tree_add_item(tree, |
714 | 0 | hf_sbus_addr_iof, tvb, offset, 2, ENC_BIG_ENDIAN); |
715 | 0 | offset += 2; |
716 | 0 | sbus_fio_cnt = (tvb_get_uint8(tvb,offset)); |
717 | 0 | sbus_fio_cnt = ((sbus_fio_cnt + 1)); |
718 | 0 | proto_tree_add_uint(tree, |
719 | 0 | hf_sbus_fio_count, tvb, offset, 1, sbus_fio_cnt); |
720 | 0 | offset += 1; |
721 | | /*Add subtree for Data*/ |
722 | 0 | sub_tree = proto_tree_add_subtree(tree, tvb, offset, |
723 | 0 | sbus_media_cnt, ett_sbus_data, NULL, "Data"); |
724 | |
|
725 | 0 | for (i=sbus_media_cnt; i>0; i--) { |
726 | 0 | sbus_helper = 1; |
727 | 0 | sbus_show_bin = 0; |
728 | 0 | sbus_binarymasked = 0x01; |
729 | 0 | sbus_binaries = tvb_get_uint8(tvb, offset); |
730 | 0 | for (j=0; j<8; j++) { |
731 | 0 | if ((sbus_binarymasked & sbus_binaries) != 0) { |
732 | 0 | sbus_show_bin = (sbus_show_bin + sbus_helper); |
733 | 0 | } |
734 | 0 | sbus_binarymasked = sbus_binarymasked<<1; |
735 | 0 | sbus_helper = 10 * sbus_helper; |
736 | 0 | } |
737 | |
|
738 | 0 | proto_tree_add_uint_format(sub_tree, |
739 | 0 | hf_sbus_data_iof, tvb, offset, 1, sbus_show_bin, |
740 | 0 | "Binary data: %08u", sbus_show_bin); |
741 | 0 | offset += 1; |
742 | 0 | } |
743 | 0 | break; |
744 | 0 | case SBUS_RD_DATA_BLOCK: |
745 | 0 | sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1; |
746 | 0 | proto_tree_add_uint(tree, |
747 | 0 | hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt); |
748 | 0 | offset += 1; |
749 | 0 | proto_tree_add_item(tree, |
750 | 0 | hf_sbus_addr_db, tvb, offset, 2, ENC_BIG_ENDIAN); |
751 | 0 | offset += 2; |
752 | | /*add base element address*/ |
753 | 0 | proto_tree_add_item(tree, |
754 | 0 | hf_sbus_addr_base_element, tvb, offset, 2, ENC_BIG_ENDIAN); |
755 | 0 | offset += 2; |
756 | 0 | break; |
757 | 0 | } |
758 | 0 | return offset; |
759 | | |
760 | |
|
761 | 0 | } |
762 | | |
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) |
765 | 0 | { |
766 | 0 | int i, j; |
767 | 0 | proto_tree *sub_tree; |
768 | 0 | uint32_t sbus_binaries; |
769 | 0 | uint32_t sbus_binarymasked; |
770 | 0 | uint32_t sbus_show_bin; |
771 | 0 | uint32_t sbus_helper; |
772 | |
|
773 | 0 | switch (cmd_code) { |
774 | | |
775 | | /*Add subtree for Data*/ |
776 | 0 | case SBUS_RD_COUNTER: |
777 | 0 | case SBUS_RD_REGISTER: |
778 | 0 | case SBUS_RD_TIMER: |
779 | 0 | case SBUS_RD_USER_MEMORY: |
780 | 0 | case SBUS_RD_PROGRAM_LINE: |
781 | 0 | case SBUS_RD_USER_EEPROM_REGISTER: |
782 | 0 | case SBUS_RD_DATA_BLOCK: |
783 | 0 | sub_tree = proto_tree_add_subtree(tree, tvb, offset, |
784 | 0 | (count * 4), ett_sbus_data, NULL, "Data"); |
785 | 0 | for (i=count; i>0; i--) { |
786 | 0 | proto_tree_add_item(sub_tree, |
787 | 0 | hf_sbus_data_rtc, tvb, offset, |
788 | 0 | 4, ENC_BIG_ENDIAN); |
789 | 0 | offset += 4; |
790 | 0 | } |
791 | 0 | break; |
792 | | |
793 | | /* Add binary data I, O, F*/ |
794 | 0 | case SBUS_RD_FLAG: |
795 | 0 | case SBUS_RD_INPUT: |
796 | 0 | case SBUS_RD_OUTPUT: |
797 | | /*Add subtree for Data*/ |
798 | 0 | sub_tree = proto_tree_add_subtree(tree, tvb, offset, |
799 | 0 | (((count) + 7) / 8), ett_sbus_data, NULL, "Data"); |
800 | |
|
801 | 0 | for (i=(((count) + 7) / 8); i>0; i--) { |
802 | 0 | sbus_helper = 1; |
803 | 0 | sbus_show_bin = 0; |
804 | 0 | sbus_binarymasked = 0x01; |
805 | 0 | sbus_binaries = tvb_get_uint8(tvb, offset); |
806 | 0 | for (j=0; j<8; j++){ |
807 | 0 | if ((sbus_binarymasked & sbus_binaries) != 0) { |
808 | 0 | sbus_show_bin = (sbus_show_bin + sbus_helper); |
809 | 0 | } |
810 | 0 | sbus_binarymasked = sbus_binarymasked<<1; |
811 | 0 | sbus_helper = 10 * sbus_helper; |
812 | 0 | } |
813 | |
|
814 | 0 | proto_tree_add_uint_format(sub_tree, |
815 | 0 | hf_sbus_data_iof, tvb, offset, 1, sbus_show_bin, |
816 | 0 | "Binary data: %08u", sbus_show_bin); |
817 | 0 | offset += 1; |
818 | 0 | } |
819 | 0 | break; |
820 | 0 | } |
821 | 0 | return offset; |
822 | 0 | } |
823 | | |
824 | | static int get_response_length(int cmd_code, int count) |
825 | 0 | { |
826 | |
|
827 | 0 | int length; |
828 | 0 | length = 0; |
829 | |
|
830 | 0 | switch (cmd_code) { |
831 | | |
832 | | /*Get length of 32 bit data*/ |
833 | 0 | case SBUS_RD_COUNTER: |
834 | 0 | case SBUS_RD_REGISTER: |
835 | 0 | case SBUS_RD_TIMER: |
836 | 0 | case SBUS_RD_USER_MEMORY: |
837 | 0 | case SBUS_RD_PROGRAM_LINE: |
838 | 0 | case SBUS_RD_USER_EEPROM_REGISTER: |
839 | 0 | case SBUS_RD_DATA_BLOCK: |
840 | 0 | length = count * 4; |
841 | 0 | break; |
842 | | |
843 | | /* Get length of binary data I, O, F*/ |
844 | 0 | case SBUS_RD_FLAG: |
845 | 0 | case SBUS_RD_INPUT: |
846 | 0 | case SBUS_RD_OUTPUT: |
847 | 0 | length = ((count) + 7) / 8; |
848 | 0 | break; |
849 | 0 | } |
850 | 0 | return length; |
851 | |
|
852 | 0 | } |
853 | | |
854 | | |
855 | | static int add_sbus_subrequest(tvbuff_t *tvb, wmem_list_t *request_list, int offset) |
856 | 0 | { |
857 | | /*append subrequest info to requests lists and return number of sub-requests*/ |
858 | 0 | int subrequest_count; |
859 | 0 | int internal_wcount; |
860 | 0 | int internal_subwcount; |
861 | 0 | int internal_offset; |
862 | 0 | int internal_last_offset; |
863 | |
|
864 | 0 | internal_offset = offset; |
865 | 0 | subrequest_count = 0; |
866 | 0 | internal_wcount = tvb_get_uint8(tvb,internal_offset); |
867 | 0 | internal_last_offset = internal_wcount + offset + 1; /*check for new sub requests until this end offset*/ |
868 | |
|
869 | 0 | for(int i=0; i < 64; i +=1){ /*max sub-requests number is 64*/ |
870 | 0 | if (internal_last_offset > internal_offset) { |
871 | 0 | sbus_subrequest *sub_req; |
872 | 0 | sub_req = wmem_new(wmem_file_scope(), sbus_subrequest); |
873 | |
|
874 | 0 | internal_offset += 1; /*move to the next sub-request wcount*/ |
875 | 0 | internal_subwcount = tvb_get_uint8(tvb,internal_offset); |
876 | 0 | internal_offset += 1; |
877 | 0 | sub_req->cmd_code = tvb_get_uint8(tvb,internal_offset); |
878 | 0 | internal_offset += 1; |
879 | 0 | sub_req->count = tvb_get_uint8(tvb,internal_offset) + 1; |
880 | 0 | internal_offset += internal_subwcount -1; |
881 | 0 | subrequest_count += 1; |
882 | |
|
883 | 0 | wmem_list_append(request_list, sub_req); |
884 | 0 | } |
885 | 0 | } |
886 | 0 | return subrequest_count; |
887 | |
|
888 | 0 | } |
889 | | |
890 | | /*Dissect the telegram*/ |
891 | | static int |
892 | | dissect_sbus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) |
893 | 3 | { |
894 | | |
895 | | /* Set up structures needed to add the protocol subtree and manage it */ |
896 | 3 | proto_item *ti, *hi; |
897 | 3 | proto_tree *sbus_tree, *ethsbus_tree, *sbusdata_tree, *sbus_multimedia_tree; |
898 | | |
899 | 3 | int i; /*for CRC calculation*/ |
900 | 3 | int offset; |
901 | 3 | int sbus_end_multimedia; |
902 | 3 | int sbus_eth_len; |
903 | 3 | unsigned sbus_crc_calc; |
904 | 3 | uint8_t sbus_attribut; |
905 | 3 | uint8_t sbus_media_cnt; |
906 | 3 | sbus_subrequest *mm_sub_req; |
907 | 3 | wmem_list_frame_t *frame; |
908 | 3 | uint8_t sbus_multimedia_total; |
909 | 3 | uint8_t sbus_multimedia_cnt; |
910 | 3 | uint8_t sbus_multimedia_cmd; |
911 | 3 | uint8_t sbus_multimedia_att; |
912 | 3 | uint8_t sbus_multimedia_bytes; |
913 | 3 | uint8_t sbus_cmd_code; |
914 | 3 | uint8_t sbus_web_size; |
915 | 3 | uint8_t sbus_web_aid; |
916 | 3 | uint8_t sbus_web_seq; |
917 | 3 | uint8_t sbus_rdwr_type; |
918 | 3 | uint8_t sbus_rdwr_sequence; |
919 | 3 | uint8_t sbus_rdwr_block_tlg; |
920 | 3 | uint8_t sbus_rdwr_block_type; |
921 | 3 | uint8_t sbus_rdwr_ack_nak; |
922 | 3 | uint8_t sbus_quint8_helper0; |
923 | 3 | uint16_t sbus_ack_code; |
924 | 3 | uint32_t sbus_rdwr_length; |
925 | 3 | uint32_t sbus_helper; |
926 | 3 | uint32_t sbus_helper1; |
927 | 3 | uint32_t sbus_helper2; |
928 | 3 | char *tmp_string; |
929 | 3 | nstime_t ns; /*we use this for the response time*/ |
930 | | |
931 | | /* Set up conversations*/ |
932 | 3 | conversation_t *conversation; |
933 | 3 | sbus_request_key request_key, *new_request_key; |
934 | 3 | sbus_request_val *request_val; |
935 | | /*sbus_multimedia_requests *multimedia_requests;*/ |
936 | | |
937 | | /* does this look like an sbus pdu? */ |
938 | 3 | if(!is_sbus_pdu(tvb)){ |
939 | 3 | return 0; |
940 | 3 | } |
941 | | |
942 | | /* Make entries in Protocol column and Info column on summary display */ |
943 | 0 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "S-Bus"); |
944 | 0 | col_clear(pinfo->cinfo, COL_INFO); |
945 | |
|
946 | 0 | conversation = find_or_create_conversation(pinfo); |
947 | |
|
948 | 0 | request_key.conversation = conversation->conv_index; |
949 | 0 | request_key.sequence = tvb_get_ntohs(tvb,6); |
950 | |
|
951 | 0 | request_val = (sbus_request_val *) wmem_map_lookup(sbus_request_hash, |
952 | 0 | &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 | 0 | sbus_attribut = tvb_get_uint8(tvb,8); |
957 | 0 | if (request_val && sbus_attribut == SBUS_REQUEST) { |
958 | 0 | if (request_val->req_frame < pinfo->num){ /*a retry; req_frame smaller this frame*/ |
959 | 0 | request_val->retry_count +=1; |
960 | 0 | } |
961 | 0 | else { /*we have a conversation but this is not a retry so we store the packet info*/ |
962 | 0 | request_val->retry_count = 0; |
963 | 0 | request_val->req_frame = pinfo->num; /*store actual frame nr.*/ |
964 | 0 | request_val->req_time = pinfo->abs_ts; |
965 | 0 | } |
966 | 0 | } |
967 | 0 | if (request_val && (sbus_attribut == SBUS_RESPONSE || |
968 | 0 | sbus_attribut == SBUS_ACKNAK)) { /*a response*/ |
969 | 0 | request_val->resp_frame = pinfo->num; /*so store this frame nr.*/ |
970 | 0 | } |
971 | | /* Only allocate a new hash element when it's a request*/ |
972 | 0 | sbus_attribut = tvb_get_uint8(tvb,8); |
973 | |
|
974 | 0 | if ( !request_val && sbus_attribut == 0 ) {/* request telegram */ |
975 | 0 | new_request_key = wmem_new(wmem_file_scope(), sbus_request_key); |
976 | 0 | *new_request_key = request_key; |
977 | |
|
978 | 0 | request_val = wmem_new(wmem_file_scope(), sbus_request_val); |
979 | 0 | request_val->cmd_code=tvb_get_uint8(tvb,10); |
980 | 0 | request_val->retry_count=0; |
981 | 0 | request_val->req_frame = pinfo->num; /*store actual frame nr.*/ |
982 | 0 | request_val->req_time = pinfo->abs_ts; |
983 | 0 | request_val->resp_frame = 0; /*response frame is not known yet*/ |
984 | 0 | request_val->mm_request_count = 0; /*init to 0 in case it is no multi media request*/ |
985 | |
|
986 | 0 | if (((request_val->cmd_code) == SBUS_RD_USER_EEPROM_REGISTER) || |
987 | 0 | ((request_val->cmd_code) == SBUS_WR_USER_EEPROM_REGISTER)) { |
988 | 0 | request_val->count=((tvb_get_uint8(tvb,12))+1); |
989 | 0 | } else if ((request_val->cmd_code) == SBUS_RDWR_MULTI_MEDIAS) { |
990 | 0 | 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 | 0 | request_val->sbus_subrequests = wmem_list_new(wmem_file_scope()); |
993 | | /*add the sub requests to the list*/ |
994 | 0 | request_val->mm_request_count = add_sbus_subrequest(tvb, request_val->sbus_subrequests, 11); |
995 | |
|
996 | 0 | } else { |
997 | 0 | request_val->count=((tvb_get_uint8(tvb,11))+1); |
998 | 0 | } |
999 | | |
1000 | | /*Enter system info or telegram type (for rd/wr block telegrams)*/ |
1001 | 0 | if ((request_val->cmd_code) == SBUS_RD_SYSTEM_INFORMATION) { |
1002 | 0 | request_val->sysinfo=(tvb_get_uint8(tvb,12)); |
1003 | 0 | request_val->block_tlg=0x0; |
1004 | 0 | } else if ((request_val->cmd_code) == SBUS_RD_WR_PCD_BLOCK) { |
1005 | 0 | request_val->sysinfo=0x0; |
1006 | 0 | request_val->block_tlg=(tvb_get_uint8(tvb,12)); |
1007 | 0 | } else { |
1008 | 0 | request_val->sysinfo = 0x0; |
1009 | 0 | request_val->block_tlg = 0x0; |
1010 | 0 | } |
1011 | |
|
1012 | 0 | wmem_map_insert(sbus_request_hash, new_request_key, request_val); |
1013 | 0 | } |
1014 | | /* End of attaching data to hash table*/ |
1015 | |
|
1016 | 0 | offset = 0; |
1017 | |
|
1018 | 0 | switch (sbus_attribut){ |
1019 | 0 | case SBUS_REQUEST: |
1020 | 0 | sbus_cmd_code = tvb_get_uint8(tvb, 10); |
1021 | 0 | switch (sbus_cmd_code){ |
1022 | 0 | 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 | 0 | sbus_web_aid = tvb_get_uint8(tvb, 12); |
1026 | 0 | sbus_web_seq = tvb_get_uint8(tvb, 13); |
1027 | 0 | col_add_fstr(pinfo->cinfo, COL_INFO, |
1028 | 0 | "Web Server Request: %s (Seq No: %d)", |
1029 | 0 | val_to_str_const(sbus_web_aid, |
1030 | 0 | webserver_aid_vals, |
1031 | 0 | "Unknown Request!"), |
1032 | 0 | sbus_web_seq); |
1033 | 0 | break; |
1034 | 0 | case SBUS_RDWR_MULTI_MEDIAS: |
1035 | 0 | col_add_fstr( pinfo->cinfo, COL_INFO, |
1036 | 0 | "Request: Multi media telegram (%d sub requests)", |
1037 | 0 | request_val->mm_request_count); |
1038 | 0 | break; |
1039 | 0 | case SBUS_RD_WR_PCD_BLOCK: |
1040 | 0 | sbus_rdwr_type = tvb_get_uint8(tvb, 12); |
1041 | 0 | col_add_fstr( pinfo->cinfo, COL_INFO, |
1042 | 0 | "Request: %s", |
1043 | 0 | val_to_str_ext_const(sbus_rdwr_type, |
1044 | 0 | &rdwrblock_vals_ext, |
1045 | 0 | "This RD/WR block telegram is not implemented")); |
1046 | | /* Add name of file to be written in case of start of file stream */ |
1047 | 0 | if (sbus_rdwr_type == SBUS_WR_START_OF_STREAM) { |
1048 | 0 | sbus_rdwr_block_type = tvb_get_uint8(tvb, 14); |
1049 | 0 | if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) || |
1050 | 0 | (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) { |
1051 | 0 | sbus_quint8_helper0=0; |
1052 | 0 | for (i=19; i<43; i++) { /*max length is 24 chars*/ |
1053 | | /*find zero-termination of string*/ |
1054 | 0 | if ((tvb_get_uint8(tvb, i)) == 0x00) { |
1055 | 0 | break; |
1056 | 0 | } |
1057 | 0 | sbus_quint8_helper0 += 1; |
1058 | 0 | } |
1059 | 0 | tmp_string = tvb_get_string_enc(pinfo->pool, tvb , 19, |
1060 | 0 | sbus_quint8_helper0, ENC_ASCII); |
1061 | 0 | col_append_fstr(pinfo->cinfo, COL_INFO, |
1062 | 0 | ": (File: %s)", tmp_string); |
1063 | 0 | } |
1064 | 0 | } else if (sbus_rdwr_type == SBUS_RD_BLOCK_START_OF_STREAM) { |
1065 | 0 | sbus_rdwr_block_type = tvb_get_uint8(tvb, 14); |
1066 | 0 | if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) || |
1067 | 0 | (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) { |
1068 | 0 | sbus_quint8_helper0=0; |
1069 | 0 | for (i=15; i<39; i++) { /*max length is 24 chars*/ |
1070 | | /*find zero-termination of string*/ |
1071 | 0 | if ((tvb_get_uint8(tvb, i)) == 0x00) { |
1072 | 0 | break; |
1073 | 0 | } |
1074 | 0 | sbus_quint8_helper0 += 1; |
1075 | 0 | } |
1076 | 0 | tmp_string = tvb_get_string_enc(pinfo->pool, tvb , 15, |
1077 | 0 | sbus_quint8_helper0, ENC_ASCII); |
1078 | 0 | col_append_fstr(pinfo->cinfo, COL_INFO, |
1079 | 0 | ": (File: %s)", tmp_string); |
1080 | 0 | } |
1081 | 0 | } |
1082 | 0 | break; |
1083 | | |
1084 | 0 | default: |
1085 | | /* All other requests */ |
1086 | 0 | col_add_fstr(pinfo->cinfo, COL_INFO, |
1087 | 0 | "Request: %s", |
1088 | 0 | val_to_str_ext_const(sbus_cmd_code, |
1089 | 0 | &sbus_command_vals_ext, |
1090 | 0 | "Unknown Command!")); |
1091 | 0 | break; |
1092 | 0 | } |
1093 | | /*mark retries*/ |
1094 | 0 | if (request_val->retry_count>0) { |
1095 | 0 | col_append_str(pinfo->cinfo, COL_INFO, |
1096 | 0 | " (Retry)"); |
1097 | 0 | } /*no retry number as it is not always correctly calculated*/ |
1098 | 0 | break; |
1099 | | |
1100 | 0 | case SBUS_RESPONSE: |
1101 | | /* Special treatment of web server request |
1102 | | * as this is very helpful to see more information in the packetlist */ |
1103 | 0 | if (request_val && ((request_val->cmd_code) == SBUS_WEB_SERVER_SERIAL_COMM)) { |
1104 | 0 | sbus_web_size = tvb_get_uint8(tvb,9); |
1105 | 0 | sbus_web_aid = tvb_get_uint8(tvb,10); |
1106 | 0 | col_add_fstr(pinfo->cinfo, COL_INFO, |
1107 | 0 | "Response: %s", |
1108 | 0 | val_to_str_const(sbus_web_aid, |
1109 | 0 | webserver_aid_vals, "Unknown Request!")); |
1110 | 0 | if (sbus_web_size > 1) { |
1111 | 0 | sbus_web_seq = tvb_get_uint8(tvb,11); |
1112 | 0 | col_append_fstr(pinfo->cinfo, COL_INFO, |
1113 | 0 | " (Seq No: %d)", |
1114 | 0 | sbus_web_seq); |
1115 | 0 | } |
1116 | 0 | } else if (request_val && ((request_val->cmd_code) == SBUS_RDWR_MULTI_MEDIAS)) { |
1117 | | /* Add some info for multi media response*/ |
1118 | 0 | col_append_fstr(pinfo->cinfo, COL_INFO, |
1119 | 0 | "Response: Multi media (%d responses)", |
1120 | 0 | request_val->mm_request_count); |
1121 | |
|
1122 | 0 | } else if (request_val && ((request_val->cmd_code) == SBUS_RD_WR_PCD_BLOCK)) { |
1123 | | /* Treat the ACK/NAK telgrams in a special way*/ |
1124 | 0 | switch (request_val->block_tlg) { |
1125 | 0 | case SBUS_WR_START_OF_STREAM: |
1126 | 0 | case SBUS_WR_BLOCK_DATA_STREAM: |
1127 | 0 | case SBUS_WR_BLOCK_END_OF_STREAM: |
1128 | 0 | case SBUS_WR_ABORT_BLOCK_STREAM: |
1129 | 0 | case SBUS_WR_BLOCK_DATA_BYTES: |
1130 | 0 | case SBUS_DELETE_BLOCK: |
1131 | 0 | case SBUS_RD_ABORT_BLOCK_STREAM: |
1132 | 0 | sbus_rdwr_ack_nak = tvb_get_uint8(tvb, 10); |
1133 | 0 | col_add_fstr( pinfo->cinfo, COL_INFO, |
1134 | 0 | "Response: %s", |
1135 | 0 | val_to_str_ext_const(sbus_rdwr_ack_nak, |
1136 | 0 | &rdwrblock_sts_ext, |
1137 | 0 | "Unknown response!")); |
1138 | 0 | break; |
1139 | 0 | default: |
1140 | 0 | sbus_rdwr_type = tvb_get_uint8(tvb, 9); |
1141 | 0 | col_add_fstr( pinfo->cinfo, COL_INFO, |
1142 | 0 | "Response: (%d byte)", sbus_rdwr_type); |
1143 | 0 | break; |
1144 | 0 | } |
1145 | |
|
1146 | 0 | } else { |
1147 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "Response"); |
1148 | 0 | } |
1149 | 0 | break; |
1150 | | |
1151 | 0 | case SBUS_ACKNAK: |
1152 | 0 | sbus_ack_code = tvb_get_ntohs(tvb,9); |
1153 | 0 | col_set_str(pinfo->cinfo, COL_INFO, |
1154 | 0 | val_to_str_const(sbus_ack_code, |
1155 | 0 | sbus_ack_nak_vals, |
1156 | 0 | "Unknown NAK response code!")); |
1157 | 0 | break; |
1158 | | |
1159 | 0 | default: |
1160 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "Unknown attribute"); |
1161 | 0 | break; |
1162 | 0 | } |
1163 | | |
1164 | | /* create display subtree for the protocol */ |
1165 | 0 | if (tree) { |
1166 | |
|
1167 | 0 | ti = proto_tree_add_item(tree, proto_sbus, tvb, offset, -1, ENC_NA); |
1168 | 0 | sbus_tree = proto_item_add_subtree(ti, ett_sbus); |
1169 | | |
1170 | | /*Add subtree for Ether-S-Bus header*/ |
1171 | 0 | ethsbus_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, 8, ett_sbus_ether, NULL, "Ether-S-Bus header"); |
1172 | | |
1173 | | /* add an item to the subtree*/ |
1174 | 0 | sbus_eth_len = tvb_get_ntohl(tvb,offset); |
1175 | 0 | proto_tree_add_item(ethsbus_tree, |
1176 | 0 | hf_sbus_length, tvb, offset, 4, ENC_BIG_ENDIAN); |
1177 | 0 | offset += 4; |
1178 | |
|
1179 | 0 | proto_tree_add_item(ethsbus_tree, |
1180 | 0 | hf_sbus_version, tvb, offset, 1, ENC_BIG_ENDIAN); |
1181 | 0 | offset += 1; |
1182 | |
|
1183 | 0 | proto_tree_add_item(ethsbus_tree, |
1184 | 0 | hf_sbus_protocol, tvb, offset, 1, ENC_BIG_ENDIAN); |
1185 | 0 | offset += 1; |
1186 | |
|
1187 | 0 | proto_tree_add_item(ethsbus_tree, |
1188 | 0 | hf_sbus_sequence, tvb, offset, 2, ENC_BIG_ENDIAN); |
1189 | 0 | offset += 2; |
1190 | | |
1191 | | /* Continue adding stuff to the main tree*/ |
1192 | 0 | sbus_attribut = tvb_get_uint8(tvb,offset); |
1193 | 0 | proto_tree_add_item(sbus_tree, |
1194 | 0 | hf_sbus_attribut, tvb, offset, 1, ENC_BIG_ENDIAN); |
1195 | 0 | offset += 1; |
1196 | |
|
1197 | 0 | if (sbus_attribut == SBUS_REQUEST) { |
1198 | 0 | proto_tree_add_item(sbus_tree, |
1199 | 0 | hf_sbus_dest, tvb, offset, 1, ENC_BIG_ENDIAN); |
1200 | 0 | offset += 1; |
1201 | 0 | sbus_cmd_code = tvb_get_uint8(tvb,offset); |
1202 | 0 | proto_tree_add_item(sbus_tree, |
1203 | 0 | hf_sbus_command, tvb, offset, 1, ENC_BIG_ENDIAN); |
1204 | 0 | offset += 1; |
1205 | 0 | if (request_val && request_val->retry_count > 0) {/*this is a retry telegram*/ |
1206 | 0 | expert_add_info(pinfo, sbus_tree, &ei_sbus_retry); |
1207 | 0 | nstime_delta(&ns, &pinfo->abs_ts, &request_val->req_time); |
1208 | 0 | proto_tree_add_time(sbus_tree, hf_sbus_timeout, |
1209 | 0 | tvb, 0, 0, &ns); |
1210 | 0 | proto_tree_add_uint(sbus_tree, hf_sbus_request_in, tvb, 0, 0, |
1211 | 0 | request_val->req_frame); |
1212 | 0 | } |
1213 | 0 | if (request_val && request_val->resp_frame > pinfo->num){ |
1214 | 0 | proto_tree_add_uint(sbus_tree, hf_sbus_response_in, tvb, 0, 0, |
1215 | 0 | request_val->resp_frame); |
1216 | 0 | } |
1217 | 0 | switch (sbus_cmd_code) { |
1218 | | /*Read Counter, Register or Timer*/ |
1219 | 0 | case SBUS_RD_COUNTER: |
1220 | 0 | case SBUS_RD_REGISTER: |
1221 | 0 | case SBUS_RD_TIMER: |
1222 | 0 | offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset); |
1223 | 0 | break; |
1224 | | |
1225 | | /*Read Flag, Input or Output*/ |
1226 | 0 | case SBUS_RD_FLAG: |
1227 | 0 | case SBUS_RD_INPUT: |
1228 | 0 | case SBUS_RD_OUTPUT: |
1229 | 0 | offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset); |
1230 | 0 | break; |
1231 | | |
1232 | | /*Write Register Timer Counter*/ |
1233 | 0 | case SBUS_WR_COUNTER: |
1234 | 0 | case SBUS_WR_REGISTER: |
1235 | 0 | case SBUS_WR_TIMER: |
1236 | 0 | offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset); |
1237 | 0 | break; |
1238 | | |
1239 | | /* Write flags and outputs*/ |
1240 | 0 | case SBUS_WR_FLAG: |
1241 | 0 | case SBUS_WR_OUTPUT: |
1242 | 0 | offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset); |
1243 | 0 | break; |
1244 | | |
1245 | | /* Request: Write Real time clock*/ |
1246 | 0 | case SBUS_WR_RTC: |
1247 | | /*Add subtree for Data*/ |
1248 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1249 | 0 | 8, ett_sbus_data, NULL, "Clock data"); |
1250 | |
|
1251 | 0 | sbus_helper = tvb_get_uint8(tvb, (offset)); /*year-week*/ |
1252 | 0 | sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*week-day*/ |
1253 | 0 | proto_tree_add_uint_format_value(sbusdata_tree, |
1254 | 0 | hf_sbus_week_day, tvb, offset, 2, tvb_get_ntohs(tvb, offset), |
1255 | 0 | "%x, Week day: %x", sbus_helper, sbus_helper1); |
1256 | 0 | offset += 2; |
1257 | 0 | sbus_helper = tvb_get_uint8(tvb, (offset)); /*year*/ |
1258 | 0 | sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*month*/ |
1259 | 0 | sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*day*/ |
1260 | 0 | proto_tree_add_uint_format_value(sbusdata_tree, |
1261 | 0 | hf_sbus_date, tvb, offset, 3, tvb_get_ntoh24(tvb, offset), |
1262 | 0 | "%02x/%02x/%02x", sbus_helper, sbus_helper1, sbus_helper2); |
1263 | 0 | offset += 3; |
1264 | 0 | sbus_helper = tvb_get_uint8(tvb, (offset)); /*hours*/ |
1265 | 0 | sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*minutes*/ |
1266 | 0 | sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*seconds*/ |
1267 | 0 | proto_tree_add_uint_format_value(sbusdata_tree, |
1268 | 0 | hf_sbus_time, tvb, offset, 3, tvb_get_ntoh24(tvb, offset), |
1269 | 0 | "%02x:%02x:%02x", sbus_helper, sbus_helper1, sbus_helper2); |
1270 | 0 | offset += 3; |
1271 | 0 | break; |
1272 | | /* Read/write multi media; multiple requests are transmitted within one single telegram*/ |
1273 | 0 | case SBUS_RDWR_MULTI_MEDIAS: |
1274 | | /*Add subtree for Sub-requests*/ |
1275 | 0 | sbus_multimedia_total = tvb_get_uint8(tvb,offset) + 1; |
1276 | 0 | proto_tree_add_uint(sbus_tree, |
1277 | 0 | hf_sbus_multimedia_length, tvb, offset, 1, sbus_multimedia_total); |
1278 | 0 | offset += 1; |
1279 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1280 | 0 | sbus_multimedia_total, ett_sbus_data, NULL, "Sub requests"); |
1281 | 0 | sbus_end_multimedia = offset + sbus_multimedia_total; |
1282 | | /*Add subtree for each Subrequest*/ |
1283 | 0 | for (i=0; i<64; i++) { /*max number of sub-requests is 64*/ |
1284 | 0 | if(offset >= sbus_end_multimedia){ |
1285 | 0 | break; |
1286 | 0 | } |
1287 | 0 | sbus_multimedia_cnt = tvb_get_uint8(tvb,offset) + 1; |
1288 | 0 | sbus_multimedia_tree = proto_tree_add_subtree_format(sbusdata_tree, tvb, offset, |
1289 | 0 | sbus_multimedia_cnt + 1, ett_sbus_data, NULL, "Request %d", i); |
1290 | 0 | proto_tree_add_item(sbus_multimedia_tree, |
1291 | 0 | hf_sbus_sub_length, tvb, offset, 1, ENC_BIG_ENDIAN); |
1292 | 0 | offset +=1; |
1293 | 0 | sbus_cmd_code = tvb_get_uint8(tvb,offset); |
1294 | 0 | proto_tree_add_item(sbus_multimedia_tree, |
1295 | 0 | hf_sbus_command, tvb, offset, 1, ENC_BIG_ENDIAN); |
1296 | 0 | offset += 1; |
1297 | 0 | offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_multimedia_tree, offset); |
1298 | 0 | } |
1299 | |
|
1300 | 0 | break; |
1301 | | /* Read user memory or program line*/ |
1302 | 0 | case SBUS_RD_USER_MEMORY: |
1303 | 0 | case SBUS_RD_PROGRAM_LINE: |
1304 | 0 | sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1; |
1305 | 0 | proto_tree_add_uint(sbus_tree, |
1306 | 0 | hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt); |
1307 | 0 | offset += 1; |
1308 | 0 | proto_tree_add_item(sbus_tree, |
1309 | 0 | hf_sbus_addr_prog, tvb, offset, 3, ENC_BIG_ENDIAN); |
1310 | 0 | offset += 3; |
1311 | 0 | break; |
1312 | | |
1313 | | /*Write user memory*/ |
1314 | 0 | case SBUS_WR_USER_MEMORY: |
1315 | 0 | sbus_media_cnt = (tvb_get_uint8(tvb,offset)); |
1316 | 0 | sbus_media_cnt = ((sbus_media_cnt - 2)/4); |
1317 | 0 | proto_tree_add_uint(sbus_tree, |
1318 | 0 | hf_sbus_wcount_calculated, tvb, offset, |
1319 | 0 | 1, sbus_media_cnt); |
1320 | 0 | proto_tree_add_item(sbus_tree, |
1321 | 0 | hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN); |
1322 | 0 | offset += 1; |
1323 | 0 | proto_tree_add_item(sbus_tree, |
1324 | 0 | hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN); |
1325 | 0 | offset += 3; |
1326 | | /*Add subtree for Data*/ |
1327 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1328 | 0 | ((sbus_media_cnt) * 4), ett_sbus_data, NULL, "Program lines"); |
1329 | |
|
1330 | 0 | for (i=((sbus_media_cnt)); i>0; i--) { |
1331 | 0 | proto_tree_add_item(sbusdata_tree, |
1332 | 0 | hf_sbus_data_rtc, tvb, offset, |
1333 | 0 | 4, ENC_BIG_ENDIAN); |
1334 | 0 | offset += 4; |
1335 | |
|
1336 | 0 | } |
1337 | 0 | break; |
1338 | | |
1339 | | /* Read byte*/ |
1340 | 0 | case SBUS_RD_BYTE: |
1341 | 0 | sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1; |
1342 | 0 | proto_tree_add_uint(sbus_tree, |
1343 | 0 | hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt); |
1344 | 0 | offset += 1; |
1345 | 0 | proto_tree_add_item(sbus_tree, |
1346 | 0 | hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN); |
1347 | 0 | offset += 3; |
1348 | 0 | break; |
1349 | | |
1350 | | /* Write byte */ |
1351 | 0 | case SBUS_WR_BYTE: |
1352 | 0 | sbus_media_cnt = (tvb_get_uint8(tvb,offset)); |
1353 | 0 | sbus_media_cnt = (sbus_media_cnt - 2); |
1354 | 0 | proto_tree_add_uint(sbus_tree, |
1355 | 0 | hf_sbus_wcount_calculated, tvb, offset, |
1356 | 0 | 1, sbus_media_cnt); |
1357 | 0 | proto_tree_add_item(sbus_tree, |
1358 | 0 | hf_sbus_wcount, tvb, offset, 1, ENC_BIG_ENDIAN); |
1359 | 0 | offset += 1; |
1360 | 0 | proto_tree_add_item(sbus_tree, |
1361 | 0 | hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN); |
1362 | 0 | offset += 3; |
1363 | | /*Add subtree for Data*/ |
1364 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1365 | 0 | ((sbus_media_cnt) * 4), ett_sbus_data, NULL, "Data (bytes)"); |
1366 | |
|
1367 | 0 | for (i=sbus_media_cnt; i>0; i--) { |
1368 | 0 | proto_tree_add_item(sbusdata_tree, |
1369 | 0 | hf_sbus_data_byte, tvb, offset, |
1370 | 0 | 1, ENC_BIG_ENDIAN); |
1371 | 0 | offset += 1; |
1372 | 0 | } |
1373 | 0 | break; |
1374 | | |
1375 | | /*Read EEPROM register*/ |
1376 | 0 | case SBUS_RD_USER_EEPROM_REGISTER: |
1377 | 0 | proto_tree_add_item(sbus_tree, |
1378 | 0 | hf_sbus_command_extension, tvb, offset, 1, ENC_BIG_ENDIAN); |
1379 | 0 | offset += 1; |
1380 | 0 | sbus_media_cnt = (tvb_get_uint8(tvb,offset))+1; |
1381 | 0 | proto_tree_add_uint(sbus_tree, |
1382 | 0 | hf_sbus_rcount, tvb, offset, 1, sbus_media_cnt); |
1383 | 0 | offset += 1; |
1384 | 0 | proto_tree_add_item(sbus_tree, |
1385 | 0 | hf_sbus_addr_eeprom, tvb, offset, 2, ENC_BIG_ENDIAN); |
1386 | 0 | offset += 2; |
1387 | 0 | break; |
1388 | | |
1389 | | /*Request for reading system info*/ |
1390 | | /*Syinfo 05 is not implemented as no serial baud is possible*/ |
1391 | 0 | case SBUS_RD_SYSTEM_INFORMATION: |
1392 | 0 | proto_tree_add_item(sbus_tree, |
1393 | 0 | hf_sbus_sysinfo_nr, tvb, offset, 1, ENC_BIG_ENDIAN); |
1394 | 0 | offset += 1; |
1395 | 0 | proto_tree_add_item(sbus_tree, |
1396 | 0 | hf_sbus_sysinfo_nr, tvb, offset, 1, ENC_BIG_ENDIAN); |
1397 | 0 | offset += 1; |
1398 | 0 | break; |
1399 | | |
1400 | | /* WebServer Request */ |
1401 | 0 | case SBUS_WEB_SERVER_SERIAL_COMM: |
1402 | 0 | sbus_web_size = tvb_get_uint8(tvb,offset); |
1403 | 0 | proto_tree_add_uint(sbus_tree, |
1404 | 0 | hf_sbus_web_size, tvb, offset, |
1405 | 0 | 1, sbus_web_size); |
1406 | 0 | offset += 1; |
1407 | |
|
1408 | 0 | sbus_web_aid = tvb_get_uint8(tvb,offset); |
1409 | 0 | proto_tree_add_uint(sbus_tree, |
1410 | 0 | hf_sbus_web_aid, tvb, offset, |
1411 | 0 | 1, sbus_web_aid); |
1412 | 0 | offset += 1; |
1413 | |
|
1414 | 0 | sbus_web_seq = tvb_get_uint8(tvb,offset); |
1415 | 0 | proto_tree_add_uint(sbus_tree, |
1416 | 0 | hf_sbus_web_seq, tvb, offset, |
1417 | 0 | 1, sbus_web_seq); |
1418 | 0 | offset += 1; |
1419 | |
|
1420 | 0 | if (sbus_web_size > 1) { |
1421 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1422 | 0 | (sbus_web_size - 1), ett_sbus_data, NULL, "Data (bytes)"); |
1423 | |
|
1424 | 0 | for (i=sbus_web_size -1 ; i>0; i--) { |
1425 | 0 | proto_tree_add_item(sbusdata_tree, |
1426 | 0 | hf_sbus_data_byte, tvb, offset, |
1427 | 0 | 1, ENC_BIG_ENDIAN); |
1428 | 0 | offset += 1; |
1429 | 0 | } |
1430 | 0 | } |
1431 | 0 | break; |
1432 | | /* Read/write block request */ |
1433 | 0 | case SBUS_RD_WR_PCD_BLOCK: |
1434 | 0 | if (tvb_get_uint8(tvb,offset) == 0xff){ |
1435 | 0 | sbus_rdwr_length = ((tvb_get_ntohl(tvb,0))-15); |
1436 | 0 | proto_tree_add_uint(sbus_tree, |
1437 | 0 | hf_sbus_rdwr_block_length_ext, tvb, 0, 4, sbus_rdwr_length); |
1438 | 0 | offset += 1; |
1439 | 0 | } else { |
1440 | 0 | sbus_rdwr_length = tvb_get_uint8(tvb,offset); |
1441 | 0 | proto_tree_add_uint(sbus_tree, |
1442 | 0 | hf_sbus_rdwr_block_length, tvb, offset, |
1443 | 0 | 1, sbus_rdwr_length); |
1444 | 0 | offset += 1; |
1445 | 0 | } |
1446 | 0 | sbus_rdwr_type = tvb_get_uint8(tvb,offset); |
1447 | 0 | proto_tree_add_uint(sbus_tree, |
1448 | 0 | hf_sbus_rdwr_telegram_type, tvb, offset, |
1449 | 0 | 1, sbus_rdwr_type); |
1450 | 0 | offset += 1; |
1451 | 0 | switch(sbus_rdwr_type) { |
1452 | 0 | case SBUS_WR_START_OF_STREAM: |
1453 | 0 | sbus_rdwr_block_type = tvb_get_uint8(tvb, 14); |
1454 | 0 | proto_tree_add_item(sbus_tree, |
1455 | 0 | hf_sbus_rdwr_telegram_sequence, tvb, offset, |
1456 | 0 | 1, ENC_BIG_ENDIAN); |
1457 | 0 | offset += 1; |
1458 | 0 | proto_tree_add_item(sbus_tree, |
1459 | 0 | hf_sbus_block_type, tvb, offset, |
1460 | 0 | 1, ENC_BIG_ENDIAN); |
1461 | 0 | offset += 1; |
1462 | | |
1463 | | /* Check for file or block download */ |
1464 | 0 | if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) || |
1465 | 0 | (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) { |
1466 | 0 | proto_tree_add_item(sbus_tree, |
1467 | 0 | hf_sbus_rdwr_block_size, tvb, offset, |
1468 | 0 | 4, ENC_BIG_ENDIAN); |
1469 | 0 | offset += 4; |
1470 | 0 | sbus_quint8_helper0=0; |
1471 | | /*find zero-termination of string*/ |
1472 | 0 | for (i=19; i<43; i++) { /*max length string is 24 char*/ |
1473 | 0 | if ((tvb_get_uint8(tvb, i)) == 0x00) { |
1474 | 0 | break; |
1475 | 0 | } |
1476 | 0 | sbus_quint8_helper0 += 1; |
1477 | 0 | } |
1478 | 0 | tmp_string = tvb_get_string_enc(pinfo->pool, tvb , 19, sbus_quint8_helper0, ENC_ASCII); |
1479 | 0 | proto_tree_add_string(sbus_tree, |
1480 | 0 | hf_sbus_rdwr_file_name, tvb, offset, |
1481 | 0 | sbus_quint8_helper0, tmp_string); |
1482 | 0 | offset += sbus_quint8_helper0; |
1483 | | /*do not display a field for block data (skip)*/ |
1484 | 0 | offset += (sbus_rdwr_length-6-sbus_quint8_helper0); |
1485 | 0 | } else { /* block write telegram, no file write*/ |
1486 | 0 | proto_tree_add_item(sbus_tree, |
1487 | 0 | hf_sbus_block_nr, tvb, offset, |
1488 | 0 | 2, ENC_BIG_ENDIAN); |
1489 | 0 | offset += 2; |
1490 | 0 | proto_tree_add_item(sbus_tree, |
1491 | 0 | hf_sbus_rdwr_block_size, tvb, offset, |
1492 | 0 | 4, ENC_BIG_ENDIAN); |
1493 | 0 | offset += 4; |
1494 | | /*do not display a field for block data (skip)*/ |
1495 | 0 | offset += (sbus_rdwr_length-8); |
1496 | 0 | } |
1497 | 0 | break; |
1498 | 0 | case SBUS_WR_BLOCK_DATA_STREAM: |
1499 | 0 | sbus_rdwr_sequence = tvb_get_uint8(tvb,offset); |
1500 | 0 | proto_tree_add_uint(sbus_tree, |
1501 | 0 | hf_sbus_rdwr_telegram_sequence, tvb, offset, |
1502 | 0 | 1, sbus_rdwr_sequence); |
1503 | 0 | offset += 1; |
1504 | | /*do not display a field for block data (skip)*/ |
1505 | 0 | offset += (sbus_rdwr_length-1); |
1506 | 0 | break; |
1507 | 0 | case SBUS_WR_BLOCK_END_OF_STREAM: |
1508 | 0 | sbus_rdwr_sequence = tvb_get_uint8(tvb,offset); |
1509 | 0 | proto_tree_add_uint(sbus_tree, |
1510 | 0 | hf_sbus_rdwr_telegram_sequence, tvb, offset, |
1511 | 0 | 1, sbus_rdwr_sequence); |
1512 | 0 | offset += 1; |
1513 | | /*do not display a field for block data (skip it)*/ |
1514 | 0 | offset += (sbus_rdwr_length-5); |
1515 | | /*do not display a field for block CRC (skip it)*/ |
1516 | 0 | offset += 4; |
1517 | 0 | break; |
1518 | 0 | case SBUS_WR_ABORT_BLOCK_STREAM: |
1519 | 0 | case SBUS_RD_ABORT_BLOCK_STREAM: |
1520 | 0 | break; |
1521 | 0 | case SBUS_WR_BLOCK_DATA_BYTES: |
1522 | 0 | sbus_rdwr_block_type = tvb_get_uint8(tvb, 14); |
1523 | 0 | proto_tree_add_item(sbus_tree, |
1524 | 0 | hf_sbus_block_type, tvb, offset, |
1525 | 0 | 1, ENC_BIG_ENDIAN); |
1526 | 0 | offset += 1; |
1527 | | |
1528 | | /* Check for file or block download */ |
1529 | 0 | if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) || |
1530 | 0 | (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) { |
1531 | 0 | proto_tree_add_item(sbus_tree, |
1532 | 0 | hf_sbus_rdwr_block_addr, tvb, offset, |
1533 | 0 | 4, ENC_BIG_ENDIAN); |
1534 | 0 | offset += 4; |
1535 | 0 | sbus_quint8_helper0=0; |
1536 | | /*find zero-termination of string*/ |
1537 | 0 | for (i=19; i<43; i++) { /*max length string is 24 char*/ |
1538 | 0 | if ((tvb_get_uint8(tvb, i)) == 0x00) { |
1539 | 0 | break; |
1540 | 0 | } |
1541 | 0 | sbus_quint8_helper0 += 1; |
1542 | 0 | } |
1543 | 0 | tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 19, sbus_quint8_helper0, ENC_ASCII); |
1544 | 0 | proto_tree_add_string(sbus_tree, |
1545 | 0 | hf_sbus_rdwr_file_name, tvb, offset, |
1546 | 0 | sbus_quint8_helper0, tmp_string); |
1547 | 0 | offset += sbus_quint8_helper0; |
1548 | | /*do not display a field for block data (skip)*/ |
1549 | 0 | offset += (sbus_rdwr_length-6-sbus_quint8_helper0); |
1550 | 0 | } else { /* block write telegram, no file write*/ |
1551 | 0 | proto_tree_add_item(sbus_tree, |
1552 | 0 | hf_sbus_block_nr, tvb, offset, |
1553 | 0 | 2, ENC_BIG_ENDIAN); |
1554 | 0 | offset += 2; |
1555 | 0 | proto_tree_add_item(sbus_tree, |
1556 | 0 | hf_sbus_rdwr_block_addr, tvb, offset, |
1557 | 0 | 4, ENC_BIG_ENDIAN); |
1558 | 0 | offset += 4; |
1559 | | /*do not display a field for block data (skip)*/ |
1560 | 0 | offset += (sbus_rdwr_length-8); |
1561 | 0 | } |
1562 | 0 | break; |
1563 | 0 | case SBUS_RD_BLOCK_START_OF_STREAM: |
1564 | 0 | sbus_rdwr_block_type = tvb_get_uint8(tvb, 14); |
1565 | 0 | proto_tree_add_item(sbus_tree, |
1566 | 0 | hf_sbus_rdwr_telegram_sequence, tvb, offset, |
1567 | 0 | 1, ENC_BIG_ENDIAN); |
1568 | 0 | offset += 1; |
1569 | 0 | proto_tree_add_item(sbus_tree, |
1570 | 0 | hf_sbus_block_type, tvb, offset, |
1571 | 0 | 1, ENC_BIG_ENDIAN); |
1572 | 0 | offset += 1; |
1573 | | |
1574 | | /* Check for file or block download */ |
1575 | 0 | if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) || |
1576 | 0 | (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) { |
1577 | 0 | sbus_quint8_helper0=0; |
1578 | | /*find zero-termination of string*/ |
1579 | 0 | for (i=14; i<38; i++) { /*max length string is 24 char*/ |
1580 | 0 | if ((tvb_get_uint8(tvb, i)) == 0x00) { |
1581 | 0 | break; |
1582 | 0 | } |
1583 | 0 | sbus_quint8_helper0 += 1; |
1584 | 0 | } |
1585 | 0 | tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 14, sbus_quint8_helper0, ENC_ASCII); |
1586 | 0 | proto_tree_add_string(sbus_tree, |
1587 | 0 | hf_sbus_rdwr_file_name, tvb, offset, |
1588 | 0 | sbus_quint8_helper0, tmp_string); |
1589 | 0 | offset += sbus_quint8_helper0; |
1590 | 0 | } else { /* block write telegram, no file write*/ |
1591 | 0 | proto_tree_add_item(sbus_tree, |
1592 | 0 | hf_sbus_block_nr, tvb, offset, |
1593 | 0 | 2, ENC_BIG_ENDIAN); |
1594 | 0 | offset += 2; |
1595 | 0 | } |
1596 | 0 | break; |
1597 | 0 | case SBUS_RD_BLOCK_DATA_STREAM: |
1598 | 0 | proto_tree_add_item(sbus_tree, |
1599 | 0 | hf_sbus_rdwr_telegram_sequence, tvb, offset, |
1600 | 0 | 1, ENC_BIG_ENDIAN); |
1601 | 0 | offset += 1; |
1602 | 0 | break; |
1603 | 0 | case SBUS_RD_BLOCK_DATA_BYTES: |
1604 | 0 | sbus_rdwr_block_type = tvb_get_uint8(tvb, 13); |
1605 | 0 | proto_tree_add_item(sbus_tree, |
1606 | 0 | hf_sbus_block_type, tvb, offset, |
1607 | 0 | 1, ENC_BIG_ENDIAN); |
1608 | 0 | offset += 1; |
1609 | | /* Check for file or block read */ |
1610 | 0 | if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) || |
1611 | 0 | (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) { |
1612 | | /*reading from a file*/ |
1613 | 0 | proto_tree_add_item(sbus_tree, |
1614 | 0 | hf_sbus_rdwr_block_addr, tvb, offset, |
1615 | 0 | 4, ENC_BIG_ENDIAN); |
1616 | 0 | offset += 4; |
1617 | 0 | proto_tree_add_item(sbus_tree, |
1618 | 0 | hf_sbus_rdwr_block_size, tvb, offset, |
1619 | 0 | 4, ENC_BIG_ENDIAN); |
1620 | 0 | offset += 4; |
1621 | 0 | sbus_quint8_helper0=0; |
1622 | | /*find zero-termination of string*/ |
1623 | 0 | for (i=22; i<46; i++) { /*max length string is 24 char*/ |
1624 | 0 | if ((tvb_get_uint8(tvb, i)) == 0x00) { |
1625 | 0 | break; |
1626 | 0 | } |
1627 | 0 | sbus_quint8_helper0 += 1; |
1628 | 0 | } |
1629 | 0 | tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 22, sbus_quint8_helper0, ENC_ASCII); |
1630 | 0 | proto_tree_add_string(sbus_tree, |
1631 | 0 | hf_sbus_rdwr_file_name, tvb, offset, |
1632 | 0 | sbus_quint8_helper0, tmp_string); |
1633 | 0 | offset += sbus_quint8_helper0 + 1; |
1634 | 0 | } else { /* block read telegram, no file read*/ |
1635 | 0 | proto_tree_add_item(sbus_tree, |
1636 | 0 | hf_sbus_block_nr, tvb, offset, |
1637 | 0 | 2, ENC_BIG_ENDIAN); |
1638 | 0 | offset += 2; |
1639 | 0 | proto_tree_add_item(sbus_tree, |
1640 | 0 | hf_sbus_rdwr_block_addr, tvb, offset, |
1641 | 0 | 4, ENC_BIG_ENDIAN); |
1642 | 0 | offset += 4; |
1643 | 0 | proto_tree_add_item(sbus_tree, |
1644 | 0 | hf_sbus_rdwr_block_size, tvb, offset, |
1645 | 0 | 4, ENC_BIG_ENDIAN); |
1646 | 0 | offset += 4; |
1647 | 0 | } |
1648 | 0 | break; |
1649 | 0 | case SBUS_DELETE_BLOCK: |
1650 | 0 | case SBUS_GET_BLOCK_SIZE: |
1651 | 0 | sbus_rdwr_block_type = tvb_get_uint8(tvb, 13); |
1652 | 0 | proto_tree_add_item(sbus_tree, |
1653 | 0 | hf_sbus_block_type, tvb, offset, |
1654 | 0 | 1, ENC_BIG_ENDIAN); |
1655 | 0 | offset += 1; |
1656 | | /* Check for file or block deletion */ |
1657 | 0 | if ((sbus_rdwr_block_type == SBUS_RD_WR_CONFIGURATION_FILE) || |
1658 | 0 | (sbus_rdwr_block_type == SBUS_RD_WR_PROGRAM_BLOCK_FILE)) { |
1659 | | /*delete a file*/ |
1660 | 0 | sbus_quint8_helper0=0; |
1661 | | /*find zero-termination of string*/ |
1662 | 0 | for (i=14; i<38; i++) { /*max length string is 24 char*/ |
1663 | 0 | if ((tvb_get_uint8(tvb, i)) == 0x00) { |
1664 | 0 | break; |
1665 | 0 | } |
1666 | 0 | sbus_quint8_helper0 += 1; |
1667 | 0 | } |
1668 | 0 | tmp_string = tvb_get_string_enc(pinfo->pool, tvb, 14, sbus_quint8_helper0, ENC_ASCII); |
1669 | 0 | proto_tree_add_string(sbus_tree, |
1670 | 0 | hf_sbus_rdwr_file_name, tvb, offset, |
1671 | 0 | sbus_quint8_helper0, tmp_string); |
1672 | 0 | offset += sbus_quint8_helper0 + 1; |
1673 | 0 | } else { /* delete a block*/ |
1674 | 0 | proto_tree_add_item(sbus_tree, |
1675 | 0 | hf_sbus_block_nr, tvb, offset, |
1676 | 0 | 2, ENC_BIG_ENDIAN); |
1677 | 0 | offset += 2; |
1678 | 0 | } |
1679 | 0 | break; |
1680 | 0 | case SBUS_GET_PROGRAM_BLOCK_LIST: |
1681 | 0 | proto_tree_add_item(sbus_tree, |
1682 | 0 | hf_sbus_rdwr_list_type, tvb, offset, |
1683 | 0 | 1, ENC_BIG_ENDIAN); |
1684 | 0 | offset += 1; |
1685 | 0 | break; |
1686 | | |
1687 | 0 | default: |
1688 | 0 | break; |
1689 | 0 | } |
1690 | | |
1691 | 0 | break; |
1692 | 0 | case SBUS_RD_DATA_BLOCK: |
1693 | 0 | offset = add_media_access_to_tree(sbus_cmd_code, tvb, sbus_tree, offset); |
1694 | |
|
1695 | 0 | break; |
1696 | | |
1697 | | /*Inform that command was not dissected and add remaining length*/ |
1698 | 0 | default: |
1699 | 0 | if (sbus_eth_len > 13) { /*13 bytes is the minimal length of a request telegram...*/ |
1700 | 0 | sbus_helper = sbus_eth_len - (offset + 2); |
1701 | 0 | proto_tree_add_expert(sbus_tree, pinfo, &ei_sbus_telegram_not_implemented, tvb, offset, sbus_helper); |
1702 | 0 | offset = offset + sbus_helper; |
1703 | 0 | } |
1704 | 0 | break; |
1705 | 0 | } |
1706 | 0 | } |
1707 | | |
1708 | | /* Response dissection*/ |
1709 | 0 | if (sbus_attribut == SBUS_RESPONSE && request_val) { |
1710 | | /*add response time*/ |
1711 | 0 | nstime_delta(&ns, &pinfo->abs_ts, &request_val->req_time); |
1712 | 0 | proto_tree_add_time(sbus_tree, hf_sbus_response_time, |
1713 | 0 | tvb, 0, 0, &ns); |
1714 | | /*add reference to request telegram*/ |
1715 | 0 | proto_tree_add_uint(sbus_tree, hf_sbus_response_to, tvb, 0, 0, |
1716 | 0 | request_val->req_frame); |
1717 | |
|
1718 | 0 | switch (request_val->cmd_code) { |
1719 | | /* Response: 32 bit values*/ |
1720 | 0 | case SBUS_RD_COUNTER: |
1721 | 0 | case SBUS_RD_REGISTER: |
1722 | 0 | case SBUS_RD_TIMER: |
1723 | 0 | case SBUS_RD_USER_MEMORY: |
1724 | 0 | case SBUS_RD_PROGRAM_LINE: |
1725 | 0 | case SBUS_RD_USER_EEPROM_REGISTER: |
1726 | 0 | case SBUS_RD_DATA_BLOCK: |
1727 | | /*Add subtree for Data*/ |
1728 | 0 | offset = add_media_response_to_tree(request_val->cmd_code, request_val->count, tvb, sbus_tree, offset); |
1729 | 0 | break; |
1730 | | |
1731 | | /* Response: PCD Display register*/ |
1732 | 0 | case SBUS_RD_DISPLAY_REGISTER: |
1733 | 0 | proto_tree_add_item(sbus_tree, |
1734 | 0 | hf_sbus_display_register, tvb, offset, 4, ENC_BIG_ENDIAN); |
1735 | 0 | offset += 4; |
1736 | 0 | break; |
1737 | | |
1738 | | /* Add binary data I, O, F*/ |
1739 | 0 | case SBUS_RD_FLAG: |
1740 | 0 | case SBUS_RD_INPUT: |
1741 | 0 | case SBUS_RD_OUTPUT: |
1742 | | /*Add subtree for Data*/ |
1743 | 0 | offset = add_media_response_to_tree(request_val->cmd_code, request_val->count, tvb, sbus_tree, offset); |
1744 | 0 | break; |
1745 | | |
1746 | | /* Response: Real time clock value*/ |
1747 | 0 | case SBUS_RD_RTC: |
1748 | | /*Add subtree for Data*/ |
1749 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1750 | 0 | 8, ett_sbus_data, NULL, "Clock data"); |
1751 | |
|
1752 | 0 | sbus_helper = tvb_get_uint8(tvb, (offset)); /*year-week*/ |
1753 | 0 | sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*week-day*/ |
1754 | 0 | proto_tree_add_uint_format_value(sbusdata_tree, |
1755 | 0 | hf_sbus_week_day, tvb, offset, 2, tvb_get_ntohs(tvb, offset), |
1756 | 0 | "%x, Week day: %x", sbus_helper, sbus_helper1); |
1757 | 0 | offset += 2; |
1758 | 0 | sbus_helper = tvb_get_uint8(tvb, (offset)); /*year*/ |
1759 | 0 | sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*month*/ |
1760 | 0 | sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*day*/ |
1761 | 0 | proto_tree_add_uint_format_value(sbusdata_tree, |
1762 | 0 | hf_sbus_date, tvb, offset, 3, tvb_get_ntoh24(tvb, offset), |
1763 | 0 | "%02x/%02x/%02x", sbus_helper, sbus_helper1, sbus_helper2); |
1764 | 0 | offset += 3; |
1765 | 0 | sbus_helper = tvb_get_uint8(tvb, (offset)); /*hours*/ |
1766 | 0 | sbus_helper1 = tvb_get_uint8(tvb, (offset +1)); /*minutes*/ |
1767 | 0 | sbus_helper2 = tvb_get_uint8(tvb, (offset +2)); /*seconds*/ |
1768 | 0 | proto_tree_add_uint_format_value(sbusdata_tree, |
1769 | 0 | hf_sbus_time, tvb, offset, 3, tvb_get_ntoh24(tvb, offset), |
1770 | 0 | "%02x:%02x:%02x", sbus_helper, sbus_helper1, sbus_helper2); |
1771 | 0 | offset += 3; |
1772 | 0 | break; |
1773 | | |
1774 | 0 | case SBUS_RDWR_MULTI_MEDIAS: |
1775 | | /*Add subtree for Subrequests*/ |
1776 | 0 | sbus_multimedia_total = tvb_get_uint8(tvb,offset); |
1777 | 0 | proto_tree_add_uint(sbus_tree, |
1778 | 0 | hf_sbus_multimedia_length, tvb, offset, 1, sbus_multimedia_total); |
1779 | 0 | offset += 1; |
1780 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1781 | 0 | sbus_multimedia_total, ett_sbus_data, NULL, "Sub responses"); |
1782 | 0 | sbus_end_multimedia = offset + sbus_multimedia_total; |
1783 | 0 | i = 0; |
1784 | | /* Start at front of list and cycle through possible sub-requests, |
1785 | | until all bytes or all requests are processed */ |
1786 | 0 | frame = wmem_list_head(request_val->sbus_subrequests); |
1787 | 0 | while (frame && (offset < sbus_end_multimedia)) { |
1788 | 0 | mm_sub_req = (sbus_subrequest *)wmem_list_frame_data(frame); |
1789 | 0 | sbus_multimedia_cmd = mm_sub_req->cmd_code; |
1790 | 0 | sbus_multimedia_cnt = mm_sub_req->count; |
1791 | | |
1792 | | /*get the attribute of the sub-response (1: response, 2: ACK/NACK)*/ |
1793 | 0 | sbus_multimedia_att = tvb_get_uint8(tvb,offset + 1) ; |
1794 | |
|
1795 | 0 | if (sbus_multimedia_att == SBUS_ACKNAK) { |
1796 | 0 | sbus_multimedia_tree = proto_tree_add_subtree_format(sbusdata_tree, tvb, offset, |
1797 | 0 | 4, ett_sbus_data, NULL, "Response %d", i); |
1798 | 0 | proto_tree_add_item(sbus_multimedia_tree, |
1799 | 0 | hf_sbus_sub_length, tvb, offset, 1, ENC_BIG_ENDIAN); |
1800 | 0 | offset +=1; |
1801 | 0 | proto_tree_add_item(sbus_multimedia_tree, |
1802 | 0 | hf_sbus_attribut, tvb, offset, 1, ENC_BIG_ENDIAN); |
1803 | 0 | offset +=1; |
1804 | 0 | hi = proto_tree_add_item(sbus_multimedia_tree, |
1805 | 0 | hf_sbus_acknackcode, tvb, offset, 2, ENC_BIG_ENDIAN); |
1806 | 0 | if (tvb_get_uint8(tvb, (offset+1)) > 0) { |
1807 | 0 | expert_add_info(pinfo, hi, &ei_sbus_telegram_not_acked); |
1808 | 0 | } |
1809 | 0 | offset += 2; |
1810 | |
|
1811 | 0 | } else { /*response containing data*/ |
1812 | 0 | sbus_multimedia_bytes = get_response_length(sbus_multimedia_cmd, sbus_multimedia_cnt); |
1813 | 0 | sbus_multimedia_tree = proto_tree_add_subtree_format(sbusdata_tree, tvb, offset, |
1814 | 0 | sbus_multimedia_bytes + 2, ett_sbus_data, NULL, "Response %d", i); |
1815 | 0 | proto_tree_add_item(sbus_multimedia_tree, |
1816 | 0 | hf_sbus_sub_length, tvb, offset, 1, ENC_BIG_ENDIAN); |
1817 | 0 | offset +=1; |
1818 | 0 | proto_tree_add_item(sbus_multimedia_tree, |
1819 | 0 | hf_sbus_attribut, tvb, offset, 1, ENC_BIG_ENDIAN); |
1820 | 0 | offset +=1; |
1821 | |
|
1822 | 0 | add_media_response_to_tree(sbus_multimedia_cmd, sbus_multimedia_cnt, tvb, sbus_multimedia_tree, offset); |
1823 | 0 | offset +=sbus_multimedia_bytes ; |
1824 | 0 | } |
1825 | | |
1826 | | /* After processing this sub request, proceed to the next */ |
1827 | 0 | frame = wmem_list_frame_next(frame); |
1828 | 0 | i++; |
1829 | 0 | } |
1830 | |
|
1831 | 0 | break; |
1832 | | |
1833 | | /* Response: CPU status, the command codes 14..1B are concerned*/ |
1834 | 0 | case SBUS_RD_PCD_STATUS_CPU0: |
1835 | 0 | case SBUS_RD_PCD_STATUS_CPU1: |
1836 | 0 | case SBUS_RD_PCD_STATUS_CPU2: |
1837 | 0 | case SBUS_RD_PCD_STATUS_CPU3: |
1838 | 0 | case SBUS_RD_PCD_STATUS_CPU4: |
1839 | 0 | case SBUS_RD_PCD_STATUS_CPU5: |
1840 | 0 | case SBUS_RD_PCD_STATUS_CPU6: |
1841 | 0 | case SBUS_RD_PCD_STATUS_OWN: |
1842 | 0 | proto_tree_add_item(sbus_tree, |
1843 | 0 | hf_sbus_cpu_status, tvb, offset, 1, ENC_BIG_ENDIAN); |
1844 | 0 | offset += 1; |
1845 | 0 | break; |
1846 | | |
1847 | | /* Response: Station address*/ |
1848 | 0 | case SBUS_RD_SBUS_STN_NBR: |
1849 | 0 | proto_tree_add_item(sbus_tree, |
1850 | 0 | hf_sbus_address, tvb, offset, 1, ENC_BIG_ENDIAN); |
1851 | 0 | offset += 1; |
1852 | 0 | break; |
1853 | | |
1854 | | /* Response: Firmware version */ |
1855 | 0 | case SBUS_RD_PROGRAM_VERSION: |
1856 | | /*PCD type*/ |
1857 | 0 | proto_tree_add_item(sbus_tree, hf_sbus_cpu_type, tvb, offset, 5, ENC_ASCII); |
1858 | 0 | offset += 5; |
1859 | | /*FW version*/ |
1860 | 0 | proto_tree_add_item(sbus_tree, hf_sbus_fw_version, tvb, offset, 3, ENC_ASCII); |
1861 | 0 | offset += 4; |
1862 | 0 | break; |
1863 | | |
1864 | | /* Response for Status Flags*/ |
1865 | 0 | case SBUS_RD_STATUSFLAG_ACCU: |
1866 | | /*Add subtree for Data*/ |
1867 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1868 | 0 | 1, ett_sbus_data, NULL, "ACCU and arithmetic status"); |
1869 | |
|
1870 | 0 | proto_tree_add_item(sbusdata_tree, hf_sbus_flags_accu, |
1871 | 0 | tvb, offset, 1, ENC_BIG_ENDIAN); |
1872 | 0 | proto_tree_add_item(sbusdata_tree, hf_sbus_flags_error, |
1873 | 0 | tvb, offset, 1, ENC_BIG_ENDIAN); |
1874 | 0 | proto_tree_add_item(sbusdata_tree, hf_sbus_flags_negative, |
1875 | 0 | tvb, offset, 1, ENC_BIG_ENDIAN); |
1876 | 0 | proto_tree_add_item(sbusdata_tree, hf_sbus_flags_zero, |
1877 | 0 | tvb, offset, 1, ENC_BIG_ENDIAN); |
1878 | 0 | offset +=1; |
1879 | 0 | break; |
1880 | | |
1881 | | /* Response for Read byte */ |
1882 | 0 | case SBUS_RD_BYTE: |
1883 | | /*Add subtree for Data*/ |
1884 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1885 | 0 | (request_val->count), ett_sbus_data, NULL, "Data (bytes)"); |
1886 | |
|
1887 | 0 | for (i=(request_val->count); i>0; i--) { |
1888 | 0 | proto_tree_add_item(sbusdata_tree, |
1889 | 0 | hf_sbus_data_byte, tvb, offset, |
1890 | 0 | 1, ENC_BIG_ENDIAN); |
1891 | 0 | offset += 1; |
1892 | 0 | } |
1893 | 0 | break; |
1894 | | |
1895 | | /* Response for Read Index register */ |
1896 | 0 | case SBUS_RD_INDEX_REGISTER: |
1897 | | /*Add subtree for Data*/ |
1898 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1899 | 0 | 2, ett_sbus_data, NULL, "Data (hex bytes)"); |
1900 | |
|
1901 | 0 | for (i=0; i<2; i++) { /*2 bytes*/ |
1902 | 0 | proto_tree_add_item(sbusdata_tree, |
1903 | 0 | hf_sbus_data_byte_hex, tvb, offset, |
1904 | 0 | 1, ENC_BIG_ENDIAN); |
1905 | 0 | offset += 1; |
1906 | 0 | } |
1907 | 0 | break; |
1908 | | |
1909 | | /* Response: Instruction pointer*/ |
1910 | 0 | case SBUS_RD_INSTRUCTION_POINTER: |
1911 | 0 | proto_tree_add_item(sbus_tree, |
1912 | 0 | hf_sbus_addr_prog, tvb, offset, 3, ENC_BIG_ENDIAN); |
1913 | 0 | offset += 3; |
1914 | 0 | break; |
1915 | | |
1916 | | /*Response for Find History*/ |
1917 | 0 | case SBUS_FIND_HISTORY: |
1918 | 0 | proto_tree_add_item(sbus_tree, |
1919 | 0 | hf_sbus_addr_68k, tvb, offset, 3, ENC_BIG_ENDIAN); |
1920 | 0 | offset += 3; |
1921 | 0 | proto_tree_add_item(sbus_tree, |
1922 | 0 | hf_sbus_nbr_elements, tvb, offset, 2, ENC_BIG_ENDIAN); |
1923 | 0 | offset += 2; |
1924 | 0 | break; |
1925 | | |
1926 | | /* Response: Read current block*/ |
1927 | 0 | case SBUS_RD_CURRENT_BLOCK: |
1928 | 0 | proto_tree_add_item(sbus_tree, |
1929 | 0 | hf_sbus_block_type, tvb, offset, 1, ENC_BIG_ENDIAN); |
1930 | 0 | offset += 1; |
1931 | 0 | proto_tree_add_item(sbus_tree, |
1932 | 0 | hf_sbus_block_nr, tvb, offset, 2, ENC_BIG_ENDIAN); |
1933 | 0 | offset += 2; |
1934 | 0 | break; |
1935 | | |
1936 | | /* Response: Read system information (without interpretation of module info)*/ |
1937 | 0 | case SBUS_RD_SYSTEM_INFORMATION: |
1938 | 0 | if (request_val->sysinfo == 0x00){ /*sysinfo 0*/ |
1939 | 0 | offset += 1; /* this byte is always 0x01*/ |
1940 | | /*Add subtree for Data*/ |
1941 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1942 | 0 | 1, ett_sbus_data, NULL, "System info"); |
1943 | |
|
1944 | 0 | proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_1, |
1945 | 0 | tvb, offset, 1, ENC_BIG_ENDIAN); |
1946 | 0 | proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_2, |
1947 | 0 | tvb, offset, 1, ENC_BIG_ENDIAN); |
1948 | 0 | proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_3, |
1949 | 0 | tvb, offset, 1, ENC_BIG_ENDIAN); |
1950 | 0 | proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_4, |
1951 | 0 | tvb, offset, 1, ENC_BIG_ENDIAN); |
1952 | 0 | proto_tree_add_item(sbusdata_tree, hf_sbus_sysinfo0_5, |
1953 | 0 | tvb, offset, 1, ENC_BIG_ENDIAN); |
1954 | 0 | offset += 1; |
1955 | 0 | } else { |
1956 | | /*do not dissect all system info telegrams as there is no need*/ |
1957 | 0 | offset = (tvb_get_uint8(tvb,9) + 10); |
1958 | 0 | } |
1959 | 0 | break; |
1960 | | |
1961 | | /* Response: Webserver request */ |
1962 | 0 | case SBUS_WEB_SERVER_SERIAL_COMM: |
1963 | 0 | sbus_web_size = tvb_get_uint8(tvb,offset); |
1964 | 0 | proto_tree_add_uint(sbus_tree, |
1965 | 0 | hf_sbus_web_size, tvb, offset, |
1966 | 0 | 1, sbus_web_size); |
1967 | 0 | offset += 1; |
1968 | |
|
1969 | 0 | sbus_web_aid = tvb_get_uint8(tvb,offset); |
1970 | 0 | proto_tree_add_uint(sbus_tree, |
1971 | 0 | hf_sbus_web_aid, tvb, offset, |
1972 | 0 | 1, sbus_web_aid); |
1973 | 0 | offset += 1; |
1974 | |
|
1975 | 0 | if (sbus_web_size > 1) { |
1976 | 0 | sbus_web_seq = tvb_get_uint8(tvb,offset); |
1977 | 0 | proto_tree_add_uint(sbus_tree, |
1978 | 0 | hf_sbus_web_seq, tvb, offset, |
1979 | 0 | 1, sbus_web_seq); |
1980 | 0 | offset += 1; |
1981 | |
|
1982 | 0 | sbusdata_tree = proto_tree_add_subtree(sbus_tree, tvb, offset, |
1983 | 0 | (sbus_web_size - 2), ett_sbus_data, NULL, "Data (bytes)"); |
1984 | |
|
1985 | 0 | for (i=sbus_web_size - 2; i>0; i--) { |
1986 | 0 | proto_tree_add_item(sbusdata_tree, |
1987 | 0 | hf_sbus_data_byte, tvb, offset, |
1988 | 0 | 1, ENC_BIG_ENDIAN); |
1989 | 0 | offset += 1; |
1990 | 0 | } |
1991 | 0 | } |
1992 | 0 | break; |
1993 | | /* Response: Read/Write block data */ |
1994 | 0 | case SBUS_RD_WR_PCD_BLOCK: |
1995 | 0 | sbus_rdwr_block_tlg = request_val->block_tlg; |
1996 | 0 | sbus_rdwr_length = tvb_get_uint8(tvb,offset); |
1997 | 0 | proto_tree_add_uint(sbus_tree, |
1998 | 0 | hf_sbus_rdwr_block_length, tvb, offset, |
1999 | 0 | 1, sbus_rdwr_length); |
2000 | 0 | offset += 1; |
2001 | 0 | hi = proto_tree_add_item(sbus_tree, |
2002 | 0 | hf_sbus_rdwr_acknakcode, tvb, offset, |
2003 | 0 | 1, ENC_BIG_ENDIAN); |
2004 | 0 | if ((tvb_get_uint8(tvb, offset) >= SBUS_RD_WR_NAK)&& |
2005 | 0 | (tvb_get_uint8(tvb, offset) <= SBUS_RD_WR_NAK_INVALID_SIZE)) { |
2006 | 0 | expert_add_info(pinfo, hi, &ei_sbus_telegram_not_acked); |
2007 | 0 | } |
2008 | 0 | offset += 1; |
2009 | 0 | switch(sbus_rdwr_block_tlg) { |
2010 | 0 | case SBUS_WR_START_OF_STREAM: |
2011 | 0 | case SBUS_WR_BLOCK_DATA_STREAM: |
2012 | 0 | case SBUS_WR_BLOCK_END_OF_STREAM: |
2013 | 0 | proto_tree_add_item(sbus_tree, |
2014 | 0 | hf_sbus_rdwr_telegram_sequence, tvb, offset, |
2015 | 0 | 1, ENC_BIG_ENDIAN); |
2016 | 0 | offset += 1; |
2017 | 0 | break; |
2018 | 0 | case SBUS_WR_ABORT_BLOCK_STREAM: |
2019 | 0 | case SBUS_RD_ABORT_BLOCK_STREAM: |
2020 | 0 | case SBUS_WR_BLOCK_DATA_BYTES: |
2021 | 0 | case SBUS_DELETE_BLOCK: |
2022 | 0 | break; |
2023 | 0 | case SBUS_RD_BLOCK_START_OF_STREAM: |
2024 | 0 | proto_tree_add_item(sbus_tree, |
2025 | 0 | hf_sbus_rdwr_telegram_sequence, tvb, offset, |
2026 | 0 | 1, ENC_BIG_ENDIAN); |
2027 | 0 | offset += 1; |
2028 | 0 | proto_tree_add_item(sbus_tree, |
2029 | 0 | hf_sbus_rdwr_block_size, tvb, offset, |
2030 | 0 | 4, ENC_BIG_ENDIAN); |
2031 | 0 | offset += 4; |
2032 | | /*do not display a field for block data (skip)*/ |
2033 | 0 | offset += (sbus_rdwr_length-6); |
2034 | 0 | break; |
2035 | 0 | case SBUS_RD_BLOCK_DATA_STREAM: |
2036 | 0 | proto_tree_add_item(sbus_tree, |
2037 | 0 | hf_sbus_rdwr_telegram_sequence, tvb, offset, |
2038 | 0 | 1, ENC_BIG_ENDIAN); |
2039 | 0 | offset += 1; |
2040 | | /*do not display a field for block data (skip)*/ |
2041 | 0 | offset += (sbus_rdwr_length-2); |
2042 | 0 | break; |
2043 | 0 | case SBUS_RD_BLOCK_DATA_BYTES: |
2044 | | /*do not display a field for block data (skip)*/ |
2045 | 0 | offset += (sbus_rdwr_length-1); |
2046 | 0 | break; |
2047 | 0 | case SBUS_GET_BLOCK_SIZE: |
2048 | 0 | sbus_rdwr_block_type = tvb_get_uint8(tvb, 10); |
2049 | | /* Check for unknown block type */ |
2050 | 0 | if (sbus_rdwr_block_type == SBUS_RD_WR_UNKNOWN_BLOCK_TYPE) { |
2051 | | /*unknown block, no more data follows*/ |
2052 | 0 | } else { /* add block size and CRC32 in case of known block*/ |
2053 | 0 | proto_tree_add_item(sbus_tree, |
2054 | 0 | hf_sbus_rdwr_block_size, tvb, offset, |
2055 | 0 | 4, ENC_BIG_ENDIAN); |
2056 | 0 | offset += 4; |
2057 | | /*Now the CRC32 follows, but I don't bother calculating it*/ |
2058 | 0 | offset += 4; |
2059 | 0 | } |
2060 | 0 | break; |
2061 | 0 | case SBUS_GET_PROGRAM_BLOCK_LIST: |
2062 | 0 | proto_tree_add_item(sbus_tree, |
2063 | 0 | hf_sbus_block_type, tvb, offset, |
2064 | 0 | 1, ENC_BIG_ENDIAN); |
2065 | 0 | offset += 1; |
2066 | 0 | proto_tree_add_item(sbus_tree, |
2067 | 0 | hf_sbus_block_nr, tvb, offset, |
2068 | 0 | 2, ENC_BIG_ENDIAN); |
2069 | 0 | offset += 2; |
2070 | 0 | proto_tree_add_item(sbus_tree, |
2071 | 0 | hf_sbus_rdwr_block_size, tvb, offset, |
2072 | 0 | 4, ENC_BIG_ENDIAN); |
2073 | 0 | offset += 4; |
2074 | | /*do not display block_timestamp as no description is available*/ |
2075 | 0 | offset += (sbus_rdwr_length-8); |
2076 | 0 | break; |
2077 | 0 | default: |
2078 | 0 | break; |
2079 | 0 | } |
2080 | 0 | break; |
2081 | | |
2082 | | /*Inform that response was not dissected and add remaining length*/ |
2083 | 0 | default: |
2084 | 0 | sbus_helper = sbus_eth_len - (offset + 2); |
2085 | 0 | proto_tree_add_expert(sbus_tree, pinfo, &ei_sbus_telegram_not_implemented, tvb, offset, sbus_helper); |
2086 | 0 | offset = offset + sbus_helper; |
2087 | 0 | break; |
2088 | 0 | } |
2089 | 0 | } else if (sbus_attribut == SBUS_RESPONSE && (!request_val)) { |
2090 | | /*calculate the offset in case the request telegram was not found or was broadcasted*/ |
2091 | 0 | sbus_eth_len = tvb_get_ntohl(tvb,0); |
2092 | 0 | sbus_helper = sbus_eth_len - 11; |
2093 | 0 | proto_tree_add_expert(sbus_tree, pinfo, &ei_sbus_no_request_telegram, tvb, offset, sbus_helper); |
2094 | 0 | offset = sbus_eth_len - 2; |
2095 | 0 | } |
2096 | | |
2097 | 0 | if (sbus_attribut == SBUS_ACKNAK) { |
2098 | | /*Add response time if possible*/ |
2099 | 0 | if (request_val) { |
2100 | 0 | nstime_delta(&ns, &pinfo->abs_ts, &request_val->req_time); |
2101 | 0 | proto_tree_add_time(sbus_tree, hf_sbus_response_time, |
2102 | 0 | tvb, 0, 0, &ns); |
2103 | | /*add reference to request telegram*/ |
2104 | 0 | proto_tree_add_uint(sbus_tree, hf_sbus_response_to, tvb, 0, 0, |
2105 | 0 | request_val->req_frame); |
2106 | 0 | } |
2107 | 0 | hi = proto_tree_add_item(sbus_tree, |
2108 | 0 | hf_sbus_acknackcode, tvb, offset, 2, ENC_BIG_ENDIAN); |
2109 | 0 | if (tvb_get_uint8(tvb, (offset+1)) > 0) { |
2110 | 0 | expert_add_info(pinfo, hi, &ei_sbus_telegram_not_acked); |
2111 | 0 | } |
2112 | 0 | offset += 2; |
2113 | 0 | } |
2114 | | |
2115 | | /* Calculate CRC */ |
2116 | 0 | sbus_crc_calc = 0; |
2117 | 0 | for (i = 0; i < sbus_eth_len - 2; i++) |
2118 | 0 | sbus_crc_calc = crc_calc (sbus_crc_calc, tvb_get_uint8(tvb, i)); |
2119 | |
|
2120 | 0 | proto_tree_add_checksum(sbus_tree, tvb, offset, hf_sbus_crc, hf_sbus_crc_status, &ei_sbus_crc_bad, pinfo, sbus_crc_calc, |
2121 | 0 | ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY); |
2122 | 0 | offset += 2; /*now at the end of the telegram*/ |
2123 | 0 | } |
2124 | 0 | return offset; |
2125 | | /*End of dissect_sbus*/ |
2126 | 0 | } |
2127 | | |
2128 | | /* Register the protocol with Wireshark */ |
2129 | | |
2130 | | void |
2131 | | proto_register_sbus(void) |
2132 | 14 | { |
2133 | | |
2134 | | /* Setup list of header fields See Section 1.6.1 for details*/ |
2135 | 14 | static hf_register_info hf[] = { |
2136 | 14 | { &hf_sbus_length, |
2137 | 14 | { "Length (bytes)", "sbus.len", |
2138 | 14 | FT_UINT32, BASE_DEC, NULL, 0, |
2139 | 14 | "SAIA Ether-S-Bus telegram length", HFILL } |
2140 | 14 | }, |
2141 | 14 | { &hf_sbus_version, |
2142 | 14 | { "Version", "sbus.vers", |
2143 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2144 | 14 | "SAIA Ether-S-Bus version", HFILL } |
2145 | 14 | }, |
2146 | 14 | { &hf_sbus_protocol, |
2147 | 14 | { "Protocol type", "sbus.proto", |
2148 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2149 | 14 | "SAIA Ether-S-Bus protocol type", HFILL } |
2150 | 14 | }, |
2151 | 14 | { &hf_sbus_sequence, |
2152 | 14 | { "Sequence", "sbus.seq", |
2153 | 14 | FT_UINT16, BASE_DEC, NULL, 0, |
2154 | 14 | "SAIA Ether-S-Bus sequence number", HFILL } |
2155 | 14 | }, |
2156 | | |
2157 | 14 | { &hf_sbus_attribut, |
2158 | 14 | { "Telegram attribute", "sbus.att", |
2159 | 14 | FT_UINT8, BASE_HEX, VALS(sbus_att_vals), 0, |
2160 | 14 | "SAIA Ether-S-Bus telegram attribute, indicating type of telegram", HFILL } |
2161 | 14 | }, |
2162 | | |
2163 | 14 | { &hf_sbus_dest, |
2164 | 14 | { "Destination", "sbus.destination", |
2165 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2166 | 14 | "SAIA S-Bus destination address", HFILL } |
2167 | 14 | }, |
2168 | | |
2169 | 14 | { &hf_sbus_address, |
2170 | 14 | { "S-Bus address", "sbus.address", |
2171 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2172 | 14 | "SAIA S-Bus station address", HFILL } |
2173 | 14 | }, |
2174 | | |
2175 | 14 | { &hf_sbus_command, |
2176 | 14 | { "Command", "sbus.cmd", |
2177 | 14 | FT_UINT8, BASE_HEX | BASE_EXT_STRING, &sbus_command_vals_ext, 0, |
2178 | 14 | "SAIA S-Bus command", HFILL } |
2179 | 14 | }, |
2180 | | |
2181 | 14 | { &hf_sbus_command_extension, |
2182 | 14 | { "Command extension", "sbus.cmd_extn", |
2183 | 14 | FT_UINT8, BASE_HEX, NULL, 0, |
2184 | 14 | "SAIA S-Bus command extension", HFILL } |
2185 | 14 | }, |
2186 | | |
2187 | 14 | { &hf_sbus_rcount, |
2188 | 14 | { "R-count", "sbus.rcount", |
2189 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2190 | 14 | "Number of elements expected in response", HFILL } |
2191 | 14 | }, |
2192 | | |
2193 | 14 | { &hf_sbus_sub_length, |
2194 | 14 | { "Sub length", "sbus.sublength", |
2195 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2196 | 14 | "Length of multi-media response or request in bytes, length and command code fields not included", HFILL } |
2197 | 14 | }, |
2198 | | |
2199 | 14 | { &hf_sbus_multimedia_length, |
2200 | 14 | { "Multi-media length", "sbus.mmlength", |
2201 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2202 | 14 | "Length of all multi-media request or responses in bytes", HFILL } |
2203 | 14 | }, |
2204 | | |
2205 | 14 | { &hf_sbus_wcount, |
2206 | 14 | { "W-count (raw)", "sbus.wcount", |
2207 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2208 | 14 | "Number of bytes to be written", HFILL } |
2209 | 14 | }, |
2210 | | |
2211 | 14 | { &hf_sbus_wcount_calculated, |
2212 | 14 | { "W-count (32 bit values)", "sbus.wcount_calc", |
2213 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2214 | 14 | "Number of elements to be written", HFILL } |
2215 | 14 | }, |
2216 | | |
2217 | 14 | { &hf_sbus_fio_count, |
2218 | 14 | { "FIO Count (amount of bits)", "sbus.fio_count", |
2219 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2220 | 14 | "Number of binary elements to be written", HFILL } |
2221 | 14 | }, |
2222 | | |
2223 | 14 | { &hf_sbus_addr_rtc, |
2224 | 14 | { "Base address RTC", "sbus.addr_RTC", |
2225 | 14 | FT_UINT16, BASE_DEC, NULL, 0, |
2226 | 14 | "Base address of 32 bit elements to read", HFILL } |
2227 | 14 | }, |
2228 | | |
2229 | 14 | { &hf_sbus_addr_iof, |
2230 | 14 | { "Base address IOF", "sbus.addr_IOF", |
2231 | 14 | FT_UINT16, BASE_DEC, NULL, 0, |
2232 | 14 | "Base address of binary elements to read", HFILL } |
2233 | 14 | }, |
2234 | | |
2235 | 14 | { &hf_sbus_addr_db, |
2236 | 14 | { "DB address", "sbus.addr_db", |
2237 | 14 | FT_UINT16, BASE_DEC, NULL, 0, |
2238 | 14 | "Datablock address to read from", HFILL } |
2239 | 14 | }, |
2240 | | |
2241 | 14 | { &hf_sbus_addr_base_element, |
2242 | 14 | { "Base DB element address", "sbus.db_base_element", |
2243 | 14 | FT_UINT16, BASE_DEC, NULL, 0, |
2244 | 14 | "Base Datablock element address of 32 bit values to read", HFILL } |
2245 | 14 | }, |
2246 | | |
2247 | 14 | { &hf_sbus_addr_eeprom, |
2248 | 14 | { "Base address of EEPROM register", "sbus.addr_EEPROM", |
2249 | 14 | FT_UINT16, BASE_DEC, NULL, 0, |
2250 | 14 | "Base address of 32 bit EEPROM register to read or write", HFILL } |
2251 | 14 | }, |
2252 | | |
2253 | 14 | { &hf_sbus_addr_prog, |
2254 | 14 | { "Base address of user memory or program lines", "sbus.addr_prog", |
2255 | 14 | FT_UINT24, BASE_DEC, NULL, 0, |
2256 | 14 | "Base address of the user memory or program lines (read or write)", HFILL } |
2257 | 14 | }, |
2258 | | |
2259 | 14 | { &hf_sbus_addr_68k, |
2260 | 14 | { "Base address of bytes", "sbus.addr_68k", |
2261 | 14 | FT_UINT24, BASE_HEX, NULL, 0, |
2262 | 14 | "Base address of bytes to read or write (68k address)", HFILL } |
2263 | 14 | }, |
2264 | | |
2265 | 14 | { &hf_sbus_block_type, |
2266 | 14 | { "Block type", "sbus.block_type", |
2267 | 14 | FT_UINT8, BASE_HEX | BASE_EXT_STRING, &sbus_block_types_ext, 0, |
2268 | 14 | "Program block type", HFILL } |
2269 | 14 | }, |
2270 | | |
2271 | 14 | { &hf_sbus_block_nr, |
2272 | 14 | { "Block/Element nr", "sbus.block_nr", |
2273 | 14 | FT_UINT16, BASE_DEC, NULL, 0, |
2274 | 14 | "Program block / DataBlock number", HFILL } |
2275 | 14 | }, |
2276 | | |
2277 | 14 | { &hf_sbus_nbr_elements, |
2278 | 14 | { "Number of elements", "sbus.nbr_elements", |
2279 | 14 | FT_UINT16, BASE_DEC, NULL, 0, |
2280 | 14 | "Number of elements or characters", HFILL } |
2281 | 14 | }, |
2282 | | |
2283 | 14 | { &hf_sbus_display_register, |
2284 | 14 | { "PCD Display register", "sbus.data_display_register", |
2285 | 14 | FT_UINT32, BASE_DEC, NULL, 0, |
2286 | 14 | "The PCD display register (32 bit value)", HFILL } |
2287 | 14 | }, |
2288 | | |
2289 | 14 | { &hf_sbus_data_rtc, |
2290 | 14 | { "S-Bus 32-bit data", "sbus.data_rtc", |
2291 | 14 | FT_UINT32, BASE_DEC, NULL, 0, |
2292 | 14 | "One register/timer of counter (32 bit value)", HFILL } |
2293 | 14 | }, |
2294 | | |
2295 | 14 | { &hf_sbus_data_byte, |
2296 | 14 | { "Data bytes", "sbus.data_byte", |
2297 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2298 | 14 | "One byte from PCD", HFILL } |
2299 | 14 | }, |
2300 | | |
2301 | 14 | { &hf_sbus_data_byte_hex, |
2302 | 14 | { "Data bytes (hex)", "sbus.data_byte_hex", |
2303 | 14 | FT_UINT8, BASE_HEX, NULL, 0, |
2304 | 14 | "One byte from PCD (hexadecimal)", HFILL } |
2305 | 14 | }, |
2306 | | |
2307 | 14 | { &hf_sbus_data_iof, |
2308 | 14 | { "S-Bus binary data", "sbus.data_iof", |
2309 | 14 | FT_UINT32, BASE_DEC, NULL, 0, |
2310 | 14 | "8 binaries", HFILL } |
2311 | 14 | }, |
2312 | | |
2313 | 14 | { &hf_sbus_cpu_type, |
2314 | 14 | { "PCD type", "sbus.pcd_type", |
2315 | 14 | FT_STRING, BASE_NONE, NULL, 0, |
2316 | 14 | "PCD type (short form)", HFILL } |
2317 | 14 | }, |
2318 | | |
2319 | 14 | { &hf_sbus_fw_version, |
2320 | 14 | { "Firmware version", "sbus.fw_version", |
2321 | 14 | FT_STRING, BASE_NONE, NULL, 0, |
2322 | 14 | "Firmware version of the PCD or module", HFILL } |
2323 | 14 | }, |
2324 | | |
2325 | 14 | { &hf_sbus_sysinfo_nr, |
2326 | 14 | { "System information number", "sbus.sysinfo", |
2327 | 14 | FT_UINT8, BASE_HEX, NULL, 0, |
2328 | 14 | "System information number (extension to command code)", HFILL } |
2329 | 14 | }, |
2330 | | |
2331 | 14 | { &hf_sbus_sysinfo0_1, |
2332 | 14 | { "Mem size info", "sbus.sysinfo0.mem", |
2333 | 14 | FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_MEMSIZE, |
2334 | 14 | "Availability of memory size information", HFILL } |
2335 | 14 | }, |
2336 | 14 | { &hf_sbus_sysinfo0_2, |
2337 | 14 | { "Trace buffer", "sbus.sysinfo0.trace", |
2338 | 14 | FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_TRACE, |
2339 | 14 | "Availability of trace buffer feature", HFILL } |
2340 | 14 | }, |
2341 | 14 | { &hf_sbus_sysinfo0_3, |
2342 | 14 | { "Slot B1", "sbus.sysinfo0.b1", |
2343 | 14 | FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_INFO_B1, |
2344 | 14 | "Presence of EEPROM information on slot B1", HFILL } |
2345 | 14 | }, |
2346 | 14 | { &hf_sbus_sysinfo0_4, |
2347 | 14 | { "Slot B2", "sbus.sysinfo0.b2", |
2348 | 14 | FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_INFO_B2, |
2349 | 14 | "Presence of EEPROM information on slot B2", HFILL } |
2350 | 14 | }, |
2351 | 14 | { &hf_sbus_sysinfo0_5, |
2352 | 14 | { "PGU baud", "sbus.sysinfo0.pgubaud", |
2353 | 14 | FT_BOOLEAN, 8, TFS(&tfs_sbus_present), F_PGU_BAUD, |
2354 | 14 | "Availability of PGU baud switch feature", HFILL } |
2355 | 14 | }, |
2356 | | |
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 } |
2362 | | }, |
2363 | | #endif |
2364 | | |
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 } |
2370 | | }, |
2371 | | #endif |
2372 | | |
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 } |
2378 | | }, |
2379 | | #endif |
2380 | | |
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 } |
2386 | | }, |
2387 | | #endif |
2388 | | |
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 } |
2394 | | }, |
2395 | | #endif |
2396 | | |
2397 | 14 | { &hf_sbus_acknackcode, |
2398 | 14 | { "ACK/NAK code", "sbus.nakcode", |
2399 | 14 | FT_UINT16, BASE_HEX, VALS(sbus_ack_nak_vals), 0, |
2400 | 14 | "SAIA S-Bus ACK/NAK response", HFILL } |
2401 | 14 | }, |
2402 | | |
2403 | 14 | { &hf_sbus_cpu_status, |
2404 | 14 | { "CPU status", "sbus.CPU_status", |
2405 | 14 | FT_UINT8, BASE_HEX, VALS(sbus_CPU_status), 0, |
2406 | 14 | "SAIA PCD CPU status", HFILL } |
2407 | 14 | }, |
2408 | | |
2409 | 14 | { &hf_sbus_week_day, |
2410 | 14 | { "Calendar week", "sbus.rtc.week_day", |
2411 | 14 | FT_UINT16, BASE_HEX, NULL, 0, |
2412 | 14 | "Calendar week and week day number of the real time clock", HFILL } |
2413 | 14 | }, |
2414 | | |
2415 | 14 | { &hf_sbus_date, |
2416 | 14 | { "RTC date (YYMMDD)", "sbus.rtc.date", |
2417 | 14 | FT_UINT24, BASE_HEX, NULL, 0, |
2418 | 14 | "Year, month and day of the real time clock", HFILL } |
2419 | 14 | }, |
2420 | | |
2421 | 14 | { &hf_sbus_time, |
2422 | 14 | { "RTC time (HHMMSS)", "sbus.rtc.time", |
2423 | 14 | FT_UINT24, BASE_HEX, NULL, 0, |
2424 | 14 | "Time of the real time clock", HFILL } |
2425 | 14 | }, |
2426 | | |
2427 | 14 | { &hf_sbus_web_size, |
2428 | 14 | { "Web server packet size", "sbus.web.size", |
2429 | 14 | FT_UINT8, BASE_HEX, NULL, 0, |
2430 | 14 | NULL, HFILL } |
2431 | 14 | }, |
2432 | | |
2433 | 14 | { &hf_sbus_web_aid, |
2434 | 14 | { "AID", "sbus.web.aid", |
2435 | 14 | FT_UINT8, BASE_HEX, NULL, 0, |
2436 | 14 | "Web server command/status code (AID)", HFILL } |
2437 | 14 | }, |
2438 | | |
2439 | 14 | { &hf_sbus_web_seq, |
2440 | 14 | { "Sequence", "sbus.web.seq", |
2441 | 14 | FT_UINT8, BASE_HEX, NULL, 0, |
2442 | 14 | "Web server sequence nr (PACK_N)", HFILL } |
2443 | 14 | }, |
2444 | | |
2445 | 14 | { &hf_sbus_rdwr_block_length, |
2446 | 14 | { "Read/write block telegram length", "sbus.block.length", |
2447 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2448 | 14 | NULL, HFILL } |
2449 | 14 | }, |
2450 | | |
2451 | 14 | { &hf_sbus_rdwr_block_length_ext, |
2452 | 14 | { "Extended length (bytes)", "sbus.len_ext", |
2453 | 14 | FT_UINT32, BASE_DEC, NULL, 0, |
2454 | 14 | NULL, HFILL } |
2455 | 14 | }, |
2456 | | |
2457 | 14 | { &hf_sbus_rdwr_telegram_type, |
2458 | 14 | { "Read/write block telegram type", "sbus.block.tlgtype", |
2459 | 14 | FT_UINT8, BASE_HEX | BASE_EXT_STRING, &rdwrblock_vals_ext, 0, |
2460 | 14 | "Type of RD/WR block telegram", HFILL } |
2461 | 14 | }, |
2462 | | |
2463 | 14 | { &hf_sbus_rdwr_telegram_sequence, |
2464 | 14 | { "Sequence", "sbus.block.seq", |
2465 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
2466 | 14 | "Sequence number of block data stream telegram", HFILL } |
2467 | 14 | }, |
2468 | | |
2469 | 14 | { &hf_sbus_rdwr_block_size, |
2470 | 14 | { "Block size in bytes", "sbus.block.size", |
2471 | 14 | FT_UINT32, BASE_DEC, NULL, 0, |
2472 | 14 | "The size of the block in bytes", HFILL } |
2473 | 14 | }, |
2474 | | |
2475 | 14 | { &hf_sbus_rdwr_block_addr, |
2476 | 14 | { "Address inside block", "sbus.block.addr", |
2477 | 14 | FT_UINT32, BASE_DEC, NULL, 0, |
2478 | 14 | "The address inside a block", HFILL } |
2479 | 14 | }, |
2480 | | |
2481 | | |
2482 | 14 | { &hf_sbus_rdwr_file_name, |
2483 | 14 | { "File name", "sbus.block.filename", |
2484 | 14 | FT_STRING, BASE_NONE, NULL, 0, |
2485 | 14 | "Name of file to in RD/WR block telegram", HFILL } |
2486 | 14 | }, |
2487 | | |
2488 | 14 | { &hf_sbus_rdwr_list_type, |
2489 | 14 | { "Get program block list, command type", "sbus.block.getlisttype", |
2490 | 14 | FT_UINT8, BASE_HEX, VALS(rdwrblock_list_type_vals), 0, |
2491 | 14 | "Type of the Get Program Block list request", HFILL } |
2492 | 14 | }, |
2493 | | |
2494 | 14 | { &hf_sbus_rdwr_acknakcode, |
2495 | 14 | { "ACK/NAK code", "sbus.block.nakcode", |
2496 | 14 | FT_UINT8, BASE_HEX | BASE_EXT_STRING, &rdwrblock_sts_ext, 0, |
2497 | 14 | "ACK/NAK response for block write requests", HFILL } |
2498 | 14 | }, |
2499 | | |
2500 | 14 | { &hf_sbus_crc, |
2501 | 14 | { "Checksum", "sbus.crc", |
2502 | 14 | FT_UINT16, BASE_HEX, NULL, 0, |
2503 | 14 | "CRC 16", HFILL } |
2504 | 14 | }, |
2505 | | |
2506 | 14 | { &hf_sbus_crc_status, |
2507 | 14 | { "Checksum Status", "sbus.crc.status", |
2508 | 14 | FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0, |
2509 | 14 | NULL, HFILL }}, |
2510 | | |
2511 | 14 | { &hf_sbus_flags_accu, |
2512 | 14 | { "ACCU", "sbus.flags.accu", |
2513 | 14 | FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ACCU, |
2514 | 14 | "PCD Accumulator", HFILL } |
2515 | 14 | }, |
2516 | | |
2517 | 14 | { &hf_sbus_flags_error, |
2518 | 14 | { "Error flag", "sbus.flags.error", |
2519 | 14 | FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ERROR, |
2520 | 14 | "PCD error flag", HFILL } |
2521 | 14 | }, |
2522 | | |
2523 | 14 | { &hf_sbus_flags_negative, |
2524 | 14 | { "N-flag", "sbus.flags.nflag", |
2525 | 14 | FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_NEGATIVE, |
2526 | 14 | "Negative status flag", HFILL } |
2527 | 14 | }, |
2528 | | |
2529 | 14 | { &hf_sbus_flags_zero, |
2530 | 14 | { "Z-flag", "sbus.flags.zflag", |
2531 | 14 | FT_BOOLEAN, 8, TFS(&tfs_sbus_flags), F_ZERO, |
2532 | 14 | "Zero status flag", HFILL } |
2533 | 14 | }, |
2534 | | |
2535 | 14 | { &hf_sbus_response_in, |
2536 | 14 | { "Response in frame nr.", "sbus.response_in", |
2537 | 14 | FT_FRAMENUM, BASE_NONE, FRAMENUM_TYPE(FT_FRAMENUM_RESPONSE), 0x0, |
2538 | 14 | "The response to this Ether-S-Bus request is in this frame", HFILL } |
2539 | 14 | }, |
2540 | | |
2541 | 14 | { &hf_sbus_response_to, |
2542 | 14 | { "Request in frame nr.", "sbus.response_to", |
2543 | 14 | FT_FRAMENUM, BASE_NONE, FRAMENUM_TYPE(FT_FRAMENUM_REQUEST), 0x0, |
2544 | 14 | "This is a response to the Ether-S-Bus request in this frame", HFILL } |
2545 | 14 | }, |
2546 | | |
2547 | 14 | { &hf_sbus_response_time, |
2548 | 14 | { "Response time", "sbus.response_time", |
2549 | 14 | FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0, |
2550 | 14 | "The time between the request and the response", HFILL } |
2551 | 14 | }, |
2552 | | |
2553 | 14 | { &hf_sbus_timeout, |
2554 | 14 | { "Time passed since first request", "sbus.timeout", |
2555 | 14 | FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0, |
2556 | 14 | "The time between the first (identical) request and the repetition", HFILL } |
2557 | 14 | }, |
2558 | | |
2559 | 14 | { &hf_sbus_request_in, |
2560 | 14 | { "First request in frame nr.", "sbus.request_in", |
2561 | 14 | FT_FRAMENUM, BASE_NONE, NULL, 0x0, |
2562 | 14 | "The first request of this repeated request is in this frame", HFILL } |
2563 | 14 | } |
2564 | | |
2565 | 14 | }; |
2566 | | |
2567 | | /* Setup protocol subtree array */ |
2568 | 14 | static int *ett[] = { |
2569 | 14 | &ett_sbus, |
2570 | 14 | &ett_sbus_ether, |
2571 | 14 | &ett_sbus_data |
2572 | 14 | }; |
2573 | | |
2574 | 14 | static ei_register_info ei[] = { |
2575 | 14 | { &ei_sbus_retry, { "sbus.retry", PI_SEQUENCE, PI_NOTE, "Repeated telegram (due to timeout?)", EXPFILL }}, |
2576 | 14 | { &ei_sbus_telegram_not_acked, { "sbus.telegram_not_acked", PI_RESPONSE_CODE, PI_CHAT, "Telegram not acknowledged by PCD", EXPFILL }}, |
2577 | 14 | { &ei_sbus_crc_bad, { "sbus.crc_bad.expert", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }}, |
2578 | 14 | { &ei_sbus_telegram_not_implemented, { "sbus.telegram_not_implemented", PI_UNDECODED, PI_WARN, "This telegram isn't implemented in the dissector", EXPFILL }}, |
2579 | 14 | { &ei_sbus_no_request_telegram, { "sbus.no_request_telegram", PI_UNDECODED, PI_WARN, "Not dissected, could not find request telegram", EXPFILL }}, |
2580 | 14 | }; |
2581 | | |
2582 | 14 | expert_module_t* expert_sbus; |
2583 | | |
2584 | | /* Register the protocol name and description */ |
2585 | 14 | proto_sbus = proto_register_protocol("SAIA S-Bus", "SBUS", "sbus"); |
2586 | | |
2587 | | /* Required function calls to register the header fields and subtrees used */ |
2588 | 14 | proto_register_field_array(proto_sbus, hf, array_length(hf)); |
2589 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
2590 | 14 | expert_sbus = expert_register_protocol(proto_sbus); |
2591 | 14 | expert_register_field_array(expert_sbus, ei, array_length(ei)); |
2592 | 14 | sbus_request_hash = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), sbus_hash, sbus_equal); |
2593 | | |
2594 | | /* Register the dissector handle */ |
2595 | 14 | sbus_handle = register_dissector("sbus", dissect_sbus, proto_sbus); |
2596 | 14 | } |
2597 | | |
2598 | | void |
2599 | | proto_reg_handoff_sbus(void) |
2600 | 14 | { |
2601 | 14 | dissector_add_uint_with_preference("udp.port", SBUS_UDP_PORT, sbus_handle); |
2602 | 14 | } |
2603 | | |
2604 | | /* |
2605 | | * Editor modelines |
2606 | | * |
2607 | | * Local Variables: |
2608 | | * c-basic-offset: 7 |
2609 | | * tab-width: 8 |
2610 | | * indent-tabs-mode: nil |
2611 | | * End: |
2612 | | * |
2613 | | * ex: set shiftwidth=7 tabstop=8 expandtab: |
2614 | | * :indentSize=7:tabSize=8:noTabs=true: |
2615 | | */ |