checkAPIs.pl: support for new-style dissectors in check_hf_entries
[metze/wireshark/wip.git] / epan / dissectors / packet-egd.c
1 /* packet-egd.c
2  * Routines for Ethernet Global Data dissection
3  * EGD Home: www.gefanuc.com
4  *
5  * Copyright 2008
6  * 29 July 2008 -- ryan wamsley
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * SPDX-License-Identifier: GPL-2.0-or-later
13  */
14
15 #include "config.h"
16
17 #include <epan/packet.h>
18
19 #define EGD_PORT 18246 /* 0x4746 - Not IANA registered */
20
21 #define EGD_ST_NONEW        0
22 #define EGD_ST_NOERROR      1
23 #define EGD_ST_CONSUMED     2
24 #define EGD_ST_SNTPERR      3
25 #define EGD_ST_SPECERR      4
26 #define EGD_ST_REFRESHERR   6
27 #define EGD_ST_REFEXDERR    7
28 #define EGD_ST_IPERR        10
29 #define EGD_ST_RESOURSEERR  12
30 #define EGD_ST_NAMERES      16
31 #define EGD_ST_ETHERR       18
32 #define EGD_ST_NOSUPPORT    22
33 #define EGD_ST_NORESP       26
34 #define EGD_ST_CREATEERR    28
35 #define EGD_ST_DELETED      30
36
37
38 void proto_register_egd(void);
39 void proto_reg_handoff_egd(void);
40
41 /* Translate status to string */
42 static const value_string egd_stat_vals[] = {
43   { EGD_ST_NONEW,                  "No new status event has occurred" },
44   { EGD_ST_NOERROR,                "No error currently exists" },
45   { EGD_ST_CONSUMED,               "No error, data consumed" },
46   { EGD_ST_SNTPERR,                "SNTP error"  },
47   { EGD_ST_SPECERR,                "Specification error" },
48   { EGD_ST_REFRESHERR,             "Data refresh error" },
49   { EGD_ST_REFEXDERR,              "Data refresh period exceeded" },
50   { EGD_ST_IPERR,                  "IP Layer not currently initialized" },
51   { EGD_ST_RESOURSEERR,            "Lack of resource error" },
52   { EGD_ST_NAMERES,                "Name Resolution in progress" },
53   { EGD_ST_ETHERR,                 "Loss of Ethernet Interface error" },
54   { EGD_ST_NOSUPPORT,              "Ethernet Interface does not support EGD" },
55   { EGD_ST_NORESP,                 "No Response from Ethernet Interface" },
56   { EGD_ST_CREATEERR,              "Failed to create an exchange." },
57   { EGD_ST_DELETED,                "Configured exchange deleted." },
58   { 0,                             NULL }
59 };
60
61 static int proto_egd = -1;
62
63 static int hf_egd_ver = -1;
64 static int hf_egd_type = -1;
65 static int hf_egd_rid = -1;
66 static int hf_egd_pid = -1;
67 static int hf_egd_exid = -1;
68 static int hf_egd_time = -1;
69 static int hf_egd_notime = -1;
70 static int hf_egd_stat = -1;
71 static int hf_egd_csig = -1;
72 static int hf_egd_resv = -1;
73
74 static gint ett_egd = -1;
75 static gint ett_status_item = -1;
76
77 static int dissect_egd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
78 {
79   /* replace UDP with EGD in display */
80   col_set_str(pinfo->cinfo, COL_PROTOCOL, "EGD");
81
82   /* Clear out stuff in the info column */
83   col_clear(pinfo->cinfo, COL_INFO);
84   col_add_fstr(pinfo->cinfo, COL_INFO, "Data Msg: ExchangeID=0x%08X, RequestID=%05u",
85                  tvb_get_letohl(tvb, 8), tvb_get_letohs(tvb, 2));
86
87   if (tree)
88   {
89     proto_item *ti = NULL;
90     proto_item *notime = NULL;
91     proto_tree *egd_tree = NULL;
92     tvbuff_t *next_tvb = NULL;
93     gint offset, data_length;
94     guint32 sectime;
95
96     offset = 0;
97
98     ti = proto_tree_add_item(tree, proto_egd, tvb, 0, -1, ENC_NA);
99     egd_tree = proto_item_add_subtree(ti, ett_egd);
100     proto_tree_add_item(egd_tree, hf_egd_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
101     offset++;
102     proto_tree_add_item(egd_tree, hf_egd_ver, tvb, offset, 1, ENC_LITTLE_ENDIAN);
103     offset++;
104     proto_tree_add_item(egd_tree, hf_egd_rid, tvb, offset, 2, ENC_LITTLE_ENDIAN);
105     offset += 2;
106     proto_tree_add_item(egd_tree, hf_egd_pid, tvb, offset, 4, ENC_BIG_ENDIAN);
107     offset += 4;
108     proto_tree_add_item(egd_tree, hf_egd_exid, tvb, offset, 4, ENC_LITTLE_ENDIAN);
109     offset += 4;
110
111     /* time */
112     sectime = tvb_get_letohl(tvb, offset);
113     if (0 == sectime)
114     {
115       notime = proto_tree_add_item(egd_tree, hf_egd_notime, tvb, offset, 8, ENC_LITTLE_ENDIAN);
116       proto_item_append_text(notime, "--No TimeStamp");
117     }
118     else
119     {
120       proto_tree_add_item(egd_tree, hf_egd_time, tvb, offset, 8, ENC_LITTLE_ENDIAN);
121     }
122     offset += 8;
123
124     proto_tree_add_item(egd_tree, hf_egd_stat, tvb, offset, 4, ENC_LITTLE_ENDIAN);
125     offset += 4;
126     proto_tree_add_item(egd_tree, hf_egd_csig, tvb, offset, 4, ENC_LITTLE_ENDIAN);
127     offset += 4;
128     proto_tree_add_item(egd_tree, hf_egd_resv, tvb, offset, 4, ENC_LITTLE_ENDIAN);
129     offset += 4;
130
131     data_length = tvb_reported_length_remaining(tvb, offset);
132     if (data_length > 0)
133     {
134       next_tvb = tvb_new_subset_remaining(tvb, offset);
135       call_data_dissector(next_tvb, pinfo, egd_tree);
136     }
137   }
138   return tvb_captured_length(tvb);
139 }
140
141 void proto_register_egd(void)
142 {
143   static hf_register_info hf[] =
144     {
145       { &hf_egd_ver,
146         { "Version", "egd.ver",
147           FT_UINT8, BASE_DEC,
148           NULL, 0x0,
149           NULL, HFILL }
150       },
151       { &hf_egd_type,
152         { "Type", "egd.type",
153           FT_UINT8, BASE_DEC,
154           NULL, 0x0,
155           NULL, HFILL }
156       },
157       { &hf_egd_rid,
158         { "RequestID", "egd.rid",
159           FT_UINT16, BASE_DEC,
160           NULL, 0x0,
161           NULL, HFILL }
162       },
163       { &hf_egd_pid,
164         { "ProducerID", "egd.pid",
165           FT_IPv4, BASE_NONE,
166           NULL, 0x0,
167           NULL, HFILL }
168       },
169       { &hf_egd_exid,
170         { "ExchangeID", "egd.exid",
171           FT_UINT32, BASE_HEX,
172           NULL, 0x0,
173           NULL, HFILL }
174       },
175       { &hf_egd_time,
176         { "Timestamp", "egd.time",
177           FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
178           NULL, 0x0,
179           NULL, HFILL }
180       },
181       { &hf_egd_notime,
182         { "Timestamp", "egd.notime",
183           FT_UINT64, BASE_HEX,
184           NULL, 0x0,
185           NULL, HFILL }
186       },
187       { &hf_egd_stat,
188         { "Status", "egd.stat",
189           FT_UINT32, BASE_DEC,
190           VALS(egd_stat_vals), 0x0,
191           NULL, HFILL }
192       },
193       { &hf_egd_csig,
194         { "ConfigSignature", "egd.csig",
195           FT_UINT32, BASE_DEC,
196           NULL, 0x0,
197           NULL, HFILL }
198       },
199       { &hf_egd_resv,
200         { "Reserved", "egd.rsrv",
201           FT_UINT32, BASE_DEC,
202           NULL, 0x0,
203           NULL, HFILL }
204       }
205     };
206
207   static gint *ett[] =
208     {
209       &ett_egd,
210       &ett_status_item
211     };
212
213   proto_egd = proto_register_protocol ("Ethernet Global Data", "EGD", "egd");
214   proto_register_field_array(proto_egd, hf, array_length(hf));
215   proto_register_subtree_array(ett, array_length(ett));
216 }
217
218 void proto_reg_handoff_egd(void)
219 {
220   dissector_handle_t egd_handle;
221
222   egd_handle = create_dissector_handle(dissect_egd, proto_egd);
223   dissector_add_uint_with_preference("udp.port", EGD_PORT, egd_handle);
224 }
225
226 /*
227  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
228  *
229  * Local Variables:
230  * c-basic-offset: 2
231  * tab-width: 8
232  * indent-tabs-mode: nil
233  * End:
234  *
235  * ex: set shiftwidth=2 tabstop=8 expandtab:
236  * :indentSize=2:tabSize=8:noTabs=true:
237  */