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