@ -58,25 +58,27 @@ TCP_ConnectionState_t ConnectionStateTable[MAX_TCP_CONNECTIONS];
*/
*/
void TCP_TCPTask ( USB_ClassInfo_RNDIS_Device_t * RNDISInterfaceInfo )
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 */
/* Run each application in sequence, to process incoming and generate outgoing packets */
for ( uint8_t CSTableEntry = 0 ; CSTableEntry < MAX_TCP_CONNECTIONS ; CSTableEntry + + )
for ( uint8_t CSTableEntry = 0 ; CSTableEntry < MAX_TCP_CONNECTIONS ; CSTableEntry + + )
{
{
/* Find the corresponding port entry in the port table */
/* Find the corresponding port entry in the port table */
for ( uint8_t PTableEntry = 0 ; PTableEntry < MAX_ TCP_CONNECTION S; PTableEntry + + )
for ( uint8_t PTableEntry = 0 ; PTableEntry < MAX_ OPEN_TCP_PORT S; PTableEntry + + )
{
{
/* Run the application handler for the port */
/* 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 ] . 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 */
/* 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 ;
return ;
/* Send response packets from each application as the TCP packet buffers are filled by the applications */
/* Send response packets from each application as the TCP packet buffers are filled by the applications */
@ -86,11 +88,11 @@ void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo)
if ( ( ConnectionStateTable [ CSTableEntry ] . Info . Buffer . Direction = = TCP_PACKETDIR_OUT ) & &
if ( ( ConnectionStateTable [ CSTableEntry ] . Info . Buffer . Direction = = TCP_PACKETDIR_OUT ) & &
( ConnectionStateTable [ CSTableEntry ] . Info . Buffer . Ready ) )
( ConnectionStateTable [ CSTableEntry ] . Info . Buffer . Ready ) )
{
{
Ethernet_Frame_Header_t * FrameOUTHeader = ( Ethernet_Frame_Header_t * ) & RNDISInterfaceInfo- > State . FrameOUT . FrameData ;
Ethernet_Frame_Header_t * FrameOUTHeader = ( Ethernet_Frame_Header_t * ) & FrameOUT- > FrameData ;
IP_Header_t * IPHeaderOUT = ( IP_Header_t * ) & RNDISInterfaceInfo- > State . FrameOUT . FrameData [ sizeof ( Ethernet_Frame_Header_t ) ] ;
IP_Header_t * IPHeaderOUT = ( IP_Header_t * ) & FrameOUT- > FrameData [ sizeof ( Ethernet_Frame_Header_t ) ] ;
TCP_Header_t * TCPHeaderOUT = ( TCP_Header_t * ) & RNDISInterfaceInfo- > State . 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 ) ] ;
sizeof ( IP_Header_t ) ] ;
void * TCPDataOUT = & RNDISInterfaceInfo - > State . FrameOUT . FrameData [ sizeof ( Ethernet_Frame_Header_t ) +
void * TCPDataOUT = & FrameOUT - > FrameData [ sizeof ( Ethernet_Frame_Header_t ) +
sizeof ( IP_Header_t ) +
sizeof ( IP_Header_t ) +
sizeof ( TCP_Header_t ) ] ;
sizeof ( TCP_Header_t ) ] ;
@ -145,8 +147,8 @@ void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* RNDISInterfaceInfo)
PacketSize + = sizeof ( Ethernet_Frame_Header_t ) ;
PacketSize + = sizeof ( Ethernet_Frame_Header_t ) ;
/* Set the response length in the buffer and indicate that a response is ready to be sent */
/* Set the response length in the buffer and indicate that a response is ready to be sent */
RNDISInterfaceInfo- > State . FrameOUT . FrameLength = PacketSize ;
FrameOUT- > FrameLength = PacketSize ;
RNDISInterfaceInfo- > State . FrameOUT . FrameInBuffer = true ;
FrameOUT- > FrameInBuffer = true ;
ConnectionStateTable [ CSTableEntry ] . Info . Buffer . Ready = false ;
ConnectionStateTable [ CSTableEntry ] . Info . Buffer . Ready = false ;
@ -366,12 +368,13 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, void* TCPHeaderInStart, void
/* Detect RST from host to abort existing connection */
/* Detect RST from host to abort existing connection */
if ( TCPHeaderIN - > Flags & TCP_FLAG_RST )
if ( TCPHeaderIN - > Flags & TCP_FLAG_RST )
{
if ( TCP_SetConnectionState ( TCPHeaderIN - > DestinationPort , IPHeaderIN - > SourceAddress ,
TCPHeaderIN - > SourcePort , TCP_Connection_Closed ) )
{
{
TCPHeaderOUT - > Flags = ( TCP_FLAG_RST | TCP_FLAG_ACK ) ;
TCPHeaderOUT - > Flags = ( TCP_FLAG_RST | TCP_FLAG_ACK ) ;
PacketResponse = true ;
PacketResponse = true ;
}
TCP_SetConnectionState ( TCPHeaderIN - > DestinationPort , IPHeaderIN - > SourceAddress ,
TCPHeaderIN - > SourcePort , TCP_Connection_Closed ) ;
}
}
else
else
{
{