FIXUP: WIP: verification_trailer
[wireshark-wip.git] / epan / dissectors / packet-tte.c
blob49bfe94c6fecc5362a12cc5aec4faed5e22aec89
1 /* packet-tte.c
2 * Routines for Time Triggered Ethernet dissection
4 * Author: Valentin Ecker, valentin.ecker (AT) tttech.com
5 * Author: Benjamin Roch, benjamin.roch (AT) tttech.com
7 * TTTech Computertechnik AG, Austria.
8 * http://www.tttech.com/solutions/ttethernet/
10 * $Id$
12 * Wireshark - Network traffic analyzer
13 * By Gerald Combs <gerald@wireshark.org>
14 * Copyright 1998 Gerald Combs
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
29 * USA.
32 #include "config.h"
34 #include <glib.h>
36 #include <epan/packet.h>
37 #include <epan/prefs.h>
38 #include <epan/etypes.h>
40 #include "packet-tte.h"
42 /* Initialize the protocol and registered fields */
43 static int proto_tte = -1;
45 static int hf_eth_dst = -1;
46 static int hf_tte_dst_cf = -1;
47 static int hf_tte_ctid = -1;
48 static int hf_eth_src = -1;
49 static int hf_eth_type = -1;
51 /* preference value pointers */
52 static guint32 tte_pref_ct_marker = 0xFFFFFFFF;
53 static guint32 tte_pref_ct_mask = 0x0;
55 /* Initialize the subtree pointers */
56 static gint ett_tte = -1;
57 static gint ett_tte_macdest = -1;
60 /* Code to actually dissect the packets */
61 static int
62 dissect_tte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
64 int is_frame_pcf;
66 /* Set up structures needed to add the protocol subtree and manage it */
67 proto_item *tte_root_item, *tte_macdest_item;
68 proto_tree *tte_tree, *tte_macdest_tree;
70 /* Check that there's enough data */
71 if (tvb_length(tvb) < TTE_HEADER_LENGTH)
72 return 0;
74 /* check if data of pcf frame */
75 is_frame_pcf =
76 (tvb_get_ntohs(tvb, TTE_MAC_LENGTH * 2) == ETHERTYPE_TTE_PCF);
78 /* return if no valid constant field is found */
79 if (!is_frame_pcf)
81 if ( (tvb_get_ntohl(tvb, 0) & tte_pref_ct_mask) != tte_pref_ct_marker)
82 return 0;
85 /* Make entries in Protocol column and Info column on summary display */
86 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TTE ");
88 col_set_str(pinfo->cinfo, COL_INFO, "Bogus TTEthernet Frame");
90 if (tree) {
92 /* create display subtree for the protocol */
93 tte_root_item = proto_tree_add_item(tree, proto_tte, tvb, 0,
94 TTE_HEADER_LENGTH, ENC_NA);
96 tte_tree = proto_item_add_subtree(tte_root_item, ett_tte);
98 tte_macdest_item = proto_tree_add_item(tte_tree,
99 hf_eth_dst, tvb, 0, TTE_MAC_LENGTH, ENC_NA);
101 proto_tree_add_item(tte_tree,
102 hf_eth_src, tvb, TTE_MAC_LENGTH, TTE_MAC_LENGTH, ENC_NA);
104 proto_tree_add_item(tte_tree,
105 hf_eth_type, tvb, TTE_MAC_LENGTH*2, TTE_ETHERTYPE_LENGTH,
106 ENC_BIG_ENDIAN);
108 tte_macdest_tree = proto_item_add_subtree(tte_macdest_item,
109 ett_tte_macdest);
111 proto_tree_add_item(tte_macdest_tree,
112 hf_tte_dst_cf, tvb, 0, TTE_MACDEST_CF_LENGTH, ENC_BIG_ENDIAN);
114 proto_tree_add_item(tte_macdest_tree,
115 hf_tte_ctid, tvb, TTE_MACDEST_CF_LENGTH,
116 TTE_MACDEST_CTID_LENGTH, ENC_BIG_ENDIAN);
119 /* prevent clearing the Columns...appending cannot be prevented */
120 col_set_fence(pinfo->cinfo, COL_PROTOCOL);
122 /* call std Ethernet dissector */
123 ethertype (tvb_get_ntohs(tvb, TTE_MAC_LENGTH * 2), tvb
124 , 14, pinfo, tree, NULL, hf_eth_type, 0, 0 );
126 return tvb_length(tvb);
130 void
131 proto_register_tte(void)
133 module_t *tte_module;
135 static hf_register_info hf[] = {
136 { &hf_tte_dst_cf,
137 { "Constant Field", "tte.cf",
138 FT_UINT32, BASE_HEX, NULL, 0x0,
139 NULL, HFILL }
141 { &hf_tte_ctid,
142 { "Critical Traffic Identifier", "tte.ctid",
143 FT_UINT16, BASE_HEX, NULL, 0x0,
144 NULL, HFILL }
148 /* Setup protocol subtree array */
149 static gint *ett[] = {
150 &ett_tte,
151 &ett_tte_macdest
154 /* Register the protocol name and description */
155 proto_tte = proto_register_protocol("TTEthernet", "TTE", "tte");
157 /* Required function calls to register header fields and subtrees used */
158 proto_register_field_array(proto_tte, hf, array_length(hf));
159 proto_register_subtree_array(ett, array_length(ett));
161 /* Register preferences module */
162 tte_module = prefs_register_protocol(proto_tte, NULL);
164 /* Register preferences */
165 prefs_register_uint_preference(tte_module, "ct_mask_value",
166 "CT Mask (in hex)",
167 "Critical Traffic Mask (base hex)",
168 16, &tte_pref_ct_mask);
170 prefs_register_uint_preference(tte_module, "ct_marker_value",
171 "CT Marker (in hex)",
172 "Critical Traffic Marker (base hex)",
173 16, &tte_pref_ct_marker);
177 void
178 proto_reg_handoff_tte(void)
180 heur_dissector_add("eth", dissect_tte, proto_tte);
182 hf_eth_dst = proto_registrar_get_id_byname ("eth.dst");
183 hf_eth_src = proto_registrar_get_id_byname ("eth.src");
184 hf_eth_type = proto_registrar_get_id_byname ("eth.type");