Add a few more menu items.
[obnox/wireshark/wip.git] / plugins / ethercat / packet-ecatmb.c
1 /* packet-ecatmb.c
2  * Routines for EtherCAT packet disassembly
3  *
4  * $Id$
5  *
6  * Copyright (c) 2007 by Beckhoff Automation GmbH
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 /* Include files */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <string.h>
34
35 #include <glib.h>
36
37 #include <epan/packet.h>
38
39 #include "packet-ecatmb.h"
40
41 #define BIT2BYTE(x) ((x+7)/8)
42 #define ENDOF(p) ((p)+1) /* pointer to end of *p */
43
44 static dissector_handle_t eth_handle;
45 static dissector_handle_t ams_handle;
46
47 /* Define the EtherCAT mailbox proto */
48 int proto_ecat_mailbox  = -1;
49
50 static int ett_ecat_mailbox = -1;
51 static int ett_ecat_mailbox_eoe = -1;
52 static int ett_ecat_mailbox_eoe_init = -1;
53 static int ett_ecat_mailbox_eoe_macfilter = -1;
54 static int ett_ecat_mailbox_eoe_macfilter_filter = -1;
55 static int ett_ecat_mailbox_eoe_macfilter_filtermask = -1;
56 static int ett_ecat_mailbox_coe = -1;
57 static int ett_ecat_mailbox_sdo = -1;
58 static int ett_ecat_mailbox_coe_sdoccs = -1;
59 static int ett_ecat_mailbox_coe_sdoscs = -1;
60 static int ett_ecat_mailbox_foe = -1;
61 static int ett_ecat_mailbox_foe_efw = -1;
62 static int ett_ecat_mailbox_soeflag = -1;
63 static int ett_ecat_mailbox_soe = -1;
64 static int ett_ecat_mailbox_fraghead = -1;
65 static int ett_ecat_mailbox_header = -1;
66
67 static int hf_ecat_mailboxlength = -1;
68 static int hf_ecat_mailboxaddress = -1;
69 static int hf_ecat_mailbox_eoe = -1;
70 static int hf_ecat_mailbox_eoe_fraghead = -1;
71 static int hf_ecat_mailbox_eoe_type = -1;
72 static int hf_ecat_mailbox_eoe_fragno = -1;
73 static int hf_ecat_mailbox_eoe_offset = -1;
74 static int hf_ecat_mailbox_eoe_frame = -1;
75 static int hf_ecat_mailbox_eoe_last = -1;
76 static int hf_ecat_mailbox_eoe_timestampreq = -1;
77 static int hf_ecat_mailbox_eoe_timestampapp = -1;
78 static int hf_ecat_mailbox_eoe_fragment = -1;
79 static int hf_ecat_mailbox_eoe_init = -1;
80 static int hf_ecat_mailbox_eoe_init_contains_macaddr = -1;
81 static int hf_ecat_mailbox_eoe_init_contains_ipaddr = -1;
82 static int hf_ecat_mailbox_eoe_init_contains_subnetmask = -1;
83 static int hf_ecat_mailbox_eoe_init_contains_defaultgateway = -1;
84 static int hf_ecat_mailbox_eoe_init_contains_dnsserver = -1;
85 static int hf_ecat_mailbox_eoe_init_contains_dnsname = -1;
86 static int hf_ecat_mailbox_eoe_init_append_timestamp = -1;
87 static int hf_ecat_mailbox_eoe_init_macaddr = -1;
88 static int hf_ecat_mailbox_eoe_init_ipaddr = -1;
89 static int hf_ecat_mailbox_eoe_init_subnetmask = -1;
90 static int hf_ecat_mailbox_eoe_init_defaultgateway = -1;
91 static int hf_ecat_mailbox_eoe_init_dnsserver = -1;
92 static int hf_ecat_mailbox_eoe_init_dnsname = -1;
93 static int hf_ecat_mailbox_eoe_macfilter = -1;
94 static int hf_ecat_mailbox_eoe_macfilter_macfiltercount = -1;
95 static int hf_ecat_mailbox_eoe_macfilter_maskcount = -1;
96 static int hf_ecat_mailbox_eoe_macfilter_nobroadcasts = -1;
97 static int hf_ecat_mailbox_eoe_macfilter_filter;
98 static int hf_ecat_mailbox_eoe_macfilter_filters[16] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
99 static int hf_ecat_mailbox_eoe_macfilter_filtermask = -1;
100 static int hf_ecat_mailbox_eoe_macfilter_filtermasks[4] = {-1,-1,-1,-1};
101 static int hf_ecat_mailbox_eoe_timestamp = -1;
102 static int hf_ecat_mailbox_coe = -1;
103 static int hf_ecat_mailbox_coe_number = -1;
104 static int hf_ecat_mailbox_coe_type = -1;
105 static int hf_ecat_mailbox_coe_sdoreq = -1;
106 static int hf_ecat_mailbox_coe_sdoccsid = -1;
107 static int hf_ecat_mailbox_coe_sdoccsid_sizeind = -1;
108 static int hf_ecat_mailbox_coe_sdoccsid_expedited = -1;
109 static int hf_ecat_mailbox_coe_sdoccsid_size0= -1;
110 static int hf_ecat_mailbox_coe_sdoccsid_size1= -1;
111 static int hf_ecat_mailbox_coe_sdoccsid_complete = -1;
112 static int hf_ecat_mailbox_coe_sdoccsds = -1;
113 static int hf_ecat_mailbox_coe_sdoccsds_lastseg = -1;
114 static int hf_ecat_mailbox_coe_sdoccsds_size = -1;
115 static int hf_ecat_mailbox_coe_sdoccsds_toggle = -1;
116 static int hf_ecat_mailbox_coe_sdoccsus = -1;
117 static int hf_ecat_mailbox_coe_sdoccsus_toggle = -1;
118 static int hf_ecat_mailbox_coe_sdoccsiu = -1;
119 static int hf_ecat_mailbox_coe_sdoccsiu_complete = -1;
120 static int hf_ecat_mailbox_coe_sdoidx = -1;
121 static int hf_ecat_mailbox_coe_sdosub = -1;
122 static int hf_ecat_mailbox_coe_sdodata = -1;
123 static int hf_ecat_mailbox_coe_sdodata1 = -1;
124 static int hf_ecat_mailbox_coe_sdodata2 = -1;
125 static int hf_ecat_mailbox_coe_sdoldata = -1;
126 static int hf_ecat_mailbox_coe_sdolength = -1;
127 static int hf_ecat_mailbox_coe_sdoerror = -1;
128 static int hf_ecat_mailbox_coe_sdores = -1;
129 static int hf_ecat_mailbox_coe_sdoscsds = -1;
130 static int hf_ecat_mailbox_coe_sdoscsds_toggle = -1;
131 static int hf_ecat_mailbox_coe_sdoscsiu = -1;
132 static int hf_ecat_mailbox_coe_sdoscsiu_sizeind = -1;
133 static int hf_ecat_mailbox_coe_sdoscsiu_expedited = -1;
134 static int hf_ecat_mailbox_coe_sdoscsiu_size0 = -1;
135 static int hf_ecat_mailbox_coe_sdoscsiu_size1 = -1;
136 static int hf_ecat_mailbox_coe_sdoscsiu_complete = -1;
137 static int hf_ecat_mailbox_coe_sdoscsus = -1;
138 static int hf_ecat_mailbox_coe_sdoscsus_lastseg = -1;
139 static int hf_ecat_mailbox_coe_sdoscsus_bytes = -1;
140 static int hf_ecat_mailbox_coe_sdoscsus_toggle = -1;
141 static int hf_ecat_mailbox_coe_sdoinfoopcode = -1;
142 static int hf_ecat_mailbox_coe_sdoinfofrag = -1;
143 static int hf_ecat_mailbox_coe_sdoinfolisttype = -1;
144 static int hf_ecat_mailbox_coe_sdoinfolist = -1;
145 static int hf_ecat_mailbox_coe_sdoinfoindex = -1;
146 static int hf_ecat_mailbox_coe_sdoinfosubindex = -1;
147 static int hf_ecat_mailbox_coe_sdoinfovalueinfo = -1;
148 static int hf_ecat_mailbox_coe_sdoinfoerrorcode = -1;
149 static int hf_ecat_mailbox_coe_sdoinfodatatype = -1;
150 static int hf_ecat_mailbox_coe_sdoinfomaxsub = -1;
151 static int hf_ecat_mailbox_coe_sdoinfoobjcode = -1;
152 static int hf_ecat_mailbox_coe_sdoinfoname = -1;
153 static int hf_ecat_mailbox_coe_sdoinfobitlen = -1;
154 static int hf_ecat_mailbox_coe_sdoinfoobjaccess = -1;
155 static int hf_ecat_mailbox_coe_sdoinfounittype = -1;
156 static int hf_ecat_mailbox_coe_sdoinfodefaultvalue = -1;
157 static int hf_ecat_mailbox_coe_sdoinfominvalue = -1;
158 static int hf_ecat_mailbox_coe_sdoinfomaxvalue = -1;
159 static int hf_ecat_mailboxdata = -1;
160 static int hf_ecat_mailbox_foe = -1;
161 static int hf_ecat_mailbox_foe_opmode = -1;
162 static int hf_ecat_mailbox_foe_filelength = -1;
163 static int hf_ecat_mailbox_foe_filename = -1;
164 static int hf_ecat_mailbox_foe_packetno = -1;
165 static int hf_ecat_mailbox_foe_errcode = -1;
166 static int hf_ecat_mailbox_foe_errtext = -1;
167 static int hf_ecat_mailbox_foe_busydone = -1;
168 static int hf_ecat_mailbox_foe_busyentire = -1;
169 static int hf_ecat_mailbox_foe_data = -1;
170 static int hf_ecat_mailbox_foe_efw = -1;
171 static int hf_ecat_mailbox_foe_efw_cmd = -1;
172 static int hf_ecat_mailbox_foe_efw_size = -1;
173 static int hf_ecat_mailbox_foe_efw_addresslw = -1;
174 static int hf_ecat_mailbox_foe_efw_addresshw = -1;
175 static int hf_ecat_mailbox_foe_efw_data = -1;
176 static int hf_ecat_mailbox_soe = -1;
177 static int hf_ecat_mailbox_soe_header = -1;
178
179 static int hf_ecat_mailbox_soe_header_opcode = -1;
180 static int hf_ecat_mailbox_soe_header_incomplete = -1;
181 static int hf_ecat_mailbox_soe_header_error = -1;
182 static int hf_ecat_mailbox_soe_header_driveno = -1;
183 static int hf_ecat_mailbox_soe_header_datastate = -1;
184 static int hf_ecat_mailbox_soe_header_name = -1;
185 static int hf_ecat_mailbox_soe_header_attribute = -1;
186 static int hf_ecat_mailbox_soe_header_unit = -1;
187 static int hf_ecat_mailbox_soe_header_min = -1;
188 static int hf_ecat_mailbox_soe_header_max = -1;
189 static int hf_ecat_mailbox_soe_header_value = -1;
190 static int hf_ecat_mailbox_soe_header_reserved = -1;
191 static int hf_ecat_mailbox_soe_idn = -1;
192 static int hf_ecat_mailbox_soe_data = -1;
193 static int hf_ecat_mailbox_soe_frag = -1;
194 static int hf_ecat_mailbox_soe_error = -1;
195
196 static const value_string EcMBoxType[] =
197 {
198    {   0, "Invalid", },
199    {   1, "AoE (Vendor specific; Beckhoff ADS over EtherCAT)", },
200    {   2, "EoE (Ethernet over EtherCAT)", },
201    {   3, "CoE (CANopen over EtherCAT)", },
202    {   4, "FoE (File access over EtherCAT)", },
203    {   5, "SoE (Servo profile over EtherCAT)", },
204    {  15, "VoE (Vendor specific over EtherCAT)"},
205    {   0x80+1, "AoE - Err", },
206    {   0x80+2, "EoE - Err", },
207    {   0x80+3, "CoE - Err", },
208    {   0x80+4, "FoE - Err", },
209    {   0x80+5, "SoE - Err", },
210    {   0, NULL }
211 };
212
213 static const value_string FoEOpMode[] =
214 {
215    {   1, "RRQ", },
216    {   2, "WRQ", },
217    {   3, "DATA", },
218    {   4, "ACK", },
219    {   5, "ERROR", },
220    {   6, "BUSY", },
221    {   0,  NULL }
222 };
223
224 static const value_string FoEEfwCmd[] =
225 {
226    {   1, "Memory Transfer", },
227    {   2, "Write Code", },
228    {   3, "Check device id", },
229    {   4, "Checksum", },
230    {   5, "Write code checksum", },
231    {   6, "Set device id", },
232    {   8, "Set code id", },
233    {   9, "NOP", },
234    {  10, "Checksum checksum", },
235    {  11, "boot checksum", },
236    { 0, NULL }
237 };
238
239 static const value_string SoeOpcode[] =
240 {
241    {   0, "unused" },
242    {   1, "readReq" },
243    {   2, "readRes"},
244    {   3, "writeReq"},
245    {   4, "writeRes" },
246    {   5, "notification" },
247    {   6, "emergency"},
248    {   0, NULL }
249 };
250
251 static const true_false_string tfs_complete =
252 {
253    "Complete", "Legacy"
254 };
255
256 void init_mbx_header(PETHERCAT_MBOX_HEADER pMbox, tvbuff_t *tvb, gint offset)
257 {
258    pMbox->Length = tvb_get_letohs(tvb, offset); offset+=sizeof(guint16);
259    pMbox->Address = tvb_get_letohs(tvb, offset); offset+=sizeof(guint16);
260    pMbox->aControlUnion.Control = tvb_get_letohs(tvb, offset);
261 }
262
263 void init_eoe_header(PETHERCAT_EOE_HEADER pEoE, tvbuff_t *tvb, gint offset)
264 {
265    pEoE->anEoeHeaderInfoUnion.Info = tvb_get_letohs(tvb, offset); offset+=sizeof(guint16);
266    pEoE->anEoeHeaderDataUnion.Result = tvb_get_letohs(tvb, offset);
267 }
268
269 void init_foe_header(PETHERCAT_FOE_HEADER pFoE, tvbuff_t *tvb, gint offset)
270 {
271    pFoE->OpMode = tvb_get_guint8(tvb, offset++);
272    pFoE->Reserved1 = tvb_get_guint8(tvb, offset++);
273    pFoE->aFoeHeaderDataUnion.FileLength = tvb_get_letohl(tvb, offset);
274 }
275
276 void init_soe_header(PETHERCAT_SOE_HEADER pSoE, tvbuff_t *tvb, gint offset)
277 {
278    pSoE->anSoeHeaderControlUnion.v2.Control = tvb_get_guint8(tvb, offset++);
279    pSoE->anSoeHeaderControlUnion.v2.Element = tvb_get_guint8(tvb, offset++);
280    pSoE->anSoeHeaderDataUnion.FragmentsLeft = tvb_get_letohs(tvb, offset);
281 }
282
283 void init_coe_header(PETHERCAT_COE_HEADER pCoE, tvbuff_t *tvb, gint offset)
284 {
285    pCoE->header = tvb_get_letohs(tvb, offset);
286 }
287
288 void init_sdo_header(PETHERCAT_SDO_HEADER pSdo, tvbuff_t *tvb, gint offset)
289 {
290    pSdo->anSdoHeaderUnion.CS = tvb_get_guint8(tvb, offset++);
291    pSdo->Index = tvb_get_letohs(tvb, offset);offset+=sizeof(guint16);
292    pSdo->SubIndex = tvb_get_guint8(tvb, offset++);
293    pSdo->Data = tvb_get_letohl(tvb, offset);
294 }
295
296 void init_sdo_info_header(PETHERCAT_SDO_INFO_HEADER pInfo, tvbuff_t *tvb, gint offset)
297 {
298    pInfo->anSdoControlUnion.Control = tvb_get_guint8(tvb, offset++);
299    pInfo->Reserved = tvb_get_guint8(tvb, offset++);
300    pInfo->FragmentsLeft = sizeof(guint16);
301 }
302
303
304 static void MailboxTypeFormatter(PETHERCAT_MBOX_HEADER pMbx, char *szText, gint nMax)
305 {
306    guint32 i;
307
308    for(i = 0; i<sizeof(EcMBoxType)/sizeof(value_string); i++ )
309    {
310       if( EcMBoxType[i].value == pMbx->aControlUnion.v.Type )
311       {
312          g_snprintf(szText, nMax, "Type    : %s (0x%x)", EcMBoxType[i].strptr, pMbx->aControlUnion.v.Type);
313          return;
314       }
315    }
316    g_snprintf ( szText, nMax,"Type    : %d", pMbx->aControlUnion.v.Type);
317 }
318
319 static void EoETypeFormatter(PETHERCAT_EOE_HEADER pEoE, char *szText, gint nMax)
320 {
321    switch (pEoE->anEoeHeaderInfoUnion.v.Type)
322    {
323    case EOE_TYPE_FRAME_FRAG:
324       g_snprintf ( szText, nMax, "Type(%d)    : Fragment", pEoE->anEoeHeaderInfoUnion.v.Type);
325       break;
326    case EOE_TYPE_TIMESTAMP_RES:
327       g_snprintf ( szText, nMax, "Type(%d)    : TimeStamp", pEoE->anEoeHeaderInfoUnion.v.Type);
328       break;
329    case EOE_TYPE_INIT_REQ:
330       g_snprintf ( szText, nMax, "Type(%d)    : Init Req", pEoE->anEoeHeaderInfoUnion.v.Type);
331       break;
332    case EOE_TYPE_INIT_RES:
333       g_snprintf ( szText, nMax, "Type(%d)    : Init Res", pEoE->anEoeHeaderInfoUnion.v.Type);
334       break;
335    case EOE_TYPE_MACFILTER_REQ:
336       g_snprintf ( szText, nMax, "Type(%d)    : MAC Req", pEoE->anEoeHeaderInfoUnion.v.Type);
337       break;
338    case EOE_TYPE_MACFILTER_RES:
339       g_snprintf ( szText, nMax, "Type(%d)    : MAC Res", pEoE->anEoeHeaderInfoUnion.v.Type);
340       break;
341    default:
342       g_snprintf ( szText, nMax, "Type(%d)    : Unknown", pEoE->anEoeHeaderInfoUnion.v.Type);
343       break;
344    }
345 }
346
347 static void EoEFragNoFormatter(PETHERCAT_EOE_HEADER pEoE, char *szText, gint nMax)
348 {
349    g_snprintf ( szText, nMax, "FragNo     : %d", pEoE->anEoeHeaderDataUnion.v.Fragment);
350 }
351
352 static void EoEOffsetFormatter(PETHERCAT_EOE_HEADER pEoE, char *szText, gint nMax)
353 {
354    if ( pEoE->anEoeHeaderDataUnion.v.Fragment == 0 )
355       g_snprintf ( szText, nMax, "BufferSize : %d", 32*pEoE->anEoeHeaderDataUnion.v.OffsetBuffer);
356    else
357       g_snprintf ( szText, nMax, "Offset     : %d", 32*pEoE->anEoeHeaderDataUnion.v.OffsetBuffer);
358 }
359
360 static void EoEFrameFormatter(PETHERCAT_EOE_HEADER pEoE, char *szText, gint nMax)
361 {
362    g_snprintf ( szText, nMax, "FrameNo    : %d", pEoE->anEoeHeaderDataUnion.v.FrameNo);
363 }
364
365 static void EoELastFormatter(PETHERCAT_EOE_HEADER pEoE, char *szText, gint nMax)
366 {
367    if ( pEoE->anEoeHeaderInfoUnion.v.LastFragment != 0 )
368       g_snprintf ( szText, nMax, "Last Frag");
369    else
370       g_snprintf ( szText, nMax, "More Frags...");
371 }
372
373 static void CANopenNumberFormatter(PETHERCAT_COE_HEADER pCoE, char *szText, gint nMax)
374 {
375    g_snprintf( szText, nMax, "Number  : %d", pCoE->v.Number);
376 }
377
378 static void CANopenTypeFormatter(PETHERCAT_COE_HEADER pCoE, char *szText, gint nMax)
379 {
380    switch ( pCoE->v.Type)
381    {
382    case ETHERCAT_COE_TYPE_EMERGENCY:
383       g_snprintf ( szText, nMax, "Type    : EMERGENCY(%d)", pCoE->v.Type);
384       break;
385    case ETHERCAT_COE_TYPE_SDOREQ:
386       g_snprintf ( szText, nMax, "Type    : SDO Req(%d)", pCoE->v.Type);
387       break;
388    case ETHERCAT_COE_TYPE_SDORES:
389       g_snprintf ( szText, nMax, "Type    : SDO Res(%d)", pCoE->v.Type);
390       break;
391    case ETHERCAT_COE_TYPE_TXPDO:
392       g_snprintf ( szText, nMax, "Type    : TxPDO(%d)", pCoE->v.Type);
393       break;
394    case ETHERCAT_COE_TYPE_RXPDO:
395       g_snprintf ( szText, nMax, "Type    : RxPDO(%d)", pCoE->v.Type);
396       break;
397    case ETHERCAT_COE_TYPE_TXPDO_RTR:
398       g_snprintf ( szText, nMax, "Type    : TxPDO_RTR(%d)", pCoE->v.Type);
399       break;
400    case ETHERCAT_COE_TYPE_RXPDO_RTR:
401       g_snprintf ( szText, nMax, "Type    : RxPDO_RTR(%d)", pCoE->v.Type);
402       break;
403    default:
404       g_snprintf ( szText, nMax, "Type    :%d", pCoE->v.Type);
405    }
406 }
407
408 static void CANopenSdoReqFormatter(PETHERCAT_SDO_HEADER pSdo, char *szText, gint nMax)
409 {
410    switch ( pSdo->anSdoHeaderUnion.Idq.Ccs )
411    {
412    case SDO_CCS_INITIATE_DOWNLOAD:
413       g_snprintf ( szText, nMax, "SDO Req : 'Initiate Download' (%d) Idx=0x%x Sub=%d", pSdo->anSdoHeaderUnion.Idq.Ccs, pSdo->Index,  pSdo->SubIndex);
414       break;
415    case SDO_CCS_INITIATE_UPLOAD:
416       g_snprintf ( szText, nMax, "SDO Req : 'Initiate Upload' (%d) Idx=0x%x Sub=%d", pSdo->anSdoHeaderUnion.Idq.Ccs, pSdo->Index,  pSdo->SubIndex);
417       break;
418    case SDO_CCS_DOWNLOAD_SEGMENT:
419       g_snprintf ( szText, nMax, "SDO Req : 'Download Segment' (%d)", pSdo->anSdoHeaderUnion.Idq.Ccs);
420       break;
421    case SDO_CCS_UPLOAD_SEGMENT:
422       g_snprintf ( szText, nMax, "SDO Req : 'Upload Segment' (%d)", pSdo->anSdoHeaderUnion.Idq.Ccs);
423       break;
424    case SDO_CCS_ABORT_TRANSFER:
425       g_snprintf ( szText, nMax, "SDO Req : 'Abort Transfer' (%d)", pSdo->anSdoHeaderUnion.Idq.Ccs);
426       break;
427    default:
428       g_snprintf ( szText, nMax, "SDO Req : Ccs %d", pSdo->anSdoHeaderUnion.Idq.Ccs);
429    }
430 }
431
432 static void CANopenSdoResFormatter(PETHERCAT_SDO_HEADER pSdo, char *szText, gint nMax)
433 {
434    g_snprintf ( szText, nMax, "SDO Res : Scs %d", pSdo->anSdoHeaderUnion.Ids.Scs);
435 }
436
437 static void CANopenSdoInfoFormatter(PETHERCAT_SDO_INFO_HEADER pHead, char *szText, gint nMax)
438 {
439    guint8 opCode = pHead->anSdoControlUnion.v.OpCode & 0x7F;
440    char* txt2 = "";
441    if ( (pHead->anSdoControlUnion.v.OpCode & 0x80) != 0 )
442       txt2 = " - More Follows";
443    switch (opCode)
444    {
445    case ECAT_COE_INFO_OPCODE_LIST_Q:
446       g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'List Req' %s", txt2);
447       break;
448    case ECAT_COE_INFO_OPCODE_LIST_S:
449       g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'List Res' %s", txt2);
450       break;
451    case ECAT_COE_INFO_OPCODE_OBJ_Q:
452       g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'Obj Req' %s", txt2);
453       break;
454    case ECAT_COE_INFO_OPCODE_OBJ_S:
455       g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'Obj Res' %s", txt2);
456       break;
457    case ECAT_COE_INFO_OPCODE_ENTRY_Q:
458       g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'Entry Req' %s", txt2);
459       break;
460    case ECAT_COE_INFO_OPCODE_ENTRY_S:
461       g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'Entry Res' %s", txt2);
462       break;
463    case ECAT_COE_INFO_OPCODE_ERROR_S:
464       g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'Error Res' %s", txt2);
465       break;
466    default:
467       g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: %d %s", opCode, txt2);
468    }
469 }
470
471 static void FoeFormatter(tvbuff_t *tvb, gint offset, char *szText, gint nMax, guint foe_length)
472 {
473    ETHERCAT_FOE_HEADER foe;
474    char tmp[50];
475    memset(tmp, 0, sizeof(tmp));
476
477    init_foe_header(&foe, tvb, offset);
478
479    switch ( foe.OpMode )
480    {
481    case ECAT_FOE_OPMODE_RRQ:
482    case ECAT_FOE_OPMODE_WRQ:
483    case ECAT_FOE_OPMODE_ERR:
484       if ( foe_length > ETHERCAT_FOE_HEADER_LEN )
485          tvb_memcpy(tvb, tmp, offset+ETHERCAT_FOE_HEADER_LEN, MIN(foe_length-ETHERCAT_FOE_HEADER_LEN, sizeof(tmp)-1));
486       break;
487    }
488
489    switch ( foe.OpMode )
490    {
491    case ECAT_FOE_OPMODE_RRQ:
492       g_snprintf ( szText, nMax, "FoE RRQ (%d) : '%s'", foe.aFoeHeaderDataUnion.FileLength, tmp);
493       break;
494    case ECAT_FOE_OPMODE_WRQ:
495       g_snprintf ( szText, nMax, "FoE WRQ (%d) : '%s'", foe.aFoeHeaderDataUnion.FileLength, tmp);
496       break;
497    case ECAT_FOE_OPMODE_DATA:
498       g_snprintf ( szText, nMax, "FoE DATA (%d) : %d Bytes", foe.aFoeHeaderDataUnion.v.PacketNo, foe_length-ETHERCAT_FOE_HEADER_LEN);
499       break;
500    case ECAT_FOE_OPMODE_ACK:
501       g_snprintf ( szText, nMax, "FoE ACK (%d)", foe.aFoeHeaderDataUnion.v.PacketNo);
502       break;
503    case ECAT_FOE_OPMODE_ERR:
504       g_snprintf ( szText, nMax, "FoE ERR (%d) : '%s'", foe.aFoeHeaderDataUnion.ErrorCode, tmp);
505       break;
506    case ECAT_FOE_OPMODE_BUSY:
507       if ( foe.aFoeHeaderDataUnion.v2.Entire > 0 )
508          g_snprintf ( szText, nMax, "FoE BUSY (%d%%)", ((guint32)foe.aFoeHeaderDataUnion.v2.Done*100)/foe.aFoeHeaderDataUnion.v2.Entire);
509       else
510          g_snprintf ( szText, nMax, "FoE BUSY (%d/%d)", foe.aFoeHeaderDataUnion.v2.Done, foe.aFoeHeaderDataUnion.v2.Entire);
511       break;
512    }
513 }
514
515 static void SoEIdToString( char* txt, guint16 id, int nMax)
516 {
517    if ( id & 0x8000 )
518       g_snprintf(txt, nMax, "P-%d-%04d", (id>>12) & 0x0007, id & 0x0FFF );
519    else
520       g_snprintf(txt, nMax, "S-%d-%04d", id>>12, id & 0x0FFF );
521 }
522
523 static void SoeFormatter(tvbuff_t *tvb, gint offset, char *szText, gint nMax, guint soe_length)
524 {
525    ETHERCAT_SOE_HEADER soe;
526    char tmp[50];
527    char elm[50];
528    memset(tmp, 0, sizeof(tmp));
529
530    init_soe_header(&soe, tvb, offset);
531    offset+=ETHERCAT_SOE_HEADER_LEN;
532
533    if ( !soe.anSoeHeaderControlUnion.v.Error )
534    {
535       if ( !soe.anSoeHeaderControlUnion.v.InComplete )
536       {
537          SoEIdToString(tmp, soe.anSoeHeaderDataUnion.IDN, sizeof(tmp)-1);
538          elm[0] = '\0';
539          if ( soe.anSoeHeaderControlUnion.v.DataState )
540             g_strlcat(elm, "D", 50);
541          if ( soe.anSoeHeaderControlUnion.v.Name )
542             g_strlcat(elm, "N", 50);
543          if ( soe.anSoeHeaderControlUnion.v.Attribute )
544             g_strlcat(elm, "A", 50);
545          if ( soe.anSoeHeaderControlUnion.v.Unit )
546             g_strlcat(elm, "U", 50);
547          if ( soe.anSoeHeaderControlUnion.v.Min )
548             g_strlcat(elm, "I", 50);
549          if ( soe.anSoeHeaderControlUnion.v.Max )
550             g_strlcat(elm, "X", 50);
551          if ( soe.anSoeHeaderControlUnion.v.Value )
552             g_strlcat(elm, "V", 50);
553          switch ( soe.anSoeHeaderControlUnion.v.OpCode )
554          {
555          case ECAT_SOE_OPCODE_RRQ:
556             g_snprintf ( szText, nMax, "SoE: RRQ (%s, '%s')", tmp, elm);
557             break;
558          case ECAT_SOE_OPCODE_RRS:
559             g_snprintf ( szText, nMax, "SoE: RRS (%s, '%s') : %u Bytes", tmp, elm, (guint)(soe_length-ETHERCAT_SOE_HEADER_LEN));
560             break;
561          case ECAT_SOE_OPCODE_WRS:
562             g_snprintf ( szText, nMax, "SoE: WRS (%s, '%s')", tmp, elm);
563             break;
564          case ECAT_SOE_OPCODE_WRQ:
565             g_snprintf ( szText, nMax, "SoE: WRQ (%s, '%s') : %u Bytes", tmp, elm, (guint)(soe_length-ETHERCAT_SOE_HEADER_LEN));
566             break;
567          case ECAT_SOE_OPCODE_NFC:
568             g_snprintf ( szText, nMax, "SoE: NFC (%s, '%s') : %u Bytes", tmp, elm, (guint)(soe_length-ETHERCAT_SOE_HEADER_LEN));
569             break;
570          case 6:
571             g_snprintf ( szText, nMax, "SoE: EMGCY");
572                         break;
573          default:
574             g_snprintf ( szText, nMax, "SoE:");
575          }
576       }
577       else
578          g_snprintf ( szText, nMax, "SoE: FragmentsLeft %d", soe.anSoeHeaderDataUnion.FragmentsLeft);
579    }
580    else
581       g_snprintf ( szText, nMax, "SoE: Error %04x", tvb_get_letohs(tvb, offset));
582 }
583
584 /* ethercat mailbox */
585 static void dissect_ecat_coe(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *tree)
586 {
587    proto_tree *ecat_coe_tree = NULL, *ecat_sdo_tree, *ecat_coe_sdoccs_tree, *ecat_coe_sdoscs_tree;
588
589    proto_item *anItem = NULL, *aparent = NULL;
590    char szText[200];
591    int nMax = sizeof(szText)-1;
592
593    guint coe_length = tvb_reported_length(tvb)-offset;
594    guint16 len;
595
596    if( tree )
597    {
598       anItem = proto_tree_add_item(tree, hf_ecat_mailbox_coe, tvb, offset, coe_length, TRUE);
599       proto_item_set_text(anItem,"CoE");
600       aparent = proto_item_get_parent(anItem);
601       proto_item_append_text(aparent,":CoE ");
602    }
603
604    col_append_str(pinfo->cinfo, COL_INFO, "CoE ");
605
606    if( coe_length >= ETHERCAT_COE_HEADER_LEN )
607    {
608       ETHERCAT_COE_HEADER coe;
609       init_coe_header(&coe, tvb, offset);
610       if( tree )
611       {
612          ecat_coe_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_coe);
613
614          CANopenNumberFormatter(&coe, szText, nMax);
615          anItem = proto_tree_add_uint(ecat_coe_tree, hf_ecat_mailbox_coe_number, tvb, offset, ETHERCAT_COE_HEADER_LEN, coe.v.Number);
616          proto_item_set_text(anItem, "%s", szText);
617
618          CANopenTypeFormatter(&coe, szText, nMax);
619          anItem = proto_tree_add_uint(ecat_coe_tree, hf_ecat_mailbox_coe_type, tvb, offset, ETHERCAT_COE_HEADER_LEN, coe.v.Type);
620          proto_item_set_text(anItem, "%s", szText);
621       }
622
623       offset += ETHERCAT_COE_HEADER_LEN;
624
625       switch (coe.v.Type)
626       {
627       case ETHERCAT_COE_TYPE_SDOREQ:
628          {
629             ETHERCAT_SDO_HEADER sdo;
630
631             if( coe_length < ETHERCAT_COE_HEADER_LEN + ETHERCAT_SDO_HEADER_LEN )
632             {
633                col_append_str(pinfo->cinfo, COL_INFO, "Sdo Req - invalid length");
634                break;
635             }
636
637             init_sdo_header(&sdo, tvb, offset);
638
639             CANopenSdoReqFormatter(&sdo, szText, nMax);
640              col_append_str(pinfo->cinfo, COL_INFO, szText);
641
642             if( tree )
643             {
644                proto_item_append_text(aparent, "%s", szText);
645
646                anItem = proto_tree_add_uint(ecat_coe_tree, hf_ecat_mailbox_coe_sdoreq, tvb, offset, 1, sdo.anSdoHeaderUnion.Idq.Ccs);
647                proto_item_set_text(anItem, "%s", szText);
648                ecat_sdo_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_sdo);
649
650                switch ( sdo.anSdoHeaderUnion.Idq.Ccs )
651                {
652                case SDO_CCS_INITIATE_DOWNLOAD:
653                   anItem = proto_tree_add_item(ecat_sdo_tree, hf_ecat_mailbox_coe_sdoccsid, tvb, offset, 1, TRUE);
654                   ecat_coe_sdoccs_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_coe_sdoccs);
655                   proto_tree_add_item(ecat_coe_sdoccs_tree, hf_ecat_mailbox_coe_sdoccsid_sizeind, tvb, offset, 1, TRUE);
656                   proto_tree_add_item(ecat_coe_sdoccs_tree, hf_ecat_mailbox_coe_sdoccsid_expedited, tvb, offset, 1, TRUE);
657                   proto_tree_add_item(ecat_coe_sdoccs_tree, hf_ecat_mailbox_coe_sdoccsid_size0, tvb, offset, 1, TRUE);
658                   proto_tree_add_item(ecat_coe_sdoccs_tree, hf_ecat_mailbox_coe_sdoccsid_size1, tvb, offset, 1, TRUE);
659                   proto_tree_add_item(ecat_coe_sdoccs_tree, hf_ecat_mailbox_coe_sdoccsid_complete, tvb, offset, 1, TRUE);
660
661                   proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoidx, tvb, offset+1, 2, TRUE);
662                   proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdosub, tvb, offset+3, 1, TRUE);
663                   if ( sdo.anSdoHeaderUnion.Idq.SizeInd && !sdo.anSdoHeaderUnion.Idq.Expedited )
664                   {
665                      len = coe_length - ETHERCAT_COE_HEADER_LEN - ETHERCAT_SDO_HEADER_LEN;
666                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdolength, tvb, offset+4, 4, TRUE);
667                      offset+=ETHERCAT_SDO_HEADER_LEN;
668                      if ( len > 0 )
669                         proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoldata, tvb, offset, len, TRUE);
670                   }
671                   else
672                   {
673                      if ( sdo.anSdoHeaderUnion.Idq.Size == 3 )
674                         proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdodata1, tvb, offset+4, 1, TRUE);
675                      else if ( sdo.anSdoHeaderUnion.Idq.Size == 2 )
676                         proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdodata2, tvb, offset+4, 2, TRUE);
677                      else
678                         proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdodata, tvb, offset+4, 4, TRUE);
679                   }
680                   break;
681                case SDO_CCS_INITIATE_UPLOAD:
682                   anItem = proto_tree_add_item(ecat_sdo_tree, hf_ecat_mailbox_coe_sdoccsiu, tvb, offset, 1, TRUE);
683                   ecat_coe_sdoccs_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_coe_sdoccs);
684                   proto_tree_add_item(ecat_coe_sdoccs_tree, hf_ecat_mailbox_coe_sdoccsid_complete, tvb, offset, 1, TRUE);
685
686                   proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoidx, tvb, offset+1, 2, TRUE);
687                   proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdosub, tvb, offset+3, 1, TRUE);
688
689                   break;
690                case SDO_CCS_DOWNLOAD_SEGMENT:
691                   anItem = proto_tree_add_item(ecat_sdo_tree, hf_ecat_mailbox_coe_sdoccsds, tvb, offset, 1, TRUE);
692                   ecat_coe_sdoccs_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_coe_sdoccs);
693                   proto_tree_add_item(ecat_coe_sdoccs_tree, hf_ecat_mailbox_coe_sdoccsds_lastseg, tvb, offset, 1, TRUE);
694                   proto_tree_add_item(ecat_coe_sdoccs_tree, hf_ecat_mailbox_coe_sdoccsds_size, tvb, offset, 1, TRUE);
695                   proto_tree_add_item(ecat_coe_sdoccs_tree, hf_ecat_mailbox_coe_sdoccsds_toggle, tvb, offset, 1, TRUE);
696                   offset+=1;
697
698                   if ( coe_length-offset > 0 )
699                   {
700                      anItem = proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoldata, tvb, offset, coe_length-offset, TRUE);
701                      proto_item_append_text(anItem, "(len = %d)", coe_length-offset);
702                   }
703                   break;
704                case SDO_CCS_UPLOAD_SEGMENT:
705                   anItem = proto_tree_add_item(ecat_sdo_tree, hf_ecat_mailbox_coe_sdoccsus, tvb, offset, 1, TRUE);
706                   ecat_coe_sdoccs_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_coe_sdoccs);
707                   proto_tree_add_item(ecat_coe_sdoccs_tree, hf_ecat_mailbox_coe_sdoccsus_toggle, tvb, offset, 1, TRUE);
708                   break;
709                case SDO_CCS_ABORT_TRANSFER:
710                   proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoidx, tvb, offset+4, 4, TRUE);
711                   break;
712                }
713             }
714          }
715          break;
716
717       case ETHERCAT_COE_TYPE_SDORES:
718          {
719             ETHERCAT_SDO_HEADER sdo;
720             if( coe_length < ETHERCAT_COE_HEADER_LEN + ETHERCAT_SDO_HEADER_LEN )
721             {
722                col_append_str(pinfo->cinfo, COL_INFO, "Sdo Res - invalid length");
723                break;
724             }
725
726             init_sdo_header(&sdo, tvb, offset);
727
728             CANopenSdoResFormatter(&sdo, szText, nMax);
729             col_append_str(pinfo->cinfo, COL_INFO, szText);
730
731             if( tree )
732             {
733                anItem = proto_tree_add_uint(ecat_coe_tree, hf_ecat_mailbox_coe_sdores, tvb, offset, 1, sdo.anSdoHeaderUnion.Ids.Scs);
734                proto_item_set_text(anItem, "%s", szText);
735                ecat_sdo_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_sdo);
736
737                switch ( sdo.anSdoHeaderUnion.Ids.Scs )
738                {
739                case SDO_SCS_INITIATE_DOWNLOAD:
740                   proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoidx, tvb, offset+1, 2, TRUE);
741                   proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdosub, tvb, offset+3, 1, TRUE);
742                   break;
743                case SDO_SCS_INITIATE_UPLOAD:
744                   anItem = proto_tree_add_item(ecat_sdo_tree, hf_ecat_mailbox_coe_sdoscsiu, tvb, offset, 1, TRUE);
745                   ecat_coe_sdoscs_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_coe_sdoscs);
746                   proto_tree_add_item(ecat_coe_sdoscs_tree, hf_ecat_mailbox_coe_sdoscsiu_sizeind, tvb, offset, 1, TRUE);
747                   proto_tree_add_item(ecat_coe_sdoscs_tree, hf_ecat_mailbox_coe_sdoscsiu_expedited, tvb, offset, 1, TRUE);
748                   proto_tree_add_item(ecat_coe_sdoscs_tree, hf_ecat_mailbox_coe_sdoscsiu_size0, tvb, offset, 1, TRUE);
749                   proto_tree_add_item(ecat_coe_sdoscs_tree, hf_ecat_mailbox_coe_sdoscsiu_size1, tvb, offset, 1, TRUE);
750                   proto_tree_add_item(ecat_coe_sdoscs_tree, hf_ecat_mailbox_coe_sdoscsiu_complete, tvb, offset, 1, TRUE);
751
752                   proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoidx, tvb, offset+1, 2, TRUE);
753                   proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdosub, tvb, offset+3, 1, TRUE);
754                   if ( sdo.anSdoHeaderUnion.Ius.SizeInd && !sdo.anSdoHeaderUnion.Ius.Expedited )
755                   {
756                      len = coe_length - ETHERCAT_COE_HEADER_LEN - ETHERCAT_SDO_HEADER_LEN;
757                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdolength, tvb, offset+4, 4, TRUE);
758                      offset+=ETHERCAT_SDO_HEADER_LEN;
759                      if ( len > 0 )
760                         proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoldata, tvb, offset, len, TRUE);
761                   }
762                   else if ( sdo.anSdoHeaderUnion.Ius.SizeInd && sdo.anSdoHeaderUnion.Ius.Expedited && sdo.anSdoHeaderUnion.Ius.Size == 3 )
763                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdodata1, tvb, offset+4, 1, TRUE);
764                   else if ( sdo.anSdoHeaderUnion.Ius.SizeInd && sdo.anSdoHeaderUnion.Ius.Expedited && sdo.anSdoHeaderUnion.Ius.Size == 2 )
765                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdodata2, tvb, offset+4, 2, TRUE);
766                   else
767                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdodata, tvb, offset+4, 4, TRUE);
768                   break;
769                case SDO_SCS_DOWNLOAD_SEGMENT:
770                   anItem = proto_tree_add_item(ecat_sdo_tree, hf_ecat_mailbox_coe_sdoscsds, tvb, offset, 1, TRUE);
771                   ecat_coe_sdoscs_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_coe_sdoscs);
772                   proto_tree_add_item(ecat_coe_sdoscs_tree, hf_ecat_mailbox_coe_sdoscsds_toggle, tvb, offset, 1, TRUE);
773                   break;
774                case SDO_SCS_UPLOAD_SEGMENT:
775                   anItem = proto_tree_add_item(ecat_sdo_tree, hf_ecat_mailbox_coe_sdoscsus, tvb, offset, 1, TRUE);
776                   ecat_coe_sdoscs_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_coe_sdoscs);
777                   proto_tree_add_item(ecat_coe_sdoscs_tree, hf_ecat_mailbox_coe_sdoscsus_lastseg, tvb, offset, 1, TRUE);
778                   proto_tree_add_item(ecat_coe_sdoscs_tree, hf_ecat_mailbox_coe_sdoscsus_bytes, tvb, offset, 1, TRUE);
779                   proto_tree_add_item(ecat_coe_sdoscs_tree, hf_ecat_mailbox_coe_sdoscsus_toggle, tvb, offset, 1, TRUE);
780                   offset+=1;
781
782                   if ( coe_length-offset> 0 )
783                   {
784                      anItem = proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoldata, tvb, offset, coe_length-offset, TRUE);
785                      proto_item_append_text(anItem, "(len = %d)", coe_length-offset);
786                   }
787                   break;
788                }
789             }
790          }
791          break;
792
793       case ETHERCAT_COE_TYPE_SDOINFO:
794          {
795             ETHERCAT_SDO_INFO_HEADER info;
796
797             if( coe_length < ETHERCAT_COE_HEADER_LEN + ETHERCAT_SDO_INFO_LISTREQ_LEN )
798             {
799                col_append_str(pinfo->cinfo, COL_INFO, "Sdo Info - invalid length");
800                break;
801             }
802
803             init_sdo_info_header(&info, tvb, offset);
804
805             CANopenSdoInfoFormatter(&info, szText, nMax);
806             col_append_str(pinfo->cinfo, COL_INFO, szText);
807
808             if( tree )
809             {
810                proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoopcode, tvb, offset++, 1, TRUE);
811                offset++; /*Reserved*/
812
813                proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfofrag, tvb, offset, 2, TRUE);
814                offset+=2;
815
816                switch ( info.anSdoControlUnion.v.OpCode )
817                {
818                case ECAT_COE_INFO_OPCODE_LIST_Q:
819                   {
820                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfolisttype, tvb, offset, 2, TRUE);
821                   }
822                   break;
823                case ECAT_COE_INFO_OPCODE_LIST_S:
824                   {
825                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfolisttype, tvb, offset, 2, TRUE);
826                      offset+=2;
827
828                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfolist, tvb, offset, coe_length-offset, TRUE);
829                   }
830                   break;
831                case ECAT_COE_INFO_OPCODE_OBJ_Q:
832                   proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoindex, tvb, offset, 2, TRUE);
833                   break;
834                case ECAT_COE_INFO_OPCODE_OBJ_S:
835                   {
836                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoindex, tvb, offset, 2, TRUE);
837                      offset+=2;
838
839                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfodatatype, tvb, offset, 2, TRUE);
840                      offset+=2;
841
842                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfomaxsub, tvb, offset++, 1, TRUE);
843                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoobjcode, tvb, offset++, 1, TRUE);
844
845                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoname, tvb, offset, coe_length-offset, TRUE);
846                   }
847                   break;
848                case ECAT_COE_INFO_OPCODE_ENTRY_Q:
849                   {
850                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoindex, tvb, offset, 2, TRUE);
851                      offset+=2;
852
853                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfosubindex, tvb, offset++, 1, TRUE);
854                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfovalueinfo, tvb, offset, 1, TRUE);
855                   }
856                   break;
857                case ECAT_COE_INFO_OPCODE_ENTRY_S:
858                   {
859                      guint16 objlen;
860
861                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoindex, tvb, offset, 2, TRUE);
862                      offset+=2;
863
864                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfosubindex, tvb, offset++, 1, TRUE);
865                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfovalueinfo, tvb, offset++, 1, TRUE);
866
867                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfodatatype, tvb, offset, 2, TRUE);
868                      offset+=2;
869
870                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfobitlen, tvb, offset, 2, TRUE);
871                      offset+=2;
872
873                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoobjaccess, tvb, offset, 2, TRUE);
874                      offset+=2;
875
876                      if ( (info.anSdoInfoUnion.Entry.ValueInfo & 0x08) != 0 )
877                      {
878                         proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfounittype, tvb, offset, 2, TRUE);
879                         offset+=2;
880                      }
881                      if ( (info.anSdoInfoUnion.Entry.ValueInfo & 0x10) != 0 )
882                      {
883                         objlen = BIT2BYTE(info.anSdoInfoUnion.Entry.Res.BitLen);
884                         proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfodefaultvalue, tvb, offset, objlen, TRUE);
885                         offset+=objlen;
886                      }
887                      if ( (info.anSdoInfoUnion.Entry.ValueInfo & 0x20) != 0 )
888                      {
889                         objlen = BIT2BYTE(info.anSdoInfoUnion.Entry.Res.BitLen);
890                         proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfominvalue, tvb, offset, objlen, TRUE);
891                         offset+=objlen;
892                      }
893                      if ( (info.anSdoInfoUnion.Entry.ValueInfo & 0x40) != 0 )
894                      {
895                         objlen = BIT2BYTE(info.anSdoInfoUnion.Entry.Res.BitLen);
896                         proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfomaxvalue, tvb, offset, objlen, TRUE);
897                         offset+=objlen;
898                      }
899                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoname, tvb, offset, coe_length-offset, TRUE);
900                   }
901                   break;
902                case ECAT_COE_INFO_OPCODE_ERROR_S:
903                   {
904                      proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoerrorcode, tvb, offset, 4, TRUE);
905                   }
906                   break;
907                }
908             }
909          }
910          break;
911       }
912    }
913    else
914    {
915       col_append_str(pinfo->cinfo, COL_INFO, "- invalid length");
916    }
917 }
918
919 static void dissect_ecat_soe(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *tree)
920 {
921    proto_tree *ecat_soeflag_tree, *ecat_soe_tree;
922
923    proto_item *anItem = NULL ,*aparent = NULL;
924    char szText[200];
925    int nMax = sizeof(szText)-1;
926
927    guint soe_length = tvb_reported_length(tvb)-offset;
928
929    if( tree )
930    {
931       anItem = proto_tree_add_item(tree, hf_ecat_mailbox_soe, tvb, offset, soe_length, TRUE);
932
933       aparent = proto_item_get_parent(anItem);
934       proto_item_append_text(aparent,":SoE ");
935    }
936
937    if( soe_length >= ETHERCAT_SOE_HEADER_LEN )
938    {
939       SoeFormatter(tvb, offset, szText, nMax, soe_length);
940       col_append_str(pinfo->cinfo, COL_INFO, szText);
941
942       if( tree )
943       {
944          ETHERCAT_SOE_HEADER soe;
945          init_soe_header(&soe, tvb, offset);
946
947          proto_item_append_text(aparent, "%s", szText);
948          proto_item_set_text(anItem, "%s", szText);
949
950          ecat_soe_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_soe);
951          anItem = proto_tree_add_item(ecat_soe_tree, hf_ecat_mailbox_soe_header, tvb, offset , 2, TRUE);
952
953          ecat_soeflag_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_soeflag);
954          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_opcode, tvb, offset, 2, TRUE);
955          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_incomplete, tvb, offset, 2, TRUE);
956          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_error, tvb, offset, 2, TRUE);
957          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_driveno, tvb, offset, 2, TRUE);
958          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_datastate, tvb, offset, 2, TRUE);
959          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_name, tvb, offset, 2, TRUE);
960          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_attribute, tvb, offset, 2, TRUE);
961          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_unit, tvb, offset, 2, TRUE);
962          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_min, tvb, offset, 2, TRUE);
963          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_max, tvb, offset, 2, TRUE);
964          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_value, tvb, offset, 2, TRUE);
965          proto_tree_add_item(ecat_soeflag_tree, hf_ecat_mailbox_soe_header_reserved, tvb, offset, 2, TRUE);
966          offset+=2;
967
968          if ( !soe.anSoeHeaderControlUnion.v.Error )
969          {
970             if ( !soe.anSoeHeaderControlUnion.v.InComplete )
971             {
972                switch (soe.anSoeHeaderControlUnion.v.OpCode)
973                {
974                case ECAT_SOE_OPCODE_RRQ:
975                case ECAT_SOE_OPCODE_WRS:
976                   proto_tree_add_item(ecat_soe_tree, hf_ecat_mailbox_soe_idn, tvb, offset, 2, TRUE);
977                   break;
978                case ECAT_SOE_OPCODE_RRS:
979                case ECAT_SOE_OPCODE_WRQ:
980                case ECAT_SOE_OPCODE_NFC:
981                   proto_tree_add_item(ecat_soe_tree, hf_ecat_mailbox_soe_idn, tvb, offset, 2, TRUE);
982                   offset+=2;
983                   proto_tree_add_item(tree, hf_ecat_mailbox_soe_data, tvb, offset, soe_length-offset, TRUE);
984                   break;
985                }
986             }
987             else
988             {
989                proto_tree_add_item(ecat_soe_tree, hf_ecat_mailbox_soe_frag, tvb, offset, 2, TRUE);
990                offset+=2;
991
992                proto_tree_add_item(tree, hf_ecat_mailbox_soe_data, tvb, offset, soe_length-offset, TRUE);
993             }
994          }
995          else
996          {
997             proto_tree_add_item(ecat_soe_tree, hf_ecat_mailbox_soe_idn, tvb, offset, 2, TRUE);
998             proto_tree_add_item(tree, hf_ecat_mailbox_soe_error, tvb, offset, 2, TRUE);
999          }
1000       }
1001    }
1002    else
1003    {
1004       col_append_str(pinfo->cinfo, COL_INFO, "SoE - invalid length");
1005    }
1006 }
1007
1008 static void dissect_ecat_eoe(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *tree)
1009 {
1010    proto_tree *ecat_eoe_tree = 0, *ecat_fraghead_tree, *ecat_eoe_init_tree, *ecat_eoe_macfilter_tree,
1011       *ecat_eoe_macfilter_filter_tree;
1012    tvbuff_t *next_tvb;
1013    proto_item *anItem = NULL, *aparent = NULL;
1014    char szText[200];
1015    int nMax = sizeof(szText)-1;
1016    int nCnt;
1017
1018    guint eoe_length = tvb_reported_length(tvb)-offset;
1019
1020    if( tree )
1021    {
1022       anItem = proto_tree_add_item(tree, hf_ecat_mailbox_eoe, tvb, offset, eoe_length, TRUE);
1023       proto_item_set_text(anItem, "EoE Fragment");
1024
1025       aparent = proto_item_get_parent(anItem);
1026       proto_item_append_text(aparent,":EoE ");
1027    }
1028
1029    if( eoe_length >= ETHERCAT_EOE_HEADER_LEN )
1030    {
1031       ETHERCAT_EOE_HEADER eoe;
1032       init_eoe_header(&eoe, tvb, offset);
1033       if ( eoe.anEoeHeaderInfoUnion.v.Type == EOE_TYPE_FRAME_FRAG )
1034          g_snprintf ( szText, nMax, "EoE-Frag %d", eoe.anEoeHeaderDataUnion.v.Fragment);
1035       else
1036          g_snprintf ( szText, nMax, "EoE");
1037          col_append_str(pinfo->cinfo, COL_INFO, szText);
1038
1039       { /* Do the following even 'if (tree == NULL)' since a call_dissector() is done */
1040          ecat_eoe_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_eoe);
1041
1042          anItem = proto_tree_add_item(ecat_eoe_tree, hf_ecat_mailbox_eoe_fraghead, tvb, offset, 4, TRUE);
1043          proto_item_set_text(anItem, "Header");
1044          ecat_fraghead_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_fraghead);
1045
1046          anItem = proto_tree_add_uint(ecat_fraghead_tree, hf_ecat_mailbox_eoe_type, tvb, offset, 4, eoe.anEoeHeaderInfoUnion.v.Type);
1047          EoETypeFormatter(&eoe, szText, nMax);
1048          proto_item_set_text(anItem, "%s", szText);
1049
1050          switch ( eoe.anEoeHeaderInfoUnion.v.Type )
1051          {
1052          case EOE_TYPE_FRAME_FRAG:
1053             anItem = proto_tree_add_uint(ecat_fraghead_tree, hf_ecat_mailbox_eoe_fragno, tvb, offset, 4, eoe.anEoeHeaderDataUnion.v.Fragment);
1054             EoEFragNoFormatter(&eoe, szText, nMax);
1055             proto_item_set_text(anItem, "%s", szText);
1056
1057             anItem = proto_tree_add_uint(ecat_fraghead_tree, hf_ecat_mailbox_eoe_offset, tvb, offset, 4, 32*eoe.anEoeHeaderDataUnion.v.OffsetBuffer);
1058             EoEOffsetFormatter(&eoe, szText, nMax);
1059             proto_item_set_text(anItem, "%s", szText);
1060
1061             anItem = proto_tree_add_uint(ecat_fraghead_tree, hf_ecat_mailbox_eoe_frame, tvb, offset, 4, eoe.anEoeHeaderDataUnion.v.FrameNo);
1062             EoEFrameFormatter(&eoe, szText, nMax);
1063             proto_item_set_text(anItem, "%s", szText);
1064
1065             anItem = proto_tree_add_uint(ecat_fraghead_tree, hf_ecat_mailbox_eoe_last, tvb, offset, 4, eoe.anEoeHeaderInfoUnion.v.LastFragment);
1066             EoELastFormatter(&eoe, szText, nMax);
1067             proto_item_set_text(anItem, "%s", szText);
1068
1069             if ( eoe.anEoeHeaderInfoUnion.v.TimeStampRequested )
1070             {
1071                anItem = proto_tree_add_uint(ecat_fraghead_tree, hf_ecat_mailbox_eoe_timestampreq, tvb, offset, 4, eoe.anEoeHeaderInfoUnion.v.TimeStampRequested);
1072                proto_item_set_text(anItem, "Time Stamp Requested");
1073             }
1074
1075             if ( eoe.anEoeHeaderInfoUnion.v.TimeStampAppended )
1076             {
1077                anItem = proto_tree_add_uint(ecat_fraghead_tree, hf_ecat_mailbox_eoe_timestampapp, tvb, offset, 4, eoe.anEoeHeaderInfoUnion.v.TimeStampAppended);
1078                proto_item_set_text(anItem, "Time Stamp Appended");
1079             }
1080
1081             offset+=ETHERCAT_EOE_HEADER_LEN;
1082             proto_tree_add_item(ecat_eoe_tree, hf_ecat_mailbox_eoe_fragment, tvb, offset, eoe_length-offset, TRUE);
1083
1084             if ( eoe.anEoeHeaderDataUnion.v.Fragment == 0 )
1085             {
1086                next_tvb = tvb_new_subset(tvb, offset, eoe_length-offset, eoe_length-offset);
1087                call_dissector( eth_handle, next_tvb, pinfo, ecat_eoe_tree);
1088             }
1089
1090             if ( eoe.anEoeHeaderInfoUnion.v.TimeStampAppended )
1091             {
1092                proto_tree_add_item(ecat_eoe_tree, hf_ecat_mailbox_eoe_timestamp, tvb, eoe_length-ETHERCAT_EOE_TIMESTAMP_LEN, ETHERCAT_EOE_TIMESTAMP_LEN, TRUE);
1093             }
1094             break;
1095
1096          case EOE_TYPE_TIMESTAMP_RES:
1097             proto_tree_add_item(ecat_eoe_tree, hf_ecat_mailbox_eoe_timestamp, tvb, offset+ETHERCAT_EOE_HEADER_LEN, ETHERCAT_EOE_TIMESTAMP_LEN, TRUE);
1098             break;
1099
1100          case EOE_TYPE_INIT_REQ:
1101             offset+=ETHERCAT_EOE_HEADER_LEN;
1102             anItem = proto_tree_add_item(ecat_fraghead_tree, hf_ecat_mailbox_eoe_init, tvb, offset, MIN(eoe_length-offset,ETHERCAT_EOE_INIT_LEN), TRUE);
1103             if( eoe_length-offset >= ETHERCAT_EOE_INIT_LEN )
1104             {
1105                ecat_eoe_init_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_eoe_init);
1106
1107                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_contains_macaddr, tvb, offset, 4, TRUE);
1108                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_contains_ipaddr, tvb, offset, 4, TRUE);
1109                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_contains_subnetmask, tvb, offset, 4, TRUE);
1110                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_contains_defaultgateway, tvb, offset, 4, TRUE);
1111                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_contains_dnsserver, tvb, offset, 4, TRUE);
1112                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_contains_dnsname, tvb, offset, 4, TRUE);
1113                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_append_timestamp, tvb, offset, 4, TRUE);
1114                offset+=4;
1115
1116                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_macaddr, tvb, offset, ETHERNET_ADDRESS_LEN, TRUE);
1117                offset+=ETHERNET_ADDRESS_LEN;
1118
1119                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_ipaddr, tvb, offset, 4, TRUE);
1120                offset+=4;
1121
1122                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_subnetmask, tvb, offset, 4, TRUE);
1123                offset+=4;
1124
1125                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_defaultgateway, tvb, offset, 4, TRUE);
1126                offset+=4;
1127
1128                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_dnsserver, tvb, offset, 4, TRUE);
1129                offset+=4;
1130
1131                proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_dnsname, tvb, offset, 32, TRUE);
1132             }
1133             else
1134                proto_item_append_text(anItem, " - Invalid length!");
1135             break;
1136
1137          case EOE_TYPE_MACFILTER_REQ:
1138             {
1139                EoeMacFilterOptionsUnion options;
1140                offset+=ETHERCAT_EOE_HEADER_LEN;
1141                anItem = proto_tree_add_item(ecat_fraghead_tree, hf_ecat_mailbox_eoe_macfilter, tvb, offset, MIN(eoe_length-offset, ETHERCAT_EOE_MACFILTER_LEN), TRUE);
1142                if( eoe_length-offset >= ETHERCAT_EOE_MACFILTER_LEN )
1143                {
1144                   proto_tree *ecat_eoe_macfilter_filtermask_tree;
1145
1146                   ecat_eoe_macfilter_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_eoe_macfilter);
1147                   proto_tree_add_item(ecat_eoe_macfilter_tree, hf_ecat_mailbox_eoe_macfilter_macfiltercount, tvb, offset, 4, TRUE);
1148                   proto_tree_add_item(ecat_eoe_macfilter_tree, hf_ecat_mailbox_eoe_macfilter_maskcount, tvb, offset, 4, TRUE);
1149                   proto_tree_add_item(ecat_eoe_macfilter_tree, hf_ecat_mailbox_eoe_macfilter_nobroadcasts, tvb, offset, 4, TRUE);
1150                   options.Options = tvb_get_letohs(tvb, offset);
1151                   offset+=4;
1152
1153                   anItem = proto_tree_add_item(ecat_eoe_macfilter_tree, hf_ecat_mailbox_eoe_macfilter_filter, tvb, offset, 16*ETHERNET_ADDRESS_LEN, TRUE);
1154                   ecat_eoe_macfilter_filter_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_eoe_macfilter_filter);
1155                   for( nCnt=0; nCnt<options.v.MacFilterCount; nCnt++)
1156                      proto_tree_add_item(ecat_eoe_macfilter_filter_tree, hf_ecat_mailbox_eoe_macfilter_filters[nCnt], tvb, offset+nCnt*ETHERNET_ADDRESS_LEN, ETHERNET_ADDRESS_LEN, TRUE);
1157                   offset+=16*ETHERNET_ADDRESS_LEN;
1158
1159                   anItem = proto_tree_add_item(ecat_eoe_macfilter_tree, hf_ecat_mailbox_eoe_macfilter_filtermask, tvb, offset, 4*sizeof(guint32), TRUE);
1160                   ecat_eoe_macfilter_filtermask_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_eoe_macfilter_filtermask);
1161                   for( nCnt=0; nCnt<options.v.MacFilterMaskCount; nCnt++)
1162                      proto_tree_add_item(ecat_eoe_macfilter_filtermask_tree, hf_ecat_mailbox_eoe_macfilter_filtermasks[nCnt], tvb, offset+nCnt*sizeof(guint32), sizeof(guint32), TRUE);
1163                }
1164                else
1165                   proto_item_append_text(anItem, " - Invalid length!");
1166             }
1167             break;
1168
1169          case EOE_TYPE_INIT_RES:
1170          case EOE_TYPE_MACFILTER_RES:
1171             break;
1172          }
1173       }
1174
1175       col_prepend_fstr(pinfo->cinfo, COL_INFO, "EoE(");
1176
1177       col_prepend_fstr(pinfo->cinfo, COL_PROTOCOL, "EoE-");
1178    }
1179    else
1180    {
1181       col_append_str(pinfo->cinfo, COL_INFO, "EoE - invalid length!");
1182    }
1183 }
1184
1185 static void dissect_ecat_foe(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *tree)
1186 {
1187    proto_tree *ecat_foe_tree,*ecat_foe_efw_tree;
1188
1189    proto_item *anItem= NULL,*aparent = NULL;
1190    char szText[200];
1191    int nMax = sizeof(szText)-1;
1192
1193    guint foe_length = tvb_reported_length(tvb)-offset;
1194
1195    if( tree )
1196    {
1197       anItem = proto_tree_add_item(tree, hf_ecat_mailbox_foe, tvb, offset, foe_length, TRUE);
1198       proto_item_set_text(anItem, ":Foe");
1199
1200       aparent = proto_item_get_parent(anItem);
1201       proto_item_append_text(aparent,"FoE ");
1202    }
1203
1204    if( foe_length >= ETHERCAT_FOE_HEADER_LEN )
1205    {
1206       FoeFormatter(tvb, offset, szText, nMax, foe_length);
1207       col_append_str(pinfo->cinfo, COL_INFO, szText);
1208
1209       if( tree )
1210       {
1211          ETHERCAT_FOE_HEADER foe;
1212          init_foe_header(&foe, tvb, offset);
1213
1214          ecat_foe_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_foe);
1215          proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_opmode, tvb, offset++, 1, TRUE);
1216          offset++; /*Reserved1;*/
1217
1218          switch (foe.OpMode)
1219          {
1220          case ECAT_FOE_OPMODE_RRQ:
1221          case ECAT_FOE_OPMODE_WRQ:
1222             proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_filelength, tvb, offset, 4, TRUE);
1223             offset+=4;
1224
1225             proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_filename, tvb, offset, foe_length-offset, TRUE);
1226             break;
1227
1228          case ECAT_FOE_OPMODE_DATA:
1229             {
1230                proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_packetno, tvb, offset, 2, TRUE);
1231                offset+=4; /*+2 for Reserved2*/
1232
1233                proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_data, tvb, offset, foe_length-offset, TRUE);
1234
1235                if( foe_length-offset >= sizeof(TEFWUPDATE_HEADER) )
1236                {
1237                   anItem = proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_efw, tvb, offset, foe_length-offset, TRUE);
1238                   ecat_foe_efw_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_foe_efw);
1239                   proto_tree_add_item(ecat_foe_efw_tree, hf_ecat_mailbox_foe_efw_cmd, tvb, offset, 2, TRUE);
1240                   offset+=2;
1241
1242                   proto_tree_add_item(ecat_foe_efw_tree, hf_ecat_mailbox_foe_efw_size, tvb, offset, 2, TRUE);
1243                   offset+=2;
1244
1245                   proto_tree_add_item(ecat_foe_efw_tree, hf_ecat_mailbox_foe_efw_addresslw, tvb, offset, 2, TRUE);
1246                   offset+=2;
1247
1248                   proto_tree_add_item(ecat_foe_efw_tree, hf_ecat_mailbox_foe_efw_addresshw, tvb, offset, 2, TRUE);
1249                   offset+=2;
1250
1251                   proto_tree_add_item(ecat_foe_efw_tree, hf_ecat_mailbox_foe_efw_data, tvb, offset, foe_length-offset, TRUE);
1252                }
1253             }
1254             break;
1255
1256          case ECAT_FOE_OPMODE_ACK:
1257             proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_packetno, tvb, offset, 2, TRUE);
1258             break;
1259
1260          case ECAT_FOE_OPMODE_ERR:
1261             proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_errcode, tvb, offset, 4, TRUE);
1262             offset+=4;
1263
1264             proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_errtext, tvb, offset, foe_length-offset, TRUE);
1265             break;
1266
1267          case ECAT_FOE_OPMODE_BUSY:
1268             proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_busydone, tvb, offset, 2, TRUE);
1269             offset+=2;
1270
1271             proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_busyentire, tvb, offset, 2, TRUE);
1272             break;
1273          }
1274       }
1275    }
1276    else
1277    {
1278       col_append_str(pinfo->cinfo, COL_INFO, "FoE - invalid length");
1279    }
1280 }
1281
1282 static void dissect_ecat_mailbox(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1283 {
1284    proto_tree *ecat_mailbox_tree = NULL;
1285    proto_tree *ecat_mailbox_header_tree = NULL;
1286    tvbuff_t *next_tvb;
1287    proto_item *anItem;
1288    gint offset = 0;
1289    char szText[200];
1290    int nMax = sizeof(szText)-1;
1291
1292    gint mailbox_length = tvb_reported_length(tvb);
1293
1294    if( mailbox_length >= ETHERCAT_MBOX_HEADER_LEN )
1295    {
1296       ETHERCAT_MBOX_HEADER hdr;
1297
1298       init_mbx_header(&hdr, tvb, offset);
1299       pinfo->private_data = &hdr;
1300
1301       if( mailbox_length >= ETHERCAT_MBOX_HEADER_LEN + hdr.Length )
1302       {
1303          col_append_str(pinfo->cinfo, COL_INFO, " Mbx(");
1304
1305          if( tree )
1306          {
1307             /* Create the mailbox sub tree */
1308             anItem = proto_tree_add_item(tree, proto_ecat_mailbox, tvb, 0, ETHERCAT_MBOX_HEADER_LEN+hdr.Length, TRUE);
1309             ecat_mailbox_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox);
1310
1311             /* Create a mailbox header subtree */
1312             anItem = proto_tree_add_text(ecat_mailbox_tree, tvb, offset, ETHERCAT_MBOX_HEADER_LEN, "Header");
1313             ecat_mailbox_header_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_header);
1314
1315             /* Add length information to the mailbox header */
1316             proto_tree_add_item(ecat_mailbox_header_tree, hf_ecat_mailboxlength, tvb, offset, sizeof(hdr.Length), TRUE);
1317             offset+=sizeof(hdr.Length);
1318
1319             /* Add address information to the mailbox header */
1320             proto_tree_add_item(ecat_mailbox_header_tree, hf_ecat_mailboxaddress, tvb, offset, sizeof(hdr.Address), TRUE);
1321             offset+=sizeof(hdr.Address);
1322
1323             /* Add priority information to the mailbox header */
1324             proto_tree_add_text(ecat_mailbox_header_tree, tvb, offset, 1, "Priority: %d", tvb_get_guint8(tvb, offset) & 0x3);
1325             offset+=sizeof(guint8);
1326
1327             /* Add type information to the mailbox header */
1328             MailboxTypeFormatter(&hdr, szText, nMax);
1329             proto_tree_add_text(ecat_mailbox_header_tree, tvb, offset, 1, "%s", szText);
1330
1331             /* Add counter information to the mailbox header */
1332             proto_tree_add_text(ecat_mailbox_header_tree, tvb, offset, 1, "Counter : %d",hdr.aControlUnion.v.Counter);
1333             offset++;
1334          }
1335          else
1336             offset+=ETHERCAT_MBOX_HEADER_LEN;
1337
1338          next_tvb = tvb_new_subset (tvb, offset, hdr.Length, hdr.Length);
1339          switch ( hdr.aControlUnion.v.Type )
1340          {
1341          case ETHERCAT_MBOX_TYPE_ADS:
1342             call_dissector(ams_handle, next_tvb, pinfo, ecat_mailbox_tree);
1343             break;
1344
1345          case ETHERCAT_MBOX_TYPE_EOE:
1346             dissect_ecat_eoe(next_tvb, 0, pinfo, ecat_mailbox_tree);
1347             break;
1348
1349          case ETHERCAT_MBOX_TYPE_COE:
1350             dissect_ecat_coe(next_tvb, 0, pinfo, ecat_mailbox_tree);
1351             break;
1352
1353          case ETHERCAT_MBOX_TYPE_FOE:
1354             dissect_ecat_foe(next_tvb, 0, pinfo, ecat_mailbox_tree);
1355             break;
1356
1357          case ETHERCAT_MBOX_TYPE_SOE:
1358             dissect_ecat_soe(next_tvb, 0, pinfo, ecat_mailbox_tree);
1359             break;
1360
1361          default:
1362             proto_tree_add_item(ecat_mailbox_tree, hf_ecat_mailboxdata, tvb, offset, hdr.Length, TRUE);
1363          }
1364
1365          col_append_str(pinfo->cinfo, COL_INFO, ")");
1366       }
1367    }
1368 }
1369
1370 void proto_register_ecat_mailbox(void)
1371 {
1372    static const true_false_string flags_set_truth =
1373    {
1374       "Set",
1375       "Not set"
1376    };
1377
1378    static hf_register_info hf[] =
1379    {
1380       { &hf_ecat_mailboxlength,
1381       { "Length", "ecat_mailbox.length",
1382       FT_UINT16, BASE_DEC, NULL, 0x0,
1383       NULL, HFILL }
1384       },
1385       { &hf_ecat_mailboxaddress,
1386       { "Address", "ecat_mailbox.address",
1387       FT_UINT16, BASE_HEX, NULL, 0x0,
1388       NULL, HFILL }
1389       },
1390       { &hf_ecat_mailbox_eoe,
1391       { "EoE Fragment", "ecat_mailbox.eoe",
1392       FT_BYTES, BASE_NONE, NULL, 0x0,
1393       NULL, HFILL }
1394       },
1395       { &hf_ecat_mailbox_eoe_fraghead,
1396       { "Eoe Frag Header", "ecat_mailbox.eoe.fraghead",
1397       FT_BYTES, BASE_NONE, NULL, 0x0,
1398       NULL, HFILL }
1399       },
1400       { &hf_ecat_mailbox_eoe_type,
1401       { "EoE"/*"Type*/, "ecat_mailbox.eoe.type",
1402       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1403       },
1404       { &hf_ecat_mailbox_eoe_fragno,
1405       { "EoE"/*"FragNo*/, "ecat_mailbox.eoe.fragno",
1406       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1407       },
1408       { &hf_ecat_mailbox_eoe_offset,
1409       { "EoE"/*"Offset"*/, "ecat_mailbox.eoe.offset",
1410       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}
1411       },
1412       { &hf_ecat_mailbox_eoe_frame,
1413       { "EoE"/*"FrameNo"*/, "ecat_mailbox.eoe.frame",
1414       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1415       },
1416       { &hf_ecat_mailbox_eoe_last,
1417       { "Last Fragment"/*"Last Fragment"*/, "ecat_mailbox.eoe.last",
1418       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1419       },
1420       { &hf_ecat_mailbox_eoe_timestampapp,
1421       { "Last Fragment"/*"Last Fragment"*/, "ecat_mailbox.eoe.timestampapp",
1422       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1423       },
1424       { &hf_ecat_mailbox_eoe_timestampreq,
1425       { "Last Fragment"/*"Last Fragment"*/, "ecat_mailbox.eoe.timestampreq",
1426       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1427       },
1428       { &hf_ecat_mailbox_eoe_fragment,
1429       { "EoE Frag Data", "ecat_mailbox.eoe.fragment",
1430       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1431       },
1432       { &hf_ecat_mailbox_eoe_init,
1433       { "Init", "ecat_mailbox.eoe.init",
1434       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1435       },
1436       { &hf_ecat_mailbox_eoe_init_contains_macaddr,
1437       { "MacAddr", "ecat_mailbox.eoe.init.contains_macaddr",
1438       FT_BOOLEAN, 32, TFS(&flags_set_truth), 0x00000001, NULL, HFILL }
1439       },
1440       { &hf_ecat_mailbox_eoe_init_contains_ipaddr,
1441       { "IpAddr", "ecat_mailbox.eoe.init.contains_ipaddr",
1442       FT_BOOLEAN, 32, TFS(&flags_set_truth), 0x00000002, NULL, HFILL }
1443       },
1444       { &hf_ecat_mailbox_eoe_init_contains_subnetmask,
1445       { "SubnetMask", "ecat_mailbox.eoe.init.contains_subnetmask",
1446       FT_BOOLEAN, 32, TFS(&flags_set_truth), 0x00000004, NULL, HFILL }
1447       },
1448       { &hf_ecat_mailbox_eoe_init_contains_defaultgateway,
1449       { "DefaultGateway", "ecat_mailbox.eoe.init.contains_defaultgateway",
1450       FT_BOOLEAN, 32, TFS(&flags_set_truth), 0x00000008, NULL, HFILL }
1451       },
1452       { &hf_ecat_mailbox_eoe_init_contains_dnsserver,
1453       { "DnsServer", "ecat_mailbox.eoe.init.contains_dnsserver",
1454       FT_BOOLEAN, 32, TFS(&flags_set_truth), 0x00000010, NULL, HFILL }
1455       },
1456       { &hf_ecat_mailbox_eoe_init_contains_dnsname,
1457       { "DnsName", "ecat_mailbox.eoe.init.contains_dnsname",
1458       FT_BOOLEAN, 32, TFS(&flags_set_truth), 0x00000020, NULL, HFILL }
1459       },
1460       { &hf_ecat_mailbox_eoe_init_append_timestamp,
1461       { "AppendTimeStamp", "ecat_mailbox.eoe.init.append_timestamp",
1462       FT_BOOLEAN, 32, TFS(&flags_set_truth), 0x00010000, NULL, HFILL }
1463       },
1464       { &hf_ecat_mailbox_eoe_init_macaddr,
1465       { "Mac Addr", "ecat_mailbox.eoe.init.macaddr",
1466       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1467       },
1468       { &hf_ecat_mailbox_eoe_init_ipaddr,
1469       { "Ip Addr", "ecat_mailbox.eoe.init.ipaddr",
1470       FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }
1471       },
1472       { &hf_ecat_mailbox_eoe_init_subnetmask,
1473       { "Subnet Mask", "ecat_mailbox.eoe.init.subnetmask",
1474       FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }
1475       },
1476       { &hf_ecat_mailbox_eoe_init_defaultgateway,
1477       { "Default Gateway", "ecat_mailbox.eoe.init.defaultgateway",
1478       FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }
1479       },
1480       { &hf_ecat_mailbox_eoe_init_dnsserver,
1481       { "Dns Server", "ecat_mailbox.eoe.init.dnsserver",
1482       FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }
1483       },
1484       { &hf_ecat_mailbox_eoe_init_dnsname,
1485       { "Dns Name", "ecat_mailbox.eoe.init.dnsname",
1486       FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
1487       },
1488       { &hf_ecat_mailbox_eoe_macfilter,
1489       { "Mac Filter", "ecat_mailbox.eoe.macfilter",
1490       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1491       },
1492       { &hf_ecat_mailbox_eoe_macfilter_macfiltercount,
1493       { "Mac Filter Count", "ecat_mailbox.eoe.macfilter.macfiltercount",
1494       FT_UINT8, 16, NULL, 0x0, NULL, HFILL }
1495       },
1496       { &hf_ecat_mailbox_eoe_macfilter_maskcount,
1497       { "Mac Filter Mask Count", "ecat_mailbox.eoe.macfilter.maskcount",
1498       FT_UINT8, 16, NULL, 0x0, NULL, HFILL }
1499       },
1500       { &hf_ecat_mailbox_eoe_macfilter_nobroadcasts,
1501       { "No Broadcasts", "ecat_mailbox.eoe.macfilter.nobroadcasts",
1502       FT_BOOLEAN, BASE_NONE,  TFS(&flags_set_truth), 0x0, NULL, HFILL }
1503       },
1504       { &hf_ecat_mailbox_eoe_macfilter_filter,
1505       { "Filter", "ecat_mailbox.eoe.macfilter.filter",
1506       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1507       },
1508       { &hf_ecat_mailbox_eoe_macfilter_filters[0],
1509       { "Filter 0", "ecat_mailbox.eoe.macfilter.filter0",
1510       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1511       },
1512       { &hf_ecat_mailbox_eoe_macfilter_filters[1],
1513       { "Filter 1", "ecat_mailbox.eoe.macfilter.filter1",
1514       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1515       },
1516       { &hf_ecat_mailbox_eoe_macfilter_filters[2],
1517       { "Filter 2", "ecat_mailbox.eoe.macfilter.filter2",
1518       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1519       },
1520       { &hf_ecat_mailbox_eoe_macfilter_filters[3],
1521       { "Filter 3", "ecat_mailbox.eoe.macfilter.filter3",
1522       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1523       },
1524       { &hf_ecat_mailbox_eoe_macfilter_filters[4],
1525       { "Filter 4", "ecat_mailbox.eoe.macfilter.filter4",
1526       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1527       },
1528       { &hf_ecat_mailbox_eoe_macfilter_filters[5],
1529       { "Filter 5", "ecat_mailbox.eoe.macfilter.filter5",
1530       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1531       },
1532       { &hf_ecat_mailbox_eoe_macfilter_filters[6],
1533       { "Filter 6", "ecat_mailbox.eoe.macfilter.filter6",
1534       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1535       },
1536       { &hf_ecat_mailbox_eoe_macfilter_filters[7],
1537       { "Filter 7", "ecat_mailbox.eoe.macfilter.filter7",
1538       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1539       },
1540       { &hf_ecat_mailbox_eoe_macfilter_filters[8],
1541       { "Filter 8", "ecat_mailbox.eoe.macfilter.filter8",
1542       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1543       },
1544       { &hf_ecat_mailbox_eoe_macfilter_filters[9],
1545       { "Filter 9", "ecat_mailbox.eoe.macfilter.filter9",
1546       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1547       },
1548       { &hf_ecat_mailbox_eoe_macfilter_filters[10],
1549       { "Filter 10", "ecat_mailbox.eoe.macfilter.filter10",
1550       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1551       },
1552       { &hf_ecat_mailbox_eoe_macfilter_filters[11],
1553       { "Filter 11", "ecat_mailbox.eoe.macfilter.filter11",
1554       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1555       },
1556       { &hf_ecat_mailbox_eoe_macfilter_filters[12],
1557       { "Filter 12", "ecat_mailbox.eoe.macfilter.filter12",
1558       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1559       },
1560       { &hf_ecat_mailbox_eoe_macfilter_filters[13],
1561       { "Filter 13", "ecat_mailbox.eoe.macfilter.filter13",
1562       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1563       },
1564       { &hf_ecat_mailbox_eoe_macfilter_filters[14],
1565       { "Filter 14", "ecat_mailbox.eoe.macfilter.filter14",
1566       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1567       },
1568       { &hf_ecat_mailbox_eoe_macfilter_filters[15],
1569       { "Filter 15", "ecat_mailbox.eoe.macfilter.filter15",
1570       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1571       },
1572       { &hf_ecat_mailbox_eoe_macfilter_filtermask,
1573       { "Filter Mask", "ecat_mailbox.eoe.macfilter.filtermask",
1574       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1575       },
1576       { &hf_ecat_mailbox_eoe_macfilter_filtermasks[0],
1577       { "Mask 0", "ecat_mailbox.eoe.macfilter.filtermask0",
1578       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1579       },
1580       { &hf_ecat_mailbox_eoe_macfilter_filtermasks[1],
1581       { "Mask 1", "ecat_mailbox.eoe.macfilter.filtermask1",
1582       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1583       },
1584       { &hf_ecat_mailbox_eoe_macfilter_filtermasks[2],
1585       { "Mask 2", "ecat_mailbox.eoe.macfilter.filtermask2",
1586       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1587       },
1588       { &hf_ecat_mailbox_eoe_macfilter_filtermasks[3],
1589       { "Mask 3", "ecat_mailbox.eoe.macfilter.filtermask3",
1590       FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1591       },
1592       { &hf_ecat_mailbox_eoe_timestamp,
1593       { "Time Stamp", "ecat_mailbox.eoe.timestamp",
1594       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1595       },
1596       { &hf_ecat_mailbox_coe,
1597       { "CoE", "ecat_mailbox.coe",
1598       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1599       },
1600       { &hf_ecat_mailbox_coe_number,
1601       { "Number", "ecat_mailbox.coe.number",
1602       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1603       },
1604       { &hf_ecat_mailbox_coe_type,
1605       { "Type", "ecat_mailbox.coe.type",
1606       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1607       },
1608       { &hf_ecat_mailbox_coe_sdoreq,
1609       { "SDO Req", "ecat_mailbox.coe.sdoreq",
1610       FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1611       },
1612       { &hf_ecat_mailbox_coe_sdoccsid,
1613       { "Initiate Download", "ecat_mailbox.coe.sdoccsid",
1614       FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }
1615       },
1616       { &hf_ecat_mailbox_coe_sdoccsid_sizeind,
1617       { "Size Ind.", "ecat_mailbox.coe.sdoccsid.sizeind",
1618       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
1619       NULL, HFILL }
1620       },
1621       { &hf_ecat_mailbox_coe_sdoccsid_expedited,
1622       { "Expedited", "ecat_mailbox.coe.sdoccsid.expedited",
1623       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000002,
1624       NULL, HFILL }
1625       },
1626       { &hf_ecat_mailbox_coe_sdoccsid_size0,
1627       { "Bytes", "ecat_mailbox.coe.sdoccsid.size0",
1628       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000004,
1629       NULL, HFILL }
1630       },
1631       { &hf_ecat_mailbox_coe_sdoccsid_size1,
1632       { "Bytes", "ecat_mailbox.coe.sdoccsid.size1",
1633       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000008,
1634       NULL, HFILL }
1635       },
1636       { &hf_ecat_mailbox_coe_sdoccsid_complete,
1637       { "Access", "ecat_mailbox.coe.sdoccsid.complete",
1638       FT_BOOLEAN, 8, TFS(&tfs_complete), 0x00000010,
1639       NULL, HFILL }
1640       },
1641       { &hf_ecat_mailbox_coe_sdoccsds,
1642       { "Download Segment", "ecat_mailbox.coe.sdoccsds",
1643       FT_UINT8, BASE_HEX, NULL, 0x0,
1644       NULL, HFILL }
1645       },
1646       { &hf_ecat_mailbox_coe_sdoccsds_lastseg,
1647       { "Last Segment", "ecat_mailbox.coe.sdoccsds.lastseg",
1648       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
1649       NULL, HFILL }
1650       },
1651       { &hf_ecat_mailbox_coe_sdoccsds_size,
1652       { "Size", "ecat_mailbox.coe.sdoccsds.size",
1653       FT_UINT8, BASE_DEC, NULL, 0x0000000E,
1654       NULL, HFILL }
1655       },
1656       { &hf_ecat_mailbox_coe_sdoccsds_toggle,
1657       { "Toggle Bit", "ecat_mailbox.coe.sdoccsds.toggle",
1658       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
1659       NULL, HFILL }
1660       },
1661       { &hf_ecat_mailbox_coe_sdoccsiu,
1662       { "Init Upload", "ecat_mailbox.coe.sdoccsiu",
1663       FT_UINT8, BASE_HEX, NULL, 0x0,
1664       NULL, HFILL }
1665       },
1666       { &hf_ecat_mailbox_coe_sdoccsiu_complete,
1667       { "Toggle Bit", "ecat_mailbox.coe.sdoccsiu_complete",
1668       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
1669       NULL, HFILL }
1670       },
1671       { &hf_ecat_mailbox_coe_sdoccsus,
1672       { "Upload Segment", "ecat_mailbox.coe.sdoccsus",
1673       FT_UINT8, BASE_HEX, NULL, 0x0,
1674       NULL, HFILL }
1675       },
1676       { &hf_ecat_mailbox_coe_sdoccsus_toggle,
1677       { "Toggle Bit", "ecat_mailbox.coe.sdoccsus_toggle",
1678       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
1679       NULL, HFILL }
1680       },
1681
1682       { &hf_ecat_mailbox_coe_sdoidx,
1683       { "Index", "ecat_mailbox.coe.sdoidx",
1684       FT_UINT16, BASE_HEX, NULL, 0x0,
1685       NULL, HFILL }
1686       },
1687       { &hf_ecat_mailbox_coe_sdosub,
1688       { "SubIndex", "ecat_mailbox.coe.sdosub",
1689       FT_UINT8, BASE_HEX, NULL, 0x0,
1690       NULL, HFILL }
1691       },
1692       { &hf_ecat_mailbox_coe_sdodata,
1693       { "Data", "ecat_mailbox.coe.sdodata",
1694       FT_UINT32, BASE_HEX, NULL, 0x0,
1695       NULL, HFILL }
1696       },
1697       { &hf_ecat_mailbox_coe_sdodata1,
1698       { "Data", "ecat_mailbox.coe.sdodata",
1699       FT_UINT8, BASE_HEX, NULL, 0x0,
1700       NULL, HFILL }
1701       },
1702       { &hf_ecat_mailbox_coe_sdodata2,
1703       { "Data", "ecat_mailbox.coe.sdodata",
1704       FT_UINT16, BASE_HEX, NULL, 0x0,
1705       NULL, HFILL }
1706       },
1707       { &hf_ecat_mailbox_coe_sdoldata,
1708       { "Data", "ecat_mailbox.coe.dsoldata",
1709       FT_BYTES, BASE_NONE, NULL, 0x0,
1710       NULL, HFILL }
1711       },
1712       { &hf_ecat_mailbox_coe_sdolength,
1713       { "Length", "ecat_mailbox.coe.sdolength",
1714       FT_UINT32, BASE_HEX, NULL, 0x0,
1715       NULL, HFILL }
1716       },
1717       { &hf_ecat_mailbox_coe_sdoerror,
1718       { "SDO Error", "ecat_mailbox.coe.sdoerror",
1719       FT_UINT32, BASE_HEX, NULL, 0x0,
1720       NULL, HFILL }
1721       },
1722       { &hf_ecat_mailbox_coe_sdores,
1723       { "SDO Res", "ecat_mailbox.coe.sdores",
1724       FT_UINT8, BASE_DEC, NULL, 0x0,
1725       NULL, HFILL }
1726       },
1727       { &hf_ecat_mailbox_coe_sdoscsiu,
1728       { "Initiate Upload Response", "ecat_mailbox.coe.sdoscsiu",
1729       FT_UINT8, BASE_HEX, NULL, 0x0,
1730       NULL, HFILL }
1731       },
1732       { &hf_ecat_mailbox_coe_sdoscsiu_sizeind,
1733       { "Size Ind.", "ecat_mailbox.coe.sdoscsiu_sizeind",
1734       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
1735       NULL, HFILL }
1736       },
1737       { &hf_ecat_mailbox_coe_sdoscsiu_expedited,
1738       { "Expedited", "ecat_mailbox.coe.sdoscsiu_expedited",
1739       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000002,
1740       NULL, HFILL }
1741       },
1742       { &hf_ecat_mailbox_coe_sdoscsiu_size0,
1743       { "Bytes", "ecat_mailbox.coe.sdoscsiu_size0",
1744       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000004,
1745       NULL, HFILL }
1746       },
1747       { &hf_ecat_mailbox_coe_sdoscsiu_size1,
1748       { "Bytes", "ecat_mailbox.coe.sdoscsiu_size1",
1749       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000008,
1750       NULL, HFILL }
1751       },
1752       { &hf_ecat_mailbox_coe_sdoscsiu_complete,
1753       { "Access", "ecat_mailbox.coe.sdoscsiu_complete",
1754       FT_BOOLEAN, 8, TFS(&tfs_complete), 0x00000010,
1755       NULL, HFILL }
1756       },
1757       { &hf_ecat_mailbox_coe_sdoscsds,
1758       { "Download Segment Response", "ecat_mailbox.coe.sdoscsds",
1759       FT_UINT8, BASE_HEX, NULL, 0x0,
1760       NULL, HFILL }
1761       },
1762       { &hf_ecat_mailbox_coe_sdoscsds_toggle,
1763       { "Toggle Bit", "ecat_mailbox.coe.sdoscsds_toggle",
1764       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
1765       NULL, HFILL }
1766       },
1767       { &hf_ecat_mailbox_coe_sdoscsus,
1768       { "Upload Segment", "ecat_mailbox.coe.sdoscsus",
1769       FT_UINT8, BASE_HEX, NULL, 0x0,
1770       NULL, HFILL }
1771       },
1772       { &hf_ecat_mailbox_coe_sdoscsus_lastseg,
1773       { "Last Segment", "ecat_mailbox.coe.sdoscsus_lastseg",
1774       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
1775       NULL, HFILL }
1776       },
1777       { &hf_ecat_mailbox_coe_sdoscsus_bytes,
1778       { "Bytes", "ecat_mailbox.coe.sdoscsus_bytes",
1779       FT_UINT8, BASE_DEC, NULL, 0x0000000E,
1780       NULL, HFILL }
1781       },
1782       { &hf_ecat_mailbox_coe_sdoscsus_toggle,
1783       { "Toggle Bit", "ecat_mailbox.coe.sdoscsus_toggle",
1784       FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
1785       NULL, HFILL }
1786       },
1787       { &hf_ecat_mailbox_coe_sdoinfoopcode,
1788       { "Info OpCode", "ecat_mailbox.coe.sdoinfoopcode",
1789       FT_UINT8, BASE_HEX, NULL, 0x0,
1790       NULL, HFILL },
1791       },
1792       { &hf_ecat_mailbox_coe_sdoinfofrag,
1793       { "Info Frag Left", "ecat_mailbox.coe.sdoinfofrag",
1794       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1795       },
1796       { &hf_ecat_mailbox_coe_sdoinfolisttype,
1797       { "Info List Type", "ecat_mailbox.coe.sdoinfolisttype",
1798       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1799       },
1800       { &hf_ecat_mailbox_coe_sdoinfolist,
1801       { "Info List", "ecat_mailbox.coe.sdoinfolist",
1802       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL },
1803       },
1804       { &hf_ecat_mailbox_coe_sdoinfoindex,
1805       { "Info Obj Index", "ecat_mailbox.coe.sdoinfoindex",
1806       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1807       },
1808       { &hf_ecat_mailbox_coe_sdoinfosubindex,
1809       { "Info Obj SubIdx", "ecat_mailbox.coe.sdoinfosubindex",
1810       FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL },
1811       },
1812       { &hf_ecat_mailbox_coe_sdoinfovalueinfo,
1813       { "Info Obj SubIdx", "ecat_mailbox.coe.sdoinfovalueinfo",
1814       FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL },
1815       },
1816       { &hf_ecat_mailbox_coe_sdoinfoerrorcode,
1817       { "Info Error Code", "ecat_mailbox.coe.sdoinfoerrorcode",
1818       FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL },
1819       },
1820       { &hf_ecat_mailbox_coe_sdoinfodatatype,
1821       { "Info Data Type", "ecat_mailbox.coe.sdoinfodatatype",
1822       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1823       },
1824       { &hf_ecat_mailbox_coe_sdoinfomaxsub,
1825       { "Info Max SubIdx", "ecat_mailbox.coe.sdoinfomaxsub",
1826       FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL },
1827       },
1828       { &hf_ecat_mailbox_coe_sdoinfoobjcode,
1829       { "Info Obj Code", "ecat_mailbox.coe.sdoinfoobjcode",
1830       FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL },
1831       },
1832       { &hf_ecat_mailbox_coe_sdoinfoname,
1833       { "Info Name", "ecat_mailbox.coe.sdoinfoname",
1834       FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL },
1835       },
1836       { &hf_ecat_mailbox_coe_sdoinfobitlen,
1837       { "Info Bit Len", "ecat_mailbox.coe.sdoinfobitlen",
1838       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1839       },
1840       { &hf_ecat_mailbox_coe_sdoinfoobjaccess,
1841       { "Info Obj Access", "ecat_mailbox.coe.sdoinfoobjaccess",
1842       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1843       },
1844       { &hf_ecat_mailbox_coe_sdoinfounittype,
1845       { "Info Data Type", "ecat_mailbox.coe.sdoinfounittype",
1846       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1847       },
1848       { &hf_ecat_mailbox_coe_sdoinfodefaultvalue,
1849       { "Info Default Val", "ecat_mailbox.coe.sdoinfodefaultvalue",
1850       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL },
1851       },
1852       { &hf_ecat_mailbox_coe_sdoinfominvalue,
1853       { "Info Min Val", "ecat_mailbox.coe.sdoinfominvalue",
1854       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL },
1855       },
1856       { &hf_ecat_mailbox_coe_sdoinfomaxvalue,
1857       { "Info Max Val", "ecat_mailbox.coe.sdoinfomaxvalue",
1858       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL },
1859       },
1860       { &hf_ecat_mailboxdata,
1861       { "MB Data", "ecat_mailbox.data",
1862       FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1863       },
1864       { &hf_ecat_mailbox_foe,
1865       { "Foe", "ecat_mailbox.foe",
1866       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1867       },
1868       { &hf_ecat_mailbox_foe_opmode,
1869       { "Foe OpMode", "ecat_mailbox.foe_opmode",
1870       FT_UINT8, BASE_HEX, VALS(FoEOpMode), 0x0, "Op modes", HFILL }
1871       },
1872       { &hf_ecat_mailbox_foe_filelength,
1873       { "Foe FileLength" , "ecat_mailbox.foe_filelength",
1874       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1875       },
1876       { &hf_ecat_mailbox_foe_filename,
1877       { "Foe FileName", "ecat_mailbox.foe_filename",
1878       FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
1879       },
1880       { &hf_ecat_mailbox_foe_packetno,
1881       { "Foe PacketNo", "ecat_mailbox.foe_packetno",
1882       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1883       },
1884       { &hf_ecat_mailbox_foe_errcode,
1885       { "Foe ErrorCode", "ecat_mailbox.foe_errcode",
1886       FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1887       },
1888       { &hf_ecat_mailbox_foe_errtext,
1889       { "Foe ErrorString", "ecat_mailbox.foe_errtext",
1890       FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
1891       },
1892       { &hf_ecat_mailbox_foe_busydone,
1893       { "Foe BusyDone", "ecat_mailbox.foe_busydone",
1894       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
1895       },
1896       { &hf_ecat_mailbox_foe_busyentire,
1897       { "Foe BusyEntire", "ecat_mailbox.foe_busyentire",
1898       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
1899       },
1900       { &hf_ecat_mailbox_foe_data,
1901       { "Foe Data", "ecat_mailbox.foe_busydata",
1902       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1903       },
1904       { &hf_ecat_mailbox_foe_efw,
1905       { "Firmware", "ecat_mailbox.foe.efw",
1906       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1907       },
1908       { &hf_ecat_mailbox_foe_efw_cmd,
1909       { "Cmd", "ecat_mailbox.foe.efw.cmd",
1910       FT_UINT16, BASE_HEX, VALS(FoEEfwCmd), 0x0, NULL, HFILL }
1911       },
1912       { &hf_ecat_mailbox_foe_efw_size,
1913       { "Size", "ecat_mailbox.foe.efw.size",
1914       FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1915       },
1916       { &hf_ecat_mailbox_foe_efw_addresslw,
1917       { "AddressLW", "ecat_mailbox.foe.efw.addresslw",
1918       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
1919       },
1920       { &hf_ecat_mailbox_foe_efw_addresshw,
1921       { "AddressHW", "ecat_mailbox.foe.efw.addresshw",
1922       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
1923       },
1924       { &hf_ecat_mailbox_foe_efw_data,
1925       { "Data", "ecat_mailbox.foe.efw.data",
1926       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1927       },
1928       { &hf_ecat_mailbox_soe,
1929       { "Soe", "ecat_mailbox.soe",
1930       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1931       },
1932       { &hf_ecat_mailbox_soe_header,
1933       { "Soe Header", "ecat_mailbox.soe_header",
1934       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
1935       },
1936       { &hf_ecat_mailbox_soe_header_opcode,
1937       { "SoE OpCode", "ecat_mailbox.soe_opcode",
1938       FT_UINT16, BASE_DEC, VALS(SoeOpcode), 0x00000007, NULL, HFILL }
1939       },
1940       { &hf_ecat_mailbox_soe_header_incomplete,
1941       { "More Follows...", "ecat_mailbox.soe_header_incomplete",
1942       FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000008, NULL, HFILL }
1943       },
1944       { &hf_ecat_mailbox_soe_header_error,
1945       { "Error", "ecat_mailbox.soe_header_error",
1946       FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000010,
1947       NULL, HFILL }
1948       },
1949       { &hf_ecat_mailbox_soe_header_driveno,
1950       { "Drive No", "ecat_mailbox.soe_header_driveno",
1951       FT_UINT16, BASE_DEC, NULL, 0x000000e0, NULL, HFILL }
1952       },
1953       { &hf_ecat_mailbox_soe_header_datastate,
1954       { "Datastate", "ecat_mailbox.soe_header_datastate",
1955       FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000100,
1956       NULL, HFILL }
1957       },
1958       { &hf_ecat_mailbox_soe_header_name,
1959       { "Name", "ecat_mailbox.soe_header_name",
1960       FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000200,
1961       NULL, HFILL }
1962       },
1963       { &hf_ecat_mailbox_soe_header_attribute,
1964       { "Attribute", "ecat_mailbox.soe_header_attribute",
1965       FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000400,
1966       NULL, HFILL }
1967       },
1968       { &hf_ecat_mailbox_soe_header_unit,
1969       { "Unit", "ecat_mailbox.soe_header_unit",
1970       FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000800,
1971       NULL, HFILL }
1972       },
1973       { &hf_ecat_mailbox_soe_header_min,
1974       { "Min", "ecat_mailbox.soe_header_min",
1975       FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00001000,
1976       NULL, HFILL }
1977       },
1978       { &hf_ecat_mailbox_soe_header_max,
1979       { "Max", "ecat_mailbox.soe_header_max",
1980       FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00002000,
1981       NULL, HFILL }
1982       },
1983       { &hf_ecat_mailbox_soe_header_value,
1984       { "Value", "ecat_mailbox.soe_header_value",
1985       FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00004000,
1986       NULL, HFILL }
1987       },
1988       { &hf_ecat_mailbox_soe_header_reserved,
1989       { "Reserved", "ecat_mailbox.soe_header_reserved",
1990       FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00008000,
1991       NULL, HFILL }
1992       },
1993       { &hf_ecat_mailbox_soe_idn,
1994       { "SoE IDN", "ecat_mailbox.soe_idn",
1995       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
1996       },
1997       { &hf_ecat_mailbox_soe_data,
1998       { "SoE Data", "ecat_mailbox.soe_data",
1999       FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
2000       },
2001       { &hf_ecat_mailbox_soe_frag,
2002       { "SoE FragLeft", "ecat_mailbox.soe_frag",
2003       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
2004       },
2005       { &hf_ecat_mailbox_soe_error,
2006       { "SoE Error", "ecat_mailbox.soe_error",
2007       FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
2008       }
2009    };
2010
2011    static gint *ett[] =
2012    {
2013       &ett_ecat_mailbox,
2014       &ett_ecat_mailbox_eoe,
2015       &ett_ecat_mailbox_eoe_init,
2016       &ett_ecat_mailbox_eoe_macfilter,
2017       &ett_ecat_mailbox_eoe_macfilter_filter,
2018       &ett_ecat_mailbox_eoe_macfilter_filtermask,
2019       &ett_ecat_mailbox_coe,
2020       &ett_ecat_mailbox_sdo,
2021       &ett_ecat_mailbox_coe_sdoccs,
2022       &ett_ecat_mailbox_coe_sdoscs,
2023       &ett_ecat_mailbox_foe,
2024       &ett_ecat_mailbox_foe_efw,
2025       &ett_ecat_mailbox_soeflag,
2026       &ett_ecat_mailbox_soe,
2027       &ett_ecat_mailbox_fraghead,
2028       &ett_ecat_mailbox_header
2029    };
2030
2031    proto_ecat_mailbox = proto_register_protocol("EtherCAT Mailbox Protocol",
2032       "ECAT_MAILBOX", "ecat_mailbox");
2033    proto_register_field_array(proto_ecat_mailbox, hf,array_length(hf));
2034    proto_register_subtree_array(ett, array_length(ett));
2035
2036    register_dissector("ecat_mailbox", dissect_ecat_mailbox, proto_ecat_mailbox);
2037 }
2038
2039 void proto_reg_handoff_ecat_mailbox(void)
2040 {
2041    dissector_handle_t ecat_mailbox_handle;
2042
2043    /* Register this dissector as a sub dissector to E88A4 based on ether type. */
2044    ecat_mailbox_handle = find_dissector("ecat_mailbox");
2045    dissector_add_uint("ecatf.type", 5, ecat_mailbox_handle);
2046
2047    eth_handle = find_dissector("eth_withoutfcs");
2048    ams_handle = find_dissector("ams");
2049 }