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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/packet.h>
34 #include <epan/dissectors/packet-dcerpc.h>
35 #include <epan/expert.h>
37 #include "packet-pn.h"
41 static int hf_pn_padding = -1;
42 static int hf_pn_undecoded_data = -1;
43 static int hf_pn_user_data = -1;
44 static int hf_pn_user_bytes = -1;
45 static int hf_pn_malformed = -1;
49 /* dissect an 8 bit unsigned integer */
51 dissect_pn_uint8(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
52 proto_tree *tree, int hfindex, guint8 *pdata)
56 data = tvb_get_guint8 (tvb, offset);
58 proto_tree_add_uint(tree, hfindex, tvb, offset, 1, data);
65 /* dissect a 16 bit unsigned integer */
67 dissect_pn_uint16(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
68 proto_tree *tree, int hfindex, guint16 *pdata)
72 data = tvb_get_ntohs (tvb, offset);
75 proto_tree_add_uint(tree, hfindex, tvb, offset, 2, data);
82 /* dissect a 32 bit unsigned integer */
84 dissect_pn_uint32(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
85 proto_tree *tree, int hfindex, guint32 *pdata)
89 data = tvb_get_ntohl (tvb, offset);
92 proto_tree_add_uint(tree, hfindex, tvb, offset, 4, data);
99 /* dissect a 16 bit signed integer */
101 dissect_pn_int16(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
102 proto_tree *tree, int hfindex, gint16 *pdata)
106 data = tvb_get_ntohs (tvb, offset);
109 proto_tree_add_int(tree, hfindex, tvb, offset, 2, data);
116 /* dissect a 32 bit signed integer */
118 dissect_pn_int32(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
119 proto_tree *tree, int hfindex, gint32 *pdata)
123 data = tvb_get_ntohl (tvb, offset);
126 proto_tree_add_int(tree, hfindex, tvb, offset, 4, data);
133 /* dissect a 24bit OUI (IEC organizational unique id) */
135 dissect_pn_oid(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
136 proto_tree *tree, int hfindex, guint32 *pdata)
140 data = tvb_get_ntoh24(tvb, offset);
143 proto_tree_add_uint(tree, hfindex, tvb, offset, 3, data);
150 /* dissect a 6 byte MAC address */
152 dissect_pn_mac(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
153 proto_tree *tree, int hfindex, guint8 *pdata)
157 tvb_memcpy(tvb, data, offset, 6);
159 proto_tree_add_ether(tree, hfindex, tvb, offset, 6, data);
162 memcpy(pdata, data, 6);
167 /* dissect an IPv4 address */
169 dissect_pn_ipv4(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
170 proto_tree *tree, int hfindex, guint32 *pdata)
174 data = tvb_get_ipv4(tvb, offset);
176 proto_tree_add_ipv4(tree, hfindex, tvb, offset, 4, data);
184 /* dissect a 16 byte UUID address */
186 dissect_pn_uuid(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
187 proto_tree *tree, int hfindex, e_uuid_t *uuid)
189 guint8 drep[2] = { 0,0 };
191 offset = dissect_dcerpc_uuid_t(tvb, offset, pinfo, tree, drep,
197 /* "dissect" some bytes still undecoded (with Expert warning) */
199 dissect_pn_undecoded(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
200 proto_tree *tree, guint32 length)
205 item = proto_tree_add_string_format(tree, hf_pn_undecoded_data, tvb, offset, length, "data",
206 "Undecoded Data: %d bytes", length);
208 expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN,
209 "Undecoded Data, %u bytes", length);
211 return offset + length;
214 /* "dissect" some user bytes */
216 dissect_pn_user_data_bytes(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
217 proto_tree *tree, guint32 length, const char *text _U_)
219 proto_tree_add_bytes(tree, hf_pn_user_bytes, tvb, offset, length, tvb_get_ptr(tvb,offset, length));
221 return offset + length;
225 dissect_pn_user_data(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
226 proto_tree *tree, guint32 length, const char *text)
228 proto_tree_add_string_format(tree, hf_pn_user_data, tvb, offset, length, "data",
229 "%s: %d bytes", text, length);
231 return offset + length;
234 /* packet is malformed, mark it as such */
236 dissect_pn_malformed(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
237 proto_tree *tree, guint32 length)
239 proto_tree_add_item(tree, hf_pn_malformed, tvb, 0, 10000, ENC_NA);
241 return offset + length;
245 /* dissect some padding data (with the given length) */
247 dissect_pn_padding(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
248 proto_tree *tree, int length)
250 proto_tree_add_string_format(tree, hf_pn_padding, tvb, offset, length, "data",
251 "Padding: %u byte", length);
253 return offset + length;
256 /* align offset to 4 */
258 dissect_pn_align4(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
264 padding = 4 - (offset % 4);
266 proto_tree_add_string_format(tree, hf_pn_padding, tvb, offset, padding, "data",
267 "Padding: %u byte", padding);
270 return offset + padding;
273 /* append the given info text to item and column */
275 pn_append_info(packet_info *pinfo, proto_item *dcp_item, const char *text)
277 col_append_str(pinfo->cinfo, COL_INFO, text);
279 proto_item_append_text(dcp_item, "%s", text);
287 static hf_register_info hf[] = {
289 { "Padding", "pn.padding", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
290 { &hf_pn_undecoded_data,
291 { "Undecoded Data", "pn.undecoded", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
293 { "User Data", "pn.user_data", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
295 { "Substitute Data", "pn.user_bytes", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
297 { "Malformed", "pn_rt.malformed", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }}
301 /*static gint *ett[] = {
304 proto_register_field_array (proto, hf, array_length (hf));
305 /*proto_register_subtree_array (ett, array_length (ett));*/