1 /* packet-ethercat-frame.c
2 * Routines for ethercat packet disassembly
6 * Copyright (c) 2007 by Beckhoff Automation GmbH
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include <epan/packet.h>
36 #include <epan/etypes.h>
38 #include "packet-ethercat-frame.h"
40 /* Define the Ethercat frame proto */
41 static int proto_ethercat_frame = -1;
43 static dissector_table_t ethercat_frame_dissector_table;
44 static dissector_handle_t ethercat_frame_data_handle;
46 /* Define the tree for the EtherCAT frame */
47 static int ett_ethercat_frame = -1;
48 static int hf_ethercat_frame_length = -1;
49 static int hf_ethercat_frame_reserved = -1;
50 static int hf_ethercat_frame_type = -1;
52 static const value_string EthercatFrameTypes[] =
54 { 1, "EtherCAT command", },
61 static const value_string ethercat_frame_reserved_vals[] =
64 { 1, "Invalid (must be zero for conformance with the protocol specification)"},
69 static void dissect_ethercat_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
73 proto_tree *ethercat_frame_tree;
75 EtherCATFrameParserHDR hdr;
77 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ECATF");
79 col_clear(pinfo->cinfo, COL_INFO);
83 ti = proto_tree_add_item(tree, proto_ethercat_frame, tvb, offset, EtherCATFrameParserHDR_Len, TRUE);
84 ethercat_frame_tree = proto_item_add_subtree(ti, ett_ethercat_frame);
86 proto_tree_add_item(ethercat_frame_tree, hf_ethercat_frame_length, tvb, offset, EtherCATFrameParserHDR_Len, TRUE);
87 proto_tree_add_item(ethercat_frame_tree, hf_ethercat_frame_reserved, tvb, offset, EtherCATFrameParserHDR_Len, TRUE);
88 proto_tree_add_item(ethercat_frame_tree, hf_ethercat_frame_type, tvb, offset, EtherCATFrameParserHDR_Len, TRUE);
90 hdr.hdr = tvb_get_letohs(tvb, offset);
91 offset = EtherCATFrameParserHDR_Len;
93 /* The EtherCAT frame header has now been processed, allow sub dissectors to
94 handle the rest of the PDU. */
95 next_tvb = tvb_new_subset_remaining (tvb, offset);
97 if (!dissector_try_uint(ethercat_frame_dissector_table, hdr.v.protocol,
98 next_tvb, pinfo, tree))
100 col_add_fstr (pinfo->cinfo, COL_PROTOCOL, "0x%04x", hdr.v.protocol);
101 /* No sub dissector wanted to handle this payload, decode it as general
103 call_dissector (ethercat_frame_data_handle, next_tvb, pinfo, tree);
107 void proto_register_ethercat_frame(void)
109 static hf_register_info hf[] =
111 { &hf_ethercat_frame_length,
112 { "Length", "ecatf.length",
113 FT_UINT16, BASE_HEX, NULL, 0x07FF,
117 { &hf_ethercat_frame_reserved,
118 { "Reserved", "ecatf.reserved",
119 FT_UINT16, BASE_HEX, VALS(ethercat_frame_reserved_vals), 0x0800,
123 { &hf_ethercat_frame_type,
124 { "Type", "ecatf.type",
125 FT_UINT16, BASE_HEX, VALS(EthercatFrameTypes), 0xF000,
126 "E88A4 Types", HFILL }
135 proto_ethercat_frame = proto_register_protocol("EtherCAT frame header",
136 "ETHERCAT","ethercat");
137 proto_register_field_array(proto_ethercat_frame,hf,array_length(hf));
138 proto_register_subtree_array(ett, array_length(ett));
140 register_dissector("ecatf", dissect_ethercat_frame, proto_ethercat_frame);
142 /* Define a handle (ecatf.type) for sub dissectors that want to dissect
143 the Ethercat frame ether type (E88A4) payload. */
144 ethercat_frame_dissector_table = register_dissector_table("ecatf.type",
145 "EtherCAT frame type", FT_UINT8, BASE_DEC);
148 void proto_reg_handoff_ethercat_frame(void)
150 dissector_handle_t ethercat_frame_handle;
152 ethercat_frame_handle = find_dissector("ecatf");
153 dissector_add_uint("ethertype", ETHERTYPE_ECATF, ethercat_frame_handle);
154 dissector_add_uint("udp.port", ETHERTYPE_ECATF, ethercat_frame_handle);
155 dissector_add_uint("tcp.port", ETHERTYPE_ECATF, ethercat_frame_handle);
156 ethercat_frame_data_handle = find_dissector("data");