Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-fefd.c
blob087f33ef3578e60cab455d11ab425dd04cb2f72d
1 /* packet-fefd.c
2 * Routines for the disassembly of the "Far End Failure Detection"
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * Copied from packet-udld.c
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <epan/packet.h>
18 void proto_register_fefd(void);
19 void proto_reg_handoff_fefd(void);
21 static dissector_handle_t fefd_handle;
23 /* Offsets in TLV structure. */
24 #define TLV_TYPE 0
25 #define TLV_LENGTH 2
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;
40 static int ett_fefd;
41 static int ett_fefd_flags;
42 static int ett_fefd_tlv;
44 #define TYPE_DEVICE_ID 0x0001
45 #define TYPE_PORT_ID 0x0002
46 #define TYPE_ECHO 0x0003
47 #define TYPE_MESSAGE_INTERVAL 0x0004
48 #define TYPE_TIMEOUT_INTERVAL 0x0005
49 #define TYPE_DEVICE_NAME 0x0006
50 #define TYPE_SEQUENCE_NUMBER 0x0007
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 }
64 #define OPCODE_RESERVED 0x00
65 #define OPCODE_PROBE 0x01
66 #define OPCODE_ECHO 0x02
67 #define OPCODE_FLUSH 0x03
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 }
77 static int
78 dissect_fefd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
80 proto_item *ti;
81 proto_tree *fefd_tree = NULL;
82 int offset = 0;
83 uint16_t type;
84 uint16_t length;
85 proto_tree *tlv_tree;
86 int real_length;
87 static int * const flags[] = {
88 &hf_fefd_flags_rt,
89 &hf_fefd_flags_rsy,
90 NULL
92 static int * const headers[] = {
93 &hf_fefd_version,
94 &hf_fefd_opcode,
95 NULL
98 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FEFD");
99 col_clear(pinfo->cinfo, COL_INFO);
101 ti = proto_tree_add_item(tree, proto_fefd, tvb, offset, -1, ENC_NA);
102 fefd_tree = proto_item_add_subtree(ti, ett_fefd);
104 /* FEFD header */
105 proto_tree_add_bitmask_list(fefd_tree, tvb, offset, 1, headers, ENC_BIG_ENDIAN);
106 offset += 1;
107 proto_tree_add_bitmask(fefd_tree, tvb, offset, hf_fefd_flags, ett_fefd_flags, flags, ENC_BIG_ENDIAN);
108 offset += 1;
109 proto_tree_add_checksum(fefd_tree, tvb, offset, hf_fefd_checksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
110 offset += 2;
112 while (tvb_reported_length_remaining(tvb, offset) != 0) {
113 type = tvb_get_ntohs(tvb, offset + TLV_TYPE);
114 length = tvb_get_ntohs(tvb, offset + TLV_LENGTH);
115 if (length < 4) {
116 if (tree) {
117 tlv_tree = proto_tree_add_subtree_format(fefd_tree, tvb, offset, 4, /* XXX - expert info? */
118 ett_fefd_tlv, NULL, "TLV with invalid length %u (< 4)",
119 length);
120 proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
121 offset + TLV_TYPE, 2, type);
122 proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
123 offset + TLV_LENGTH, 2, length);
125 offset += 4;
126 break;
129 switch (type) {
131 case TYPE_DEVICE_ID:
132 /* Device ID */
134 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL,
135 "Device ID: %s",
136 tvb_format_stringzpad(pinfo->pool, tvb, offset + 4,
137 length - 4));
139 if (tree) {
140 tlv_tree = proto_tree_add_subtree_format(fefd_tree, tvb, offset,
141 length, ett_fefd_tlv, NULL, "Device ID: %s",
142 tvb_format_stringzpad(pinfo->pool, tvb, offset + 4, length - 4));
143 proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
144 offset + TLV_TYPE, 2, type);
145 proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
146 offset + TLV_LENGTH, 2, length);
147 proto_tree_add_item(tlv_tree, hf_fefd_device_id, tvb, offset + 4,
148 length - 4, ENC_NA|ENC_ASCII);
150 offset += length;
151 break;
153 case TYPE_PORT_ID:
154 real_length = length;
155 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 real_length = length + 3;
165 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL,
166 "Port ID: %s",
167 tvb_format_stringzpad(pinfo->pool, tvb, offset + 4, real_length - 4));
169 if (tree) {
170 tlv_tree = proto_tree_add_subtree_format(fefd_tree, tvb, offset,
171 real_length, ett_fefd_tlv, NULL, "Port ID: %s",
172 tvb_format_text(pinfo->pool, tvb, offset + 4, real_length - 4));
173 proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
174 offset + TLV_TYPE, 2, type);
175 proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
176 offset + TLV_LENGTH, 2, length);
177 proto_tree_add_item(tlv_tree, hf_fefd_sent_through_interface, tvb, offset + 4,
178 real_length - 4, ENC_NA|ENC_ASCII);
180 offset += real_length;
181 break;
183 case TYPE_ECHO:
184 case TYPE_MESSAGE_INTERVAL:
185 case TYPE_TIMEOUT_INTERVAL:
186 case TYPE_DEVICE_NAME:
187 case TYPE_SEQUENCE_NUMBER:
188 default:
189 tlv_tree = proto_tree_add_subtree_format(fefd_tree, tvb, offset,
190 length, ett_fefd_tlv, NULL, "Type: %s, length: %u",
191 val_to_str(type, type_vals, "Unknown (0x%04x)"),
192 length);
193 proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
194 offset + TLV_TYPE, 2, type);
195 proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
196 offset + TLV_LENGTH, 2, length);
197 if (length > 4) {
198 proto_tree_add_item(tlv_tree, hf_fefd_data, tvb, offset + 4,
199 length - 4, ENC_NA);
200 } else {
201 return tvb_captured_length(tvb);
203 offset += length;
207 call_data_dissector(tvb_new_subset_remaining(tvb, offset), pinfo, fefd_tree);
208 return tvb_captured_length(tvb);
211 void
212 proto_register_fefd(void)
214 static hf_register_info hf[] = {
215 { &hf_fefd_version,
216 { "Version", "fefd.version", FT_UINT8, BASE_DEC, NULL, 0xE0,
217 NULL, HFILL }},
219 { &hf_fefd_opcode,
220 { "Opcode", "fefd.opcode", FT_UINT8, BASE_DEC, VALS(opcode_vals), 0x1F,
221 NULL, HFILL }},
223 { &hf_fefd_flags,
224 { "Flags", "fefd.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
225 NULL, HFILL }},
227 { &hf_fefd_flags_rt,
228 { "Recommended timeout", "fefd.flags.rt", FT_BOOLEAN, 8, NULL, 0x80,
229 NULL, HFILL }},
231 { &hf_fefd_flags_rsy,
232 { "ReSynch", "fefd.flags.rsy", FT_BOOLEAN, 8, NULL, 0x40,
233 NULL, HFILL }},
235 { &hf_fefd_checksum,
236 { "Checksum", "fefd.checksum", FT_UINT16, BASE_HEX, NULL, 0x0,
237 NULL, HFILL }},
239 { &hf_fefd_tlvtype,
240 { "Type", "fefd.tlv.type", FT_UINT16, BASE_HEX, VALS(type_vals), 0x0,
241 NULL, HFILL }},
243 { &hf_fefd_tlvlength,
244 { "Length", "fefd.tlv.len", FT_UINT16, BASE_DEC, NULL, 0x0,
245 NULL, HFILL }},
247 { &hf_fefd_device_id,
248 { "Device ID", "fefd.device_id", FT_STRINGZ, BASE_NONE, NULL, 0x0,
249 NULL, HFILL }},
251 { &hf_fefd_sent_through_interface,
252 { "Sent through Interface", "fefd.sent_through_interface", FT_STRING, BASE_NONE, NULL, 0x0,
253 NULL, HFILL }},
255 { &hf_fefd_data,
256 { "Data", "fefd.data", FT_BYTES, BASE_NONE, NULL, 0x0,
257 NULL, HFILL }},
260 static int *ett[] = {
261 &ett_fefd,
262 &ett_fefd_flags,
263 &ett_fefd_tlv
266 proto_fefd = proto_register_protocol("Far End Failure Detection", "FEFD", "fefd");
267 proto_register_field_array(proto_fefd, hf, array_length(hf));
268 proto_register_subtree_array(ett, array_length(ett));
270 fefd_handle = register_dissector("fefd", dissect_fefd, proto_fefd);
273 void
274 proto_reg_handoff_fefd(void)
276 dissector_add_uint("llc.force10_pid", 0x0111, fefd_handle);
280 * Editor modelines - https://www.wireshark.org/tools/modelines.html
282 * Local variables:
283 * c-basic-offset: 4
284 * tab-width: 8
285 * indent-tabs-mode: nil
286 * End:
288 * vi: set shiftwidth=4 tabstop=8 expandtab:
289 * :indentSize=4:tabSize=8:noTabs=true: