2 * Routines for EtherCAT packet disassembly
4 * Copyright (c) 2007 by Beckhoff Automation GmbH
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * 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.
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.
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.
33 #include <epan/packet.h>
35 #include "packet-ecatmb.h"
37 #define BIT2BYTE(x) ((x+7)/8)
38 #define ENDOF(p) ((p)+1) /* pointer to end of *p */
40 void proto_register_ecat_mailbox(void);
41 void proto_reg_handoff_ecat_mailbox(void);
43 static dissector_handle_t eth_handle;
44 static dissector_handle_t ams_handle;
46 /* Define the EtherCAT mailbox proto */
47 int proto_ecat_mailbox = -1;
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;
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;
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;
195 static const value_string EcMBoxType[] =
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", },
212 static const value_string FoEOpMode[] =
223 static const value_string FoEEfwCmd[] =
225 { 1, "Memory Transfer", },
226 { 2, "Write Code", },
227 { 3, "Check device id", },
229 { 5, "Write code checksum", },
230 { 6, "Set device id", },
231 { 8, "Set code id", },
233 { 10, "Checksum checksum", },
234 { 11, "boot checksum", },
238 static const value_string SoeOpcode[] =
245 { 5, "notification" },
250 static const true_false_string tfs_complete =
255 void init_mbx_header(PETHERCAT_MBOX_HEADER pMbox, tvbuff_t *tvb, gint offset)
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);
262 static void init_eoe_header(PETHERCAT_EOE_HEADER pEoE, tvbuff_t *tvb, gint offset)
264 pEoE->anEoeHeaderInfoUnion.Info = tvb_get_letohs(tvb, offset); offset+=(int)sizeof(guint16);
265 pEoE->anEoeHeaderDataUnion.Result = tvb_get_letohs(tvb, offset);
268 static void init_foe_header(PETHERCAT_FOE_HEADER pFoE, tvbuff_t *tvb, gint offset)
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);
275 static void init_soe_header(PETHERCAT_SOE_HEADER pSoE, tvbuff_t *tvb, gint offset)
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);
282 static void init_coe_header(PETHERCAT_COE_HEADER pCoE, tvbuff_t *tvb, gint offset)
284 pCoE->header = tvb_get_letohs(tvb, offset);
287 static void init_sdo_header(PETHERCAT_SDO_HEADER pSdo, tvbuff_t *tvb, gint offset)
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);
295 static void init_sdo_info_header(PETHERCAT_SDO_INFO_HEADER pInfo, tvbuff_t *tvb, gint offset)
297 pInfo->anSdoControlUnion.Control = tvb_get_guint8(tvb, offset++);
298 pInfo->Reserved = tvb_get_guint8(tvb, offset);
299 pInfo->FragmentsLeft = (int)sizeof(guint16);
303 static void MailboxTypeFormatter(PETHERCAT_MBOX_HEADER pMbx, char *szText, gint nMax)
307 for(i = 0; i<sizeof(EcMBoxType)/sizeof(value_string); i++ )
309 if( EcMBoxType[i].value == pMbx->aControlUnion.v.Type )
311 g_snprintf(szText, nMax, "Type : %s (0x%x)", EcMBoxType[i].strptr, pMbx->aControlUnion.v.Type);
315 g_snprintf ( szText, nMax,"Type : %d", pMbx->aControlUnion.v.Type);
318 static void EoETypeFormatter(PETHERCAT_EOE_HEADER pEoE, char *szText, gint nMax)
320 switch (pEoE->anEoeHeaderInfoUnion.v.Type)
322 case EOE_TYPE_FRAME_FRAG:
323 g_snprintf ( szText, nMax, "Type(%d) : Fragment", pEoE->anEoeHeaderInfoUnion.v.Type);
325 case EOE_TYPE_TIMESTAMP_RES:
326 g_snprintf ( szText, nMax, "Type(%d) : TimeStamp", pEoE->anEoeHeaderInfoUnion.v.Type);
328 case EOE_TYPE_INIT_REQ:
329 g_snprintf ( szText, nMax, "Type(%d) : Init Req", pEoE->anEoeHeaderInfoUnion.v.Type);
331 case EOE_TYPE_INIT_RES:
332 g_snprintf ( szText, nMax, "Type(%d) : Init Res", pEoE->anEoeHeaderInfoUnion.v.Type);
334 case EOE_TYPE_MACFILTER_REQ:
335 g_snprintf ( szText, nMax, "Type(%d) : MAC Req", pEoE->anEoeHeaderInfoUnion.v.Type);
337 case EOE_TYPE_MACFILTER_RES:
338 g_snprintf ( szText, nMax, "Type(%d) : MAC Res", pEoE->anEoeHeaderInfoUnion.v.Type);
341 g_snprintf ( szText, nMax, "Type(%d) : Unknown", pEoE->anEoeHeaderInfoUnion.v.Type);
346 static void EoEFragNoFormatter(PETHERCAT_EOE_HEADER pEoE, char *szText, gint nMax)
348 g_snprintf ( szText, nMax, "FragNo : %d", pEoE->anEoeHeaderDataUnion.v.Fragment);
351 static void EoEOffsetFormatter(PETHERCAT_EOE_HEADER pEoE, char *szText, gint nMax)
353 if ( pEoE->anEoeHeaderDataUnion.v.Fragment == 0 )
354 g_snprintf ( szText, nMax, "BufferSize : %d", 32*pEoE->anEoeHeaderDataUnion.v.OffsetBuffer);
356 g_snprintf ( szText, nMax, "Offset : %d", 32*pEoE->anEoeHeaderDataUnion.v.OffsetBuffer);
359 static void EoEFrameFormatter(PETHERCAT_EOE_HEADER pEoE, char *szText, gint nMax)
361 g_snprintf ( szText, nMax, "FrameNo : %d", pEoE->anEoeHeaderDataUnion.v.FrameNo);
364 static void EoELastFormatter(PETHERCAT_EOE_HEADER pEoE, char *szText, gint nMax)
366 if ( pEoE->anEoeHeaderInfoUnion.v.LastFragment != 0 )
367 g_snprintf ( szText, nMax, "Last Frag");
369 g_snprintf ( szText, nMax, "More Frags...");
372 static void CANopenNumberFormatter(PETHERCAT_COE_HEADER pCoE, char *szText, gint nMax)
374 g_snprintf( szText, nMax, "Number : %d", pCoE->v.Number);
377 static void CANopenTypeFormatter(PETHERCAT_COE_HEADER pCoE, char *szText, gint nMax)
379 switch ( pCoE->v.Type)
381 case ETHERCAT_COE_TYPE_EMERGENCY:
382 g_snprintf ( szText, nMax, "Type : EMERGENCY(%d)", pCoE->v.Type);
384 case ETHERCAT_COE_TYPE_SDOREQ:
385 g_snprintf ( szText, nMax, "Type : SDO Req(%d)", pCoE->v.Type);
387 case ETHERCAT_COE_TYPE_SDORES:
388 g_snprintf ( szText, nMax, "Type : SDO Res(%d)", pCoE->v.Type);
390 case ETHERCAT_COE_TYPE_TXPDO:
391 g_snprintf ( szText, nMax, "Type : TxPDO(%d)", pCoE->v.Type);
393 case ETHERCAT_COE_TYPE_RXPDO:
394 g_snprintf ( szText, nMax, "Type : RxPDO(%d)", pCoE->v.Type);
396 case ETHERCAT_COE_TYPE_TXPDO_RTR:
397 g_snprintf ( szText, nMax, "Type : TxPDO_RTR(%d)", pCoE->v.Type);
399 case ETHERCAT_COE_TYPE_RXPDO_RTR:
400 g_snprintf ( szText, nMax, "Type : RxPDO_RTR(%d)", pCoE->v.Type);
403 g_snprintf ( szText, nMax, "Type :%d", pCoE->v.Type);
407 static void CANopenSdoReqFormatter(PETHERCAT_SDO_HEADER pSdo, char *szText, gint nMax)
409 switch ( pSdo->anSdoHeaderUnion.Idq.Ccs )
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);
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);
417 case SDO_CCS_DOWNLOAD_SEGMENT:
418 g_snprintf ( szText, nMax, "SDO Req : 'Download Segment' (%d)", pSdo->anSdoHeaderUnion.Idq.Ccs);
420 case SDO_CCS_UPLOAD_SEGMENT:
421 g_snprintf ( szText, nMax, "SDO Req : 'Upload Segment' (%d)", pSdo->anSdoHeaderUnion.Idq.Ccs);
423 case SDO_CCS_ABORT_TRANSFER:
424 g_snprintf ( szText, nMax, "SDO Req : 'Abort Transfer' (%d)", pSdo->anSdoHeaderUnion.Idq.Ccs);
427 g_snprintf ( szText, nMax, "SDO Req : Ccs %d", pSdo->anSdoHeaderUnion.Idq.Ccs);
431 static void CANopenSdoResFormatter(PETHERCAT_SDO_HEADER pSdo, char *szText, gint nMax)
433 g_snprintf ( szText, nMax, "SDO Res : Scs %d", pSdo->anSdoHeaderUnion.Ids.Scs);
436 static void CANopenSdoInfoFormatter(PETHERCAT_SDO_INFO_HEADER pHead, char *szText, gint nMax)
438 guint8 opCode = pHead->anSdoControlUnion.v.OpCode & 0x7F;
439 const char* txt2 = "";
440 if ( (pHead->anSdoControlUnion.v.OpCode & 0x80) != 0 )
441 txt2 = " - More Follows";
444 case ECAT_COE_INFO_OPCODE_LIST_Q:
445 g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'List Req' %s", txt2);
447 case ECAT_COE_INFO_OPCODE_LIST_S:
448 g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'List Res' %s", txt2);
450 case ECAT_COE_INFO_OPCODE_OBJ_Q:
451 g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'Obj Req' %s", txt2);
453 case ECAT_COE_INFO_OPCODE_OBJ_S:
454 g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'Obj Res' %s", txt2);
456 case ECAT_COE_INFO_OPCODE_ENTRY_Q:
457 g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'Entry Req' %s", txt2);
459 case ECAT_COE_INFO_OPCODE_ENTRY_S:
460 g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'Entry Res' %s", txt2);
462 case ECAT_COE_INFO_OPCODE_ERROR_S:
463 g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: 'Error Res' %s", txt2);
466 g_snprintf ( szText, nMax, "CoE SDO Info, OpCode: %d %s", opCode, txt2);
470 static void FoeFormatter(tvbuff_t *tvb, gint offset, char *szText, gint nMax, guint foe_length)
472 ETHERCAT_FOE_HEADER foe;
474 memset(tmp, 0, sizeof(tmp));
476 init_foe_header(&foe, tvb, offset);
478 switch ( foe.OpMode )
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));
488 switch ( foe.OpMode )
490 case ECAT_FOE_OPMODE_RRQ:
491 g_snprintf ( szText, nMax, "FoE RRQ (%d) : '%s'", foe.aFoeHeaderDataUnion.FileLength, tmp);
493 case ECAT_FOE_OPMODE_WRQ:
494 g_snprintf ( szText, nMax, "FoE WRQ (%d) : '%s'", foe.aFoeHeaderDataUnion.FileLength, tmp);
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);
499 case ECAT_FOE_OPMODE_ACK:
500 g_snprintf ( szText, nMax, "FoE ACK (%d)", foe.aFoeHeaderDataUnion.v.PacketNo);
502 case ECAT_FOE_OPMODE_ERR:
503 g_snprintf ( szText, nMax, "FoE ERR (%d) : '%s'", foe.aFoeHeaderDataUnion.ErrorCode, tmp);
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);
509 g_snprintf ( szText, nMax, "FoE BUSY (%d/%d)", foe.aFoeHeaderDataUnion.v2.Done, foe.aFoeHeaderDataUnion.v2.Entire);
514 static void SoEIdToString( char* txt, guint16 id, int nMax)
517 g_snprintf(txt, nMax, "P-%d-%04d", (id>>12) & 0x0007, id & 0x0FFF );
519 g_snprintf(txt, nMax, "S-%d-%04d", id>>12, id & 0x0FFF );
522 static void SoeFormatter(tvbuff_t *tvb, gint offset, char *szText, gint nMax, guint soe_length)
524 ETHERCAT_SOE_HEADER soe;
527 memset(tmp, 0, sizeof(tmp));
529 init_soe_header(&soe, tvb, offset);
530 offset+=ETHERCAT_SOE_HEADER_LEN;
532 if ( !soe.anSoeHeaderControlUnion.v.Error )
534 if ( !soe.anSoeHeaderControlUnion.v.InComplete )
536 SoEIdToString(tmp, soe.anSoeHeaderDataUnion.IDN, sizeof(tmp)-1);
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 )
554 case ECAT_SOE_OPCODE_RRQ:
555 g_snprintf ( szText, nMax, "SoE: RRQ (%s, '%s')", tmp, elm);
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));
560 case ECAT_SOE_OPCODE_WRS:
561 g_snprintf ( szText, nMax, "SoE: WRS (%s, '%s')", tmp, elm);
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));
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));
570 g_snprintf ( szText, nMax, "SoE: EMGCY");
573 g_snprintf ( szText, nMax, "SoE:");
577 g_snprintf ( szText, nMax, "SoE: FragmentsLeft %d", soe.anSoeHeaderDataUnion.FragmentsLeft);
580 g_snprintf ( szText, nMax, "SoE: Error %04x", tvb_get_letohs(tvb, offset));
583 /* ethercat mailbox */
584 static void dissect_ecat_coe(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *tree)
586 proto_tree *ecat_coe_tree = NULL, *ecat_sdo_tree, *ecat_coe_sdoccs_tree, *ecat_coe_sdoscs_tree;
588 proto_item *anItem = NULL, *aparent = NULL;
590 int nMax = sizeof(szText)-1;
592 guint coe_length = tvb_reported_length(tvb)-offset;
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 ");
603 col_append_str(pinfo->cinfo, COL_INFO, "CoE ");
605 if( coe_length >= ETHERCAT_COE_HEADER_LEN )
607 ETHERCAT_COE_HEADER coe;
608 init_coe_header(&coe, tvb, offset);
611 ecat_coe_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_coe);
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);
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);
622 offset += ETHERCAT_COE_HEADER_LEN;
626 case ETHERCAT_COE_TYPE_SDOREQ:
628 ETHERCAT_SDO_HEADER sdo;
630 if( coe_length < ETHERCAT_COE_HEADER_LEN + ETHERCAT_SDO_HEADER_LEN )
632 col_append_str(pinfo->cinfo, COL_INFO, "Sdo Req - invalid length");
636 init_sdo_header(&sdo, tvb, offset);
638 CANopenSdoReqFormatter(&sdo, szText, nMax);
639 col_append_str(pinfo->cinfo, COL_INFO, szText);
643 proto_item_append_text(aparent, "%s", szText);
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);
649 switch ( sdo.anSdoHeaderUnion.Idq.Ccs )
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);
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 )
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;
668 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoldata, tvb, offset, len, ENC_NA);
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);
677 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdodata, tvb, offset+4, 4, ENC_LITTLE_ENDIAN);
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);
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);
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);
697 if ( coe_length-offset > 0 )
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);
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);
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);
716 case ETHERCAT_COE_TYPE_SDORES:
718 ETHERCAT_SDO_HEADER sdo;
719 if( coe_length < ETHERCAT_COE_HEADER_LEN + ETHERCAT_SDO_HEADER_LEN )
721 col_append_str(pinfo->cinfo, COL_INFO, "Sdo Res - invalid length");
725 init_sdo_header(&sdo, tvb, offset);
727 CANopenSdoResFormatter(&sdo, szText, nMax);
728 col_append_str(pinfo->cinfo, COL_INFO, szText);
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);
736 switch ( sdo.anSdoHeaderUnion.Ids.Scs )
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);
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);
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 )
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;
759 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoldata, tvb, offset, len, ENC_NA);
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);
766 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdodata, tvb, offset+4, 4, ENC_LITTLE_ENDIAN);
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);
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);
781 if ( coe_length-offset> 0 )
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);
792 case ETHERCAT_COE_TYPE_SDOINFO:
794 ETHERCAT_SDO_INFO_HEADER info;
796 if( coe_length < ETHERCAT_COE_HEADER_LEN + ETHERCAT_SDO_INFO_LISTREQ_LEN )
798 col_append_str(pinfo->cinfo, COL_INFO, "Sdo Info - invalid length");
802 memset(&info, 0x0, sizeof(info));
803 init_sdo_info_header(&info, tvb, offset);
805 CANopenSdoInfoFormatter(&info, szText, nMax);
806 col_append_str(pinfo->cinfo, COL_INFO, szText);
810 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoopcode, tvb, offset++, 1, ENC_LITTLE_ENDIAN);
811 offset++; /*Reserved*/
813 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfofrag, tvb, offset, 2, ENC_LITTLE_ENDIAN);
816 switch ( info.anSdoControlUnion.v.OpCode )
818 case ECAT_COE_INFO_OPCODE_LIST_Q:
820 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfolisttype, tvb, offset, 2, ENC_LITTLE_ENDIAN);
823 case ECAT_COE_INFO_OPCODE_LIST_S:
825 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfolisttype, tvb, offset, 2, ENC_LITTLE_ENDIAN);
828 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfolist, tvb, offset, coe_length-offset, ENC_NA);
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);
834 case ECAT_COE_INFO_OPCODE_OBJ_S:
836 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoindex, tvb, offset, 2, ENC_LITTLE_ENDIAN);
839 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfodatatype, tvb, offset, 2, ENC_LITTLE_ENDIAN);
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);
845 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoname, tvb, offset, coe_length-offset, ENC_ASCII|ENC_NA);
848 case ECAT_COE_INFO_OPCODE_ENTRY_Q:
850 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoindex, tvb, offset, 2, ENC_LITTLE_ENDIAN);
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);
857 case ECAT_COE_INFO_OPCODE_ENTRY_S:
861 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoindex, tvb, offset, 2, ENC_LITTLE_ENDIAN);
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);
867 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfodatatype, tvb, offset, 2, ENC_LITTLE_ENDIAN);
870 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfobitlen, tvb, offset, 2, ENC_LITTLE_ENDIAN);
873 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoobjaccess, tvb, offset, 2, ENC_LITTLE_ENDIAN);
876 if ( (info.anSdoInfoUnion.Entry.ValueInfo & 0x08) != 0 )
878 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfounittype, tvb, offset, 2, ENC_LITTLE_ENDIAN);
881 if ( (info.anSdoInfoUnion.Entry.ValueInfo & 0x10) != 0 )
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);
887 if ( (info.anSdoInfoUnion.Entry.ValueInfo & 0x20) != 0 )
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);
893 if ( (info.anSdoInfoUnion.Entry.ValueInfo & 0x40) != 0 )
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);
899 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoname, tvb, offset, coe_length-offset, ENC_ASCII|ENC_NA);
902 case ECAT_COE_INFO_OPCODE_ERROR_S:
904 proto_tree_add_item(ecat_coe_tree, hf_ecat_mailbox_coe_sdoinfoerrorcode, tvb, offset, 4, ENC_LITTLE_ENDIAN);
915 col_append_str(pinfo->cinfo, COL_INFO, "- invalid length");
919 static void dissect_ecat_soe(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *tree)
921 proto_tree *ecat_soeflag_tree, *ecat_soe_tree;
923 proto_item *anItem = NULL ,*aparent = NULL;
925 int nMax = sizeof(szText)-1;
927 guint soe_length = tvb_reported_length(tvb)-offset;
931 anItem = proto_tree_add_item(tree, hf_ecat_mailbox_soe, tvb, offset, soe_length, ENC_NA);
933 aparent = proto_item_get_parent(anItem);
934 proto_item_append_text(aparent,":SoE ");
937 if( soe_length >= ETHERCAT_SOE_HEADER_LEN )
939 SoeFormatter(tvb, offset, szText, nMax, soe_length);
940 col_append_str(pinfo->cinfo, COL_INFO, szText);
944 ETHERCAT_SOE_HEADER soe;
945 init_soe_header(&soe, tvb, offset);
947 proto_item_append_text(aparent, "%s", szText);
948 proto_item_set_text(anItem, "%s", szText);
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);
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);
968 if ( !soe.anSoeHeaderControlUnion.v.Error )
970 if ( !soe.anSoeHeaderControlUnion.v.InComplete )
972 switch (soe.anSoeHeaderControlUnion.v.OpCode)
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);
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);
983 proto_tree_add_item(tree, hf_ecat_mailbox_soe_data, tvb, offset, soe_length-offset, ENC_NA);
989 proto_tree_add_item(ecat_soe_tree, hf_ecat_mailbox_soe_frag, tvb, offset, 2, ENC_LITTLE_ENDIAN);
992 proto_tree_add_item(tree, hf_ecat_mailbox_soe_data, tvb, offset, soe_length-offset, ENC_NA);
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);
1004 col_append_str(pinfo->cinfo, COL_INFO, "SoE - invalid length");
1008 static void dissect_ecat_eoe(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *tree)
1010 proto_tree *ecat_eoe_tree = 0, *ecat_fraghead_tree, *ecat_eoe_init_tree, *ecat_eoe_macfilter_tree,
1011 *ecat_eoe_macfilter_filter_tree;
1013 proto_item *anItem = NULL, *aparent = NULL;
1015 int nMax = sizeof(szText)-1;
1018 guint eoe_length = tvb_reported_length(tvb)-offset;
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");
1025 aparent = proto_item_get_parent(anItem);
1026 proto_item_append_text(aparent,":EoE ");
1029 if( eoe_length >= ETHERCAT_EOE_HEADER_LEN )
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);
1036 g_snprintf ( szText, nMax, "EoE");
1037 col_append_str(pinfo->cinfo, COL_INFO, szText);
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);
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);
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);
1050 switch ( eoe.anEoeHeaderInfoUnion.v.Type )
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);
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);
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);
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);
1069 if ( eoe.anEoeHeaderInfoUnion.v.TimeStampRequested )
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");
1075 if ( eoe.anEoeHeaderInfoUnion.v.TimeStampAppended )
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");
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);
1084 if ( eoe.anEoeHeaderDataUnion.v.Fragment == 0 )
1086 next_tvb = tvb_new_subset_length(tvb, offset, eoe_length-offset);
1087 call_dissector( eth_handle, next_tvb, pinfo, ecat_eoe_tree);
1090 if ( eoe.anEoeHeaderInfoUnion.v.TimeStampAppended )
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);
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);
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 )
1105 ecat_eoe_init_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_eoe_init);
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);
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;
1119 proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_ipaddr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
1122 proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_subnetmask, tvb, offset, 4, ENC_LITTLE_ENDIAN);
1125 proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_defaultgateway, tvb, offset, 4, ENC_LITTLE_ENDIAN);
1128 proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_dnsserver, tvb, offset, 4, ENC_LITTLE_ENDIAN);
1131 proto_tree_add_item(ecat_eoe_init_tree, hf_ecat_mailbox_eoe_init_dnsname, tvb, offset, 32, ENC_ASCII|ENC_NA);
1134 proto_item_append_text(anItem, " - Invalid length!");
1137 case EOE_TYPE_MACFILTER_REQ:
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 )
1144 proto_tree *ecat_eoe_macfilter_filtermask_tree;
1146 ecat_eoe_macfilter_tree = proto_item_add_subtree(anItem, ett_ecat_mailbox_eoe_macfilter);
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);
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;
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);
1172 proto_item_append_text(anItem, " - Invalid length!");
1176 case EOE_TYPE_INIT_RES:
1177 case EOE_TYPE_MACFILTER_RES:
1182 col_prepend_fstr(pinfo->cinfo, COL_INFO, "EoE(");
1184 col_prepend_fstr(pinfo->cinfo, COL_PROTOCOL, "EoE-");
1188 col_append_str(pinfo->cinfo, COL_INFO, "EoE - invalid length!");
1192 static void dissect_ecat_foe(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *tree)
1194 proto_tree *ecat_foe_tree,*ecat_foe_efw_tree;
1196 proto_item *anItem= NULL,*aparent = NULL;
1198 int nMax = sizeof(szText)-1;
1200 guint foe_length = tvb_reported_length(tvb)-offset;
1204 anItem = proto_tree_add_item(tree, hf_ecat_mailbox_foe, tvb, offset, foe_length, ENC_NA);
1205 proto_item_set_text(anItem, ":Foe");
1207 aparent = proto_item_get_parent(anItem);
1208 proto_item_append_text(aparent,"FoE ");
1211 if( foe_length >= ETHERCAT_FOE_HEADER_LEN )
1213 FoeFormatter(tvb, offset, szText, nMax, foe_length);
1214 col_append_str(pinfo->cinfo, COL_INFO, szText);
1218 ETHERCAT_FOE_HEADER foe;
1219 init_foe_header(&foe, tvb, offset);
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;*/
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);
1232 proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_filename, tvb, offset, foe_length-offset, ENC_ASCII|ENC_NA);
1235 case ECAT_FOE_OPMODE_DATA:
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*/
1240 proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_data, tvb, offset, foe_length-offset, ENC_NA);
1242 if( foe_length-offset >= sizeof(TEFWUPDATE_HEADER) )
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);
1249 proto_tree_add_item(ecat_foe_efw_tree, hf_ecat_mailbox_foe_efw_size, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1252 proto_tree_add_item(ecat_foe_efw_tree, hf_ecat_mailbox_foe_efw_addresslw, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1255 proto_tree_add_item(ecat_foe_efw_tree, hf_ecat_mailbox_foe_efw_addresshw, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1258 proto_tree_add_item(ecat_foe_efw_tree, hf_ecat_mailbox_foe_efw_data, tvb, offset, foe_length-offset, ENC_NA);
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);
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);
1271 proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_errtext, tvb, offset, foe_length-offset, ENC_ASCII|ENC_NA);
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);
1278 proto_tree_add_item(ecat_foe_tree, hf_ecat_mailbox_foe_busyentire, tvb, offset, 2, ENC_LITTLE_ENDIAN);
1285 col_append_str(pinfo->cinfo, COL_INFO, "FoE - invalid length");
1289 static void dissect_ecat_mailbox(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1291 proto_tree *ecat_mailbox_tree = NULL;
1292 proto_tree *ecat_mailbox_header_tree = NULL;
1297 int nMax = sizeof(szText)-1;
1299 gint mailbox_length = tvb_reported_length(tvb);
1301 if( mailbox_length >= ETHERCAT_MBOX_HEADER_LEN )
1303 ETHERCAT_MBOX_HEADER hdr;
1305 init_mbx_header(&hdr, tvb, offset);
1307 if( mailbox_length >= ETHERCAT_MBOX_HEADER_LEN + hdr.Length )
1309 col_append_str(pinfo->cinfo, COL_INFO, " Mbx(");
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);
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);
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);
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);
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);
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);
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);
1342 offset+=ETHERCAT_MBOX_HEADER_LEN;
1344 next_tvb = tvb_new_subset_length (tvb, offset, hdr.Length);
1345 switch ( hdr.aControlUnion.v.Type )
1347 case ETHERCAT_MBOX_TYPE_ADS:
1348 call_dissector(ams_handle, next_tvb, pinfo, ecat_mailbox_tree);
1351 case ETHERCAT_MBOX_TYPE_EOE:
1352 dissect_ecat_eoe(next_tvb, 0, pinfo, ecat_mailbox_tree);
1355 case ETHERCAT_MBOX_TYPE_COE:
1356 dissect_ecat_coe(next_tvb, 0, pinfo, ecat_mailbox_tree);
1359 case ETHERCAT_MBOX_TYPE_FOE:
1360 dissect_ecat_foe(next_tvb, 0, pinfo, ecat_mailbox_tree);
1363 case ETHERCAT_MBOX_TYPE_SOE:
1364 dissect_ecat_soe(next_tvb, 0, pinfo, ecat_mailbox_tree);
1368 proto_tree_add_item(ecat_mailbox_tree, hf_ecat_mailboxdata, tvb, offset, hdr.Length, ENC_NA);
1371 col_append_str(pinfo->cinfo, COL_INFO, ")");
1376 void proto_register_ecat_mailbox(void)
1378 static const true_false_string flags_set_truth =
1384 static hf_register_info hf[] =
1386 { &hf_ecat_mailboxlength,
1387 { "Length", "ecat_mailbox.length",
1388 FT_UINT16, BASE_DEC, NULL, 0x0,
1391 { &hf_ecat_mailboxaddress,
1392 { "Address", "ecat_mailbox.address",
1393 FT_UINT16, BASE_HEX, NULL, 0x0,
1396 { &hf_ecat_mailbox_eoe,
1397 { "EoE Fragment", "ecat_mailbox.eoe",
1398 FT_BYTES, BASE_NONE, NULL, 0x0,
1401 { &hf_ecat_mailbox_eoe_fraghead,
1402 { "Eoe Frag Header", "ecat_mailbox.eoe.fraghead",
1403 FT_BYTES, BASE_NONE, NULL, 0x0,
1406 { &hf_ecat_mailbox_eoe_type,
1407 { "EoE"/*"Type*/, "ecat_mailbox.eoe.type",
1408 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1410 { &hf_ecat_mailbox_eoe_fragno,
1411 { "EoE"/*"FragNo*/, "ecat_mailbox.eoe.fragno",
1412 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1414 { &hf_ecat_mailbox_eoe_offset,
1415 { "EoE"/*"Offset"*/, "ecat_mailbox.eoe.offset",
1416 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}
1418 { &hf_ecat_mailbox_eoe_frame,
1419 { "EoE"/*"FrameNo"*/, "ecat_mailbox.eoe.frame",
1420 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1422 { &hf_ecat_mailbox_eoe_last,
1423 { "Last Fragment"/*"Last Fragment"*/, "ecat_mailbox.eoe.last",
1424 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1426 { &hf_ecat_mailbox_eoe_timestampapp,
1427 { "Last Fragment"/*"Last Fragment"*/, "ecat_mailbox.eoe.timestampapp",
1428 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1430 { &hf_ecat_mailbox_eoe_timestampreq,
1431 { "Last Fragment"/*"Last Fragment"*/, "ecat_mailbox.eoe.timestampreq",
1432 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1434 { &hf_ecat_mailbox_eoe_fragment,
1435 { "EoE Frag Data", "ecat_mailbox.eoe.fragment",
1436 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1438 { &hf_ecat_mailbox_eoe_init,
1439 { "Init", "ecat_mailbox.eoe.init",
1440 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
1470 { &hf_ecat_mailbox_eoe_init_macaddr,
1471 { "Mac Addr", "ecat_mailbox.eoe.init.macaddr",
1472 FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }
1474 { &hf_ecat_mailbox_eoe_init_ipaddr,
1475 { "Ip Addr", "ecat_mailbox.eoe.init.ipaddr",
1476 FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }
1478 { &hf_ecat_mailbox_eoe_init_subnetmask,
1479 { "Subnet Mask", "ecat_mailbox.eoe.init.subnetmask",
1480 FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }
1482 { &hf_ecat_mailbox_eoe_init_defaultgateway,
1483 { "Default Gateway", "ecat_mailbox.eoe.init.defaultgateway",
1484 FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }
1486 { &hf_ecat_mailbox_eoe_init_dnsserver,
1487 { "Dns Server", "ecat_mailbox.eoe.init.dnsserver",
1488 FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }
1490 { &hf_ecat_mailbox_eoe_init_dnsname,
1491 { "Dns Name", "ecat_mailbox.eoe.init.dnsname",
1492 FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
1494 { &hf_ecat_mailbox_eoe_macfilter,
1495 { "Mac Filter", "ecat_mailbox.eoe.macfilter",
1496 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
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 }
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 }
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 }
1515 { &hf_ecat_mailbox_eoe_macfilter_filter,
1516 { "Filter", "ecat_mailbox.eoe.macfilter.filter",
1517 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
1583 { &hf_ecat_mailbox_eoe_macfilter_filtermask,
1584 { "Filter Mask", "ecat_mailbox.eoe.macfilter.filtermask",
1585 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
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 }
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 }
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 }
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 }
1603 { &hf_ecat_mailbox_eoe_timestamp,
1604 { "Time Stamp", "ecat_mailbox.eoe.timestamp",
1605 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1607 { &hf_ecat_mailbox_coe,
1608 { "CoE", "ecat_mailbox.coe",
1609 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1611 { &hf_ecat_mailbox_coe_number,
1612 { "Number", "ecat_mailbox.coe.number",
1613 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1615 { &hf_ecat_mailbox_coe_type,
1616 { "Type", "ecat_mailbox.coe.type",
1617 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1619 { &hf_ecat_mailbox_coe_sdoreq,
1620 { "SDO Req", "ecat_mailbox.coe.sdoreq",
1621 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
1623 { &hf_ecat_mailbox_coe_sdoccsid,
1624 { "Initiate Download", "ecat_mailbox.coe.sdoccsid",
1625 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }
1627 { &hf_ecat_mailbox_coe_sdoccsid_sizeind,
1628 { "Size Ind.", "ecat_mailbox.coe.sdoccsid.sizeind",
1629 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
1632 { &hf_ecat_mailbox_coe_sdoccsid_expedited,
1633 { "Expedited", "ecat_mailbox.coe.sdoccsid.expedited",
1634 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000002,
1637 { &hf_ecat_mailbox_coe_sdoccsid_size0,
1638 { "Bytes", "ecat_mailbox.coe.sdoccsid.size0",
1639 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000004,
1642 { &hf_ecat_mailbox_coe_sdoccsid_size1,
1643 { "Bytes", "ecat_mailbox.coe.sdoccsid.size1",
1644 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000008,
1647 { &hf_ecat_mailbox_coe_sdoccsid_complete,
1648 { "Access", "ecat_mailbox.coe.sdoccsid.complete",
1649 FT_BOOLEAN, 8, TFS(&tfs_complete), 0x00000010,
1652 { &hf_ecat_mailbox_coe_sdoccsds,
1653 { "Download Segment", "ecat_mailbox.coe.sdoccsds",
1654 FT_UINT8, BASE_HEX, NULL, 0x0,
1657 { &hf_ecat_mailbox_coe_sdoccsds_lastseg,
1658 { "Last Segment", "ecat_mailbox.coe.sdoccsds.lastseg",
1659 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
1662 { &hf_ecat_mailbox_coe_sdoccsds_size,
1663 { "Size", "ecat_mailbox.coe.sdoccsds.size",
1664 FT_UINT8, BASE_DEC, NULL, 0x0000000E,
1667 { &hf_ecat_mailbox_coe_sdoccsds_toggle,
1668 { "Toggle Bit", "ecat_mailbox.coe.sdoccsds.toggle",
1669 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
1672 { &hf_ecat_mailbox_coe_sdoccsiu,
1673 { "Init Upload", "ecat_mailbox.coe.sdoccsiu",
1674 FT_UINT8, BASE_HEX, NULL, 0x0,
1678 { &hf_ecat_mailbox_coe_sdoccsiu_complete,
1679 { "Toggle Bit", "ecat_mailbox.coe.sdoccsiu_complete",
1680 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
1684 { &hf_ecat_mailbox_coe_sdoccsus,
1685 { "Upload Segment", "ecat_mailbox.coe.sdoccsus",
1686 FT_UINT8, BASE_HEX, NULL, 0x0,
1689 { &hf_ecat_mailbox_coe_sdoccsus_toggle,
1690 { "Toggle Bit", "ecat_mailbox.coe.sdoccsus_toggle",
1691 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
1695 { &hf_ecat_mailbox_coe_sdoidx,
1696 { "Index", "ecat_mailbox.coe.sdoidx",
1697 FT_UINT16, BASE_HEX, NULL, 0x0,
1700 { &hf_ecat_mailbox_coe_sdosub,
1701 { "SubIndex", "ecat_mailbox.coe.sdosub",
1702 FT_UINT8, BASE_HEX, NULL, 0x0,
1705 { &hf_ecat_mailbox_coe_sdodata,
1706 { "Data", "ecat_mailbox.coe.sdodata",
1707 FT_UINT32, BASE_HEX, NULL, 0x0,
1710 { &hf_ecat_mailbox_coe_sdodata1,
1711 { "Data", "ecat_mailbox.coe.sdodata",
1712 FT_UINT8, BASE_HEX, NULL, 0x0,
1715 { &hf_ecat_mailbox_coe_sdodata2,
1716 { "Data", "ecat_mailbox.coe.sdodata",
1717 FT_UINT16, BASE_HEX, NULL, 0x0,
1720 { &hf_ecat_mailbox_coe_sdoldata,
1721 { "Data", "ecat_mailbox.coe.dsoldata",
1722 FT_BYTES, BASE_NONE, NULL, 0x0,
1725 { &hf_ecat_mailbox_coe_sdolength,
1726 { "Length", "ecat_mailbox.coe.sdolength",
1727 FT_UINT32, BASE_HEX, NULL, 0x0,
1731 { &hf_ecat_mailbox_coe_sdoerror,
1732 { "SDO Error", "ecat_mailbox.coe.sdoerror",
1733 FT_UINT32, BASE_HEX, NULL, 0x0,
1737 { &hf_ecat_mailbox_coe_sdores,
1738 { "SDO Res", "ecat_mailbox.coe.sdores",
1739 FT_UINT8, BASE_DEC, NULL, 0x0,
1742 { &hf_ecat_mailbox_coe_sdoscsiu,
1743 { "Initiate Upload Response", "ecat_mailbox.coe.sdoscsiu",
1744 FT_UINT8, BASE_HEX, NULL, 0x0,
1747 { &hf_ecat_mailbox_coe_sdoscsiu_sizeind,
1748 { "Size Ind.", "ecat_mailbox.coe.sdoscsiu_sizeind",
1749 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
1752 { &hf_ecat_mailbox_coe_sdoscsiu_expedited,
1753 { "Expedited", "ecat_mailbox.coe.sdoscsiu_expedited",
1754 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000002,
1757 { &hf_ecat_mailbox_coe_sdoscsiu_size0,
1758 { "Bytes", "ecat_mailbox.coe.sdoscsiu_size0",
1759 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000004,
1762 { &hf_ecat_mailbox_coe_sdoscsiu_size1,
1763 { "Bytes", "ecat_mailbox.coe.sdoscsiu_size1",
1764 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000008,
1767 { &hf_ecat_mailbox_coe_sdoscsiu_complete,
1768 { "Access", "ecat_mailbox.coe.sdoscsiu_complete",
1769 FT_BOOLEAN, 8, TFS(&tfs_complete), 0x00000010,
1772 { &hf_ecat_mailbox_coe_sdoscsds,
1773 { "Download Segment Response", "ecat_mailbox.coe.sdoscsds",
1774 FT_UINT8, BASE_HEX, NULL, 0x0,
1777 { &hf_ecat_mailbox_coe_sdoscsds_toggle,
1778 { "Toggle Bit", "ecat_mailbox.coe.sdoscsds_toggle",
1779 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
1782 { &hf_ecat_mailbox_coe_sdoscsus,
1783 { "Upload Segment", "ecat_mailbox.coe.sdoscsus",
1784 FT_UINT8, BASE_HEX, NULL, 0x0,
1787 { &hf_ecat_mailbox_coe_sdoscsus_lastseg,
1788 { "Last Segment", "ecat_mailbox.coe.sdoscsus_lastseg",
1789 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000001,
1792 { &hf_ecat_mailbox_coe_sdoscsus_bytes,
1793 { "Bytes", "ecat_mailbox.coe.sdoscsus_bytes",
1794 FT_UINT8, BASE_DEC, NULL, 0x0000000E,
1797 { &hf_ecat_mailbox_coe_sdoscsus_toggle,
1798 { "Toggle Bit", "ecat_mailbox.coe.sdoscsus_toggle",
1799 FT_BOOLEAN, 8, TFS(&flags_set_truth), 0x00000010,
1802 { &hf_ecat_mailbox_coe_sdoinfoopcode,
1803 { "Info OpCode", "ecat_mailbox.coe.sdoinfoopcode",
1804 FT_UINT8, BASE_HEX, NULL, 0x0,
1807 { &hf_ecat_mailbox_coe_sdoinfofrag,
1808 { "Info Frag Left", "ecat_mailbox.coe.sdoinfofrag",
1809 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1811 { &hf_ecat_mailbox_coe_sdoinfolisttype,
1812 { "Info List Type", "ecat_mailbox.coe.sdoinfolisttype",
1813 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1815 { &hf_ecat_mailbox_coe_sdoinfolist,
1816 { "Info List", "ecat_mailbox.coe.sdoinfolist",
1817 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL },
1819 { &hf_ecat_mailbox_coe_sdoinfoindex,
1820 { "Info Obj Index", "ecat_mailbox.coe.sdoinfoindex",
1821 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1823 { &hf_ecat_mailbox_coe_sdoinfosubindex,
1824 { "Info Obj SubIdx", "ecat_mailbox.coe.sdoinfosubindex",
1825 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL },
1827 { &hf_ecat_mailbox_coe_sdoinfovalueinfo,
1828 { "Info Obj SubIdx", "ecat_mailbox.coe.sdoinfovalueinfo",
1829 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL },
1831 { &hf_ecat_mailbox_coe_sdoinfoerrorcode,
1832 { "Info Error Code", "ecat_mailbox.coe.sdoinfoerrorcode",
1833 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL },
1835 { &hf_ecat_mailbox_coe_sdoinfodatatype,
1836 { "Info Data Type", "ecat_mailbox.coe.sdoinfodatatype",
1837 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1839 { &hf_ecat_mailbox_coe_sdoinfomaxsub,
1840 { "Info Max SubIdx", "ecat_mailbox.coe.sdoinfomaxsub",
1841 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL },
1843 { &hf_ecat_mailbox_coe_sdoinfoobjcode,
1844 { "Info Obj Code", "ecat_mailbox.coe.sdoinfoobjcode",
1845 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL },
1847 { &hf_ecat_mailbox_coe_sdoinfoname,
1848 { "Info Name", "ecat_mailbox.coe.sdoinfoname",
1849 FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL },
1851 { &hf_ecat_mailbox_coe_sdoinfobitlen,
1852 { "Info Bit Len", "ecat_mailbox.coe.sdoinfobitlen",
1853 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1855 { &hf_ecat_mailbox_coe_sdoinfoobjaccess,
1856 { "Info Obj Access", "ecat_mailbox.coe.sdoinfoobjaccess",
1857 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1859 { &hf_ecat_mailbox_coe_sdoinfounittype,
1860 { "Info Data Type", "ecat_mailbox.coe.sdoinfounittype",
1861 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
1863 { &hf_ecat_mailbox_coe_sdoinfodefaultvalue,
1864 { "Info Default Val", "ecat_mailbox.coe.sdoinfodefaultvalue",
1865 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL },
1867 { &hf_ecat_mailbox_coe_sdoinfominvalue,
1868 { "Info Min Val", "ecat_mailbox.coe.sdoinfominvalue",
1869 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL },
1871 { &hf_ecat_mailbox_coe_sdoinfomaxvalue,
1872 { "Info Max Val", "ecat_mailbox.coe.sdoinfomaxvalue",
1873 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL },
1875 { &hf_ecat_mailboxdata,
1876 { "MB Data", "ecat_mailbox.data",
1877 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
1879 { &hf_ecat_mailbox_foe,
1880 { "Foe", "ecat_mailbox.foe",
1881 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1883 { &hf_ecat_mailbox_foe_opmode,
1884 { "Foe OpMode", "ecat_mailbox.foe_opmode",
1885 FT_UINT8, BASE_HEX, VALS(FoEOpMode), 0x0, "Op modes", HFILL }
1887 { &hf_ecat_mailbox_foe_filelength,
1888 { "Foe FileLength" , "ecat_mailbox.foe_filelength",
1889 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1891 { &hf_ecat_mailbox_foe_filename,
1892 { "Foe FileName", "ecat_mailbox.foe_filename",
1893 FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
1895 { &hf_ecat_mailbox_foe_packetno,
1896 { "Foe PacketNo", "ecat_mailbox.foe_packetno",
1897 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1899 { &hf_ecat_mailbox_foe_errcode,
1900 { "Foe ErrorCode", "ecat_mailbox.foe_errcode",
1901 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
1903 { &hf_ecat_mailbox_foe_errtext,
1904 { "Foe ErrorString", "ecat_mailbox.foe_errtext",
1905 FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
1907 { &hf_ecat_mailbox_foe_busydone,
1908 { "Foe BusyDone", "ecat_mailbox.foe_busydone",
1909 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
1911 { &hf_ecat_mailbox_foe_busyentire,
1912 { "Foe BusyEntire", "ecat_mailbox.foe_busyentire",
1913 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
1915 { &hf_ecat_mailbox_foe_data,
1916 { "Foe Data", "ecat_mailbox.foe_busydata",
1917 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1919 { &hf_ecat_mailbox_foe_efw,
1920 { "Firmware", "ecat_mailbox.foe.efw",
1921 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1923 { &hf_ecat_mailbox_foe_efw_cmd,
1924 { "Cmd", "ecat_mailbox.foe.efw.cmd",
1925 FT_UINT16, BASE_HEX, VALS(FoEEfwCmd), 0x0, NULL, HFILL }
1927 { &hf_ecat_mailbox_foe_efw_size,
1928 { "Size", "ecat_mailbox.foe.efw.size",
1929 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
1931 { &hf_ecat_mailbox_foe_efw_addresslw,
1932 { "AddressLW", "ecat_mailbox.foe.efw.addresslw",
1933 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
1935 { &hf_ecat_mailbox_foe_efw_addresshw,
1936 { "AddressHW", "ecat_mailbox.foe.efw.addresshw",
1937 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
1939 { &hf_ecat_mailbox_foe_efw_data,
1940 { "Data", "ecat_mailbox.foe.efw.data",
1941 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1943 { &hf_ecat_mailbox_soe,
1944 { "Soe", "ecat_mailbox.soe",
1945 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
1947 { &hf_ecat_mailbox_soe_header,
1948 { "Soe Header", "ecat_mailbox.soe_header",
1949 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
1951 { &hf_ecat_mailbox_soe_header_opcode,
1952 { "SoE OpCode", "ecat_mailbox.soe_opcode",
1953 FT_UINT16, BASE_DEC, VALS(SoeOpcode), 0x00000007, NULL, HFILL }
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 }
1959 { &hf_ecat_mailbox_soe_header_error,
1960 { "Error", "ecat_mailbox.soe_header_error",
1961 FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000010,
1964 { &hf_ecat_mailbox_soe_header_driveno,
1965 { "Drive No", "ecat_mailbox.soe_header_driveno",
1966 FT_UINT16, BASE_DEC, NULL, 0x000000e0, NULL, HFILL }
1968 { &hf_ecat_mailbox_soe_header_datastate,
1969 { "Datastate", "ecat_mailbox.soe_header_datastate",
1970 FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000100,
1973 { &hf_ecat_mailbox_soe_header_name,
1974 { "Name", "ecat_mailbox.soe_header_name",
1975 FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000200,
1978 { &hf_ecat_mailbox_soe_header_attribute,
1979 { "Attribute", "ecat_mailbox.soe_header_attribute",
1980 FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000400,
1983 { &hf_ecat_mailbox_soe_header_unit,
1984 { "Unit", "ecat_mailbox.soe_header_unit",
1985 FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00000800,
1988 { &hf_ecat_mailbox_soe_header_min,
1989 { "Min", "ecat_mailbox.soe_header_min",
1990 FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00001000,
1993 { &hf_ecat_mailbox_soe_header_max,
1994 { "Max", "ecat_mailbox.soe_header_max",
1995 FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00002000,
1998 { &hf_ecat_mailbox_soe_header_value,
1999 { "Value", "ecat_mailbox.soe_header_value",
2000 FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00004000,
2003 { &hf_ecat_mailbox_soe_header_reserved,
2004 { "Reserved", "ecat_mailbox.soe_header_reserved",
2005 FT_BOOLEAN, 16, TFS(&flags_set_truth), 0x00008000,
2008 { &hf_ecat_mailbox_soe_idn,
2009 { "SoE IDN", "ecat_mailbox.soe_idn",
2010 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
2012 { &hf_ecat_mailbox_soe_data,
2013 { "SoE Data", "ecat_mailbox.soe_data",
2014 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
2016 { &hf_ecat_mailbox_soe_frag,
2017 { "SoE FragLeft", "ecat_mailbox.soe_frag",
2018 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
2020 { &hf_ecat_mailbox_soe_error,
2021 { "SoE Error", "ecat_mailbox.soe_error",
2022 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
2026 static gint *ett[] =
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
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));
2051 register_dissector("ecat_mailbox", dissect_ecat_mailbox, proto_ecat_mailbox);
2054 void proto_reg_handoff_ecat_mailbox(void)
2056 dissector_handle_t ecat_mailbox_handle;
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);
2062 eth_handle = find_dissector("eth_withoutfcs");
2063 ams_handle = find_dissector("ams");