CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Nasty Bug in MCHP TCP/IP 3.75 Drivers (CCS Friendly)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

Nasty Bug in MCHP TCP/IP 3.75 Drivers (CCS Friendly)
PostPosted: Wed Oct 14, 2009 2:26 am     Reply with quote

I just found an icky bug I'd like anyone to confirm out there for me.

in the tcpip/helpers.c:

Code:
WORD CalcIPChecksum(BYTE* buffer, WORD count)
{
   WORD i, y,z;
   WORD *val;

   WORD temp;

   union
   {
      DWORD Val;
      struct
      {
         WORD_VAL LSB;
         WORD_VAL MSB;
      } w;
   } sum;

   sum.Val = 0;

   i = count >> 1;
   val = (WORD*)buffer;

   // Calculate the sum of all words
   while(i--)
      sum.Val += (DWORD)*val++;

   // Add in the sum of the remaining byte, if present
   #warning "Fixed: 'if(((WORD_VAL*)&count) & 1)' to 'if( count & 1)' - BEN"
   if( count & 1)
      sum.Val += (DWORD)*(BYTE*)val;

   // Do an end-around carry (one's complement arrithmatic)
   sum.Val = (DWORD)sum.w.LSB + (DWORD)sum.w.MSB;

   // Do another end-around carry in case if the prior add
   // caused a carry out
   y = sum.w.LSB;
   z = sum.w.MSB;
   y += z;

   // Return the resulting checksum
   return (~y);

}



Look to see if you have if( ((WORD_VAL*) &count) & 1).

The author really just wanted to test count for being odd (not even) and ends up with the address of count.

Depending on the RAM location the compiler assigns it, you can either be working or not...

When I used my PICDEM.net2 with the built-in ethernet, no problem. When I switched to the onboard ENC28J60, it would fail checksums.

So fix away and let me know if this solved a problem for you.

-Ben[/u]
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 14, 2009 10:48 am     Reply with quote

The v3.75 CCS port has "count & 1" already.
_________________
Andrew
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Oct 14, 2009 2:19 pm     Reply with quote

That's bizarre since I'm using the CCS port(!).


I double checked the code from the install directory. (I made a copy of the source before starting my project.)

Anyone else?

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 14, 2009 2:31 pm     Reply with quote

Download CCS TCP/IP package on this page (requires current maintenance):
http://www.ccsinfo.com/compilerupdates.php

Install, and run Examine32 (or other text search engine) on this directory:
Quote:
c:\program files\picc\tcp-ip

Search for this text:
Quote:
count & 1

Use this filespec:
Quote:
*.c *.h

Get these hits:
Quote:
c:\program files\picc\tcp-ip\pic examples source\drivers\helpers.c 5/24/04 12:36:22 PM 3945

int16 CalcIPChecksum(int8* buff, int16 count)
{
.
.
.
if ( count & 1 )
sum.Val += *(int8 *)val;
.
.
}


Quote:
c:\program files\picc\tcp-ip\pic examples source\tcpip\helpers.c 10/24/06 4:20:00 PM 7283

WORD CalcIPChecksum(BYTE* buffer, WORD count)
{
.
.
.

if ( count & 1 )
sum.Val += *(BYTE *)val;
.
.
.


Version information from the above file:
Quote:

* Darren Rook (CCS) 10/24/06 In synch with Microchip's V3.75 stack
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Oct 14, 2009 3:41 pm     Reply with quote

Wow.

Wow.

I swear I'm not a rabid user of mind enhancers. I pop a centrum complete a day and that's it.

This file is a copy of the CCS TCP source which when I look at the install tree I find the same things you are finding.

The whole CalcIPChecksum routine looks different.

It's official. I have no idea where this version of helpers.c came from.

Not microchip. Not CCS.

I blame my computer. It runs Windoze and Bill is the root of all things eeeevviiiill. That's gotta be it.

Thanks for the verification everyone,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group