epan/dissectors/pidl/ C99 drsuapi
[wireshark-sm.git] / plugins / epan / ethercat / packet-ethercat-frame.c
blob687ca8bdaca11a394772dcb76874265619033916
1 /* packet-ethercat-frame.c
2 * Routines for ethercat packet disassembly
4 * Copyright (c) 2007 by Beckhoff Automation GmbH
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 /* Include files */
15 #include "config.h"
17 #include <epan/packet.h>
18 #include <epan/etypes.h>
20 #include "packet-ethercat-frame.h"
22 void proto_register_ethercat_frame(void);
23 void proto_reg_handoff_ethercat_frame(void);
25 /* Define the Ethercat frame proto */
26 static int proto_ethercat_frame;
28 static dissector_table_t ethercat_frame_dissector_table;
30 static dissector_handle_t ethercat_frame_handle;
32 /* Define the tree for the EtherCAT frame */
33 static int ett_ethercat_frame;
34 static int hf_ethercat_frame_length;
35 static int hf_ethercat_frame_reserved;
36 static int hf_ethercat_frame_type;
38 static const value_string EthercatFrameTypes[] =
40 { 1, "EtherCAT command", },
41 { 2, "ADS", },
42 { 3, "RAW-IO", },
43 { 4, "NV", },
44 { 5, "Mailbox"},
45 { 0, NULL }
48 static const value_string ethercat_frame_reserved_vals[] =
50 { 0, "Valid"},
51 { 1, "Invalid (must be zero for conformance with the protocol specification)"},
52 { 0, NULL}
55 /* Ethercat Frame */
56 static int dissect_ethercat_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
58 tvbuff_t *next_tvb;
59 proto_item *ti;
60 proto_tree *ethercat_frame_tree;
61 int offset = 0;
62 EtherCATFrameParserHDR hdr;
64 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ECATF");
66 col_clear(pinfo->cinfo, COL_INFO);
68 if (tree)
70 ti = proto_tree_add_item(tree, proto_ethercat_frame, tvb, offset, EtherCATFrameParserHDR_Len, ENC_NA);
71 ethercat_frame_tree = proto_item_add_subtree(ti, ett_ethercat_frame);
73 proto_tree_add_item(ethercat_frame_tree, hf_ethercat_frame_length, tvb, offset, EtherCATFrameParserHDR_Len, ENC_LITTLE_ENDIAN);
74 proto_tree_add_item(ethercat_frame_tree, hf_ethercat_frame_reserved, tvb, offset, EtherCATFrameParserHDR_Len, ENC_LITTLE_ENDIAN);
75 proto_tree_add_item(ethercat_frame_tree, hf_ethercat_frame_type, tvb, offset, EtherCATFrameParserHDR_Len, ENC_LITTLE_ENDIAN);
77 hdr.hdr = tvb_get_letohs(tvb, offset);
78 offset = EtherCATFrameParserHDR_Len;
80 /* The EtherCAT frame header has now been processed, allow sub dissectors to
81 handle the rest of the PDU. */
82 next_tvb = tvb_new_subset_remaining (tvb, offset);
84 if (!dissector_try_uint(ethercat_frame_dissector_table, hdr.v.protocol,
85 next_tvb, pinfo, tree))
87 col_add_fstr (pinfo->cinfo, COL_PROTOCOL, "0x%04x", hdr.v.protocol);
88 /* No sub dissector wanted to handle this payload, decode it as general
89 data instead. */
90 call_data_dissector(next_tvb, pinfo, tree);
92 return tvb_captured_length(tvb);
95 void proto_register_ethercat_frame(void)
97 static hf_register_info hf[] =
99 { &hf_ethercat_frame_length,
100 { "Length", "ecatf.length",
101 FT_UINT16, BASE_HEX, NULL, 0x07FF,
102 NULL, HFILL }
105 { &hf_ethercat_frame_reserved,
106 { "Reserved", "ecatf.reserved",
107 FT_UINT16, BASE_HEX, VALS(ethercat_frame_reserved_vals), 0x0800,
108 NULL, HFILL}
111 { &hf_ethercat_frame_type,
112 { "Type", "ecatf.type",
113 FT_UINT16, BASE_HEX, VALS(EthercatFrameTypes), 0xF000,
114 "E88A4 Types", HFILL }
118 static int *ett[] =
120 &ett_ethercat_frame
123 proto_ethercat_frame = proto_register_protocol("EtherCAT frame header", "ETHERCAT", "ecatf");
124 proto_register_field_array(proto_ethercat_frame,hf,array_length(hf));
125 proto_register_subtree_array(ett, array_length(ett));
127 ethercat_frame_handle = register_dissector("ecatf", dissect_ethercat_frame, proto_ethercat_frame);
129 /* Define a handle (ecatf.type) for sub dissectors that want to dissect
130 the Ethercat frame ether type (E88A4) payload. */
131 ethercat_frame_dissector_table = register_dissector_table("ecatf.type", "EtherCAT frame type",
132 proto_ethercat_frame, FT_UINT8, BASE_DEC);
135 void proto_reg_handoff_ethercat_frame(void)
137 dissector_add_uint("ethertype", ETHERTYPE_ECATF, ethercat_frame_handle);
138 dissector_add_uint_with_preference("udp.port", ETHERTYPE_ECATF, ethercat_frame_handle);
139 dissector_add_uint_with_preference("tcp.port", ETHERTYPE_ECATF, ethercat_frame_handle);
143 * Editor modelines - https://www.wireshark.org/tools/modelines.html
145 * Local Variables:
146 * c-basic-offset: 3
147 * tab-width: 8
148 * indent-tabs-mode: nil
149 * End:
151 * ex: set shiftwidth=3 tabstop=8 expandtab:
152 * :indentSize=3:tabSize=8:noTabs=true: