/src/wireshark/epan/dissectors/packet-fefd.c
Line | Count | Source |
1 | | /* packet-fefd.c |
2 | | * Routines for the disassembly of the "Far End Failure Detection" |
3 | | * |
4 | | * Wireshark - Network traffic analyzer |
5 | | * By Gerald Combs <gerald@wireshark.org> |
6 | | * Copyright 1998 Gerald Combs |
7 | | * |
8 | | * Copied from packet-udld.c |
9 | | * |
10 | | * SPDX-License-Identifier: GPL-2.0-or-later |
11 | | */ |
12 | | |
13 | | #include "config.h" |
14 | | |
15 | | #include <epan/packet.h> |
16 | | |
17 | | |
18 | | void proto_register_fefd(void); |
19 | | void proto_reg_handoff_fefd(void); |
20 | | |
21 | | static dissector_handle_t fefd_handle; |
22 | | |
23 | | /* Offsets in TLV structure. */ |
24 | 0 | #define TLV_TYPE 0 |
25 | 0 | #define TLV_LENGTH 2 |
26 | | |
27 | | static int proto_fefd; |
28 | | static int hf_fefd_version; |
29 | | static int hf_fefd_opcode; |
30 | | static int hf_fefd_flags; |
31 | | static int hf_fefd_flags_rt; |
32 | | static int hf_fefd_flags_rsy; |
33 | | static int hf_fefd_checksum; |
34 | | static int hf_fefd_tlvtype; |
35 | | static int hf_fefd_tlvlength; |
36 | | static int hf_fefd_device_id; |
37 | | static int hf_fefd_sent_through_interface; |
38 | | static int hf_fefd_data; |
39 | | |
40 | | static int ett_fefd; |
41 | | static int ett_fefd_flags; |
42 | | static int ett_fefd_tlv; |
43 | | |
44 | 0 | #define TYPE_DEVICE_ID 0x0001 |
45 | 0 | #define TYPE_PORT_ID 0x0002 |
46 | 0 | #define TYPE_ECHO 0x0003 |
47 | 0 | #define TYPE_MESSAGE_INTERVAL 0x0004 |
48 | 0 | #define TYPE_TIMEOUT_INTERVAL 0x0005 |
49 | 0 | #define TYPE_DEVICE_NAME 0x0006 |
50 | 0 | #define TYPE_SEQUENCE_NUMBER 0x0007 |
51 | | |
52 | | |
53 | | static const value_string type_vals[] = { |
54 | | { TYPE_DEVICE_ID, "Device ID" }, |
55 | | { TYPE_PORT_ID, "Port ID" }, |
56 | | { TYPE_ECHO, "Echo" }, |
57 | | { TYPE_MESSAGE_INTERVAL, "Message interval" }, |
58 | | { TYPE_TIMEOUT_INTERVAL, "Timeout interval" }, |
59 | | { TYPE_DEVICE_NAME, "Device name" }, |
60 | | { TYPE_SEQUENCE_NUMBER, "Sequence number" }, |
61 | | { 0, NULL } |
62 | | }; |
63 | | |
64 | | #define OPCODE_RESERVED 0x00 |
65 | | #define OPCODE_PROBE 0x01 |
66 | | #define OPCODE_ECHO 0x02 |
67 | | #define OPCODE_FLUSH 0x03 |
68 | | |
69 | | static const value_string opcode_vals[] = { |
70 | | { OPCODE_RESERVED, "Reserved" }, |
71 | | { OPCODE_PROBE, "Probe" }, |
72 | | { OPCODE_ECHO, "Echo" }, |
73 | | { OPCODE_FLUSH, "Flush" }, |
74 | | { 0, NULL } |
75 | | }; |
76 | | |
77 | | static int |
78 | | dissect_fefd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) |
79 | 0 | { |
80 | 0 | proto_item *ti; |
81 | 0 | proto_tree *fefd_tree = NULL; |
82 | 0 | int offset = 0; |
83 | 0 | uint16_t type; |
84 | 0 | uint16_t length; |
85 | 0 | proto_tree *tlv_tree; |
86 | 0 | int real_length; |
87 | 0 | static int * const flags[] = { |
88 | 0 | &hf_fefd_flags_rt, |
89 | 0 | &hf_fefd_flags_rsy, |
90 | 0 | NULL |
91 | 0 | }; |
92 | 0 | static int * const headers[] = { |
93 | 0 | &hf_fefd_version, |
94 | 0 | &hf_fefd_opcode, |
95 | 0 | NULL |
96 | 0 | }; |
97 | |
|
98 | 0 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "FEFD"); |
99 | 0 | col_clear(pinfo->cinfo, COL_INFO); |
100 | |
|
101 | 0 | ti = proto_tree_add_item(tree, proto_fefd, tvb, offset, -1, ENC_NA); |
102 | 0 | fefd_tree = proto_item_add_subtree(ti, ett_fefd); |
103 | | |
104 | | /* FEFD header */ |
105 | 0 | proto_tree_add_bitmask_list(fefd_tree, tvb, offset, 1, headers, ENC_BIG_ENDIAN); |
106 | 0 | offset += 1; |
107 | 0 | proto_tree_add_bitmask(fefd_tree, tvb, offset, hf_fefd_flags, ett_fefd_flags, flags, ENC_BIG_ENDIAN); |
108 | 0 | offset += 1; |
109 | 0 | proto_tree_add_checksum(fefd_tree, tvb, offset, hf_fefd_checksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS); |
110 | 0 | offset += 2; |
111 | |
|
112 | 0 | while (tvb_reported_length_remaining(tvb, offset) != 0) { |
113 | 0 | type = tvb_get_ntohs(tvb, offset + TLV_TYPE); |
114 | 0 | length = tvb_get_ntohs(tvb, offset + TLV_LENGTH); |
115 | 0 | if (length < 4) { |
116 | 0 | if (tree) { |
117 | 0 | tlv_tree = proto_tree_add_subtree_format(fefd_tree, tvb, offset, 4, /* XXX - expert info? */ |
118 | 0 | ett_fefd_tlv, NULL, "TLV with invalid length %u (< 4)", |
119 | 0 | length); |
120 | 0 | proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb, |
121 | 0 | offset + TLV_TYPE, 2, type); |
122 | 0 | proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb, |
123 | 0 | offset + TLV_LENGTH, 2, length); |
124 | 0 | } |
125 | 0 | offset += 4; |
126 | 0 | break; |
127 | 0 | } |
128 | | |
129 | 0 | switch (type) { |
130 | | |
131 | 0 | case TYPE_DEVICE_ID: |
132 | | /* Device ID */ |
133 | |
|
134 | 0 | col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, |
135 | 0 | "Device ID: %s", |
136 | 0 | tvb_format_stringzpad(pinfo->pool, tvb, offset + 4, |
137 | 0 | length - 4)); |
138 | |
|
139 | 0 | if (tree) { |
140 | 0 | tlv_tree = proto_tree_add_subtree_format(fefd_tree, tvb, offset, |
141 | 0 | length, ett_fefd_tlv, NULL, "Device ID: %s", |
142 | 0 | tvb_format_stringzpad(pinfo->pool, tvb, offset + 4, length - 4)); |
143 | 0 | proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb, |
144 | 0 | offset + TLV_TYPE, 2, type); |
145 | 0 | proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb, |
146 | 0 | offset + TLV_LENGTH, 2, length); |
147 | 0 | proto_tree_add_item(tlv_tree, hf_fefd_device_id, tvb, offset + 4, |
148 | 0 | length - 4, ENC_ASCII); |
149 | 0 | } |
150 | 0 | offset += length; |
151 | 0 | break; |
152 | | |
153 | 0 | case TYPE_PORT_ID: |
154 | 0 | real_length = length; |
155 | 0 | if (tvb_get_uint8(tvb, offset + real_length) != 0x00) { |
156 | | /* The length in the TLV doesn't appear to be the |
157 | | length of the TLV, as the byte just past it |
158 | | isn't the first byte of a 2-byte big-endian |
159 | | small integer; make the length of the TLV the length |
160 | | in the TLV, plus 4 bytes for the TLV type and length, |
161 | | minus 1 because that's what makes one capture work. */ |
162 | 0 | real_length = length + 3; |
163 | 0 | } |
164 | |
|
165 | 0 | col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, |
166 | 0 | "Port ID: %s", |
167 | 0 | tvb_format_stringzpad(pinfo->pool, tvb, offset + 4, real_length - 4)); |
168 | |
|
169 | 0 | if (tree) { |
170 | 0 | tlv_tree = proto_tree_add_subtree_format(fefd_tree, tvb, offset, |
171 | 0 | real_length, ett_fefd_tlv, NULL, "Port ID: %s", |
172 | 0 | tvb_format_text(pinfo->pool, tvb, offset + 4, real_length - 4)); |
173 | 0 | proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb, |
174 | 0 | offset + TLV_TYPE, 2, type); |
175 | 0 | proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb, |
176 | 0 | offset + TLV_LENGTH, 2, length); |
177 | 0 | proto_tree_add_item(tlv_tree, hf_fefd_sent_through_interface, tvb, offset + 4, |
178 | 0 | real_length - 4, ENC_ASCII); |
179 | 0 | } |
180 | 0 | offset += real_length; |
181 | 0 | break; |
182 | | |
183 | 0 | case TYPE_ECHO: |
184 | 0 | case TYPE_MESSAGE_INTERVAL: |
185 | 0 | case TYPE_TIMEOUT_INTERVAL: |
186 | 0 | case TYPE_DEVICE_NAME: |
187 | 0 | case TYPE_SEQUENCE_NUMBER: |
188 | 0 | default: |
189 | 0 | tlv_tree = proto_tree_add_subtree_format(fefd_tree, tvb, offset, |
190 | 0 | length, ett_fefd_tlv, NULL, "Type: %s, length: %u", |
191 | 0 | val_to_str(pinfo->pool, type, type_vals, "Unknown (0x%04x)"), |
192 | 0 | length); |
193 | 0 | proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb, |
194 | 0 | offset + TLV_TYPE, 2, type); |
195 | 0 | proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb, |
196 | 0 | offset + TLV_LENGTH, 2, length); |
197 | 0 | if (length > 4) { |
198 | 0 | proto_tree_add_item(tlv_tree, hf_fefd_data, tvb, offset + 4, |
199 | 0 | length - 4, ENC_NA); |
200 | 0 | } else { |
201 | 0 | return tvb_captured_length(tvb); |
202 | 0 | } |
203 | 0 | offset += length; |
204 | 0 | } |
205 | 0 | } |
206 | | |
207 | 0 | call_data_dissector(tvb_new_subset_remaining(tvb, offset), pinfo, fefd_tree); |
208 | 0 | return tvb_captured_length(tvb); |
209 | 0 | } |
210 | | |
211 | | void |
212 | | proto_register_fefd(void) |
213 | 14 | { |
214 | 14 | static hf_register_info hf[] = { |
215 | 14 | { &hf_fefd_version, |
216 | 14 | { "Version", "fefd.version", FT_UINT8, BASE_DEC, NULL, 0xE0, |
217 | 14 | NULL, HFILL }}, |
218 | | |
219 | 14 | { &hf_fefd_opcode, |
220 | 14 | { "Opcode", "fefd.opcode", FT_UINT8, BASE_DEC, VALS(opcode_vals), 0x1F, |
221 | 14 | NULL, HFILL }}, |
222 | | |
223 | 14 | { &hf_fefd_flags, |
224 | 14 | { "Flags", "fefd.flags", FT_UINT8, BASE_HEX, NULL, 0x0, |
225 | 14 | NULL, HFILL }}, |
226 | | |
227 | 14 | { &hf_fefd_flags_rt, |
228 | 14 | { "Recommended timeout", "fefd.flags.rt", FT_BOOLEAN, 8, NULL, 0x80, |
229 | 14 | NULL, HFILL }}, |
230 | | |
231 | 14 | { &hf_fefd_flags_rsy, |
232 | 14 | { "ReSynch", "fefd.flags.rsy", FT_BOOLEAN, 8, NULL, 0x40, |
233 | 14 | NULL, HFILL }}, |
234 | | |
235 | 14 | { &hf_fefd_checksum, |
236 | 14 | { "Checksum", "fefd.checksum", FT_UINT16, BASE_HEX, NULL, 0x0, |
237 | 14 | NULL, HFILL }}, |
238 | | |
239 | 14 | { &hf_fefd_tlvtype, |
240 | 14 | { "Type", "fefd.tlv.type", FT_UINT16, BASE_HEX, VALS(type_vals), 0x0, |
241 | 14 | NULL, HFILL }}, |
242 | | |
243 | 14 | { &hf_fefd_tlvlength, |
244 | 14 | { "Length", "fefd.tlv.len", FT_UINT16, BASE_DEC, NULL, 0x0, |
245 | 14 | NULL, HFILL }}, |
246 | | |
247 | 14 | { &hf_fefd_device_id, |
248 | 14 | { "Device ID", "fefd.device_id", FT_STRINGZ, BASE_NONE, NULL, 0x0, |
249 | 14 | NULL, HFILL }}, |
250 | | |
251 | 14 | { &hf_fefd_sent_through_interface, |
252 | 14 | { "Sent through Interface", "fefd.sent_through_interface", FT_STRING, BASE_NONE, NULL, 0x0, |
253 | 14 | NULL, HFILL }}, |
254 | | |
255 | 14 | { &hf_fefd_data, |
256 | 14 | { "Data", "fefd.data", FT_BYTES, BASE_NONE, NULL, 0x0, |
257 | 14 | NULL, HFILL }}, |
258 | 14 | }; |
259 | | |
260 | 14 | static int *ett[] = { |
261 | 14 | &ett_fefd, |
262 | 14 | &ett_fefd_flags, |
263 | 14 | &ett_fefd_tlv |
264 | 14 | }; |
265 | | |
266 | 14 | proto_fefd = proto_register_protocol("Far End Failure Detection", "FEFD", "fefd"); |
267 | 14 | proto_register_field_array(proto_fefd, hf, array_length(hf)); |
268 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
269 | | |
270 | 14 | fefd_handle = register_dissector("fefd", dissect_fefd, proto_fefd); |
271 | 14 | } |
272 | | |
273 | | void |
274 | | proto_reg_handoff_fefd(void) |
275 | 14 | { |
276 | 14 | dissector_add_uint("llc.force10_pid", 0x0111, fefd_handle); |
277 | 14 | } |
278 | | |
279 | | /* |
280 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
281 | | * |
282 | | * Local variables: |
283 | | * c-basic-offset: 4 |
284 | | * tab-width: 8 |
285 | | * indent-tabs-mode: nil |
286 | | * End: |
287 | | * |
288 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
289 | | * :indentSize=4:tabSize=8:noTabs=true: |
290 | | */ |