2 * Routines for PRP (Parallel Redundancy Protocol; IEC62439 Part 3) dissection
3 * Copyright 2007, Sven Meier <msv[AT]zhwin.ch>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #include <epan/packet.h>
38 #include <epan/etypes.h>
39 #include <epan/prefs.h>
41 /**********************************************************/
42 /* Offsets of fields within a PRP packet. */
43 /**********************************************************/
44 #define PRP_VERSION_OFFSET 0
45 #define PRP_TYPE_OFFSET 2
46 #define PRP_LENGTH_OFFSET 3
47 #define PRP_SOURCEMACADDRESSA_OFFSET 4
48 #define PRP_SOURCEMACADDRESSB_OFFSET 10
49 #define PRP_TYPE2_OFFSET 16
50 #define PRP_LENGTH2_OFFSET 17
51 #define PRP_REDBOXVDANMACADDRESS_OFFSET 18
53 /**********************************************************/
54 /* Lengths of fields within a PRP packet. */
55 /**********************************************************/
56 #define PRP_VERSION_LENGTH 2
57 #define PRP_TYPE_LENGTH 1
58 #define PRP_LENGTH_LENGTH 1
59 #define PRP_SOURCE_LENGTH 6
60 #define PRP_TOTAL_LENGTH 24
62 /**********************************************************/
63 /* Channel values for the PRP_TYPE field */
64 /**********************************************************/
65 #define PRP_TYPE_DUPLICATE_ACCEPT 21
66 #define PRP_TYPE_DUPLICATE_DISCARD 20
67 #define PRP_TYPE_REDBOX 30
68 #define PRP_TYPE_VDAN 31
70 static const value_string prp_type_vals[] = {
71 {PRP_TYPE_DUPLICATE_ACCEPT, "Duplicate Accept"},
72 {PRP_TYPE_DUPLICATE_DISCARD, "Duplicate Discard"},
73 {PRP_TYPE_REDBOX, "Redundancy Box"},
74 {PRP_TYPE_VDAN, "Virtual Dual Attached Node"},
81 static const value_string prp_lan_vals[] = {
86 /**********************************************************/
87 /* Initialize the protocol and registered fields */
88 /**********************************************************/
90 void proto_reg_handoff_prp(void);
91 static int proto_prp = -1;
92 static module_t *prp_module;
94 /* Initialize supervision frame fields */
95 static int hf_prp_supervision_frame_version = -1;
96 static int hf_prp_supervision_frame_type = -1;
97 static int hf_prp_supervision_frame_length = -1;
98 static int hf_prp_supervision_frame_source_mac_address_A = -1;
99 static int hf_prp_supervision_frame_source_mac_address_B = -1;
100 static int hf_prp_supervision_frame_type2 = -1;
101 static int hf_prp_supervision_frame_length2 = -1;
102 static int hf_prp_supervision_frame_red_box_mac_address = -1;
103 static int hf_prp_supervision_frame_vdan_mac_address = -1;
105 /* Initialize trailer fields */
106 static int hf_prp_redundancy_control_trailer_sequence_nr = -1;
107 static int hf_prp_redundancy_control_trailer_lan = -1;
108 static int hf_prp_redundancy_control_trailer_size = -1;
111 /* Initialize the subtree pointers */
112 static gint ett_prp_supervision_frame = -1;
113 static gint ett_prp_redundancy_control_trailer = -1;
116 /* Post dissectors (such as the trailer dissector for this protocol)
117 * get called for every single frame anyone loads into Wireshark.
118 * Since this protocol is not of general interest we disable this
119 * protocol by default.
121 * This is done separately from the disabled protocols list mainly so
122 * we can disable it by default. XXX Maybe there's a better way.
124 static gboolean prp_enable_dissector = FALSE;
127 /* Code to actually dissect the packets */
129 dissect_prp_supervision_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
132 proto_tree *prp_tree;
135 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PRP");
137 col_set_str(pinfo->cinfo, COL_INFO, "Supervision Frame");
142 /* create display subtree for the protocol */
143 ti = proto_tree_add_item(tree, proto_prp, tvb, 0, PRP_TOTAL_LENGTH,
146 prp_tree = proto_item_add_subtree(ti, ett_prp_supervision_frame);
148 proto_tree_add_item(prp_tree, hf_prp_supervision_frame_version,
149 tvb, PRP_VERSION_OFFSET, PRP_VERSION_LENGTH, FALSE);
151 proto_tree_add_item(prp_tree, hf_prp_supervision_frame_type,
152 tvb, PRP_TYPE_OFFSET, PRP_TYPE_LENGTH, FALSE);
154 proto_tree_add_item(prp_tree, hf_prp_supervision_frame_length,
155 tvb, PRP_LENGTH_OFFSET, PRP_LENGTH_LENGTH, FALSE);
157 proto_tree_add_item(prp_tree, hf_prp_supervision_frame_source_mac_address_A,
158 tvb, PRP_SOURCEMACADDRESSA_OFFSET, PRP_SOURCE_LENGTH,
161 proto_tree_add_item(prp_tree, hf_prp_supervision_frame_source_mac_address_B,
162 tvb, PRP_SOURCEMACADDRESSB_OFFSET, PRP_SOURCE_LENGTH,
166 tlv2 = tvb_get_ntohs(tvb, PRP_TYPE2_OFFSET);
168 if((tlv2 == 0x1e06) || (tlv2 == 0x1f06))
170 proto_tree_add_item(prp_tree, hf_prp_supervision_frame_type2,
171 tvb, PRP_TYPE2_OFFSET, PRP_TYPE_LENGTH, FALSE);
173 proto_tree_add_item(prp_tree, hf_prp_supervision_frame_length2,
174 tvb, PRP_LENGTH2_OFFSET, PRP_LENGTH_LENGTH, FALSE);
178 proto_tree_add_item(prp_tree, hf_prp_supervision_frame_red_box_mac_address,
179 tvb, PRP_REDBOXVDANMACADDRESS_OFFSET, PRP_SOURCE_LENGTH,
184 proto_tree_add_item(prp_tree, hf_prp_supervision_frame_vdan_mac_address,
185 tvb, PRP_REDBOXVDANMACADDRESS_OFFSET, PRP_SOURCE_LENGTH,
193 dissect_prp_redundancy_control_trailer(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
196 proto_tree *prp_tree;
201 guint trailer_offset;
207 length = tvb_reported_length(tvb);
214 if(ETHERTYPE_VLAN == tvb_get_ntohs(tvb, 12)) /* tagged frame */
225 for(i=length; i>=(offset+4); i--) /* search trailer */
227 lan_size = tvb_get_ntohs(tvb, (i-2));
228 if((lan_size == (0xa000 | ((i-offset) & 0x0fff)))
229 || (lan_size == (0xb000 | ((i-offset) & 0x0fff))))
237 lan_size = tvb_get_ntohs(tvb, (length-2));
238 if((lan_size == (0xa000 | ((length-offset) & 0x0fff)))
239 || (lan_size == (0xb000 | ((length-offset) & 0x0fff))))
241 trailer_offset = length;
245 if(trailer_offset != 0)
247 /* create display subtree for the protocol */
248 ti = proto_tree_add_item(tree, proto_prp, tvb, trailer_offset - 4,
249 trailer_offset, FALSE);
251 prp_tree = proto_item_add_subtree(ti, ett_prp_redundancy_control_trailer);
253 proto_tree_add_item(prp_tree, hf_prp_redundancy_control_trailer_sequence_nr,
254 tvb, (trailer_offset-4), 2, FALSE);
256 proto_tree_add_item(prp_tree, hf_prp_redundancy_control_trailer_lan,
257 tvb, (trailer_offset-2), 2, FALSE);
259 proto_tree_add_item(prp_tree, hf_prp_redundancy_control_trailer_size,
260 tvb, (trailer_offset-2), 2, FALSE);
264 /* Register the protocol with Wireshark */
265 void proto_register_prp(void)
267 static hf_register_info hf[] = {
269 /*supervision frame*/
270 { &hf_prp_supervision_frame_version,
271 { "version", "prp.supervision_frame.version",
272 FT_UINT16, BASE_DEC, NULL, 0x00,
275 { &hf_prp_supervision_frame_type,
276 { "type", "prp.supervision_frame.type",
277 FT_UINT8, BASE_DEC, VALS(prp_type_vals), 0x00,
280 { &hf_prp_supervision_frame_length,
281 { "length", "prp.supervision_frame.length",
282 FT_UINT8, BASE_DEC, NULL, 0x00,
285 { &hf_prp_supervision_frame_source_mac_address_A,
286 { "sourceMacAddressA", "prp.supervision_frame.prp_source_mac_address_A",
287 FT_ETHER, BASE_NONE, NULL, 0x00,
290 { &hf_prp_supervision_frame_source_mac_address_B,
291 { "sourceMacAddressB", "prp.supervision_frame.prp_source_mac_address_B",
292 FT_ETHER, BASE_NONE, NULL, 0x00,
295 { &hf_prp_supervision_frame_type2,
296 { "type2", "prp.supervision_frame.type2",
297 FT_UINT8, BASE_DEC, VALS(prp_type_vals), 0x00,
300 { &hf_prp_supervision_frame_length2,
301 { "length2", "prp.supervision_frame.length2",
302 FT_UINT8, BASE_DEC, NULL, 0x00,
305 { &hf_prp_supervision_frame_red_box_mac_address,
306 { "redBoxMacAddress", "prp.supervision_frame.prp_red_box_mac_address",
307 FT_ETHER, BASE_NONE, NULL, 0x00,
310 { &hf_prp_supervision_frame_vdan_mac_address,
311 { "vdanMacAddress", "prp.supervision_frame.prp_vdan_mac_address",
312 FT_ETHER, BASE_NONE, NULL, 0x00,
317 { &hf_prp_redundancy_control_trailer_sequence_nr,
318 { "sequenceNr", "prp.trailer.prp_sequence_nr",
319 FT_UINT16, BASE_DEC, NULL, 0x00,
323 { &hf_prp_redundancy_control_trailer_lan,
324 { "lan", "prp.trailer.prp_lan",
325 FT_UINT16, BASE_DEC, VALS(prp_lan_vals), 0xf000,
329 { &hf_prp_redundancy_control_trailer_size,
330 { "size", "prp.trailer.prp_size",
331 FT_UINT16, BASE_DEC, NULL, 0x0fff,
336 static gint *ett[] = {
337 &ett_prp_supervision_frame,
338 &ett_prp_redundancy_control_trailer,
342 /* Register the protocol name and description */
343 proto_prp = proto_register_protocol("Parallel Redundancy Protocol (IEC62439 Part 3)",
345 prp_module = prefs_register_protocol(proto_prp, proto_reg_handoff_prp);
347 prefs_register_bool_preference(prp_module, "enable", "Enable dissector",
348 "Enable this dissector (default is false)",
349 &prp_enable_dissector);
351 /* Required function calls to register the header fields and subtree used */
352 proto_register_field_array(proto_prp, hf, array_length(hf));
353 proto_register_subtree_array(ett, array_length(ett));
357 void proto_reg_handoff_prp(void)
359 static gboolean prefs_initialized = FALSE;
361 if (!prefs_initialized) {
362 dissector_handle_t prp_supervision_frame_handle;
363 dissector_handle_t prp_redundancy_control_trailer_handle;
365 prp_supervision_frame_handle = create_dissector_handle(dissect_prp_supervision_frame, proto_prp);
366 dissector_add_uint("ethertype", ETHERTYPE_PRP, prp_supervision_frame_handle);
368 prp_redundancy_control_trailer_handle = create_dissector_handle(dissect_prp_redundancy_control_trailer, proto_prp);
369 register_postdissector(prp_redundancy_control_trailer_handle);
371 prefs_initialized = TRUE;
374 proto_set_decoding(proto_prp, prp_enable_dissector);