HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-mrp-mvrp.c
blobfa61276320dbf3627ef148ba21de58b2ebf7aaa1
1 /* packet-mrp_mvrp.c
2 * Routines for MVRP (MRP Multiple VLAN Registration Protocol) dissection
3 * Copyright 2011, Pascal Levesque <plevesque[AT]orthogone.ca>
6 * Based on the code from packet-mrp-mmrp.c (MMRP) from
7 * Johannes Jochen <johannes.jochen[AT]belden.com>
8 * Copyright 2011
10 * $Id$
12 * Wireshark - Network traffic analyzer
13 * By Gerald Combs <gerald[AT]wireshark.org>
14 * Copyright 1998 Gerald Combs
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 * The MVRP Protocol specification can be found at the following:
31 * http://standards.ieee.org/about/get/802/802.1.html
35 #include "config.h"
37 #include <epan/packet.h>
38 #include <epan/etypes.h>
40 /* MVRP End Mark Sequence */
41 #define MVRP_END_MARK 0x0000
43 /**********************************************************/
44 /* Offsets of fields within an MVRP packet */
45 /**********************************************************/
46 #define MVRP_PROTOCOL_VERSION_OFFSET 0
48 /* Next comes the MVRP Message group */
49 #define MVRP_MESSAGE_GROUP_OFFSET (MVRP_PROTOCOL_VERSION_OFFSET + 1) /* Message is a group of fields */
50 #define MVRP_ATTRIBUTE_TYPE_OFFSET (MVRP_MESSAGE_GROUP_OFFSET)
51 #define MVRP_ATTRIBUTE_LENGTH_OFFSET (MVRP_ATTRIBUTE_TYPE_OFFSET + 1)
53 /* Next comes the MVRP AttributeList group */
54 #define MVRP_ATTRIBUTE_LIST_GROUP_OFFSET (MVRP_ATTRIBUTE_LENGTH_OFFSET + 1) /* AttributeList is a group of fields */
56 /* Next comes the MVRP VectorAttribute group */
57 #define MVRP_VECTOR_ATTRIBUTE_GROUP_OFFSET (MVRP_ATTRIBUTE_LIST_GROUP_OFFSET) /* VectorAttribute is a group of fields */
58 #define MVRP_VECTOR_HEADER_OFFSET (MVRP_VECTOR_ATTRIBUTE_GROUP_OFFSET) /* contains the following two fields */
59 #define MVRP_LEAVE_ALL_EVENT_OFFSET (MVRP_VECTOR_HEADER_OFFSET)
60 #define MVRP_LEAVE_ALL_EVENT_MASK 0xE000
61 #define MVRP_NUMBER_OF_VALUES_OFFSET (MVRP_VECTOR_HEADER_OFFSET)
62 #define MVRP_NUMBER_OF_VALUES_MASK 0x1fff
64 /* Next comes the MVRP FirstValue group */
65 #define MVRP_FIRST_VALUE_GROUP_OFFSET (MVRP_VECTOR_HEADER_OFFSET + 2) /* FirstValue is a group of fields */
67 #define MVRP_VID_THREE_PACKED_OFFSET (MVRP_FIRST_VALUE_GROUP_OFFSET + 2)
69 /**********************************************************/
70 /* Valid field contents */
71 /**********************************************************/
73 /* Attribute Type definitions */
74 #define MVRP_ATTRIBUTE_TYPE_VID 0x01
75 static const value_string attribute_type_vals[] = {
76 { MVRP_ATTRIBUTE_TYPE_VID, "VLAN Identifier" },
77 { 0, NULL }
80 /* Leave All Event definitions */
81 #define MVRP_NULLLEAVEALL 0
82 #define MVRP_LEAVEALL 1
83 static const value_string leave_all_vals[] = {
84 { MVRP_NULLLEAVEALL, "Null" },
85 { MVRP_LEAVEALL, "Leave All" },
86 { 0, NULL }
89 /* Three Packed Event definitions */
90 static const value_string three_packed_vals[] = {
91 { 0, "New" },
92 { 1, "JoinIn" },
93 { 2, "In" },
94 { 3, "JoinMt" },
95 { 4, "Mt" },
96 { 5, "Lv" },
97 { 0, NULL }
100 /**********************************************************/
101 /* Initialize the protocol and registered fields */
102 /**********************************************************/
103 static int proto_mvrp = -1;
104 static int hf_mvrp_proto_id = -1;
105 static int hf_mvrp_message = -1; /* Message is a group of fields */
106 static int hf_mvrp_attribute_type = -1;
107 static int hf_mvrp_attribute_length = -1;
108 static int hf_mvrp_attribute_list = -1; /* AttributeList is a group of fields */
109 static int hf_mvrp_vector_attribute = -1; /* VectorAttribute is a group of fields */
111 /* The following VectorHeader contains the LeaveAllEvent and NumberOfValues */
112 static int hf_mvrp_vector_header = -1;
113 static int hf_mvrp_leave_all_event = -1;
114 static int hf_mvrp_number_of_values = -1;
115 static gint ett_vector_header = -1;
116 static const int *vector_header_fields[] = {
117 &hf_mvrp_leave_all_event,
118 &hf_mvrp_number_of_values,
119 NULL
122 static int hf_mvrp_first_value = -1; /* FirstValue is a group of fields */
123 static int hf_mvrp_vid = -1;
124 static int hf_mvrp_three_packed_event = -1;
126 static int hf_mvrp_end_mark = -1;
128 /* Initialize the subtree pointers */
129 static gint ett_mvrp = -1;
130 static gint ett_msg = -1;
131 static gint ett_attr_list = -1;
132 static gint ett_vect_attr = -1;
133 static gint ett_first_value = -1;
137 /**********************************************************/
138 /* Dissector starts here */
139 /**********************************************************/
141 /* dissect_mvrp_common1 (called from dissect_mvrp)
143 * dissect the following fields which are common to all MVRP attributes:
144 * Attribute Type
145 * Attribute Length
146 * Attribute List Length
148 static void
149 dissect_mvrp_common1(proto_tree *msg_tree, tvbuff_t *tvb, int msg_offset)
151 proto_tree_add_item(msg_tree, hf_mvrp_attribute_type, tvb,
152 MVRP_ATTRIBUTE_TYPE_OFFSET + msg_offset, 1, ENC_BIG_ENDIAN);
153 proto_tree_add_item(msg_tree, hf_mvrp_attribute_length, tvb,
154 MVRP_ATTRIBUTE_LENGTH_OFFSET + msg_offset, 1, ENC_BIG_ENDIAN);
158 /* dissect_mvrp_common2 (called from dissect_mvrp)
160 * dissect the following fields which are common to all MVRP attributes:
161 * Leave All Event
162 * Number of Values fields
164 static void
165 dissect_mvrp_common2(proto_tree *vect_attr_tree, tvbuff_t *tvb, int msg_offset)
167 proto_tree_add_bitmask(vect_attr_tree, tvb, MVRP_VECTOR_HEADER_OFFSET + msg_offset,
168 hf_mvrp_vector_header, ett_vector_header, vector_header_fields, ENC_BIG_ENDIAN);
171 /* dissect_mvrp_three_packed_event (called from dissect_mvrp)
173 * dissect one or more ThreePackedEvents
175 static guint
176 dissect_mvrp_three_packed_event(proto_tree *vect_attr_tree, tvbuff_t *tvb, guint offset, guint16 number_of_values)
178 guint counter;
180 for ( counter = 0; counter < number_of_values; ) {
181 guint8 value;
182 guint8 three_packed_event[3];
184 value = tvb_get_guint8(tvb, offset);
185 three_packed_event[0] = value / 36;
186 value -= 36 * three_packed_event[0];
187 three_packed_event[1] = value / 6;
188 value -= 6 * three_packed_event[1];
189 three_packed_event[2] = value;
191 proto_tree_add_uint(vect_attr_tree, hf_mvrp_three_packed_event, tvb, offset, sizeof(guint8),
192 three_packed_event[0]);
193 counter++;
194 if ( counter < number_of_values ) {
195 proto_tree_add_uint(vect_attr_tree, hf_mvrp_three_packed_event, tvb, offset, sizeof(guint8),
196 three_packed_event[1]);
197 counter++;
199 if ( counter < number_of_values ) {
200 proto_tree_add_uint(vect_attr_tree, hf_mvrp_three_packed_event, tvb, offset, sizeof(guint8),
201 three_packed_event[2]);
202 counter++;
205 offset++;
207 return( offset );
210 /* dissect_main
212 * main dissect function that calls the other functions listed above as necessary
214 static void
215 dissect_mvrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
217 /* Set up structures needed to add the protocol subtrees and manage them */
218 proto_item *ti, *msg_ti, *attr_list_ti, *vect_attr_ti, *first_value_ti;
219 proto_tree *mvrp_tree, *msg_tree, *attr_list_tree, *vect_attr_tree, *first_value_tree;
221 /* Make entries in Protocol column and Info column on summary display */
222 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MRP-MVRP");
224 col_set_str(pinfo->cinfo, COL_INFO, "Multiple VLAN Registration Protocol");
226 if (tree) {
227 guint8 attribute_type;
228 guint8 attribute_length;
229 guint16 number_of_values;
230 guint offset = 0;
231 int vect_attr_len;
232 int msg_offset; /* Use when handling multiple messages. This points to current msg being decoded. */
233 int vect_offset; /* Use when handling multiple vector attributes. This points to the current vector attribute being decoded. */
235 ti = proto_tree_add_item(tree, proto_mvrp, tvb, 0, -1, ENC_NA);
236 mvrp_tree = proto_item_add_subtree(ti, ett_mvrp);
238 proto_tree_add_item(mvrp_tree, hf_mvrp_proto_id, tvb, MVRP_PROTOCOL_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
240 /* MVRP supports multiple MRP Messages per frame. Handle those Messages in
241 * the following while() loop. You will know you are at the end of the list
242 * of messages when the EndMark (0x0000) is encountered instead of an
243 * Attribute Type and Attribute Length (guaranteed to not be 0x0000).
245 msg_offset = 0;
246 while (tvb_get_ntohs(tvb, MVRP_ATTRIBUTE_TYPE_OFFSET + msg_offset) != MVRP_END_MARK) {
248 attribute_type = tvb_get_guint8(tvb, MVRP_ATTRIBUTE_TYPE_OFFSET + msg_offset);
249 attribute_length = tvb_get_guint8(tvb, MVRP_ATTRIBUTE_LENGTH_OFFSET + msg_offset);
251 /* MVRP Message is a group of fields
253 * Contains AttributeType (1 byte)
254 * + AttributeLength (1 byte)
255 * + AttributeList (AttributeListLength bytes)
256 * bytes of data
258 msg_ti = proto_tree_add_item(mvrp_tree, hf_mvrp_message, tvb,
259 MVRP_MESSAGE_GROUP_OFFSET + msg_offset,
260 -1, ENC_NA);
261 msg_tree = proto_item_add_subtree(msg_ti, ett_msg);
263 /* Append AttributeType description to the end of the "Message" heading */
264 proto_item_append_text(msg_tree, ": %s (%d)",
265 val_to_str_const(attribute_type, attribute_type_vals, "<Unknown>"),
266 attribute_type);
268 dissect_mvrp_common1(msg_tree, tvb, msg_offset);
270 /* MVRP AttributeList is a group of fields
272 * Contains AttributeListLength bytes of data NOT
274 attr_list_ti = proto_tree_add_item(msg_tree, hf_mvrp_attribute_list, tvb,
275 MVRP_ATTRIBUTE_LIST_GROUP_OFFSET + msg_offset,
276 -1, ENC_NA);
277 attr_list_tree = proto_item_add_subtree(attr_list_ti, ett_attr_list);
280 /* MVRP supports multiple MRP Vector Attributes per Attribute List. Handle those
281 * Vector Attributes in the following while() loop. You will know you are at the
282 * end of the list of Vector Attributes when the EndMark (0x0000) is encountered
283 * instead of a Vector Header (guaranteed to not be 0x0000).
285 vect_offset = 0;
286 while (tvb_get_ntohs(tvb, MVRP_VECTOR_HEADER_OFFSET + msg_offset + vect_offset) != MVRP_END_MARK) {
287 /* MVRP VectorAttribute is a group of fields
289 * Contains VectorHeader (2 bytes)
290 * + FirstValue (AttributeLength bytes)
291 * + VectorThreePacked (NumberOfValues @ 3/vector bytes)
292 * + VectorFourPacked (NumberOfValues @ 4/vector bytes only for Listener attributes)
293 * bytes of data
295 number_of_values = tvb_get_ntohs(tvb, MVRP_NUMBER_OF_VALUES_OFFSET + msg_offset + vect_offset)
296 & MVRP_NUMBER_OF_VALUES_MASK;
298 vect_attr_len = 2 + attribute_length + (number_of_values + 2)/3; /* stores 3 values per byte */
300 vect_attr_ti = proto_tree_add_item(attr_list_tree, hf_mvrp_vector_attribute, tvb,
301 MVRP_VECTOR_ATTRIBUTE_GROUP_OFFSET + msg_offset + vect_offset,
302 vect_attr_len, ENC_NA);
304 vect_attr_tree = proto_item_add_subtree(vect_attr_ti, ett_vect_attr);
306 dissect_mvrp_common2(vect_attr_tree, tvb, msg_offset + vect_offset);
308 if (attribute_type == MVRP_ATTRIBUTE_TYPE_VID) {
309 /* MVRP VLAN ID FirstValue is a group of fields
311 * Contains VID (2 bytes)
312 * bytes of data
314 first_value_ti = proto_tree_add_item(vect_attr_tree, hf_mvrp_first_value, tvb,
315 MVRP_FIRST_VALUE_GROUP_OFFSET + msg_offset + vect_offset,
316 attribute_length, ENC_NA);
317 first_value_tree = proto_item_add_subtree(first_value_ti, ett_first_value);
319 /* Add VLAN components to First Value tree */
320 proto_tree_add_item(first_value_tree, hf_mvrp_vid, tvb,
321 MVRP_FIRST_VALUE_GROUP_OFFSET + msg_offset + vect_offset, 2, ENC_BIG_ENDIAN);
323 /* Decode three packed events. */
324 offset = dissect_mvrp_three_packed_event(vect_attr_tree, tvb,
325 MVRP_VID_THREE_PACKED_OFFSET + msg_offset + vect_offset,
326 number_of_values);
330 vect_offset += vect_attr_len; /* Move to next Vector Attribute, if there is one */
331 } /* Multiple VectorAttribute while() */
333 proto_tree_add_item(attr_list_tree, hf_mvrp_end_mark, tvb, offset, 2, ENC_NA); /* VectorAttribute EndMark */
335 proto_item_set_len(attr_list_ti, vect_offset); /*without an endmark*/
336 msg_offset += vect_offset + 2; /* + endmark; Move to next Message, if there is one */
337 proto_item_set_len(msg_ti, vect_offset + 2); /*length of message*/
339 } /* Multiple Message while() */
341 proto_tree_add_item(mvrp_tree, hf_mvrp_end_mark, tvb, offset+2, 2, ENC_NA); /* Message EndMark */
346 /* Register the protocol with Wireshark */
347 void
348 proto_register_mrp_mvrp(void)
350 static hf_register_info hf[] = {
351 { &hf_mvrp_proto_id,
352 { "Protocol Version", "mrp-mvrp.protocol_version",
353 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
355 { &hf_mvrp_message, /* Message is a group of fields */
356 { "Message", "mrp-mvrp.message",
357 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
359 { &hf_mvrp_attribute_type,
360 { "Attribute Type", "mrp-mvrp.attribute_type",
361 FT_UINT8, BASE_DEC, VALS(attribute_type_vals), 0x0, NULL, HFILL }
363 { &hf_mvrp_attribute_length,
364 { "Attribute Length", "mrp-mvrp.attribute_length",
365 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
367 { &hf_mvrp_attribute_list, /* AttributeList is a group of fields */
368 { "Attribute List", "mrp-mvrp.attribute_list",
369 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
371 { &hf_mvrp_vector_attribute, /* VectorAttribute is a group of fields */
372 { "Vector Attribute", "mrp-mvrp.vector_attribute",
373 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
375 { &hf_mvrp_vector_header,
376 { "Vector Header", "mrp-mvrp.vector_header",
377 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
379 { &hf_mvrp_leave_all_event,
380 { "Leave All Event", "mrp-mvrp.leave_all_event",
381 FT_UINT16, BASE_DEC, VALS(leave_all_vals), MVRP_LEAVE_ALL_EVENT_MASK, NULL, HFILL }
383 { &hf_mvrp_number_of_values,
384 { "Number of Values", "mrp-mvrp.number_of_values",
385 FT_UINT16, BASE_DEC, NULL, MVRP_NUMBER_OF_VALUES_MASK, NULL, HFILL }
387 { &hf_mvrp_first_value, /* FirstValue is a group of fields */
388 { "First Value", "mrp-mvrp.first_value",
389 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
391 { &hf_mvrp_vid,
392 { "VLAN ID", "mrp-mvrp.vid",
393 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
395 { &hf_mvrp_three_packed_event,
396 { "Attribute Event", "mrp-msrp.three_packed_event",
397 FT_UINT8, BASE_DEC, VALS(three_packed_vals), 0x0, NULL, HFILL }
399 { &hf_mvrp_end_mark,
400 { "End Mark", "mrp-mvrp.end_mark",
401 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
405 /* Setup protocol subtree array */
406 static gint *ett[] = {
407 &ett_mvrp,
408 &ett_msg,
409 &ett_attr_list,
410 &ett_vect_attr,
411 &ett_vector_header,
412 &ett_first_value
415 /* Register the protocol name and description */
416 proto_mvrp = proto_register_protocol("Multiple VLAN Registration Protocol",
417 "MRP-MVRP", "mrp-mvrp");
419 /* Required function calls to register the header fields and subtrees used */
420 proto_register_field_array(proto_mvrp, hf, array_length(hf));
421 proto_register_subtree_array(ett, array_length(ett));
424 void
425 proto_reg_handoff_mrp_mvrp(void)
427 dissector_handle_t mvrp_handle;
429 mvrp_handle = create_dissector_handle(dissect_mvrp, proto_mvrp);
430 dissector_add_uint("ethertype", ETHERTYPE_MVRP, mvrp_handle);
433 * Editor modelines - http://www.wireshark.org/tools/modelines.html
435 * Local variables:
436 * c-basic-offset: 4
437 * tab-width: 8
438 * indent-tabs-mode: nil
439 * End:
441 * ex: set shiftwidth=4 tabstop=8 expandtab:
442 * :indentSize=4:tabSize=8:noTabs=true: