-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
basic EtherCat layer #569
basic EtherCat layer #569
Conversation
scapy/contrib/EtherCat.py
Outdated
if pad_len > 0: | ||
|
||
pad = Padding() | ||
pad.load = '\x00' * pad_len |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please adapt your code to the new contributing rules:
That only means using b'\x0....' instead of '\x0....'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do. there is also a bug in the frame padding (frames are to big).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. padding is fixed & tested against real devices.
scapy/fields.py
Outdated
as we don't know the final size of the full bitfield we need to accumulate the data. | ||
if we reach a field that ends at a octet boundary, we build the whole string | ||
|
||
!!! NEVER MIX LEBitField with BitField !!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean ?
Would it be possible to check that and raise an error ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so and I will add an exception. It was not completely clear to me how to handle that kind of internal error as I was not able to derive some kind of rule by looking at the remaining code base 😄
edit: typo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed by 3fd2b76, adds explicit check for lower/upper layer sharing LEBitField type
Hi, I'm not sure what you mean by |
Hi, negative size works only on BitFields using 16 or 32 bit length. quick example (number after the # is assigned to the field):
gives (added some spaces to separate fields)
As EtherCat uses some 2-11-3-sized-fields negative field length was no option as this is not handled by the current implementation. Even worse: it silently returns the unchanged value - maybe an Exception should be thrown here as this is not the expected behavior (as shown by your comment too). Open question: what is the effort to add the ability to handle non 16/32 bit sized fields with the stock-BitField class.... |
Codecov Report
@@ Coverage Diff @@
## master #569 +/- ##
=========================================
+ Coverage 83.68% 83.8% +0.12%
=========================================
Files 159 160 +1
Lines 38120 38337 +217
=========================================
+ Hits 31899 32129 +230
+ Misses 6221 6208 -13
|
@speakinghedge could you rebase you changes ? Thanks. |
181acb2
to
45f8892
Compare
did. also reduced the plethora of commits to some meaningful ones... |
scapy/contrib/EtherCat.uts
Outdated
@@ -0,0 +1,256 @@ | |||
from enum import test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in ae0317c (I was fooled by pycharm. again. sorry.)
Please rebase against current master as we now have Python 3 tests. Also , do not use |
underscores removed in 49fd726. maybe this should be added to your contribution rules. |
I will take care for the Python 3 related issues. |
@speakinghedge #1090 updates the documentation. Thanks for the idea. |
I was really busy - will start working on this later today. |
...6 days ago. naa. that human timescale is wrong. |
@speakinghedge I restarted the failing osx test and it is now ok. Could you rename your files to |
You certainly mean |
done in c4b5843. how could this survive that long? 😃 |
scapy/contrib/ethercat.uts
Outdated
assert(len(frm) == 60) | ||
frm = Ether(frm.do_build()) | ||
assert(frm[EtherCat].length == 10) | ||
frm = Ether()/EtherCat()/Raw('012345678901234567890123456789012345678901234567890123456789') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to write:
frm = Ether()/EtherCat()/Raw(b'012345678901234567890123456789012345678901234567890123456789')
The same comment apply to other part of your code.
Sorry, I have more requests:
|
c4b5843
to
cea0723
Compare
scapy/fields.py
Outdated
@@ -1121,6 +1121,7 @@ def any2i(self, pkt, x): | |||
def i2repr(self, pkt, x): | |||
return _EnumField.i2repr(self, pkt, x) | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please remove this useless change to preserve this file's code history? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I touched that part of the code (by adding new fields but later on I moved them to another location) I honored the boy scout rule and added a newline between the two classes to follow pep8. but I see your point - 3da7f3f
What happened to this PR? I am very interested in this functionality. |
It seems that the PR moved to https://github.com/speakinghedge/scapy/tree/EtherCat-support from speakinghedge/master, and he did not reopen the PR |
Sorry - I lost somehow track - this 'close and move' didn't happen on purpose. Seems https://github.com/speakinghedge/scapy/tree/EtherCat-support is also in a bad state. I will go and
Side note: I'm not able to test this against real hardware anymore (as I switched the employer). |
this is the cleaned up version of broken PR secdev#569 it incorporates all requested changes up to 3da7f3f sorry for the noise.
this is the cleaned up version of broken PR secdev#569 it incorporates all requested changes up to 3da7f3f sorry for the noise.
This pull request adds basic support for Type 12 EtherCat messages (IEC 61158-4-12).
As the EtherCat protocol uses LittleEndian byte order - even for BitFields - this also adds LEBitFields support. There is a small regression test on top of the EtherCat-tests - but I don't know if the whole LEBitField implementation is mature enough...