renatoaloi / EtherEncLib

Ethernet ENC28J60 Library for Arduino
GNU General Public License v3.0
26 stars 14 forks source link

Testing checksum #1

Closed ThomasArts closed 9 years ago

ThomasArts commented 9 years ago

Hi Renato

I forked your project and tested two properties of the checksum computation. 1) whenever you compute the checksum add this to the buffer and compute it again, you obtain zero. This property passed 2) your implementation is equivalent with my implementation of checksum This property failed

Thus, I must have made a mistake in my implementation... but then I checked against WikiPedia (from which I implemented http://en.wikipedia.org/wiki/IPv4_header_checksum). Your checksum gives a different answer.

Is this because you have a different checksum than the one described in RFC1071 ?? /Thomas

renatoaloi commented 9 years ago

Hi! I have some trouble with checksum indeed.

1) It is little dificult to get it working because you need to manually save checksum data, then put some zeroes at checksum data, just then you send it to checksum function. I think you are doing exact the oposite, if I got it right.

2) I think the problem is not the code but the usage.

I must check it, but I think I already solved this problem using internal checksum from ENC28J60 command set.

Take a look at this project: https://github.com/renatoaloi/Enc28CoreLib

ThomasArts commented 9 years ago

Thanks Renato for looking into this.

I indeed think it is the usage. The standard I read said that you first compute the checksum over the bytes that are NOT the header, then you add the checksum to it. You add 00 00 to the header and compute the checksum of the things with 00 00 in it, which differs from leaving out the 00 00 completely.

Regards Thomas

On 03 Nov 2014, at 13:05 , Renato Aloi notifications@github.com wrote:

Hi! I have some trouble with checksum indeed.

1) It is little dificult to get it working because you need to manually save checksum data, then put some zeroes at checksum data, just then you send it to checksum function. I think you are doing exact the oposite, if I got it right.

2) I think the problem is not the code but the usage.

I must check it, but I think I already solved this problem using internal checksum from ENC28J60 command set.

Take a look at this project: https://github.com/renatoaloi/Enc28CoreLib

— Reply to this email directly or view it on GitHub.

Thomas Arts CTO Quviq AB

thomas.arts@quviq.com tel: +46 70 43 88567 http://www.quviq.com/

renatoaloi commented 9 years ago

Thanks for replying! I think it is because of item 15 from Errata B7: http://shop.tuxgraphics.org/snippets/enc28j60-B7_errata.pdf

Thinking again about question #2, I found 2 different implementation for checksum routine, throughout my research...

But as I far as I can remember the implementation aproach shared between them had some redunctants if's; I just did not care for UDP implementation details, for example.

Another things to consider:

Ow, I almost forgot! At same item 15, at same errata we can see that does not affect DMA Copy! So I took advantage of Schundler's code to implement Zero-DMA Copy. And guess what? It works!

I am trying to merge this one:

https://github.com/renatoaloi/EtherEncLib/blob/master/enc28j60.c

with this one:

https://github.com/renatoaloi/Enc28CoreLib/blob/master/enc28j60.c

This task will consolidate the libs EtherEnc and Enc28Core together! No more RAM buffer at all!

Best Regards, Renato

renatoaloi commented 9 years ago

I am remembering this by my own comments. See this file below starting at line 223: https://github.com/renatoaloi/Enc28CoreLib/blob/master/tcpStack.cpp

DMA Buffer and checksum are bounded to FIFO. Some workaround is needed. I think it is the reason you have some dificulties to checklist every item.

Keep me in the loop! Renato

renatoaloi commented 9 years ago

Hi! I am reviewing checksum now! It is a mess! Now I am seeing that lot of rules are being fullfiled by mere luck! I am working on it now. Thanks! Renato

ThomasArts commented 9 years ago

Hi Renato

Sorry, I was a bit busy with other stuff. But yes, there are a number of ways checksums can be implemented. When you now re-implemented, I am happy to test it again against the standard that we used. You can even do that yourself by registering your project at QuickCheck-CI, but I guess it’s easier when I do so.

Cheers Thomas

On 13 Nov 2014, at 01:52 , Renato Aloi notifications@github.com wrote:

Hi! I am reviewing checksum now! It is a mess! Now I am seeing that lot of rules are being fullfiled by mere luck! I am working on it now. Thanks! Renato

— Reply to this email directly or view it on GitHub.

Thomas Arts CTO Quviq AB

thomas.arts@quviq.com tel: +46 70 43 88567 http://www.quviq.com/

renatoaloi commented 9 years ago

Thanks Thomas! I am already taking a look at QuickCheck-CI site! It appears to be what I need in terms of testing!

From last week till yesterday we've been working on this: https://github.com/renatoaloi/EtherEncLib/tree/enc28coremerge

Among other things I have implemented checksum routines in a very straight way. Every function returnXYZ() has its own checksum (duplicated, if the case).

But as you can see, the variables/constants names are poorly choosen. This way, we have a messy code when TCP routine takes advantage of ICMP constants... A real mess.

I think it works by luck! Soon I will have free time to take look at this.

Thanks to bring this to light.

Renato Aloi