MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / dissectors / packet-hsr.c
blob9d5c80e8c5355b6d36d16f78c9fac339cd726ec2
1 /* packet-hsr.c
2 * Routines for HSR dissection (IEC62439 Part 3)
3 * Copyright 2009, Florian Reichert <refl[AT]zhaw.ch>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald[AT]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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
29 #include <epan/packet.h>
30 #include <epan/etypes.h>
32 /**********************************************************/
33 /* Lengths of fields within a HSR packet. */
34 /**********************************************************/
35 #define HSR_LSDU_PATH_LENGTH 2
36 #define HSR_SEQUENZNR_LENGTH 2
38 #define HSR_TOTAL_LENGTH 4
40 /**********************************************************/
41 /* Offsets of fields within a HSR packet. */
42 /**********************************************************/
43 #define HSR_PATH_OFFSET 0
44 #define HSR_SEQUENZNR_OFFSET 2
46 static const value_string hsr_laneid_vals[] = {
47 {0, "Lane A"},
48 {1, "Lane B"},
49 {0, NULL}
52 /**********************************************************/
53 /* Initialize the protocol and registered fields */
54 /**********************************************************/
56 static int proto_hsr = -1;
58 /* Initialize supervision frame fields */
61 static int hf_hsr_path = -1;
62 static int hf_hsr_netid = -1;
63 static int hf_hsr_laneid = -1;
64 static int hf_hsr_lsdu_size = -1;
65 static int hf_hsr_sequence_nr = -1;
66 static int hf_type= -1;
68 static dissector_table_t ethertype_subdissector_table;
69 /* Initialize the subtree pointers */
70 static gint ett_hsr_frame = -1;
72 static dissector_handle_t data_handle;
74 /* Code to actually dissect the packets */
75 static void
76 dissect_hsr_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
78 proto_item *ti;
79 proto_tree *hsr_tree;
80 tvbuff_t *next_tvb;
81 guint16 etype;
82 guint16 lsdu_size, lsdu_size_correct;
84 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HSR");
86 col_set_str(pinfo->cinfo, COL_INFO, "HSR-Data Frame");
88 /* create display subtree for the protocol */
90 ti = proto_tree_add_item(tree, proto_hsr, tvb, 0, HSR_TOTAL_LENGTH, ENC_NA);
92 hsr_tree = proto_item_add_subtree(ti, ett_hsr_frame);
94 proto_tree_add_item(hsr_tree, hf_hsr_path,
95 tvb, HSR_PATH_OFFSET, HSR_LSDU_PATH_LENGTH , ENC_BIG_ENDIAN);
97 proto_tree_add_item(hsr_tree, hf_hsr_netid,
98 tvb, HSR_PATH_OFFSET, HSR_LSDU_PATH_LENGTH , ENC_BIG_ENDIAN);
100 proto_tree_add_item(hsr_tree, hf_hsr_laneid,
101 tvb, HSR_PATH_OFFSET, HSR_LSDU_PATH_LENGTH , ENC_BIG_ENDIAN);
104 lsdu_size = tvb_get_ntohs(tvb, HSR_PATH_OFFSET) & 0x0fff;
105 lsdu_size_correct = tvb_reported_length_remaining(tvb, 0);
106 if (lsdu_size == lsdu_size_correct) {
107 proto_tree_add_uint_format_value(hsr_tree, hf_hsr_lsdu_size,
108 tvb, HSR_PATH_OFFSET, HSR_LSDU_PATH_LENGTH, lsdu_size,
109 "%d [correct]", lsdu_size);
110 } else {
111 proto_tree_add_uint_format_value(hsr_tree, hf_hsr_lsdu_size,
112 tvb, HSR_PATH_OFFSET, HSR_LSDU_PATH_LENGTH, lsdu_size,
113 "%d [WRONG, should be %d]", lsdu_size, lsdu_size_correct);
116 proto_tree_add_item(hsr_tree, hf_hsr_sequence_nr,
117 tvb, HSR_SEQUENZNR_OFFSET,HSR_SEQUENZNR_LENGTH, ENC_BIG_ENDIAN);
119 proto_tree_add_item(hsr_tree, hf_type,
120 tvb, HSR_TOTAL_LENGTH,2, ENC_BIG_ENDIAN);
122 next_tvb = tvb_new_subset_remaining(tvb, HSR_TOTAL_LENGTH + 2);
124 etype = tvb_get_ntohs(tvb, HSR_TOTAL_LENGTH);
126 if (!dissector_try_uint(ethertype_subdissector_table, etype, next_tvb, pinfo, tree))
127 call_dissector(data_handle, next_tvb, pinfo, hsr_tree);
133 /* Register the protocol with Wireshark */
134 void proto_register_hsr(void)
136 static hf_register_info hf[] = {
137 { &hf_hsr_path,
138 { "Path", "hsr.path",
139 FT_UINT16, BASE_DEC, NULL, 0xf000,
140 NULL, HFILL }
143 { &hf_hsr_netid,
144 { "Network id", "hsr.netid",
145 FT_UINT16, BASE_DEC, NULL, 0xe000,
146 NULL, HFILL }
149 { &hf_hsr_laneid,
150 { "Lane id", "hsr.laneid",
151 FT_UINT16, BASE_DEC, VALS(hsr_laneid_vals), 0x1000,
152 NULL, HFILL }
155 { &hf_hsr_lsdu_size,
156 { "LSDU size", "hsr.lsdu_size",
157 FT_UINT16, BASE_DEC, NULL, 0x0fff,
158 NULL, HFILL }
161 { &hf_hsr_sequence_nr,
162 { "Sequence number", "hsr.sequence_nr",
163 FT_UINT16, BASE_DEC, NULL, 0x00,
164 NULL, HFILL }
166 { &hf_type,
167 { "Type", "hsr.type",
168 FT_UINT16, BASE_HEX, VALS(etype_vals), 0x00,
169 NULL, HFILL }
174 static gint *ett[] = {
175 &ett_hsr_frame,
178 /* Register the protocol name and description */
179 proto_hsr = proto_register_protocol("High-availability Seamless Redundancy (IEC62439 Part 3 Chapter 5)",
180 "HSR", "hsr");
182 /* Required function calls to register the header fields and subtree used */
183 proto_register_field_array(proto_hsr, hf, array_length(hf));
184 proto_register_subtree_array(ett, array_length(ett));
188 void proto_reg_handoff_hsr(void)
190 dissector_handle_t hsr_frame_handle;
191 hsr_frame_handle = create_dissector_handle(dissect_hsr_frame, proto_hsr);
192 dissector_add_uint("ethertype", ETHERTYPE_HSR, hsr_frame_handle);
194 ethertype_subdissector_table = find_dissector_table("ethertype");
195 data_handle = find_dissector("data");