2 * Routines for DEC BPDU (DEC Spanning Tree Protocol) disassembly
4 * $Id: packet-dec-bpdu.c,v 1.15 2002/08/28 21:00:12 jmayer Exp $
6 * Copyright 2001 Paul Ionescu <paul@acorp.ro>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
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.
34 #include <epan/packet.h>
35 #include <epan/resolv.h>
39 /* Offsets of fields within a BPDU */
41 #define BPDU_DEC_CODE 0
43 #define BPDU_VERSION 2
45 #define BPDU_ROOT_PRI 4
46 #define BPDU_ROOT_MAC 6
47 #define BPDU_ROOT_PATH_COST 12
48 #define BPDU_BRIDGE_PRI 14
49 #define BPDU_BRIDGE_MAC 16
50 #define BPDU_PORT_IDENTIFIER 22
51 #define BPDU_MESSAGE_AGE 23
52 #define BPDU_HELLO_TIME 24
53 #define BPDU_MAX_AGE 25
54 #define BPDU_FORWARD_DELAY 26
56 #define DEC_BPDU_SIZE 27
60 #define BPDU_FLAGS_SHORT_TIMERS 0x80
61 #define BPDU_FLAGS_TCACK 0x02
62 #define BPDU_FLAGS_TC 0x01
64 static int proto_dec_bpdu = -1;
65 static int hf_dec_bpdu_proto_id = -1;
66 static int hf_dec_bpdu_type = -1;
67 static int hf_dec_bpdu_version_id = -1;
68 static int hf_dec_bpdu_flags = -1;
69 static int hf_dec_bpdu_flags_short_timers = -1;
70 static int hf_dec_bpdu_flags_tcack = -1;
71 static int hf_dec_bpdu_flags_tc = -1;
72 static int hf_dec_bpdu_root_pri = -1;
73 static int hf_dec_bpdu_root_mac = -1;
74 static int hf_dec_bpdu_root_cost = -1;
75 static int hf_dec_bpdu_bridge_pri = -1;
76 static int hf_dec_bpdu_bridge_mac = -1;
77 static int hf_dec_bpdu_port_id = -1;
78 static int hf_dec_bpdu_msg_age = -1;
79 static int hf_dec_bpdu_hello_time = -1;
80 static int hf_dec_bpdu_max_age = -1;
81 static int hf_dec_bpdu_forward_delay = -1;
83 static gint ett_dec_bpdu = -1;
84 static gint ett_dec_bpdu_flags = -1;
86 static const value_string protocol_id_vals[] = {
87 { 0xe1, "DEC Spanning Tree Protocol" },
91 #define BPDU_TYPE_TOPOLOGY_CHANGE 2
92 #define BPDU_TYPE_HELLO 25
94 static const value_string bpdu_type_vals[] = {
95 { BPDU_TYPE_TOPOLOGY_CHANGE, "Topology Change Notification" },
96 { BPDU_TYPE_HELLO, "Hello Packet" },
100 static const char initial_sep[] = " (";
101 static const char cont_sep[] = ", ";
103 #define APPEND_BOOLEAN_FLAG(flag, item, string) \
106 proto_item_append_text(item, string, sep); \
111 dissect_dec_bpdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
113 guint8 protocol_version;
116 proto_tree *bpdu_tree;
117 proto_tree *flags_tree;
121 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
122 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DEC_STP");
124 if (check_col(pinfo->cinfo, COL_INFO)) {
125 col_clear(pinfo->cinfo, COL_INFO);
128 bpdu_type = tvb_get_guint8(tvb, BPDU_TYPE);
130 if (check_col(pinfo->cinfo, COL_INFO)) {
131 col_add_str(pinfo->cinfo, COL_INFO,
132 val_to_str(bpdu_type, bpdu_type_vals,
133 "Unknown BPDU type (%u)"));
136 set_actual_length(tvb, DEC_BPDU_SIZE);
139 ti = proto_tree_add_item(tree, proto_dec_bpdu, tvb, 0, DEC_BPDU_SIZE,
141 bpdu_tree = proto_item_add_subtree(ti, ett_dec_bpdu);
143 protocol_version = tvb_get_guint8(tvb, BPDU_VERSION);
145 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_proto_id, tvb,
146 BPDU_DEC_CODE, 1, FALSE);
148 proto_tree_add_uint(bpdu_tree, hf_dec_bpdu_type, tvb,
149 BPDU_TYPE, 1, bpdu_type);
151 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_version_id, tvb,
152 BPDU_VERSION, 1, FALSE);
154 flags = tvb_get_guint8(tvb, BPDU_FLAGS);
155 ti = proto_tree_add_uint(bpdu_tree, hf_dec_bpdu_flags, tvb,
156 BPDU_FLAGS, 1, flags);
157 flags_tree = proto_item_add_subtree(ti, ett_dec_bpdu_flags);
159 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_SHORT_TIMERS, ti,
160 "%sUse short timers");
161 proto_tree_add_boolean(flags_tree, hf_dec_bpdu_flags_short_timers, tvb,
162 BPDU_FLAGS, 1, flags);
163 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_TCACK, ti,
164 "%sTopology Change Acknowledgment");
165 proto_tree_add_boolean(flags_tree, hf_dec_bpdu_flags_tcack, tvb,
166 BPDU_FLAGS, 1, flags);
167 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_TC, ti,
168 "%sTopology Change");
169 proto_tree_add_boolean(flags_tree, hf_dec_bpdu_flags_tc, tvb,
170 BPDU_FLAGS, 1, flags);
171 if (sep != initial_sep) {
172 /* We put something in; put in the terminating ")" */
173 proto_item_append_text(ti, ")");
176 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_root_pri, tvb,
177 BPDU_ROOT_PRI, 2, FALSE);
178 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_root_mac, tvb,
179 BPDU_ROOT_MAC, 6, FALSE);
180 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_root_cost, tvb,
181 BPDU_ROOT_PATH_COST, 2, FALSE);
182 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_bridge_pri, tvb,
183 BPDU_BRIDGE_PRI, 2, FALSE);
184 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_bridge_mac, tvb,
185 BPDU_BRIDGE_MAC, 6, FALSE);
186 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_port_id, tvb,
187 BPDU_PORT_IDENTIFIER, 1, FALSE);
188 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_msg_age, tvb,
189 BPDU_MESSAGE_AGE, 1, FALSE);
190 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_hello_time, tvb,
191 BPDU_HELLO_TIME, 1, FALSE);
192 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_max_age, tvb,
193 BPDU_MAX_AGE, 1, FALSE);
194 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_forward_delay, tvb,
195 BPDU_FORWARD_DELAY, 1, FALSE);
200 static const true_false_string yesno = {
206 proto_register_dec_bpdu(void)
209 static hf_register_info hf[] = {
210 { &hf_dec_bpdu_proto_id,
211 { "Protocol Identifier", "dec_stp.protocol",
212 FT_UINT8, BASE_HEX, VALS(&protocol_id_vals), 0x0,
215 { "BPDU Type", "dec_stp.type",
216 FT_UINT8, BASE_DEC, VALS(&bpdu_type_vals), 0x0,
218 { &hf_dec_bpdu_version_id,
219 { "BPDU Version", "dec_stp.version",
220 FT_UINT8, BASE_DEC, NULL, 0x0,
222 { &hf_dec_bpdu_flags,
223 { "BPDU flags", "dec_stp.flags",
224 FT_UINT8, BASE_HEX, NULL, 0x0,
226 { &hf_dec_bpdu_flags_short_timers,
227 { "Use short timers", "dec_stp.flags.short_timers",
228 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_SHORT_TIMERS,
230 { &hf_dec_bpdu_flags_tcack,
231 { "Topology Change Acknowledgment", "dec_stp.flags.tcack",
232 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_TCACK,
234 { &hf_dec_bpdu_flags_tc,
235 { "Topology Change", "dec_stp.flags.tc",
236 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_TC,
238 { &hf_dec_bpdu_root_pri,
239 { "Root Priority", "dec_stp.root.pri",
240 FT_UINT16, BASE_DEC, NULL, 0x0,
242 { &hf_dec_bpdu_root_mac,
243 { "Root MAC", "dec_stp.root.mac",
244 FT_ETHER, BASE_NONE, NULL, 0x0,
246 { &hf_dec_bpdu_root_cost,
247 { "Root Path Cost", "dec_stp.root.cost",
248 FT_UINT16, BASE_DEC, NULL, 0x0,
250 { &hf_dec_bpdu_bridge_pri,
251 { "Bridge Priority", "dec_stp.bridge.pri",
252 FT_UINT16, BASE_DEC, NULL, 0x0,
254 { &hf_dec_bpdu_bridge_mac,
255 { "Bridge MAC", "dec_stp.bridge.mac",
256 FT_ETHER, BASE_NONE, NULL, 0x0,
258 { &hf_dec_bpdu_port_id,
259 { "Port identifier", "dec_stp.port",
260 FT_UINT8, BASE_DEC, NULL, 0x0,
262 { &hf_dec_bpdu_msg_age,
263 { "Message Age", "dec_stp.msg_age",
264 FT_UINT8, BASE_DEC, NULL, 0x0,
266 { &hf_dec_bpdu_hello_time,
267 { "Hello Time", "dec_stp.hello",
268 FT_UINT8, BASE_DEC, NULL, 0x0,
270 { &hf_dec_bpdu_max_age,
271 { "Max Age", "dec_stp.max_age",
272 FT_UINT8, BASE_DEC, NULL, 0x0,
274 { &hf_dec_bpdu_forward_delay,
275 { "Forward Delay", "dec_stp.forward",
276 FT_UINT8, BASE_DEC, NULL, 0x0,
279 static gint *ett[] = {
284 proto_dec_bpdu = proto_register_protocol("DEC Spanning Tree Protocol",
285 "DEC_STP", "dec_stp");
286 proto_register_field_array(proto_dec_bpdu, hf, array_length(hf));
287 proto_register_subtree_array(ett, array_length(ett));
291 proto_reg_handoff_dec_bpdu(void)
293 dissector_handle_t dec_bpdu_handle;
295 dec_bpdu_handle = create_dissector_handle(dissect_dec_bpdu,
297 dissector_add("ethertype", ETHERTYPE_DEC_LB, dec_bpdu_handle);
298 dissector_add("chdlctype", ETHERTYPE_DEC_LB, dec_bpdu_handle);
299 dissector_add("ppp.protocol", PPP_DEC_LB, dec_bpdu_handle);