2011-10-31 18:37:58 +00:00
|
|
|
/* packet-hsr.c
|
|
|
|
* Routines for HSR dissection (IEC62439 Part 3)
|
|
|
|
* Copyright 2009, Florian Reichert <refl[AT]zhaw.ch>
|
|
|
|
*
|
|
|
|
* 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.
|
2011-10-31 18:37:58 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2011-10-31 18:37:58 +00:00
|
|
|
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/etypes.h>
|
|
|
|
|
2013-12-15 23:44:12 +00:00
|
|
|
void proto_register_hsr(void);
|
|
|
|
void proto_reg_handoff_hsr(void);
|
|
|
|
|
2011-10-31 18:37:58 +00:00
|
|
|
/**********************************************************/
|
|
|
|
/* Lengths of fields within a HSR packet. */
|
|
|
|
/**********************************************************/
|
|
|
|
#define HSR_LSDU_PATH_LENGTH 2
|
|
|
|
#define HSR_SEQUENZNR_LENGTH 2
|
|
|
|
|
|
|
|
#define HSR_TOTAL_LENGTH 4
|
|
|
|
|
|
|
|
/**********************************************************/
|
|
|
|
/* Offsets of fields within a HSR packet. */
|
|
|
|
/**********************************************************/
|
|
|
|
#define HSR_PATH_OFFSET 0
|
|
|
|
#define HSR_SEQUENZNR_OFFSET 2
|
|
|
|
|
|
|
|
static const value_string hsr_laneid_vals[] = {
|
|
|
|
{0, "Lane A"},
|
|
|
|
{1, "Lane B"},
|
|
|
|
{0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**********************************************************/
|
|
|
|
/* Initialize the protocol and registered fields */
|
|
|
|
/**********************************************************/
|
|
|
|
|
|
|
|
static int proto_hsr = -1;
|
|
|
|
|
|
|
|
/* Initialize supervision frame fields */
|
|
|
|
|
|
|
|
|
|
|
|
static int hf_hsr_path = -1;
|
|
|
|
static int hf_hsr_netid = -1;
|
|
|
|
static int hf_hsr_laneid = -1;
|
|
|
|
static int hf_hsr_lsdu_size = -1;
|
|
|
|
static int hf_hsr_sequence_nr = -1;
|
|
|
|
static int hf_type= -1;
|
|
|
|
|
|
|
|
static dissector_table_t ethertype_subdissector_table;
|
|
|
|
/* Initialize the subtree pointers */
|
|
|
|
static gint ett_hsr_frame = -1;
|
|
|
|
|
|
|
|
static dissector_handle_t data_handle;
|
|
|
|
|
|
|
|
/* Code to actually dissect the packets */
|
2015-11-15 21:51:45 +00:00
|
|
|
static int
|
|
|
|
dissect_hsr_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
|
2011-10-31 18:37:58 +00:00
|
|
|
{
|
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *hsr_tree;
|
|
|
|
tvbuff_t *next_tvb;
|
|
|
|
guint16 etype;
|
|
|
|
guint16 lsdu_size, lsdu_size_correct;
|
|
|
|
|
2011-11-14 20:04:04 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "HSR");
|
2011-10-31 18:37:58 +00:00
|
|
|
|
2011-11-14 20:04:04 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "HSR-Data Frame");
|
2011-10-31 18:37:58 +00:00
|
|
|
|
|
|
|
/* create display subtree for the protocol */
|
|
|
|
|
|
|
|
ti = proto_tree_add_item(tree, proto_hsr, tvb, 0, HSR_TOTAL_LENGTH, ENC_NA);
|
|
|
|
|
|
|
|
hsr_tree = proto_item_add_subtree(ti, ett_hsr_frame);
|
|
|
|
|
|
|
|
proto_tree_add_item(hsr_tree, hf_hsr_path,
|
|
|
|
tvb, HSR_PATH_OFFSET, HSR_LSDU_PATH_LENGTH , ENC_BIG_ENDIAN);
|
|
|
|
|
|
|
|
proto_tree_add_item(hsr_tree, hf_hsr_netid,
|
|
|
|
tvb, HSR_PATH_OFFSET, HSR_LSDU_PATH_LENGTH , ENC_BIG_ENDIAN);
|
|
|
|
|
|
|
|
proto_tree_add_item(hsr_tree, hf_hsr_laneid,
|
|
|
|
tvb, HSR_PATH_OFFSET, HSR_LSDU_PATH_LENGTH , ENC_BIG_ENDIAN);
|
|
|
|
|
|
|
|
|
|
|
|
lsdu_size = tvb_get_ntohs(tvb, HSR_PATH_OFFSET) & 0x0fff;
|
|
|
|
lsdu_size_correct = tvb_reported_length_remaining(tvb, 0);
|
|
|
|
if (lsdu_size == lsdu_size_correct) {
|
2013-09-15 01:48:30 +00:00
|
|
|
proto_tree_add_uint_format_value(hsr_tree, hf_hsr_lsdu_size,
|
2011-10-31 18:37:58 +00:00
|
|
|
tvb, HSR_PATH_OFFSET, HSR_LSDU_PATH_LENGTH, lsdu_size,
|
2013-09-15 01:48:30 +00:00
|
|
|
"%d [correct]", lsdu_size);
|
2011-10-31 18:37:58 +00:00
|
|
|
} else {
|
2013-09-15 01:48:30 +00:00
|
|
|
proto_tree_add_uint_format_value(hsr_tree, hf_hsr_lsdu_size,
|
2011-10-31 18:37:58 +00:00
|
|
|
tvb, HSR_PATH_OFFSET, HSR_LSDU_PATH_LENGTH, lsdu_size,
|
2013-09-15 01:48:30 +00:00
|
|
|
"%d [WRONG, should be %d]", lsdu_size, lsdu_size_correct);
|
2011-10-31 18:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proto_tree_add_item(hsr_tree, hf_hsr_sequence_nr,
|
|
|
|
tvb, HSR_SEQUENZNR_OFFSET,HSR_SEQUENZNR_LENGTH, ENC_BIG_ENDIAN);
|
|
|
|
|
|
|
|
proto_tree_add_item(hsr_tree, hf_type,
|
|
|
|
tvb, HSR_TOTAL_LENGTH,2, ENC_BIG_ENDIAN);
|
|
|
|
|
2013-02-19 23:17:07 +00:00
|
|
|
next_tvb = tvb_new_subset_remaining(tvb, HSR_TOTAL_LENGTH + 2);
|
2011-10-31 18:37:58 +00:00
|
|
|
|
|
|
|
etype = tvb_get_ntohs(tvb, HSR_TOTAL_LENGTH);
|
|
|
|
|
|
|
|
if (!dissector_try_uint(ethertype_subdissector_table, etype, next_tvb, pinfo, tree))
|
|
|
|
call_dissector(data_handle, next_tvb, pinfo, hsr_tree);
|
|
|
|
|
2015-11-15 21:51:45 +00:00
|
|
|
return tvb_captured_length(tvb);
|
2011-10-31 18:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Register the protocol with Wireshark */
|
|
|
|
void proto_register_hsr(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_hsr_path,
|
|
|
|
{ "Path", "hsr.path",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0xf000,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_hsr_netid,
|
|
|
|
{ "Network id", "hsr.netid",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0xe000,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_hsr_laneid,
|
|
|
|
{ "Lane id", "hsr.laneid",
|
|
|
|
FT_UINT16, BASE_DEC, VALS(hsr_laneid_vals), 0x1000,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_hsr_lsdu_size,
|
|
|
|
{ "LSDU size", "hsr.lsdu_size",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0fff,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
|
|
|
|
{ &hf_hsr_sequence_nr,
|
2012-07-22 03:06:37 +00:00
|
|
|
{ "Sequence number", "hsr.sequence_nr",
|
2011-10-31 18:37:58 +00:00
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x00,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_type,
|
|
|
|
{ "Type", "hsr.type",
|
|
|
|
FT_UINT16, BASE_HEX, VALS(etype_vals), 0x00,
|
|
|
|
NULL, HFILL }
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_hsr_frame,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register the protocol name and description */
|
|
|
|
proto_hsr = proto_register_protocol("High-availability Seamless Redundancy (IEC62439 Part 3 Chapter 5)",
|
|
|
|
"HSR", "hsr");
|
|
|
|
|
|
|
|
/* Required function calls to register the header fields and subtree used */
|
|
|
|
proto_register_field_array(proto_hsr, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void proto_reg_handoff_hsr(void)
|
|
|
|
{
|
|
|
|
dissector_handle_t hsr_frame_handle;
|
2015-12-09 03:49:44 +00:00
|
|
|
hsr_frame_handle = create_dissector_handle(dissect_hsr_frame, proto_hsr);
|
2011-10-31 18:37:58 +00:00
|
|
|
dissector_add_uint("ethertype", ETHERTYPE_HSR, hsr_frame_handle);
|
|
|
|
|
|
|
|
ethertype_subdissector_table = find_dissector_table("ethertype");
|
|
|
|
data_handle = find_dissector("data");
|
|
|
|
}
|
2014-09-29 18:42:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|