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>
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 MMRP Protocol specification can be found at the following:
31 * http://standards.ieee.org/about/get/802/802.1.html
37 #include <epan/packet.h>
38 #include <epan/etypes.h>
40 /* MMRP End Mark Sequence */
41 #define MMRP_END_MARK 0x0000
43 /**********************************************************/
44 /* Offsets of fields within an MMRP packet */
45 /**********************************************************/
46 #define MMRP_PROTOCOL_VERSION_OFFSET 0
48 /* Next comes the MMRP Message group */
49 #define MMRP_MESSAGE_GROUP_OFFSET (MMRP_PROTOCOL_VERSION_OFFSET + 1) /* Message is a group of fields */
50 #define MMRP_ATTRIBUTE_TYPE_OFFSET (MMRP_MESSAGE_GROUP_OFFSET)
51 #define MMRP_ATTRIBUTE_LENGTH_OFFSET (MMRP_ATTRIBUTE_TYPE_OFFSET + 1)
53 /* Next comes the MMRP AttributeList group */
54 #define MMRP_ATTRIBUTE_LIST_GROUP_OFFSET (MMRP_ATTRIBUTE_LENGTH_OFFSET + 1) /* AttributeList is a group of fields */
56 /* Next comes the MMRP VectorAttribute group */
57 #define MMRP_VECTOR_ATTRIBUTE_GROUP_OFFSET (MMRP_ATTRIBUTE_LIST_GROUP_OFFSET) /* VectorAttribute is a group of fields */
58 #define MMRP_VECTOR_HEADER_OFFSET (MMRP_VECTOR_ATTRIBUTE_GROUP_OFFSET) /* contains the following two fields */
59 #define MMRP_LEAVE_ALL_EVENT_OFFSET (MMRP_VECTOR_HEADER_OFFSET)
60 #define MMRP_LEAVE_ALL_EVENT_MASK 0xE000
61 #define MMRP_NUMBER_OF_VALUES_OFFSET (MMRP_VECTOR_HEADER_OFFSET)
62 #define MMRP_NUMBER_OF_VALUES_MASK 0x1fff
64 /* Next comes the MMRP FirstValue group */
65 #define MMRP_FIRST_VALUE_GROUP_OFFSET (MMRP_VECTOR_HEADER_OFFSET + 2) /* FirstValue is a group of fields */
67 #define MMRP_SERVICE_THREE_PACKED_OFFSET (MMRP_FIRST_VALUE_GROUP_OFFSET + 1)
68 #define MMRP_MAC_THREE_PACKED_OFFSET (MMRP_FIRST_VALUE_GROUP_OFFSET + 6)
70 /**********************************************************/
71 /* Valid field contents */
72 /**********************************************************/
74 /* Attribute Type definitions */
75 #define MMRP_ATTRIBUTE_TYPE_SERVICE 0x01
76 #define MMRP_ATTRIBUTE_TYPE_MAC 0x02
77 static const value_string attribute_type_vals
[] = {
78 { MMRP_ATTRIBUTE_TYPE_SERVICE
, "Service Requirement" },
79 { MMRP_ATTRIBUTE_TYPE_MAC
, "MAC" },
83 /* Leave All Event definitions */
84 #define MMRP_NULLLEAVEALL 0
85 #define MMRP_LEAVEALL 1
86 static const value_string leave_all_vals
[] = {
87 { MMRP_NULLLEAVEALL
, "Null" },
88 { MMRP_LEAVEALL
, "Leave All" },
92 /* Three Packed Event definitions */
93 static const value_string three_packed_vals
[] = {
103 /**********************************************************/
104 /* Initialize the protocol and registered fields */
105 /**********************************************************/
106 static int proto_mmrp
= -1;
107 static int hf_mmrp_proto_id
= -1;
108 static int hf_mmrp_message
= -1; /* Message is a group of fields */
109 static int hf_mmrp_attribute_type
= -1;
110 static int hf_mmrp_attribute_length
= -1;
111 static int hf_mmrp_attribute_list
= -1; /* AttributeList is a group of fields */
112 static int hf_mmrp_vector_attribute
= -1; /* VectorAttribute is a group of fields */
114 /* The following VectorHeader contains the LeaveAllEvent and NumberOfValues */
115 static int hf_mmrp_vector_header
= -1;
116 static int hf_mmrp_leave_all_event
= -1;
117 static int hf_mmrp_number_of_values
= -1;
118 static gint ett_vector_header
= -1;
119 static const int *vector_header_fields
[] = {
120 &hf_mmrp_leave_all_event
,
121 &hf_mmrp_number_of_values
,
125 static int hf_mmrp_first_value
= -1; /* FirstValue is a group of fields */
127 static int hf_mmrp_three_packed_event
= -1;
129 static int hf_mmrp_end_mark
= -1;
131 /* Initialize the subtree pointers */
132 static gint ett_mmrp
= -1;
133 static gint ett_msg
= -1;
134 static gint ett_attr_list
= -1;
135 static gint ett_vect_attr
= -1;
136 static gint ett_first_value
= -1;
140 /**********************************************************/
141 /* Dissector starts here */
142 /**********************************************************/
144 /* dissect_mmrp_common1 (called from dissect_mmrp)
146 * dissect the following fields which are common to all MMRP attributes:
149 * Attribute List Length
152 dissect_mmrp_common1(proto_tree
*msg_tree
, tvbuff_t
*tvb
, int msg_offset
)
154 proto_tree_add_item(msg_tree
, hf_mmrp_attribute_type
, tvb
,
155 MMRP_ATTRIBUTE_TYPE_OFFSET
+ msg_offset
, 1, ENC_BIG_ENDIAN
);
156 proto_tree_add_item(msg_tree
, hf_mmrp_attribute_length
, tvb
,
157 MMRP_ATTRIBUTE_LENGTH_OFFSET
+ msg_offset
, 1, ENC_BIG_ENDIAN
);
161 /* dissect_mmrp_common2 (called from dissect_mmrp)
163 * dissect the following fields which are common to all MMRP attributes:
165 * Number of Values fields
168 dissect_mmrp_common2(proto_tree
*vect_attr_tree
, tvbuff_t
*tvb
, int msg_offset
)
170 proto_tree_add_bitmask(vect_attr_tree
, tvb
, MMRP_VECTOR_HEADER_OFFSET
+ msg_offset
,
171 hf_mmrp_vector_header
, ett_vector_header
, vector_header_fields
, ENC_BIG_ENDIAN
);
174 /* dissect_mmrp_three_packed_event (called from dissect_mmrp)
176 * dissect one or more ThreePackedEvents
179 dissect_mmrp_three_packed_event(proto_tree
*vect_attr_tree
, tvbuff_t
*tvb
, guint offset
, guint16 number_of_values
)
183 for ( counter
= 0; counter
< number_of_values
; ) {
185 guint8 three_packed_event
[3];
187 value
= tvb_get_guint8(tvb
, offset
);
188 three_packed_event
[0] = value
/ 36;
189 value
-= 36 * three_packed_event
[0];
190 three_packed_event
[1] = value
/ 6;
191 value
-= 6 * three_packed_event
[1];
192 three_packed_event
[2] = value
;
194 proto_tree_add_uint(vect_attr_tree
, hf_mmrp_three_packed_event
, tvb
, offset
, sizeof(guint8
),
195 three_packed_event
[0]);
197 if ( counter
< number_of_values
) {
198 proto_tree_add_uint(vect_attr_tree
, hf_mmrp_three_packed_event
, tvb
, offset
, sizeof(guint8
),
199 three_packed_event
[1]);
202 if ( counter
< number_of_values
) {
203 proto_tree_add_uint(vect_attr_tree
, hf_mmrp_three_packed_event
, tvb
, offset
, sizeof(guint8
),
204 three_packed_event
[2]);
215 * main dissect function that calls the other functions listed above as necessary
218 dissect_mmrp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
220 /* Set up structures needed to add the protocol subtrees and manage them */
221 proto_item
*ti
, *msg_ti
, *attr_list_ti
, *vect_attr_ti
;
222 proto_tree
*mmrp_tree
, *msg_tree
, *attr_list_tree
, *vect_attr_tree
;
224 /* Make entries in Protocol column and Info column on summary display */
225 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "MRP-MMRP");
227 col_set_str(pinfo
->cinfo
, COL_INFO
, "Multiple Mac Registration Protocol");
230 guint8 attribute_type
;
231 guint8 attribute_length
;
232 guint16 number_of_values
;
235 int msg_offset
; /* Use when handling multiple messages. This points to current msg being decoded. */
236 int vect_offset
; /* Use when handling multiple vector attributes. This points to the current vector attribute being decoded. */
238 ti
= proto_tree_add_item(tree
, proto_mmrp
, tvb
, 0, -1, ENC_NA
);
239 mmrp_tree
= proto_item_add_subtree(ti
, ett_mmrp
);
241 proto_tree_add_item(mmrp_tree
, hf_mmrp_proto_id
, tvb
, MMRP_PROTOCOL_VERSION_OFFSET
, 1, ENC_BIG_ENDIAN
);
243 /* MMRP supports multiple MRP Messages per frame. Handle those Messages in
244 * the following while() loop. You will know you are at the end of the list
245 * of messages when the EndMark (0x0000) is encountered instead of an
246 * Attribute Type and Attribute Length (guaranteed to not be 0x0000).
249 while (tvb_get_ntohs(tvb
, MMRP_ATTRIBUTE_TYPE_OFFSET
+ msg_offset
) != MMRP_END_MARK
) {
251 attribute_type
= tvb_get_guint8(tvb
, MMRP_ATTRIBUTE_TYPE_OFFSET
+ msg_offset
);
252 attribute_length
= tvb_get_guint8(tvb
, MMRP_ATTRIBUTE_LENGTH_OFFSET
+ msg_offset
);
254 /* MMRP Message is a group of fields
256 * Contains AttributeType (1 byte)
257 * + AttributeLength (1 byte)
258 * + AttributeList (AttributeListLength bytes)
261 msg_ti
= proto_tree_add_item(mmrp_tree
, hf_mmrp_message
, tvb
,
262 MMRP_MESSAGE_GROUP_OFFSET
+ msg_offset
,
264 msg_tree
= proto_item_add_subtree(msg_ti
, ett_msg
);
266 /* Append AttributeType description to the end of the "Message" heading */
267 proto_item_append_text(msg_tree
, ": %s (%d)",
268 val_to_str_const(attribute_type
, attribute_type_vals
, "<Unknown>"),
271 dissect_mmrp_common1(msg_tree
, tvb
, msg_offset
);
273 /* MMRP AttributeList is a group of fields
275 * Contains AttributeListLength bytes of data NOT
277 attr_list_ti
= proto_tree_add_item(msg_tree
, hf_mmrp_attribute_list
, tvb
,
278 MMRP_ATTRIBUTE_LIST_GROUP_OFFSET
+ msg_offset
,
280 attr_list_tree
= proto_item_add_subtree(attr_list_ti
, ett_attr_list
);
283 /* MMRP supports multiple MRP Vector Attributes per Attribute List. Handle those
284 * Vector Attributes in the following while() loop. You will know you are at the
285 * end of the list of Vector Attributes when the EndMark (0x0000) is encountered
286 * instead of a Vector Header (guaranteed to not be 0x0000).
289 while (tvb_get_ntohs(tvb
, MMRP_VECTOR_HEADER_OFFSET
+ msg_offset
+ vect_offset
) != MMRP_END_MARK
) {
290 /* MMRP VectorAttribute is a group of fields
292 * Contains VectorHeader (2 bytes)
293 * + FirstValue (AttributeLength bytes)
294 * + VectorThreePacked (NumberOfValues @ 3/vector bytes)
295 * + VectorFourPacked (NumberOfValues @ 4/vector bytes only for Listener attributes)
298 number_of_values
= tvb_get_ntohs(tvb
, MMRP_NUMBER_OF_VALUES_OFFSET
+ msg_offset
+ vect_offset
)
299 & MMRP_NUMBER_OF_VALUES_MASK
;
301 vect_attr_len
= 2 + attribute_length
+ (number_of_values
+ 2)/3; /* stores 3 values per byte */
303 vect_attr_ti
= proto_tree_add_item(attr_list_tree
, hf_mmrp_vector_attribute
, tvb
,
304 MMRP_VECTOR_ATTRIBUTE_GROUP_OFFSET
+ msg_offset
+ vect_offset
,
305 vect_attr_len
, ENC_NA
);
307 vect_attr_tree
= proto_item_add_subtree(vect_attr_ti
, ett_vect_attr
);
309 dissect_mmrp_common2(vect_attr_tree
, tvb
, msg_offset
+ vect_offset
);
311 if (attribute_type
== MMRP_ATTRIBUTE_TYPE_MAC
) {
312 /* MMRP FirstValue is a Mac Adress*/
313 proto_tree_add_item(vect_attr_tree
, hf_mmrp_first_value
, tvb
,
314 MMRP_FIRST_VALUE_GROUP_OFFSET
+ msg_offset
+ vect_offset
,
315 attribute_length
, ENC_NA
);
316 /* Decode three packed events. */
317 offset
= dissect_mmrp_three_packed_event(vect_attr_tree
, tvb
,
318 MMRP_MAC_THREE_PACKED_OFFSET
+ msg_offset
+ vect_offset
,
322 else if (attribute_type
== MMRP_ATTRIBUTE_TYPE_SERVICE
) {
323 /* MMRP Service Requierment*/
324 proto_tree_add_item(vect_attr_tree
, hf_mmrp_first_value
, tvb
,
325 MMRP_FIRST_VALUE_GROUP_OFFSET
+ msg_offset
+ vect_offset
,
326 attribute_length
, ENC_NA
);
327 offset
= dissect_mmrp_three_packed_event(vect_attr_tree
, tvb
,
328 MMRP_MAC_THREE_PACKED_OFFSET
+ msg_offset
+ vect_offset
,
333 vect_offset
+= vect_attr_len
; /* Move to next Vector Attribute, if there is one */
334 } /* Multiple VectorAttribute while() */
336 proto_tree_add_item(attr_list_tree
, hf_mmrp_end_mark
, tvb
, offset
, 2, ENC_NA
); /* VectorAttribute EndMark */
338 proto_item_set_len(attr_list_ti
, vect_offset
); /*without an endmark*/
339 msg_offset
+= vect_offset
+ 2; /* + endmark; Move to next Message, if there is one */
340 proto_item_set_len(msg_ti
, vect_offset
+ 2); /*length of message*/
342 } /* Multiple Message while() */
344 proto_tree_add_item(mmrp_tree
, hf_mmrp_end_mark
, tvb
, offset
+2, 2, ENC_NA
); /* Message EndMark */
349 /* Register the protocol with Wireshark */
351 proto_register_mrp_mmrp(void)
353 static hf_register_info hf
[] = {
355 { "Protocol Version", "mrp-mmrp.protocol_version",
356 FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}
358 { &hf_mmrp_message
, /* Message is a group of fields */
359 { "Message", "mrp-mmrp.message",
360 FT_NONE
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
362 { &hf_mmrp_attribute_type
,
363 { "Attribute Type", "mrp-mmrp.attribute_type",
364 FT_UINT8
, BASE_DEC
, VALS(attribute_type_vals
), 0x0, NULL
, HFILL
}
366 { &hf_mmrp_attribute_length
,
367 { "Attribute Length", "mrp-mmrp.attribute_length",
368 FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}
370 { &hf_mmrp_attribute_list
, /* AttributeList is a group of fields */
371 { "Attribute List", "mrp-mmrp.attribute_list",
372 FT_NONE
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
374 { &hf_mmrp_vector_attribute
, /* VectorAttribute is a group of fields */
375 { "Vector Attribute", "mrp-mmrp.vector_attribute",
376 FT_NONE
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
378 { &hf_mmrp_vector_header
,
379 { "Vector Header", "mrp-mmrp.vector_header",
380 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
382 { &hf_mmrp_leave_all_event
,
383 { "Leave All Event", "mrp-mmrp.leave_all_event",
384 FT_UINT16
, BASE_DEC
, VALS(leave_all_vals
), MMRP_LEAVE_ALL_EVENT_MASK
, NULL
, HFILL
}
386 { &hf_mmrp_number_of_values
,
387 { "Number of Values", "mrp-mmrp.number_of_values",
388 FT_UINT16
, BASE_DEC
, NULL
, MMRP_NUMBER_OF_VALUES_MASK
, NULL
, HFILL
}
390 { &hf_mmrp_first_value
, /* FirstValue is a group of fields */
391 { "First Value", "mrp-mmrp.first_value",
392 FT_NONE
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
394 { &hf_mmrp_three_packed_event
,
395 { "Attribute Event", "mrp-msrp.three_packed_event",
396 FT_UINT8
, BASE_DEC
, VALS(three_packed_vals
), 0x0, NULL
, HFILL
}
399 { "End Mark", "mrp-mmrp.end_mark",
400 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
404 /* Setup protocol subtree array */
405 static gint
*ett
[] = {
414 /* Register the protocol name and description */
415 proto_mmrp
= proto_register_protocol("Multiple Mac Registration Protocol",
416 "MRP-MMRP", "mrp-mmrp");
418 /* Required function calls to register the header fields and subtrees used */
419 proto_register_field_array(proto_mmrp
, hf
, array_length(hf
));
420 proto_register_subtree_array(ett
, array_length(ett
));
424 proto_reg_handoff_mrp_mmrp(void)
426 dissector_handle_t mmrp_handle
;
428 mmrp_handle
= create_dissector_handle(dissect_mmrp
, proto_mmrp
);
429 dissector_add_uint("ethertype", ETHERTYPE_MMRP
, mmrp_handle
);