Attachment 'ethereal-0.10.14-ewsd.diff'
Download 1 diff -rN ethereal-0.10.14/epan/dissectors/Makefile.common ethereal-0.10.14-2/epan/dissectors/Makefile.common
2 279a280
3 > packet-ewsd.c \
4 diff -rN ethereal-0.10.14/epan/dissectors/Makefile.in ethereal-0.10.14-2/epan/dissectors/Makefile.in
5 190c190
6 < packet-ethertype.lo packet-extreme.lo packet-fc.lo \
7 ---
8 > packet-ethertype.lo packet-ewsd.lo packet-extreme.lo packet-fc.lo \
9 799a800
10 > packet-ewsd.c \
11 1777a1779
12 > @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/packet-ewsd.Plo@am__quote@
13 diff -rN ethereal-0.10.14/epan/dissectors/packet-ewsd.c ethereal-0.10.14-2/epan/dissectors/packet-ewsd.c
14 0a1,306
15 > /* packet-ewsd.c
16 > *
17 > * Radek Podgorny <radek@podgorny.cz>
18 > *
19 > * This program is free software; you can redistribute it and/or
20 > * modify it under the terms of the GNU General Public License
21 > * as published by the Free Software Foundation; either version 2
22 > * of the License, or (at your option) any later version.
23 > *
24 > * This program is distributed in the hope that it will be useful,
25 > * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 > * GNU General Public License for more details.
28 > *
29 > * You should have received a copy of the GNU General Public License
30 > * along with this program; if not, write to the Free Software
31 > * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 > */
33 >
34 >
35 > #ifdef HAVE_CONFIG_H
36 > #include "config.h"
37 > #endif
38 >
39 > #include <stdio.h>
40 > #include <string.h>
41 > #include <glib.h>
42 > #include <epan/packet.h>
43 >
44 >
45 > #define FAMILY_COMMAND 0xf1
46 > #define FAMILY_ANSWER 0xf2
47 >
48 >
49 > static int proto_ewsd = -1;
50 >
51 > static guint8 hf_ewsd_family = -1;
52 > static guint8 hf_ewsd_dir = -1;
53 > static guint8 hf_ewsd_pltype = -1;
54 > static guint16 hf_ewsd_connid = -1;
55 > static guint8 hf_ewsd_subseq = -1;
56 > //static gint hf_ewsd_shit = -1;
57 >
58 > static gint ett_ewsd = -1;
59 > static gint ett_ewsd_preamble = -1;
60 > static gint ett_ewsd_ewsd = -1;
61 >
62 >
63 > guint8 idmatch(guint8 *info, guint8 *mask) {
64 > int info_len = strlen(info);
65 > int mask_len = strlen(mask);
66 >
67 > if (info_len != mask_len) return 0;
68 >
69 > int i = 0;
70 > for (i = 0; i < mask_len; i++) {
71 > if (mask[i] == 'x') continue;
72 > if (mask[i] != info[i]) return 0;
73 > }
74 >
75 > return 1;
76 > }
77 >
78 > /* idinfo is used as we recurse deeper (we need to keep track of upper level ids) */
79 > guint16 dis_ewsd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 *levelinfo) {
80 > guint8 id;
81 > guint16 len;
82 >
83 > tvbuff_t *subtvb;
84 >
85 > guint16 pos;
86 >
87 > id = tvb_get_guint8(tvb, 0);
88 > len = tvb_get_ntohs(tvb, 1);
89 >
90 > // Broken when enabled?
91 > //tvb_set_reported_length(tvb, len+3);
92 >
93 > guint8 mylevel[100];
94 > strcpy(mylevel, levelinfo);
95 > int i = strlen(mylevel);
96 > mylevel[i] = id + '0';
97 > mylevel[i+1] = 0;
98 >
99 > if (idmatch(mylevel, "x")
100 > || (idmatch(mylevel, "x3") && hf_ewsd_dir == 0x0c && hf_ewsd_pltype == 1)
101 > || idmatch(mylevel, "x4")
102 > || (idmatch(mylevel, "x43") && hf_ewsd_dir == 4 && hf_ewsd_pltype == 0)
103 > || (idmatch(mylevel, "x432") && hf_ewsd_dir == 4 && hf_ewsd_pltype == 0)
104 > || (idmatch(mylevel, "x5") && hf_ewsd_dir == 2 && hf_ewsd_pltype == 0)
105 > || (idmatch(mylevel, "x5") && hf_ewsd_dir == 0x0e && hf_ewsd_pltype == 0)
106 > || idmatch(mylevel, "x6")
107 > || idmatch(mylevel, "x8")) {
108 > proto_item *ti = proto_tree_add_text(tree, tvb, 0, len+3, "ewsd %d (len: %d) (mylevel: %s)", id, len, mylevel);
109 > proto_tree *subtree = proto_item_add_subtree(ti, ett_ewsd_preamble);
110 >
111 > pos = 3;
112 > while (pos < len+3) {
113 > subtvb = tvb_new_subset(tvb, pos, -1, -1);
114 > guint16 len = dis_ewsd(subtvb, pinfo, subtree, mylevel);
115 > pos += len;
116 > }
117 > } else if (idmatch(mylevel, "x2")) {
118 > guint8 *unk1 = tvb_bytes_to_str_punct(tvb, 3, 2, '.');
119 > guint16 jobnr = tvb_get_ntohs(tvb, 5);
120 > guint8 *unk2 = tvb_bytes_to_str_punct(tvb, 7, len-4, '.');
121 > proto_tree_add_text(tree, tvb, 3, 2, "!!!unknown!!! (mylevel: %s) - %s", mylevel, unk1);
122 > proto_tree_add_text(tree, tvb, 5, 2, "Job number: %d", jobnr);
123 > proto_tree_add_text(tree, tvb, 7, len-4, "!!!unknown!!! (mylevel: %s) - %s", mylevel, unk2);
124 > /* */ if (check_col(pinfo->cinfo, COL_INFO)) col_append_fstr(pinfo->cinfo, COL_INFO, " (x2-unk2: %s)", unk2);
125 > } else if (idmatch(mylevel, "x31")) {
126 > guint8 *exname = tvb_get_ephemeral_string(tvb, 3, len);
127 > proto_tree_add_text(tree, tvb, 3, len, "Exchange name: %s", exname);
128 > } else if (idmatch(mylevel, "x32")) {
129 > guint8 *apsver = tvb_get_ephemeral_string(tvb, 3, len);
130 > proto_tree_add_text(tree, tvb, 3, len, "APS version: %s", apsver);
131 > } else if (idmatch(mylevel, "x33")) {
132 > guint8 *patchver = tvb_get_ephemeral_string(tvb, 3, len);
133 > proto_tree_add_text(tree, tvb, 3, len, "Patch version: %s", patchver);
134 > } else if (idmatch(mylevel, "x35")) {
135 > guint8 *username = tvb_get_ephemeral_string(tvb, 3, len);
136 > proto_tree_add_text(tree, tvb, 3, len, "Username: %s", username);
137 > } else if (idmatch(mylevel, "x41") && hf_ewsd_dir == 4 && hf_ewsd_pltype == 0) {
138 > guint8 *termname = tvb_get_ephemeral_string(tvb, 3, len);
139 > proto_tree_add_text(tree, tvb, 3, len, "Terminal name: %s", termname);
140 > } else if (idmatch(mylevel, "x41")) {
141 > guint8 *exname = tvb_get_ephemeral_string(tvb, 3, len);
142 > proto_tree_add_text(tree, tvb, 3, len, "Exchange name: %s", exname);
143 > } else if (idmatch(mylevel, "x42")) {
144 > guint8 *apsver = tvb_get_ephemeral_string(tvb, 3, len);
145 > proto_tree_add_text(tree, tvb, 3, len, "APS version: %s", apsver);
146 > } else if (idmatch(mylevel, "x43")) {
147 > guint8 *patchver = tvb_get_ephemeral_string(tvb, 3, len);
148 > proto_tree_add_text(tree, tvb, 3, len, "Patch version: %s", patchver);
149 > } else if (idmatch(mylevel, "x4322")) {
150 > guint8 *username = tvb_get_ephemeral_string(tvb, 3, len);
151 > proto_tree_add_text(tree, tvb, 3, len, "Username: %s", username);
152 > } else if (idmatch(mylevel, "x4323")) {
153 > guint8 *date = tvb_get_ephemeral_string(tvb, 3, 6);
154 > guint8 *time = tvb_get_ephemeral_string(tvb, 9, 6);
155 > guint8 *unk = tvb_bytes_to_str_punct(tvb, 15, len-12, '.');
156 > proto_tree_add_text(tree, tvb, 3, 6, "Date: %s", date);
157 > proto_tree_add_text(tree, tvb, 9, 6, "Time: %s", time);
158 > proto_tree_add_text(tree, tvb, 15, len-12, "!!!unknown!!! (mylevel: %s) - %s", mylevel, unk);
159 > } else if (idmatch(mylevel, "x44")) {
160 > guint8 *termname = tvb_get_ephemeral_string(tvb, 3, len);
161 > proto_tree_add_text(tree, tvb, 3, len, "Terminal name: %s", termname);
162 > } else if (idmatch(mylevel, "x45")) {
163 > guint8 *username = tvb_get_ephemeral_string(tvb, 3, len);
164 > proto_tree_add_text(tree, tvb, 3, len, "Username: %s", username);
165 > } else if (idmatch(mylevel, "x46")) {
166 > guint8 year = tvb_get_guint8(tvb, 3);
167 > guint8 month = tvb_get_guint8(tvb, 4);
168 > guint8 day = tvb_get_guint8(tvb, 5);
169 > proto_tree_add_text(tree, tvb, 3, len, "Date: %.2d-%.2d-%.2d", year, month, day);
170 > } else if (idmatch(mylevel, "x47")) {
171 > guint8 hour = tvb_get_guint8(tvb, 3);
172 > guint8 minute = tvb_get_guint8(tvb, 4);
173 > guint8 second = tvb_get_guint8(tvb, 5);
174 > proto_tree_add_text(tree, tvb, 3, len, "Time: %.2d:%.2d:%.2d", hour, minute, second);
175 > } else if (idmatch(mylevel, "x52") && hf_ewsd_family == FAMILY_COMMAND && hf_ewsd_dir == 2 && hf_ewsd_pltype == 0) {
176 > guint8 *err = tvb_get_ephemeral_string(tvb, 3, len);
177 > proto_tree_add_text(tree, tvb, 3, len, "Command error: %s", err);
178 > } else if (idmatch(mylevel, "x61") && hf_ewsd_family == FAMILY_COMMAND) {
179 > guint8 *command = tvb_get_ephemeral_string(tvb, 3, len);
180 > proto_tree_add_text(tree, tvb, 3, len, "Command: %s", command);
181 > } else if (idmatch(mylevel, "x7") && hf_ewsd_family == FAMILY_ANSWER) {
182 > // tvb_get_ephemeral_string seems to be unhappy with large lengths
183 > guint16 tmp = len; if (tmp > 1024) tmp = 1024;
184 > guint8 *ans = tvb_get_ephemeral_string(tvb, 3, tmp);
185 > proto_tree_add_text(tree, tvb, 3, len, "Answer: %s", ans);
186 > } else {
187 > guint8 *data = tvb_bytes_to_str_punct(tvb, 3, len, '.');
188 > proto_tree_add_text(tree, tvb, 3, len, "!!!unknown!!! (mylevel: %s) - %s", mylevel, data);
189 > }
190 >
191 > return len+3;
192 > }
193 >
194 > void dis_preamble(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
195 > proto_item *ti;
196 > proto_tree *subtree;
197 > tvbuff_t *subtvb;
198 >
199 > hf_ewsd_family = tvb_get_guint8(tvb, 0);
200 >
201 > if (hf_ewsd_family != FAMILY_COMMAND
202 > && hf_ewsd_family != FAMILY_ANSWER) {
203 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "Something weird!!!");
204 > return;
205 > }
206 >
207 > guint8 unk1 = tvb_get_guint8(tvb, 1);
208 > hf_ewsd_dir = tvb_get_guint8(tvb, 2);
209 > hf_ewsd_pltype = tvb_get_guint8(tvb, 3);
210 > hf_ewsd_connid = tvb_get_ntohs(tvb, 4);
211 > hf_ewsd_subseq = tvb_get_guint8(tvb, 6);
212 > guint8 unk2 = tvb_get_guint8(tvb, 7);
213 > guint16 unk3 = tvb_get_ntohs(tvb, 8);
214 > guint8 tail = tvb_get_guint8(tvb, 10);
215 >
216 > ti = proto_tree_add_text(tree, tvb, 0, 11,
217 > "preamble (family?: %#.2x) (dir?: %#.2x) (pltype?: %#.2x) (connid?: %#.4x) (subseq?: %d) (unk3?: %#.4x) (tail?: %#.2x)",
218 > hf_ewsd_family, hf_ewsd_dir, hf_ewsd_pltype, hf_ewsd_connid, hf_ewsd_subseq, unk3, tail);
219 >
220 > subtree = proto_item_add_subtree(ti, ett_ewsd_preamble);
221 > proto_tree_add_text(subtree, tvb, 0, 1, "family: %#.2x", hf_ewsd_family);
222 > proto_tree_add_text(subtree, tvb, 1, 1, "unk1: %#.2x", unk1);
223 > proto_tree_add_text(subtree, tvb, 2, 1, "dir: %#.2x", hf_ewsd_dir);
224 > proto_tree_add_text(subtree, tvb, 3, 1, "payload type: %#.2x", hf_ewsd_pltype);
225 > proto_tree_add_text(subtree, tvb, 4, 2, "cennection id: %#.4x", hf_ewsd_connid);
226 > proto_tree_add_text(subtree, tvb, 6, 1, "subseq: %d", hf_ewsd_subseq);
227 > proto_tree_add_text(subtree, tvb, 7, 1, "unk2: %#.2x", unk2);
228 > proto_tree_add_text(subtree, tvb, 8, 2, "unk3: %#.4x", unk3);
229 > proto_tree_add_text(subtree, tvb, 10, 1, "tail: %#.2x", tail);
230 >
231 >
232 > if (hf_ewsd_dir == 1 && hf_ewsd_pltype == 2) {
233 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "Something!!!");
234 > subtvb = tvb_new_subset(tvb, 11, -1, -1);
235 > dis_ewsd(subtvb, pinfo, tree, "");
236 > } else if (hf_ewsd_dir == 2 && hf_ewsd_subseq > 1) {
237 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "Continued answer");
238 > // tvb_get_ephemeral_string seems to be unhappy with large lengths
239 > guint16 tmp = tvb_length_remaining(tvb, 11);// if (tmp > 1024) tmp = 1024;
240 > guint8 *ans = tvb_get_ephemeral_string(tvb, 11, tmp);
241 > proto_tree_add_text(tree, tvb, 11, -1, "Continued answer: %s", ans);
242 > } else if (hf_ewsd_dir == 2 && hf_ewsd_pltype == 0) {
243 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "Command");
244 > subtvb = tvb_new_subset(tvb, 11, -1, -1);
245 > dis_ewsd(subtvb, pinfo, tree, "");
246 > } else if (hf_ewsd_dir == 2 && hf_ewsd_pltype == 1 && hf_ewsd_subseq <= 1) {
247 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "Long answer");
248 > subtvb = tvb_new_subset(tvb, 11, -1, -1);
249 > dis_ewsd(subtvb, pinfo, tree, "");
250 > } else if (hf_ewsd_dir == 2 && hf_ewsd_pltype == 2) {
251 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "Short answer");
252 > subtvb = tvb_new_subset(tvb, 11, -1, -1);
253 > dis_ewsd(subtvb, pinfo, tree, "");
254 > } else if (hf_ewsd_dir == 3 && hf_ewsd_pltype == 1) {
255 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "Command confirmation");
256 > subtvb = tvb_new_subset(tvb, 11, -1, -1);
257 > dis_ewsd(subtvb, pinfo, tree, "");
258 > } else if (hf_ewsd_dir == 4 && hf_ewsd_pltype == 0) {
259 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "Login attempt ?");
260 > subtvb = tvb_new_subset(tvb, 11, -1, -1);
261 > dis_ewsd(subtvb, pinfo, tree, "");
262 > } else if (hf_ewsd_dir == 0x0c && hf_ewsd_pltype == 1) {
263 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "Login accept ?");
264 > subtvb = tvb_new_subset(tvb, 11, -1, -1);
265 > dis_ewsd(subtvb, pinfo, tree, "");
266 > } else if (hf_ewsd_dir == 0x0e && hf_ewsd_pltype == 0) {
267 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "Something!!!");
268 > subtvb = tvb_new_subset(tvb, 11, -1, -1);
269 > dis_ewsd(subtvb, pinfo, tree, "");
270 > } else if (hf_ewsd_dir == 3 && hf_ewsd_pltype == 6) {
271 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "Answer confirmation, send more data");
272 > } else {
273 > if (check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, "!!!unknown!!!");
274 > }
275 > }
276 >
277 > static void dissect_ewsd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
278 > proto_item *ti;
279 > proto_tree *subtree;
280 > tvbuff_t *subtvb;
281 >
282 > if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_add_str(pinfo->cinfo, COL_PROTOCOL, "EWSD");
283 >
284 > if (tree) {
285 > ti = proto_tree_add_item(tree, proto_ewsd, tvb, 0, -1, FALSE);
286 > subtree = proto_item_add_subtree(ti, ett_ewsd);
287 >
288 > subtvb = tvb_new_subset(tvb, 0, -1, -1);
289 > dis_preamble(subtvb, pinfo, subtree);
290 > }
291 > }
292 >
293 > void proto_register_ewsd(void) {
294 > // static hf_register_info hf[] = {
295 > // {&hf_ewsd_direction, {"Direction", "ewsd.direction", FT_INT8, BASE_HEX, NULL, 0x0, "Direction", HFILL}},
296 > // {&hf_ewsd_data, {"Test data", "ewsd.data", FT_BYTES, BASE_HEX, NULL, 0x0, "Test data", HFILL}},
297 > // {&hf_ewsd_realdata, {"realdata", "ewsd.realdata", FT_BYTES, BASE_HEX, NULL, 0, "realdata", HFILL}},
298 > // };
299 >
300 > static gint *ett[] = {
301 > &ett_ewsd,
302 > &ett_ewsd_preamble,
303 > &ett_ewsd_ewsd
304 > };
305 >
306 > proto_ewsd = proto_register_protocol("Siemens EWSD", "EWSD", "ewsd");
307 > // proto_register_field_array(proto_ewsd, hf, array_length(hf));
308 > proto_register_subtree_array(ett, array_length(ett));
309 >
310 > register_dissector("ewsd", dissect_ewsd, proto_ewsd);
311 > register_dissector_table("ewsd.ewsd", "ewsd ewsd", FT_UINT8, BASE_DEC);
312 > }
313 >
314 > void proto_reg_handoff_ewsd(void) {
315 > dissector_handle_t ewsd_handle = NULL;
316 >
317 > ewsd_handle = create_dissector_handle(dissect_ewsd, proto_ewsd);
318 >
319 > dissector_add("ewsd.ewsd", 0, proto_ewsd);
320 > }
321 diff -rN ethereal-0.10.14/epan/dissectors/packet-x25.c ethereal-0.10.14-2/epan/dissectors/packet-x25.c
322 2367a2368,2373
323 > // added by Radek Podgorny
324 > dissector_handle_t *t = find_dissector("ewsd");
325 > call_dissector(t, next_tvb, pinfo, tree);
326 > pinfo->private_data = saved_private_data;
327 > return;
328 >
329 diff -rN ethereal-0.10.14/epan/dissectors/register.c ethereal-0.10.14-2/epan/dissectors/register.c
330 197a198
331 > {extern void proto_register_ewsd (void); proto_register_ewsd ();}
332 815a817
333 > {extern void proto_reg_handoff_ewsd (void); proto_reg_handoff_ewsd ();}
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.