X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FIPStack%2Flink.c;h=f0c6367a6b63e73b26ee35817a8fe967d289b4f8;hb=de6091a10d2cdded5e58f25ba3e3db7db726d01d;hp=c4f716f0b38c5874c780ccf99176a01db3fe3d12;hpb=742983c97b5cd2e38df86cb0e51c7f483730ebc5;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/IPStack/link.c b/KernelLand/Modules/IPStack/link.c index c4f716f0..f0c6367a 100644 --- a/KernelLand/Modules/IPStack/link.c +++ b/KernelLand/Modules/IPStack/link.c @@ -12,6 +12,8 @@ #include "include/adapters_int.h" // === CONSTANTS === +#define LINK_LOGPACKETS 0 +#define VALIDATE_CHECKSUM 0 #define MAX_PACKET_SIZE 2048 // === PROTOTYPES === @@ -82,29 +84,38 @@ void Link_RegisterType(Uint16 Type, tPacketCallback Callback) void Link_SendPacket(tAdapter *Adapter, Uint16 Type, tMacAddr To, tIPStackBuffer *Buffer) { int length = IPStack_Buffer_GetLength(Buffer); - int ofs = 4 - (length & 3); + int ofs = (4 - (length & 3)) & 3; Uint8 buf[sizeof(tEthernetHeader) + ofs + 4]; + //Uint32 *checksum = (void*)(buf + sizeof(tEthernetHeader) + ofs); tEthernetHeader *hdr = (void*)buf; - if( ofs == 4 ) ofs = 0; - - Log_Log("Net Link", "Sending %i bytes to %02x:%02x:%02x:%02x:%02x:%02x (Type 0x%x)", - length, To.B[0], To.B[1], To.B[2], To.B[3], To.B[4], To.B[5], Type); - hdr->Dest = To; memcpy(&hdr->Src, Adapter->HWAddr, 6); // TODO: Remove hard coded 6 hdr->Type = htons(Type); - *(Uint32*)(buf + sizeof(tEthernetHeader) + ofs) = 0; - - IPStack_Buffer_AppendSubBuffer(Buffer, sizeof(tEthernetHeader), ofs + 4, hdr, NULL, NULL); - - *(Uint32*)(buf + sizeof(tEthernetHeader) + ofs) = htonl( Link_CalculateCRC(Buffer) ); + memset(hdr+1, 0, ofs+4); // zero padding and checksum - Log_Log("Net Link", " from %02x:%02x:%02x:%02x:%02x:%02x", + Log_Log("Net Link", "Sending %i bytes (Type 0x%x)" + " to %02x:%02x:%02x:%02x:%02x:%02x" + " from %02x:%02x:%02x:%02x:%02x:%02x", + length, Type, + To.B[0], To.B[1], To.B[2], To.B[3], To.B[4], To.B[5], hdr->Src.B[0], hdr->Src.B[1], hdr->Src.B[2], hdr->Src.B[3], hdr->Src.B[4], hdr->Src.B[5] ); + #if 0 + if( (Adapter->Type->Flags & ADAPTERFLAG_OFFLOAD_MAC) ) + #endif + IPStack_Buffer_AppendSubBuffer(Buffer, sizeof(tEthernetHeader), ofs, hdr, NULL, NULL); + #if 0 + else + { + IPStack_Buffer_AppendSubBuffer(Buffer, sizeof(tEthernetHeader), ofs + 4, hdr, NULL, NULL); + *checksum = htonl( Link_CalculateCRC(Buffer) ); + Log_Debug("Net Link", "Non-Offloaded: 0x%x, 0x%x", *checksum, ntohl(*checksum)); + } + #endif + Adapter_SendPacket(Adapter, Buffer); } @@ -121,7 +132,8 @@ int Link_HandlePacket(tAdapter *Adapter, tIPStackBuffer *Buffer) free(data); return 1; } - + + #if LINK_LOGPACKETS Log_Log("Net Link", "Packet from %02x:%02x:%02x:%02x:%02x:%02x" " to %02x:%02x:%02x:%02x:%02x:%02x (Type=%04x)", @@ -131,9 +143,14 @@ int Link_HandlePacket(tAdapter *Adapter, tIPStackBuffer *Buffer) hdr->Dest.B[3], hdr->Dest.B[4], hdr->Dest.B[5], ntohs(hdr->Type) ); -// Uint32 checksum = *(Uint32*)(data + len + 4); - //Log_Log("NET", "Checksum 0x%08x", checksum); + #endif + + #if VALIDATE_CHECKSUM + Uint32 checksum = *(Uint32*)(data + len + 4); + Log_Log("NET Link", "Checksum 0x%08x", checksum); + Uint32 calculated = Link_CalculateCRC(Buffer); // TODO: Check checksum + #endif // Check if there is a registered callback for this packet type int i; @@ -166,15 +183,12 @@ int Link_HandlePacket(tAdapter *Adapter, tIPStackBuffer *Buffer) #define QUOTIENT 0x04c11db7 void Link_InitCRC(void) { - int i, j; - Uint32 crc; - - for (i = 0; i < 256; i++) + for( int i = 0; i < 256; i++ ) { - crc = i << 24; - for (j = 0; j < 8; j++) + Uint32 crc = i << 24; + for( int j = 0; j < 8; j++ ) { - if (crc & 0x80000000) + if( crc >> 31 ) crc = (crc << 1) ^ QUOTIENT; else crc = crc << 1;