Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-dec-bpdu.c
bloba3117f80f181511e288c5d6c21f098af31b88865
1 /* packet-dec-bpdu.c
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
13 #include "config.h"
15 #include <epan/packet.h>
16 #include <epan/etypes.h>
17 #include <epan/ppptypes.h>
18 #include <epan/tfs.h>
20 /* Offsets of fields within a BPDU */
22 #define BPDU_DEC_CODE 0
23 #define BPDU_TYPE 1
24 #define BPDU_VERSION 2
25 #define BPDU_FLAGS 3
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
39 /* Flag bits */
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" },
74 { 0, NULL }
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" },
83 { 0, NULL }
86 static int
87 dissect_dec_bpdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
89 uint8_t bpdu_type;
90 proto_tree *bpdu_tree;
91 proto_item *ti;
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,
96 NULL
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);
110 if (tree) {
111 ti = proto_tree_add_item(tree, proto_dec_bpdu, tvb, 0, DEC_BPDU_SIZE,
112 ENC_NA);
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);
150 void
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,
158 NULL, HFILL }},
159 { &hf_dec_bpdu_type,
160 { "BPDU Type", "dec_stp.type",
161 FT_UINT8, BASE_DEC, VALS(bpdu_type_vals), 0x0,
162 NULL, HFILL }},
163 { &hf_dec_bpdu_version_id,
164 { "BPDU Version", "dec_stp.version",
165 FT_UINT8, BASE_DEC, NULL, 0x0,
166 NULL, HFILL }},
167 { &hf_dec_bpdu_flags,
168 { "BPDU flags", "dec_stp.flags",
169 FT_UINT8, BASE_HEX, NULL, 0x0,
170 NULL, HFILL }},
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,
174 NULL, HFILL }},
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,
178 NULL, HFILL }},
179 { &hf_dec_bpdu_flags_tc,
180 { "Topology Change", "dec_stp.flags.tc",
181 FT_BOOLEAN, 8, TFS(&tfs_yes_no), BPDU_FLAGS_TC,
182 NULL, HFILL }},
183 { &hf_dec_bpdu_root_pri,
184 { "Root Priority", "dec_stp.root.pri",
185 FT_UINT16, BASE_DEC, NULL, 0x0,
186 NULL, HFILL }},
187 { &hf_dec_bpdu_root_mac,
188 { "Root MAC", "dec_stp.root.mac",
189 FT_ETHER, BASE_NONE, NULL, 0x0,
190 NULL, HFILL }},
191 { &hf_dec_bpdu_root_cost,
192 { "Root Path Cost", "dec_stp.root.cost",
193 FT_UINT16, BASE_DEC, NULL, 0x0,
194 NULL, HFILL }},
195 { &hf_dec_bpdu_bridge_pri,
196 { "Bridge Priority", "dec_stp.bridge.pri",
197 FT_UINT16, BASE_DEC, NULL, 0x0,
198 NULL, HFILL }},
199 { &hf_dec_bpdu_bridge_mac,
200 { "Bridge MAC", "dec_stp.bridge.mac",
201 FT_ETHER, BASE_NONE, NULL, 0x0,
202 NULL, HFILL }},
203 { &hf_dec_bpdu_port_id,
204 { "Port identifier", "dec_stp.port",
205 FT_UINT8, BASE_DEC, NULL, 0x0,
206 NULL, HFILL }},
207 { &hf_dec_bpdu_msg_age,
208 { "Message Age", "dec_stp.msg_age",
209 FT_UINT8, BASE_DEC, NULL, 0x0,
210 NULL, HFILL }},
211 { &hf_dec_bpdu_hello_time,
212 { "Hello Time", "dec_stp.hello",
213 FT_UINT8, BASE_DEC, NULL, 0x0,
214 NULL, HFILL }},
215 { &hf_dec_bpdu_max_age,
216 { "Max Age", "dec_stp.max_age",
217 FT_UINT8, BASE_DEC, NULL, 0x0,
218 NULL, HFILL }},
219 { &hf_dec_bpdu_forward_delay,
220 { "Forward Delay", "dec_stp.forward",
221 FT_UINT8, BASE_DEC, NULL, 0x0,
222 NULL, HFILL }},
224 static int *ett[] = {
225 &ett_dec_bpdu,
226 &ett_dec_bpdu_flags,
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,
235 proto_dec_bpdu);
238 void
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
249 * Local variables:
250 * c-basic-offset: 4
251 * tab-width: 8
252 * indent-tabs-mode: nil
253 * End:
255 * vi: set shiftwidth=4 tabstop=8 expandtab:
256 * :indentSize=4:tabSize=8:noTabs=true: