2 * Routines for DEC BPDU (DEC Spanning Tree Protocol) disassembly
4 * $Id: packet-dec-bpdu.c,v 1.13 2002/03/19 09:02:01 guy 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.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
35 #ifdef HAVE_NETINET_IN_H
36 # include <netinet/in.h>
42 #include <epan/packet.h>
43 #include <epan/resolv.h>
47 /* Offsets of fields within a BPDU */
49 #define BPDU_DEC_CODE 0
51 #define BPDU_VERSION 2
53 #define BPDU_ROOT_PRI 4
54 #define BPDU_ROOT_MAC 6
55 #define BPDU_ROOT_PATH_COST 12
56 #define BPDU_BRIDGE_PRI 14
57 #define BPDU_BRIDGE_MAC 16
58 #define BPDU_PORT_IDENTIFIER 22
59 #define BPDU_MESSAGE_AGE 23
60 #define BPDU_HELLO_TIME 24
61 #define BPDU_MAX_AGE 25
62 #define BPDU_FORWARD_DELAY 26
64 #define DEC_BPDU_SIZE 27
68 #define BPDU_FLAGS_SHORT_TIMERS 0x80
69 #define BPDU_FLAGS_TCACK 0x02
70 #define BPDU_FLAGS_TC 0x01
72 static int proto_dec_bpdu = -1;
73 static int hf_dec_bpdu_proto_id = -1;
74 static int hf_dec_bpdu_type = -1;
75 static int hf_dec_bpdu_version_id = -1;
76 static int hf_dec_bpdu_flags = -1;
77 static int hf_dec_bpdu_flags_short_timers = -1;
78 static int hf_dec_bpdu_flags_tcack = -1;
79 static int hf_dec_bpdu_flags_tc = -1;
80 static int hf_dec_bpdu_root_pri = -1;
81 static int hf_dec_bpdu_root_mac = -1;
82 static int hf_dec_bpdu_root_cost = -1;
83 static int hf_dec_bpdu_bridge_pri = -1;
84 static int hf_dec_bpdu_bridge_mac = -1;
85 static int hf_dec_bpdu_port_id = -1;
86 static int hf_dec_bpdu_msg_age = -1;
87 static int hf_dec_bpdu_hello_time = -1;
88 static int hf_dec_bpdu_max_age = -1;
89 static int hf_dec_bpdu_forward_delay = -1;
91 static gint ett_dec_bpdu = -1;
92 static gint ett_dec_bpdu_flags = -1;
94 static const value_string protocol_id_vals[] = {
95 { 0xe1, "DEC Spanning Tree Protocol" },
99 #define BPDU_TYPE_TOPOLOGY_CHANGE 2
100 #define BPDU_TYPE_HELLO 25
102 static const value_string bpdu_type_vals[] = {
103 { BPDU_TYPE_TOPOLOGY_CHANGE, "Topology Change Notification" },
104 { BPDU_TYPE_HELLO, "Hello Packet" },
108 static const char initial_sep[] = " (";
109 static const char cont_sep[] = ", ";
111 #define APPEND_BOOLEAN_FLAG(flag, item, string) \
114 proto_item_append_text(item, string, sep); \
119 dissect_dec_bpdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
121 guint8 protocol_version;
124 proto_tree *bpdu_tree;
125 proto_tree *flags_tree;
129 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
130 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DEC_STP");
132 if (check_col(pinfo->cinfo, COL_INFO)) {
133 col_clear(pinfo->cinfo, COL_INFO);
136 bpdu_type = tvb_get_guint8(tvb, BPDU_TYPE);
138 if (check_col(pinfo->cinfo, COL_INFO)) {
139 col_add_str(pinfo->cinfo, COL_INFO,
140 val_to_str(bpdu_type, bpdu_type_vals,
141 "Unknown BPDU type (%u)"));
144 set_actual_length(tvb, DEC_BPDU_SIZE);
147 ti = proto_tree_add_item(tree, proto_dec_bpdu, tvb, 0, DEC_BPDU_SIZE,
149 bpdu_tree = proto_item_add_subtree(ti, ett_dec_bpdu);
151 protocol_version = tvb_get_guint8(tvb, BPDU_VERSION);
153 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_proto_id, tvb,
154 BPDU_DEC_CODE, 1, FALSE);
156 proto_tree_add_uint(bpdu_tree, hf_dec_bpdu_type, tvb,
157 BPDU_TYPE, 1, bpdu_type);
159 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_version_id, tvb,
160 BPDU_VERSION, 1, FALSE);
162 flags = tvb_get_guint8(tvb, BPDU_FLAGS);
163 ti = proto_tree_add_uint(bpdu_tree, hf_dec_bpdu_flags, tvb,
164 BPDU_FLAGS, 1, flags);
165 flags_tree = proto_item_add_subtree(ti, ett_dec_bpdu_flags);
167 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_SHORT_TIMERS, ti,
168 "%sUse short timers");
169 proto_tree_add_boolean(flags_tree, hf_dec_bpdu_flags_short_timers, tvb,
170 BPDU_FLAGS, 1, flags);
171 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_TCACK, ti,
172 "%sTopology Change Acknowledgment");
173 proto_tree_add_boolean(flags_tree, hf_dec_bpdu_flags_tcack, tvb,
174 BPDU_FLAGS, 1, flags);
175 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_TC, ti,
176 "%sTopology Change");
177 proto_tree_add_boolean(flags_tree, hf_dec_bpdu_flags_tc, tvb,
178 BPDU_FLAGS, 1, flags);
179 if (sep != initial_sep) {
180 /* We put something in; put in the terminating ")" */
181 proto_item_append_text(ti, ")");
184 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_root_pri, tvb,
185 BPDU_ROOT_PRI, 2, FALSE);
186 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_root_mac, tvb,
187 BPDU_ROOT_MAC, 6, FALSE);
188 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_root_cost, tvb,
189 BPDU_ROOT_PATH_COST, 2, FALSE);
190 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_bridge_pri, tvb,
191 BPDU_BRIDGE_PRI, 2, FALSE);
192 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_bridge_mac, tvb,
193 BPDU_BRIDGE_MAC, 6, FALSE);
194 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_port_id, tvb,
195 BPDU_PORT_IDENTIFIER, 1, FALSE);
196 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_msg_age, tvb,
197 BPDU_MESSAGE_AGE, 1, FALSE);
198 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_hello_time, tvb,
199 BPDU_HELLO_TIME, 1, FALSE);
200 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_max_age, tvb,
201 BPDU_MAX_AGE, 1, FALSE);
202 proto_tree_add_item(bpdu_tree, hf_dec_bpdu_forward_delay, tvb,
203 BPDU_FORWARD_DELAY, 1, FALSE);
208 static const true_false_string yesno = {
214 proto_register_dec_bpdu(void)
217 static hf_register_info hf[] = {
218 { &hf_dec_bpdu_proto_id,
219 { "Protocol Identifier", "dec_stp.protocol",
220 FT_UINT8, BASE_HEX, VALS(&protocol_id_vals), 0x0,
223 { "BPDU Type", "dec_stp.type",
224 FT_UINT8, BASE_DEC, VALS(&bpdu_type_vals), 0x0,
226 { &hf_dec_bpdu_version_id,
227 { "BPDU Version", "dec_stp.version",
228 FT_UINT8, BASE_DEC, NULL, 0x0,
230 { &hf_dec_bpdu_flags,
231 { "BPDU flags", "dec_stp.flags",
232 FT_UINT8, BASE_HEX, NULL, 0x0,
234 { &hf_dec_bpdu_flags_short_timers,
235 { "Use short timers", "dec_stp.flags.short_timers",
236 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_SHORT_TIMERS,
238 { &hf_dec_bpdu_flags_tcack,
239 { "Topology Change Acknowledgment", "dec_stp.flags.tcack",
240 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_TCACK,
242 { &hf_dec_bpdu_flags_tc,
243 { "Topology Change", "dec_stp.flags.tc",
244 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_TC,
246 { &hf_dec_bpdu_root_pri,
247 { "Root Priority", "dec_stp.root.pri",
248 FT_UINT16, BASE_DEC, NULL, 0x0,
250 { &hf_dec_bpdu_root_mac,
251 { "Root MAC", "dec_stp.root.mac",
252 FT_ETHER, BASE_NONE, NULL, 0x0,
254 { &hf_dec_bpdu_root_cost,
255 { "Root Path Cost", "dec_stp.root.cost",
256 FT_UINT16, BASE_DEC, NULL, 0x0,
258 { &hf_dec_bpdu_bridge_pri,
259 { "Bridge Priority", "dec_stp.bridge.pri",
260 FT_UINT16, BASE_DEC, NULL, 0x0,
262 { &hf_dec_bpdu_bridge_mac,
263 { "Bridge MAC", "dec_stp.bridge.mac",
264 FT_ETHER, BASE_NONE, NULL, 0x0,
266 { &hf_dec_bpdu_port_id,
267 { "Port identifier", "dec_stp.port",
268 FT_UINT8, BASE_DEC, NULL, 0x0,
270 { &hf_dec_bpdu_msg_age,
271 { "Message Age", "dec_stp.msg_age",
272 FT_UINT8, BASE_DEC, NULL, 0x0,
274 { &hf_dec_bpdu_hello_time,
275 { "Hello Time", "dec_stp.hello",
276 FT_UINT8, BASE_DEC, NULL, 0x0,
278 { &hf_dec_bpdu_max_age,
279 { "Max Age", "dec_stp.max_age",
280 FT_UINT8, BASE_DEC, NULL, 0x0,
282 { &hf_dec_bpdu_forward_delay,
283 { "Forward Delay", "dec_stp.forward",
284 FT_UINT8, BASE_DEC, NULL, 0x0,
287 static gint *ett[] = {
292 proto_dec_bpdu = proto_register_protocol("DEC Spanning Tree Protocol",
293 "DEC_STP", "dec_stp");
294 proto_register_field_array(proto_dec_bpdu, hf, array_length(hf));
295 proto_register_subtree_array(ett, array_length(ett));
299 proto_reg_handoff_dec_bpdu(void)
301 dissector_handle_t dec_bpdu_handle;
303 dec_bpdu_handle = create_dissector_handle(dissect_dec_bpdu,
305 dissector_add("ethertype", ETHERTYPE_DEC_LB, dec_bpdu_handle);
306 dissector_add("chdlctype", ETHERTYPE_DEC_LB, dec_bpdu_handle);
307 dissector_add("ppp.protocol", PPP_DEC_LB, dec_bpdu_handle);