HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-egd.c
blob21c7f90a1500168ed005e227193e8a59e6f3219c
1 /* packet-egd.c
2 * Routines for Ethernet Global Data dissection
3 * EGD Home: www.gefanuc.com
5 * Copyright 2008
6 * 29 July 2008 -- ryan wamsley
8 * $Id$
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "config.h"
31 #include <string.h>
32 #include <epan/packet.h>
34 #define EGD_PORT 18246 /* 0x4746 */
36 #define EGD_ST_NONEW 0
37 #define EGD_ST_NOERROR 1
38 #define EGD_ST_CONSUMED 2
39 #define EGD_ST_SNTPERR 3
40 #define EGD_ST_SPECERR 4
41 #define EGD_ST_REFRESHERR 6
42 #define EGD_ST_REFEXDERR 7
43 #define EGD_ST_IPERR 10
44 #define EGD_ST_RESOURSEERR 12
45 #define EGD_ST_NAMERES 16
46 #define EGD_ST_ETHERR 18
47 #define EGD_ST_NOSUPPORT 22
48 #define EGD_ST_NORESP 26
49 #define EGD_ST_CREATEERR 28
50 #define EGD_ST_DELETED 30
53 void proto_register_egd(void);
54 void proto_reg_handoff_egd(void);
56 /* Translate status to string */
57 static const value_string egd_stat_vals[] = {
58 { EGD_ST_NONEW, "No new status event has occurred" },
59 { EGD_ST_NOERROR, "No error currently exists" },
60 { EGD_ST_CONSUMED, "No error, data consumed" },
61 { EGD_ST_SNTPERR, "SNTP error" },
62 { EGD_ST_SPECERR, "Specification error" },
63 { EGD_ST_REFRESHERR, "Data refresh error" },
64 { EGD_ST_REFEXDERR, "Data refresh period exceeded" },
65 { EGD_ST_IPERR, "IP Layer not currently initialized" },
66 { EGD_ST_RESOURSEERR, "Lack of resource error" },
67 { EGD_ST_NAMERES, "Name Resolution in progress" },
68 { EGD_ST_ETHERR, "Loss of Ethernet Interface error" },
69 { EGD_ST_NOSUPPORT, "Ethernet Interface does not support EGD" },
70 { EGD_ST_NORESP, "No Response from Ethernet Interface" },
71 { EGD_ST_CREATEERR, "Failed to create an exchange." },
72 { EGD_ST_DELETED, "Configured exchange deleted." },
73 { 0, NULL }
76 static int proto_egd = -1;
78 static dissector_handle_t data_handle;
80 static int hf_egd_ver = -1;
81 static int hf_egd_type = -1;
82 static int hf_egd_rid = -1;
83 static int hf_egd_pid = -1;
84 static int hf_egd_exid = -1;
85 static int hf_egd_time = -1;
86 static int hf_egd_notime = -1;
87 static int hf_egd_stat = -1;
88 static int hf_egd_csig = -1;
89 static int hf_egd_resv = -1;
91 static gint ett_egd = -1;
92 static gint ett_status_item = -1;
94 static void dissect_egd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
96 /* replace UDP with EGD in display */
97 col_set_str(pinfo->cinfo, COL_PROTOCOL, "EGD");
99 /* Clear out stuff in the info column */
100 col_clear(pinfo->cinfo, COL_INFO);
101 col_add_fstr(pinfo->cinfo, COL_INFO, "Data Msg: ExchangeID=0x%08X, RequestID=%05u",
102 tvb_get_letohl(tvb, 8), tvb_get_letohs(tvb, 2));
104 if (tree)
106 proto_item *ti = NULL;
107 proto_item *notime = NULL;
108 proto_tree *egd_tree = NULL;
109 tvbuff_t *next_tvb = NULL;
110 gint offset, data_length;
111 guint32 sectime;
112 nstime_t egd_time;
114 memset(&egd_time, 0, sizeof(nstime_t));
115 offset = 0;
117 ti = proto_tree_add_item(tree, proto_egd, tvb, 0, -1, ENC_NA);
118 egd_tree = proto_item_add_subtree(ti, ett_egd);
119 proto_tree_add_item(egd_tree, hf_egd_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
120 offset++;
121 proto_tree_add_item(egd_tree, hf_egd_ver, tvb, offset, 1, ENC_LITTLE_ENDIAN);
122 offset++;
123 proto_tree_add_item(egd_tree, hf_egd_rid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
124 offset += 2;
125 proto_tree_add_item(egd_tree, hf_egd_pid, tvb, offset, 4, ENC_BIG_ENDIAN);
126 offset += 4;
127 proto_tree_add_item(egd_tree, hf_egd_exid, tvb, offset, 4, ENC_LITTLE_ENDIAN);
128 offset += 4;
130 /* time */
131 sectime = tvb_get_letohl(tvb, offset);
132 if (0 == sectime)
134 notime = proto_tree_add_item(egd_tree, hf_egd_notime, tvb, offset, 8, ENC_LITTLE_ENDIAN);
135 proto_item_append_text(notime, "--No TimeStamp");
137 else
139 egd_time.secs = tvb_get_letohl(tvb, offset);
140 egd_time.nsecs = tvb_get_letohl(tvb, offset+4);
141 proto_tree_add_time(egd_tree, hf_egd_time, tvb, offset, 8, &egd_time);
143 offset += 8;
145 proto_tree_add_item(egd_tree, hf_egd_stat, tvb, offset, 4, ENC_LITTLE_ENDIAN);
146 offset += 4;
147 proto_tree_add_item(egd_tree, hf_egd_csig, tvb, offset, 4, ENC_LITTLE_ENDIAN);
148 offset += 4;
149 proto_tree_add_item(egd_tree, hf_egd_resv, tvb, offset, 4, ENC_LITTLE_ENDIAN);
150 offset += 4;
152 data_length = tvb_length_remaining(tvb, offset);
153 if (data_length > 0)
155 next_tvb = tvb_new_subset_remaining(tvb, offset);
156 call_dissector(data_handle, next_tvb, pinfo, egd_tree);
161 void proto_register_egd(void)
163 static hf_register_info hf[] =
165 { &hf_egd_ver,
166 { "Version", "egd.ver",
167 FT_UINT8, BASE_DEC,
168 NULL, 0x0,
169 NULL, HFILL }
171 { &hf_egd_type,
172 { "Type", "egd.type",
173 FT_UINT8, BASE_DEC,
174 NULL, 0x0,
175 NULL, HFILL }
177 { &hf_egd_rid,
178 { "RequestID", "egd.rid",
179 FT_UINT16, BASE_DEC,
180 NULL, 0x0,
181 NULL, HFILL }
183 { &hf_egd_pid,
184 { "ProducerID", "egd.pid",
185 FT_IPv4, BASE_NONE,
186 NULL, 0x0,
187 NULL, HFILL }
189 { &hf_egd_exid,
190 { "ExchangeID", "egd.exid",
191 FT_UINT32, BASE_HEX,
192 NULL, 0x0,
193 NULL, HFILL }
195 { &hf_egd_time,
196 { "Timestamp", "egd.time",
197 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
198 NULL, 0x0,
199 NULL, HFILL }
201 { &hf_egd_notime,
202 { "Timestamp", "egd.notime",
203 FT_UINT64, BASE_HEX,
204 NULL, 0x0,
205 NULL, HFILL }
207 { &hf_egd_stat,
208 { "Status", "egd.stat",
209 FT_UINT32, BASE_DEC,
210 VALS(egd_stat_vals), 0x0,
211 NULL, HFILL }
213 { &hf_egd_csig,
214 { "ConfigSignature", "egd.csig",
215 FT_UINT32, BASE_DEC,
216 NULL, 0x0,
217 NULL, HFILL }
219 { &hf_egd_resv,
220 { "Reserved", "egd.rsrv",
221 FT_UINT32, BASE_DEC,
222 NULL, 0x0,
223 NULL, HFILL }
227 static gint *ett[] =
229 &ett_egd,
230 &ett_status_item
233 proto_egd = proto_register_protocol (
234 "Ethernet Global Data", /* name */
235 "EGD", /* short name */
236 "egd" /* abbrev */
238 proto_register_field_array(proto_egd, hf, array_length(hf));
239 proto_register_subtree_array(ett, array_length(ett));
242 void proto_reg_handoff_egd(void)
244 dissector_handle_t egd_handle;
246 egd_handle = create_dissector_handle(dissect_egd, proto_egd);
247 dissector_add_uint("udp.port", EGD_PORT, egd_handle);
249 /* find data dissector */
250 data_handle = find_dissector("data");