2008-02-27 21:52:17 +00:00
|
|
|
/* packet-prp.c
|
2011-01-21 06:30:55 +00:00
|
|
|
* Routines for PRP (Parallel Redundancy Protocol; IEC62439 Part 3) dissection
|
2008-02-27 21:52:17 +00:00
|
|
|
* Copyright 2007, Sven Meier <msv[AT]zhwin.ch>
|
2011-10-31 18:37:58 +00:00
|
|
|
* Copyright 2011, Martin Renold <reld[AT]zhaw.ch>
|
|
|
|
* Copyright 2011, Florian Reichert <refl [AT] zhaw.ch>
|
2008-02-27 21:52:17 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald[AT]wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 23:18:38 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-02-27 21:52:17 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2008-02-27 21:52:17 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/etypes.h>
|
2008-02-27 23:24:40 +00:00
|
|
|
#include <epan/prefs.h>
|
2008-02-27 21:52:17 +00:00
|
|
|
|
2008-03-04 19:13:06 +00:00
|
|
|
#define PRP_LAN_A 10
|
|
|
|
#define PRP_LAN_B 11
|
2008-02-27 21:52:17 +00:00
|
|
|
|
|
|
|
static const value_string prp_lan_vals[] = {
|
2011-10-31 18:37:58 +00:00
|
|
|
{PRP_LAN_A, "LAN A"},
|
|
|
|
{PRP_LAN_B, "LAN B"},
|
|
|
|
{0, NULL}
|
|
|
|
};
|
2008-02-27 21:52:17 +00:00
|
|
|
|
|
|
|
/**********************************************************/
|
2008-03-04 19:13:06 +00:00
|
|
|
/* Initialize the protocol and registered fields */
|
2008-02-27 21:52:17 +00:00
|
|
|
/**********************************************************/
|
|
|
|
|
2013-12-12 19:52:14 +00:00
|
|
|
void proto_register_prp(void);
|
2008-02-27 23:24:40 +00:00
|
|
|
void proto_reg_handoff_prp(void);
|
2013-12-12 19:52:14 +00:00
|
|
|
|
2008-02-27 21:52:17 +00:00
|
|
|
static int proto_prp = -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize trailer fields */
|
|
|
|
static int hf_prp_redundancy_control_trailer_sequence_nr = -1;
|
|
|
|
static int hf_prp_redundancy_control_trailer_lan = -1;
|
|
|
|
static int hf_prp_redundancy_control_trailer_size = -1;
|
2011-10-31 18:37:58 +00:00
|
|
|
static int hf_prp_redundancy_control_trailer_suffix = -1;
|
|
|
|
static int hf_prp_redundancy_control_trailer_version = -1;
|
2008-02-27 21:52:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Initialize the subtree pointers */
|
|
|
|
static gint ett_prp_redundancy_control_trailer = -1;
|
|
|
|
|
2008-02-27 23:24:40 +00:00
|
|
|
|
|
|
|
/* Post dissectors (such as the trailer dissector for this protocol)
|
|
|
|
* get called for every single frame anyone loads into Wireshark.
|
|
|
|
* Since this protocol is not of general interest we disable this
|
|
|
|
* protocol by default.
|
|
|
|
*
|
|
|
|
* This is done separately from the disabled protocols list mainly so
|
|
|
|
* we can disable it by default. XXX Maybe there's a better way.
|
|
|
|
*/
|
|
|
|
static gboolean prp_enable_dissector = FALSE;
|
|
|
|
|
|
|
|
|
2008-02-27 21:52:17 +00:00
|
|
|
/* Code to actually dissect the packets */
|
|
|
|
static void
|
|
|
|
dissect_prp_redundancy_control_trailer(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
|
|
|
|
{
|
2008-03-04 19:13:06 +00:00
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *prp_tree;
|
2012-01-19 17:42:28 +00:00
|
|
|
guint i;
|
|
|
|
guint length;
|
|
|
|
guint offset;
|
|
|
|
guint16 lan_id;
|
|
|
|
guint16 lsdu_size;
|
|
|
|
guint16 prp1_suffix;
|
|
|
|
guint trailer_start;
|
|
|
|
guint trailer_length;
|
2008-03-04 19:13:06 +00:00
|
|
|
|
|
|
|
if (!tree)
|
|
|
|
return;
|
|
|
|
|
2011-10-31 18:37:58 +00:00
|
|
|
trailer_start = 0;
|
|
|
|
trailer_length = 0;
|
2008-03-04 19:13:06 +00:00
|
|
|
length = tvb_reported_length(tvb);
|
|
|
|
|
|
|
|
if(length < 14)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-22 15:08:32 +00:00
|
|
|
if(ETHERTYPE_VLAN == tvb_get_ntohs(tvb, 12)) /* tagged frame */
|
2008-03-04 19:13:06 +00:00
|
|
|
{
|
|
|
|
offset = 18;
|
|
|
|
}
|
2010-10-22 15:08:32 +00:00
|
|
|
else /* untagged */
|
2008-03-04 19:13:06 +00:00
|
|
|
{
|
|
|
|
offset = 14;
|
|
|
|
}
|
|
|
|
|
2011-10-31 18:37:58 +00:00
|
|
|
/* search for PRP-0 trailer */
|
|
|
|
/* If the frame is > 64 bytes, the PRP-0 trailer is always at the end. */
|
|
|
|
/* If the frame is <= 64 bytes, the PRP-0 trailer may be anywhere (before the padding) */
|
|
|
|
for(i=length-4; i>=offset; i--)
|
2008-03-04 19:13:06 +00:00
|
|
|
{
|
2011-10-31 18:37:58 +00:00
|
|
|
lan_id = tvb_get_ntohs(tvb, (i+2)) >> 12;
|
|
|
|
lsdu_size = tvb_get_ntohs(tvb, (i+2)) & 0x0fff;
|
|
|
|
if(lsdu_size == i+4-offset && (lan_id == 0xa || lan_id == 0xb))
|
2008-03-04 19:13:06 +00:00
|
|
|
{
|
2012-01-19 17:42:28 +00:00
|
|
|
trailer_start = i;
|
2011-10-31 18:37:58 +00:00
|
|
|
trailer_length = 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length > 64) {
|
|
|
|
break; /* don't search, just check the last position */
|
2008-03-04 19:13:06 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-31 18:37:58 +00:00
|
|
|
|
|
|
|
/* check for PRP-1 trailer */
|
|
|
|
/* PRP-1 trailer is always at the end of the frame, after any padding. */
|
2008-03-04 19:13:06 +00:00
|
|
|
{
|
2011-10-31 18:37:58 +00:00
|
|
|
lan_id = tvb_get_ntohs(tvb, length-4) >> 12;
|
|
|
|
lsdu_size = tvb_get_ntohs(tvb, length-4) & 0x0fff;
|
|
|
|
prp1_suffix = tvb_get_ntohs(tvb, length-2);
|
|
|
|
|
|
|
|
if(prp1_suffix == ETHERTYPE_PRP && (lan_id == 0xa || lan_id == 0xb))
|
2008-03-04 19:13:06 +00:00
|
|
|
{
|
2011-10-31 18:37:58 +00:00
|
|
|
/* We don't check the lsdu_size, we just display whether
|
|
|
|
it's correct. Helpful for testing, because different
|
|
|
|
definitions of the lsdu_size did exist. */
|
2012-01-19 17:42:28 +00:00
|
|
|
trailer_start = length-6;
|
2011-10-31 18:37:58 +00:00
|
|
|
trailer_length = 6;
|
2008-03-04 19:13:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-31 18:37:58 +00:00
|
|
|
if(trailer_length != 0)
|
2008-03-04 19:13:06 +00:00
|
|
|
{
|
|
|
|
/* create display subtree for the protocol */
|
2011-10-31 18:37:58 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_prp, tvb, trailer_start,
|
|
|
|
trailer_length, ENC_NA);
|
2008-03-04 19:13:06 +00:00
|
|
|
|
|
|
|
prp_tree = proto_item_add_subtree(ti, ett_prp_redundancy_control_trailer);
|
|
|
|
|
2011-10-31 18:37:58 +00:00
|
|
|
if (trailer_length == 4) {
|
|
|
|
ti = proto_tree_add_string(prp_tree, hf_prp_redundancy_control_trailer_version,
|
|
|
|
tvb, trailer_start, trailer_length, "PRP-0");
|
|
|
|
} else {
|
|
|
|
ti = proto_tree_add_string(prp_tree, hf_prp_redundancy_control_trailer_version,
|
|
|
|
tvb, trailer_start, trailer_length, "PRP-1");
|
|
|
|
}
|
|
|
|
PROTO_ITEM_SET_GENERATED(ti);
|
|
|
|
|
2008-03-04 19:13:06 +00:00
|
|
|
proto_tree_add_item(prp_tree, hf_prp_redundancy_control_trailer_sequence_nr,
|
2011-10-31 18:37:58 +00:00
|
|
|
tvb, trailer_start, 2, ENC_BIG_ENDIAN);
|
2008-03-04 19:13:06 +00:00
|
|
|
|
|
|
|
proto_tree_add_item(prp_tree, hf_prp_redundancy_control_trailer_lan,
|
2011-10-31 18:37:58 +00:00
|
|
|
tvb, trailer_start+2, 2, ENC_BIG_ENDIAN);
|
|
|
|
|
|
|
|
if (trailer_length == 4) {
|
|
|
|
/* PRP-0 */
|
|
|
|
proto_tree_add_item(prp_tree, hf_prp_redundancy_control_trailer_size,
|
|
|
|
tvb, trailer_start+2, 2, ENC_BIG_ENDIAN);
|
|
|
|
} else {
|
|
|
|
/* PRP-1 */
|
|
|
|
int lsdu_size_correct = length-offset;
|
|
|
|
if (lsdu_size == lsdu_size_correct) {
|
|
|
|
proto_tree_add_uint_format(prp_tree, hf_prp_redundancy_control_trailer_size,
|
|
|
|
tvb, trailer_start+2, 2, lsdu_size,
|
|
|
|
"LSDU size: %d [correct]", lsdu_size);
|
|
|
|
} else {
|
|
|
|
proto_tree_add_uint_format(prp_tree, hf_prp_redundancy_control_trailer_size,
|
|
|
|
tvb, trailer_start+2, 2, lsdu_size,
|
|
|
|
"LSDU size: %d [WRONG, should be %d]", lsdu_size, lsdu_size_correct);
|
|
|
|
}
|
|
|
|
/* suffix */
|
|
|
|
proto_tree_add_item(prp_tree, hf_prp_redundancy_control_trailer_suffix,
|
|
|
|
tvb, trailer_start+4, 2, ENC_BIG_ENDIAN);
|
|
|
|
}
|
2008-03-04 19:13:06 +00:00
|
|
|
}
|
2008-02-27 21:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Register the protocol with Wireshark */
|
|
|
|
void proto_register_prp(void)
|
|
|
|
{
|
2011-10-31 18:37:58 +00:00
|
|
|
static hf_register_info hf[] = {
|
2008-03-04 19:13:06 +00:00
|
|
|
/*trailer*/
|
|
|
|
{ &hf_prp_redundancy_control_trailer_sequence_nr,
|
2011-10-31 18:37:58 +00:00
|
|
|
{ "Sequence number", "prp.trailer.prp_sequence_nr",
|
2008-03-04 19:13:06 +00:00
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x00,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2008-03-04 19:13:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_prp_redundancy_control_trailer_lan,
|
2011-10-31 18:37:58 +00:00
|
|
|
{ "LAN", "prp.trailer.prp_lan",
|
2008-03-04 19:13:06 +00:00
|
|
|
FT_UINT16, BASE_DEC, VALS(prp_lan_vals), 0xf000,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2008-03-04 19:13:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_prp_redundancy_control_trailer_size,
|
2011-10-31 18:37:58 +00:00
|
|
|
{ "Size", "prp.trailer.prp_size",
|
2008-03-04 19:13:06 +00:00
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0fff,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
NULL, HFILL }
|
2011-10-31 18:37:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_prp_redundancy_control_trailer_suffix,
|
|
|
|
{ "Suffix", "prp.trailer.prp1_suffix",
|
|
|
|
FT_UINT16, BASE_HEX, NULL, 0x00,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_prp_redundancy_control_trailer_version,
|
|
|
|
{ "PRP Version", "prp.trailer.version",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x00,
|
|
|
|
NULL, HFILL }
|
2008-03-04 19:13:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_prp_redundancy_control_trailer,
|
|
|
|
};
|
|
|
|
|
2011-11-14 20:04:04 +00:00
|
|
|
module_t *prp_module;
|
2008-03-04 19:13:06 +00:00
|
|
|
|
|
|
|
/* Register the protocol name and description */
|
2011-01-21 06:30:55 +00:00
|
|
|
proto_prp = proto_register_protocol("Parallel Redundancy Protocol (IEC62439 Part 3)",
|
2008-03-04 19:13:06 +00:00
|
|
|
"PRP", "prp");
|
|
|
|
prp_module = prefs_register_protocol(proto_prp, proto_reg_handoff_prp);
|
|
|
|
|
|
|
|
prefs_register_bool_preference(prp_module, "enable", "Enable dissector",
|
|
|
|
"Enable this dissector (default is false)",
|
|
|
|
&prp_enable_dissector);
|
|
|
|
|
|
|
|
/* Required function calls to register the header fields and subtree used */
|
|
|
|
proto_register_field_array(proto_prp, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
2008-02-27 21:52:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void proto_reg_handoff_prp(void)
|
|
|
|
{
|
2008-09-22 16:26:41 +00:00
|
|
|
static gboolean prefs_initialized = FALSE;
|
2008-02-27 21:52:17 +00:00
|
|
|
|
2008-03-04 19:13:06 +00:00
|
|
|
if (!prefs_initialized) {
|
|
|
|
dissector_handle_t prp_redundancy_control_trailer_handle;
|
2008-02-27 23:24:40 +00:00
|
|
|
|
2008-03-04 19:13:06 +00:00
|
|
|
prp_redundancy_control_trailer_handle = create_dissector_handle(dissect_prp_redundancy_control_trailer, proto_prp);
|
|
|
|
register_postdissector(prp_redundancy_control_trailer_handle);
|
2008-02-27 23:24:40 +00:00
|
|
|
|
2008-03-04 19:13:06 +00:00
|
|
|
prefs_initialized = TRUE;
|
|
|
|
}
|
2008-02-27 21:52:17 +00:00
|
|
|
|
2011-11-14 20:04:04 +00:00
|
|
|
proto_set_decoding(proto_prp, prp_enable_dissector);
|
2008-02-27 21:52:17 +00:00
|
|
|
}
|