3 * Copyright (c) 2007 by Beckhoff Automation GmbH
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
11 #ifndef _PACKET_ECATMAILBOX_H_
12 #define _PACKET_ECATMAILBOX_H_
14 #include <ws_diag_control.h>
17 /* Ensure the same data layout for all platforms */
19 typedef struct TETHERNET_ADDRESS
22 } ETHERNET_ADDRESS
, *PETHERNET_ADDRESS
;
23 #define ETHERNET_ADDRESS_LEN ((int) sizeof(ETHERNET_ADDRESS))
26 #define ETHERCAT_MBOX_TYPE_ADS 1 /* AMS/ADS header follows*/
27 #define ETHERCAT_MBOX_TYPE_EOE 2 /* ETHERCAT_EOE_HEADER follows*/
28 #define ETHERCAT_MBOX_TYPE_COE 3 /* ETHERCAT_COE_HEADER follows*/
29 #define ETHERCAT_MBOX_TYPE_FOE 4 /* ETHERCAT_FOE_HEADER follows*/
30 #define ETHERCAT_MBOX_TYPE_SOE 5 /* ETHERCAT_SOE_HEADER follows*/
32 typedef union tMbxHeaderControlUnion
37 uint16_t Channel
: 6; /* optional communication channels (default = 0)*/
38 uint16_t Priority
: 2; /* optional communication priority (default = 0)*/
39 uint16_t Type
: 4; /* TETHERCAT_MBOX_TYPE_xxx*/
40 uint16_t Counter
: 3; /* 0 = counter not used (old version)*/
41 uint16_t Unsupported
: 1; /* unsupported protocol detected*/
43 } MbxHeaderControlUnion
;
45 typedef struct TETHERCAT_MBOX_HEADER
47 uint16_t Length
; /* following bytes*/
48 uint16_t Address
; /* S->M: phys addr of destination; M->S: phys addr of source; 0 = master*/
49 MbxHeaderControlUnion aControlUnion
;
50 } ETHERCAT_MBOX_HEADER
, *PETHERCAT_MBOX_HEADER
;
52 #define ETHERCAT_MBOX_HEADER_LEN ((int) sizeof(ETHERCAT_MBOX_HEADER))
55 #define ETHERNET_FRAMENO_MASK 0x0000000F
57 #define EOE_TYPE_FRAME_FRAG 0 /* ETHERCAT_EOE_HEADER followed by frame fragment (ETHERCAT_EOE_TIMESTAMP may included) */
58 #define EOE_TYPE_TIMESTAMP_RES 1 /* ETHERCAT_EOE_HEADER followed by ETHERCAT_EOE_TIMESTAMP */
59 #define EOE_TYPE_INIT_REQ 2 /* ETHERCAT_EOE_HEADER followed by ETHERCAT_EOE_INIT */
60 #define EOE_TYPE_INIT_RES 3 /* ETHERCAT_EOE_HEADER */
61 #define EOE_TYPE_MACFILTER_REQ 4 /* ETHERCAT_EOE_HEADER followed by ETHERCAT_EOE_MACFILTER */
62 #define EOE_TYPE_MACFILTER_RES 5 /* ETHERCAT_EOE_HEADER */
64 #define EOE_RESULT_NOERROR 0x0000
65 #define EOE_RESULT_UNSPECIFIED_ERROR 0x0001
66 #define EOE_RESULT_UNSUPPORTED_TYPE 0x0002
67 #define EOE_RESULT_NO_IP_SUPPORT 0x0201
68 #define EOE_RESULT_NO_MACFILTERMASK_SUPPORT 0x0401
71 /*typedef struct TETHERCAT_EOE_INIT
73 uint32_t ContainsMacAddr :1;
74 uint32_t ContainsIpAddr :1;
75 uint32_t ContainsSubnetMask :1;
76 uint32_t ContainsDefaultGateway :1;
77 uint32_t ContainsDnsServer :1;
78 uint32_t ContainsDnsName :1;
79 uint32_t Reserved :26;
80 ETHERNET_ADDRESS MacAddr;
83 uint32_t DefaultGateway;
86 } ETHERCAT_EOE_INIT, *PETHERCAT_EOE_INIT;*/
87 #define ETHERCAT_EOE_INIT_LEN 58 /*sizeof(ETHERCAT_EOE_INIT)*/
89 typedef union tEoeMacFilterOptionsUnion
93 uint16_t MacFilterCount
:4;
94 uint16_t MacFilterMaskCount
:2;
95 uint16_t Reserved1
:1;
96 uint16_t NoBroadcasts
:1;
97 uint16_t Reserved2
:8;
100 } EoeMacFilterOptionsUnion
;
102 typedef struct TETHERCAT_EOE_MACFILTER
104 EoeMacFilterOptionsUnion anEoeMacFilterOptionsUnion
;
105 ETHERNET_ADDRESS MacFilter
[16];
106 ETHERNET_ADDRESS MacFilterMask
[4];
107 } ETHERCAT_EOE_MACFILTER
;
108 #define ETHERCAT_EOE_MACFILTER_LEN ((int) sizeof(ETHERCAT_EOE_MACFILTER))
110 typedef struct TETHERCAT_EOE_TIMESTAMP
112 uint32_t TimeStamp
; /* 32 bit time stamp */
113 } ETHERCAT_EOE_TIMESTAMP
;
114 #define ETHERCAT_EOE_TIMESTAMP_LEN ((int) sizeof(ETHERCAT_EOE_TIMESTAMP))
116 typedef union tEoeHeaderDataUnion
119 { /* EOE_TYPE_FRAME_FRAG and EOE_TYPE_TIMESTAMP_RES only */
120 uint16_t Fragment
: 6; /* fragment number (EOE_TYPE_FRAME_FRAG only) */
121 uint16_t OffsetBuffer
: 6; /* byte offset multiplied by 32 (if Fragment != 0) (EOE_TYPE_FRAME_FRAG only) */
122 /* buffer size multiplied by 32 (if Fragment == 0) (EOE_TYPE_FRAME_FRAG only) */
123 uint16_t FrameNo
: 4; /* frame number (EOE_TYPE_FRAME_FRAG and EOE_TYPE_TIMESTAMP_RES only) */
125 uint16_t Result
; /* EOE_TYPE_INIT_RES and EOE_TYPE_MACFILTER_RES only */
126 } EoeHeaderDataUnion
;
128 typedef union tEoeHeaderInfoUnion
132 uint16_t Type
: 4; /* specifies following data */
133 uint16_t PortAssign
: 4; /* 0 = unspecified, 1 = port 1 */
134 uint16_t LastFragment
: 1; /* true if last fragment (EOE_TYPE_FRAME_FRAG only) */
135 uint16_t TimeStampAppended
: 1; /* 32 bit time stamp appended (EOE_TYPE_FRAME_FRAG with LastFragment=1 only) */
136 uint16_t TimeStampRequested
: 1; /* time stamp response requested (EOE_TYPE_FRAME_FRAG only) */
137 uint16_t Reserved
: 5;
140 } EoeHeaderInfoUnion
;
142 typedef struct TETHERCAT_EOE_HEADER
144 EoeHeaderInfoUnion anEoeHeaderInfoUnion
;
145 EoeHeaderDataUnion anEoeHeaderDataUnion
;
146 } ETHERCAT_EOE_HEADER
, *PETHERCAT_EOE_HEADER
;
147 #define ETHERCAT_EOE_HEADER_LEN ((int) sizeof(ETHERCAT_EOE_HEADER))
150 #define ETHERCAT_COE_TYPE_EMERGENCY 1
151 #define ETHERCAT_COE_TYPE_SDOREQ 2
152 #define ETHERCAT_COE_TYPE_SDORES 3
153 #define ETHERCAT_COE_TYPE_TXPDO 4
154 #define ETHERCAT_COE_TYPE_RXPDO 5
155 #define ETHERCAT_COE_TYPE_TXPDO_RTR 6 /* Remote transmission request of TXPDO (master requested)*/
156 #define ETHERCAT_COE_TYPE_RXPDO_RTR 7 /* Remote transmission request of RXPDO (slave requested) */
157 #define ETHERCAT_COE_TYPE_SDOINFO 8
159 typedef union TETHERCAT_COE_HEADER
163 uint16_t Number
: 9; /* e.g. PDO number*/
164 uint16_t Reserved
: 3; /* = 0*/
165 uint16_t Type
: 4; /* CANopen type*/
168 } ETHERCAT_COE_HEADER
, *PETHERCAT_COE_HEADER
;
169 #define ETHERCAT_COE_HEADER_LEN ((int) sizeof(ETHERCAT_COE_HEADER))
172 typedef union tSdoHeaderUnion
175 { /* Initiate Download Request*/
177 uint8_t Expedited
: 1;
179 uint8_t Complete
: 1;
180 uint8_t Ccs
: 3; /* = 1*/
183 { /* Initiate Download Response*/
184 uint8_t Reserved
: 5;
185 uint8_t Scs
: 3; /* = 3*/
188 { /* Download Segment Request*/
192 uint8_t Ccs
: 3; /* = 0*/
195 { /* Download Segment Response*/
196 uint8_t Reserved
: 4;
198 uint8_t Scs
: 3; /* = 1*/
201 { /* Initiate Upload Request*/
202 uint8_t Reserved
: 4;
203 uint8_t Complete
: 1;
204 uint8_t Ccs
: 3; /* = 2*/
207 { /* Initiate Upload Response*/
209 uint8_t Expedited
: 1;
211 uint8_t Complete
: 1;
212 uint8_t Scs
: 3; /* = 2*/
215 { /* Upload Segment Request*/
216 uint8_t Reserved
: 4;
218 uint8_t Ccs
: 3; /* = 3*/
221 { /* Upload Segment Response*/
225 uint8_t Scs
: 3; /* = 0*/
228 { /* Abort Transfer*/
229 uint8_t Reserved
: 5;
230 uint8_t Ccs
: 3; /* = 4*/
235 typedef struct TETHERCAT_SDO_HEADER
237 SdoHeaderUnion anSdoHeaderUnion
;
242 } ETHERCAT_SDO_HEADER
, *PETHERCAT_SDO_HEADER
;
244 #define ETHERCAT_SDO_HEADER_LEN 8 /* sizeof(ETHERCAT_SDO_HEADER)*/
246 #define SDO_CCS_DOWNLOAD_SEGMENT 0
247 #define SDO_CCS_INITIATE_DOWNLOAD 1
248 #define SDO_CCS_INITIATE_UPLOAD 2
249 #define SDO_CCS_UPLOAD_SEGMENT 3
250 #define SDO_CCS_ABORT_TRANSFER 4
252 #define SDO_SCS_UPLOAD_SEGMENT 0
253 #define SDO_SCS_DOWNLOAD_SEGMENT 1
254 #define SDO_SCS_INITIATE_UPLOAD 2
255 #define SDO_SCS_INITIATE_DOWNLOAD 3
257 /* CoE SDO Information */
258 #define ECAT_COE_INFO_OPCODE_LIST_Q 1
259 #define ECAT_COE_INFO_OPCODE_LIST_S 2
260 #define ECAT_COE_INFO_OPCODE_OBJ_Q 3
261 #define ECAT_COE_INFO_OPCODE_OBJ_S 4
262 #define ECAT_COE_INFO_OPCODE_ENTRY_Q 5
263 #define ECAT_COE_INFO_OPCODE_ENTRY_S 6
264 #define ECAT_COE_INFO_OPCODE_ERROR_S 7
266 #define ECAT_COE_INFO_LIST_TYPE_LENGTH 0
267 #define ECAT_COE_INFO_LIST_TYPE_ALL 1
268 #define ECAT_COE_INFO_LIST_TYPE_PDOMAP 2
269 #define ECAT_COE_INFO_LIST_TYPE_BACKUP 3
271 #define ECAT_COE_INFO_OBJCODE_NULL 0
272 #define ECAT_COE_INFO_OBJCODE_DOMAIN 2
273 #define ECAT_COE_INFO_OBJCODE_DEFTYPE 5
274 #define ECAT_COE_INFO_OBJCODE_DEFSTRUCT 6
275 #define ECAT_COE_INFO_OBJCODE_VAR 7
276 #define ECAT_COE_INFO_OBJCODE_ARRAY 8
277 #define ECAT_COE_INFO_OBJCODE_RECORD 9
279 #define ECAT_COE_INFO_OBJCAT_OPTIONAL 0
280 #define ECAT_COE_INFO_OBJCAT_MANDATORY 1
282 #define ECAT_COE_INFO_OBJACCESS_RO 0x07
283 #define ECAT_COE_INFO_OBJACCESS_RW 0x3f
285 typedef struct TETHERCAT_SDO_INFO_LIST
287 uint16_t ListType
; /* == SDO_INFO_LIST_TYPE_XXX */
292 } ETHERCAT_SDO_INFO_LIST
;
294 typedef struct TETHERCAT_SDO_INFO_OBJ
299 uint16_t DataType
; /* refer to data type index */
300 uint8_t MaxSubIndex
; /* max subIndex */
301 uint8_t ObjCode
; /* defined in DS 301 (Table 37)*/
302 char Name
[1]; /* rest of mailbox data*/
304 } ETHERCAT_SDO_INFO_OBJ
;
306 typedef struct TETHERCAT_SDO_INFO_ENTRY
310 uint8_t ValueInfo
; /* bit0 = ObjAccess, bit1 = ObjCategory, bit2 = PdoMapping, bit3 = UnitType
311 bit4 = DefaultValue, bit5 = MinValue, bit6 = MaxValue*/
314 uint16_t DataType
; /* refer to data type index */
316 uint16_t ObjAccess
; /* bit0 = read; bit1 = write; bit2 = const. bit3 = 'PRE-OP'; bit4 = 'SAFE-OP'; bit5 = 'OP'.*/
318 } ETHERCAT_SDO_INFO_ENTRY
;
320 typedef struct TETHERCAT_SDO_INFO_ERROR
323 char ErrorText
[1]; /* rest of mailbox data */
324 } ETHERCAT_SDO_INFO_ERROR
;
326 typedef union tSdoInfoUnion
328 ETHERCAT_SDO_INFO_LIST List
;
329 ETHERCAT_SDO_INFO_OBJ Obj
;
330 ETHERCAT_SDO_INFO_ENTRY Entry
;
331 ETHERCAT_SDO_INFO_ERROR Error
;
335 typedef union tSdoControlUnion
339 uint8_t OpCode
: 7; /* == SDO_INFO_TYPE_XXX */
340 uint8_t InComplete
: 1;
345 typedef struct TETHERCAT_SDO_INFO_HEADER
347 SdoControlUnion anSdoControlUnion
;
348 uint8_t Reserved
; /* == 0 */
349 uint16_t FragmentsLeft
;
350 SdoInfoUnion anSdoInfoUnion
;
351 } ETHERCAT_SDO_INFO_HEADER
, *PETHERCAT_SDO_INFO_HEADER
;
353 #define ETHERCAT_SDO_INFO_LISTREQ_LEN 6 /*offsetof(ETHERCAT_SDO_INFO_HEADER, anSdoInfoUnion.List.Res)*/
355 /* FoE (File Access over EtherCAT)*/
356 #define ECAT_FOE_OPMODE_RRQ 1
357 #define ECAT_FOE_OPMODE_WRQ 2
358 #define ECAT_FOE_OPMODE_DATA 3
359 #define ECAT_FOE_OPMODE_ACK 4
360 #define ECAT_FOE_OPMODE_ERR 5
361 #define ECAT_FOE_OPMODE_BUSY 6
363 #define ECAT_FOE_ERRCODE_NOTDEFINED 0
364 #define ECAT_FOE_ERRCODE_NOTFOUND 1
365 #define ECAT_FOE_ERRCODE_ACCESS 2
366 #define ECAT_FOE_ERRCODE_DISKFULL 3
367 #define ECAT_FOE_ERRCODE_ILLEAGAL 4
368 #define ECAT_FOE_ERRCODE_PACKENO 5
369 #define ECAT_FOE_ERRCODE_EXISTS 6
370 #define ECAT_FOE_ERRCODE_NOUSER 7
371 #define ECAT_FOE_ERRCODE_BOOTSTRAPONLY 8
372 #define ECAT_FOE_ERRCODE_NOTINBOOTSTRAP 9
374 typedef union tFoeHeaderDataUnion
376 uint32_t FileLength
; /* (RRQ, WRQ) = 0 if unknown */
379 uint16_t PacketNo
; /* (DATA, ACK)*/
380 uint16_t Reserved2
; /* (DATA, ACK)*/
382 uint32_t ErrorCode
; /* (ERR)*/
385 uint16_t Done
; /* (BUSY)*/
386 uint16_t Entire
; /* (BUSY)*/
388 } FoeHeaderDataUnion
;
390 typedef struct TETHERCAT_FOE_HEADER
392 uint8_t OpMode
; /* = 1 (RRQ), = 2 (WRQ), = 3 (DATA), = 4 (ACK), = 5 (ERR), = 6 (BUSY) */
393 uint8_t Reserved1
; /* = 0 */
395 FoeHeaderDataUnion aFoeHeaderDataUnion
;
396 /* typedef union tMailBoxDataUnion
398 char Name[] (RRQ, WRQ) rest of mailbox data
399 uint8_t Data[] (DATA) rest of mailbox data (if OpMode = 3)
400 char ErrorText[] (ERR) rest of mailbox data
401 } MailBoxDataUnion;*/
402 } ETHERCAT_FOE_HEADER
, *PETHERCAT_FOE_HEADER
;
403 #define ETHERCAT_FOE_HEADER_LEN 6 /*sizeof(ETHERCAT_FOE_HEADER)*/
414 /* SoE (SOE over EtherCAT)*/
415 #define ECAT_SOE_OPCODE_RRQ 1
416 #define ECAT_SOE_OPCODE_RRS 2
417 #define ECAT_SOE_OPCODE_WRQ 3
418 #define ECAT_SOE_OPCODE_WRS 4
419 #define ECAT_SOE_OPCODE_NFC 5
422 typedef union tSoeHeaderControlUnion
426 uint8_t OpCode
: 3; /* 0 = unused, 1 = readReq, 2 = readRes, 3 = writeReq, 4 = writeRes
427 5 = notification (command changed notification)*/
428 uint8_t InComplete
: 1; /* more follows*/
429 uint8_t Error
: 1; /* an error word follows */
430 uint8_t DriveNo
: 3; /* drive number */
432 uint8_t DataState
: 1; /* follows or requested */
433 uint8_t Name
: 1; /* follows or requested */
434 uint8_t Attribute
: 1; /* follows or requested */
435 uint8_t Unit
: 1; /* follows or requested */
436 uint8_t Min
: 1; /* follows or requested */
437 uint8_t Max
: 1; /* follows or requested */
438 uint8_t Value
: 1; /* follows or requested */
439 uint8_t Reserved
: 1;
446 } SoeHeaderControlUnion
;
448 typedef union tSoeHeaderDataUnion
450 uint16_t IDN
; /* SOE IDN if (InComplete==0) */
451 uint16_t FragmentsLeft
; /* Pending fragments if (InComplete==1) */
452 } SoeHeaderDataUnion
;
454 typedef struct TETHERCAT_SOE_HEADER
456 SoeHeaderControlUnion anSoeHeaderControlUnion
;
457 SoeHeaderDataUnion anSoeHeaderDataUnion
;
458 /* typedef union tMailBoxDataUnion
460 uint8_t Data[] rest of mailbox data if (Error==0)
461 uint16_t ErrorCode if (Error==1)
462 } MailBoxDataUnion;*/
463 } ETHERCAT_SOE_HEADER
, *PETHERCAT_SOE_HEADER
;
464 #define ETHERCAT_SOE_HEADER_LEN ((int) sizeof(ETHERCAT_SOE_HEADER))
466 extern void init_mbx_header(PETHERCAT_MBOX_HEADER pMbox
, tvbuff_t
*tvb
, int offset
);
469 #endif /* _PACKET_ECATMAILBOX_H_ */