MCPcopy Index your code
hub / github.com/secdev/scapy / LEBitField

Class LEBitField

scapy/contrib/ethercat.py:63–241  ·  view source on GitHub ↗

a little endian version of the BitField

Source from the content-addressed store, hash-verified

61
62
63class LEBitField(BitField):
64 """
65 a little endian version of the BitField
66 """
67
68 def _check_field_type(self, pkt, index):
69 """
70 check if the field addressed by given index relative to this field
71 shares type of this field so we can catch a mix of LEBitField
72 and BitField/other types
73 """
74 my_idx = pkt.fields_desc.index(self)
75 try:
76 next_field = pkt.fields_desc[my_idx + index]
77 if type(next_field) is not LEBitField and \
78 next_field.__class__.__base__ is not LEBitField:
79 raise LEBitFieldSequenceException('field after field {} must '
80 'be of type LEBitField or '
81 'derived classes'.format(self.name)) # noqa: E501
82 except IndexError:
83 # no more fields -> error
84 raise LEBitFieldSequenceException('Missing further LEBitField '
85 'based fields after field '
86 '{} '.format(self.name))
87
88 def addfield(self, pkt, s, val):
89 """
90
91 :param pkt: packet instance the raw string s and field belongs to
92 :param s: raw string representing the frame
93 :param val: value
94 :return: final raw string, tuple (s, bitsdone, data) if in between bit field # noqa: E501
95
96 as we don't know the final size of the full bitfield we need to accumulate the data. # noqa: E501
97 if we reach a field that ends at a octet boundary, we build the whole string # noqa: E501
98
99 """
100 if type(s) is tuple and len(s) == 4:
101 s, bitsdone, data, _ = s
102 self._check_field_type(pkt, -1)
103 else:
104 # this is the first bit field in the set
105 bitsdone = 0
106 data = []
107
108 bitsdone += self.size
109 data.append((self.size, self.i2m(pkt, val)))
110
111 if bitsdone % 8:
112 # somewhere in between bit 0 .. 7 - next field should add more bits... # noqa: E501
113 self._check_field_type(pkt, 1)
114 return s, bitsdone, data, type(LEBitField)
115 else:
116 data.reverse()
117 octet = 0
118 remaining_len = 8
119 octets = bytearray()
120 for size, val in data:

Callers 10

BTLE_RFClass · 0.90
LL_CTE_REQClass · 0.90
LL_CIS_REQClass · 0.90
LL_POWER_CHANGE_INDClass · 0.90
EtherCatType12DLPDUClass · 0.85
EtherCatClass · 0.85
_EtherCatLengthCalcClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected