MSWSP: add ids for another unknown Property Set
[wireshark-wip.git] / epan / dissectors / packet-pw-eth.c
blob8ad4cab5a83604c304beaed28254f549774e21ed
1 /* packet-pw-eth.c
2 * Routines for ethernet PW dissection: it should conform to RFC 4448.
4 * Copyright 2008 _FF_
6 * Francesco Fondelli <francesco dot fondelli, gmail dot com>
8 * $Id$
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "config.h"
31 #include <glib.h>
33 #include <epan/packet.h>
34 #include <epan/addr_resolv.h>
36 #include "packet-mpls.h"
38 static gint proto_pw_eth_cw = -1;
39 static gint proto_pw_eth_nocw = -1;
40 static gint proto_pw_eth_heuristic = -1;
42 static gint ett_pw_eth = -1;
44 static int hf_pw_eth = -1;
45 static int hf_pw_eth_cw = -1;
46 static int hf_pw_eth_cw_sequence_number = -1;
48 static dissector_handle_t eth_withoutfcs_handle;
49 static dissector_handle_t pw_eth_handle_cw;
50 static dissector_handle_t pw_eth_handle_nocw;
52 static void
53 dissect_pw_eth_cw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
55 tvbuff_t *next_tvb;
56 guint16 sequence_number;
58 if (tvb_reported_length_remaining(tvb, 0) < 4) {
59 if (tree)
60 proto_tree_add_text(tree, tvb, 0, -1,
61 "Error processing Message");
62 return;
65 if (dissect_try_cw_first_nibble(tvb, pinfo, tree))
66 return;
68 sequence_number = tvb_get_ntohs(tvb, 2);
70 if (tree) {
71 proto_tree *pw_eth_tree;
72 proto_item *ti;
74 ti = proto_tree_add_boolean(tree, hf_pw_eth_cw,
75 tvb, 0, 0, TRUE);
76 PROTO_ITEM_SET_HIDDEN(ti);
77 ti = proto_tree_add_item(tree, proto_pw_eth_cw,
78 tvb, 0, 4, ENC_NA);
79 pw_eth_tree = proto_item_add_subtree(ti, ett_pw_eth);
81 proto_tree_add_uint_format(pw_eth_tree,
82 hf_pw_eth_cw_sequence_number,
83 tvb, 2, 2, sequence_number,
84 "Sequence Number: %d",
85 sequence_number);
88 next_tvb = tvb_new_subset_remaining(tvb, 4);
91 * When Ethernet frames being decoded, pinfo->ethertype is extracted
92 * from the top-level Ethernet frame. Dissection of Ethernet PW payload
93 * overwrites this value as the same dissector is invoked again.
94 * This may lead to undesired behavior (like disappearance of "Link"
95 * tab from the "Decode as" menu).
97 * Let's save/restore ethertype. --ATA
99 * XXX it looks that more pinfo members (or even the whole pinfo)
100 * XXX should be saved/restored in PW cases. Multilayer encapsulations,
101 * XXX like ethernet/mpls/ethernet-pw/ip/vlan, may lead to undesired
102 * XXX changes if pinfo->ipproto, ptype etc.
104 guint32 etype_save = pinfo->ethertype;
105 call_dissector(eth_withoutfcs_handle, next_tvb, pinfo, tree);
106 pinfo->ethertype = etype_save;
110 static void
111 dissect_pw_eth_nocw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
113 tvbuff_t *next_tvb;
115 if (tree) {
116 proto_item *ti;
117 ti = proto_tree_add_boolean(tree, hf_pw_eth, tvb, 0, 0, TRUE);
118 PROTO_ITEM_SET_HIDDEN(ti);
121 next_tvb = tvb_new_subset_remaining(tvb, 0);
123 guint32 etype_save = pinfo->ethertype;
124 call_dissector(eth_withoutfcs_handle, next_tvb, pinfo, tree);
125 pinfo->ethertype = etype_save;
130 * FF: this function returns TRUE if the first 12 bytes in tvb looks like
131 * two valid ethernet addresses. FALSE otherwise.
133 static gboolean
134 looks_like_plain_eth(tvbuff_t *tvb _U_)
136 const gchar *manuf_name_da;
137 const gchar *manuf_name_sa;
139 if (tvb_reported_length_remaining(tvb, 0) < 14) {
140 return FALSE;
143 manuf_name_da = tvb_get_manuf_name_if_known(tvb, 0);
144 manuf_name_sa = tvb_get_manuf_name_if_known(tvb, 6);
146 if (manuf_name_da && manuf_name_sa) {
147 return TRUE;
150 return FALSE;
153 static void
154 dissect_pw_eth_heuristic(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
156 guint8 first_nibble = (tvb_get_guint8(tvb, 0) >> 4) & 0x0F;
158 if (looks_like_plain_eth(tvb))
159 call_dissector(pw_eth_handle_nocw, tvb, pinfo, tree);
160 else if (first_nibble == 0)
161 call_dissector(pw_eth_handle_cw, tvb, pinfo, tree);
162 else
163 call_dissector(pw_eth_handle_nocw, tvb, pinfo, tree);
166 void
167 proto_register_pw_eth(void)
169 static hf_register_info hf[] = {
171 &hf_pw_eth,
173 "PW (ethernet)",
174 "pweth", FT_BOOLEAN,
175 BASE_NONE, NULL, 0x0, NULL, HFILL
179 &hf_pw_eth_cw,
181 "PW Control Word (ethernet)",
182 "pweth.cw", FT_BOOLEAN,
183 BASE_NONE, NULL, 0x0, NULL, HFILL
187 &hf_pw_eth_cw_sequence_number,
189 "PW sequence number (ethernet)",
190 "pweth.cw.sequence_number", FT_UINT16,
191 BASE_DEC, NULL, 0x0, NULL, HFILL
196 static gint *ett[] = {
197 &ett_pw_eth
200 proto_pw_eth_cw =
201 proto_register_protocol("PW Ethernet Control Word",
202 "Ethernet PW (with CW)",
203 "pwethcw");
204 proto_pw_eth_nocw =
205 proto_register_protocol("Ethernet PW (no CW)", /* not displayed */
206 "Ethernet PW (no CW)",
207 "pwethnocw");
208 proto_pw_eth_heuristic =
209 proto_register_protocol("Ethernet PW (CW heuristic)", /* not disp. */
210 "Ethernet PW (CW heuristic)",
211 "pwethheuristic");
212 proto_register_field_array(proto_pw_eth_cw, hf, array_length(hf));
213 proto_register_subtree_array(ett, array_length(ett));
214 register_dissector("pw_eth_cw", dissect_pw_eth_cw, proto_pw_eth_cw);
215 register_dissector("pw_eth_nocw", dissect_pw_eth_nocw,
216 proto_pw_eth_nocw);
217 register_dissector("pw_eth_heuristic", dissect_pw_eth_heuristic,
218 proto_pw_eth_heuristic);
221 void
222 proto_reg_handoff_pw_eth(void)
224 dissector_handle_t pw_eth_handle_heuristic;
226 eth_withoutfcs_handle = find_dissector("eth_withoutfcs");
228 pw_eth_handle_cw = find_dissector("pw_eth_cw");
229 dissector_add_uint("mpls.label", MPLS_LABEL_INVALID, pw_eth_handle_cw);
231 pw_eth_handle_nocw = find_dissector("pw_eth_nocw");
232 dissector_add_uint("mpls.label", MPLS_LABEL_INVALID, pw_eth_handle_nocw);
234 pw_eth_handle_heuristic = find_dissector("pw_eth_heuristic");
235 dissector_add_uint("mpls.label", MPLS_LABEL_INVALID, pw_eth_handle_heuristic);
239 * Editor modelines - http://www.wireshark.org/tools/modelines.html
241 * Local variables:
242 * c-basic-offset: 4
243 * tab-width: 8
244 * indent-tabs-mode: nil
245 * End:
247 * vi: set shiftwidth=4 tabstop=8 expandtab:
248 * :indentSize=4:tabSize=8:noTabs=true: