/src/wireshark/epan/dissectors/packet-tte.c
Line | Count | Source |
1 | | /* packet-tte.c |
2 | | * Routines for Time Triggered Ethernet dissection |
3 | | * |
4 | | * Author: Valentin Ecker, valentin.ecker (AT) tttech.com |
5 | | * Author: Benjamin Roch, benjamin.roch (AT) tttech.com |
6 | | * |
7 | | * TTTech Computertechnik AG, Austria. |
8 | | * https://www.tttech.com/technologies/time-triggered-ethernet/ |
9 | | * |
10 | | * Wireshark - Network traffic analyzer |
11 | | * By Gerald Combs <gerald@wireshark.org> |
12 | | * Copyright 1998 Gerald Combs |
13 | | * |
14 | | * SPDX-License-Identifier: GPL-2.0-or-later |
15 | | */ |
16 | | |
17 | | #include "config.h" |
18 | | |
19 | | #include <epan/packet.h> |
20 | | #include <epan/prefs.h> |
21 | | #include <epan/etypes.h> |
22 | | |
23 | | #include "packet-tte.h" |
24 | | |
25 | | void proto_register_tte(void); |
26 | | void proto_reg_handoff_tte(void); |
27 | | |
28 | | static dissector_handle_t ethertype_handle; |
29 | | |
30 | | /* Initialize the protocol and registered fields */ |
31 | | static int proto_tte; |
32 | | |
33 | | static int hf_eth_dst; |
34 | | static int hf_tte_dst_cf; |
35 | | static int hf_tte_ctid; |
36 | | static int hf_eth_src; |
37 | | static int hf_eth_type; |
38 | | |
39 | | /* preference value pointers */ |
40 | | static uint32_t tte_pref_ct_marker = 0xFFFFFFFF; |
41 | | static uint32_t tte_pref_ct_mask = 0x0; |
42 | | |
43 | | /* Initialize the subtree pointers */ |
44 | | static int ett_tte; |
45 | | static int ett_tte_macdest; |
46 | | |
47 | | |
48 | | /* Code to actually dissect the packets */ |
49 | | static bool |
50 | | dissect_tte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) |
51 | 20.9k | { |
52 | 20.9k | int is_frame_pcf; |
53 | 20.9k | ethertype_data_t ethertype_data; |
54 | | |
55 | | /* Set up structures needed to add the protocol subtree and manage it */ |
56 | 20.9k | proto_item *tte_root_item, *tte_macdest_item; |
57 | 20.9k | proto_tree *tte_tree, *tte_macdest_tree; |
58 | | |
59 | | /* Check that there's enough data */ |
60 | 20.9k | if (tvb_reported_length(tvb) < TTE_HEADER_LENGTH) |
61 | 0 | return false; |
62 | | |
63 | | /* check if data of pcf frame */ |
64 | 20.9k | is_frame_pcf = |
65 | 20.9k | (tvb_get_ntohs(tvb, TTE_MAC_LENGTH * 2) == ETHERTYPE_TTE_PCF); |
66 | | |
67 | | /* return if no valid constant field is found */ |
68 | 20.9k | if (!is_frame_pcf) |
69 | 20.8k | { |
70 | 20.8k | if ( (tvb_get_ntohl(tvb, 0) & tte_pref_ct_mask) != tte_pref_ct_marker) |
71 | 20.8k | return false; |
72 | 20.8k | } |
73 | | |
74 | | /* Make entries in Protocol column and Info column on summary display */ |
75 | 20 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "TTE/"); |
76 | | |
77 | 20 | if (tvb_get_ntohs(tvb, TTE_MAC_LENGTH * 2) <= IEEE_802_3_MAX_LEN) |
78 | 0 | { |
79 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "TTEthernet Frame"); |
80 | 0 | } |
81 | 20 | else |
82 | 20 | { |
83 | 20 | col_set_str(pinfo->cinfo, COL_INFO, "Bogus TTEthernet Frame"); |
84 | 20 | } |
85 | | |
86 | 20 | if (tree) { |
87 | | |
88 | | /* create display subtree for the protocol */ |
89 | 20 | tte_root_item = proto_tree_add_item(tree, proto_tte, tvb, 0, |
90 | 20 | TTE_HEADER_LENGTH, ENC_NA); |
91 | | |
92 | 20 | tte_tree = proto_item_add_subtree(tte_root_item, ett_tte); |
93 | | |
94 | 20 | tte_macdest_item = proto_tree_add_item(tte_tree, |
95 | 20 | hf_eth_dst, tvb, 0, TTE_MAC_LENGTH, ENC_NA); |
96 | | |
97 | 20 | proto_tree_add_item(tte_tree, |
98 | 20 | hf_eth_src, tvb, TTE_MAC_LENGTH, TTE_MAC_LENGTH, ENC_NA); |
99 | | |
100 | 20 | proto_tree_add_item(tte_tree, |
101 | 20 | hf_eth_type, tvb, TTE_MAC_LENGTH*2, TTE_ETHERTYPE_LENGTH, |
102 | 20 | ENC_BIG_ENDIAN); |
103 | | |
104 | 20 | tte_macdest_tree = proto_item_add_subtree(tte_macdest_item, |
105 | 20 | ett_tte_macdest); |
106 | | |
107 | 20 | proto_tree_add_item(tte_macdest_tree, |
108 | 20 | hf_tte_dst_cf, tvb, 0, TTE_MACDEST_CF_LENGTH, ENC_BIG_ENDIAN); |
109 | | |
110 | 20 | proto_tree_add_item(tte_macdest_tree, |
111 | 20 | hf_tte_ctid, tvb, TTE_MACDEST_CF_LENGTH, |
112 | 20 | TTE_MACDEST_CTID_LENGTH, ENC_BIG_ENDIAN); |
113 | 20 | } |
114 | | |
115 | | /* prevent clearing the Columns...appending cannot be prevented */ |
116 | 20 | col_set_fence(pinfo->cinfo, COL_PROTOCOL); |
117 | | |
118 | | /* call std Ethernet dissector */ |
119 | 20 | ethertype_data.etype = tvb_get_ntohs(tvb, TTE_MAC_LENGTH * 2); |
120 | 20 | ethertype_data.payload_offset = TTE_HEADER_LENGTH; |
121 | 20 | ethertype_data.fh_tree = NULL; |
122 | 20 | ethertype_data.trailer_id = 0; |
123 | 20 | ethertype_data.fcs_len = 0; |
124 | | |
125 | 20 | call_dissector_with_data(ethertype_handle, tvb, pinfo, tree, ðertype_data); |
126 | 20 | return true; |
127 | 20.9k | } |
128 | | |
129 | | |
130 | | void |
131 | | proto_register_tte(void) |
132 | 16 | { |
133 | 16 | module_t *tte_module; |
134 | | |
135 | 16 | static hf_register_info hf[] = { |
136 | 16 | { &hf_tte_dst_cf, |
137 | 16 | { "Constant Field", "tte.cf", |
138 | 16 | FT_UINT32, BASE_HEX, NULL, 0x0, |
139 | 16 | NULL, HFILL } |
140 | 16 | }, |
141 | 16 | { &hf_tte_ctid, |
142 | 16 | { "Critical Traffic Identifier", "tte.ctid", |
143 | 16 | FT_UINT16, BASE_HEX, NULL, 0x0, |
144 | 16 | NULL, HFILL } |
145 | 16 | } |
146 | 16 | }; |
147 | | |
148 | | /* Setup protocol subtree array */ |
149 | 16 | static int *ett[] = { |
150 | 16 | &ett_tte, |
151 | 16 | &ett_tte_macdest |
152 | 16 | }; |
153 | | |
154 | | /* Register the protocol name and description */ |
155 | 16 | proto_tte = proto_register_protocol("TTEthernet", "TTE", "tte"); |
156 | | |
157 | | /* Required function calls to register header fields and subtrees used */ |
158 | 16 | proto_register_field_array(proto_tte, hf, array_length(hf)); |
159 | 16 | proto_register_subtree_array(ett, array_length(ett)); |
160 | | |
161 | | /* Register preferences module */ |
162 | 16 | tte_module = prefs_register_protocol(proto_tte, NULL); |
163 | | |
164 | | /* Register preferences */ |
165 | 16 | prefs_register_uint_preference(tte_module, "ct_mask_value", |
166 | 16 | "CT Mask (in hex)", |
167 | 16 | "Critical Traffic Mask (base hex)", |
168 | 16 | 16, &tte_pref_ct_mask); |
169 | | |
170 | 16 | prefs_register_uint_preference(tte_module, "ct_marker_value", |
171 | 16 | "CT Marker (in hex)", |
172 | 16 | "Critical Traffic Marker (base hex)", |
173 | 16 | 16, &tte_pref_ct_marker); |
174 | 16 | } |
175 | | |
176 | | |
177 | | void |
178 | | proto_reg_handoff_tte(void) |
179 | 16 | { |
180 | 16 | heur_dissector_add("eth", dissect_tte, "TTEthernet", "tte_eth", proto_tte, HEURISTIC_ENABLE); |
181 | | |
182 | 16 | hf_eth_dst = proto_registrar_get_id_byname ("eth.dst"); |
183 | 16 | hf_eth_src = proto_registrar_get_id_byname ("eth.src"); |
184 | 16 | hf_eth_type = proto_registrar_get_id_byname ("eth.type"); |
185 | | |
186 | 16 | ethertype_handle = find_dissector_add_dependency("ethertype", proto_tte); |
187 | 16 | } |
188 | | |
189 | | /* |
190 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
191 | | * |
192 | | * Local variables: |
193 | | * c-basic-offset: 4 |
194 | | * tab-width: 8 |
195 | | * indent-tabs-mode: nil |
196 | | * End: |
197 | | * |
198 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
199 | | * :indentSize=4:tabSize=8:noTabs=true: |
200 | | */ |