Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / plugins / epan / profinet / packet-pn-mrrt.c
blobb4f2a85e44c39706c2a46d02c6fb1ab43cb589a5
1 /* packet-pn-mrrt.c
2 * Routines for PN-MRRT (PROFINET Media Redundancy for cyclic realtime data)
3 * packet dissection.
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/dissectors/packet-dcerpc.h>
17 #include "packet-pn.h"
19 void proto_register_pn_mrrt(void);
20 void proto_reg_handoff_pn_mrrt(void);
22 static int proto_pn_mrrt;
24 static int hf_pn_mrrt_sequence_id;
25 static int hf_pn_mrrt_domain_uuid;
26 static int hf_pn_mrrt_type;
27 static int hf_pn_mrrt_length;
28 static int hf_pn_mrrt_version;
29 static int hf_pn_mrrt_sa;
32 static int ett_pn_mrrt;
36 static const value_string pn_mrrt_block_type_vals[] = {
37 { 0x00, "End" },
38 { 0x01, "Common" },
39 { 0x02, "Test" },
40 /*0x03 - 0x7E Reserved */
41 { 0x7F, "Organizationally Specific"},
42 { 0, NULL },
48 static int
49 dissect_PNMRRT_Common(tvbuff_t *tvb, int offset,
50 packet_info *pinfo, proto_tree *tree, proto_item *item, uint8_t length _U_)
52 uint16_t sequence_id;
53 e_guid_t uuid;
56 /* MRRT_SequenceID */
57 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrrt_sequence_id, &sequence_id);
59 /* MRRT_DomainUUID */
60 offset = dissect_pn_uuid(tvb, offset, pinfo, tree, hf_pn_mrrt_domain_uuid, &uuid);
62 col_append_str(pinfo->cinfo, COL_INFO, "Common");
64 proto_item_append_text(item, "Common");
66 return offset;
70 static int
71 dissect_PNMRRT_Test(tvbuff_t *tvb, int offset,
72 packet_info *pinfo, proto_tree *tree, proto_item *item, uint8_t length _U_)
74 uint8_t mac[6];
77 /* MRRT_SA */
78 offset = dissect_pn_mac(tvb, offset, pinfo, tree, hf_pn_mrrt_sa, mac);
80 /* Padding */
81 offset = dissect_pn_align4(tvb, offset, pinfo, tree);
83 col_append_str(pinfo->cinfo, COL_INFO, "Test");
85 proto_item_append_text(item, "Test");
87 return offset;
90 static int
91 dissect_PNMRRT_PDU(tvbuff_t *tvb, int offset,
92 packet_info *pinfo, proto_tree *tree, proto_item *item)
94 uint16_t version;
95 uint8_t type;
96 uint8_t length;
97 int i = 0;
100 /* MRRT_Version */
101 offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_mrrt_version, &version);
103 while (tvb_reported_length_remaining(tvb, offset) > 0) {
104 /* MRRT_TLVHeader.Type */
105 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_mrrt_type, &type);
107 /* MRRT_TLVHeader.Length */
108 offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_mrrt_length, &length);
111 if (i != 0) {
112 col_append_str(pinfo->cinfo, COL_INFO, ", ");
114 proto_item_append_text(item, ", ");
117 i++;
119 switch(type) {
120 case 0x00:
121 /* no content */
122 col_append_str(pinfo->cinfo, COL_INFO, "End");
123 proto_item_append_text(item, "End");
124 return offset;
125 case 0x01:
126 offset = dissect_PNMRRT_Common(tvb, offset, pinfo, tree, item, length);
127 break;
128 case 0x02:
129 offset = dissect_PNMRRT_Test(tvb, offset, pinfo, tree, item, length);
130 break;
131 default:
132 offset = dissect_pn_undecoded(tvb, offset, pinfo, tree, length);
134 col_append_fstr(pinfo->cinfo, COL_INFO, "Unknown TLVType 0x%x", type);
135 proto_item_append_text(item, "Unknown TLVType 0x%x", type);
136 break;
140 return offset;
144 /* possibly dissect a PN-RT packet (frame ID must be in the appropriate range) */
145 static bool
146 dissect_PNMRRT_Data_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
147 void *data)
149 /* the tvb will NOT contain the frame_id here, so get it from dissector data! */
150 uint16_t u16FrameID = GPOINTER_TO_UINT(data);
151 proto_item *item;
152 proto_tree *mrrt_tree;
153 int offset = 0;
154 uint32_t u32SubStart;
157 /* frame id must be in valid range (MRRT) */
158 if (u16FrameID != 0xFF60) {
159 /* we are not interested in this packet */
160 return false;
163 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PN-MRRT");
164 col_clear(pinfo->cinfo, COL_INFO);
166 /* subtree for MRRT */
167 item = proto_tree_add_protocol_format(tree, proto_pn_mrrt, tvb, 0, 0, "PROFINET MRRT, ");
168 mrrt_tree = proto_item_add_subtree(item, ett_pn_mrrt);
169 u32SubStart = offset;
171 offset = dissect_PNMRRT_PDU(tvb, offset, pinfo, mrrt_tree, item);
173 proto_item_set_len(item, offset - u32SubStart);
175 return true;
179 void
180 proto_register_pn_mrrt (void)
182 static hf_register_info hf[] = {
184 { &hf_pn_mrrt_type,
185 { "Type", "pn_mrrt.type",
186 FT_UINT8, BASE_HEX, VALS(pn_mrrt_block_type_vals), 0x0,
187 NULL, HFILL }},
189 { &hf_pn_mrrt_length,
190 { "Length", "pn_mrrt.length",
191 FT_UINT8, BASE_DEC, NULL, 0x0,
192 NULL, HFILL }},
194 { &hf_pn_mrrt_version,
195 { "Version", "pn_mrrt.version",
196 FT_UINT16, BASE_DEC, NULL, 0x0,
197 NULL, HFILL }},
199 { &hf_pn_mrrt_sequence_id,
200 { "SequenceID", "pn_mrrt.sequence_id",
201 FT_UINT16, BASE_HEX, NULL, 0x0,
202 "Unique sequence number to each outstanding service request", HFILL }},
204 { &hf_pn_mrrt_sa,
205 { "SA", "pn_mrrt.sa",
206 FT_ETHER, BASE_NONE, 0x0, 0x0,
207 NULL, HFILL }},
209 { &hf_pn_mrrt_domain_uuid,
210 { "DomainUUID", "pn_mrrt.domain_uuid",
211 FT_GUID, BASE_NONE, NULL, 0x0,
212 NULL, HFILL }},
217 static int *ett[] = {
218 &ett_pn_mrrt
221 proto_pn_mrrt = proto_register_protocol ("PROFINET MRRT", "PN-MRRT", "pn_mrrt");
222 proto_register_field_array (proto_pn_mrrt, hf, array_length (hf));
223 proto_register_subtree_array (ett, array_length (ett));
227 void
228 proto_reg_handoff_pn_mrrt (void)
231 /* register ourself as an heuristic pn-rt payload dissector */
232 heur_dissector_add("pn_rt", dissect_PNMRRT_Data_heur, "PROFINET MRRT IO", "pn_mrrt_pn_rt", proto_pn_mrrt, HEURISTIC_ENABLE);
236 * Editor modelines - https://www.wireshark.org/tools/modelines.html
238 * Local variables:
239 * c-basic-offset: 4
240 * tab-width: 8
241 * indent-tabs-mode: nil
242 * End:
244 * vi: set shiftwidth=4 tabstop=8 expandtab:
245 * :indentSize=4:tabSize=8:noTabs=true: