FIXUP: WIP: verification_trailer
[wireshark-wip.git] / epan / dissectors / packet-mrp-msrp.c
blobc762d520e004d0fc361b62cd91b1684c195f92c0
1 /* packet-mrp_msrp.c
2 * Routines for MSRP (MRP Multiple Stream Reservation Protocol) dissection
3 * Copyright 2010, Torrey Atcitty <tatcitty@harman.com>
4 * Craig Gunther <craig.gunther@harman.com>
6 * Based on the code from packet-mmrp.c (MMRP) from
7 * Markus Seehofer <mseehofe@nt.hirschmann.de> Copyright 2001
9 * $Id$
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 * The MSRP Protocol specification can be found at the following:
30 * http://www.ieee802.org/1/files/private/at-drafts/d6/802-1at-d6-0.pdf
34 #include "config.h"
36 #include <glib.h>
37 #include <epan/packet.h>
38 #include <epan/etypes.h>
40 /* MSRP End Mark Sequence */
41 #define MSRP_END_MARK 0x0000
43 /**********************************************************/
44 /* Offsets of fields within an MSRP packet */
45 /**********************************************************/
46 #define MSRP_PROTOCOL_VERSION_OFFSET 0
48 /* Next comes the MSRP Message group */
49 #define MSRP_MESSAGE_GROUP_OFFSET (MSRP_PROTOCOL_VERSION_OFFSET + 1) /* Message is a group of fields */
50 #define MSRP_ATTRIBUTE_TYPE_OFFSET (MSRP_MESSAGE_GROUP_OFFSET)
51 #define MSRP_ATTRIBUTE_LENGTH_OFFSET (MSRP_ATTRIBUTE_TYPE_OFFSET + 1)
52 #define MSRP_ATTRIBUTE_LIST_LENGTH_OFFSET (MSRP_ATTRIBUTE_LENGTH_OFFSET + 1)
54 /* Next comes the MSRP AttributeList group */
55 #define MSRP_ATTRIBUTE_LIST_GROUP_OFFSET (MSRP_ATTRIBUTE_LIST_LENGTH_OFFSET + 2) /* AttributeList is a group of fields */
57 /* Next comes the MSRP VectorAttribute group */
58 #define MSRP_VECTOR_ATTRIBUTE_GROUP_OFFSET (MSRP_ATTRIBUTE_LIST_GROUP_OFFSET) /* VectorAttribute is a group of fields */
59 #define MSRP_VECTOR_HEADER_OFFSET (MSRP_VECTOR_ATTRIBUTE_GROUP_OFFSET) /* contains the following two fields */
60 #define MSRP_LEAVE_ALL_EVENT_OFFSET (MSRP_VECTOR_HEADER_OFFSET)
61 #define MSRP_LEAVE_ALL_EVENT_MASK 0xE000
62 #define MSRP_NUMBER_OF_VALUES_OFFSET (MSRP_VECTOR_HEADER_OFFSET)
63 #define MSRP_NUMBER_OF_VALUES_MASK 0x1fff
65 /* Next comes the MSRP FirstValue group */
66 #define MSRP_FIRST_VALUE_GROUP_OFFSET (MSRP_VECTOR_HEADER_OFFSET + 2) /* FirstValue is a group of fields */
67 #define MSRP_STREAM_ID_OFFSET (MSRP_FIRST_VALUE_GROUP_OFFSET)
68 #define MSRP_STREAM_DA_OFFSET (MSRP_STREAM_ID_OFFSET + 8)
69 #define MSRP_VLAN_ID_OFFSET (MSRP_STREAM_DA_OFFSET + 6)
70 #define MSRP_TSPEC_MAX_FRAME_SIZE_OFFSET (MSRP_VLAN_ID_OFFSET + 2)
71 #define MSRP_TSPEC_MAX_INTERVAL_FRAMES_OFFSET (MSRP_TSPEC_MAX_FRAME_SIZE_OFFSET + 2)
72 #define MSRP_PRIORITY_AND_RANK_OFFSET (MSRP_TSPEC_MAX_INTERVAL_FRAMES_OFFSET + 2) /* contains the following two fields */
73 #define MSRP_PRIORITY_OFFSET (MSRP_PRIORITY_AND_RANK_OFFSET)
74 #define MSRP_PRIORITY_MASK 0xe0
75 #define MSRP_RANK_OFFSET (MSRP_PRIORITY_AND_RANK_OFFSET)
76 #define MSRP_RANK_MASK 0x10
77 #define MSRP_RESERVED_OFFSET (MSRP_PRIORITY_AND_RANK_OFFSET)
78 #define MSRP_RESERVED_MASK 0x0F
79 #define MSRP_ACCUMULATED_LATENCY_OFFSET (MSRP_PRIORITY_AND_RANK_OFFSET + 1)
80 #define MSRP_FAILURE_BRIDGE_ID_OFFSET (MSRP_ACCUMULATED_LATENCY_OFFSET + 4)
81 #define MSRP_FAILURE_CODE_OFFSET (MSRP_FAILURE_BRIDGE_ID_OFFSET + 8)
83 #define MSRP_DOMAIN_THREE_PACKED_OFFSET (MSRP_FIRST_VALUE_GROUP_OFFSET + 4)
84 #define MSRP_LISTENER_THREE_PACKED_OFFSET (MSRP_STREAM_ID_OFFSET + 8)
85 #define MSRP_TALKER_ADVERTISE_THREE_PACKED_OFFSET (MSRP_ACCUMULATED_LATENCY_OFFSET + 4)
86 #define MSRP_TALKER_FAILED_THREE_PACKED_OFFSET (MSRP_FAILURE_CODE_OFFSET + 1)
88 /**********************************************************/
89 /* Valid field contents */
90 /**********************************************************/
92 /* Attribute Type definitions */
93 #define MSRP_ATTRIBUTE_TYPE_TALKER_ADVERTISE 0x01
94 #define MSRP_ATTRIBUTE_TYPE_TALKER_FAILED 0x02
95 #define MSRP_ATTRIBUTE_TYPE_LISTENER 0x03
96 #define MSRP_ATTRIBUTE_TYPE_DOMAIN 0x04
97 static const value_string attribute_type_vals[] = {
98 { MSRP_ATTRIBUTE_TYPE_TALKER_ADVERTISE, "Talker Advertise" },
99 { MSRP_ATTRIBUTE_TYPE_TALKER_FAILED, "Talker Failed" },
100 { MSRP_ATTRIBUTE_TYPE_LISTENER, "Listener" },
101 { MSRP_ATTRIBUTE_TYPE_DOMAIN, "Domain" },
102 { 0, NULL }
105 /* Leave All Event definitions */
106 #define MSRP_NULLLEAVEALL 0
107 #define MSRP_LEAVEALL 1
108 static const value_string leave_all_vals[] = {
109 { MSRP_NULLLEAVEALL, "Null" },
110 { MSRP_LEAVEALL, "Leave All" },
111 { 0, NULL }
114 /* Priority definitions */
115 #define MSRP_TRAFFIC_CLASS_A 3
116 #define MSRP_TRAFFIC_CLASS_B 2
118 static const value_string priority_vals[] = {
119 { MSRP_TRAFFIC_CLASS_A, "Traffic Class A" },
120 { MSRP_TRAFFIC_CLASS_B, "Traffic Class B" },
121 { 0, NULL }
124 /* Rank definitions */
125 static const value_string rank_vals[] = {
126 { 0, "Emergency" },
127 { 1, "Non-emergency" },
128 { 0, NULL }
130 static const value_string reserved_vals[] = {
131 { 0, "Reserved-0" },
132 { 1, "Reserved-1" },
133 { 2, "Reserved-2" },
134 { 3, "Reserved-3" },
135 { 4, "Reserved-4" },
136 { 5, "Reserved-5" },
137 { 6, "Reserved-6" },
138 { 7, "Reserved-7" },
139 { 8, "Reserved-8" },
140 { 9, "Reserved-9" },
141 { 10, "Reserved-10" },
142 { 11, "Reserved-11" },
143 { 12, "Reserved-12" },
144 { 13, "Reserved-13" },
145 { 14, "Reserved-14" },
146 { 15, "Reserved-15" },
147 { 0, NULL }
150 /* Failure Code definitions */
151 static const value_string failure_vals[] = {
152 { 1, "Insufficient Bandwidth" },
153 { 2, "Insufficient Bridge resources" },
154 { 3, "Insufficient Bandwidth for Traffic Class" },
155 { 4, "Stream ID in use by another Talker" },
156 { 5, "Stream destination_address already in use" },
157 { 6, "Stream preempted by higher rank" },
158 { 7, "Reported latency has changed" },
159 { 8, "Egress port in not AVB capable" },
160 { 9, "Use a different destination address (i.e. MAC DA hash table full)" },
161 { 10, "Out of MSRP resources" },
162 { 11, "Out of MMRP resources" },
163 { 12, "Cannot store destination_address (i.e. Bridge is out of MAC resources)" },
164 { 13, "Requested priority not an SR Class (3.3) priority" },
165 { 14, "MaxFrameSize (35.2.2.8.4(a)) is too large for media" },
166 { 15, "msrpMaxFanInPorts (35.2.1.4(f)) limit has been reached" },
167 { 16, "Changes in FirstValue for a registered StreamID" },
168 { 17, "VLAN is blocked on this egress port (Registration Forbidden)" },
169 { 18, "VLAN tagging is disabled on this egress port (untagged set)" },
170 { 19, "SR class priority mismatch" },
171 { 0, NULL }
174 /* SR class ID definitions */
175 #define MSRP_SR_CLASS_A 6
176 #define MSRP_SR_CLASS_B 5
177 #define MSRP_SR_CLASS_C 4
178 #define MSRP_SR_CLASS_D 3
179 #define MSRP_SR_CLASS_E 2
180 #define MSRP_SR_CLASS_F 1
181 #define MSRP_SR_CLASS_G 0
183 static const value_string sr_class_vals[] = {
184 { MSRP_SR_CLASS_A, "SR Class A" },
185 { MSRP_SR_CLASS_B, "SR Class B" },
186 { MSRP_SR_CLASS_C, "SR Class C" },
187 { MSRP_SR_CLASS_D, "SR Class D" },
188 { MSRP_SR_CLASS_E, "SR Class E" },
189 { MSRP_SR_CLASS_F, "SR Class F" },
190 { MSRP_SR_CLASS_G, "SR Class G" },
191 { 0, NULL }
194 /* Three Packed Event definitions */
195 static const value_string three_packed_vals[] = {
196 { 0, "New" },
197 { 1, "JoinIn" },
198 { 2, "In" },
199 { 3, "JoinMt" },
200 { 4, "Mt" },
201 { 5, "Lv" },
202 { 0, NULL }
205 /* Four Packed Event definitions */
206 static const value_string four_packed_vals[] = {
207 { 0, "Ignore" },
208 { 1, "Asking Failed" },
209 { 2, "Ready" },
210 { 3, "Ready Failed" },
211 { 0, NULL }
214 /**********************************************************/
215 /* Initialize the protocol and registered fields */
216 /**********************************************************/
217 static int proto_msrp = -1;
218 static int hf_msrp_proto_id = -1;
219 static int hf_msrp_message = -1; /* Message is a group of fields */
220 static int hf_msrp_attribute_type = -1;
221 static int hf_msrp_attribute_length = -1;
222 static int hf_msrp_attribute_list_length = -1;
223 static int hf_msrp_attribute_list = -1; /* AttributeList is a group of fields */
224 static int hf_msrp_vector_attribute = -1; /* VectorAttribute is a group of fields */
226 /* The following VectorHeader contains the LeaveAllEvent and NumberOfValues */
227 static int hf_msrp_vector_header = -1;
228 static int hf_msrp_leave_all_event = -1;
229 static int hf_msrp_number_of_values = -1;
230 static gint ett_vector_header = -1;
231 static const int *vector_header_fields[] = {
232 &hf_msrp_leave_all_event,
233 &hf_msrp_number_of_values,
234 NULL
237 static int hf_msrp_first_value = -1; /* FirstValue is a group of fields */
238 static int hf_msrp_stream_id = -1;
239 static int hf_msrp_stream_da = -1;
240 static int hf_msrp_vlan_id = -1;
241 static int hf_msrp_tspec_max_frame_size = -1;
242 static int hf_msrp_tspec_max_interval_frames = -1;
243 static int hf_msrp_priority_and_rank = -1;
244 static int hf_msrp_priority = -1;
245 static int hf_msrp_rank = -1;
246 static int hf_msrp_reserved = -1;
247 static gint ett_priority_and_rank = -1;
248 static const int *priority_and_rank_fields[] = {
249 &hf_msrp_priority,
250 &hf_msrp_rank,
251 &hf_msrp_reserved,
252 NULL
255 static int hf_msrp_sr_class_id = -1;
256 static int hf_msrp_sr_class_priority = -1;
257 static int hf_msrp_sr_class_vid = -1;
259 static int hf_msrp_accumulated_latency = -1;
260 static int hf_msrp_failure_bridge_id = -1;
261 static int hf_msrp_failure_code = -1;
263 static int hf_msrp_three_packed_event = -1;
264 static int hf_msrp_four_packed_event = -1;
266 static int hf_msrp_end_mark = -1;
268 /* Initialize the subtree pointers */
269 static gint ett_msrp = -1;
270 static gint ett_msg = -1;
271 static gint ett_attr_list = -1;
272 static gint ett_vect_attr = -1;
273 static gint ett_first_value = -1;
277 /**********************************************************/
278 /* Dissector starts here */
279 /**********************************************************/
281 /* dissect_msrp_common1 (called from dissect_msrp)
283 * dissect the following fields which are common to all MSRP attributes:
284 * Attribute Type
285 * Attribute Length
286 * Attribute List Length
288 static void
289 dissect_msrp_common1(proto_tree *msg_tree, tvbuff_t *tvb, int msg_offset)
291 proto_tree_add_item(msg_tree, hf_msrp_attribute_type, tvb,
292 MSRP_ATTRIBUTE_TYPE_OFFSET + msg_offset, 1, ENC_BIG_ENDIAN);
293 proto_tree_add_item(msg_tree, hf_msrp_attribute_length, tvb,
294 MSRP_ATTRIBUTE_LENGTH_OFFSET + msg_offset, 1, ENC_BIG_ENDIAN);
295 proto_tree_add_item(msg_tree, hf_msrp_attribute_list_length, tvb,
296 MSRP_ATTRIBUTE_LIST_LENGTH_OFFSET + msg_offset, 2, ENC_BIG_ENDIAN);
300 /* dissect_msrp_common2 (called from dissect_msrp)
302 * dissect the following fields which are common to all MSRP attributes:
303 * Leave All Event
304 * Number of Values fields
306 static void
307 dissect_msrp_common2(proto_tree *vect_attr_tree, tvbuff_t *tvb, int msg_offset)
309 proto_tree_add_bitmask(vect_attr_tree, tvb, MSRP_VECTOR_HEADER_OFFSET + msg_offset,
310 hf_msrp_vector_header, ett_vector_header, vector_header_fields, ENC_BIG_ENDIAN);
314 /* dissect_msrp_talker_common (called from dissect_msrp)
316 * dissect the following fields which are common to all MSRP Talker attributes:
317 * Stream MAC DA
318 * Stream VLAN ID
319 * TSpec Bandwidth
320 * TSpec Frame Rate
321 * Priority (Traffic Class)
322 * Rank
323 * Accumulated Latency
325 static void
326 dissect_msrp_talker_common(proto_tree *first_value_tree, tvbuff_t *tvb, int msg_offset)
329 proto_tree_add_item(first_value_tree, hf_msrp_stream_da, tvb,
330 MSRP_STREAM_DA_OFFSET + msg_offset, 6, ENC_NA);
331 proto_tree_add_item(first_value_tree, hf_msrp_vlan_id, tvb,
332 MSRP_VLAN_ID_OFFSET + msg_offset, 2, ENC_BIG_ENDIAN);
333 proto_tree_add_item(first_value_tree, hf_msrp_tspec_max_frame_size, tvb,
334 MSRP_TSPEC_MAX_FRAME_SIZE_OFFSET + msg_offset, 2, ENC_BIG_ENDIAN);
335 proto_tree_add_item(first_value_tree, hf_msrp_tspec_max_interval_frames, tvb,
336 MSRP_TSPEC_MAX_INTERVAL_FRAMES_OFFSET + msg_offset, 2, ENC_BIG_ENDIAN);
337 proto_tree_add_bitmask(first_value_tree, tvb, MSRP_PRIORITY_AND_RANK_OFFSET + msg_offset,
338 hf_msrp_priority_and_rank, ett_priority_and_rank, priority_and_rank_fields, ENC_BIG_ENDIAN);
339 proto_tree_add_item(first_value_tree, hf_msrp_accumulated_latency, tvb,
340 MSRP_ACCUMULATED_LATENCY_OFFSET + msg_offset, 4, ENC_BIG_ENDIAN);
344 /* dissect_msrp_talker_failed (called from dissect_msrp)
346 * dissect the following fields which are common to all MSRP Talker Failed attributes:
347 * Failure Information: Bridge ID
348 * Failure Information: Failure Code
350 static void
351 dissect_msrp_talker_failed(proto_tree *first_value_tree, tvbuff_t *tvb, int msg_offset)
354 proto_tree_add_item(first_value_tree, hf_msrp_failure_bridge_id, tvb,
355 MSRP_FAILURE_BRIDGE_ID_OFFSET + msg_offset, 8, ENC_BIG_ENDIAN);
356 proto_tree_add_item(first_value_tree, hf_msrp_failure_code, tvb,
357 MSRP_FAILURE_CODE_OFFSET + msg_offset, 1, ENC_BIG_ENDIAN);
361 /* dissect_msrp_three_packed_event (called from dissect_msrp)
363 * dissect one or more ThreePackedEvents
365 static guint
366 dissect_msrp_three_packed_event(proto_tree *vect_attr_tree, tvbuff_t *tvb, guint offset, guint16 number_of_values)
368 guint counter;
370 for ( counter = 0; counter < number_of_values; ) {
371 guint8 value;
372 guint8 three_packed_event[3];
374 value = tvb_get_guint8(tvb, offset);
375 three_packed_event[0] = value / 36;
376 value -= 36 * three_packed_event[0];
377 three_packed_event[1] = value / 6;
378 value -= 6 * three_packed_event[1];
379 three_packed_event[2] = value;
381 proto_tree_add_uint(vect_attr_tree, hf_msrp_three_packed_event, tvb, offset, sizeof(guint8),
382 three_packed_event[0]);
383 counter++;
384 if ( counter < number_of_values ) {
385 proto_tree_add_uint(vect_attr_tree, hf_msrp_three_packed_event, tvb, offset, sizeof(guint8),
386 three_packed_event[1]);
387 counter++;
389 if ( counter < number_of_values ) {
390 proto_tree_add_uint(vect_attr_tree, hf_msrp_three_packed_event, tvb, offset, sizeof(guint8),
391 three_packed_event[2]);
392 counter++;
395 offset++;
397 return( offset );
401 /* dissect_msrp_four_packed_event (called from dissect_msrp)
403 * dissect one or more FourPackedEvents
405 static guint
406 dissect_msrp_four_packed_event(proto_tree *vect_attr_tree, tvbuff_t *tvb, guint offset, guint16 number_of_values)
408 guint counter;
410 for ( counter = 0; counter < number_of_values; ) {
411 guint8 value;
412 guint8 four_packed_event[4];
414 value = tvb_get_guint8(tvb, offset);
415 four_packed_event[0] = (value & 0xc0) >> 6;
416 four_packed_event[1] = (value & 0x30) >> 4;
417 four_packed_event[2] = (value & 0x0c) >> 2;
418 four_packed_event[3] = (value & 0x03);
420 proto_tree_add_uint(vect_attr_tree, hf_msrp_four_packed_event, tvb, offset, sizeof(guint8),
421 four_packed_event[0]);
422 counter++;
423 if ( counter < number_of_values ) {
424 proto_tree_add_uint(vect_attr_tree, hf_msrp_four_packed_event, tvb, offset, sizeof(guint8),
425 four_packed_event[1]);
426 counter++;
428 if ( counter < number_of_values ) {
429 proto_tree_add_uint(vect_attr_tree, hf_msrp_four_packed_event, tvb, offset, sizeof(guint8),
430 four_packed_event[2]);
431 counter++;
433 if ( counter < number_of_values ) {
434 proto_tree_add_uint(vect_attr_tree, hf_msrp_four_packed_event, tvb, offset, sizeof(guint8),
435 four_packed_event[3]);
436 counter++;
439 offset++;
441 return( offset );
445 /* dissect_main
447 * main dissect function that calls the other functions listed above as necessary
449 static void
450 dissect_msrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
452 /* Set up structures needed to add the protocol subtrees and manage them */
453 proto_item *ti, *msg_ti, *attr_list_ti, *vect_attr_ti, *first_value_ti;
454 proto_tree *msrp_tree, *msg_tree, *attr_list_tree, *vect_attr_tree, *first_value_tree;
456 /* Make entries in Protocol column and Info column on summary display */
457 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MRP-MSRP");
459 col_set_str(pinfo->cinfo, COL_INFO, "Multiple Stream Reservation Protocol");
461 if (tree) {
462 guint8 attribute_type;
463 guint8 attribute_length;
464 guint16 number_of_values;
465 guint16 attribute_list_length;
466 guint offset = 0;
467 int vect_attr_len;
468 int msg_length; /* Length of MSRP/MRP Message */
469 int msg_offset; /* Use when handling multiple messages. This points to current msg being decoded. */
470 int vect_offset; /* Use when handling multiple vector attributes. This points to the current vector attribute being decoded. */
472 ti = proto_tree_add_item(tree, proto_msrp, tvb, 0, -1, ENC_NA);
473 msrp_tree = proto_item_add_subtree(ti, ett_msrp);
475 proto_tree_add_item(msrp_tree, hf_msrp_proto_id, tvb, MSRP_PROTOCOL_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
477 /* MSRP supports multiple MRP Messages per frame. Handle those Messages in
478 * the following while() loop. You will know you are at the end of the list
479 * of messages when the EndMark (0x0000) is encountered instead of an
480 * Attribute Type and Attribute Length (guaranteed to not be 0x0000).
482 msg_offset = 0;
483 while (tvb_get_ntohs(tvb, MSRP_ATTRIBUTE_TYPE_OFFSET + msg_offset) != MSRP_END_MARK) {
485 attribute_type = tvb_get_guint8(tvb, MSRP_ATTRIBUTE_TYPE_OFFSET + msg_offset);
486 attribute_length = tvb_get_guint8(tvb, MSRP_ATTRIBUTE_LENGTH_OFFSET + msg_offset);
487 attribute_list_length = tvb_get_ntohs(tvb, MSRP_ATTRIBUTE_LIST_LENGTH_OFFSET + msg_offset);
489 /* MSRP Message is a group of fields
491 * Contains AttributeType (1 byte)
492 * + AttributeLength (1 byte)
493 * + AttributeListLength (2 bytes)
494 * + AttributeList (AttributeListLength bytes)
495 * bytes of data
497 msg_length = 1 + 1 + 2 + attribute_list_length;
498 msg_ti = proto_tree_add_item(msrp_tree, hf_msrp_message, tvb,
499 MSRP_MESSAGE_GROUP_OFFSET + msg_offset,
500 msg_length, ENC_NA);
501 msg_tree = proto_item_add_subtree(msg_ti, ett_msg);
503 /* Append AttributeType description to the end of the "Message" heading */
504 proto_item_append_text(msg_tree, ": %s (%d)",
505 val_to_str_const(attribute_type, attribute_type_vals, "<Unknown>"),
506 attribute_type);
508 dissect_msrp_common1(msg_tree, tvb, msg_offset);
510 /* MSRP AttributeList is a group of fields
512 * Contains AttributeListLength bytes of data
514 attr_list_ti = proto_tree_add_item(msg_tree, hf_msrp_attribute_list, tvb,
515 MSRP_ATTRIBUTE_LIST_GROUP_OFFSET + msg_offset,
516 attribute_list_length, ENC_NA);
517 attr_list_tree = proto_item_add_subtree(attr_list_ti, ett_attr_list);
520 /* MSRP supports multiple MRP Vector Attributes per Attribute List. Handle those
521 * Vector Attributes in the following while() loop. You will know you are at the
522 * end of the list of Vector Attributes when the EndMark (0x0000) is encountered
523 * instead of a Vector Header (guaranteed to not be 0x0000).
525 vect_offset = 0;
526 while (tvb_get_ntohs(tvb, MSRP_VECTOR_HEADER_OFFSET + msg_offset + vect_offset) != MSRP_END_MARK) {
527 /* MSRP VectorAttribute is a group of fields
529 * Contains VectorHeader (2 bytes)
530 * + FirstValue (AttributeLength bytes)
531 * + VectorThreePacked (NumberOfValues @ 3/vector bytes)
532 * + VectorFourPacked (NumberOfValues @ 4/vector bytes only for Listener attributes)
533 * bytes of data
535 number_of_values = tvb_get_ntohs(tvb, MSRP_NUMBER_OF_VALUES_OFFSET + msg_offset + vect_offset)
536 & MSRP_NUMBER_OF_VALUES_MASK;
538 vect_attr_len = 2 + attribute_length + (number_of_values + 2)/3; /* stores 3 values per byte */
539 if (attribute_type == MSRP_ATTRIBUTE_TYPE_LISTENER)
540 vect_attr_len += (number_of_values + 3)/4; /* stores 4 values per byte */
542 vect_attr_ti = proto_tree_add_item(attr_list_tree, hf_msrp_vector_attribute, tvb,
543 MSRP_VECTOR_ATTRIBUTE_GROUP_OFFSET + msg_offset + vect_offset,
544 vect_attr_len, ENC_NA);
546 vect_attr_tree = proto_item_add_subtree(vect_attr_ti, ett_vect_attr);
548 dissect_msrp_common2(vect_attr_tree, tvb, msg_offset + vect_offset);
550 if(attribute_type == MSRP_ATTRIBUTE_TYPE_DOMAIN) {
551 /* MSRP Domain FirstValue is a group of fields
553 * Contains SRclassID (1 byte)
554 * + SRclassPriority (1 byte)
555 * + SRclassVID (2 bytes)
556 * bytes of data
558 first_value_ti = proto_tree_add_item(vect_attr_tree, hf_msrp_first_value, tvb,
559 MSRP_FIRST_VALUE_GROUP_OFFSET + msg_offset + vect_offset,
560 attribute_length, ENC_NA);
561 first_value_tree = proto_item_add_subtree(first_value_ti, ett_first_value);
563 /* Add Domain components to First Value tree */
564 proto_tree_add_item(first_value_tree, hf_msrp_sr_class_id, tvb,
565 MSRP_FIRST_VALUE_GROUP_OFFSET + msg_offset + vect_offset, 1, ENC_BIG_ENDIAN);
566 proto_tree_add_item(first_value_tree, hf_msrp_sr_class_priority, tvb,
567 MSRP_FIRST_VALUE_GROUP_OFFSET + msg_offset + vect_offset + 1, 1, ENC_BIG_ENDIAN);
568 proto_tree_add_item(first_value_tree, hf_msrp_sr_class_vid, tvb,
569 MSRP_FIRST_VALUE_GROUP_OFFSET + msg_offset + vect_offset + 2, 2, ENC_BIG_ENDIAN);
571 /* Decode three packed events. */
572 offset = dissect_msrp_three_packed_event(vect_attr_tree, tvb,
573 MSRP_DOMAIN_THREE_PACKED_OFFSET + msg_offset + vect_offset,
574 number_of_values);
577 else {
578 /* MSRP Stream Reservations FirstValue is a group of fields
580 * Contains StreamID (8 bytes)
581 * + DataFrameParameters (8 bytes on Talker attributes)
582 * + TSpec (8 bytes on Talker attributes)
583 * + PriorityAndRank (1 byte on Talker attributes)
584 * + AccumulatedLatency (4 bytes on Talker attributes)
585 * + FailureInformation (9 bytes on Talker Failed attributes)
586 * bytes of data
588 first_value_ti = proto_tree_add_item(vect_attr_tree, hf_msrp_first_value, tvb,
589 MSRP_FIRST_VALUE_GROUP_OFFSET + msg_offset + vect_offset,
590 attribute_length, ENC_NA);
591 first_value_tree = proto_item_add_subtree(first_value_ti, ett_first_value);
593 /* Decode StreamID */
594 proto_tree_add_item(first_value_tree, hf_msrp_stream_id, tvb,
595 MSRP_STREAM_ID_OFFSET + msg_offset + vect_offset, 8, ENC_BIG_ENDIAN);
597 switch ( attribute_type ) {
598 case MSRP_ATTRIBUTE_TYPE_LISTENER:
599 offset = dissect_msrp_three_packed_event(vect_attr_tree, tvb,
600 MSRP_LISTENER_THREE_PACKED_OFFSET + msg_offset + vect_offset,
601 number_of_values);
602 offset = dissect_msrp_four_packed_event(vect_attr_tree, tvb, offset, number_of_values);
603 break;
604 case MSRP_ATTRIBUTE_TYPE_TALKER_ADVERTISE:
605 dissect_msrp_talker_common(first_value_tree, tvb, msg_offset + vect_offset);
606 offset = dissect_msrp_three_packed_event(vect_attr_tree, tvb,
607 MSRP_TALKER_ADVERTISE_THREE_PACKED_OFFSET + msg_offset + vect_offset,
608 number_of_values);
609 break;
610 case MSRP_ATTRIBUTE_TYPE_TALKER_FAILED:
611 dissect_msrp_talker_common(first_value_tree, tvb, msg_offset + vect_offset);
612 dissect_msrp_talker_failed(first_value_tree, tvb, msg_offset + vect_offset);
613 offset = dissect_msrp_three_packed_event(vect_attr_tree, tvb,
614 MSRP_TALKER_FAILED_THREE_PACKED_OFFSET + msg_offset + vect_offset,
615 number_of_values);
616 break;
617 default:
618 proto_tree_add_text(first_value_tree, tvb, msg_offset + vect_offset, vect_attr_len, "Unknown Attribute");
619 break;
622 vect_offset += vect_attr_len; /* Move to next Vector Attribute, if there is one */
623 } /* Multiple VectorAttribute while() */
625 proto_tree_add_item(attr_list_tree, hf_msrp_end_mark, tvb, offset, 2, ENC_BIG_ENDIAN); /* VectorAttribute EndMark */
627 msg_offset += msg_length; /* Move to next Message, if there is one */
628 } /* Multiple Message while() */
629 proto_tree_add_item(msrp_tree, hf_msrp_end_mark, tvb, offset+2, 2, ENC_BIG_ENDIAN); /* Message EndMark */
634 /* Register the protocol with Wireshark */
635 void
636 proto_register_mrp_msrp(void)
638 static hf_register_info hf[] = {
639 { &hf_msrp_proto_id,
640 { "Protocol Version", "mrp-msrp.protocol_version",
641 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
643 { &hf_msrp_message, /* Message is a group of fields */
644 { "Message", "mrp-msrp.message",
645 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
647 { &hf_msrp_attribute_type,
648 { "Attribute Type", "mrp-msrp.attribute_type",
649 FT_UINT8, BASE_DEC, VALS(attribute_type_vals), 0x0, NULL, HFILL }
651 { &hf_msrp_attribute_length,
652 { "Attribute Length", "mrp-msrp.attribute_length",
653 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
655 { &hf_msrp_attribute_list_length,
656 { "Attribute List Length", "mrp-msrp.attribute_list_length",
657 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
659 { &hf_msrp_attribute_list, /* AttributeList is a group of fields */
660 { "Attribute List", "mrp-msrp.attribute_list",
661 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
663 { &hf_msrp_vector_attribute, /* VectorAttribute is a group of fields */
664 { "Vector Attribute", "mrp-msrp.vector_attribute",
665 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
667 { &hf_msrp_vector_header,
668 { "Vector Header", "mrp-msrp.vector_header",
669 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
671 { &hf_msrp_leave_all_event,
672 { "Leave All Event", "mrp-msrp.leave_all_event",
673 FT_UINT16, BASE_DEC, VALS(leave_all_vals), MSRP_LEAVE_ALL_EVENT_MASK, NULL, HFILL }
675 { &hf_msrp_number_of_values,
676 { "Number of Values", "mrp-msrp.number_of_values",
677 FT_UINT16, BASE_DEC, NULL, MSRP_NUMBER_OF_VALUES_MASK, NULL, HFILL }
679 { &hf_msrp_first_value, /* FirstValue is a group of fields */
680 { "First Value", "mrp-msrp.first_value",
681 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
683 { &hf_msrp_stream_id,
684 { "Stream ID", "mrp-msrp.stream_id",
685 FT_UINT64, BASE_HEX, NULL, 0x00, NULL, HFILL }
687 { &hf_msrp_stream_da,
688 { "Stream DA", "mrp-msrp.stream_da",
689 FT_ETHER, BASE_NONE, NULL, 0x00, NULL, HFILL }
691 { &hf_msrp_vlan_id,
692 { "VLAN ID", "mrp-msrp.vlan_id",
693 FT_UINT16, BASE_HEX, NULL, 0x00, NULL, HFILL }
695 { &hf_msrp_tspec_max_frame_size,
696 { "TSpec Max Frame Size", "mrp-msrp.tspec_max_frame_size",
697 FT_UINT16, BASE_DEC, NULL, 0x00, NULL, HFILL }
699 { &hf_msrp_tspec_max_interval_frames,
700 { "TSpec Max Frame Interval", "mrp-msrp.tspec_max_interval_frames",
701 FT_UINT16, BASE_DEC, NULL, 0x00, NULL, HFILL }
703 { &hf_msrp_priority_and_rank,
704 { "Priority and Rank", "mrp-msrp.priority_and_rank",
705 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }
707 { &hf_msrp_priority,
708 { "Priority", "mrp-msrp.priority",
709 FT_UINT8, BASE_DEC, VALS(priority_vals), MSRP_PRIORITY_MASK, NULL, HFILL }
711 { &hf_msrp_rank,
712 { "Rank", "mrp-msrp.rank",
713 FT_UINT8, BASE_DEC, VALS(rank_vals), MSRP_RANK_MASK, NULL, HFILL }
715 { &hf_msrp_reserved,
716 { "Reserved", "mrp-msrp.reserved",
717 FT_UINT8, BASE_DEC, VALS(reserved_vals), MSRP_RESERVED_MASK, NULL, HFILL }
719 { &hf_msrp_accumulated_latency,
720 { "Accumulated Latency", "mrp-msrp.accumulated_latency",
721 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
723 { &hf_msrp_failure_bridge_id,
724 { "Failure Bridge ID", "mrp-msrp.failure_bridge_id",
725 FT_UINT64, BASE_HEX, NULL, 0x0, NULL, HFILL }
727 { &hf_msrp_failure_code,
728 { "Failure Code", "mrp-msrp.failure_code",
729 FT_UINT8, BASE_DEC, VALS(failure_vals), 0x0, NULL, HFILL }
731 { &hf_msrp_sr_class_id,
732 { "SR Class ID", "mrp-msrp.sr_class_id",
733 FT_UINT8, BASE_DEC, VALS(sr_class_vals), 0x0, NULL, HFILL }
735 { &hf_msrp_sr_class_priority,
736 { "SR Class Priority", "mrp-msrp.sr_class_priority",
737 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
739 { &hf_msrp_sr_class_vid,
740 { "SR Class VID", "mrp-msrp.sr_class_vid",
741 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
743 { &hf_msrp_three_packed_event,
744 { "Attribute Event", "mrp-msrp.three_packed_event",
745 FT_UINT8, BASE_DEC, VALS(three_packed_vals), 0x0, NULL, HFILL }
747 { &hf_msrp_four_packed_event,
748 { "Declaration Type", "mrp-msrp.four_packed_event",
749 FT_UINT8, BASE_DEC, VALS(four_packed_vals), 0x0, NULL, HFILL }
751 { &hf_msrp_end_mark,
752 { "End Mark", "mrp-msrp.end_mark",
753 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
757 /* Setup protocol subtree array */
758 static gint *ett[] = {
759 &ett_msrp,
760 &ett_msg,
761 &ett_attr_list,
762 &ett_vect_attr,
763 &ett_vector_header,
764 &ett_first_value,
765 &ett_priority_and_rank
768 /* Register the protocol name and description */
769 proto_msrp = proto_register_protocol("Multiple Stream Reservation Protocol",
770 "MRP-MSRP", "mrp-msrp");
772 /* Required function calls to register the header fields and subtrees used */
773 proto_register_field_array(proto_msrp, hf, array_length(hf));
774 proto_register_subtree_array(ett, array_length(ett));
777 void
778 proto_reg_handoff_mrp_msrp(void)
780 dissector_handle_t msrp_handle;
782 msrp_handle = create_dissector_handle(dissect_msrp, proto_msrp);
783 dissector_add_uint("ethertype", ETHERTYPE_MSRP, msrp_handle);