2 * Routines for Ether-S-I/O dissection (from Saia Burgess Controls AG )
3 * Copyright 2010, Christian Durrer <christian.durrer@sensemail.ch>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <epan/packet.h>
32 #include <epan/expert.h>
35 #define ESIO_TRANSFER 0x01
36 #define ESIO_STATUS 0x02
38 /* Initialize the protocol and registered fields */
39 static int proto_esio = -1;
40 static int hf_esio_type = -1;
41 static int hf_esio_version = -1;
42 static int hf_esio_length = -1;
43 static int hf_esio_transaction_id = -1;
44 static int hf_esio_tlg_id = -1;
45 static int hf_esio_src_stn_id = -1;
46 static int hf_esio_data_nbr = -1;
47 static int hf_esio_data_flags = -1;
48 static int hf_esio_data_transfer_id = -1;
49 static int hf_esio_data_dest_id = -1;
50 static int hf_esio_data_length = -1;
51 static int hf_esio_data = -1;
52 static int hf_esio_sts_type = -1;
53 static int hf_esio_sts_size = -1;
54 static int hf_esio_rio_sts = -1;
55 static int hf_esio_rio_tlgs_lost = -1;
56 static int hf_esio_rio_diag = -1;
57 static int hf_esio_rio_flags = -1;
59 /* Initialize the subtree pointers */
60 static gint ett_esio = -1;
61 static gint ett_esio_header = -1;
62 static gint ett_esio_transfer_header = -1;
63 static gint ett_esio_transfer_data = -1;
64 static gint ett_esio_data = -1;
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_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)
121 /* Set up structures needed to add the protocol subtree and manage it */
122 proto_item *ti, *et, *hi;
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);
145 if (check_col(pinfo->cinfo, COL_INFO)) {
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_fstr( 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,
173 /* create display subtree for the protocol */
176 ti = proto_tree_add_item(tree, proto_esio, tvb, offset, -1, FALSE);
177 esio_tree = proto_item_add_subtree(ti, ett_esio);
178 /*Add subtree for Ether-S-I/O header*/
179 et = proto_tree_add_text(esio_tree, tvb, offset, 12, "Ether-S-I/O header");
180 esio_header_tree = proto_item_add_subtree(et, ett_esio_header);
181 offset +=4; /*first four bytes are "ESIO"*/
182 /* add items to the Ether-S-I/O header subtree*/
183 esio_tlg_type = tvb_get_ntohs(tvb,offset);
184 proto_tree_add_item(esio_header_tree,
185 hf_esio_type, tvb, offset, 2, FALSE);
187 proto_tree_add_item(esio_header_tree,
188 hf_esio_version, tvb, offset, 2, FALSE);
190 proto_tree_add_item(esio_header_tree,
191 hf_esio_length, tvb, offset, 2, FALSE);
193 proto_tree_add_item(esio_header_tree,
194 hf_esio_transaction_id, tvb, offset, 2, FALSE);
196 switch (esio_tlg_type) {
198 /*Add subtree for Ether-S-I/O header*/
199 et = proto_tree_add_text(esio_tree, tvb, offset, 12, "Transfer header");
200 esio_transfer_header_tree = proto_item_add_subtree(et, ett_esio_transfer_header);
201 proto_tree_add_item(esio_transfer_header_tree,
202 hf_esio_tlg_id, tvb, offset, 4, FALSE);
204 proto_tree_add_item(esio_transfer_header_tree,
205 hf_esio_src_stn_id, tvb, offset, 4, FALSE);
207 esio_nbr_data_transfers = tvb_get_guint8(tvb,offset);
208 proto_tree_add_item(esio_transfer_header_tree,
209 hf_esio_data_nbr, tvb, offset, 1, FALSE);
211 proto_tree_add_item(esio_transfer_header_tree,
212 hf_esio_data_flags, tvb, offset, 1, FALSE);
214 for (i=((esio_nbr_data_transfers)); i>0; i--) {
215 /*Add subtree(s) for Ether-S-I/O data transfers*/
216 esio_transfer_dest_id = tvb_get_ntohl(tvb,(offset+4));
217 esio_transfer_length = tvb_get_ntohs(tvb,(offset+8));
218 et = proto_tree_add_text(esio_tree, tvb, offset,
219 (esio_transfer_length + 10), "Data transfer to ID: %d ",
220 esio_transfer_dest_id);
221 esio_data_tansfer_tree = proto_item_add_subtree(et, ett_esio_transfer_data);
222 proto_tree_add_item(esio_data_tansfer_tree,
223 hf_esio_data_transfer_id, tvb, offset, 4, FALSE);
225 proto_tree_add_item(esio_data_tansfer_tree,
226 hf_esio_data_dest_id, tvb, offset, 4, FALSE);
228 proto_tree_add_item(esio_data_tansfer_tree,
229 hf_esio_data_length, tvb, offset, 2, FALSE);
231 /*here comes the data*/
232 et = proto_tree_add_text(esio_data_tansfer_tree, tvb, offset,
233 esio_transfer_length, "Data bytes ");
234 esio_data_tree = proto_item_add_subtree(et, ett_esio_data);
235 for (i=((esio_transfer_length)); i>0; i--) {
236 proto_tree_add_item(esio_data_tree,
237 hf_esio_data, tvb, offset,
244 proto_tree_add_item(esio_tree,
245 hf_esio_sts_type, tvb, offset, 2, FALSE);
247 proto_tree_add_item(esio_tree,
248 hf_esio_sts_size, tvb, offset, 2, FALSE);
250 proto_tree_add_item(esio_tree,
251 hf_esio_src_stn_id, tvb, offset, 4, FALSE);
253 proto_tree_add_item(esio_tree,
254 hf_esio_rio_sts, tvb, offset,
257 hi = proto_tree_add_item(esio_tree,
258 hf_esio_rio_tlgs_lost, tvb, offset,
260 expert_add_info_format(pinfo, hi, PI_SEQUENCE, PI_NOTE,
263 proto_tree_add_item(esio_tree,
264 hf_esio_rio_diag, tvb, offset,
267 proto_tree_add_item(esio_tree,
268 hf_esio_rio_flags, tvb, offset, 1, FALSE);
275 return tvb_length(tvb);
276 /*End of dissect_sbus*/
279 /* Register the protocol with Wireshark */
281 proto_register_esio(void)
283 /* Setup list of header fields See Section 1.6.1 for details*/
284 static hf_register_info hf[] = {
286 { "Telegram type", "esio.type",
287 FT_UINT16, BASE_HEX, VALS(esio_tlg_types), 0,
292 { "Version", "esio.vers",
293 FT_UINT16, BASE_DEC, NULL, 0,
298 { "Length (bytes)", "esio.len",
299 FT_UINT16, BASE_DEC, NULL, 0,
303 { &hf_esio_transaction_id,
304 { "Transaction ID", "esio.transaction_id",
305 FT_UINT16, BASE_DEC, NULL, 0,
309 { &hf_esio_src_stn_id,
310 { "Source station ID", "esio.src_stn_id",
311 FT_UINT32, BASE_DEC, NULL, 0,
316 { "Telegram ID", "esio.transfer.tlg_id",
317 FT_UINT32, BASE_DEC, NULL, 0,
322 { "Nbr. of data transfers", "esio.data.nbr",
323 FT_UINT8, BASE_DEC, NULL, 0,
327 { &hf_esio_data_flags,
328 { "Transfer header flags", "esio.data.flags",
329 FT_UINT8, BASE_HEX, NULL, 0,
333 { &hf_esio_data_transfer_id,
334 { "Data transfer ID", "esio.data.transfer_id",
335 FT_UINT32, BASE_DEC, NULL, 0,
339 { &hf_esio_data_dest_id,
340 { "Data destination ID", "esio.data.destination_id",
341 FT_UINT32, BASE_DEC, NULL, 0,
345 { &hf_esio_data_length,
346 { "Data transfer length", "esio.data.length",
347 FT_UINT16, BASE_DEC, NULL, 0,
352 { "Data", "esio.data",
353 FT_UINT8, BASE_DEC, NULL, 0,
358 { "Status type", "esio.sts.type",
359 FT_UINT16, BASE_HEX, VALS(esio_sts_types), 0,
364 { "Status length (bytes)", "esio.sts.length",
365 FT_UINT16, BASE_DEC, NULL, 0,
370 { "RIO status", "esio.sts.rio_sts",
371 FT_UINT8, BASE_DEC, NULL, 0,
375 { &hf_esio_rio_tlgs_lost,
376 { "Lost telegrams to RIO", "esio.sts.rio_lost_tlg",
377 FT_UINT8, BASE_DEC, NULL, 0,
382 { "RIO diagnostics", "esio.sts.rio_diag",
383 FT_UINT8, BASE_DEC, NULL, 0,
387 { &hf_esio_rio_flags,
388 { "RIO flags", "esio.sts.rio_flags",
389 FT_UINT8, BASE_HEX, NULL, 0,
395 /* Setup protocol subtree array */
396 static gint *ett[] = {
399 &ett_esio_transfer_header,
400 &ett_esio_transfer_data,
404 /* Register the protocol name and description */
405 proto_esio = proto_register_protocol("SAIA Ether-S-I/O protocol", "ESIO", "esio");
407 /* Required function calls to register the header fields and subtrees used */
408 proto_register_field_array(proto_esio, hf, array_length(hf));
409 proto_register_subtree_array(ett, array_length(ett));
413 proto_reg_handoff_esio(void)
415 dissector_handle_t esio_handle;
417 esio_handle = new_create_dissector_handle(dissect_esio, proto_esio);
418 dissector_add("udp.port", 6060, esio_handle);
427 * indent-tabs-mode: nil
430 * ex: set shiftwidth=7 tabstop=8 expandtab
431 * :indentSize=7:tabSize=8:noTabs=true: