X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/071e02c6b6b4837fa9cf0b6d4c749994e02638d7..a8b66f318dda3cc18dfcedaa3af3d01ab68b82e8:/Demos/Device/ClassDriver/RNDISEthernet/Lib/Ethernet.c?ds=sidebyside diff --git a/Demos/Device/ClassDriver/RNDISEthernet/Lib/Ethernet.c b/Demos/Device/ClassDriver/RNDISEthernet/Lib/Ethernet.c index a3a42e22d..61193faaa 100644 --- a/Demos/Device/ClassDriver/RNDISEthernet/Lib/Ethernet.c +++ b/Demos/Device/ClassDriver/RNDISEthernet/Lib/Ethernet.c @@ -1,21 +1,21 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com + www.lufa-lib.org */ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -31,10 +31,10 @@ /** \file * * Ethernet frame packet handling routines. This protocol handles the processing of raw Ethernet - * frames sent and received, deferring the processing of subpacket protocols to the appropriate + * frames sent and received, deferring the processing of sub-packet protocols to the appropriate * protocol handlers, such as DHCP or ARP. */ - + #include "Ethernet.h" /** Constant for convenience when checking against or setting a MAC address to the virtual server MAC address. */ @@ -56,16 +56,17 @@ const IP_Address_t ClientIPAddress = {CLIENT_IP_ADDRESS}; /** Processes an incoming Ethernet frame, and writes the appropriate response to the output Ethernet * frame buffer if the sub protocol handlers create a valid response. */ -void Ethernet_ProcessPacket(Ethernet_Frame_Info_t* FrameIN, Ethernet_Frame_Info_t* FrameOUT) +void Ethernet_ProcessPacket(Ethernet_Frame_Info_t* const FrameIN, + Ethernet_Frame_Info_t* const FrameOUT) { DecodeEthernetFrameHeader(FrameIN); /* Cast the incoming Ethernet frame to the Ethernet header type */ Ethernet_Frame_Header_t* FrameINHeader = (Ethernet_Frame_Header_t*)&FrameIN->FrameData; Ethernet_Frame_Header_t* FrameOUTHeader = (Ethernet_Frame_Header_t*)&FrameOUT->FrameData; - + int16_t RetSize = NO_RESPONSE; - + /* Ensure frame is addressed to either all (broadcast) or the virtual webserver, and is a type II frame */ if ((MAC_COMPARE(&FrameINHeader->Destination, &ServerMACAddress) || MAC_COMPARE(&FrameINHeader->Destination, &BroadcastMACAddress)) && @@ -77,14 +78,14 @@ void Ethernet_ProcessPacket(Ethernet_Frame_Info_t* FrameIN, Ethernet_Frame_Info_ case ETHERTYPE_ARP: RetSize = ARP_ProcessARPPacket(&FrameIN->FrameData[sizeof(Ethernet_Frame_Header_t)], &FrameOUT->FrameData[sizeof(Ethernet_Frame_Header_t)]); - break; + break; case ETHERTYPE_IPV4: RetSize = IP_ProcessIPPacket(FrameIN, &FrameIN->FrameData[sizeof(Ethernet_Frame_Header_t)], &FrameOUT->FrameData[sizeof(Ethernet_Frame_Header_t)]); break; } - + /* Protocol processing routine has filled a response, complete the ethernet frame header */ if (RetSize > 0) { @@ -92,7 +93,7 @@ void Ethernet_ProcessPacket(Ethernet_Frame_Info_t* FrameIN, Ethernet_Frame_Info_ FrameOUTHeader->Source = ServerMACAddress; FrameOUTHeader->Destination = FrameINHeader->Source; FrameOUTHeader->EtherType = FrameINHeader->EtherType; - + /* Set the response length in the buffer and indicate that a response is ready to be sent */ FrameOUT->FrameLength = (sizeof(Ethernet_Frame_Header_t) + RetSize); FrameOUT->FrameInBuffer = true; @@ -115,16 +116,18 @@ void Ethernet_ProcessPacket(Ethernet_Frame_Info_t* FrameIN, Ethernet_Frame_Info_ * * \return A 16-bit Ethernet checksum value */ -uint16_t Ethernet_Checksum16(void* Data, uint16_t Bytes) +uint16_t Ethernet_Checksum16(void* Data, + uint16_t Bytes) { uint16_t* Words = (uint16_t*)Data; uint32_t Checksum = 0; - for (uint8_t CurrWord = 0; CurrWord < (Bytes >> 1); CurrWord++) + for (uint16_t CurrWord = 0; CurrWord < (Bytes >> 1); CurrWord++) Checksum += Words[CurrWord]; - + while (Checksum & 0xFFFF0000) Checksum = ((Checksum & 0xFFFF) + (Checksum >> 16)); - + return ~Checksum; } +