X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/4421782b7fb49e160b1c18f2295e6cd1f0b00c04..a9e0935a90346beb0c981924becc1f55d969a08b:/Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c?ds=sidebyside diff --git a/Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c b/Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c index c94495dc3..6500f3ba0 100644 --- a/Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c +++ b/Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c @@ -1,21 +1,21 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, 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 + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + 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 + 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 software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -38,7 +38,6 @@ #define INCLUDE_FROM_TCP_C #include "TCP.h" -/* Global Variables: */ /** Port state table array. This contains the current status of TCP ports in the device. To save on space, only open ports are * stored - closed ports may be overwritten at any time, and the system will assume any ports not present in the array are closed. This * allows for MAX_OPEN_TCP_PORTS to be less than the number of ports used by the application if desired. @@ -58,25 +57,27 @@ TCP_ConnectionState_t ConnectionStateTable[MAX_TCP_CONNECTIONS]; */ void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo) { - /* Task to hand off TCP packets to and from the listening applications. */ - /* Run each application in sequence, to process incoming and generate outgoing packets */ for (uint8_t CSTableEntry = 0; CSTableEntry < MAX_TCP_CONNECTIONS; CSTableEntry++) { /* Find the corresponding port entry in the port table */ - for (uint8_t PTableEntry = 0; PTableEntry < MAX_TCP_CONNECTIONS; PTableEntry++) + 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) && (PortStateTable[PTableEntry].State == TCP_Port_Open)) { - PortStateTable[PTableEntry].ApplicationHandler(&ConnectionStateTable[CSTableEntry], &ConnectionStateTable[CSTableEntry].Info.Buffer); + PortStateTable[PTableEntry].ApplicationHandler(&ConnectionStateTable[CSTableEntry], + &ConnectionStateTable[CSTableEntry].Info.Buffer); } } } + /* Get pointer to the output frame info struct for convenience */ + Ethernet_Frame_Info_t* FrameOUT = &RNDISInterfaceInfo->State.FrameOUT; + /* Bail out early if there is already a frame waiting to be sent in the Ethernet OUT buffer */ - if (RNDISInterfaceInfo->State.FrameOUT.FrameInBuffer) + if (FrameOUT->FrameInBuffer) return; /* Send response packets from each application as the TCP packet buffers are filled by the applications */ @@ -86,13 +87,13 @@ void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo) if ((ConnectionStateTable[CSTableEntry].Info.Buffer.Direction == TCP_PACKETDIR_OUT) && (ConnectionStateTable[CSTableEntry].Info.Buffer.Ready)) { - Ethernet_Frame_Header_t* FrameOUTHeader = (Ethernet_Frame_Header_t*)&RNDISInterfaceInfo->State.FrameOUT.FrameData; - IP_Header_t* IPHeaderOUT = (IP_Header_t*)&RNDISInterfaceInfo->State.FrameOUT.FrameData[sizeof(Ethernet_Frame_Header_t)]; - TCP_Header_t* TCPHeaderOUT = (TCP_Header_t*)&RNDISInterfaceInfo->State.FrameOUT.FrameData[sizeof(Ethernet_Frame_Header_t) + - sizeof(IP_Header_t)]; - void* TCPDataOUT = &RNDISInterfaceInfo->State.FrameOUT.FrameData[sizeof(Ethernet_Frame_Header_t) + - sizeof(IP_Header_t) + - sizeof(TCP_Header_t)]; + Ethernet_Frame_Header_t* FrameOUTHeader = (Ethernet_Frame_Header_t*)&FrameOUT->FrameData; + IP_Header_t* IPHeaderOUT = (IP_Header_t*)&FrameOUT->FrameData[sizeof(Ethernet_Frame_Header_t)]; + TCP_Header_t* TCPHeaderOUT = (TCP_Header_t*)&FrameOUT->FrameData[sizeof(Ethernet_Frame_Header_t) + + sizeof(IP_Header_t)]; + void* TCPDataOUT = &FrameOUT->FrameData[sizeof(Ethernet_Frame_Header_t) + + sizeof(IP_Header_t) + + sizeof(TCP_Header_t)]; uint16_t PacketSize = ConnectionStateTable[CSTableEntry].Info.Buffer.Length; @@ -145,8 +146,8 @@ void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo) PacketSize += sizeof(Ethernet_Frame_Header_t); /* Set the response length in the buffer and indicate that a response is ready to be sent */ - RNDISInterfaceInfo->State.FrameOUT.FrameLength = PacketSize; - RNDISInterfaceInfo->State.FrameOUT.FrameInBuffer = true; + FrameOUT->FrameLength = PacketSize; + FrameOUT->FrameInBuffer = true; ConnectionStateTable[CSTableEntry].Info.Buffer.Ready = false; @@ -367,11 +368,12 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, void* TCPHeaderInStart, void /* Detect RST from host to abort existing connection */ if (TCPHeaderIN->Flags & TCP_FLAG_RST) { - TCPHeaderOUT->Flags = (TCP_FLAG_RST | TCP_FLAG_ACK); - PacketResponse = true; - - TCP_SetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, - TCPHeaderIN->SourcePort, TCP_Connection_Closed); + if (TCP_SetConnectionState(TCPHeaderIN->DestinationPort, IPHeaderIN->SourceAddress, + TCPHeaderIN->SourcePort, TCP_Connection_Closed)) + { + TCPHeaderOUT->Flags = (TCP_FLAG_RST | TCP_FLAG_ACK); + PacketResponse = true; + } } else {