epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-hsr-prp-supervision.c
blob67ef2d29ec6f893392259ae9164374257257d6ba
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>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald[AT]wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <epan/packet.h>
16 #include <epan/etypes.h>
18 void proto_register_hsr_prp_supervision(void);
19 void proto_reg_handoff_hsr_prp_supervision(void);
21 static dissector_handle_t hsr_prp_supervision_handle;
23 /**********************************************************/
24 /* Channel values for the supervision type field */
25 /**********************************************************/
27 static const value_string type_vals[] = {
28 {20, "PRP Node (Duplicate Discard)"},
29 {21, "PRP Node (Duplicate Accept)"},
30 {22, "Obsolete TLV value"},
31 {23, "HSR Node"},
32 {30, "Redundancy Box MAC Address"},
33 {31, "Virtual Dual Attached Node"},
34 {0, "End of TLVs"},
35 {0, NULL}
38 /**********************************************************/
39 /* Initialize the protocol and registered fields */
40 /**********************************************************/
42 static int proto_hsr_prp_supervision;
44 /* Initialize supervision frame fields */
45 static int hf_hsr_prp_supervision_path;
46 static int hf_hsr_prp_supervision_version;
47 static int hf_hsr_prp_supervision_seqno;
48 static int hf_hsr_prp_supervision_tlv_type;
49 static int hf_hsr_prp_supervision_tlv_length;
50 static int hf_hsr_prp_supervision_source_mac_address_A;
51 static int hf_hsr_prp_supervision_source_mac_address_B;
52 static int hf_hsr_prp_supervision_source_mac_address;
53 static int hf_hsr_prp_supervision_red_box_mac_address;
54 static int hf_hsr_prp_supervision_vdan_mac_address;
56 /* Initialize the subtree pointers */
57 static int ett_hsr_prp_supervision;
59 /* Code to actually dissect the packets */
60 static int
61 dissect_hsr_prp_supervision(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
63 proto_item *ti;
64 proto_tree *hsr_prp_supervision_tree;
65 uint8_t tlv_type;
66 uint8_t tlv_length;
67 uint16_t sup_version;
68 int offset;
70 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HSR/PRP");
72 /* may get modified later while parsing */
73 col_set_str(pinfo->cinfo, COL_INFO, "HSR or PRP Supervision");
75 /* create display subtree for the protocol */
76 ti = proto_tree_add_item(tree, proto_hsr_prp_supervision, tvb, 0, -1, ENC_NA);
78 hsr_prp_supervision_tree = proto_item_add_subtree(ti, ett_hsr_prp_supervision);
80 offset = 0;
82 /* SupVersion */
83 proto_tree_add_item(hsr_prp_supervision_tree, hf_hsr_prp_supervision_path,
84 tvb, offset, 2, ENC_BIG_ENDIAN);
85 proto_tree_add_item(hsr_prp_supervision_tree, hf_hsr_prp_supervision_version,
86 tvb, offset, 2, ENC_BIG_ENDIAN);
87 sup_version = tvb_get_ntohs(tvb, 0) & 0x0fff;
88 offset += 2;
90 if (sup_version > 0) {
91 /* SupSequenceNumber */
92 proto_tree_add_item(hsr_prp_supervision_tree, hf_hsr_prp_supervision_seqno,
93 tvb, offset, 2, ENC_BIG_ENDIAN);
94 offset += 2;
97 while (tvb_reported_length_remaining(tvb, offset) > 0) {
98 /* TLV.type */
99 tlv_type = tvb_get_uint8(tvb, offset);
100 proto_tree_add_item(hsr_prp_supervision_tree, hf_hsr_prp_supervision_tlv_type,
101 tvb, offset, 1, ENC_BIG_ENDIAN);
102 offset += 1;
104 /* TLV.length */
105 tlv_length = tvb_get_uint8(tvb, offset);
106 proto_tree_add_item(hsr_prp_supervision_tree, hf_hsr_prp_supervision_tlv_length,
107 tvb, offset, 1, ENC_BIG_ENDIAN);
108 offset += 1;
110 /* TLV.value */
111 if ((tlv_type == 20 || tlv_type == 21 || tlv_type == 23) && (tlv_length == 6 || tlv_length == 12)) {
112 if (tlv_type == 23) {
113 col_set_str(pinfo->cinfo, COL_INFO, "HSR Supervision");
114 } else {
115 col_set_str(pinfo->cinfo, COL_INFO, "PRP Supervision");
117 if (tlv_length == 12) {
118 /* MacAddressA, MacAddressB (PRP only) */
119 proto_tree_add_item(hsr_prp_supervision_tree, hf_hsr_prp_supervision_source_mac_address_A,
120 tvb, offset, 6, ENC_NA);
121 proto_tree_add_item(hsr_prp_supervision_tree, hf_hsr_prp_supervision_source_mac_address_B,
122 tvb, offset+6, 6, ENC_NA);
123 /* PRP-0 supervision: if the node is not a RedBox, we have
124 just read the last TLV. The next two octets are
125 required to be zero by PRP-0. We will dissect those as
126 "end of list" and break. */
127 } else {
128 /* MacAddress */
129 proto_tree_add_item(hsr_prp_supervision_tree, hf_hsr_prp_supervision_source_mac_address,
130 tvb, offset, 6, ENC_NA);
132 } else if (tlv_type == 30 && tlv_length == 6) {
133 /* RedBoxMacAddress */
134 proto_tree_add_item(hsr_prp_supervision_tree, hf_hsr_prp_supervision_red_box_mac_address,
135 tvb, offset, 6, ENC_NA);
136 if (sup_version == 0) {
137 /* PRP-0 supervision: end of TLV data. Stop now, don't
138 interpret the padding. */
139 offset += tlv_length;
140 break;
142 } else if (tlv_type == 31 && tlv_length == 6) {
143 /* VdanMacAddress */
144 proto_tree_add_item(hsr_prp_supervision_tree, hf_hsr_prp_supervision_vdan_mac_address,
145 tvb, offset, 6, ENC_NA);
146 if (sup_version == 0) {
147 /* PRP-0 supervision: end of TLV data, padding starts */
148 offset += tlv_length;
149 break;
151 } else if (tlv_type == 0) {
152 /* End of TLV list. */
153 offset += tlv_length;
154 break;
155 } else {
156 /* unknown TLV.type, or unexpected TLV.length */
158 offset += tlv_length;
161 proto_item_set_len(ti, offset);
162 /* Adjust the length of this tvbuff to include only the supervision data.
163 This allows the rest to be marked as padding. */
164 tvb_set_reported_length(tvb, offset);
165 return tvb_captured_length(tvb);
169 /* Register the protocol with Wireshark */
170 void proto_register_hsr_prp_supervision(void)
173 static hf_register_info hf[] = {
175 { &hf_hsr_prp_supervision_path,
176 { "Path", "hsr_prp_supervision.path",
177 FT_UINT16, BASE_DEC, NULL, 0xf000,
178 NULL, HFILL }
180 { &hf_hsr_prp_supervision_version,
181 { "Version", "hsr_prp_supervision.version",
182 FT_UINT16, BASE_DEC, NULL, 0x0fff,
183 NULL, HFILL }
185 { &hf_hsr_prp_supervision_seqno,
186 { "Sequence number", "hsr_prp_supervision.supervision_seqno",
187 FT_UINT16, BASE_DEC, NULL, 0x00,
188 NULL, HFILL }
190 { &hf_hsr_prp_supervision_tlv_type,
191 { "TLV type", "hsr_prp_supervision.tlv.type",
192 FT_UINT8, BASE_DEC, VALS(type_vals), 0x00,
193 NULL, HFILL }
195 { &hf_hsr_prp_supervision_tlv_length,
196 { "TLV length", "hsr_prp_supervision.tlv.length",
197 FT_UINT8, BASE_DEC, NULL, 0x00,
198 NULL, HFILL }
200 { &hf_hsr_prp_supervision_source_mac_address_A,
201 { "Source MAC Address A", "hsr_prp_supervision.source_mac_address_A",
202 FT_ETHER, BASE_NONE, NULL, 0x00,
203 NULL, HFILL }
205 { &hf_hsr_prp_supervision_source_mac_address_B,
206 { "Source MAC Address B", "hsr_prp_supervision.source_mac_address_B",
207 FT_ETHER, BASE_NONE, NULL, 0x00,
208 NULL, HFILL }
210 { &hf_hsr_prp_supervision_source_mac_address,
211 { "Source MAC Address", "hsr_prp_supervision.source_mac_address",
212 FT_ETHER, BASE_NONE, NULL, 0x00,
213 NULL, HFILL }
215 { &hf_hsr_prp_supervision_red_box_mac_address,
216 { "RedBox MAC Address", "hsr_prp_supervision.red_box_mac_address",
217 FT_ETHER, BASE_NONE, NULL, 0x00,
218 NULL, HFILL }
220 { &hf_hsr_prp_supervision_vdan_mac_address,
221 { "VDAN MAC Address", "hsr_prp_supervision.vdan_mac_address",
222 FT_ETHER, BASE_NONE, NULL, 0x00,
223 NULL, HFILL }
228 static int *ett[] = {
229 &ett_hsr_prp_supervision
232 /* Register the protocol name and description */
233 proto_hsr_prp_supervision = proto_register_protocol("HSR/PRP Supervision (IEC62439 Part 3)",
234 "HSR_PRP_SUPERVISION", "hsr_prp_supervision");
237 /* Required function calls to register the header fields and subtree used */
238 proto_register_field_array(proto_hsr_prp_supervision, hf, array_length(hf));
239 proto_register_subtree_array(ett, array_length(ett));
241 hsr_prp_supervision_handle = register_dissector("hsr_prp_supervision",
242 dissect_hsr_prp_supervision, proto_hsr_prp_supervision);
246 void proto_reg_handoff_hsr_prp_supervision(void)
248 dissector_add_uint("ethertype", ETHERTYPE_PRP, hsr_prp_supervision_handle);
252 * Editor modelines - https://www.wireshark.org/tools/modelines.html
254 * Local variables:
255 * c-basic-offset: 4
256 * tab-width: 8
257 * indent-tabs-mode: nil
258 * End:
260 * vi: set shiftwidth=4 tabstop=8 expandtab:
261 * :indentSize=4:tabSize=8:noTabs=true: