2 * Routines for PN-MRP (PROFINET Media Redundancy Protocol)
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
36 #include <epan/packet.h>
37 #include <epan/dissectors/packet-dcerpc.h>
39 #include <epan/etypes.h>
41 #include "packet-pn.h"
44 static int proto_pn_mrp = -1;
46 static int hf_pn_mrp_type = -1;
47 static int hf_pn_mrp_length = -1;
48 static int hf_pn_mrp_version = -1;
49 static int hf_pn_mrp_sequence_id = -1;
50 static int hf_pn_mrp_sa = -1;
51 static int hf_pn_mrp_prio = -1;
52 static int hf_pn_mrp_port_role = -1;
53 static int hf_pn_mrp_ring_state = -1;
54 static int hf_pn_mrp_interval = -1;
55 static int hf_pn_mrp_transition = -1;
56 static int hf_pn_mrp_time_stamp = -1;
57 static int hf_pn_mrp_blocked = -1;
58 static int hf_pn_mrp_manufacturer_oui = -1;
59 static int hf_pn_mrp_domain_uuid = -1;
60 static int hf_pn_mrp_oui = -1;
63 static gint ett_pn_mrp = -1;
67 static const value_string pn_mrp_block_type_vals[] = {
71 { 0x03, "TopologyChange" },
74 /*0x06 - 0x7E Reserved */
75 { 0x7F, "Organizationally Specific"},
79 static const value_string pn_mrp_oui_vals[] = {
80 { OUI_PROFINET, "PROFINET" },
81 { OUI_SIEMENS, "SIEMENS" },
88 static const value_string pn_mrp_port_role_vals[] = {
89 { 0x0000, "Primary ring port" },
90 { 0x0001, "Secondary ring port"},
91 /*0x0002 - 0xFFFF Reserved */
96 static const value_string pn_mrp_ring_state_vals[] = {
97 { 0x0000, "Ring open" },
98 { 0x0001, "Ring closed"},
99 /*0x0002 - 0xFFFF Reserved */
105 static const value_string pn_mrp_prio_vals[] = {
106 { 0x8000, "Default priority for redundancy manager" },
114 dissect_PNMRP_Common(tvbuff_t *tvb, int offset,
115 packet_info *pinfo, proto_tree *tree, proto_item *item)
122 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_sequence_id, &sequence_id);
125 offset = dissect_pn_uuid(tvb, offset, pinfo, tree, hf_pn_mrp_domain_uuid, &uuid);
127 col_append_str(pinfo->cinfo, COL_INFO, "Common");
129 proto_item_append_text(item, "Common");
136 dissect_PNMRP_LinkUp(tvbuff_t *tvb, int offset,
137 packet_info *pinfo, proto_tree *tree, proto_item *item)
145 offset = dissect_pn_mac(tvb, offset, pinfo, tree, hf_pn_mrp_sa, mac);
148 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_port_role, &port_role);
151 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_interval, &interval);
154 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_blocked, &blocked);
157 offset = dissect_pn_align4(tvb, offset, pinfo, tree);
159 col_append_str(pinfo->cinfo, COL_INFO, "LinkUp");
161 proto_item_append_text(item, "LinkUp");
168 dissect_PNMRP_LinkDown(tvbuff_t *tvb, int offset,
169 packet_info *pinfo, proto_tree *tree, proto_item *item)
177 offset = dissect_pn_mac(tvb, offset, pinfo, tree, hf_pn_mrp_sa, mac);
180 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_port_role, &port_role);
183 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_interval, &interval);
186 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_blocked, &blocked);
189 offset = dissect_pn_align4(tvb, offset, pinfo, tree);
191 col_append_str(pinfo->cinfo, COL_INFO, "LinkDown");
193 proto_item_append_text(item, "LinkDown");
200 dissect_PNMRP_Test(tvbuff_t *tvb, int offset,
201 packet_info *pinfo, proto_tree *tree, proto_item *item)
212 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_prio, &prio);
215 offset = dissect_pn_mac(tvb, offset, pinfo, tree, hf_pn_mrp_sa, mac);
218 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_port_role, &port_role);
221 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_ring_state, &ring_state);
224 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_transition, &transition);
227 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_time_stamp, &time_stamp);
230 offset = dissect_pn_align4(tvb, offset, pinfo, tree);
232 col_append_str(pinfo->cinfo, COL_INFO, "Test");
234 proto_item_append_text(item, "Test");
241 dissect_PNMRP_TopologyChange(tvbuff_t *tvb, int offset,
242 packet_info *pinfo, proto_tree *tree, proto_item *item)
250 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_prio, &prio);
253 offset = dissect_pn_mac(tvb, offset, pinfo, tree, hf_pn_mrp_sa, mac);
256 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_interval, &interval);
259 /*offset = dissect_pn_align4(tvb, offset, pinfo, tree);*/
261 col_append_str(pinfo->cinfo, COL_INFO, "TopologyChange");
263 proto_item_append_text(item, "TopologyChange");
270 dissect_PNMRP_Option(tvbuff_t *tvb, int offset,
271 packet_info *pinfo, proto_tree *tree, proto_item *item, guint8 length)
276 /* OUI (organizational unique id) */
277 offset = dissect_pn_oid(tvb, offset, pinfo,tree, hf_pn_mrp_oui, &oui);
283 proto_item_append_text(item, "Option(SIEMENS)");
286 length -= 4 - (offset % 4);
287 offset = dissect_pn_align4(tvb, offset, pinfo, tree);
290 offset = dissect_pn_undecoded(tvb, offset, pinfo, tree, length);
292 col_append_str(pinfo->cinfo, COL_INFO, "Option(Siemens)");
295 proto_item_append_text(item, "Option(Unknown-OUI)");
296 offset = dissect_pn_undecoded(tvb, offset, pinfo, tree, length);
298 col_append_str(pinfo->cinfo, COL_INFO, "Option");
304 offset = dissect_pn_align4(tvb, offset, pinfo, tree);
311 dissect_PNMRP_PDU(tvbuff_t *tvb, int offset,
312 packet_info *pinfo, proto_tree *tree, proto_item *item)
322 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrp_version, &version);
324 /* the rest of the packet has 4byte alignment regarding to the beginning of the next TLV block! */
325 /* XXX - do we have to free this new tvb below? */
326 new_tvb = tvb_new_subset_remaining(tvb, offset);
329 for(i=0; tvb_length_remaining(tvb, offset) > 0; i++) {
330 /* MRP_TLVHeader.Type */
331 offset = dissect_pn_uint8(new_tvb, offset, pinfo, tree, hf_pn_mrp_type, &type);
333 /* MRP_TLVHeader.Length */
334 offset = dissect_pn_uint8(new_tvb, offset, pinfo, tree, hf_pn_mrp_length, &length);
337 col_append_str(pinfo->cinfo, COL_INFO, ", ");
339 proto_item_append_text(item, ", ");
345 col_append_str(pinfo->cinfo, COL_INFO, "End");
346 proto_item_append_text(item, "End");
350 offset = dissect_PNMRP_Common(new_tvb, offset, pinfo, tree, item);
353 offset = dissect_PNMRP_Test(new_tvb, offset, pinfo, tree, item);
356 offset = dissect_PNMRP_TopologyChange(new_tvb, offset, pinfo, tree, item);
359 offset = dissect_PNMRP_LinkDown(new_tvb, offset, pinfo, tree, item);
362 offset = dissect_PNMRP_LinkUp(new_tvb, offset, pinfo, tree, item);
365 offset = dissect_PNMRP_Option(new_tvb, offset, pinfo, tree, item, length);
368 offset = dissect_pn_undecoded(tvb, offset, pinfo, tree, length);
370 col_append_fstr(pinfo->cinfo, COL_INFO, "Unknown TLVType 0x%x", type);
371 proto_item_append_text(item, "Unknown TLVType 0x%x", type);
379 /* Dissect MRP packets */
381 dissect_PNMRP(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
383 proto_item *ti = NULL;
384 proto_tree *mrp_tree = NULL;
388 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PN-MRP");
390 /* Clear the information column on summary display */
391 col_clear(pinfo->cinfo, COL_INFO);
395 ti = proto_tree_add_item(tree, proto_pn_mrp, tvb, offset, -1, FALSE);
396 mrp_tree = proto_item_add_subtree(ti, ett_pn_mrp);
399 dissect_PNMRP_PDU(tvb, offset, pinfo, mrp_tree, ti);
404 proto_register_pn_mrp (void)
406 static hf_register_info hf[] = {
408 { "Type", "pn_mrp.type", FT_UINT8, BASE_HEX, VALS(pn_mrp_block_type_vals), 0x0, NULL, HFILL }},
410 { "Length", "pn_mrp.length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
411 { &hf_pn_mrp_version,
412 { "Version", "pn_mrp.version", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
413 { &hf_pn_mrp_sequence_id,
414 { "SequenceID", "pn_mrp.sequence_id", FT_UINT16, BASE_HEX, NULL, 0x0, "Unique sequence number to each outstanding service request", HFILL }},
416 { "SA", "pn_mrp.sa", FT_ETHER, BASE_NONE, 0x0, 0x0, NULL, HFILL }},
418 { "Prio", "pn_mrp.prio", FT_UINT16, BASE_HEX, VALS(pn_mrp_prio_vals), 0x0, NULL, HFILL }},
419 { &hf_pn_mrp_port_role,
420 { "PortRole", "pn_mrp.port_role", FT_UINT16, BASE_HEX, VALS(pn_mrp_port_role_vals), 0x0, NULL, HFILL }},
421 { &hf_pn_mrp_ring_state,
422 { "RingState", "pn_mrp.ring_state", FT_UINT16, BASE_HEX, VALS(pn_mrp_ring_state_vals), 0x0, NULL, HFILL }},
423 { &hf_pn_mrp_interval,
424 { "Interval", "pn_mrp.interval", FT_UINT16, BASE_DEC, NULL, 0x0, "Interval for next topologie change event (in ms)", HFILL }},
425 { &hf_pn_mrp_transition,
426 { "Transition", "pn_mrp.transition", FT_UINT16, BASE_HEX, NULL, 0x0, "Number of transitions between media redundancy lost and ok states", HFILL }},
427 { &hf_pn_mrp_time_stamp,
428 { "TimeStamp", "pn_mrp.time_stamp", FT_UINT16, BASE_HEX, NULL, 0x0, "Actual counter value of 1ms counter", HFILL }},
429 { &hf_pn_mrp_blocked,
430 { "Blocked", "pn_mrp.blocked", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
431 { &hf_pn_mrp_manufacturer_oui,
432 { "ManufacturerOUI", "pn_mrp.manufacturer_oui", FT_UINT24, BASE_HEX, VALS(pn_mrp_oui_vals), 0x0, NULL, HFILL }},
433 { &hf_pn_mrp_domain_uuid,
434 { "DomainUUID", "pn_mrp.domain_uuid", FT_GUID, BASE_NONE, NULL, 0x0, NULL, HFILL }},
436 { "Organizationally Unique Identifier", "pn_mrp.oui", FT_UINT24, BASE_HEX,
437 VALS(pn_mrp_oui_vals), 0x0, NULL, HFILL }},
440 static gint *ett[] = {
444 proto_pn_mrp = proto_register_protocol ("PROFINET MRP", "PN-MRP", "pn_mrp");
445 proto_register_field_array (proto_pn_mrp, hf, array_length (hf));
446 proto_register_subtree_array (ett, array_length (ett));
451 proto_reg_handoff_pn_mrp (void)
453 dissector_handle_t mrp_handle;
456 mrp_handle = create_dissector_handle(dissect_PNMRP,proto_pn_mrp);
457 dissector_add("ethertype", ETHERTYPE_MRP, mrp_handle);