2 * Routines for DEC BPDU (DEC Spanning Tree Protocol) disassembly
4 * Copyright 2001 Paul Ionescu <paul@acorp.ro>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
16 #include <epan/etypes.h>
17 #include <epan/ppptypes.h>
20 /* Offsets of fields within a BPDU */
22 #define BPDU_DEC_CODE 0
24 #define BPDU_VERSION 2
26 #define BPDU_ROOT_PRI 4
27 #define BPDU_ROOT_MAC 6
28 #define BPDU_ROOT_PATH_COST 12
29 #define BPDU_BRIDGE_PRI 14
30 #define BPDU_BRIDGE_MAC 16
31 #define BPDU_PORT_IDENTIFIER 22
32 #define BPDU_MESSAGE_AGE 23
33 #define BPDU_HELLO_TIME 24
34 #define BPDU_MAX_AGE 25
35 #define BPDU_FORWARD_DELAY 26
37 #define DEC_BPDU_SIZE 27
41 #define BPDU_FLAGS_SHORT_TIMERS 0x80
42 #define BPDU_FLAGS_TCACK 0x02
43 #define BPDU_FLAGS_TC 0x01
45 void proto_register_dec_bpdu(void);
46 void proto_reg_handoff_dec_bpdu(void);
48 static dissector_handle_t dec_bpdu_handle
;
50 static int proto_dec_bpdu
;
51 static int hf_dec_bpdu_proto_id
;
52 static int hf_dec_bpdu_type
;
53 static int hf_dec_bpdu_version_id
;
54 static int hf_dec_bpdu_flags
;
55 static int hf_dec_bpdu_flags_short_timers
;
56 static int hf_dec_bpdu_flags_tcack
;
57 static int hf_dec_bpdu_flags_tc
;
58 static int hf_dec_bpdu_root_pri
;
59 static int hf_dec_bpdu_root_mac
;
60 static int hf_dec_bpdu_root_cost
;
61 static int hf_dec_bpdu_bridge_pri
;
62 static int hf_dec_bpdu_bridge_mac
;
63 static int hf_dec_bpdu_port_id
;
64 static int hf_dec_bpdu_msg_age
;
65 static int hf_dec_bpdu_hello_time
;
66 static int hf_dec_bpdu_max_age
;
67 static int hf_dec_bpdu_forward_delay
;
69 static int ett_dec_bpdu
;
70 static int ett_dec_bpdu_flags
;
72 static const value_string protocol_id_vals
[] = {
73 { 0xe1, "DEC Spanning Tree Protocol" },
77 #define BPDU_TYPE_TOPOLOGY_CHANGE 2
78 #define BPDU_TYPE_HELLO 25
80 static const value_string bpdu_type_vals
[] = {
81 { BPDU_TYPE_TOPOLOGY_CHANGE
, "Topology Change Notification" },
82 { BPDU_TYPE_HELLO
, "Hello Packet" },
87 dissect_dec_bpdu(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
90 proto_tree
*bpdu_tree
;
92 static int * const bpdu_flags
[] = {
93 &hf_dec_bpdu_flags_short_timers
,
94 &hf_dec_bpdu_flags_tcack
,
95 &hf_dec_bpdu_flags_tc
,
99 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "DEC_STP");
100 col_clear(pinfo
->cinfo
, COL_INFO
);
102 bpdu_type
= tvb_get_uint8(tvb
, BPDU_TYPE
);
104 col_add_str(pinfo
->cinfo
, COL_INFO
,
105 val_to_str(bpdu_type
, bpdu_type_vals
,
106 "Unknown BPDU type (%u)"));
108 set_actual_length(tvb
, DEC_BPDU_SIZE
);
111 ti
= proto_tree_add_item(tree
, proto_dec_bpdu
, tvb
, 0, DEC_BPDU_SIZE
,
113 bpdu_tree
= proto_item_add_subtree(ti
, ett_dec_bpdu
);
115 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_proto_id
, tvb
,
116 BPDU_DEC_CODE
, 1, ENC_BIG_ENDIAN
);
118 proto_tree_add_uint(bpdu_tree
, hf_dec_bpdu_type
, tvb
,
119 BPDU_TYPE
, 1, bpdu_type
);
121 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_version_id
, tvb
,
122 BPDU_VERSION
, 1, ENC_BIG_ENDIAN
);
124 proto_tree_add_bitmask_with_flags(bpdu_tree
, tvb
, BPDU_FLAGS
, hf_dec_bpdu_flags
, ett_dec_bpdu_flags
, bpdu_flags
, ENC_NA
, BMT_NO_FALSE
|BMT_NO_TFS
);
125 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_root_pri
, tvb
,
126 BPDU_ROOT_PRI
, 2, ENC_BIG_ENDIAN
);
127 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_root_mac
, tvb
,
128 BPDU_ROOT_MAC
, 6, ENC_NA
);
129 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_root_cost
, tvb
,
130 BPDU_ROOT_PATH_COST
, 2, ENC_BIG_ENDIAN
);
131 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_bridge_pri
, tvb
,
132 BPDU_BRIDGE_PRI
, 2, ENC_BIG_ENDIAN
);
133 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_bridge_mac
, tvb
,
134 BPDU_BRIDGE_MAC
, 6, ENC_NA
);
135 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_port_id
, tvb
,
136 BPDU_PORT_IDENTIFIER
, 1, ENC_BIG_ENDIAN
);
137 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_msg_age
, tvb
,
138 BPDU_MESSAGE_AGE
, 1, ENC_BIG_ENDIAN
);
139 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_hello_time
, tvb
,
140 BPDU_HELLO_TIME
, 1, ENC_BIG_ENDIAN
);
141 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_max_age
, tvb
,
142 BPDU_MAX_AGE
, 1, ENC_BIG_ENDIAN
);
143 proto_tree_add_item(bpdu_tree
, hf_dec_bpdu_forward_delay
, tvb
,
144 BPDU_FORWARD_DELAY
, 1, ENC_BIG_ENDIAN
);
147 return tvb_captured_length(tvb
);
151 proto_register_dec_bpdu(void)
154 static hf_register_info hf
[] = {
155 { &hf_dec_bpdu_proto_id
,
156 { "Protocol Identifier", "dec_stp.protocol",
157 FT_UINT8
, BASE_HEX
, VALS(protocol_id_vals
), 0x0,
160 { "BPDU Type", "dec_stp.type",
161 FT_UINT8
, BASE_DEC
, VALS(bpdu_type_vals
), 0x0,
163 { &hf_dec_bpdu_version_id
,
164 { "BPDU Version", "dec_stp.version",
165 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
167 { &hf_dec_bpdu_flags
,
168 { "BPDU flags", "dec_stp.flags",
169 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
171 { &hf_dec_bpdu_flags_short_timers
,
172 { "Use short timers", "dec_stp.flags.short_timers",
173 FT_BOOLEAN
, 8, TFS(&tfs_yes_no
), BPDU_FLAGS_SHORT_TIMERS
,
175 { &hf_dec_bpdu_flags_tcack
,
176 { "Topology Change Acknowledgment", "dec_stp.flags.tcack",
177 FT_BOOLEAN
, 8, TFS(&tfs_yes_no
), BPDU_FLAGS_TCACK
,
179 { &hf_dec_bpdu_flags_tc
,
180 { "Topology Change", "dec_stp.flags.tc",
181 FT_BOOLEAN
, 8, TFS(&tfs_yes_no
), BPDU_FLAGS_TC
,
183 { &hf_dec_bpdu_root_pri
,
184 { "Root Priority", "dec_stp.root.pri",
185 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
187 { &hf_dec_bpdu_root_mac
,
188 { "Root MAC", "dec_stp.root.mac",
189 FT_ETHER
, BASE_NONE
, NULL
, 0x0,
191 { &hf_dec_bpdu_root_cost
,
192 { "Root Path Cost", "dec_stp.root.cost",
193 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
195 { &hf_dec_bpdu_bridge_pri
,
196 { "Bridge Priority", "dec_stp.bridge.pri",
197 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
199 { &hf_dec_bpdu_bridge_mac
,
200 { "Bridge MAC", "dec_stp.bridge.mac",
201 FT_ETHER
, BASE_NONE
, NULL
, 0x0,
203 { &hf_dec_bpdu_port_id
,
204 { "Port identifier", "dec_stp.port",
205 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
207 { &hf_dec_bpdu_msg_age
,
208 { "Message Age", "dec_stp.msg_age",
209 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
211 { &hf_dec_bpdu_hello_time
,
212 { "Hello Time", "dec_stp.hello",
213 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
215 { &hf_dec_bpdu_max_age
,
216 { "Max Age", "dec_stp.max_age",
217 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
219 { &hf_dec_bpdu_forward_delay
,
220 { "Forward Delay", "dec_stp.forward",
221 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
224 static int *ett
[] = {
229 proto_dec_bpdu
= proto_register_protocol("DEC Spanning Tree Protocol",
230 "DEC_STP", "dec_stp");
231 proto_register_field_array(proto_dec_bpdu
, hf
, array_length(hf
));
232 proto_register_subtree_array(ett
, array_length(ett
));
234 dec_bpdu_handle
= register_dissector("dec_stp", dissect_dec_bpdu
,
239 proto_reg_handoff_dec_bpdu(void)
241 dissector_add_uint("ethertype", ETHERTYPE_DEC_LB
, dec_bpdu_handle
);
242 dissector_add_uint("chdlc.protocol", ETHERTYPE_DEC_LB
, dec_bpdu_handle
);
243 dissector_add_uint("ppp.protocol", PPP_DEC_LB
, dec_bpdu_handle
);
247 * Editor modelines - https://www.wireshark.org/tools/modelines.html
252 * indent-tabs-mode: nil
255 * vi: set shiftwidth=4 tabstop=8 expandtab:
256 * :indentSize=4:tabSize=8:noTabs=true: