Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / plugins / epan / ethercat / packet-ams.c
blob4c0aa8f7ab42bb5fd626d81d110df8b6d675c747
1 /* packet-ams.c
2 * Routines for ethercat packet disassembly
4 * Copyright (c) 2007 by Beckhoff Automation GmbH
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 /* Include files */
15 #include "config.h"
17 #include <epan/packet.h>
18 #include <epan/tfs.h>
19 #include <wsutil/array.h>
21 #include "packet-ams.h"
23 void proto_register_ams(void);
24 void proto_reg_handoff_ams(void);
26 #define AMS_TCP_PORT 48898 /* Not IANA registered */
28 /* Define the ams proto */
29 int proto_ams;
31 static dissector_handle_t amstcp_handle;
33 /* Define the tree for ams */
34 static int ett_ams;
35 static int ett_ams_stateflags;
36 static int ett_ams_adsreadrequest;
37 static int ett_ams_adsreadresponse;
38 static int ett_ams_adswriterequest;
39 static int ett_ams_adswriteresponse;
40 static int ett_ams_adsreadwriterequest;
41 static int ett_ams_adsreadwriteresponse;
42 static int ett_ams_adsreadstaterequest;
43 static int ett_ams_adsreadstateresponse;
44 static int ett_ams_adswritectrlrequest;
45 static int ett_ams_adswritectrlresponse;
46 static int ett_ams_adsreaddinforequest;
47 static int ett_ams_adsreaddinforesponse;
48 static int ett_ams_adsadddnrequest;
49 static int ett_ams_adsadddnresponse;
50 static int ett_ams_adsdeldnrequest;
51 static int ett_ams_adsdeldnresponse;
52 static int ett_ams_adsdnrequest;
54 static int hf_ams_sendernetid;
55 static int hf_ams_senderport;
56 static int hf_ams_targetnetid;
57 static int hf_ams_targetport;
58 static int hf_ams_cmdid;
59 static int hf_ams_stateflags;
60 static int hf_ams_stateresponse;
61 static int hf_ams_statenoreturn;
62 static int hf_ams_stateadscmd;
63 static int hf_ams_statesyscmd;
64 static int hf_ams_statehighprio;
65 static int hf_ams_statetimestampadded;
66 static int hf_ams_stateudp;
67 static int hf_ams_stateinitcmd;
68 static int hf_ams_statebroadcast;
69 static int hf_ams_cbdata;
70 static int hf_ams_errorcode;
71 static int hf_ams_invokeid;
72 static int hf_ams_data;
74 /*ads Commands */
75 static int hf_ams_adsindexgroup;
76 static int hf_ams_adsindexoffset;
77 static int hf_ams_adscblength;
78 static int hf_ams_adsreadrequest;
79 static int hf_ams_adsreadresponse;
80 static int hf_ams_adsinvokeid;
81 static int hf_ams_adsresult;
82 static int hf_ams_adsdata;
83 static int hf_ams_adswriterequest;
84 static int hf_ams_adswriteresponse;
85 static int hf_ams_adsreadwriterequest;
86 static int hf_ams_adsreadwriteresponse;
87 static int hf_ams_adscbreadlength;
88 static int hf_ams_adscbwritelength;
89 static int hf_ams_adsstate;
90 static int hf_ams_adsdevicestate;
91 static int hf_ams_adsnotificationhandle;
92 static int hf_ams_adsreadstaterequest;
93 static int hf_ams_adsreadstateresponse;
94 static int hf_ams_adswritectrlrequest;
95 static int hf_ams_adswritectrlresponse;
96 static int hf_ams_adsreaddinforequest;
97 static int hf_ams_adsreaddinforesponse;
98 static int hf_ams_adsadddnrequest;
99 static int hf_ams_adsadddnresponse;
100 static int hf_ams_adsdeldnrequest;
101 static int hf_ams_adsdeldnresponse;
102 static int hf_ams_adsdnrequest;
103 /* static int hf_ams_adsdnresponse; */
104 /* static int hf_ams_adsnoteattrib; */
105 /* static int hf_ams_adsnoteblocks; */
106 /* static int hf_ams_adsversion; */
107 static int hf_ams_adsdevicename;
108 static int hf_ams_adsversionversion;
109 static int hf_ams_adsversionrevision;
110 static int hf_ams_adsversionbuild;
111 static int hf_ams_adsnoteblocksstamps;
112 /* static int hf_ams_adsnoteblocksstamp; */
113 /* static int hf_ams_adstimestamp; */
114 /* static int hf_ams_adssamplecnt; */
115 /* static int hf_ams_adsnoteblockssample; */
116 static int hf_ams_adstransmode;
117 static int hf_ams_adsmaxdelay;
118 static int hf_ams_adscycletime;
119 /* static int hf_ams_adscmpmax; */
120 /* static int hf_ams_adscmpmin; */
122 static dissector_handle_t ams_handle;
124 static const value_string TransMode[] =
126 { 0, "NO TRANS"},
127 { 1, "CLIENT CYCLE"},
128 { 2, "CLIENT ON CHANGE"},
129 { 3, "SERVER CYCLE"},
130 { 4, "SERVER ON CHANGE"},
131 { 10, "CLIENT FIRST REQUEST"},
132 { 0, NULL }
135 static const value_string ErrorCode[] =
137 { ERR_NOERROR, "NO ERROR"},
138 { ERR_INTERNAL, "INTERNAL"},
139 { ERR_NORTIME, "NO RTIME"},
140 { ERR_ALLOCLOCKEDMEM, "ALLOC LOCKED MEM"},
141 { ERR_INSERTMAILBOX, "INSERT MAILBOX"},
142 { ERR_WRONGRECEIVEHMSG, "WRONGRECEIVEHMSG"},
143 { ERR_TARGETPORTNOTFOUND, "TARGET PORT NOT FOUND"},
144 { ERR_TARGETMACHINENOTFOUND, "TARGET MACHINE NOT FOUND"},
145 { ERR_UNKNOWNCMDID, "UNKNOWN CMDID"},
146 { ERR_BADTASKID, "BAD TASKID"},
147 { ERR_NOIO, "NOIO"},
148 { ERR_UNKNOWNAMSCMD, "UNKNOWN AMSCMD"},
149 { ERR_WIN32ERROR, "WIN32 ERROR"},
150 { ERR_PORTNOTCONNECTED, "PORT NOT CONNECTED"},
151 { ERR_INVALIDAMSLENGTH, "INVALID AMS LENGTH"},
152 { ERR_INVALIDAMSNETID, "INVALID AMS NETID"},
153 { ERR_LOWINSTLEVEL, "LOW INST LEVEL"},
154 { ERR_NODEBUGINTAVAILABLE, "NO DEBUG INT AVAILABLE"},
155 { ERR_PORTDISABLED, "PORT DISABLED"},
156 { ERR_PORTALREADYCONNECTED, "PORT ALREADY CONNECTED"},
157 { ERR_AMSSYNC_W32ERROR, "AMSSYNC_W32ERROR"},
158 { ERR_AMSSYNC_TIMEOUT, "AMSSYNC_TIMEOUT"},
159 { ERR_AMSSYNC_AMSERROR, "AMSSYNC_AMSERROR"},
160 { ERR_AMSSYNC_NOINDEXINMAP, "AMSSYNC_NOINDEXINMAP"},
161 { ERR_INVALIDAMSPORT, "INVALID AMSPORT"},
162 { ERR_NOMEMORY, "NO MEMORY"},
163 { ERR_TCPSEND, "TCP SEND"},
164 { ERR_HOSTUNREACHABLE, "HOST UNREACHABLE"},
165 { ROUTERERR_NOLOCKEDMEMORY, "ROUTERERR_NOLOCKEDMEMORY"},
166 { ROUTERERR_RESIZEMEMORY, "ROUTERERR_RESIZEMEMORY"},
167 { ROUTERERR_MAILBOXFULL, "ROUTERERR_MAILBOXFULL"},
168 { ROUTERERR_DEBUGBOXFULL, "ROUTERERR_DEBUGBOXFULL"},
169 { ROUTERERR_UNKNOWNPORTTYPE, "ROUTERERR_UNKNOWNPORTTYPE"},
170 { ROUTERERR_NOTINITIALIZED, "ROUTERERR_NOTINITIALIZED"},
171 { ROUTERERR_PORTALREADYINUSE, "ROUTERERR_PORTALREADYINUSE"},
172 { ROUTERERR_NOTREGISTERED, "ROUTERERR_NOTREGISTERED "},
173 { ROUTERERR_NOMOREQUEUES, "ROUTERERR_NOMOREQUEUES"},
174 { ROUTERERR_INVALIDPORT, "ROUTERERR_INVALIDPORT"},
175 { ROUTERERR_NOTACTIVATED, "ROUTERERR_NOTACTIVATED"},
176 { IOERR_INTERNAL, "IOERR_INTERNAL"},
177 { IOERR_BADCARDNO, "IOERR_BADCARDNO"},
178 { IOERR_INVALIDCARDADDR, "IOERR_INVALIDCARDADDR"},
179 { IOERR_CDLLISTFULL, "IOERR_CDLLISTFULL"},
180 { IOERR_BADCDLPARAM, "IOERR_BADCDLPARAM"},
181 { IOERR_OPENIOFAILED, "IOERR_OPENIOFAILED"},
182 { IOERR_RESETIOFAILED, "IOERR_RESETIOFAILED"},
183 { IOERR_UNKNOWNDEVICE, "IOERR_UNKNOWNDEVICE"},
184 { IOERR_UNKNOWNDEVICEID, "IOERR_UNKNOWNDEVICEID"},
185 { IOERR_UNKNOWNIMAGEID, "IOERR_UNKNOWNIMAGEID"},
186 { IOERR_GETIOSTATE, "IOERR_GETIOSTATE"},
187 { IOERR_BADIMAGEID, "IOERR_BADIMAGEID"},
188 { IOERR_NOMORECLIENTSPACE, "IOERR_NOMORECLIENTSPACE"},
189 { IOERR_CLIENTINFONOTFOUND, "IOERR_CLIENTINFONOTFOUND"},
190 { IOERR_CDLNOTINUSE, "IOERR_CDLNOTINUSE"},
191 { IOERR_TIMEOUTWITHDEVICE, "IOERR_TIMEOUTWITHDEVICE"},
192 { IOERR_C1220FUNC_1, "IOERR_C1220FUNC_1"},
193 { IOERR_C1220FUNC_9, "IOERR_C1220FUNC_9"},
194 { IOERR_C1220FUNC_C, "IOERR_C1220FUNC_C"},
195 { IOERR_C1220FUNC_10, "IOERR_C1220FUNC_10"},
196 { IOERR_C1220FUNC_1_MAXSEND, "IOERR_C1220FUNC_1_MAXSEND"},
197 { IOERR_C1220FUNC_1_ADDRSET, "IOERR_C1220FUNC_1_ADDRSET"},
198 { IOERR_C1220FUNC_1_BREAK, "IOERR_C1220FUNC_1_BREAK"},
199 { IOERR_C1220FUNC_1_BREAK0, "IOERR_C1220FUNC_1_BREAK0"},
200 { IOERR_C1220FUNC_1_BREAK1, "IOERR_C1220FUNC_1_BREAK1"},
201 { IOERR_C1220FUNC_1_BREAK2, "IOERR_C1220FUNC_1_BREAK2"},
202 { IOERR_C1220FUNC_1_BREAK3, "IOERR_C1220FUNC_1_BREAK3"},
203 { IOERR_C1220FUNC_1_BREAK4, "IOERR_C1220FUNC_1_BREAK4"},
204 { IOERR_C1220FUNC_1_BREAK5, "IOERR_C1220FUNC_1_BREAK5"},
205 { IOERR_C1220FUNC_1_BREAK6, "IOERR_C1220FUNC_1_BREAK6"},
206 { IOERR_C1220FUNC_1_BREAK7, "IOERR_C1220FUNC_1_BREAK7"},
207 { IOERR_C1220FUNC_1_BREAK8, "IOERR_C1220FUNC_1_BREAK8"},
208 { IOERR_C1220FUNC_1_BREAK9, "IOERR_C1220FUNC_1_BREAK9"},
209 { IOERR_C1220FUNC_1_BREAK10, "IOERR_C1220FUNC_1_BREAK10"},
210 { IOERR_C1220FUNC_1_BREAK11, "IOERR_C1220FUNC_1_BREAK11"},
211 { IOERR_C1220FUNC_1_BREAK12, "IOERR_C1220FUNC_1_BREAK12"},
212 { IOERR_C1220FUNC_1_BREAK13, "IOERR_C1220FUNC_1_BREAK13"},
213 { IOERR_C1220FUNC_1_BREAK14, "IOERR_C1220FUNC_1_BREAK14"},
214 { IOERR_C1220FUNC_1_BREAK15, "IOERR_C1220FUNC_1_BREAK15"},
215 { IOERR_C1220FUNC_1_BREAK16, "IOERR_C1220FUNC_1_BREAK16"},
216 { IOERR_SPC3DEVINITDP, "IOERR_SPC3DEVINITDP"},
217 { IOERR_SPC3UPDATEOUTPUT, "IOERR_SPC3UPDATEOUTPUT"},
218 { IOERR_CIF30READDIAG, "IOERR_CIF30READDIAG"},
219 { IOERR_CIF30COMMNOTSTARTED, "IOERR_CIF30COMMNOTSTARTED"},
220 { IOERR_CIF30SLAVEPARASIZE, "IOERR_CIF30SLAVEPARASIZE"},
221 { IOERR_CIF30NOPARAS, "IOERR_CIF30NOPARAS"},
222 { IOERR_CIF30SLAVEERROR, "IOERR_CIF30SLAVEERROR"},
223 { IOERR_CIF30WATCHDOGEXPIRED, "IOERR_CIF30WATCHDOGEXPIRED"},
224 { IOERR_UNKNOWNDEVICECMD, "IOERR_UNKNOWNDEVICECMD"},
225 { IOERR_CIF40MESSAGEHANDLING, "IOERR_CIF40MESSAGEHANDLING"},
226 { IOERR_CIF40PARAERROR, "IOERR_CIF40PARAERROR"},
227 { IOERR_CIF40WATCHDOGEXPIRED, "IOERR_CIF40WATCHDOGEXPIRED"},
228 { IOERR_CIF40FLAGERROR, "IOERR_CIF40FLAGERROR"},
229 { IOERR_CIF40COMMNOTSTARTED, "IOERR_CIF40COMMNOTSTARTED"},
230 { IOERR_CIF40READDIAG, "IOERR_CIF40READDIAG"},
231 { IOERR_CIF40SLAVEERROR, "IOERR_CIF40SLAVEERROR"},
232 { IOERR_CIF40GLOBALERROR, "IOERR_CIF40GLOBALERROR"},
233 { IOERR_CIF40CONFIGLIST, "IOERR_CIF40CONFIGLIST"},
234 { IOERR_CP5412A2SLAVEPARASIZE, "IOERR_CP5412A2SLAVEPARASIZE"},
235 { IOERR_CP5412A2NOPARAS, "IOERR_CP5412A2NOPARAS"},
236 { IOERR_CP5412A2SLAVEERROR, "IOERR_CP5412A2SLAVEERROR"},
237 { IOERR_CP5412A2FATAL, "IOERR_CP5412A2FATAL"},
238 { IOERR_CP5412A2MAILBOXUSED, "IOERR_CP5412A2MAILBOXUSED"},
239 { IOERR_BEGINCONFIGWHILETICKER, "IOERR_BEGINCONFIGWHILETICKER"},
240 { IOERR_UNEXPECTEDBOXCOUNT, "IOERR_UNEXPECTEDBOXCOUNT"},
241 { IOERR_C1200CHECKADDR, "IOERR_C1200CHECKADDR"},
242 { IOERR_C1200INTENSITYTEST, "IOERR_C1200INTENSITYTEST"},
243 { IOERR_NOIMAGE, "IOERR_NOIMAGE"},
244 { IOERR_INVALIDIMAGEOFFSSIZE, "IOERR_INVALIDIMAGEOFFSSIZE"},
245 { IOERR_FORCESCOUNTEXCEEDEDMAXIMUM, "IOERR_FORCESCOUNTEXCEEDEDMAXIMUM"},
246 { IOERR_SERCOSLIFECOUNTERERR, "IOERR_SERCOSLIFECOUNTERERR"},
247 { IOERR_C1220NOTFOUND, "IOERR_C1220NOTFOUND"},
248 { IOERR_AMSDEVICENOAMSINTF, "IOERR_AMSDEVICENOAMSINTF"},
249 { IOERR_AMSDEVICEAMSCMDIDNOTSUPP, "IOERR_AMSDEVICEAMSCMDIDNOTSUPP"},
250 { IOERR_AMSDEVICEAMSSERVICERUNNING, "IOERR_AMSDEVICEAMSSERVICERUNNING"},
251 { IOERR_PLCINTERFACE_BUSY, "IOERR_PLCINTERFACE_BUSY"},
252 { IOERR_PLCINTERFACE_FAULT, "IOERR_PLCINTERFACE_FAULT"},
253 { IOERR_PLCINTERFACE_TIMEOUT, "IOERR_PLCINTERFACE_TIMEOUT"},
254 { IOERR_PLCINTERFACE_RESETTIMEOUT, "IOERR_PLCINTERFACE_RESETTIMEOUT"},
255 { IOERR_PLCINTERFACE_NODATAEXCH, "IOERR_PLCINTERFACE_NODATAEXCH"},
256 { IOERR_PLCINTERFACE_RESET, "IOERR_PLCINTERFACE_RESET"},
257 { IOERR_CP5412A2INVALIDADDR, "IOERR_CP5412A2INVALIDADDR"},
258 { IOERR_CP5412A2INVALIDPORT, "IOERR_CP5412A2INVALIDPORT"},
259 { IOERR_AMSDEVICEBADBOXNO, "IOERR_AMSDEVICEBADBOXNO"},
260 { IOERR_AMSDEVICEBADTYPE, "IOERR_AMSDEVICEBADTYPE"},
261 { IOERR_AMSDEVICEILLEGALADDRESS, "IOERR_AMSDEVICEILLEGALADDRESS"},
262 { IOERR_CP5412A2INVALIDBOX, "IOERR_CP5412A2INVALIDBOX"},
263 { IOERR_AMSDEVICEFIFOOVERFLOW, "IOERR_AMSDEVICEFIFOOVERFLOW"},
264 { IOERR_AMSDEVICEAMSSEQUENCEERROR, "IOERR_AMSDEVICEAMSSEQUENCEERROR"},
265 { IOERR_CP5412A2DPV1SYNTAXERROR, "IOERR_CP5412A2DPV1SYNTAXERROR"},
266 { IOERR_CP5412A2DEVICENOTRUNNING, "IOERR_CP5412A2DEVICENOTRUNNING"},
267 { IOERR_AMSDEVICENOTRUNNING, "IOERR_AMSDEVICENOTRUNNING"},
268 { IOERR_AMSDEVICEBOXNOTDEFINED, "IOERR_AMSDEVICEBOXNOTDEFINED"},
269 { IOERR_CP5412A2BADSERVICEPARA, "IOERR_CP5412A2BADSERVICEPARA"},
270 { IOERR_CP5412A2FIFOOVERFLOW, "IOERR_CP5412A2FIFOOVERFLOW"},
271 { IOERR_COMPORTOPENFAILED, "IOERR_COMPORTOPENFAILED"},
272 { IOERR_CIF30BADMESSAGERESPONSE, "IOERR_CIF30BADMESSAGERESPONSE"},
273 { IOERR_CIF30DELETEDATABASE, "IOERR_CIF30DELETEDATABASE"},
274 { IOERR_CIF30STARTSEQFAILED, "IOERR_CIF30STARTSEQFAILED"},
275 { IOERR_CIF30DOWNLOADFAILED, "IOERR_CIF30DOWNLOADFAILED"},
276 { IOERR_CIF30ENDSEQFAILED, "IOERR_CIF30ENDSEQFAILED"},
277 { IOERR_CIF30BUSLOADFAILED, "IOERR_CIF30BUSLOADFAILED"},
278 { IOERR_PLCINTERFACE_RESETREQ, "IOERR_PLCINTERFACE_RESETREQ"},
279 { IOERR_CP5412A2INVALIDCYCLETICKS, "IOERR_CP5412A2INVALIDCYCLETICKS"},
280 { IOERR_CP5412A2DPBUSFAULT, "IOERR_CP5412A2DPBUSFAULT"},
281 { IOERR_INVALIDTERMCONFIG, "IOERR_INVALIDTERMCONFIG"},
282 { IOERR_SERCANSBREAK, "IOERR_SERCANSBREAK"},
283 { IOERR_SERCANSPHASE0, "IOERR_SERCANSPHASE0"},
284 { IOERR_SERCANSPHASE1, "IOERR_SERCANSPHASE1"},
285 { IOERR_SERCANSPHASE2, "IOERR_SERCANSPHASE2"},
286 { IOERR_SERCANSPHASE3, "IOERR_SERCANSPHASE3"},
287 { IOERR_SERCANSPHASE4, "IOERR_SERCANSPHASE4"},
288 { IOERR_SERCANSNCSERVICECHNFAILED, "IOERR_SERCANSNCSERVICECHNFAILED"},
289 { IOERR_RESOURCECONFICT, "IOERR_RESOURCECONFICT"},
290 { IOERR_C1220INITSTRINGCOMM, "IOERR_C1220INITSTRINGCOMM"},
291 { IOERR_C1220REGSTRINGSLAVE, "IOERR_C1220REGSTRINGSLAVE"},
292 { IOERR_C1220STRREGFAULT, "IOERR_C1220STRREGFAULT"},
293 { IOERR_IOSTATEBUSY, "IOERR_IOSTATEBUSY"},
294 { IOERR_IBSSCITWATCHDOGEXPIRED, "IOERR_IBSSCITWATCHDOGEXPIRED"},
295 { IOERR_IBSSCITSYNCMAILBOXERROR, "IOERR_IBSSCITSYNCMAILBOXERROR"},
296 { IOERR_IBSSCITCONFIRMDIAGERROR, "IOERR_IBSSCITCONFIRMDIAGERROR"},
297 { IOERR_IBSSCITCREATECFGERROR, "IOERR_IBSSCITCREATECFGERROR"},
298 { 0, NULL }
301 static const value_string AdsErrorMode[] =
303 { ADSERR_NOERR, "NO ERROR", },
304 { ADSERR_DEVICE_ERROR, "ERROR", },
305 { ADSERR_DEVICE_SRVNOTSUPP, "SRV NOT SUPP", },
306 { ADSERR_DEVICE_INVALIDGRP, "INVALID GRP", },
307 { ADSERR_DEVICE_INVALIDOFFSET, "INVALID OFFSET", },
308 { ADSERR_DEVICE_INVALIDACCESS, "INVALID ACCESS", },
309 { ADSERR_DEVICE_INVALIDSIZE, "INVALID SIZE", },
310 { ADSERR_DEVICE_INVALIDDATA, "INVALID DATA", },
311 { ADSERR_DEVICE_NOTREADY, "NOT READY", },
312 { ADSERR_DEVICE_BUSY, "BUSY", },
313 { ADSERR_DEVICE_INVALIDCONTEXT, "INVALID CONTEXT", },
314 { ADSERR_DEVICE_NOMEMORY, "NO MEMORY", },
315 { ADSERR_DEVICE_INVALIDPARM, "INVALID PARM", },
316 { ADSERR_DEVICE_NOTFOUND, "NOT FOUND", },
317 { ADSERR_DEVICE_SYNTAX, "SYNTAX", },
318 { ADSERR_DEVICE_INCOMPATIBLE, "INCOMPATIBLE", },
319 { ADSERR_DEVICE_EXISTS, "EXISTS", },
320 { ADSERR_DEVICE_SYMBOLNOTFOUND, "SYMBOL NOT FOUND", },
321 { ADSERR_DEVICE_SYMBOLVERSIONINVALID, "SYMBOL VERSION INVALID", },
322 { ADSERR_DEVICE_INVALIDSTATE, "INVALID STATE", },
323 { ADSERR_DEVICE_TRANSMODENOTSUPP, "TRANS MODE NOT SUPP", },
324 { ADSERR_DEVICE_NOTIFYHNDINVALID, "NOTIFY HND INVALID", },
325 { ADSERR_DEVICE_CLIENTUNKNOWN, "CLIENT UNKNOWN", },
326 { ADSERR_DEVICE_NOMOREHDLS, "NO MORE HDLS", },
327 { ADSERR_DEVICE_INVALIDWATCHSIZE, "INVALID WATCHSIZE", },
328 { ADSERR_DEVICE_NOTINIT, "NOT INIT", },
329 { ADSERR_DEVICE_TIMEOUT, "TIMEOUT", },
330 { ADSERR_DEVICE_NOINTERFACE, "NO INTERFACE", },
331 { ADSERR_DEVICE_INVALIDINTERFACE, "INVALID INTERFACE", },
332 { ADSERR_DEVICE_INVALIDCLSID, "INVALID CLSID", },
333 { ADSERR_DEVICE_INVALIDOBJID, "INVALID OBJID", },
334 { ADSERR_DEVICE_PENDING, "PENDING", },
335 { ADSERR_DEVICE_ABORTED, "ABORTED", },
336 { ADSERR_DEVICE_WARNING, "WARNING", },
337 { ADSERR_DEVICE_INVALIDARRAYIDX, "INVALID ARRAY IDX", },
338 { ADSERR_CLIENT_ERROR, "CLIENT ERROR", },
339 { ADSERR_CLIENT_INVALIDPARM, "CLIENT INVALID PARM", },
340 { ADSERR_CLIENT_LISTEMPTY, "CLIENT LIST EMPTY", },
341 { ADSERR_CLIENT_VARUSED, "CLIENT VAR USED", },
342 { ADSERR_CLIENT_DUPLINVOKEID, "CLIENT DUPL INVOKEID", },
343 { ADSERR_CLIENT_SYNCTIMEOUT, "CLIENT SYNC TIMEOUT", },
344 { ADSERR_CLIENT_W32ERROR, "CLIENT W32ERROR", },
345 { ADSERR_CLIENT_TIMEOUTINVALID, "CLIENT TIMEOUT INVALID", },
346 { ADSERR_CLIENT_PORTNOTOPEN, "CLIENT PORT NOT OPEN", },
347 { ADSERR_CLIENT_NOAMSADDR, "CLIENT NO AMS ADDR", },
348 { ADSERR_CLIENT_SYNCINTERNAL, "CLIENT SYNC INTERNAL", },
349 { ADSERR_CLIENT_ADDHASH, "CLIENT ADD HASH", },
350 { ADSERR_CLIENT_REMOVEHASH, "CLIENT REMOVE HASH", },
351 { ADSERR_CLIENT_NOMORESYM, "CLIENT NO MORE SYM", },
352 { ADSERR_CLIENT_SYNCRESINVALID, "CLIENT SYNC RES INVALID", },
353 { ADSERR_CLIENT_SYNCPORTLOCKED, "CLIENT SYNC PORT LOCKED", },
354 { 0, NULL }
358 /* AMS Command Id
359 * https://infosys.beckhoff.com/english.php?content=../content/1033/tcadsamsspec/html/tcadsamsspec_adscmd_readstate.htm&id=10652
361 static const value_string AMS_CommandId_vals[] =
363 { ADSSRVID_INVALID, "Invalid", },
364 { ADSSRVID_READDEVICEINFO, "ADS Read Device Info", },
365 { ADSSRVID_READ, "ADS Read", },
366 { ADSSRVID_WRITE, "ADS Write", },
367 { ADSSRVID_READSTATE, "ADS Read State", },
368 { ADSSRVID_WRITECTRL, "ADS Write Control", },
369 { ADSSRVID_ADDDEVICENOTE, "ADS Add Device Notification", },
370 { ADSSRVID_DELDEVICENOTE, "ADS Delete Device Notification", },
371 { ADSSRVID_DEVICENOTE, "ADS Device Notification", },
372 { ADSSRVID_READWRITE, "ADS Read Write", },
373 { 0, NULL }
377 static void NetIdFormater(tvbuff_t *tvb, unsigned offset, char *szText, int nMax)
379 snprintf ( szText, nMax, "%d.%d.%d.%d.%d.%d", tvb_get_uint8(tvb, offset),
380 tvb_get_uint8(tvb, offset+1),
381 tvb_get_uint8(tvb, offset+2),
382 tvb_get_uint8(tvb, offset+3),
383 tvb_get_uint8(tvb, offset+4),
384 tvb_get_uint8(tvb, offset+5)
390 /*ams*/
391 static int dissect_ams_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
393 proto_item *ti, *anItem;
394 proto_tree *ams_tree = NULL, *ams_adstree, *ams_statetree;
395 unsigned ams_length = tvb_reported_length(tvb);
396 uint16_t stateflags = 0;
397 uint16_t cmdId = 0;
398 uint32_t cbdata = 0;
400 char szText[200];
401 int nMax = sizeof(szText)-1;
403 col_set_str(pinfo->cinfo, COL_PROTOCOL, "AMS");
405 col_clear(pinfo->cinfo, COL_INFO);
407 if( ams_length < AmsHead_Len )
408 return offset;
410 if (tree)
412 ti = proto_tree_add_item(tree, proto_ams, tvb, 0, -1, ENC_NA);
413 ams_tree = proto_item_add_subtree(ti, ett_ams);
415 NetIdFormater(tvb, offset, szText, nMax);
416 proto_tree_add_string(ams_tree, hf_ams_targetnetid, tvb, offset, AmsNetId_Len, szText);
417 offset += AmsNetId_Len;
419 proto_tree_add_item(ams_tree, hf_ams_targetport, tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
420 offset += (int)sizeof(uint16_t);
422 NetIdFormater(tvb, offset, szText, nMax);
423 proto_tree_add_string(ams_tree, hf_ams_sendernetid, tvb, offset, AmsNetId_Len, szText);
424 offset += AmsNetId_Len;
426 proto_tree_add_item(ams_tree, hf_ams_senderport, tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
427 offset += (int)sizeof(uint16_t);
429 proto_tree_add_item(ams_tree, hf_ams_cmdid, tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
430 cmdId = tvb_get_letohs(tvb, offset);
431 offset+=(int)sizeof(uint16_t);
433 anItem = proto_tree_add_item(ams_tree, hf_ams_stateflags, tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
434 ams_statetree = proto_item_add_subtree(anItem, ett_ams_stateflags);
435 proto_tree_add_item(ams_statetree, hf_ams_stateresponse,tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
436 proto_tree_add_item(ams_statetree, hf_ams_statenoreturn,tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
437 proto_tree_add_item(ams_statetree, hf_ams_stateadscmd,tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
438 proto_tree_add_item(ams_statetree, hf_ams_statesyscmd,tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
439 proto_tree_add_item(ams_statetree, hf_ams_statehighprio,tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
440 proto_tree_add_item(ams_statetree, hf_ams_statetimestampadded,tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
441 proto_tree_add_item(ams_statetree, hf_ams_stateudp,tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
442 proto_tree_add_item(ams_statetree, hf_ams_stateinitcmd,tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
443 proto_tree_add_item(ams_statetree, hf_ams_statebroadcast,tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
444 stateflags = tvb_get_letohs(tvb, offset);
445 offset+=(int)sizeof(uint16_t);
447 proto_tree_add_item(ams_tree, hf_ams_cbdata, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
448 cbdata = tvb_get_letohl(tvb,offset);
449 offset+=(int)sizeof(uint32_t);
451 proto_tree_add_item(ams_tree, hf_ams_errorcode, tvb, offset, (int)sizeof(uint32_t),ENC_LITTLE_ENDIAN);
452 offset+=(int)sizeof(uint32_t);
454 proto_tree_add_item(ams_tree, hf_ams_invokeid, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
455 offset+=(int)sizeof(uint32_t);
457 else
459 offset+=AmsHead_Len;
462 if ( (stateflags & AMSCMDSF_ADSCMD) != 0 )
464 /* ADS */
465 if ( (stateflags & AMSCMDSF_RESPONSE) == 0 )
467 /* Request */
468 switch ( cmdId )
470 case ADSSRVID_READ:
472 col_append_str(pinfo->cinfo, COL_INFO, "ADS Read Request");
474 if( tree )
476 anItem = proto_tree_add_item(ams_tree, hf_ams_adsreadrequest, tvb, offset, ams_length-offset, ENC_NA);
477 if( ams_length-offset >= TAdsReadReq_Len )
479 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsreadrequest);
480 proto_tree_add_item(ams_adstree, hf_ams_adsindexgroup, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
481 offset+=(int)sizeof(uint32_t);
483 proto_tree_add_item(ams_adstree, hf_ams_adsindexoffset, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
484 offset+=(int)sizeof(uint32_t);
486 proto_tree_add_item(ams_adstree, hf_ams_adscblength, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
487 offset+=(int)sizeof(uint32_t);
491 break;
492 case ADSSRVID_WRITE:
494 col_append_str(pinfo->cinfo, COL_INFO, "ADS Write Request");
496 if( tree )
498 anItem = proto_tree_add_item(ams_tree, hf_ams_adswriterequest, tvb, offset, ams_length-offset, ENC_NA);
499 if( ams_length-offset >= TAdsWriteReq_Len - (int)sizeof(uint16_t) )
501 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adswriterequest);
502 proto_tree_add_item(ams_adstree, hf_ams_adsindexgroup, tvb, offset, 4, ENC_LITTLE_ENDIAN);
503 offset+=(int)sizeof(uint32_t);
505 proto_tree_add_item(ams_adstree, hf_ams_adsindexoffset, tvb, offset, 4, ENC_LITTLE_ENDIAN);
506 offset+=(int)sizeof(uint32_t);
508 proto_tree_add_item(ams_adstree, hf_ams_adscblength, tvb, offset, 4, ENC_LITTLE_ENDIAN);
509 offset+=(int)sizeof(uint32_t);
511 proto_tree_add_item(ams_adstree, hf_ams_adsdata, tvb, offset, ams_length-offset, ENC_NA);
515 break;
516 case ADSSRVID_READWRITE:
518 col_append_str(pinfo->cinfo, COL_INFO, "ADS Read Write Request");
520 if( tree )
522 anItem = proto_tree_add_item(ams_tree, hf_ams_adsreadwriterequest, tvb, offset, ams_length-offset, ENC_NA);
523 if( ams_length-offset >= TAdsReadWriteReq_Len - (int)sizeof(uint16_t))
525 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsreadwriterequest);
526 proto_tree_add_item(ams_adstree, hf_ams_adsindexgroup, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
527 offset+=(int)sizeof(uint32_t);
529 proto_tree_add_item(ams_adstree, hf_ams_adsindexoffset, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
530 offset+=(int)sizeof(uint32_t);
532 proto_tree_add_item(ams_adstree, hf_ams_adscbreadlength, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
533 offset+=(int)sizeof(uint32_t);
535 proto_tree_add_item(ams_adstree, hf_ams_adscbwritelength, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
536 offset+=(int)sizeof(uint32_t);
538 proto_tree_add_item(ams_adstree, hf_ams_adsdata, tvb, offset, ams_length-offset, ENC_NA);
542 break;
543 case ADSSRVID_READSTATE:
545 col_append_str(pinfo->cinfo, COL_INFO, "ADS Read State Request");
547 if( tree && cbdata !=0 )
549 anItem = proto_tree_add_item(ams_tree, hf_ams_adsreadstaterequest, tvb, offset, ams_length-offset, ENC_NA);
550 if( ams_length-offset >= TAdsReadStateReq_Len )
552 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsreadstaterequest);
553 proto_tree_add_item(ams_adstree, hf_ams_adsinvokeid, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
557 break;
558 case ADSSRVID_WRITECTRL:
560 col_append_str(pinfo->cinfo, COL_INFO, "ADS Write Control Request");
562 if( tree )
564 anItem = proto_tree_add_item(ams_tree, hf_ams_adswritectrlrequest, tvb, offset, ams_length-offset, ENC_NA);
565 if( ams_length-offset >= TAdsWriteControlReq_Len - (int)sizeof(uint16_t) )
567 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adswritectrlrequest);
568 proto_tree_add_item(ams_adstree, hf_ams_adsstate, tvb, offset, 2, ENC_LITTLE_ENDIAN);
569 offset+=(int)sizeof(uint16_t);
571 proto_tree_add_item(ams_adstree, hf_ams_adsdevicestate, tvb, offset, 2, ENC_LITTLE_ENDIAN);
572 offset+=(int)sizeof(uint16_t);
574 proto_tree_add_item(ams_adstree, hf_ams_adscblength, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
575 offset+=(int)sizeof(uint32_t);
577 proto_tree_add_item(ams_adstree, hf_ams_adsdata, tvb, offset, ams_length-offset, ENC_NA);
581 break;
582 case ADSSRVID_READDEVICEINFO:
584 col_append_str(pinfo->cinfo, COL_INFO, "ADS Read Device Info Request");
586 if( tree && cbdata !=0 )
588 anItem = proto_tree_add_item(ams_tree, hf_ams_adsreaddinforequest, tvb, offset, ams_length-offset, ENC_NA);
589 if( ams_length-offset >= TAdsReadDeviceInfoReq_Len )
591 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsreaddinforequest);
592 proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
596 break;
597 case ADSSRVID_ADDDEVICENOTE:
599 col_append_str(pinfo->cinfo, COL_INFO, "ADS Add Device Notification Request");
601 if( tree )
603 anItem = proto_tree_add_item(ams_tree, hf_ams_adsadddnrequest, tvb, offset, ams_length-offset, ENC_NA);
604 if( ams_length-offset >= TAdsAddDeviceNotificationReq_Len )
606 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsadddnrequest);
607 proto_tree_add_item(ams_adstree, hf_ams_adsindexgroup, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
608 offset+=(int)sizeof(uint32_t);
610 proto_tree_add_item(ams_adstree, hf_ams_adsindexoffset, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
611 offset+=(int)sizeof(uint32_t);
613 proto_tree_add_item(ams_adstree, hf_ams_adscblength, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
614 offset+=(int)sizeof(uint32_t);
616 proto_tree_add_item(ams_adstree, hf_ams_adstransmode, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
617 offset+=(int)sizeof(uint32_t);
619 proto_tree_add_item(ams_adstree, hf_ams_adsmaxdelay, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
620 offset+=(int)sizeof(uint32_t);
622 proto_tree_add_item(ams_adstree, hf_ams_adscycletime, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
623 offset+=(int)sizeof(uint32_t);
627 break;
628 case ADSSRVID_DELDEVICENOTE:
630 col_append_str(pinfo->cinfo, COL_INFO, "ADS Delete Device Notification Request");
632 if( tree )
634 anItem = proto_tree_add_item(ams_tree, hf_ams_adsdeldnrequest, tvb, offset, ams_length-offset, ENC_NA);
635 if( ams_length-offset >= TAdsDelDeviceNotificationReq_Len )
637 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsdeldnrequest);
638 proto_tree_add_item(ams_adstree, hf_ams_adsnotificationhandle, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
642 break;
643 case ADSSRVID_DEVICENOTE:
645 col_append_str(pinfo->cinfo, COL_INFO, "ADS Device Notification Request");
647 if( tree )
649 /*uint32_t cbLength;
650 uint32_t nStamps;*/
652 anItem = proto_tree_add_item(ams_tree, hf_ams_adsdnrequest, tvb, offset, ams_length-offset, ENC_NA);
653 if( ams_length-offset >= TAdsDeviceNotificationReq_Len )
655 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsdnrequest);
656 proto_tree_add_item(ams_adstree, hf_ams_adscblength, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
657 /*cbLength = tvb_get_letohs(tvb, offset);*/
658 offset+=(int)sizeof(uint32_t);
660 proto_tree_add_item(ams_adstree, hf_ams_adsnoteblocksstamps, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
661 /*nStamps = tvb_get_letohs(tvb, offset);*/
662 offset+=(int)sizeof(uint32_t);
664 /*ToDo: dissect noteblocks*/
668 break;
671 else
673 /* Response */
674 switch ( cmdId )
676 case ADSSRVID_READ:
678 col_append_str(pinfo->cinfo, COL_INFO, "ADS Read Response");
680 if( tree )
682 anItem = proto_tree_add_item(ams_tree, hf_ams_adsreadresponse, tvb, offset, ams_length-offset, ENC_NA);
683 if( ams_length-offset >= TAdsReadRes_Len - (int)sizeof(uint16_t) )
685 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsreadresponse);
686 proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
687 offset+=(int)sizeof(uint32_t);
689 proto_tree_add_item(ams_adstree, hf_ams_adscblength, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
690 offset+=(int)sizeof(uint32_t);
692 proto_tree_add_item(ams_adstree, hf_ams_adsdata, tvb, offset, ams_length-offset, ENC_NA);
696 break;
697 case ADSSRVID_WRITE:
699 col_append_str(pinfo->cinfo, COL_INFO, "ADS Write Response");
701 if( tree )
703 anItem = proto_tree_add_item(ams_tree, hf_ams_adswriteresponse, tvb, offset, ams_length-offset, ENC_NA);
704 if( ams_length-offset >= TAdsWriteRes_Len )
706 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adswriteresponse);
707 proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
711 break;
712 case ADSSRVID_READWRITE:
714 col_append_str(pinfo->cinfo, COL_INFO, "ADS Read Write Response");
716 if( tree )
718 anItem = proto_tree_add_item(ams_tree, hf_ams_adsreadwriteresponse, tvb, offset, ams_length-offset, ENC_NA);
719 if( ams_length-offset >= TAdsReadWriteRes_Len - (int)sizeof(uint16_t) )
721 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsreadwriteresponse);
722 proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
723 offset+=(int)sizeof(uint32_t);
725 proto_tree_add_item(ams_adstree, hf_ams_adscblength, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
726 offset+=(int)sizeof(uint32_t);
728 proto_tree_add_item(ams_adstree, hf_ams_adsdata, tvb, offset, ams_length-offset, ENC_NA);
732 break;
733 case ADSSRVID_READSTATE:
735 col_append_str(pinfo->cinfo, COL_INFO, "ADS Read State Response");
737 if( tree )
739 anItem = proto_tree_add_item(ams_tree, hf_ams_adsreadstateresponse, tvb, offset, ams_length-offset, ENC_NA);
740 if( ams_length-offset >= TAdsReadStateRes_Len )
742 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsreadstateresponse);
743 proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
744 offset+=(int)sizeof(uint32_t);
746 proto_tree_add_item(ams_adstree, hf_ams_adsstate, tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
747 offset+=(int)sizeof(uint16_t);
749 proto_tree_add_item(ams_adstree, hf_ams_adsdevicestate, tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
753 break;
754 case ADSSRVID_WRITECTRL:
756 col_append_str(pinfo->cinfo, COL_INFO, "ADS Write Control Response");
758 if( tree )
760 anItem = proto_tree_add_item(ams_tree, hf_ams_adswritectrlresponse, tvb, offset, ams_length-offset, ENC_NA);
761 if( ams_length-offset >= TAdsWriteControlRes_Len )
763 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adswritectrlresponse);
764 proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
768 break;
769 case ADSSRVID_READDEVICEINFO:
771 col_append_str(pinfo->cinfo, COL_INFO, "ADS Read Device Info Response");
773 if( tree )
775 anItem = proto_tree_add_item(ams_tree, hf_ams_adsreaddinforesponse, tvb, offset, ams_length-offset, ENC_NA);
776 if( ams_length-offset >= TAdsReadDeviceInfoRes_Len )
778 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsreaddinforesponse);
779 proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
780 offset+=(int)sizeof(uint32_t);
782 proto_tree_add_item(ams_adstree, hf_ams_adsversionversion, tvb, offset++, (int)sizeof(uint8_t), ENC_LITTLE_ENDIAN);
783 proto_tree_add_item(ams_adstree, hf_ams_adsversionrevision, tvb, offset++, (int)sizeof(uint8_t), ENC_LITTLE_ENDIAN);
784 proto_tree_add_item(ams_adstree, hf_ams_adsversionbuild, tvb, offset, (int)sizeof(uint16_t), ENC_LITTLE_ENDIAN);
785 offset+=(int)sizeof(uint16_t);
787 proto_tree_add_item(ams_adstree, hf_ams_adsdevicename, tvb, offset, ams_length-offset, ENC_ASCII|ENC_NA);
791 break;
792 case ADSSRVID_ADDDEVICENOTE:
794 col_append_str(pinfo->cinfo, COL_INFO, "ADS Device Notification Response");
796 if( tree )
798 anItem = proto_tree_add_item(ams_tree, hf_ams_adsadddnresponse, tvb, offset, ams_length-offset, ENC_NA);
799 if( ams_length-offset >= TAdsAddDeviceNotificationRes_Len )
801 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsadddnresponse);
802 proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
803 offset+=(int)sizeof(uint32_t);
805 proto_tree_add_item(ams_adstree, hf_ams_adsnotificationhandle, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
809 break;
810 case ADSSRVID_DELDEVICENOTE:
812 col_append_str(pinfo->cinfo, COL_INFO, "ADS Delete Device Notification Response");
814 if( tree )
816 anItem = proto_tree_add_item(ams_tree, hf_ams_adsdeldnresponse, tvb, offset, ams_length-offset, ENC_NA);
817 if( ams_length-offset >= TAdsDelDeviceNotificationRes_Len )
819 ams_adstree = proto_item_add_subtree(anItem, ett_ams_adsdeldnresponse);
820 proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, (int)sizeof(uint32_t), ENC_LITTLE_ENDIAN);
824 break;
828 else
830 if ( (stateflags & AMSCMDSF_RESPONSE) == 0 )
831 col_append_str(pinfo->cinfo, COL_INFO, "AMS Request");
832 else
833 col_append_str(pinfo->cinfo, COL_INFO, "AMS Response");
834 if( tree && ams_length-offset > 0 )
835 proto_tree_add_item(ams_tree, hf_ams_data, tvb, offset, ams_length-offset, ENC_NA);
837 return offset;
840 /*ams*/
841 static int dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
843 return dissect_ams_pdu(tvb, pinfo, tree, 0);
846 static int dissect_amstcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
848 if( TcpAdsParserHDR_Len > tvb_reported_length(tvb))
849 return 0;
851 return dissect_ams_pdu(tvb, pinfo, tree, TcpAdsParserHDR_Len);
854 void proto_register_ams(void)
856 static const true_false_string flags_set_truth =
858 "Set",
859 "Not set"
862 static hf_register_info hf[] =
864 { &hf_ams_sendernetid,
865 { "AMS Sender Net Id", "ams.sendernetid",
866 FT_STRING, BASE_NONE, NULL, 0x0,
867 NULL, HFILL }
869 { &hf_ams_senderport,
870 { "AMS Sender port", "ams.senderport",
871 FT_UINT16, BASE_DEC, NULL, 0x0,
872 NULL, HFILL }
874 { &hf_ams_targetnetid,
875 { "AMS Target Net Id", "ams.targetnetid",
876 FT_STRING, BASE_NONE, NULL, 0x0,
877 NULL, HFILL }
879 { &hf_ams_targetport,
880 { "AMS Target port", "ams.targetport",
881 FT_UINT16, BASE_DEC, NULL, 0x0,
882 NULL, HFILL }
884 { &hf_ams_cmdid,
885 { "CmdId", "ams.cmdid",
886 FT_UINT16, BASE_DEC, VALS(AMS_CommandId_vals), 0x0,
887 NULL, HFILL }
889 { &hf_ams_stateflags,
890 { "StateFlags", "ams.stateflags",
891 FT_UINT16, BASE_HEX, NULL, 0x0,
892 NULL, HFILL }
894 { &hf_ams_stateresponse,
895 { "RESPONSE", "ams.state_response",
896 FT_BOOLEAN, 16, TFS(&flags_set_truth), AMSCMDSF_RESPONSE,
897 NULL, HFILL }
899 { &hf_ams_statenoreturn,
900 { "NO RETURN", "ams.state_noreturn",
901 FT_BOOLEAN, 16, TFS(&flags_set_truth), AMSCMDSF_NORETURN,
902 NULL, HFILL }
904 { &hf_ams_stateadscmd,
905 { "ADS COMMAND", "ams.state_adscmd",
906 FT_BOOLEAN, 16, TFS(&flags_set_truth), AMSCMDSF_ADSCMD,
907 NULL, HFILL }
909 { &hf_ams_statesyscmd,
910 { "SYSTEM COMMAND", "ams.state_syscmd",
911 FT_BOOLEAN, 16, TFS(&flags_set_truth), AMSCMDSF_SYSCMD,
912 NULL, HFILL }
914 { &hf_ams_statehighprio,
915 { "HIGH PRIORITY COMMAND", "ams.state_highprio",
916 FT_BOOLEAN, 16, TFS(&flags_set_truth), AMSCMDSF_HIGHPRIO,
917 NULL, HFILL }
919 { &hf_ams_statetimestampadded,
920 { "TIMESTAMP ADDED", "ams.state_timestampadded",
921 FT_BOOLEAN, 16, TFS(&flags_set_truth), AMSCMDSF_TIMESTAMPADDED,
922 NULL, HFILL }
924 { &hf_ams_stateudp,
925 { "UDP COMMAND", "ams.state_udp",
926 FT_BOOLEAN, 16, TFS(&flags_set_truth), AMSCMDSF_UDP,
927 NULL, HFILL }
929 { &hf_ams_stateinitcmd,
930 { "INIT COMMAND", "ams.state_initcmd",
931 FT_BOOLEAN, 16, TFS(&flags_set_truth), AMSCMDSF_INITCMD,
932 NULL, HFILL }
934 { &hf_ams_statebroadcast,
935 { "BROADCAST", "ams.state_broadcast",
936 FT_BOOLEAN, 16, TFS(&flags_set_truth), AMSCMDSF_BROADCAST,
937 NULL, HFILL }
939 { &hf_ams_cbdata,
940 { "cbData", "ams.cbdata",
941 FT_UINT32, BASE_DEC, NULL, 0x0,
942 NULL, HFILL }
944 { &hf_ams_errorcode,
945 { "ErrorCode", "ams.errorcode",
946 FT_UINT32, BASE_HEX, VALS(ErrorCode), 0x0,
947 NULL, HFILL }
949 { &hf_ams_invokeid,
950 { "InvokeId", "ams.invokeid",
951 FT_UINT32, BASE_HEX, NULL, 0x0,
952 NULL, HFILL }
954 { &hf_ams_adsdata,
955 { "Data", "ams.ads_data",
956 FT_NONE, BASE_NONE, NULL, 0x0,
957 NULL, HFILL }
959 { &hf_ams_data,
960 { "Data", "ams.data",
961 FT_NONE, BASE_NONE, NULL, 0x0,
962 NULL, HFILL }
964 { &hf_ams_adsindexgroup,
965 { "IndexGroup", "ams.ads_indexgroup",
966 FT_UINT32, BASE_HEX, NULL, 0x0,
967 NULL, HFILL }
969 { &hf_ams_adsindexoffset,
970 { "IndexOffset", "ams.ads_indexoffset",
971 FT_UINT32, BASE_HEX, NULL, 0x0,
972 NULL, HFILL }
974 { &hf_ams_adscblength,
975 { "CbLength", "ams.ads_cblength",
976 FT_UINT32, BASE_DEC, NULL, 0x0,
977 NULL, HFILL }
979 { &hf_ams_adsreadrequest,
980 { "ADS Read Request", "ams.ads_read_req",
981 FT_NONE, BASE_NONE, NULL, 0x0,
982 NULL, HFILL }
984 { &hf_ams_adsreadresponse,
985 { "ADS Read Response", "ams.ads_read_res",
986 FT_NONE, BASE_NONE, NULL, 0x0,
987 NULL, HFILL }
989 { &hf_ams_adsinvokeid,
990 { "InvokeId", "ams.ads_invokeid",
991 FT_UINT32, BASE_HEX, NULL, 0x0,
992 NULL, HFILL }
994 { &hf_ams_adsresult,
995 { "Result", "ams.adsresult",
996 FT_UINT32, BASE_HEX, VALS(AdsErrorMode), 0x0,
997 NULL, HFILL }
999 { &hf_ams_adswriterequest,
1000 { "ADS Write Request", "ams.ads_write_req",
1001 FT_NONE, BASE_NONE, NULL, 0x0,
1002 NULL, HFILL }
1004 { &hf_ams_adswriteresponse,
1005 { "ADS Write Response", "ams.ads_write_res",
1006 FT_NONE, BASE_NONE, NULL, 0x0,
1007 NULL, HFILL }
1009 { &hf_ams_adsreadwriterequest,
1010 { "ADS ReadWrite Request", "ams.ads_readwrite_req",
1011 FT_NONE, BASE_NONE, NULL, 0x0,
1012 NULL, HFILL }
1014 { &hf_ams_adsreadwriteresponse,
1015 { "ADS ReadWrite Response", "ams.ads_readwrite_res",
1016 FT_NONE, BASE_NONE, NULL, 0x0,
1017 NULL, HFILL }
1019 { &hf_ams_adscbreadlength,
1020 { "CBReadLength", "ams.ads_cbreadlength",
1021 FT_UINT32, BASE_DEC, NULL, 0x0,
1022 NULL, HFILL }
1024 { &hf_ams_adscbwritelength,
1025 { "CBWriteLength", "ams.ads_cbwritelength",
1026 FT_UINT32, BASE_DEC, NULL, 0x0,
1027 NULL, HFILL }
1029 { &hf_ams_adsstate,
1030 { "AdsState", "ams.ads_state",
1031 FT_UINT16, BASE_HEX, NULL, 0x0,
1032 NULL, HFILL }
1034 { &hf_ams_adsdevicestate,
1035 { "DeviceState", "ams.ads_devicestate",
1036 FT_UINT16, BASE_HEX, NULL, 0x0,
1037 NULL, HFILL }
1039 { &hf_ams_adsnotificationhandle,
1040 { "NotificationHandle", "ams.ads_notificationhandle",
1041 FT_UINT32, BASE_HEX, NULL, 0x0,
1042 NULL, HFILL }
1044 { &hf_ams_adsreadstaterequest,
1045 { "ADS Read State Request", "ams.ads_readstate_req",
1046 FT_NONE, BASE_NONE, NULL, 0x0,
1047 NULL, HFILL }
1049 { &hf_ams_adsreadstateresponse,
1050 { "ADS Read State Response", "ams.ads_readstate_res",
1051 FT_NONE, BASE_NONE, NULL, 0x0,
1052 NULL, HFILL }
1054 { &hf_ams_adswritectrlrequest,
1055 { "ADS Write Ctrl Request", "ams.ads_writectrl_req",
1056 FT_NONE, BASE_NONE, NULL, 0x0,
1057 NULL, HFILL }
1059 { &hf_ams_adswritectrlresponse,
1060 { "ADS Write Ctrl Response", "ams.ads_writectrl_res",
1061 FT_NONE, BASE_NONE, NULL, 0x0,
1062 NULL, HFILL }
1064 { &hf_ams_adsreaddinforequest,
1065 { "ADS Read Device Info Request", "ams.ads_readdinfo_req",
1066 FT_NONE, BASE_NONE, NULL, 0x0,
1067 NULL, HFILL }
1069 { &hf_ams_adsreaddinforesponse,
1070 { "ADS Read Device Info Response", "ams.ads_readdinfo_res",
1071 FT_NONE, BASE_NONE, NULL, 0x0,
1072 NULL, HFILL }
1074 { &hf_ams_adsadddnrequest,
1075 { "ADS Add Device Notification Request", "ams.ads_adddn_req",
1076 FT_NONE, BASE_NONE, NULL, 0x0,
1077 NULL, HFILL }
1079 { &hf_ams_adsadddnresponse,
1080 { "ADS Add Device Notification Response", "ams.ads_adddn_res",
1081 FT_NONE, BASE_NONE, NULL, 0x0,
1082 NULL, HFILL }
1084 { &hf_ams_adsdeldnrequest,
1085 { "ADS Delete Device Notification Request", "ams.ads_deldn_req",
1086 FT_NONE, BASE_NONE, NULL, 0x0,
1087 NULL, HFILL }
1089 { &hf_ams_adsdeldnresponse,
1090 { "ADS Delete Device Notification Response", "ams.ads_deldn_res",
1091 FT_NONE, BASE_NONE, NULL, 0x0,
1092 NULL, HFILL }
1094 { &hf_ams_adsdnrequest,
1095 { "ADS Device Notification Request", "ams.ads_dn_req",
1096 FT_NONE, BASE_NONE, NULL, 0x0,
1097 NULL, HFILL }
1099 #if 0
1100 { &hf_ams_adsdnresponse,
1101 { "ADS Device Notification Response", "ams.ads_dn_res",
1102 FT_NONE, BASE_NONE, NULL, 0x0,
1103 NULL, HFILL }
1105 { &hf_ams_adsnoteattrib,
1106 { "InvokeId", "ams.ads_noteattrib",
1107 FT_NONE, BASE_NONE, NULL, 0x0,
1108 NULL, HFILL }
1110 { &hf_ams_adsnoteblocks,
1111 { "InvokeId", "ams.ads_noteblocks",
1112 FT_NONE, BASE_NONE, NULL, 0x0,
1113 NULL, HFILL }
1115 { &hf_ams_adsversion,
1116 { "ADS Version", "ams.ads_version",
1117 FT_UINT32, BASE_DEC, NULL, 0x0,
1118 NULL, HFILL }
1120 #endif
1121 { &hf_ams_adsdevicename,
1122 { "Device Name","ams.ads_devicename",
1123 FT_STRING, BASE_NONE, NULL, 0x0,
1124 NULL, HFILL }
1126 { &hf_ams_adsversionversion,
1127 { "ADS Major Version", "ams.ads_versionversion",
1128 FT_UINT8, BASE_DEC, NULL, 0x0,
1129 NULL, HFILL }
1131 { &hf_ams_adsversionrevision,
1132 { "ADS Minor Version", "ams.ads_versionrevision",
1133 FT_UINT8, BASE_DEC, NULL, 0x0,
1134 NULL, HFILL }
1136 { &hf_ams_adsversionbuild,
1137 { "ADS Version Build", "ams.ads_versionbuild",
1138 FT_UINT16, BASE_DEC, NULL, 0x0,
1139 NULL, HFILL }
1141 { &hf_ams_adsnoteblocksstamps,
1142 { "Count of Stamps", "ams.ads_noteblocksstamps",
1143 FT_UINT32, BASE_DEC, NULL, 0x0,
1144 NULL, HFILL }
1146 #if 0
1147 { &hf_ams_adsnoteblocksstamp,
1148 { "Notification Stamp", "ams.ads_noteblocksstamp",
1149 FT_NONE, BASE_NONE, NULL, 0x0,
1150 NULL, HFILL }
1152 { &hf_ams_adstimestamp,
1153 { "Time Stamp", "ams.ads_timestamp",
1154 FT_UINT64, BASE_DEC, NULL, 0x0,
1155 NULL, HFILL }
1157 { &hf_ams_adssamplecnt,
1158 { "Count of Stamps", "ams.ads_samplecnt",
1159 FT_UINT32, BASE_DEC, NULL, 0x0,
1160 NULL, HFILL }
1162 { &hf_ams_adsnoteblockssample,
1163 { "Notification Sample", "ams.ads_noteblockssample",
1164 FT_NONE, BASE_NONE, NULL, 0x0,
1165 NULL, HFILL }
1167 #endif
1168 { &hf_ams_adstransmode,
1169 { "Trans Mode", "ams.ads_transmode",
1170 FT_UINT32, BASE_DEC, VALS(TransMode), 0x0,
1171 NULL, HFILL }
1173 { &hf_ams_adsmaxdelay,
1174 { "Max Delay", "ams.ads_maxdelay",
1175 FT_UINT32, BASE_DEC, NULL, 0x0,
1176 NULL, HFILL }
1178 { &hf_ams_adscycletime,
1179 { "Cycle Time", "ams.ads_cycletime",
1180 FT_UINT32, BASE_DEC, NULL, 0x0,
1181 NULL, HFILL }
1183 #if 0
1184 { &hf_ams_adscmpmax,
1185 { "Cmp Mad", "ams.ads_cmpmax",
1186 FT_NONE, BASE_NONE, NULL, 0x0,
1187 NULL, HFILL }
1189 { &hf_ams_adscmpmin,
1190 { "Cmp Min", "ams.ads_cmpmin",
1191 FT_NONE, BASE_NONE, NULL, 0x0,
1192 NULL, HFILL }
1194 #endif
1197 static int *ett[] =
1199 &ett_ams,
1200 &ett_ams_stateflags,
1201 &ett_ams_adsreadrequest,
1202 &ett_ams_adsreadresponse,
1203 &ett_ams_adswriterequest,
1204 &ett_ams_adswriteresponse,
1205 &ett_ams_adsreadwriterequest,
1206 &ett_ams_adsreadwriteresponse,
1207 &ett_ams_adsreadstaterequest,
1208 &ett_ams_adsreadstateresponse,
1209 &ett_ams_adswritectrlrequest,
1210 &ett_ams_adswritectrlresponse,
1211 &ett_ams_adsreaddinforequest,
1212 &ett_ams_adsreaddinforesponse,
1213 &ett_ams_adsadddnrequest,
1214 &ett_ams_adsadddnresponse,
1215 &ett_ams_adsdeldnrequest,
1216 &ett_ams_adsdeldnresponse,
1217 &ett_ams_adsdnrequest
1220 proto_ams = proto_register_protocol("AMS", "AMS", "ams");
1221 proto_register_field_array(proto_ams, hf, array_length(hf));
1222 proto_register_subtree_array(ett, array_length(ett));
1224 ams_handle = register_dissector("ams", dissect_ams, proto_ams);
1225 amstcp_handle = register_dissector("ams.tcp", dissect_amstcp, proto_ams );
1228 /* The registration hand-off routing */
1230 void proto_reg_handoff_ams(void)
1232 dissector_add_uint_with_preference("tcp.port", AMS_TCP_PORT, amstcp_handle);
1233 dissector_add_uint("ecatf.type", 2, ams_handle);
1237 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1239 * Local Variables:
1240 * c-basic-offset: 3
1241 * tab-width: 8
1242 * indent-tabs-mode: nil
1243 * End:
1245 * ex: set shiftwidth=3 tabstop=8 expandtab:
1246 * :indentSize=3:tabSize=8:noTabs=true: