@ -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_CONNECTION S;  PTableEntry + + ) 
 
			
		
	
		
			
				
							for  ( uint8_t  PTableEntry  =  0 ;  PTableEntry  <  MAX_ OPEN_TCP_PORT S;  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 
 
			
		
	
		
			
				
							{