diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2010-10-13 14:05:35 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2010-10-13 14:05:35 +0000 |
commit | 5a4def747897c1c6ffbe465506d846c7c686d3e9 (patch) | |
tree | e5a9ca31ab554e993f1a9041e44976cf7b253921 /Demos/Device/LowLevel/RNDISEthernet/Lib | |
parent | a8871c7fba73307226bd13e2cad4c840c850e6f1 (diff) | |
download | lufa-5a4def747897c1c6ffbe465506d846c7c686d3e9.tar.gz lufa-5a4def747897c1c6ffbe465506d846c7c686d3e9.tar.bz2 lufa-5a4def747897c1c6ffbe465506d846c7c686d3e9.zip |
Clean up excessive whitespace at the end of each line using the wspurify tool made by Laszlo Monda
Diffstat (limited to 'Demos/Device/LowLevel/RNDISEthernet/Lib')
22 files changed, 413 insertions, 391 deletions
diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/ARP.c b/Demos/Device/LowLevel/RNDISEthernet/Lib/ARP.c index 853d50542..ca66256e7 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/ARP.c +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/ARP.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -34,7 +34,7 @@ * conversion of physical MAC addresses to protocol IP addresses between the host and the * device. */ - + #include "ARP.h" /** Processes an ARP packet inside an Ethernet frame, and writes the appropriate response @@ -59,7 +59,7 @@ int16_t ARP_ProcessARPPacket(void* InDataStart, (SwapEndian_16(ARPHeaderIN->Operation) == ARP_OPERATION_REQUEST)) { /* If the ARP packet is requesting the MAC or IP of the virtual webserver, return the response */ - if (IP_COMPARE(&ARPHeaderIN->TPA, &ServerIPAddress) || + if (IP_COMPARE(&ARPHeaderIN->TPA, &ServerIPAddress) || MAC_COMPARE(&ARPHeaderIN->THA, &ServerMACAddress)) { /* Fill out the ARP response header */ @@ -81,6 +81,7 @@ int16_t ARP_ProcessARPPacket(void* InDataStart, return sizeof(ARP_Header_t); } } - + return NO_RESPONSE; } + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/ARP.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/ARP.h index 8de76f3b6..d97761539 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/ARP.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/ARP.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -32,18 +32,18 @@ * * Header file for ARP.c. */ - + #ifndef _ARP_H_ #define _ARP_H_ /* Includes: */ #include <avr/io.h> #include <string.h> - + #include "EthernetProtocols.h" #include "Ethernet.h" #include "ProtocolDecoders.h" - + /* Macros: */ /** ARP header operation constant, indicating a request from a host for an address translation. */ #define ARP_OPERATION_REQUEST 1 @@ -57,19 +57,20 @@ { uint16_t HardwareType; /**< Hardware type constant, indicating the hardware used */ uint16_t ProtocolType; /**< Protocol being resolved, usually ETHERTYPE_IPV4 */ - + uint8_t HLEN; /**< Length in bytes of the source/destination hardware addresses */ uint8_t PLEN; /**< Length in bytes of the source/destination protocol addresses */ uint16_t Operation; /**< Type of operation, either ARP_OPERATION_REQUEST or ARP_OPERATION_REPLY */ - + MAC_Address_t SHA; /**< Sender's hardware address */ IP_Address_t SPA; /**< Sender's protocol address */ MAC_Address_t THA; /**< Target's hardware address */ IP_Address_t TPA; /**< Target's protocol address */ } ARP_Header_t; - + /* Function Prototypes: */ int16_t ARP_ProcessARPPacket(void* InDataStart, void* OutDataStart); #endif + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/DHCP.c b/Demos/Device/LowLevel/RNDISEthernet/Lib/DHCP.c index 41265aa27..118f5e0b5 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/DHCP.c +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/DHCP.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -34,7 +34,7 @@ * handles the automatic IP negotiation to the host, so that the host will use the provided * IP address given to it by the device. */ - + #include "DHCP.h" /** Processes a DHCP packet inside an Ethernet frame, and writes the appropriate response @@ -53,7 +53,7 @@ int16_t DHCP_ProcessDHCPPacket(void* IPHeaderInStart, IP_Header_t* IPHeaderIN = (IP_Header_t*)IPHeaderInStart; DHCP_Header_t* DHCPHeaderIN = (DHCP_Header_t*)DHCPHeaderInStart; DHCP_Header_t* DHCPHeaderOUT = (DHCP_Header_t*)DHCPHeaderOutStart; - + uint8_t* DHCPOptionsINStart = (uint8_t*)(DHCPHeaderInStart + sizeof(DHCP_Header_t)); uint8_t* DHCPOptionsOUTStart = (uint8_t*)(DHCPHeaderOutStart + sizeof(DHCP_Header_t)); @@ -73,7 +73,7 @@ int16_t DHCP_ProcessDHCPPacket(void* IPHeaderInStart, DHCPHeaderOUT->YourIP = ClientIPAddress; memmove(&DHCPHeaderOUT->ClientHardwareAddress, &DHCPHeaderIN->ClientHardwareAddress, sizeof(MAC_Address_t)); DHCPHeaderOUT->Cookie = SwapEndian_32(DHCP_MAGIC_COOKIE); - + /* Alter the incoming IP packet header so that the corrected IP source and destinations are used - this means that when the response IP header is generated, it will use the corrected addresses and not the null/broatcast addresses */ IPHeaderIN->SourceAddress = ClientIPAddress; @@ -81,7 +81,7 @@ int16_t DHCP_ProcessDHCPPacket(void* IPHeaderInStart, /* Process the incoming DHCP packet options */ while (DHCPOptionsINStart[0] != DHCP_OPTION_END) - { + { /* Find the Message Type DHCP option, to determine the type of DHCP packet */ if (DHCPOptionsINStart[0] == DHCP_OPTION_MESSAGETYPE) { @@ -107,14 +107,15 @@ int16_t DHCP_ProcessDHCPPacket(void* IPHeaderInStart, DHCPOptionsOUTStart += sizeof(IP_Address_t); *(DHCPOptionsOUTStart++) = DHCP_OPTION_END; - + return (sizeof(DHCP_Header_t) + 12 + sizeof(IP_Address_t)); } } - + /* Go to the next DHCP option - skip one byte if option is a padding byte, else skip the complete option's size */ DHCPOptionsINStart += ((DHCPOptionsINStart[0] == DHCP_OPTION_PAD) ? 1 : (DHCPOptionsINStart[1] + 2)); } - + return NO_RESPONSE; } + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/DHCP.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/DHCP.h index 3bfdb29be..a4dc00dbb 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/DHCP.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/DHCP.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -32,14 +32,14 @@ * * Header file for DHCP.c. */ - + #ifndef _DHCP_H_ #define _DHCP_H_ /* Includes: */ #include <avr/io.h> #include <string.h> - + #include "EthernetProtocols.h" #include "Ethernet.h" #include "ProtocolDecoders.h" @@ -50,13 +50,13 @@ /** DHCP operation constant, indicating a reply from a DHCP server to a host. */ #define DHCP_OP_BOOTREPLY 0x02 - + /** Hardware type constant, indicating Ethernet as a carrier. */ #define DHCP_HTYPE_ETHERNET 0x01 - + /** Magic boot protocol "cookie", inserted into all BOOTP packets (BOOTP is the carrier of DHCP). */ #define DHCP_MAGIC_COOKIE 0x63825363 - + /** DHCP option list entry header, indicating that a subnet mask will follow. */ #define DHCP_OPTION_SUBNETMASK 1 @@ -71,7 +71,7 @@ /** DHCP option list entry header, indicating the end of option data. */ #define DHCP_OPTION_END 255 - + /** Message type constant, used in the DHCP option data field, requesting that a DHCP server offer an IP address. */ #define DHCP_MESSAGETYPE_DISCOVER 1 @@ -106,16 +106,16 @@ uint16_t ElapsedSeconds; /**< Elapsed seconds since the request was made */ uint16_t Flags; /**< BOOTP packet flags */ - + IP_Address_t ClientIP; /**< Client IP address, if already leased an IP */ IP_Address_t YourIP; /**< Client IP address */ IP_Address_t NextServerIP; /**< Legacy BOOTP protocol field, unused for DHCP */ IP_Address_t RelayAgentIP; /**< Legacy BOOTP protocol field, unused for DHCP */ - + uint8_t ClientHardwareAddress[16]; /**< Hardware (MAC) address of the client making a request to the DHCP server */ uint8_t ServerHostnameString[64]; /**< Legacy BOOTP protocol field, unused for DHCP */ uint8_t BootFileName[128]; /**< Legacy BOOTP protocol field, unused for DHCP */ - + uint32_t Cookie; /**< Magic BOOTP protocol cookie to indicate a valid packet */ } DHCP_Header_t; @@ -125,3 +125,4 @@ void* DHCPHeaderOutStart); #endif + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/Ethernet.c b/Demos/Device/LowLevel/RNDISEthernet/Lib/Ethernet.c index 0b9563347..0b74d9cbc 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/Ethernet.c +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/Ethernet.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -34,7 +34,7 @@ * frames sent and received, deferring the processing of sub-packet protocols to the appropriate * protocol handlers, such as DHCP or ARP. */ - + #include "Ethernet.h" /** Ethernet Frame buffer structure, to hold the incoming Ethernet frame from the host. */ @@ -69,9 +69,9 @@ void Ethernet_ProcessPacket(void) /* 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)) && @@ -83,13 +83,13 @@ void Ethernet_ProcessPacket(void) 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.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) { @@ -97,7 +97,7 @@ void Ethernet_ProcessPacket(void) 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; @@ -128,9 +128,10 @@ uint16_t Ethernet_Checksum16(void* Data, for (uint16_t CurrWord = 0; CurrWord < (Bytes >> 1); CurrWord++) Checksum += Words[CurrWord]; - + while (Checksum & 0xFFFF0000) Checksum = ((Checksum & 0xFFFF) + (Checksum >> 16)); - + return ~Checksum; } + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/Ethernet.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/Ethernet.h index 49c6b1c25..68fffb48f 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/Ethernet.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/Ethernet.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -32,7 +32,7 @@ * * Header file for Ethernet.c. */ - + #ifndef _ETHERNET_H_ #define _ETHERNET_H_ @@ -48,19 +48,19 @@ #include "DHCP.h" #include "ARP.h" #include "IP.h" - + /* Macros: */ /** Physical MAC address of the USB RNDIS network adapter. */ #define ADAPTER_MAC_ADDRESS {0x02, 0x00, 0x02, 0x00, 0x02, 0x00} - + /** Physical MAC address of the virtual server on the network. */ - #define SERVER_MAC_ADDRESS {0x00, 0x01, 0x00, 0x01, 0x00, 0x01} + #define SERVER_MAC_ADDRESS {0x00, 0x01, 0x00, 0x01, 0x00, 0x01} /** Physical MAC address of the network broadcast address. */ #define BROADCAST_MAC_ADDRESS {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} - + /** Performs a comparison between two MAC addresses, indicating if they are identical. - * + * * \param[in] MAC1 First MAC address * \param[in] MAC2 Second MAC address * @@ -70,12 +70,12 @@ /** Maximum size of an incoming or outgoing Ethernet frame in bytes. */ #define ETHERNET_FRAME_SIZE_MAX 1500 - + /** Minimum size of an Ethernet packet in bytes, to conform to the Ethernet V2 packet standard. */ #define ETHERNET_VER2_MINSIZE 0x0600 - + /** Return value for all sub protocol handling routines, indicating that no response packet has been generated. */ - #define NO_RESPONSE 0 + #define NO_RESPONSE 0 /** Return value for all sub protocol handling routines, indicating that the packet has not yet been handled. */ #define NO_PROCESS -1 @@ -96,7 +96,7 @@ MAC_Address_t Source; /**< Physics MAC address of the packet source */ uint16_t EtherType; /**< Ethernet packet sub-protocol type, for Ethernet V2 packets */ } Ethernet_Frame_Header_t; - + /* External Variables: */ extern Ethernet_Frame_Info_t FrameIN; extern Ethernet_Frame_Info_t FrameOUT; @@ -106,10 +106,11 @@ extern const MAC_Address_t BroadcastMACAddress; extern const IP_Address_t BroadcastIPAddress; extern const IP_Address_t ClientIPAddress; - + /* Function Prototypes: */ void Ethernet_ProcessPacket(void); uint16_t Ethernet_Checksum16(void* Data, uint16_t Bytes); - + #endif + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/EthernetProtocols.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/EthernetProtocols.h index 014a441cf..8f529d6b4 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/EthernetProtocols.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/EthernetProtocols.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -63,7 +63,7 @@ #define ETHERTYPE_FIBRECHANNEL 0x8906 #define ETHERTYPE_QINQ 0x9100 #define ETHERTYPE_VLLT 0xCAFE - + #define PROTOCOL_ICMP 1 #define PROTOCOL_IGMP 2 #define PROTOCOL_TCP 6 @@ -77,7 +77,7 @@ { uint8_t Octets[6]; /**< Individual bytes of a MAC address */ } MAC_Address_t; - + /** Type define for a protocol IP address of a device on a network. */ typedef struct { @@ -85,3 +85,4 @@ } IP_Address_t; #endif + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/ICMP.c b/Demos/Device/LowLevel/RNDISEthernet/Lib/ICMP.c index 7e4be9c3d..3bf01cd4b 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/ICMP.c +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/ICMP.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -34,7 +34,7 @@ * Echo requests from the host, to indicate a successful network connection between the host * and the virtual server. */ - + #include "ICMP.h" /** Processes an ICMP packet inside an Ethernet frame, and writes the appropriate response @@ -62,9 +62,9 @@ int16_t ICMP_ProcessICMPPacket(void* InDataStart, ICMPHeaderOUT->Checksum = 0; ICMPHeaderOUT->Id = ICMPHeaderIN->Id; ICMPHeaderOUT->Sequence = ICMPHeaderIN->Sequence; - + intptr_t DataSize = FrameIN.FrameLength - ((((intptr_t)InDataStart + sizeof(ICMP_Header_t)) - (intptr_t)FrameIN.FrameData)); - + /* Copy the remaining payload to the response - echo requests should echo back any sent data */ memmove(&((uint8_t*)OutDataStart)[sizeof(ICMP_Header_t)], &((uint8_t*)InDataStart)[sizeof(ICMP_Header_t)], @@ -75,6 +75,7 @@ int16_t ICMP_ProcessICMPPacket(void* InDataStart, /* Return the size of the response so far */ return (DataSize + sizeof(ICMP_Header_t)); } - + return NO_RESPONSE; } + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/ICMP.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/ICMP.h index dcea1ada4..a0fb6eeee 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/ICMP.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/ICMP.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -39,18 +39,18 @@ /* Includes: */ #include <avr/io.h> #include <string.h> - + #include "EthernetProtocols.h" #include "Ethernet.h" #include "ProtocolDecoders.h" - + /* Macros: */ /** ICMP message type constant, indicating an ICMP ECHO Reply message. */ #define ICMP_TYPE_ECHOREPLY 0 /** ICMP message type constant, indicating a packet destination is unreachable. */ #define ICMP_TYPE_DESTINATIONUNREACHABLE 3 - + /** ICMP message type constant, indicating an ICMP Source Quench message. */ #define ICMP_TYPE_SOURCEQUENCH 4 @@ -62,7 +62,7 @@ /** ICMP message type constant, indicating an ICMP Time Exceeded message. */ #define ICMP_TYPE_TIMEEXCEEDED 11 - + /* Type Defines: */ /** Type define for an ICMP message header. */ typedef struct @@ -73,9 +73,10 @@ uint16_t Id; /**< Id of the ICMP message */ uint16_t Sequence; /**< Sequence number of the ICMP message, to link together message responses */ } ICMP_Header_t; - + /* Function Prototypes: */ int16_t ICMP_ProcessICMPPacket(void* InDataStart, void* OutDataStart); #endif + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/IP.c b/Demos/Device/LowLevel/RNDISEthernet/Lib/IP.c index 85ccf426e..731043f8f 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/IP.c +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/IP.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -33,7 +33,7 @@ * Internet Protocol (IP) packet handling routines. This protocol handles IP packets from the * host which typically encapsulate other protocols such as ICMP, UDP and TCP. */ - + #include "IP.h" /** Processes an IP packet inside an Ethernet frame, and writes the appropriate response @@ -65,7 +65,7 @@ int16_t IP_ProcessIPPacket(void* InDataStart, { return NO_RESPONSE; } - + /* Pass off the IP payload to the appropriate protocol processing routine */ switch (IPHeaderIN->Protocol) { @@ -76,15 +76,15 @@ int16_t IP_ProcessIPPacket(void* InDataStart, case PROTOCOL_TCP: RetSize = TCP_ProcessTCPPacket(InDataStart, &((uint8_t*)InDataStart)[HeaderLengthBytes], - &((uint8_t*)OutDataStart)[sizeof(IP_Header_t)]); + &((uint8_t*)OutDataStart)[sizeof(IP_Header_t)]); break; case PROTOCOL_UDP: RetSize = UDP_ProcessUDPPacket(InDataStart, &((uint8_t*)InDataStart)[HeaderLengthBytes], - &((uint8_t*)OutDataStart)[sizeof(IP_Header_t)]); + &((uint8_t*)OutDataStart)[sizeof(IP_Header_t)]); break; } - + /* Check to see if the protocol processing routine has filled out a response */ if (RetSize > 0) { @@ -101,12 +101,13 @@ int16_t IP_ProcessIPPacket(void* InDataStart, IPHeaderOUT->TTL = DEFAULT_TTL; IPHeaderOUT->SourceAddress = IPHeaderIN->DestinationAddress; IPHeaderOUT->DestinationAddress = IPHeaderIN->SourceAddress; - + IPHeaderOUT->HeaderChecksum = Ethernet_Checksum16(IPHeaderOUT, sizeof(IP_Header_t)); - + /* Return the size of the response so far */ return (sizeof(IP_Header_t) + RetSize); } - + return RetSize; } + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/IP.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/IP.h index 8f45113be..c1b2817ca 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/IP.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/IP.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -32,18 +32,18 @@ * * Header file for IP.c. */ - + #ifndef _IP_H_ #define _IP_H_ /* Includes: */ #include <avr/io.h> #include <string.h> - + #include "EthernetProtocols.h" #include "Ethernet.h" #include "ProtocolDecoders.h" - + /* Macros: */ /** Protocol IP address of the host (client) machine, once assigned by DHCP. */ #define CLIENT_IP_ADDRESS { 10, 0, 0, 1} @@ -58,16 +58,16 @@ * is reached. */ #define DEFAULT_TTL 128 - + /** Performs a comparison between two IP addresses, indicating if they are identical. - * + * * \param[in] IP1 First IP address * \param[in] IP2 Second IP address * * \return True if the addresses match, false otherwise */ #define IP_COMPARE(IP1, IP2) (memcmp(IP1, IP2, sizeof(IP_Address_t)) == 0) - + /* Type Defines: */ /** Type define of an IP packet header. */ typedef struct @@ -84,13 +84,14 @@ uint8_t TTL; /**< Maximum allowable number of hops to reach the packet destination */ uint8_t Protocol; /**< Encapsulated protocol type */ uint16_t HeaderChecksum; /**< Ethernet checksum of the IP header */ - + IP_Address_t SourceAddress; /**< Source protocol IP address of the packet */ IP_Address_t DestinationAddress; /**< Destination protocol IP address of the packet */ } IP_Header_t; - + /* Function Prototypes: */ int16_t IP_ProcessIPPacket(void* InDataStart, void* OutDataStart); #endif + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/ProtocolDecoders.c b/Demos/Device/LowLevel/RNDISEthernet/Lib/ProtocolDecoders.c index 84e03e0ae..38df7eb64 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/ProtocolDecoders.c +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/ProtocolDecoders.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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,7 +31,7 @@ /* Protocol decoders for Ethernet, TCP, IP, ICMP and ARP. Each of these routines accepts a header to the appropriate protocol and prints out pertinent information on the packet through the serial port. - + To disable printing of a specific protocol, define the token NO_DECODE_{Protocol} in the project makefile, and pass it to the compiler using the -D switch. */ @@ -46,7 +46,7 @@ * Packet decoding routines can be disabled by defining NO_DECODE_{Protocol Name} in the project makefile * and passing it to the compiler via the -D switch. */ - + #include "ProtocolDecoders.h" /** Decodes an Ethernet frame header and prints its contents to through the USART in a human readable format. @@ -57,9 +57,9 @@ void DecodeEthernetFrameHeader(void* InDataStart) { #if !defined(NO_DECODE_ETHERNET) Ethernet_Frame_Header_t* FrameHeader = (Ethernet_Frame_Header_t*)InDataStart; - + printf_P(PSTR("\r\n")); - + printf_P(PSTR(" ETHERNET\r\n")); printf_P(PSTR(" + Frame Size: %u\r\n"), FrameIN.FrameLength); @@ -98,7 +98,7 @@ void DecodeEthernetFrameHeader(void* InDataStart) void DecodeARPHeader(void* InDataStart) { #if !defined(NO_DECODE_ARP) - ARP_Header_t* ARPHeader = (ARP_Header_t*)InDataStart; + ARP_Header_t* ARPHeader = (ARP_Header_t*)InDataStart; printf_P(PSTR(" \\\r\n ARP\r\n")); @@ -106,12 +106,12 @@ void DecodeARPHeader(void* InDataStart) !(MAC_COMPARE(&ARPHeader->THA, &ServerMACAddress))) { printf_P(PSTR(" + NOT ADDRESSED TO DEVICE\r\n")); - return; + return; } printf_P(PSTR(" + Protocol: %x\r\n"), SwapEndian_16(ARPHeader->ProtocolType)); printf_P(PSTR(" + Operation: %u\r\n"), SwapEndian_16(ARPHeader->Operation)); - + if (SwapEndian_16(ARPHeader->ProtocolType) == ETHERTYPE_IPV4) { printf_P(PSTR(" + SHA MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n"), ARPHeader->SHA.Octets[0], @@ -163,14 +163,14 @@ void DecodeIPHeader(void* InDataStart) printf_P(PSTR(" + Header Length: %u Bytes\r\n"), HeaderLengthBytes); printf_P(PSTR(" + Packet Version: %u\r\n"), IPHeader->Version); printf_P(PSTR(" + Total Length: %u\r\n"), SwapEndian_16(IPHeader->TotalLength)); - + printf_P(PSTR(" + Protocol: %u\r\n"), IPHeader->Protocol); printf_P(PSTR(" + TTL: %u\r\n"), IPHeader->TTL); - + printf_P(PSTR(" + IP Src: %u.%u.%u.%u\r\n"), IPHeader->SourceAddress.Octets[0], IPHeader->SourceAddress.Octets[1], IPHeader->SourceAddress.Octets[2], - IPHeader->SourceAddress.Octets[3]); + IPHeader->SourceAddress.Octets[3]); printf_P(PSTR(" + IP Dst: %u.%u.%u.%u\r\n"), IPHeader->DestinationAddress.Octets[0], IPHeader->DestinationAddress.Octets[1], @@ -215,9 +215,9 @@ void DecodeTCPHeader(void* InDataStart) printf_P(PSTR(" + Sequence Number: %lu\r\n"), SwapEndian_32(TCPHeader->SequenceNumber)); printf_P(PSTR(" + Acknowledgment Number: %lu\r\n"), SwapEndian_32(TCPHeader->AcknowledgmentNumber)); - + printf_P(PSTR(" + Flags: 0x%02X\r\n"), TCPHeader->Flags); - + if (TCP_GetPortState(TCPHeader->DestinationPort) == TCP_Port_Closed) printf_P(PSTR(" + NOT LISTENING ON DESTINATION PORT\r\n")); #endif @@ -272,8 +272,9 @@ void DecodeDHCPHeader(void* InDataStart) break; } } - + DHCPOptions += ((DHCPOptions[0] == DHCP_OPTION_PAD) ? 1 : (DHCPOptions[1] + 2)); } #endif } + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/ProtocolDecoders.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/ProtocolDecoders.h index 4723bf472..8c124b427 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/ProtocolDecoders.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/ProtocolDecoders.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -40,12 +40,12 @@ #include <avr/io.h> #include <avr/pgmspace.h> #include <stdio.h> - + #include <LUFA/Drivers/Peripheral/SerialStream.h> - + #include "EthernetProtocols.h" #include "Ethernet.h" - + /* Function Prototypes: */ void DecodeEthernetFrameHeader(void* InDataStart); void DecodeARPHeader(void* InDataStart); @@ -56,3 +56,4 @@ void DecodeDHCPHeader(void* InDataStart); #endif + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDIS.c b/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDIS.c index 3875f8801..520557003 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDIS.c +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDIS.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -33,7 +33,7 @@ * RNDIS command handler functions. This handles RNDIS commands according to * the Microsoft RNDIS specification, creating a USB Ethernet network adapter. */ - + #define INCLUDE_FROM_RNDIS_C #include "RNDIS.h" @@ -93,7 +93,7 @@ bool ResponseReady = false; uint8_t CurrRNDISState = RNDIS_Uninitialized; /** Current Ethernet packet filter mask. This is non-zero when the adapter is initialized, or zero when disabled. */ -uint32_t CurrPacketFilter = 0; +uint32_t CurrPacketFilter = 0; /** Processes the RNDIS message received by the host and stored in the RNDISMessageBuffer global buffer. If a response is @@ -110,17 +110,17 @@ void ProcessRNDISControlMessage(void) /* Initialize the adapter - return information about the supported RNDIS version and buffer sizes */ ResponseReady = true; - + RNDIS_Initialize_Message_t* INITIALIZE_Message = (RNDIS_Initialize_Message_t*)&RNDISMessageBuffer; RNDIS_Initialize_Complete_t* INITIALIZE_Response = (RNDIS_Initialize_Complete_t*)&RNDISMessageBuffer; - + INITIALIZE_Response->MessageType = REMOTE_NDIS_INITIALIZE_CMPLT; INITIALIZE_Response->MessageLength = sizeof(RNDIS_Initialize_Complete_t); INITIALIZE_Response->RequestId = INITIALIZE_Message->RequestId; INITIALIZE_Response->Status = REMOTE_NDIS_STATUS_SUCCESS; - + INITIALIZE_Response->MajorVersion = REMOTE_NDIS_VERSION_MAJOR; - INITIALIZE_Response->MinorVersion = REMOTE_NDIS_VERSION_MINOR; + INITIALIZE_Response->MinorVersion = REMOTE_NDIS_VERSION_MINOR; INITIALIZE_Response->DeviceFlags = REMOTE_NDIS_DF_CONNECTIONLESS; INITIALIZE_Response->Medium = REMOTE_NDIS_MEDIUM_802_3; INITIALIZE_Response->MaxPacketsPerTransfer = 1; @@ -128,9 +128,9 @@ void ProcessRNDISControlMessage(void) INITIALIZE_Response->PacketAlignmentFactor = 0; INITIALIZE_Response->AFListOffset = 0; INITIALIZE_Response->AFListSize = 0; - + CurrRNDISState = RNDIS_Initialized; - + break; case REMOTE_NDIS_HALT_MSG: /* Halt the adapter, reset the adapter state - note that no response should be returned when completed */ @@ -145,42 +145,42 @@ void ProcessRNDISControlMessage(void) /* Request for information about a parameter about the adapter, specified as an OID token */ ResponseReady = true; - + RNDIS_Query_Message_t* QUERY_Message = (RNDIS_Query_Message_t*)&RNDISMessageBuffer; RNDIS_Query_Complete_t* QUERY_Response = (RNDIS_Query_Complete_t*)&RNDISMessageBuffer; uint32_t Query_Oid = QUERY_Message->Oid; - + void* QueryData = &RNDISMessageBuffer[sizeof(RNDIS_Message_Header_t) + QUERY_Message->InformationBufferOffset]; - void* ResponseData = &RNDISMessageBuffer[sizeof(RNDIS_Query_Complete_t)]; + void* ResponseData = &RNDISMessageBuffer[sizeof(RNDIS_Query_Complete_t)]; uint16_t ResponseSize; QUERY_Response->MessageType = REMOTE_NDIS_QUERY_CMPLT; QUERY_Response->MessageLength = sizeof(RNDIS_Query_Complete_t); - + if (ProcessNDISQuery(Query_Oid, QueryData, QUERY_Message->InformationBufferLength, ResponseData, &ResponseSize)) { QUERY_Response->Status = REMOTE_NDIS_STATUS_SUCCESS; QUERY_Response->MessageLength += ResponseSize; - + QUERY_Response->InformationBufferLength = ResponseSize; QUERY_Response->InformationBufferOffset = (sizeof(RNDIS_Query_Complete_t) - sizeof(RNDIS_Message_Header_t)); } else - { + { QUERY_Response->Status = REMOTE_NDIS_STATUS_NOT_SUPPORTED; QUERY_Response->InformationBufferLength = 0; QUERY_Response->InformationBufferOffset = 0; } - + break; case REMOTE_NDIS_SET_MSG: /* Request to set a parameter of the adapter, specified as an OID token */ - + ResponseReady = true; - + RNDIS_Set_Message_t* SET_Message = (RNDIS_Set_Message_t*)&RNDISMessageBuffer; RNDIS_Set_Complete_t* SET_Response = (RNDIS_Set_Complete_t*)&RNDISMessageBuffer; uint32_t SET_Oid = SET_Message->Oid; @@ -191,7 +191,7 @@ void ProcessRNDISControlMessage(void) void* SetData = &RNDISMessageBuffer[sizeof(RNDIS_Message_Header_t) + SET_Message->InformationBufferOffset]; - + if (ProcessNDISSet(SET_Oid, SetData, SET_Message->InformationBufferLength)) SET_Response->Status = REMOTE_NDIS_STATUS_SUCCESS; else @@ -200,9 +200,9 @@ void ProcessRNDISControlMessage(void) break; case REMOTE_NDIS_RESET_MSG: /* Soft reset the adapter */ - + ResponseReady = true; - + RNDIS_Reset_Complete_t* RESET_Response = (RNDIS_Reset_Complete_t*)&RNDISMessageBuffer; RESET_Response->MessageType = REMOTE_NDIS_RESET_CMPLT; @@ -213,9 +213,9 @@ void ProcessRNDISControlMessage(void) break; case REMOTE_NDIS_KEEPALIVE_MSG: /* Keep alive message sent to the adapter every 5 seconds when idle to ensure it is still responding */ - + ResponseReady = true; - + RNDIS_KeepAlive_Message_t* KEEPALIVE_Message = (RNDIS_KeepAlive_Message_t*)&RNDISMessageBuffer; RNDIS_KeepAlive_Complete_t* KEEPALIVE_Response = (RNDIS_KeepAlive_Complete_t*)&RNDISMessageBuffer; @@ -223,7 +223,7 @@ void ProcessRNDISControlMessage(void) KEEPALIVE_Response->MessageLength = sizeof(RNDIS_KeepAlive_Complete_t); KEEPALIVE_Response->RequestId = KEEPALIVE_Message->RequestId; KEEPALIVE_Response->Status = REMOTE_NDIS_STATUS_SUCCESS; - + break; } } @@ -248,66 +248,66 @@ static bool ProcessNDISQuery(const uint32_t OId, void* QueryData, uint16_t Query { case OID_GEN_SUPPORTED_LIST: *ResponseSize = sizeof(AdapterSupportedOIDList); - + /* Copy the list of supported NDIS OID tokens to the response buffer */ memcpy_P(ResponseData, AdapterSupportedOIDList, sizeof(AdapterSupportedOIDList)); - + return true; case OID_GEN_PHYSICAL_MEDIUM: *ResponseSize = sizeof(uint32_t); - + /* Indicate that the device is a true ethernet link */ *((uint32_t*)ResponseData) = 0; - + return true; case OID_GEN_HARDWARE_STATUS: *ResponseSize = sizeof(uint32_t); - + /* Always indicate hardware ready */ *((uint32_t*)ResponseData) = NdisHardwareStatusReady; - + return true; case OID_GEN_MEDIA_SUPPORTED: case OID_GEN_MEDIA_IN_USE: *ResponseSize = sizeof(uint32_t); - + /* Indicate 802.3 (Ethernet) supported by the adapter */ *((uint32_t*)ResponseData) = REMOTE_NDIS_MEDIUM_802_3; - + return true; case OID_GEN_VENDOR_ID: *ResponseSize = sizeof(uint32_t); - + /* Vendor ID 0x0xFFFFFF is reserved for vendors who have not purchased a NDIS VID */ *((uint32_t*)ResponseData) = 0x00FFFFFF; - + return true; case OID_GEN_MAXIMUM_FRAME_SIZE: case OID_GEN_TRANSMIT_BLOCK_SIZE: case OID_GEN_RECEIVE_BLOCK_SIZE: *ResponseSize = sizeof(uint32_t); - + /* Indicate that the maximum frame size is the size of the ethernet frame buffer */ *((uint32_t*)ResponseData) = ETHERNET_FRAME_SIZE_MAX; - + return true; case OID_GEN_VENDOR_DESCRIPTION: *ResponseSize = sizeof(AdapterVendorDescription); - + /* Copy vendor description string to the response buffer */ memcpy_P(ResponseData, AdapterVendorDescription, sizeof(AdapterVendorDescription)); - + return true; case OID_GEN_MEDIA_CONNECT_STATUS: *ResponseSize = sizeof(uint32_t); - + /* Always indicate that the adapter is connected to a network */ *((uint32_t*)ResponseData) = REMOTE_NDIS_MEDIA_STATE_CONNECTED; - + return true; case OID_GEN_LINK_SPEED: *ResponseSize = sizeof(uint32_t); - + /* Indicate 10Mb/s link speed */ *((uint32_t*)ResponseData) = 100000; @@ -315,25 +315,25 @@ static bool ProcessNDISQuery(const uint32_t OId, void* QueryData, uint16_t Query case OID_802_3_PERMANENT_ADDRESS: case OID_802_3_CURRENT_ADDRESS: *ResponseSize = sizeof(MAC_Address_t); - + /* Copy over the fixed adapter MAC to the response buffer */ memcpy_P(ResponseData, &AdapterMACAddress, sizeof(MAC_Address_t)); return true; case OID_802_3_MAXIMUM_LIST_SIZE: *ResponseSize = sizeof(uint32_t); - + /* Indicate only one multicast address supported */ *((uint32_t*)ResponseData) = 1; - + return true; case OID_GEN_CURRENT_PACKET_FILTER: *ResponseSize = sizeof(uint32_t); - + /* Indicate the current packet filter mask */ *((uint32_t*)ResponseData) = CurrPacketFilter; - - return true; + + return true; case OID_GEN_XMIT_OK: case OID_GEN_RCV_OK: case OID_GEN_XMIT_ERROR: @@ -343,24 +343,24 @@ static bool ProcessNDISQuery(const uint32_t OId, void* QueryData, uint16_t Query case OID_802_3_XMIT_ONE_COLLISION: case OID_802_3_XMIT_MORE_COLLISIONS: *ResponseSize = sizeof(uint32_t); - + /* Unused statistic OIDs - always return 0 for each */ *((uint32_t*)ResponseData) = 0; - + return true; case OID_GEN_MAXIMUM_TOTAL_SIZE: *ResponseSize = sizeof(uint32_t); - + /* Indicate maximum overall buffer (Ethernet frame and RNDIS header) the adapter can handle */ *((uint32_t*)ResponseData) = (sizeof(RNDISMessageBuffer) + ETHERNET_FRAME_SIZE_MAX); - + return true; default: return false; } } -/** Processes RNDIS set commands, setting adapter parameters to values given by the host. The requested parameter is given +/** Processes RNDIS set commands, setting adapter parameters to values given by the host. The requested parameter is given * as an OID value. * * \param[in] OId OId value of the parameter being set @@ -378,16 +378,17 @@ static bool ProcessNDISSet(uint32_t OId, void* SetData, uint16_t SetSize) case OID_GEN_CURRENT_PACKET_FILTER: /* Save the packet filter mask in case the host queries it again later */ CurrPacketFilter = *((uint32_t*)SetData); - + /* Set the RNDIS state to initialized if the packet filter is non-zero */ CurrRNDISState = ((CurrPacketFilter) ? RNDIS_Data_Initialized : RNDIS_Data_Initialized); - + return true; case OID_802_3_MULTICAST_LIST: /* Do nothing - throw away the value from the host as it is unused */ - + return true; default: return false; } } + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDIS.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDIS.h index 17a34ace7..ed35b3546 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDIS.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDIS.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -39,7 +39,7 @@ /* Includes: */ #include <avr/io.h> #include <stdbool.h> - + #include "RNDISEthernet.h" #include "RNDISConstants.h" #include "Ethernet.h" @@ -50,13 +50,13 @@ /** Implemented RNDIS Version Minor. */ #define REMOTE_NDIS_VERSION_MINOR 0x00 - + /** RNDIS request to issue a host-to-device NDIS command. */ #define REQ_SendEncapsulatedCommand 0x00 /** RNDIS request to issue a device-to-host NDIS response. */ #define REQ_GetEncapsulatedResponse 0x01 - + /* Enums: */ /** Enum for the possible NDIS adapter states. */ enum RNDIS_States_t @@ -99,19 +99,19 @@ uint32_t VcHandle; uint32_t Reserved; } RNDIS_Packet_Message_t; - + /** Type define for a RNDIS Initialize command message. */ typedef struct { uint32_t MessageType; uint32_t MessageLength; uint32_t RequestId; - + uint32_t MajorVersion; uint32_t MinorVersion; uint32_t MaxTransferSize; } RNDIS_Initialize_Message_t; - + /** Type define for a RNDIS Initialize complete response message. */ typedef struct { @@ -119,7 +119,7 @@ uint32_t MessageLength; uint32_t RequestId; uint32_t Status; - + uint32_t MajorVersion; uint32_t MinorVersion; uint32_t DeviceFlags; @@ -130,7 +130,7 @@ uint32_t AFListOffset; uint32_t AFListSize; } RNDIS_Initialize_Complete_t; - + /** Type define for a RNDIS Keep-alive command message. */ typedef struct { @@ -157,14 +157,14 @@ uint32_t AddressingReset; } RNDIS_Reset_Complete_t; - + /** Type define for a RNDIS Set command message. */ typedef struct { uint32_t MessageType; uint32_t MessageLength; uint32_t RequestId; - + uint32_t Oid; uint32_t InformationBufferLength; uint32_t InformationBufferOffset; @@ -179,20 +179,20 @@ uint32_t RequestId; uint32_t Status; } RNDIS_Set_Complete_t; - + /** Type define for a RNDIS Query command message. */ typedef struct { uint32_t MessageType; uint32_t MessageLength; uint32_t RequestId; - + uint32_t Oid; uint32_t InformationBufferLength; uint32_t InformationBufferOffset; uint32_t DeviceVcHandle; } RNDIS_Query_Message_t; - + /** Type define for a RNDIS Query complete response message. */ typedef struct { @@ -200,11 +200,11 @@ uint32_t MessageLength; uint32_t RequestId; uint32_t Status; - + uint32_t InformationBufferLength; uint32_t InformationBufferOffset; } RNDIS_Query_Complete_t; - + /* External Variables: */ extern uint8_t RNDISMessageBuffer[]; extern RNDIS_Message_Header_t* MessageHeader; @@ -222,7 +222,8 @@ uint16_t* ResponseSize); static bool ProcessNDISSet(const uint32_t OId, void* SetData, - uint16_t SetSize); + uint16_t SetSize); #endif - + #endif + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDISConstants.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDISConstants.h index efe22b699..273fdb81e 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDISConstants.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/RNDISConstants.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -33,7 +33,7 @@ * RNDIS specification related constants. For more information on these * constants, please refer to the Microsoft RNDIS specification. */ - + #ifndef _RNDIS_CONSTANTS_DEVICE_H_ #define _RNDIS_CONSTANTS_DEVICE_H_ @@ -52,19 +52,19 @@ #define REMOTE_NDIS_SET_CMPLT 0x80000005UL #define REMOTE_NDIS_RESET_CMPLT 0x80000006UL #define REMOTE_NDIS_KEEPALIVE_CMPLT 0x80000008UL - + #define REMOTE_NDIS_STATUS_SUCCESS 0x00000000UL #define REMOTE_NDIS_STATUS_FAILURE 0xC0000001UL #define REMOTE_NDIS_STATUS_INVALID_DATA 0xC0010015UL #define REMOTE_NDIS_STATUS_NOT_SUPPORTED 0xC00000BBUL #define REMOTE_NDIS_STATUS_MEDIA_CONNECT 0x4001000BUL #define REMOTE_NDIS_STATUS_MEDIA_DISCONNECT 0x4001000CUL - + #define REMOTE_NDIS_MEDIA_STATE_CONNECTED 0x00000000UL #define REMOTE_NDIS_MEDIA_STATE_DISCONNECTED 0x00000001UL - + #define REMOTE_NDIS_MEDIUM_802_3 0x00000000UL - + #define REMOTE_NDIS_DF_CONNECTIONLESS 0x00000001UL #define REMOTE_NDIS_DF_CONNECTION_ORIENTED 0x00000002UL @@ -79,8 +79,8 @@ #define REMOTE_NDIS_PACKET_GROUP 0x00001000UL #define REMOTE_NDIS_PACKET_ALL_FUNCTIONAL 0x00002000UL #define REMOTE_NDIS_PACKET_FUNCTIONAL 0x00004000UL - #define REMOTE_NDIS_PACKET_MAC_FRAME 0x00008000UL - + #define REMOTE_NDIS_PACKET_MAC_FRAME 0x00008000UL + #define OID_GEN_SUPPORTED_LIST 0x00010101UL #define OID_GEN_HARDWARE_STATUS 0x00010102UL #define OID_GEN_MEDIA_SUPPORTED 0x00010103UL @@ -110,3 +110,4 @@ #define OID_802_3_XMIT_MORE_COLLISIONS 0x01020103UL #endif + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/TCP.c b/Demos/Device/LowLevel/RNDISEthernet/Lib/TCP.c index a159f35d1..fe8716890 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/TCP.c +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/TCP.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -34,7 +34,7 @@ * and reception of packets to and from devices on a network, to "ports" on the device. It is used in situations where data * delivery must be reliable and correct, e.g. HTTP, TELNET and most other non-streaming protocols. */ - + #define INCLUDE_FROM_TCP_C #include "TCP.h" @@ -64,7 +64,7 @@ void TCP_Task(void) for (uint8_t PTableEntry = 0; PTableEntry < MAX_OPEN_TCP_PORTS; PTableEntry++) { /* Run the application handler for the port */ - if ((PortStateTable[PTableEntry].Port == ConnectionStateTable[CSTableEntry].Port) && + if ((PortStateTable[PTableEntry].Port == ConnectionStateTable[CSTableEntry].Port) && (PortStateTable[PTableEntry].State == TCP_Port_Open)) { PortStateTable[PTableEntry].ApplicationHandler(&ConnectionStateTable[CSTableEntry], @@ -72,11 +72,11 @@ void TCP_Task(void) } } } - + /* Bail out early if there is already a frame waiting to be sent in the Ethernet OUT buffer */ if (FrameOUT.FrameInBuffer) return; - + /* Send response packets from each application as the TCP packet buffers are filled by the applications */ for (uint8_t CSTableEntry = 0; CSTableEntry < MAX_TCP_CONNECTIONS; CSTableEntry++) { @@ -108,7 +108,7 @@ void TCP_Task(void) TCPHeaderOUT->Reserved = 0; memcpy(TCPDataOUT, ConnectionStateTable[CSTableEntry].Info.Buffer.Data, PacketSize); - + ConnectionStateTable[CSTableEntry].Info.SequenceNumberOut += PacketSize; TCPHeaderOUT->Checksum = TCP_Checksum16(TCPHeaderOUT, ServerIPAddress, @@ -130,11 +130,11 @@ void TCP_Task(void) IPHeaderOUT->TTL = DEFAULT_TTL; IPHeaderOUT->SourceAddress = ServerIPAddress; IPHeaderOUT->DestinationAddress = ConnectionStateTable[CSTableEntry].RemoteAddress; - + IPHeaderOUT->HeaderChecksum = Ethernet_Checksum16(IPHeaderOUT, sizeof(IP_Header_t)); - + PacketSize += sizeof(IP_Header_t); - + /* Fill out the response Ethernet frame header */ FrameOUTHeader->Source = ServerMACAddress; FrameOUTHeader->Destination = (MAC_Address_t){{0x02, 0x00, 0x02, 0x00, 0x02, 0x00}}; @@ -145,9 +145,9 @@ void TCP_Task(void) /* Set the response length in the buffer and indicate that a response is ready to be sent */ FrameOUT.FrameLength = PacketSize; FrameOUT.FrameInBuffer = true; - + ConnectionStateTable[CSTableEntry].Info.Buffer.Ready = false; - + break; } } @@ -207,7 +207,7 @@ bool TCP_SetPortState(const uint16_t Port, return true; } } - + /* Port not in table and no room to add it, return failure */ return false; } @@ -234,7 +234,7 @@ uint8_t TCP_GetPortState(const uint16_t Port) if (PortStateTable[PTableEntry].Port == Port) return PortStateTable[PTableEntry].State; } - + /* Port not in table, assume closed */ return TCP_Port_Closed; } @@ -267,20 +267,20 @@ bool TCP_SetConnectionState(const uint16_t Port, return true; } } - + for (uint8_t CSTableEntry = 0; CSTableEntry < MAX_TCP_CONNECTIONS; CSTableEntry++) { /* Find empty entry in the table */ if (ConnectionStateTable[CSTableEntry].State == TCP_Connection_Closed) { ConnectionStateTable[CSTableEntry].Port = Port; - ConnectionStateTable[CSTableEntry].RemoteAddress = RemoteAddress; + ConnectionStateTable[CSTableEntry].RemoteAddress = RemoteAddress; ConnectionStateTable[CSTableEntry].RemotePort = RemotePort; ConnectionStateTable[CSTableEntry].State = State; return true; } } - + return false; } @@ -304,12 +304,12 @@ uint8_t TCP_GetConnectionState(const uint16_t Port, if ((ConnectionStateTable[CSTableEntry].Port == Port) && IP_COMPARE(&ConnectionStateTable[CSTableEntry].RemoteAddress, &RemoteAddress) && ConnectionStateTable[CSTableEntry].RemotePort == RemotePort) - + { return ConnectionStateTable[CSTableEntry].State; } } - + return TCP_Connection_Closed; } @@ -337,7 +337,7 @@ TCP_ConnectionInfo_t* TCP_GetConnectionInfo(const uint16_t Port, return &ConnectionStateTable[CSTableEntry].Info; } } - + return NULL; } @@ -361,11 +361,11 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, TCP_Header_t* TCPHeaderOUT = (TCP_Header_t*)TCPHeaderOutStart; TCP_ConnectionInfo_t* ConnectionInfo; - + DecodeTCPHeader(TCPHeaderInStart); bool PacketResponse = false; - + /* Check if the destination port is open and allows incoming connections */ if (TCP_GetPortState(TCPHeaderIN->DestinationPort) == TCP_Port_Open) { @@ -379,8 +379,8 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, if (TCP_SetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort, TCP_Connection_Closed)) { - TCPHeaderOUT->Flags = (TCP_FLAG_RST | TCP_FLAG_ACK); - PacketResponse = true; + TCPHeaderOUT->Flags = (TCP_FLAG_RST | TCP_FLAG_ACK); + PacketResponse = true; } } else @@ -395,7 +395,7 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, if (TCP_SetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort, TCP_Connection_SYNReceived)) { - TCPHeaderOUT->Flags = (TCP_FLAG_SYN | TCP_FLAG_ACK); + TCPHeaderOUT->Flags = (TCP_FLAG_SYN | TCP_FLAG_ACK); ConnectionInfo = TCP_GetConnectionInfo(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort); @@ -407,10 +407,10 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, { TCPHeaderOUT->Flags = TCP_FLAG_RST; } - + PacketResponse = true; } - + break; case TCP_Connection_SYNReceived: if (TCPHeaderIN->Flags == TCP_FLAG_ACK) @@ -422,19 +422,19 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, ConnectionInfo = TCP_GetConnectionInfo(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort); - + ConnectionInfo->SequenceNumberOut++; } - + break; case TCP_Connection_Established: if (TCPHeaderIN->Flags == (TCP_FLAG_FIN | TCP_FLAG_ACK)) { /* FIN ACK when connected to a peer starts the finalization process */ - - TCPHeaderOUT->Flags = (TCP_FLAG_FIN | TCP_FLAG_ACK); + + TCPHeaderOUT->Flags = (TCP_FLAG_FIN | TCP_FLAG_ACK); PacketResponse = true; - + TCP_SetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort, TCP_Connection_CloseWait); @@ -449,14 +449,14 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, ConnectionInfo = TCP_GetConnectionInfo(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort); - /* Check if the buffer is currently in use either by a buffered data to send, or receive */ + /* Check if the buffer is currently in use either by a buffered data to send, or receive */ if ((ConnectionInfo->Buffer.InUse == false) && (ConnectionInfo->Buffer.Ready == false)) - { + { ConnectionInfo->Buffer.Direction = TCP_PACKETDIR_IN; ConnectionInfo->Buffer.InUse = true; ConnectionInfo->Buffer.Length = 0; } - + /* Check if the buffer has been claimed by us to read in data from the peer */ if ((ConnectionInfo->Buffer.Direction == TCP_PACKETDIR_IN) && (ConnectionInfo->Buffer.Length != TCP_WINDOW_SIZE)) @@ -472,7 +472,7 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, ConnectionInfo->SequenceNumberIn += DataLength; ConnectionInfo->Buffer.Length += DataLength; - + /* Check if the buffer is full or if the PSH flag is set, if so indicate buffer ready */ if ((!(TCP_WINDOW_SIZE - ConnectionInfo->Buffer.Length)) || (TCPHeaderIN->Flags & TCP_FLAG_PSH)) { @@ -489,7 +489,7 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, return NO_PROCESS; } } - + break; case TCP_Connection_Closing: ConnectionInfo = TCP_GetConnectionInfo(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, @@ -497,9 +497,9 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, TCPHeaderOUT->Flags = (TCP_FLAG_ACK | TCP_FLAG_FIN); PacketResponse = true; - + ConnectionInfo->Buffer.InUse = false; - + TCP_SetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort, TCP_Connection_FINWait1); @@ -515,7 +515,7 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, ConnectionInfo->SequenceNumberIn++; ConnectionInfo->SequenceNumberOut++; - + TCP_SetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort, TCP_Connection_Closed); } @@ -524,7 +524,7 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, TCP_SetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort, TCP_Connection_FINWait2); } - + break; case TCP_Connection_FINWait2: if (TCPHeaderIN->Flags == (TCP_FLAG_FIN | TCP_FLAG_ACK)) @@ -537,11 +537,11 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, ConnectionInfo->SequenceNumberIn++; ConnectionInfo->SequenceNumberOut++; - + TCP_SetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort, TCP_Connection_Closed); } - + break; case TCP_Connection_CloseWait: if (TCPHeaderIN->Flags == TCP_FLAG_ACK) @@ -549,7 +549,7 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, TCP_SetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, TCPHeaderIN->SourcePort, TCP_Connection_Closed); } - + break; } } @@ -557,10 +557,10 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, else { /* Port is not open, indicate via a RST/ACK response to the sender */ - TCPHeaderOUT->Flags = (TCP_FLAG_RST | TCP_FLAG_ACK); + TCPHeaderOUT->Flags = (TCP_FLAG_RST | TCP_FLAG_ACK); PacketResponse = true; } - + /* Check if we need to respond to the sent packet */ if (PacketResponse) { @@ -572,7 +572,7 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, TCPHeaderOUT->SequenceNumber = SwapEndian_32(ConnectionInfo->SequenceNumberOut); TCPHeaderOUT->AcknowledgmentNumber = SwapEndian_32(ConnectionInfo->SequenceNumberIn); TCPHeaderOUT->DataOffset = (sizeof(TCP_Header_t) / sizeof(uint32_t)); - + if (!(ConnectionInfo->Buffer.InUse)) TCPHeaderOUT->WindowSize = SwapEndian_16(TCP_WINDOW_SIZE); else @@ -581,11 +581,11 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, TCPHeaderOUT->UrgentPointer = 0; TCPHeaderOUT->Checksum = 0; TCPHeaderOUT->Reserved = 0; - + TCPHeaderOUT->Checksum = TCP_Checksum16(TCPHeaderOUT, IPHeaderIN->DestinationAddress, - IPHeaderIN->SourceAddress, sizeof(TCP_Header_t)); + IPHeaderIN->SourceAddress, sizeof(TCP_Header_t)); - return sizeof(TCP_Header_t); + return sizeof(TCP_Header_t); } return NO_RESPONSE; @@ -607,10 +607,10 @@ static uint16_t TCP_Checksum16(void* TCPHeaderOutStart, uint16_t TCPOutSize) { uint32_t Checksum = 0; - + /* TCP/IP checksums are the addition of the one's compliment of each word including the IP pseudo-header, complimented */ - + Checksum += ((uint16_t*)&SourceAddress)[0]; Checksum += ((uint16_t*)&SourceAddress)[1]; Checksum += ((uint16_t*)&DestinationAddress)[0]; @@ -620,12 +620,13 @@ static uint16_t TCP_Checksum16(void* TCPHeaderOutStart, for (uint16_t CurrWord = 0; CurrWord < (TCPOutSize >> 1); CurrWord++) Checksum += ((uint16_t*)TCPHeaderOutStart)[CurrWord]; - + if (TCPOutSize & 0x01) Checksum += (((uint16_t*)TCPHeaderOutStart)[TCPOutSize >> 1] & 0x00FF); - + while (Checksum & 0xFFFF0000) Checksum = ((Checksum & 0xFFFF) + (Checksum >> 16)); - + return ~Checksum; } + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/TCP.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/TCP.h index 838e0134b..0b1160dee 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/TCP.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/TCP.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -39,11 +39,11 @@ /* Includes: */ #include <avr/io.h> #include <stdbool.h> - + #include "EthernetProtocols.h" #include "Ethernet.h" #include "ProtocolDecoders.h" - + /* Macros: */ /** Maximum number of TCP ports which can be open at the one time. */ #define MAX_OPEN_TCP_PORTS 1 @@ -53,16 +53,16 @@ /** TCP window size, giving the maximum number of bytes which can be buffered at the one time. */ #define TCP_WINDOW_SIZE 512 - + /** Port number for HTTP transmissions. */ #define TCP_PORT_HTTP SwapEndian_16(80) - + /** Data direction indicator for a TCP application buffer, indicating data from host-to-device. */ #define TCP_PACKETDIR_IN false /** Data direction indicator for a TCP application buffer, indicating data from device-to-host. */ #define TCP_PACKETDIR_OUT true - + /** Congestion Window Reduced TCP flag mask. */ #define TCP_FLAG_CWR (1 << 7) @@ -86,7 +86,7 @@ /** Connection Finalize TCP flag mask. */ #define TCP_FLAG_FIN (1 << 0) - + /** Application macro: Determines if the given application buffer contains a packet received from the host * * \param[in] Buffer Application buffer to check @@ -139,7 +139,7 @@ * \param[in] Buffer Application buffer to clear */ #define TCP_APP_CLEAR_BUFFER(Buffer) MACROS{ Buffer->Ready = false; Buffer->Length = 0; }MACROE - + /** Application macro: Closes an open connection to a host. * * \param[in] Connection Open TCP connection to close @@ -153,7 +153,7 @@ TCP_Port_Closed = 0, /**< TCP port closed, no connections to a host may be made on this port. */ TCP_Port_Open = 1, /**< TCP port open, connections to a host may be made on this port. */ }; - + /** Enum for possible TCP connection states. */ enum TCP_ConnectionStates_t { @@ -167,9 +167,9 @@ TCP_Connection_Closing = 7, /**< Unused */ TCP_Connection_LastACK = 8, /**< Unused */ TCP_Connection_TimeWait = 9, /**< Unused */ - TCP_Connection_Closed = 10, /**< Connection closed in both directions */ + TCP_Connection_Closed = 10, /**< Connection closed in both directions */ }; - + /* Type Defines: */ /** Type define for a TCP connection buffer structure, including size, data and direction. */ typedef struct @@ -186,7 +186,7 @@ /** Type define for a TCP connection information structure. */ typedef struct { - uint32_t SequenceNumberIn; /**< Current TCP sequence number for host-to-device */ + uint32_t SequenceNumberIn; /**< Current TCP sequence number for host-to-device */ uint32_t SequenceNumberOut; /**< Current TCP sequence number for device-to-host */ TCP_ConnectionBuffer_t Buffer; /**< Connection application data buffer */ } TCP_ConnectionInfo_t; @@ -215,15 +215,15 @@ { uint16_t SourcePort; /**< Source port of the TCP packet */ uint16_t DestinationPort; /**< Destination port of the TCP packet */ - + uint32_t SequenceNumber; /**< Data sequence number of the packet */ uint32_t AcknowledgmentNumber; /**< Data acknowledgment number of the packet */ - + unsigned char Reserved : 4; /**< Reserved, must be all 0 */ unsigned char DataOffset : 4; /**< Offset of the data from the start of the header, in 4 byte chunks */ uint8_t Flags; /**< TCP packet flags */ uint16_t WindowSize; /**< Current data window size (bytes remaining in reception buffer) */ - + uint16_t Checksum; /**< TCP checksum */ uint16_t UrgentPointer; /**< Urgent data pointer */ } TCP_Header_t; @@ -257,3 +257,4 @@ #endif #endif + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/UDP.c b/Demos/Device/LowLevel/RNDISEthernet/Lib/UDP.c index 15b065656..9637bebcb 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/UDP.c +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/UDP.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -33,7 +33,7 @@ * User Datagram Protocol (UDP) packet handling routines. This protocol handles high throughput, low * reliability packets which are typically used to encapsulate streaming data. */ - + #define INCLUDE_FROM_UDP_C #include "UDP.h" @@ -52,11 +52,11 @@ int16_t UDP_ProcessUDPPacket(void* IPHeaderInStart, { UDP_Header_t* UDPHeaderIN = (UDP_Header_t*)UDPHeaderInStart; UDP_Header_t* UDPHeaderOUT = (UDP_Header_t*)UDPHeaderOutStart; - + int16_t RetSize = NO_RESPONSE; - + DecodeUDPHeader(UDPHeaderInStart); - + switch (SwapEndian_16(UDPHeaderIN->DestinationPort)) { case UDP_PORT_DHCP_REQUEST: @@ -65,7 +65,7 @@ int16_t UDP_ProcessUDPPacket(void* IPHeaderInStart, &((uint8_t*)UDPHeaderOutStart)[sizeof(UDP_Header_t)]); break; } - + /* Check to see if the protocol processing routine has filled out a response */ if (RetSize > 0) { @@ -78,6 +78,7 @@ int16_t UDP_ProcessUDPPacket(void* IPHeaderInStart, /* Return the size of the response so far */ return (sizeof(UDP_Header_t) + RetSize); } - + return NO_RESPONSE; } + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/UDP.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/UDP.h index 42d7925a3..32861a420 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/UDP.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/UDP.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -38,12 +38,12 @@ /* Includes: */ #include <avr/io.h> - + #include "EthernetProtocols.h" #include "Ethernet.h" #include "ProtocolDecoders.h" #include "DHCP.h" - + /* Macros: */ /** Source UDP port for a DHCP request. */ #define UDP_PORT_DHCP_REQUEST 67 @@ -63,10 +63,11 @@ uint16_t Length; /**< Total packet length, in bytes */ uint16_t Checksum; /**< Optional UDP packet checksum */ } UDP_Header_t; - + /* Function Prototypes: */ int16_t UDP_ProcessUDPPacket(void* IPHeaderInStart, void* UDPHeaderInStart, void* UDPHeaderOutStart); #endif + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/Webserver.c b/Demos/Device/LowLevel/RNDISEthernet/Lib/Webserver.c index bc42ef395..bca8673ca 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/Webserver.c +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/Webserver.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -43,7 +43,7 @@ char PROGMEM HTTP200Header[] = "HTTP/1.1 200 OK\r\n" "Server: LUFA RNDIS\r\n" "Content-type: text/html\r\n" "Connection: close\r\n\r\n"; - + /** HTTP server response header, for transmission before a resource not found error. This indicates to the host that the given * given URL is invalid, and gives extra error information. */ @@ -54,7 +54,7 @@ char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n" /** HTTP page to serve to the host when a HTTP request is made. This page is too long for a single response, thus it is automatically * broken up into smaller blocks and sent as a series of packets each time the webserver application callback is run. */ -char PROGMEM HTTPPage[] = +char PROGMEM HTTPPage[] = "<html>" " <head>" " <title>" @@ -108,7 +108,7 @@ void Webserver_ApplicationCallback(TCP_ConnectionState_t* const ConnectionState, { char* BufferDataStr = (char*)Buffer->Data; static uint8_t PageBlock = 0; - + /* Check to see if a packet has been received on the HTTP port from a remote host */ if (TCP_APP_HAS_RECEIVED_PACKET(Buffer)) { @@ -120,7 +120,7 @@ void Webserver_ApplicationCallback(TCP_ConnectionState_t* const ConnectionState, /* Copy the HTTP 200 response header into the packet buffer */ strcpy_P(BufferDataStr, HTTP200Header); - + /* Send the buffer contents to the host */ TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr)); @@ -131,10 +131,10 @@ void Webserver_ApplicationCallback(TCP_ConnectionState_t* const ConnectionState, { /* Copy the HTTP 404 response header into the packet buffer */ strcpy_P(BufferDataStr, HTTP404Header); - + /* Send the buffer contents to the host */ TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr)); - + /* All data sent, close the connection */ TCP_APP_CLOSECONNECTION(ConnectionState); } @@ -155,9 +155,9 @@ void Webserver_ApplicationCallback(TCP_ConnectionState_t* const ConnectionState, strcpy_P(BufferDataStr, HTTP404Header); /* Send the buffer contents to the host */ - TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr)); + TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr)); } - + /* All data sent, close the connection */ TCP_APP_CLOSECONNECTION(ConnectionState); } @@ -165,7 +165,7 @@ void Webserver_ApplicationCallback(TCP_ConnectionState_t* const ConnectionState, { /* Echo the host's query back to the host */ TCP_APP_SEND_BUFFER(Buffer, Buffer->Length); - + /* All data sent, close the connection */ TCP_APP_CLOSECONNECTION(ConnectionState); } @@ -179,13 +179,13 @@ void Webserver_ApplicationCallback(TCP_ConnectionState_t* const ConnectionState, { uint16_t RemLength = strlen_P(&HTTPPage[PageBlock * HTTP_REPLY_BLOCK_SIZE]); uint16_t Length; - + /* Determine the length of the loaded block */ Length = ((RemLength > HTTP_REPLY_BLOCK_SIZE) ? HTTP_REPLY_BLOCK_SIZE : RemLength); /* Copy the next buffer sized block of the page to the packet buffer */ strncpy_P(BufferDataStr, &HTTPPage[PageBlock * HTTP_REPLY_BLOCK_SIZE], Length); - + /* Send the buffer contents to the host */ TCP_APP_SEND_BUFFER(Buffer, Length); @@ -194,9 +194,10 @@ void Webserver_ApplicationCallback(TCP_ConnectionState_t* const ConnectionState, { /* Unlock the buffer so that the host can fill it with future packets */ TCP_APP_RELEASE_BUFFER(Buffer); - + /* Close the connection to the host */ TCP_APP_CLOSECONNECTION(ConnectionState); } } } + diff --git a/Demos/Device/LowLevel/RNDISEthernet/Lib/Webserver.h b/Demos/Device/LowLevel/RNDISEthernet/Lib/Webserver.h index 87fe1c91d..7abd6adc9 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/Lib/Webserver.h +++ b/Demos/Device/LowLevel/RNDISEthernet/Lib/Webserver.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* 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 @@ -32,25 +32,26 @@ * * Header file for Webserver.c. */ - + #ifndef _WEBSERVER_H_ #define _WEBSERVER_H_ /* Includes: */ #include <avr/io.h> #include <avr/pgmspace.h> - + #include <LUFA/Version.h> - + #include "TCP.h" - + /* Macros: */ /** Maximum size of a HTTP response per transmission */ #define HTTP_REPLY_BLOCK_SIZE 128 - + /* Function Prototypes: */ void Webserver_Init(void); void Webserver_ApplicationCallback(TCP_ConnectionState_t* const ConnectionState, TCP_ConnectionBuffer_t* const Buffer); #endif + |