2 * Common functions for other PROFINET protocols like IO, CBA, DCP, ...
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1999 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <epan/packet.h>
32 #include <epan/dissectors/packet-dcerpc.h>
33 #include <epan/expert.h>
35 #include "packet-pn.h"
39 static int hf_pn_padding
= -1;
40 static int hf_pn_undecoded_data
= -1;
41 static int hf_pn_user_data
= -1;
42 static int hf_pn_user_bytes
= -1;
43 static int hf_pn_frag_bytes
= -1;
44 static int hf_pn_malformed
= -1;
46 static expert_field ei_pn_undecoded_data
= EI_INIT
;
48 /* dissect an 8 bit unsigned integer */
50 dissect_pn_uint8(tvbuff_t
*tvb
, gint offset
, packet_info
*pinfo _U_
,
51 proto_tree
*tree
, int hfindex
, guint8
*pdata
)
55 data
= tvb_get_guint8 (tvb
, offset
);
57 proto_tree_add_uint(tree
, hfindex
, tvb
, offset
, 1, data
);
64 /* dissect a 16 bit unsigned integer */
66 dissect_pn_uint16(tvbuff_t
*tvb
, gint offset
, packet_info
*pinfo _U_
,
67 proto_tree
*tree
, int hfindex
, guint16
*pdata
)
71 data
= tvb_get_ntohs (tvb
, offset
);
74 proto_tree_add_uint(tree
, hfindex
, tvb
, offset
, 2, data
);
81 /* dissect a 32 bit unsigned integer */
83 dissect_pn_uint32(tvbuff_t
*tvb
, gint offset
, packet_info
*pinfo _U_
,
84 proto_tree
*tree
, int hfindex
, guint32
*pdata
)
88 data
= tvb_get_ntohl (tvb
, offset
);
91 proto_tree_add_uint(tree
, hfindex
, tvb
, offset
, 4, data
);
98 /* dissect a 16 bit signed integer */
100 dissect_pn_int16(tvbuff_t
*tvb
, gint offset
, packet_info
*pinfo _U_
,
101 proto_tree
*tree
, int hfindex
, gint16
*pdata
)
105 data
= tvb_get_ntohs (tvb
, offset
);
108 proto_tree_add_int(tree
, hfindex
, tvb
, offset
, 2, data
);
115 /* dissect a 32 bit signed integer */
117 dissect_pn_int32(tvbuff_t
*tvb
, gint offset
, packet_info
*pinfo _U_
,
118 proto_tree
*tree
, int hfindex
, gint32
*pdata
)
122 data
= tvb_get_ntohl (tvb
, offset
);
125 proto_tree_add_int(tree
, hfindex
, tvb
, offset
, 4, data
);
132 /* dissect a 24bit OUI (IEC organizational unique id) */
134 dissect_pn_oid(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
,
135 proto_tree
*tree
, int hfindex
, guint32
*pdata
)
139 data
= tvb_get_ntoh24(tvb
, offset
);
142 proto_tree_add_uint(tree
, hfindex
, tvb
, offset
, 3, data
);
149 /* dissect a 6 byte MAC address */
151 dissect_pn_mac(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
,
152 proto_tree
*tree
, int hfindex
, guint8
*pdata
)
156 tvb_memcpy(tvb
, data
, offset
, 6);
158 proto_tree_add_ether(tree
, hfindex
, tvb
, offset
, 6, data
);
161 memcpy(pdata
, data
, 6);
166 /* dissect an IPv4 address */
168 dissect_pn_ipv4(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
,
169 proto_tree
*tree
, int hfindex
, guint32
*pdata
)
173 data
= tvb_get_ipv4(tvb
, offset
);
175 proto_tree_add_ipv4(tree
, hfindex
, tvb
, offset
, 4, data
);
183 /* dissect a 16 byte UUID address */
185 dissect_pn_uuid(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
,
186 proto_tree
*tree
, int hfindex
, e_uuid_t
*uuid
)
188 guint8 drep
[2] = { 0,0 };
190 offset
= dissect_dcerpc_uuid_t(tvb
, offset
, pinfo
, tree
, drep
,
196 /* "dissect" some bytes still undecoded (with Expert warning) */
198 dissect_pn_undecoded(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
,
199 proto_tree
*tree
, guint32 length
)
204 item
= proto_tree_add_string_format(tree
, hf_pn_undecoded_data
, tvb
, offset
, length
, "data",
205 "Undecoded Data: %d bytes", length
);
207 expert_add_info_format(pinfo
, item
, &ei_pn_undecoded_data
,
208 "Undecoded Data, %u bytes", length
);
210 return offset
+ length
;
213 /* "dissect" some user bytes */
215 dissect_pn_user_data_bytes(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
,
216 proto_tree
*tree
, guint32 length
, int iSelect
)
219 if(iSelect
== FRAG_DATA
)
220 proto_tree_add_bytes(tree
, hf_pn_frag_bytes
, tvb
, offset
, length
, tvb_get_ptr(tvb
,offset
, length
));
222 proto_tree_add_bytes(tree
, hf_pn_user_bytes
, tvb
, offset
, length
, tvb_get_ptr(tvb
,offset
, length
));
224 return offset
+ length
;
228 dissect_pn_user_data(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
,
229 proto_tree
*tree
, guint32 length
, const char *text
)
232 proto_tree_add_string_format(tree
, hf_pn_user_data
, tvb
, offset
, length
, "data",
233 "%s: %d bytes", text
, length
);
235 return offset
+ length
;
238 /* packet is malformed, mark it as such */
240 dissect_pn_malformed(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
,
241 proto_tree
*tree
, guint32 length
)
243 proto_tree_add_item(tree
, hf_pn_malformed
, tvb
, 0, 10000, ENC_NA
);
245 return offset
+ length
;
249 /* dissect some padding data (with the given length) */
251 dissect_pn_padding(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
,
252 proto_tree
*tree
, int length
)
254 proto_tree_add_string_format(tree
, hf_pn_padding
, tvb
, offset
, length
, "data",
255 "Padding: %u byte", length
);
257 return offset
+ length
;
260 /* align offset to 4 */
262 dissect_pn_align4(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo _U_
, proto_tree
*tree
)
268 padding
= 4 - (offset
% 4);
270 proto_tree_add_string_format(tree
, hf_pn_padding
, tvb
, offset
, padding
, "data",
271 "Padding: %u byte", padding
);
274 return offset
+ padding
;
277 /* append the given info text to item and column */
279 pn_append_info(packet_info
*pinfo
, proto_item
*dcp_item
, const char *text
)
281 col_append_str(pinfo
->cinfo
, COL_INFO
, text
);
283 proto_item_append_text(dcp_item
, "%s", text
);
291 static hf_register_info hf
[] = {
293 { "Padding", "pn.padding",
294 FT_STRING
, BASE_NONE
, NULL
, 0x0,
297 { &hf_pn_undecoded_data
,
298 { "Undecoded Data", "pn.undecoded",
299 FT_STRING
, BASE_NONE
, NULL
, 0x0,
303 { "User Data", "pn.user_data",
304 FT_STRING
, BASE_NONE
, NULL
, 0x0,
308 { "Substitute Data", "pn.user_bytes",
309 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
313 { "Fragment Data", "pn.frag_bytes",
314 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
318 { "Malformed", "pn_rt.malformed",
319 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
324 /*static gint *ett[] = {
327 static ei_register_info ei
[] = {
328 { &ei_pn_undecoded_data
, { "pn.undecoded_data", PI_UNDECODED
, PI_WARN
, "Undecoded Data", EXPFILL
}},
331 expert_module_t
* expert_pn
;
334 proto_register_field_array (proto
, hf
, array_length (hf
));
335 /*proto_register_subtree_array (ett, array_length (ett));*/
336 expert_pn
= expert_register_protocol(proto
);
337 expert_register_field_array(expert_pn
, ei
, array_length(ei
));