2 * Routines for the disassembly of the "Far End Failure Detection"
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * Copied from packet-udld.c
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <epan/packet.h>
32 #include <epan/strutil.h>
35 #include <epan/nlpid.h>
39 /* Offsets in TLV structure. */
43 static int proto_fefd = -1;
44 static int hf_fefd_version = -1;
45 static int hf_fefd_opcode = -1;
46 static int hf_fefd_flags = -1;
47 static int hf_fefd_flags_rt = -1;
48 static int hf_fefd_flags_rsy = -1;
49 static int hf_fefd_checksum = -1;
50 static int hf_fefd_tlvtype = -1;
51 static int hf_fefd_tlvlength = -1;
53 static gint ett_fefd = -1;
54 static gint ett_fefd_flags = -1;
55 static gint ett_fefd_tlv = -1;
57 static dissector_handle_t data_handle;
59 #define TYPE_DEVICE_ID 0x0001
60 #define TYPE_PORT_ID 0x0002
61 #define TYPE_ECHO 0x0003
62 #define TYPE_MESSAGE_INTERVAL 0x0004
63 #define TYPE_TIMEOUT_INTERVAL 0x0005
64 #define TYPE_DEVICE_NAME 0x0006
65 #define TYPE_SEQUENCE_NUMBER 0x0007
68 static const value_string type_vals[] = {
69 { TYPE_DEVICE_ID, "Device ID" },
70 { TYPE_PORT_ID, "Port ID" },
71 { TYPE_ECHO, "Echo" },
72 { TYPE_MESSAGE_INTERVAL, "Message interval" },
73 { TYPE_TIMEOUT_INTERVAL, "Timeout interval" },
74 { TYPE_DEVICE_NAME, "Device name" },
75 { TYPE_SEQUENCE_NUMBER, "Sequence number" },
79 #define OPCODE_RESERVED 0x00
80 #define OPCODE_PROBE 0x01
81 #define OPCODE_ECHO 0x02
82 #define OPCODE_FLUSH 0x03
84 static const value_string opcode_vals[] = {
85 { OPCODE_RESERVED, "Reserved" },
86 { OPCODE_PROBE, "Probe" },
87 { OPCODE_ECHO, "Echo" },
88 { OPCODE_FLUSH, "Flush" },
93 dissect_fefd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
96 proto_tree *fefd_tree = NULL;
101 proto_tree *tlv_tree;
104 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FEFD");
105 col_clear(pinfo->cinfo, COL_INFO);
108 proto_item *flags_ti;
109 proto_tree *flags_tree;
111 ti = proto_tree_add_item(tree, proto_fefd, tvb, offset, -1, FALSE);
112 fefd_tree = proto_item_add_subtree(ti, ett_fefd);
115 proto_tree_add_item(fefd_tree, hf_fefd_version, tvb, offset, 1, FALSE);
116 proto_tree_add_item(fefd_tree, hf_fefd_opcode, tvb, offset, 1, FALSE);
118 flags_ti = proto_tree_add_item(fefd_tree, hf_fefd_flags, tvb, offset, 1, FALSE);
119 flags_tree = proto_item_add_subtree(flags_ti, ett_fefd_flags);
120 proto_tree_add_item(flags_tree, hf_fefd_flags_rt, tvb, offset, 1, FALSE);
121 proto_tree_add_item(flags_tree, hf_fefd_flags_rsy, tvb, offset, 1, FALSE);
123 proto_tree_add_item(fefd_tree, hf_fefd_checksum, tvb, offset, 2, FALSE);
126 offset += 4; /* The version/opcode/flags/checksum fields from above */
129 while (tvb_reported_length_remaining(tvb, offset) != 0) {
130 type = tvb_get_ntohs(tvb, offset + TLV_TYPE);
131 length = tvb_get_ntohs(tvb, offset + TLV_LENGTH);
134 tlvi = proto_tree_add_text(fefd_tree, tvb, offset, 4,
135 "TLV with invalid length %u (< 4)",
137 tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
138 proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
139 offset + TLV_TYPE, 2, type);
140 proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
141 offset + TLV_LENGTH, 2, length);
152 if (check_col(pinfo->cinfo, COL_INFO))
153 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL,
155 tvb_format_stringzpad(tvb, offset + 4,
159 tlvi = proto_tree_add_text(fefd_tree, tvb, offset,
160 length, "Device ID: %s",
161 tvb_format_stringzpad(tvb, offset + 4, length - 4));
162 tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
163 proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
164 offset + TLV_TYPE, 2, type);
165 proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
166 offset + TLV_LENGTH, 2, length);
167 proto_tree_add_text(tlv_tree, tvb, offset + 4,
168 length - 4, "Device ID: %s",
169 tvb_format_stringzpad(tvb, offset + 4, length - 4));
175 real_length = length;
176 if (tvb_get_guint8(tvb, offset + real_length) != 0x00) {
177 /* The length in the TLV doesn't appear to be the
178 length of the TLV, as the byte just past it
179 isn't the first byte of a 2-byte big-endian
180 small integer; make the length of the TLV the length
181 in the TLV, plus 4 bytes for the TLV type and length,
182 minus 1 because that's what makes one capture work. */
183 real_length = length + 3;
186 if (check_col(pinfo->cinfo, COL_INFO))
187 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL,
189 tvb_format_stringzpad(tvb, offset + 4, real_length - 4));
192 tlvi = proto_tree_add_text(fefd_tree, tvb, offset,
193 real_length, "Port ID: %s",
194 tvb_format_text(tvb, offset + 4, real_length - 4));
195 tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
196 proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
197 offset + TLV_TYPE, 2, type);
198 proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
199 offset + TLV_LENGTH, 2, length);
200 proto_tree_add_text(tlv_tree, tvb, offset + 4,
202 "Sent through Interface: %s",
203 tvb_format_text(tvb, offset + 4, real_length - 4));
205 offset += real_length;
209 case TYPE_MESSAGE_INTERVAL:
210 case TYPE_TIMEOUT_INTERVAL:
211 case TYPE_DEVICE_NAME:
212 case TYPE_SEQUENCE_NUMBER:
214 tlvi = proto_tree_add_text(fefd_tree, tvb, offset,
215 length, "Type: %s, length: %u",
216 val_to_str(type, type_vals, "Unknown (0x%04x)"),
218 tlv_tree = proto_item_add_subtree(tlvi, ett_fefd_tlv);
219 proto_tree_add_uint(tlv_tree, hf_fefd_tlvtype, tvb,
220 offset + TLV_TYPE, 2, type);
221 proto_tree_add_uint(tlv_tree, hf_fefd_tlvlength, tvb,
222 offset + TLV_LENGTH, 2, length);
224 proto_tree_add_text(tlv_tree, tvb, offset + 4,
233 call_dissector(data_handle, tvb_new_subset_remaining(tvb, offset), pinfo, fefd_tree);
237 proto_register_fefd(void)
239 static hf_register_info hf[] = {
241 { "Version", "fefd.version", FT_UINT8, BASE_DEC, NULL, 0xE0,
245 { "Opcode", "fefd.opcode", FT_UINT8, BASE_DEC, VALS(opcode_vals), 0x1F,
249 { "Flags", "fefd.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
253 { "Recommended timeout", "fefd.flags.rt", FT_BOOLEAN, 8, NULL, 0x80,
256 { &hf_fefd_flags_rsy,
257 { "ReSynch", "fefd.flags.rsy", FT_BOOLEAN, 8, NULL, 0x40,
261 { "Checksum", "fefd.checksum", FT_UINT16, BASE_HEX, NULL, 0x0,
265 { "Type", "fefd.tlv.type", FT_UINT16, BASE_HEX, VALS(type_vals), 0x0,
268 { &hf_fefd_tlvlength,
269 { "Length", "fefd.tlv.len", FT_UINT16, BASE_DEC, NULL, 0x0,
272 static gint *ett[] = {
278 proto_fefd = proto_register_protocol("Far End Failure Detection", "FEFD", "fefd");
279 proto_register_field_array(proto_fefd, hf, array_length(hf));
280 proto_register_subtree_array(ett, array_length(ett));
284 proto_reg_handoff_fefd(void)
286 dissector_handle_t fefd_handle;
288 data_handle = find_dissector("data");
289 fefd_handle = create_dissector_handle(dissect_fefd, proto_fefd);
290 dissector_add_uint("llc.force10_pid", 0x0111, fefd_handle);