Help - Search - Members - Calendar
Full Version: Another checksum bug
1Emulation.Com > Official Emulator Forums > DSWifi
Stonebone
While transfering big files with tftpds i noticed that it seemed to fail systematically. After studying the traffic in ethereal I came to the conclusion that dswifi calculates the checksum for the udp package incorrectly in some rare cases. I read here on the forum that it fails on odd-sized packages but this was an even sized package so it is not the same bug.

After spending several hours tracking down this bug, my friend Gustav Munkby and I found the cause of this bug. In a few places in the checksum calculation code similar to this appears:
CODE
checksum += checksum>>16;
checksum &= 0xFFFF;

This code is meant to take of the carries from the ones'-complement additions. The correct way of doing this is like this:
CODE
while(checksum >> 16) checksum = (checksum & 0xFFFF) + (checksum >> 16);

As an example, if checksum = 0x1FFFF the former code give an incorrect result (0), but the later code will give the correct result (1).

I have updated my hacked version to fix this in at least some places:
http://www.itstud.chalmers.se/~larssten/wifi_lib.tar.bz2
sgstair
QUOTE (Stonebone @ Feb 24 2006, 10:07 AM)
While transfering big files with tftpds i noticed that it seemed to fail systematically. After studying the traffic in ethereal I came to the conclusion that dswifi calculates the checksum for the udp package incorrectly in some rare cases. I read here on the forum that it fails on odd-sized packages but this was an even sized package so it is not the same bug.

After spending several hours tracking down this bug, my friend Gustav Munkby and I found the cause of this bug. In a few places in the checksum calculation code similar to this appears:
CODE
checksum += checksum>>16;
checksum &= 0xFFFF;

This code is meant to take of the carries from the ones'-complement additions. The correct way of doing this is like this:
CODE
while(checksum >> 16) checksum = (checksum & 0xFFFF) + (checksum >> 16);

As an example, if checksum = 0x1FFFF the former code give an incorrect result (0), but the later code will give the correct result (1).

I have updated my hacked version to fix this in at least some places:
http://www.itstud.chalmers.se/~larssten/wifi_lib.tar.bz2
*


Hi! Thanks for the feedback, but I had already noticed and fixed this in my working version of the lib (that's what I get for having long delays between releases, I guess) - I do appreciate being informed though smile.gif

-Stephen
Stonebone
QUOTE (sgstair @ Feb 25 2006, 04:44 AM)
Hi! Thanks for the feedback, but I had already noticed and fixed this in my working version of the lib (that's what I get for having long delays between releases, I guess) - I do appreciate being informed though smile.gif

-Stephen
*

Ok well, maybe you should keep the source in a public repository instead. I assume you use something like cvs anyway since it's so convinient even if you are the only programmer. That way you don't need to spend time on doing many intermediate releases. Sourceforge started supporting subversion recently...
sgstair
Stonebone: or I can simply not do intermediate releases and make you all wait tongue.gif

No, really though. I'm more than happy doing this project as I see fit, no need to try to make me change my mind.

-Stephen
knight0fdragon
i know how you feel sgstairs, dont let comments like these discourage you, do what u seem fit to make this project work, because its the only way its going to get done, Id rather you doing something u love doing the way u love doing it then any other way, gives us a better quality product in the end. I too would like to see a new version, just like the rest of the communiry, but we are finding ways to deal with it till that day comes, so best of luck to ya
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.