2 * Routines for Ether-S-I/O dissection (from Saia Burgess Controls AG )
3 * Copyright 2010, Christian Durrer <christian.durrer@sensemail.ch>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <epan/packet.h>
27 #include <epan/expert.h>
30 #define ESIO_TRANSFER 0x01
31 #define ESIO_STATUS 0x02
33 void proto_register_esio(void);
34 void proto_reg_handoff_esio(void);
36 /* Initialize the protocol and registered fields */
37 static int proto_esio = -1;
38 static int hf_esio_type = -1;
39 static int hf_esio_version = -1;
40 static int hf_esio_length = -1;
41 static int hf_esio_transaction_id = -1;
42 static int hf_esio_tlg_id = -1;
43 static int hf_esio_src_stn_id = -1;
44 static int hf_esio_data_nbr = -1;
45 static int hf_esio_data_flags = -1;
46 static int hf_esio_data_transfer_id = -1;
47 static int hf_esio_data_dest_id = -1;
48 static int hf_esio_data_length = -1;
49 static int hf_esio_data = -1;
50 static int hf_esio_sts_type = -1;
51 static int hf_esio_sts_size = -1;
52 static int hf_esio_rio_sts = -1;
53 static int hf_esio_rio_tlgs_lost = -1;
54 static int hf_esio_rio_diag = -1;
55 static int hf_esio_rio_flags = -1;
57 /* Initialize the subtree pointers */
58 static gint ett_esio = -1;
59 static gint ett_esio_header = -1;
60 static gint ett_esio_transfer_header = -1;
61 static gint ett_esio_transfer_data = -1;
62 static gint ett_esio_data = -1;
64 static expert_field ei_esio_telegram_lost = EI_INIT;
66 /* value to string definitions*/
67 /* Ether-S-I/O telegram types*/
68 static const value_string esio_tlg_types[] = {
70 {1, "Data transfer telegram"},
71 {2, "Status/Diag telegram"},
75 /* Status telegram types*/
76 static const value_string esio_sts_types[] = {
82 /* check whether the packet looks like SBUS or not */
84 is_esio_pdu(tvbuff_t *tvb)
86 /* we need at least 8 bytes to determine whether this is
88 /* minimal length is 20 bytes*/
89 if (tvb_captured_length(tvb) < 20) {
92 /* First four bytes must be "ESIO"*/
93 if (tvb_strneql(tvb, 0, "ESIO", 4) != 0) {
96 /* fifth byte must be 0*/
97 if (tvb_get_guint8(tvb, 4) > 0x00) {
100 /* sixth byte indicates telegram type and must be 0, 1 or 2*/
101 if (tvb_get_guint8(tvb, 5) > 0x02) {
104 /* seventh byte must be 0*/
105 if (tvb_get_guint8(tvb, 6) > 0x00) {
108 /* eight byte indicates telegram version and must be 0 (up to now)*/
109 if (tvb_get_guint8(tvb, 7) > 0x00) {
112 /*header seems to be Ether-S-I/O*/
116 /*Dissect the telegram*/
118 dissect_esio(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
121 /* Set up structures needed to add the protocol subtree and manage it */
123 proto_tree *esio_tree, *esio_header_tree, *esio_transfer_header_tree,
124 *esio_data_tansfer_tree, *esio_data_tree;
128 guint8 esio_nbr_data_transfers;
129 guint16 esio_telegram_type;
130 guint16 esio_tlg_type;
131 guint16 esio_transfer_length;
132 guint32 esio_transfer_dest_id;
136 /* does this look like an sbus pdu? */
137 if (!is_esio_pdu(tvb)) {
141 /* Make entries in Protocol column and Info column on summary display */
142 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ESIO");
143 col_clear(pinfo->cinfo, COL_INFO);
144 esio_telegram_type = tvb_get_guint8(tvb,5);
146 switch (esio_telegram_type) {
148 esio_src_id = tvb_get_ntohl(tvb,16);
149 esio_nbr_data_transfers = tvb_get_guint8(tvb, 20);
150 esio_dst_id = tvb_get_ntohl(tvb,26);
151 col_add_fstr( pinfo->cinfo, COL_INFO,
152 "Data transfer: Src ID: %d, Dst ID(s): %d",
153 esio_src_id, esio_dst_id);
154 if (esio_nbr_data_transfers > 1) {
155 col_append_str( pinfo->cinfo, COL_INFO,
160 esio_src_id = tvb_get_ntohl(tvb,16);
161 col_add_fstr( pinfo->cinfo, COL_INFO,
162 "Status/diag telegram: Src ID: %d",
166 /* All other telegrams */
167 col_set_str( pinfo->cinfo, COL_INFO,
172 /* create display subtree for the protocol */
174 ti = proto_tree_add_item(tree, proto_esio, tvb, offset, -1, ENC_NA);
175 esio_tree = proto_item_add_subtree(ti, ett_esio);
176 /*Add subtree for Ether-S-I/O header*/
177 esio_header_tree = proto_tree_add_subtree(esio_tree, tvb, offset, 12, ett_esio_header, NULL, "Ether-S-I/O header");
178 offset += 4; /*first four bytes are "ESIO"*/
179 /* add items to the Ether-S-I/O header subtree*/
180 esio_tlg_type = tvb_get_ntohs(tvb,offset);
181 proto_tree_add_item(esio_header_tree,
182 hf_esio_type, tvb, offset, 2, ENC_BIG_ENDIAN);
184 proto_tree_add_item(esio_header_tree,
185 hf_esio_version, tvb, offset, 2, ENC_BIG_ENDIAN);
187 proto_tree_add_item(esio_header_tree,
188 hf_esio_length, tvb, offset, 2, ENC_BIG_ENDIAN);
190 proto_tree_add_item(esio_header_tree,
191 hf_esio_transaction_id, tvb, offset, 2, ENC_BIG_ENDIAN);
193 switch (esio_tlg_type) {
196 /*Add subtree for Ether-S-I/O header*/
197 esio_transfer_header_tree = proto_tree_add_subtree(esio_tree, tvb, offset, 12,
198 ett_esio_transfer_header, NULL, "Transfer header");
199 proto_tree_add_item(esio_transfer_header_tree,
200 hf_esio_tlg_id, tvb, offset, 4, ENC_BIG_ENDIAN);
202 proto_tree_add_item(esio_transfer_header_tree,
203 hf_esio_src_stn_id, tvb, offset, 4, ENC_BIG_ENDIAN);
205 esio_nbr_data_transfers = tvb_get_guint8(tvb,offset);
206 proto_tree_add_item(esio_transfer_header_tree,
207 hf_esio_data_nbr, tvb, offset, 1, ENC_BIG_ENDIAN);
209 proto_tree_add_item(esio_transfer_header_tree,
210 hf_esio_data_flags, tvb, offset, 1, ENC_BIG_ENDIAN);
212 for (i=((esio_nbr_data_transfers)); i>0; i--) {
213 /*Add subtree(s) for Ether-S-I/O data transfers*/
214 esio_transfer_dest_id = tvb_get_ntohl(tvb,(offset+4));
215 esio_transfer_length = tvb_get_ntohs(tvb,(offset+8));
216 esio_data_tansfer_tree = proto_tree_add_subtree_format(esio_tree, tvb, offset,
217 (esio_transfer_length + 10), ett_esio_transfer_data, NULL,
218 "Data transfer to ID: %d ", esio_transfer_dest_id);
220 proto_tree_add_item(esio_data_tansfer_tree,
221 hf_esio_data_transfer_id, tvb, offset, 4, ENC_BIG_ENDIAN);
223 proto_tree_add_item(esio_data_tansfer_tree,
224 hf_esio_data_dest_id, tvb, offset, 4, ENC_BIG_ENDIAN);
226 proto_tree_add_item(esio_data_tansfer_tree,
227 hf_esio_data_length, tvb, offset, 2, ENC_BIG_ENDIAN);
229 /*here comes the data*/
230 esio_data_tree = proto_tree_add_subtree(esio_data_tansfer_tree, tvb, offset,
231 esio_transfer_length, ett_esio_data, NULL, "Data bytes ");
232 for (i=((esio_transfer_length)); i>0; i--) {
233 proto_tree_add_item(esio_data_tree,
234 hf_esio_data, tvb, offset,
242 proto_item *hi = NULL;
244 proto_tree_add_item(esio_tree,
245 hf_esio_sts_type, tvb, offset, 2, ENC_BIG_ENDIAN);
246 proto_tree_add_item(esio_tree,
247 hf_esio_sts_size, tvb, offset+2, 2, ENC_BIG_ENDIAN);
248 proto_tree_add_item(esio_tree,
249 hf_esio_src_stn_id, tvb, offset+4, 4, ENC_BIG_ENDIAN);
250 proto_tree_add_item(esio_tree,
251 hf_esio_rio_sts, tvb, offset+8,
253 hi = proto_tree_add_item(esio_tree,
254 hf_esio_rio_tlgs_lost, tvb, offset+9,
256 proto_tree_add_item(esio_tree,
257 hf_esio_rio_diag, tvb, offset+10,
259 proto_tree_add_item(esio_tree,
260 hf_esio_rio_flags, tvb, offset+11, 1, ENC_BIG_ENDIAN);
262 if (tvb_get_guint8(tvb, offset + 9) > 0) {
263 expert_add_info(pinfo, hi, &ei_esio_telegram_lost);
271 return tvb_captured_length(tvb);
272 /*End of dissect_sbus*/
275 /* Register the protocol with Wireshark */
277 proto_register_esio(void)
279 /* Setup list of header fields See Section 1.6.1 for details*/
280 static hf_register_info hf[] = {
282 { "Telegram type", "esio.type",
283 FT_UINT16, BASE_HEX, VALS(esio_tlg_types), 0,
288 { "Version", "esio.vers",
289 FT_UINT16, BASE_DEC, NULL, 0,
294 { "Length (bytes)", "esio.len",
295 FT_UINT16, BASE_DEC, NULL, 0,
299 { &hf_esio_transaction_id,
300 { "Transaction ID", "esio.transaction_id",
301 FT_UINT16, BASE_DEC, NULL, 0,
305 { &hf_esio_src_stn_id,
306 { "Source station ID", "esio.src_stn_id",
307 FT_UINT32, BASE_DEC, NULL, 0,
312 { "Telegram ID", "esio.transfer.tlg_id",
313 FT_UINT32, BASE_DEC, NULL, 0,
318 { "Nbr. of data transfers", "esio.data.nbr",
319 FT_UINT8, BASE_DEC, NULL, 0,
323 { &hf_esio_data_flags,
324 { "Transfer header flags", "esio.data.flags",
325 FT_UINT8, BASE_HEX, NULL, 0,
329 { &hf_esio_data_transfer_id,
330 { "Data transfer ID", "esio.data.transfer_id",
331 FT_UINT32, BASE_DEC, NULL, 0,
335 { &hf_esio_data_dest_id,
336 { "Data destination ID", "esio.data.destination_id",
337 FT_UINT32, BASE_DEC, NULL, 0,
341 { &hf_esio_data_length,
342 { "Data transfer length", "esio.data.length",
343 FT_UINT16, BASE_DEC, NULL, 0,
348 { "Data", "esio.data",
349 FT_UINT8, BASE_DEC, NULL, 0,
354 { "Status type", "esio.sts.type",
355 FT_UINT16, BASE_HEX, VALS(esio_sts_types), 0,
360 { "Status length (bytes)", "esio.sts.length",
361 FT_UINT16, BASE_DEC, NULL, 0,
366 { "RIO status", "esio.sts.rio_sts",
367 FT_UINT8, BASE_DEC, NULL, 0,
371 { &hf_esio_rio_tlgs_lost,
372 { "Lost telegrams to RIO", "esio.sts.rio_lost_tlg",
373 FT_UINT8, BASE_DEC, NULL, 0,
378 { "RIO diagnostics", "esio.sts.rio_diag",
379 FT_UINT8, BASE_DEC, NULL, 0,
383 { &hf_esio_rio_flags,
384 { "RIO flags", "esio.sts.rio_flags",
385 FT_UINT8, BASE_HEX, NULL, 0,
391 /* Setup protocol subtree array */
392 static gint *ett[] = {
395 &ett_esio_transfer_header,
396 &ett_esio_transfer_data,
400 static ei_register_info ei[] = {
401 { &ei_esio_telegram_lost, { "esio.telegram_lost", PI_SEQUENCE, PI_NOTE, "Telegram(s) lost", EXPFILL }},
404 expert_module_t* expert_esio;
406 /* Register the protocol name and description */
407 proto_esio = proto_register_protocol("SAIA Ether-S-I/O protocol", "ESIO", "esio");
409 /* Required function calls to register the header fields and subtrees used */
410 proto_register_field_array(proto_esio, hf, array_length(hf));
411 proto_register_subtree_array(ett, array_length(ett));
412 expert_esio = expert_register_protocol(proto_esio);
413 expert_register_field_array(expert_esio, ei, array_length(ei));
417 proto_reg_handoff_esio(void)
419 dissector_handle_t esio_handle;
421 esio_handle = new_create_dissector_handle(dissect_esio, proto_esio);
422 dissector_add_uint("udp.port", 6060, esio_handle);
431 * indent-tabs-mode: nil
434 * ex: set shiftwidth=7 tabstop=8 expandtab:
435 * :indentSize=7:tabSize=8:noTabs=true: