aboutsummaryrefslogtreecommitdiff
path: root/Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c
diff options
context:
space:
mode:
authorDean Camera <[email protected]>2009-08-07 06:55:31 +0000
committerDean Camera <[email protected]>2009-08-07 06:55:31 +0000
commitd423090b26ade8912e669d6c6d3c5463e0669429 (patch)
treef443783209b96313146c539de92c408788d2778d /Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c
parent85c2716f2d37bb50d126102fcdd09fb78d26ebc5 (diff)
downloadqmk_firmware-d423090b26ade8912e669d6c6d3c5463e0669429.tar.gz
qmk_firmware-d423090b26ade8912e669d6c6d3c5463e0669429.zip
Cleanups to RNDIS device demos. Fix issue in RNDIS demos where the memory would become corrupted due to an incorrect bounds check when iterating over the port state table, causing random resets.
Revert change to Template_Endpoint_Control_R.c, which broke control stream reads. Remove uneeded ADC.h include in the class driver AudioOutput demo.
Diffstat (limited to 'Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c')
-rw-r--r--Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c b/Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c
index c94495dc33..2a626e9752 100644
--- a/Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c
+++ b/Demos/Device/ClassDriver/RNDISEthernet/Lib/TCP.c
@@ -58,25 +58,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 = (Ethernet_Frame_Info_t*)&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 +88,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 +147,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 +369,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
{