1 /* packet-hsr-prp-supervision.c
2 * Routines for HSR/PRP supervision dissection (IEC62439 Part 3)
3 * Copyright 2009, Florian Reichert <refl[AT]zhaw.ch>
4 * Copyright 2011, Martin Renold <reld[AT]zhaw.ch>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald[AT]wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/packet.h>
31 #include <epan/etypes.h>
33 /**********************************************************/
34 /* Channel values for the supervision type field */
35 /**********************************************************/
37 static const value_string type_vals
[] = {
38 {20, "PRP Node (Duplicate Discard)"},
39 {21, "PRP Node (Duplicate Accept)"},
40 {22, "Obsolete TLV value"},
42 {30, "Redundancy Box MAC Address"},
43 {31, "Virtual Dual Attached Node"},
48 /**********************************************************/
49 /* Initialize the protocol and registered fields */
50 /**********************************************************/
52 static int proto_hsr_prp_supervision
= -1;
54 /* Initialize supervision frame fields */
55 static int hf_hsr_prp_supervision_path
= -1;
56 static int hf_hsr_prp_supervision_version
= -1;
57 static int hf_hsr_prp_supervision_seqno
= -1;
58 static int hf_hsr_prp_supervision_tlv_type
= -1;
59 static int hf_hsr_prp_supervision_tlv_length
= -1;
60 static int hf_hsr_prp_supervision_source_mac_address_A
= -1;
61 static int hf_hsr_prp_supervision_source_mac_address_B
= -1;
62 static int hf_hsr_prp_supervision_source_mac_address
= -1;
63 static int hf_hsr_prp_supervision_red_box_mac_address
= -1;
64 static int hf_hsr_prp_supervision_vdan_mac_address
= -1;
66 /* Initialize the subtree pointers */
67 static gint ett_hsr_prp_supervision
= -1;
69 /* Code to actually dissect the packets */
71 dissect_hsr_prp_supervision(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
74 proto_tree
*hsr_prp_supervision_tree
;
80 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "HSR/PRP");
82 /* may get modified later while parsing */
83 col_set_str(pinfo
->cinfo
, COL_INFO
, "HSR or PRP Supervision");
85 /* create display subtree for the protocol */
86 ti
= proto_tree_add_item(tree
, proto_hsr_prp_supervision
, tvb
, 0, -1, ENC_NA
);
88 hsr_prp_supervision_tree
= proto_item_add_subtree(ti
, ett_hsr_prp_supervision
);
93 proto_tree_add_item(hsr_prp_supervision_tree
, hf_hsr_prp_supervision_path
,
94 tvb
, offset
, 2, ENC_BIG_ENDIAN
);
95 proto_tree_add_item(hsr_prp_supervision_tree
, hf_hsr_prp_supervision_version
,
96 tvb
, offset
, 2, ENC_BIG_ENDIAN
);
97 sup_version
= tvb_get_ntohs(tvb
, 0) & 0x0fff;
100 if (sup_version
> 0) {
101 /* SupSequenceNumber */
102 proto_tree_add_item(hsr_prp_supervision_tree
, hf_hsr_prp_supervision_seqno
,
103 tvb
, offset
, 2, ENC_BIG_ENDIAN
);
107 while (tvb_reported_length_remaining(tvb
, offset
) > 0) {
109 tlv_type
= tvb_get_guint8(tvb
, offset
);
110 proto_tree_add_item(hsr_prp_supervision_tree
, hf_hsr_prp_supervision_tlv_type
,
111 tvb
, offset
, 1, ENC_BIG_ENDIAN
);
115 tlv_length
= tvb_get_guint8(tvb
, offset
);
116 proto_tree_add_item(hsr_prp_supervision_tree
, hf_hsr_prp_supervision_tlv_length
,
117 tvb
, offset
, 1, ENC_BIG_ENDIAN
);
121 if ((tlv_type
== 20 || tlv_type
== 21 || tlv_type
== 23) && (tlv_length
== 6 || tlv_length
== 12)) {
122 if (tlv_type
== 23) {
123 col_set_str(pinfo
->cinfo
, COL_INFO
, "HSR Supervision");
125 col_set_str(pinfo
->cinfo
, COL_INFO
, "PRP Supervision");
127 if (tlv_length
== 12) {
128 /* MacAddressA, MacAddressB (PRP only) */
129 proto_tree_add_item(hsr_prp_supervision_tree
, hf_hsr_prp_supervision_source_mac_address_A
,
130 tvb
, offset
, 6, ENC_NA
);
131 proto_tree_add_item(hsr_prp_supervision_tree
, hf_hsr_prp_supervision_source_mac_address_B
,
132 tvb
, offset
+6, 6, ENC_NA
);
133 /* PRP-0 supervision: if the node is not a RedBox, we have
134 just read the last TLV. The next two octets are
135 required to be zero by PRP-0. We will dissect those as
136 "end of list" and break. */
139 proto_tree_add_item(hsr_prp_supervision_tree
, hf_hsr_prp_supervision_source_mac_address
,
140 tvb
, offset
, 6, ENC_NA
);
142 } else if (tlv_type
== 30 && tlv_length
== 6) {
143 /* RedBoxMacAddress */
144 proto_tree_add_item(hsr_prp_supervision_tree
, hf_hsr_prp_supervision_red_box_mac_address
,
145 tvb
, offset
, 6, ENC_NA
);
146 if (sup_version
== 0) {
147 /* PRP-0 supervision: end of TLV data. Stop now, don't
148 interpret the padding. */
149 offset
+= tlv_length
;
152 } else if (tlv_type
== 31 && tlv_length
== 6) {
154 proto_tree_add_item(hsr_prp_supervision_tree
, hf_hsr_prp_supervision_vdan_mac_address
,
155 tvb
, offset
, 6, ENC_NA
);
156 if (sup_version
== 0) {
157 /* PRP-0 supervision: end of TLV data, padding starts */
158 offset
+= tlv_length
;
161 } else if (tlv_type
== 0) {
162 /* End of TLV list. */
163 offset
+= tlv_length
;
166 /* unknown TLV.type, or unexpected TLV.length */
168 offset
+= tlv_length
;
171 proto_item_set_len(ti
, offset
);
172 /* Adjust the length of this tvbuff to include only the supervision data.
173 This allows the rest to be marked as padding. */
174 tvb_set_reported_length(tvb
, offset
);
178 /* Register the protocol with Wireshark */
179 void proto_register_hsr_prp_supervision(void)
182 static hf_register_info hf
[] = {
184 { &hf_hsr_prp_supervision_path
,
185 { "Path", "hsr_prp_supervision.path",
186 FT_UINT16
, BASE_DEC
, NULL
, 0xf000,
189 { &hf_hsr_prp_supervision_version
,
190 { "Version", "hsr_prp_supervision.version",
191 FT_UINT16
, BASE_DEC
, NULL
, 0x0fff,
194 { &hf_hsr_prp_supervision_seqno
,
195 { "Sequence number", "hsr_prp_supervision.supervision_seqno",
196 FT_UINT16
, BASE_DEC
, NULL
, 0x00,
199 { &hf_hsr_prp_supervision_tlv_type
,
200 { "TLV type", "hsr_prp_supervision.tlv.type",
201 FT_UINT8
, BASE_DEC
, VALS(type_vals
), 0x00,
204 { &hf_hsr_prp_supervision_tlv_length
,
205 { "TLV length", "hsr_prp_supervision.tlv.length",
206 FT_UINT8
, BASE_DEC
, NULL
, 0x00,
209 { &hf_hsr_prp_supervision_source_mac_address_A
,
210 { "Source MAC Address A", "hsr_prp_supervision.source_mac_address_A",
211 FT_ETHER
, BASE_NONE
, NULL
, 0x00,
214 { &hf_hsr_prp_supervision_source_mac_address_B
,
215 { "Source MAC Address B", "hsr_prp_supervision.source_mac_address_B",
216 FT_ETHER
, BASE_NONE
, NULL
, 0x00,
219 { &hf_hsr_prp_supervision_source_mac_address
,
220 { "Source MAC Address", "hsr_prp_supervision.source_mac_address",
221 FT_ETHER
, BASE_NONE
, NULL
, 0x00,
224 { &hf_hsr_prp_supervision_red_box_mac_address
,
225 { "RedBox MAC Address", "hsr_prp_supervision.red_box_mac_address",
226 FT_ETHER
, BASE_NONE
, NULL
, 0x00,
229 { &hf_hsr_prp_supervision_vdan_mac_address
,
230 { "VDAN MAC Address", "hsr_prp_supervision.vdan_mac_address",
231 FT_ETHER
, BASE_NONE
, NULL
, 0x00,
237 static gint
*ett
[] = {
238 &ett_hsr_prp_supervision
241 /* Register the protocol name and description */
242 proto_hsr_prp_supervision
= proto_register_protocol("HSR/PRP Supervision (IEC62439 Part 3)",
243 "HSR_PRP_SUPERVISION", "hsr_prp_supervision");
246 /* Required function calls to register the header fields and subtree used */
247 proto_register_field_array(proto_hsr_prp_supervision
, hf
, array_length(hf
));
248 proto_register_subtree_array(ett
, array_length(ett
));
252 void proto_reg_handoff_hsr_prp_supervision(void)
254 dissector_handle_t hsr_prp_supervision_handle
;
255 hsr_prp_supervision_handle
= create_dissector_handle(dissect_hsr_prp_supervision
, proto_hsr_prp_supervision
);
256 dissector_add_uint("ethertype", ETHERTYPE_PRP
, hsr_prp_supervision_handle
);