Wireshark  4.3.0
The Wireshark network protocol analyzer
packet-ecatmb.h
1 /* packet-ecatmb.h
2  *
3  * Copyright (c) 2007 by Beckhoff Automation GmbH
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11 #ifndef _PACKET_ECATMAILBOX_H_
12 #define _PACKET_ECATMAILBOX_H_
13 
14 #include <ws_diag_control.h>
15 DIAG_OFF_PEDANTIC
16 
17 /* Ensure the same data layout for all platforms */
18 
19 typedef struct TETHERNET_ADDRESS
20 {
21  guint8 b[6];
22 } ETHERNET_ADDRESS, *PETHERNET_ADDRESS;
23 #define ETHERNET_ADDRESS_LEN ((int) sizeof(ETHERNET_ADDRESS))
24 
25 /* Mailbox*/
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*/
31 
33 {
34  guint16 Control;
35  struct
36  {
37  guint16 Channel : 6; /* optional communication channels (default = 0)*/
38  guint16 Priority : 2; /* optional communication priority (default = 0)*/
39  guint16 Type : 4; /* TETHERCAT_MBOX_TYPE_xxx*/
40  guint16 Counter : 3; /* 0 = counter not used (old version)*/
41  guint16 Unsupported : 1; /* unsupported protocol detected*/
42  } v;
44 
45 typedef struct TETHERCAT_MBOX_HEADER
46 {
47  guint16 Length; /* following bytes*/
48  guint16 Address; /* S->M: phys addr of destination; M->S: phys addr of source; 0 = master*/
49  MbxHeaderControlUnion aControlUnion;
51 
52 #define ETHERCAT_MBOX_HEADER_LEN ((int) sizeof(ETHERCAT_MBOX_HEADER))
53 
54 /* EoE*/
55 #define ETHERNET_FRAMENO_MASK 0x0000000F
56 
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 */
63 
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
69 
70 
71 /*typedef struct TETHERCAT_EOE_INIT
72 {
73  guint32 ContainsMacAddr :1;
74  guint32 ContainsIpAddr :1;
75  guint32 ContainsSubnetMask :1;
76  guint32 ContainsDefaultGateway :1;
77  guint32 ContainsDnsServer :1;
78  guint32 ContainsDnsName :1;
79  guint32 Reserved :26;
80  ETHERNET_ADDRESS MacAddr;
81  guint32 IpAddr;
82  guint32 SubnetMask;
83  guint32 DefaultGateway;
84  guint32 DnsServer;
85  char DnsName[32];
86 } ETHERCAT_EOE_INIT, *PETHERCAT_EOE_INIT;*/
87 #define ETHERCAT_EOE_INIT_LEN 58 /*sizeof(ETHERCAT_EOE_INIT)*/
88 
90 {
91  struct
92  {
93  guint16 MacFilterCount :4;
94  guint16 MacFilterMaskCount :2;
95  guint16 Reserved1 :1;
96  guint16 NoBroadcasts :1;
97  guint16 Reserved2 :8;
98  } v;
99  guint16 Options;
101 
103 {
104  EoeMacFilterOptionsUnion anEoeMacFilterOptionsUnion;
105  ETHERNET_ADDRESS MacFilter[16];
106  ETHERNET_ADDRESS MacFilterMask[4];
108 #define ETHERCAT_EOE_MACFILTER_LEN ((int) sizeof(ETHERCAT_EOE_MACFILTER))
109 
111 {
112  guint32 TimeStamp; /* 32 bit time stamp */
114 #define ETHERCAT_EOE_TIMESTAMP_LEN ((int) sizeof(ETHERCAT_EOE_TIMESTAMP))
115 
116 typedef union tEoeHeaderDataUnion
117 {
118  struct
119  { /* EOE_TYPE_FRAME_FRAG and EOE_TYPE_TIMESTAMP_RES only */
120  guint16 Fragment : 6; /* fragment number (EOE_TYPE_FRAME_FRAG only) */
121  guint16 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  guint16 FrameNo : 4; /* frame number (EOE_TYPE_FRAME_FRAG and EOE_TYPE_TIMESTAMP_RES only) */
124  } v;
125  guint16 Result; /* EOE_TYPE_INIT_RES and EOE_TYPE_MACFILTER_RES only */
127 
128 typedef union tEoeHeaderInfoUnion
129 {
130  struct
131  {
132  guint16 Type : 4; /* specifies following data */
133  guint16 PortAssign : 4; /* 0 = unspecified, 1 = port 1 */
134  guint16 LastFragment : 1; /* TRUE if last fragment (EOE_TYPE_FRAME_FRAG only) */
135  guint16 TimeStampAppended : 1; /* 32 bit time stamp appended (EOE_TYPE_FRAME_FRAG with LastFragment=1 only) */
136  guint16 TimeStampRequested : 1; /* time stamp response requested (EOE_TYPE_FRAME_FRAG only) */
137  guint16 Reserved : 5;
138  } v;
139  guint16 Info;
141 
142 typedef struct TETHERCAT_EOE_HEADER
143 {
144  EoeHeaderInfoUnion anEoeHeaderInfoUnion;
145  EoeHeaderDataUnion anEoeHeaderDataUnion;
147 #define ETHERCAT_EOE_HEADER_LEN ((int) sizeof(ETHERCAT_EOE_HEADER))
148 
149 /* CANopen*/
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
158 
159 typedef union TETHERCAT_COE_HEADER
160 {
161  struct
162  {
163  guint16 Number : 9; /* e.g. PDO number*/
164  guint16 Reserved : 3; /* = 0*/
165  guint16 Type : 4; /* CANopen type*/
166  } v;
167  guint16 header;
169 #define ETHERCAT_COE_HEADER_LEN ((int) sizeof(ETHERCAT_COE_HEADER))
170 
171 
172 typedef union tSdoHeaderUnion
173 {
174  struct
175  { /* Initiate Download Request*/
176  guint8 SizeInd : 1;
177  guint8 Expedited : 1;
178  guint8 Size : 2;
179  guint8 Complete : 1;
180  guint8 Ccs : 3; /* = 1*/
181  } Idq;
182  struct
183  { /* Initiate Download Response*/
184  guint8 Reserved : 5;
185  guint8 Scs : 3; /* = 3*/
186  } Ids;
187  struct
188  { /* Download Segment Request*/
189  guint8 LastSeg : 1;
190  guint8 Size : 3;
191  guint8 Toggle : 1;
192  guint8 Ccs : 3; /* = 0*/
193  } Dsq;
194  struct
195  { /* Download Segment Response*/
196  guint8 Reserved : 4;
197  guint8 Toggle : 1;
198  guint8 Scs : 3; /* = 1*/
199  } Dss;
200  struct
201  { /* Initiate Upload Request*/
202  guint8 Reserved : 4;
203  guint8 Complete : 1;
204  guint8 Ccs : 3; /* = 2*/
205  } Iuq;
206  struct
207  { /* Initiate Upload Response*/
208  guint8 SizeInd : 1;
209  guint8 Expedited : 1;
210  guint8 Size : 2;
211  guint8 Complete : 1;
212  guint8 Scs : 3; /* = 2*/
213  } Ius;
214  struct
215  { /* Upload Segment Request*/
216  guint8 Reserved : 4;
217  guint8 Toggle : 1;
218  guint8 Ccs : 3; /* = 3*/
219  } Usq;
220  struct
221  { /* Upload Segment Response*/
222  guint8 LastSeg : 1;
223  guint8 Bytes : 3;
224  guint8 Toggle : 1;
225  guint8 Scs : 3; /* = 0*/
226  } Uss;
227  struct
228  { /* Abort Transfer*/
229  guint8 Reserved : 5;
230  guint8 Ccs : 3; /* = 4*/
231  } Abt;
232  guint8 CS;
234 
235 typedef struct TETHERCAT_SDO_HEADER
236 {
237  SdoHeaderUnion anSdoHeaderUnion;
238 
239  guint16 Index;
240  guint8 SubIndex;
241  guint32 Data;
243 
244 #define ETHERCAT_SDO_HEADER_LEN 8 /* sizeof(ETHERCAT_SDO_HEADER)*/
245 
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
251 
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
256 
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
265 
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
270 
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
278 
279 #define ECAT_COE_INFO_OBJCAT_OPTIONAL 0
280 #define ECAT_COE_INFO_OBJCAT_MANDATORY 1
281 
282 #define ECAT_COE_INFO_OBJACCESS_RO 0x07
283 #define ECAT_COE_INFO_OBJACCESS_RW 0x3f
284 
286 {
287  guint16 ListType; /* == SDO_INFO_LIST_TYPE_XXX */
288  struct
289  {
290  guint16 Index[1];
291  } Res;
293 
295 {
296  guint16 Index;
297  struct
298  {
299  guint16 DataType; /* refer to data type index */
300  guint8 MaxSubIndex; /* max subIndex */
301  guint8 ObjCode; /* defined in DS 301 (Table 37)*/
302  char Name[1]; /* rest of mailbox data*/
303  } Res;
305 
307 {
308  guint16 Index;
309  guint8 SubIdx;
310  guint8 ValueInfo; /* bit0 = ObjAccess, bit1 = ObjCategory, bit2 = PdoMapping, bit3 = UnitType
311  bit4 = DefaultValue, bit5 = MinValue, bit6 = MaxValue*/
312  struct
313  {
314  guint16 DataType; /* refer to data type index */
315  guint16 BitLen;
316  guint16 ObjAccess; /* bit0 = read; bit1 = write; bit2 = const. bit3 = 'PRE-OP'; bit4 = 'SAFE-OP'; bit5 = 'OP'.*/
317  } Res;
319 
321 {
322  guint32 ErrorCode;
323  char ErrorText[1]; /* rest of mailbox data */
325 
326 typedef union tSdoInfoUnion
327 {
332  guint8 Data[1];
333 } SdoInfoUnion;
334 
335 typedef union tSdoControlUnion
336 {
337  struct
338  {
339  guint8 OpCode : 7; /* == SDO_INFO_TYPE_XXX */
340  guint8 InComplete : 1;
341  } v;
342  guint8 Control;
344 
346 {
347  SdoControlUnion anSdoControlUnion;
348  guint8 Reserved; /* == 0 */
349  guint16 FragmentsLeft;
350  SdoInfoUnion anSdoInfoUnion;
352 
353 #define ETHERCAT_SDO_INFO_LISTREQ_LEN 6 /*offsetof(ETHERCAT_SDO_INFO_HEADER, anSdoInfoUnion.List.Res)*/
354 
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
362 
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
373 
374 typedef union tFoeHeaderDataUnion
375 {
376  guint32 FileLength; /* (RRQ, WRQ) = 0 if unknown */
377  struct
378  {
379  guint16 PacketNo; /* (DATA, ACK)*/
380  guint16 Reserved2; /* (DATA, ACK)*/
381  } v;
382  guint32 ErrorCode; /* (ERR)*/
383  struct
384  {
385  guint16 Done; /* (BUSY)*/
386  guint16 Entire; /* (BUSY)*/
387  } v2;
389 
390 typedef struct TETHERCAT_FOE_HEADER
391 {
392  guint8 OpMode; /* = 1 (RRQ), = 2 (WRQ), = 3 (DATA), = 4 (ACK), = 5 (ERR), = 6 (BUSY) */
393  guint8 Reserved1; /* = 0 */
394 
395  FoeHeaderDataUnion aFoeHeaderDataUnion;
396  /* typedef union tMailBoxDataUnion
397  {
398  char Name[] (RRQ, WRQ) rest of mailbox data
399  guint8 Data[] (DATA) rest of mailbox data (if OpMode = 3)
400  char ErrorText[] (ERR) rest of mailbox data
401  } MailBoxDataUnion;*/
403 #define ETHERCAT_FOE_HEADER_LEN 6 /*sizeof(ETHERCAT_FOE_HEADER)*/
404 
405 typedef struct
406 {
407  guint16 Cmd;
408  guint16 Size;
409  guint16 AddressLW;
410  guint16 AddressHW;
412 
413 
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
420 
421 
423 {
424  struct
425  {
426  guint8 OpCode : 3; /* 0 = unused, 1 = readReq, 2 = readRes, 3 = writeReq, 4 = writeRes
427  5 = notification (command changed notification)*/
428  guint8 InComplete : 1; /* more follows*/
429  guint8 Error : 1; /* an error word follows */
430  guint8 DriveNo : 3; /* drive number */
431 
432  guint8 DataState : 1; /* follows or requested */
433  guint8 Name : 1; /* follows or requested */
434  guint8 Attribute : 1; /* follows or requested */
435  guint8 Unit : 1; /* follows or requested */
436  guint8 Min : 1; /* follows or requested */
437  guint8 Max : 1; /* follows or requested */
438  guint8 Value : 1; /* follows or requested */
439  guint8 Reserved : 1;
440  } v;
441  struct
442  {
443  guint8 Control;
444  guint8 Element;
445  } v2;
447 
448 typedef union tSoeHeaderDataUnion
449 {
450  guint16 IDN; /* SOE IDN if (InComplete==0) */
451  guint16 FragmentsLeft; /* Pending fragments if (InComplete==1) */
453 
454 typedef struct TETHERCAT_SOE_HEADER
455 {
456  SoeHeaderControlUnion anSoeHeaderControlUnion;
457  SoeHeaderDataUnion anSoeHeaderDataUnion;
458  /* typedef union tMailBoxDataUnion
459  {
460  guint8 Data[] rest of mailbox data if (Error==0)
461  guint16 ErrorCode if (Error==1)
462  } MailBoxDataUnion;*/
464 #define ETHERCAT_SOE_HEADER_LEN ((int) sizeof(ETHERCAT_SOE_HEADER))
465 
466 extern void init_mbx_header(PETHERCAT_MBOX_HEADER pMbox, tvbuff_t *tvb, gint offset);
467 
468 DIAG_ON_PEDANTIC
469 #endif /* _PACKET_ECATMAILBOX_H_ */
Definition: address.h:56
Definition: packet-ecatmb.h:406
Definition: packet-ecatmb.h:143
Definition: packet-ecatmb.h:103
Definition: packet-ecatmb.h:111
Definition: packet-ecatmb.h:391
Definition: packet-ecatmb.h:46
Definition: packet-ecatmb.h:236
Definition: packet-ecatmb.h:307
Definition: packet-ecatmb.h:321
Definition: packet-ecatmb.h:346
Definition: packet-ecatmb.h:286
Definition: packet-ecatmb.h:295
Definition: packet-ecatmb.h:455
Definition: packet-ecatmb.h:20
Definition: tvbuff-int.h:35
Definition: packet-ecatmb.h:160
Definition: packet-ecatmb.h:117
Definition: packet-ecatmb.h:129
Definition: packet-ecatmb.h:90
Definition: packet-ecatmb.h:375
Definition: packet-ecatmb.h:33
Definition: packet-ecatmb.h:336
Definition: packet-ecatmb.h:173
Definition: packet-ecatmb.h:327
Definition: packet-ecatmb.h:423
Definition: packet-ecatmb.h:449