2 * Routines for MMRP (MRP Multiple Mac Registration Protocol) dissection
3 * Copyright 2011, Johannes Jochen <johannes.jochen[AT]belden.com>
6 * Based on the code from packet-mrp-msrp.c (MSRP) from
7 * Torrey Atcitty <tatcitty[AT]harman.com> and Craig Gunther <craig.gunther[AT]harman.com>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald[AT]wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * SPDX-License-Identifier: GPL-2.0-or-later
16 * The MMRP Protocol specification can be found at the following:
17 * http://standards.ieee.org/about/get/802/802.1.html
23 #include <epan/packet.h>
24 #include <epan/etypes.h>
26 void proto_register_mrp_mmrp(void);
27 void proto_reg_handoff_mrp_mmrp(void);
29 /* MMRP End Mark Sequence */
30 #define MMRP_END_MARK 0x0000
32 /**********************************************************/
33 /* Offsets of fields within an MMRP packet */
34 /**********************************************************/
35 #define MMRP_PROTOCOL_VERSION_OFFSET 0
37 /* Next comes the MMRP Message group */
38 #define MMRP_MESSAGE_GROUP_OFFSET (MMRP_PROTOCOL_VERSION_OFFSET + 1) /* Message is a group of fields */
39 #define MMRP_ATTRIBUTE_TYPE_OFFSET (MMRP_MESSAGE_GROUP_OFFSET)
40 #define MMRP_ATTRIBUTE_LENGTH_OFFSET (MMRP_ATTRIBUTE_TYPE_OFFSET + 1)
42 /* Next comes the MMRP AttributeList group */
43 #define MMRP_ATTRIBUTE_LIST_GROUP_OFFSET (MMRP_ATTRIBUTE_LENGTH_OFFSET + 1) /* AttributeList is a group of fields */
45 /* Next comes the MMRP VectorAttribute group */
46 #define MMRP_VECTOR_ATTRIBUTE_GROUP_OFFSET (MMRP_ATTRIBUTE_LIST_GROUP_OFFSET) /* VectorAttribute is a group of fields */
47 #define MMRP_VECTOR_HEADER_OFFSET (MMRP_VECTOR_ATTRIBUTE_GROUP_OFFSET) /* contains the following two fields */
48 #define MMRP_LEAVE_ALL_EVENT_OFFSET (MMRP_VECTOR_HEADER_OFFSET)
49 #define MMRP_LEAVE_ALL_EVENT_MASK 0xE000
50 #define MMRP_NUMBER_OF_VALUES_OFFSET (MMRP_VECTOR_HEADER_OFFSET)
51 #define MMRP_NUMBER_OF_VALUES_MASK 0x1fff
53 /* Next comes the MMRP FirstValue group */
54 #define MMRP_FIRST_VALUE_GROUP_OFFSET (MMRP_VECTOR_HEADER_OFFSET + 2) /* FirstValue is a group of fields */
56 #define MMRP_SERVICE_THREE_PACKED_OFFSET (MMRP_FIRST_VALUE_GROUP_OFFSET + 1)
57 #define MMRP_MAC_THREE_PACKED_OFFSET (MMRP_FIRST_VALUE_GROUP_OFFSET + 6)
59 /**********************************************************/
60 /* Valid field contents */
61 /**********************************************************/
63 /* Attribute Type definitions */
64 #define MMRP_ATTRIBUTE_TYPE_SERVICE 0x01
65 #define MMRP_ATTRIBUTE_TYPE_MAC 0x02
66 static const value_string attribute_type_vals[] = {
67 { MMRP_ATTRIBUTE_TYPE_SERVICE, "Service Requirement" },
68 { MMRP_ATTRIBUTE_TYPE_MAC, "MAC" },
72 /* Leave All Event definitions */
73 #define MMRP_NULLLEAVEALL 0
74 #define MMRP_LEAVEALL 1
75 static const value_string leave_all_vals[] = {
76 { MMRP_NULLLEAVEALL, "Null" },
77 { MMRP_LEAVEALL, "Leave All" },
81 /* Three Packed Event definitions */
82 static const value_string three_packed_vals[] = {
92 /**********************************************************/
93 /* Initialize the protocol and registered fields */
94 /**********************************************************/
95 static int proto_mmrp = -1;
96 static int hf_mmrp_proto_id = -1;
97 static int hf_mmrp_message = -1; /* Message is a group of fields */
98 static int hf_mmrp_attribute_type = -1;
99 static int hf_mmrp_attribute_length = -1;
100 static int hf_mmrp_attribute_list = -1; /* AttributeList is a group of fields */
101 static int hf_mmrp_vector_attribute = -1; /* VectorAttribute is a group of fields */
103 /* The following VectorHeader contains the LeaveAllEvent and NumberOfValues */
104 static int hf_mmrp_vector_header = -1;
105 static int hf_mmrp_leave_all_event = -1;
106 static int hf_mmrp_number_of_values = -1;
107 static gint ett_vector_header = -1;
108 static const int *vector_header_fields[] = {
109 &hf_mmrp_leave_all_event,
110 &hf_mmrp_number_of_values,
114 static int hf_mmrp_first_value = -1; /* FirstValue is a group of fields */
116 static int hf_mmrp_three_packed_event = -1;
118 static int hf_mmrp_end_mark = -1;
120 /* Initialize the subtree pointers */
121 static gint ett_mmrp = -1;
122 static gint ett_msg = -1;
123 static gint ett_attr_list = -1;
124 static gint ett_vect_attr = -1;
125 static gint ett_first_value = -1;
129 /**********************************************************/
130 /* Dissector starts here */
131 /**********************************************************/
133 /* dissect_mmrp_common1 (called from dissect_mmrp)
135 * dissect the following fields which are common to all MMRP attributes:
138 * Attribute List Length
141 dissect_mmrp_common1(proto_tree *msg_tree, tvbuff_t *tvb, int msg_offset)
143 proto_tree_add_item(msg_tree, hf_mmrp_attribute_type, tvb,
144 MMRP_ATTRIBUTE_TYPE_OFFSET + msg_offset, 1, ENC_BIG_ENDIAN);
145 proto_tree_add_item(msg_tree, hf_mmrp_attribute_length, tvb,
146 MMRP_ATTRIBUTE_LENGTH_OFFSET + msg_offset, 1, ENC_BIG_ENDIAN);
150 /* dissect_mmrp_common2 (called from dissect_mmrp)
152 * dissect the following fields which are common to all MMRP attributes:
154 * Number of Values fields
157 dissect_mmrp_common2(proto_tree *vect_attr_tree, tvbuff_t *tvb, int msg_offset)
159 proto_tree_add_bitmask(vect_attr_tree, tvb, MMRP_VECTOR_HEADER_OFFSET + msg_offset,
160 hf_mmrp_vector_header, ett_vector_header, vector_header_fields, ENC_BIG_ENDIAN);
163 /* dissect_mmrp_three_packed_event (called from dissect_mmrp)
165 * dissect one or more ThreePackedEvents
168 dissect_mmrp_three_packed_event(proto_tree *vect_attr_tree, tvbuff_t *tvb, guint offset, guint16 number_of_values)
172 for ( counter = 0; counter < number_of_values; ) {
174 guint8 three_packed_event[3];
176 value = tvb_get_guint8(tvb, offset);
177 three_packed_event[0] = value / 36;
178 value -= 36 * three_packed_event[0];
179 three_packed_event[1] = value / 6;
180 value -= 6 * three_packed_event[1];
181 three_packed_event[2] = value;
183 proto_tree_add_uint(vect_attr_tree, hf_mmrp_three_packed_event, tvb, offset, sizeof(guint8),
184 three_packed_event[0]);
186 if ( counter < number_of_values ) {
187 proto_tree_add_uint(vect_attr_tree, hf_mmrp_three_packed_event, tvb, offset, sizeof(guint8),
188 three_packed_event[1]);
191 if ( counter < number_of_values ) {
192 proto_tree_add_uint(vect_attr_tree, hf_mmrp_three_packed_event, tvb, offset, sizeof(guint8),
193 three_packed_event[2]);
204 * main dissect function that calls the other functions listed above as necessary
207 dissect_mmrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) {
208 /* Set up structures needed to add the protocol subtrees and manage them */
209 proto_item *ti, *msg_ti, *attr_list_ti, *vect_attr_ti;
210 proto_tree *mmrp_tree, *msg_tree, *attr_list_tree, *vect_attr_tree;
212 /* Make entries in Protocol column and Info column on summary display */
213 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MRP-MMRP");
215 col_set_str(pinfo->cinfo, COL_INFO, "Multiple Mac Registration Protocol");
218 guint8 attribute_type;
219 guint8 attribute_length;
220 guint16 number_of_values;
223 int msg_offset; /* Use when handling multiple messages. This points to current msg being decoded. */
224 int vect_offset; /* Use when handling multiple vector attributes. This points to the current vector attribute being decoded. */
226 ti = proto_tree_add_item(tree, proto_mmrp, tvb, 0, -1, ENC_NA);
227 mmrp_tree = proto_item_add_subtree(ti, ett_mmrp);
229 proto_tree_add_item(mmrp_tree, hf_mmrp_proto_id, tvb, MMRP_PROTOCOL_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
231 /* MMRP supports multiple MRP Messages per frame. Handle those Messages in
232 * the following while() loop. You will know you are at the end of the list
233 * of messages when the EndMark (0x0000) is encountered instead of an
234 * Attribute Type and Attribute Length (guaranteed to not be 0x0000).
237 while (tvb_get_ntohs(tvb, MMRP_ATTRIBUTE_TYPE_OFFSET + msg_offset) != MMRP_END_MARK) {
239 attribute_type = tvb_get_guint8(tvb, MMRP_ATTRIBUTE_TYPE_OFFSET + msg_offset);
240 attribute_length = tvb_get_guint8(tvb, MMRP_ATTRIBUTE_LENGTH_OFFSET + msg_offset);
242 /* MMRP Message is a group of fields
244 * Contains AttributeType (1 byte)
245 * + AttributeLength (1 byte)
246 * + AttributeList (AttributeListLength bytes)
249 msg_ti = proto_tree_add_item(mmrp_tree, hf_mmrp_message, tvb,
250 MMRP_MESSAGE_GROUP_OFFSET + msg_offset,
252 msg_tree = proto_item_add_subtree(msg_ti, ett_msg);
254 /* Append AttributeType description to the end of the "Message" heading */
255 proto_item_append_text(msg_tree, ": %s (%d)",
256 val_to_str_const(attribute_type, attribute_type_vals, "<Unknown>"),
259 dissect_mmrp_common1(msg_tree, tvb, msg_offset);
261 /* MMRP AttributeList is a group of fields
263 * Contains AttributeListLength bytes of data NOT
265 attr_list_ti = proto_tree_add_item(msg_tree, hf_mmrp_attribute_list, tvb,
266 MMRP_ATTRIBUTE_LIST_GROUP_OFFSET + msg_offset,
268 attr_list_tree = proto_item_add_subtree(attr_list_ti, ett_attr_list);
271 /* MMRP supports multiple MRP Vector Attributes per Attribute List. Handle those
272 * Vector Attributes in the following while() loop. You will know you are at the
273 * end of the list of Vector Attributes when the EndMark (0x0000) is encountered
274 * instead of a Vector Header (guaranteed to not be 0x0000).
277 while (tvb_get_ntohs(tvb, MMRP_VECTOR_HEADER_OFFSET + msg_offset + vect_offset) != MMRP_END_MARK) {
278 /* MMRP VectorAttribute is a group of fields
280 * Contains VectorHeader (2 bytes)
281 * + FirstValue (AttributeLength bytes)
282 * + VectorThreePacked (NumberOfValues @ 3/vector bytes)
283 * + VectorFourPacked (NumberOfValues @ 4/vector bytes only for Listener attributes)
286 number_of_values = tvb_get_ntohs(tvb, MMRP_NUMBER_OF_VALUES_OFFSET + msg_offset + vect_offset)
287 & MMRP_NUMBER_OF_VALUES_MASK;
289 vect_attr_len = 2 + attribute_length + (number_of_values + 2)/3; /* stores 3 values per byte */
291 vect_attr_ti = proto_tree_add_item(attr_list_tree, hf_mmrp_vector_attribute, tvb,
292 MMRP_VECTOR_ATTRIBUTE_GROUP_OFFSET + msg_offset + vect_offset,
293 vect_attr_len, ENC_NA);
295 vect_attr_tree = proto_item_add_subtree(vect_attr_ti, ett_vect_attr);
297 dissect_mmrp_common2(vect_attr_tree, tvb, msg_offset + vect_offset);
299 if (attribute_type == MMRP_ATTRIBUTE_TYPE_MAC) {
300 /* MMRP FirstValue is a Mac Address*/
301 proto_tree_add_item(vect_attr_tree, hf_mmrp_first_value, tvb,
302 MMRP_FIRST_VALUE_GROUP_OFFSET + msg_offset + vect_offset,
303 attribute_length, ENC_NA);
304 /* Decode three packed events. */
305 offset = dissect_mmrp_three_packed_event(vect_attr_tree, tvb,
306 MMRP_MAC_THREE_PACKED_OFFSET + msg_offset + vect_offset,
310 else if (attribute_type == MMRP_ATTRIBUTE_TYPE_SERVICE) {
311 /* MMRP Service Requirement*/
312 proto_tree_add_item(vect_attr_tree, hf_mmrp_first_value, tvb,
313 MMRP_FIRST_VALUE_GROUP_OFFSET + msg_offset + vect_offset,
314 attribute_length, ENC_NA);
315 offset = dissect_mmrp_three_packed_event(vect_attr_tree, tvb,
316 MMRP_MAC_THREE_PACKED_OFFSET + msg_offset + vect_offset,
321 vect_offset += vect_attr_len; /* Move to next Vector Attribute, if there is one */
322 } /* Multiple VectorAttribute while() */
324 proto_tree_add_item(attr_list_tree, hf_mmrp_end_mark, tvb, offset, 2, ENC_BIG_ENDIAN); /* VectorAttribute EndMark */
326 proto_item_set_len(attr_list_ti, vect_offset); /*without an endmark*/
327 msg_offset += vect_offset + 2; /* + endmark; Move to next Message, if there is one */
328 proto_item_set_len(msg_ti, vect_offset + 2); /*length of message*/
330 } /* Multiple Message while() */
332 proto_tree_add_item(mmrp_tree, hf_mmrp_end_mark, tvb, offset+2, 2, ENC_BIG_ENDIAN); /* Message EndMark */
334 return tvb_captured_length(tvb);
338 /* Register the protocol with Wireshark */
340 proto_register_mrp_mmrp(void)
342 static hf_register_info hf[] = {
344 { "Protocol Version", "mrp-mmrp.protocol_version",
345 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
347 { &hf_mmrp_message, /* Message is a group of fields */
348 { "Message", "mrp-mmrp.message",
349 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
351 { &hf_mmrp_attribute_type,
352 { "Attribute Type", "mrp-mmrp.attribute_type",
353 FT_UINT8, BASE_DEC, VALS(attribute_type_vals), 0x0, NULL, HFILL }
355 { &hf_mmrp_attribute_length,
356 { "Attribute Length", "mrp-mmrp.attribute_length",
357 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
359 { &hf_mmrp_attribute_list, /* AttributeList is a group of fields */
360 { "Attribute List", "mrp-mmrp.attribute_list",
361 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
363 { &hf_mmrp_vector_attribute, /* VectorAttribute is a group of fields */
364 { "Vector Attribute", "mrp-mmrp.vector_attribute",
365 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
367 { &hf_mmrp_vector_header,
368 { "Vector Header", "mrp-mmrp.vector_header",
369 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
371 { &hf_mmrp_leave_all_event,
372 { "Leave All Event", "mrp-mmrp.leave_all_event",
373 FT_UINT16, BASE_DEC, VALS(leave_all_vals), MMRP_LEAVE_ALL_EVENT_MASK, NULL, HFILL }
375 { &hf_mmrp_number_of_values,
376 { "Number of Values", "mrp-mmrp.number_of_values",
377 FT_UINT16, BASE_DEC, NULL, MMRP_NUMBER_OF_VALUES_MASK, NULL, HFILL }
379 { &hf_mmrp_first_value, /* FirstValue is a group of fields */
380 { "First Value", "mrp-mmrp.first_value",
381 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
383 { &hf_mmrp_three_packed_event,
384 { "Attribute Event", "mrp-mmrp.three_packed_event",
385 FT_UINT8, BASE_DEC, VALS(three_packed_vals), 0x0, NULL, HFILL }
388 { "End Mark", "mrp-mmrp.end_mark",
389 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
393 /* Setup protocol subtree array */
394 static gint *ett[] = {
403 /* Register the protocol name and description */
404 proto_mmrp = proto_register_protocol("Multiple Mac Registration Protocol",
405 "MRP-MMRP", "mrp-mmrp");
407 /* Required function calls to register the header fields and subtrees used */
408 proto_register_field_array(proto_mmrp, hf, array_length(hf));
409 proto_register_subtree_array(ett, array_length(ett));
413 proto_reg_handoff_mrp_mmrp(void)
415 dissector_handle_t mmrp_handle;
417 mmrp_handle = create_dissector_handle(dissect_mmrp, proto_mmrp);
418 dissector_add_uint("ethertype", ETHERTYPE_MMRP, mmrp_handle);
422 * Editor modelines - http://www.wireshark.org/tools/modelines.html
427 * indent-tabs-mode: nil
430 * vi: set shiftwidth=4 tabstop=8 expandtab:
431 * :indentSize=4:tabSize=8:noTabs=true: