scapy.contrib.ethercat

EtherCat automation protocol

author

Thomas Tannhaeuser, hecke @ naberius .

license

GPLv2

该模块是免费软件; 您可以根据自由软件基金会发布的GNU通用公共许可证的条款重新分发和/或修改它; 许可的版本2,或(由您选择)任何更高的版本.

分发该模块是希望它会有用,但是没有任何保证; 甚至没有对适销性或特定用途适用性的暗示保证. 有关更多详细信息,请参见GNU通用公共许可证.

description

该模块为EtherCat协议提供Scapy层.

normative references:
  • IEC 61158-3-12-数据链路服务和拓扑描述

  • IEC 61158-4-12-协议规范

当前仅按IEC 61158-4-12(秒)中定义的读/写服务. 支持5.4.

TODO
  • 邮箱服务(第5.5节)

  • 网络变量服务(第5.6节)

NOTES
  • 使用填充的xxx字节,EtherCat帧类型默认为TYPE-12-PDU(0x01)

  • 自动添加最小帧尺寸的填充

class scapy.contrib.ethercat.EtherCat

Bases: scapy.packet.Packet

通用EtherCat标头层

ETHERCAT_HEADER_LEN = 2
ETHERCAT_TYPE12_DLPDU_TYPES = {1: <class 'scapy.contrib.ethercat.EtherCatAPRD'>, 2: <class 'scapy.contrib.ethercat.EtherCatAPWR'>, 3: <class 'scapy.contrib.ethercat.EtherCatAPRW'>, 4: <class 'scapy.contrib.ethercat.EtherCatFPRD'>, 5: <class 'scapy.contrib.ethercat.EtherCatFPWR'>, 6: <class 'scapy.contrib.ethercat.EtherCatFPRW'>, 7: <class 'scapy.contrib.ethercat.EtherCatBRD'>, 8: <class 'scapy.contrib.ethercat.EtherCatBWR'>, 9: <class 'scapy.contrib.ethercat.EtherCatBRW'>, 10: <class 'scapy.contrib.ethercat.EtherCatLRD'>, 11: <class 'scapy.contrib.ethercat.EtherCatLWR'>, 12: <class 'scapy.contrib.ethercat.EtherCatLRW'>, 13: <class 'scapy.contrib.ethercat.EtherCatARMW'>, 14: <class 'scapy.contrib.ethercat.EtherCatFRMW'>}
ETHER_FRAME_MIN_LEN = 64
ETHER_FSC_LEN = 4
ETHER_HEADER_LEN = 14
FRAME_TYPES = {1: 'TYPE-12-PDU', 4: 'NETWORK-VARIABLES', 5: 'MAILBOX'}
aliastypes
fields_desc
EtherCat字段

length

LEBitField (11位)

0

_reserved

LEBitField (1位)

0

type

LEBitField (4位)

0

guess_payload_class(payload)
payload_guess

可能的子层: EtherCatAPRDEtherCatAPRWEtherCatAPWREtherCatARMWEtherCatBRDEtherCatBRWEtherCatBWREtherCatFPRDEtherCatFPRWEtherCatFPWREtherCatFRMWEtherCatLRDEtherCatLRWEtherCatLWR

post_build(pkt, pay)

需要手动设置整个PDU的长度,以避免任何位摆弄使用虚拟类来构建层内容

如果帧小于64字节,也要添加填充

Note: padding only handles Ether/n*Dot1Q/EtherCat

(没有特别的巨型)

Parameters
  • pkt –包含当前图层的原始字符串

  • pay –包含有效载荷的原始字符串

Returns

<新的当前层> +有效负载

class scapy.contrib.ethercat.EtherCatAPRD

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

APRD-自动增量物理读取(IEC 61158-5-12,sec.5.4.1.2 tab.14 / p.32)

aliastypes
fields_desc
EtherCatAPRD字段

_cmd

ByteField

1

idx

ByteField

0

adp

LEShortField

0

ado

LEShortField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatAPRW

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

APRW-自动增量物理读写(IEC 61158-5-12,sec.5.4.3.1 tab.22 / p.41)

aliastypes
fields_desc
EtherCatAPRW字段

_cmd

ByteField

3

idx

ByteField

0

adp

LEShortField

0

ado

LEShortField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatAPWR

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

APWR-自动增量物理写入(IEC 61158-5-12,sec.5.4.2.2 tab.18 / p.37)

aliastypes
fields_desc
EtherCatAPWR字段

_cmd

ByteField

2

idx

ByteField

0

adp

LEShortField

0

ado

LEShortField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatARMW

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

ARMW-自动递增物理读取多次写入(IEC 61158-5-12,sec.5.4.3.5 tab.26 / p.46)

aliastypes
fields_desc
EtherCatARMW字段

_cmd

ByteField

13

idx

ByteField

0

adp

LEShortField

0

ado

LEShortField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatBRD

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

BRD-广播读取(IEC 61158-5-12,sec.5.4.1.4 tab.16 / p.34)

aliastypes
fields_desc
EtherCatBRD字段

_cmd

ByteField

7

idx

ByteField

0

adp

LEShortField

0

ado

LEShortField

0

len

LEBitFieldLenField (11 bits)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatBRW

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

BRW-广播读写(IEC 61158-5-12,sec.5.4.3.3 tab.24 / p.39)

aliastypes
fields_desc
EtherCatBRW字段

_cmd

ByteField

9

idx

ByteField

0

adp

LEShortField

0

ado

LEShortField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatBWR

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

BWR-广播读取(IEC 61158-5-12,sec.5.4.2.4 tab.20 / p.39)

aliastypes
fields_desc
EtherCatBWR字段

_cmd

ByteField

8

idx

ByteField

0

adp

LEShortField

0

ado

LEShortField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatFPRD

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

FPRD-配置的地址物理读取(IEC 61158-5-12,sec.5.4.1.3 tab.15 / p.33)

aliastypes
fields_desc
EtherCatFPRD字段

_cmd

ByteField

4

idx

ByteField

0

adp

LEShortField

0

ado

LEShortField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1 bit)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatFPRW

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

FPRW-配置的地址物理读写(IEC 61158-5-12,第5.4.3.2页,第23页/第43页)

aliastypes
fields_desc
EtherCatFPRW字段

_cmd

ByteField

6

idx

ByteField

0

adp

LEShortField

0

ado

LEShortField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatFPWR

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

FPWR-配置的地址物理写入(IEC 61158-5-12,sec.5.4.2.3 Tab.19 / p.38)

aliastypes
fields_desc
EtherCatFPWR字段

_cmd

ByteField

5

idx

ByteField

0

adp

LEShortField

0

ado

LEShortField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatFRMW

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

FRMW-配置的地址物理读多次写(IEC 61158-5-12,sec.5.4.3.6 Tab.27 / p.47)

aliastypes
fields_desc
EtherCatFRMW字段

_cmd

ByteField

14

idx

ByteField

0

adp

LEShortField

0

ado

LEShortField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatLRD

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

LRD-逻辑读取(IEC 61158-5-12,sec.5.4.1.5 tab.17 / p.36)

aliastypes
fields_desc
EtherCatLRD字段

_cmd

ByteField

10

idx

ByteField

0

adr

LEIntField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1 bit)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatLRW

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

LRW-逻辑读写(IEC 61158-5-12,sec.5.4.3.4 tab.25 / p.45)

aliastypes
fields_desc
EtherCatLRW字段

_cmd

ByteField

12

idx

ByteField

0

adr

LEIntField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatLWR

Bases: scapy.contrib.ethercat.EtherCatType12DLPDU

LWR-逻辑写入(IEC 61158-5-12,sec.5.4.2.5 tab.21 / p.40)

aliastypes
fields_desc
EtherCatLWR字段

_cmd

ByteField

11

idx

ByteField

0

adr

LEIntField

0

len

LEBitFieldLenField (11位)

None

_reserved

LEBitField (3位)

0

c

LEBitEnumField (1位)

0

next

LEBitEnumField (1位)

None

irq

LEShortField

0

data

FieldListField

[]

wkc

LEShortField

0

class scapy.contrib.ethercat.EtherCatType12DLPDU

Bases: scapy.packet.Packet

Type12消息基类

BROADCAST_ADDRESSING_DESC = [<Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).idx>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).adp>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).ado>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).len>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW)._reserved>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).c>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).next>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).irq>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).data>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).wkc>]
LOGICAL_ADDRESSING_DESC = [<Field (EtherCatLRD,EtherCatLWR,EtherCatLRW).idx>, <Field (EtherCatLRD,EtherCatLWR,EtherCatLRW).adr>, <Field (EtherCatLRD,EtherCatLWR,EtherCatLRW).len>, <Field (EtherCatLRD,EtherCatLWR,EtherCatLRW)._reserved>, <Field (EtherCatLRD,EtherCatLWR,EtherCatLRW).c>, <Field (EtherCatLRD,EtherCatLWR,EtherCatLRW).next>, <Field (EtherCatLRD,EtherCatLWR,EtherCatLRW).irq>, <Field (EtherCatLRD,EtherCatLWR,EtherCatLRW).data>, <Field (EtherCatLRD,EtherCatLWR,EtherCatLRW).wkc>]
PHYSICAL_ADDRESSING_DESC = [<Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).idx>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).adp>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).ado>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).len>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW)._reserved>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).c>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).next>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).irq>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).data>, <Field (EtherCatAPRD,EtherCatFPRD,EtherCatBRD,EtherCatAPWR,EtherCatFPWR,EtherCatBWR,EtherCatAPRW,EtherCatFPRW,EtherCatBRW,EtherCatARMW,EtherCatFRMW).wkc>]
aliastypes
guess_payload_class(payload)
post_build(pkt, pay)

如果未由用户明确设置,则自动设置下一个attr

Parameters
  • pkt –包含当前图层的原始字符串

  • pay –包含有效载荷的原始字符串

Returns

<新的当前层> +有效负载

class scapy.contrib.ethercat.LEBitEnumField(name, default, size, enum)

Bases: scapy.contrib.ethercat.LEBitField, scapy.fields._EnumField

i2s
i2s_cb
s2i
s2i_cb
class scapy.contrib.ethercat.LEBitField(name, default, size)

Bases: scapy.fields.BitField

BitField的小端版本

addfield(pkt, s, val)
Parameters
  • pkt –原始字符串s和字段所属的数据包实例

  • s –表示框架的原始字符串

  • val –值

Returns

最终的原始字符串,元组(s,bitsdone,数据)(如果在位字段#noqa之间):E501

由于我们不知道整个位域的最终大小,因此我们需要累积数据. #noqa:E501如果我们到达以八位位组边界结尾的字段,则会构建整个字符串.#noqa:E501

getfield(pkt, s)

从原始str提取数据

收集属于该位字段集的所有实例. 如果我们到达以八位位组边界结尾的字段,请立即剖析整个位字段#noqa:E501

Parameters
  • pkt –字段所属的数据包实例

  • s –表示帧的原始字符串-包含原始str,位数和字段数组的元组#noqa:E501

Returns

包含原始str,位数和字段数组的元组-或-剩余的原始str和此#noqa的值:E501

class scapy.contrib.ethercat.LEBitFieldLenField(name, default, size, length_of=None, count_of=None, adjust=<function LEBitFieldLenField.<lambda>>)

Bases: scapy.contrib.ethercat.LEBitField

adjust
count_of
i2m(pkt, x)
length_of
exception scapy.contrib.ethercat.LEBitFieldSequenceException

Bases: scapy.error.Scapy_Exception

由EtherCat结构测试抛出