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.
This commit is contained in:
		
							parent
							
								
									85c2716f2d
								
							
						
					
					
						commit
						d423090b26
					
				
					 16 changed files with 75 additions and 70 deletions
				
			
		| 
						 | 
				
			
			@ -50,6 +50,9 @@
 | 
			
		|||
		#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}		
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -275,6 +275,5 @@ void DecodeDHCPHeader(void* InDataStart)
 | 
			
		|||
		
 | 
			
		||||
		DHCPOptions += ((DHCPOptions[0] == DHCP_OPTION_PAD) ? 1 : (DHCPOptions[1] + 2));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	#endif
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,9 +45,6 @@
 | 
			
		|||
		#include "Ethernet.h"
 | 
			
		||||
 | 
			
		||||
	/* Macros: */
 | 
			
		||||
		/** Physical MAC Address of the USB network adapter */
 | 
			
		||||
		#define ADAPTER_MAC_ADDRESS                   {0x02, 0x00, 0x02, 0x00, 0x02, 0x00}
 | 
			
		||||
	
 | 
			
		||||
		/** Implemented RNDIS Version Major */
 | 
			
		||||
		#define REMOTE_NDIS_VERSION_MAJOR             0x01
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -58,19 +58,18 @@ TCP_ConnectionState_t  ConnectionStateTable[MAX_TCP_CONNECTIONS];
 | 
			
		|||
 */
 | 
			
		||||
void TCP_Task(void)
 | 
			
		||||
{
 | 
			
		||||
	/* 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);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -89,7 +88,7 @@ void TCP_Task(void)
 | 
			
		|||
			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)];						
 | 
			
		||||
			                                                                             sizeof(IP_Header_t)];
 | 
			
		||||
			void*                    TCPDataOUT     = &FrameOUT.FrameData[sizeof(Ethernet_Frame_Header_t) +
 | 
			
		||||
			                                                              sizeof(IP_Header_t) +
 | 
			
		||||
			                                                              sizeof(TCP_Header_t)];
 | 
			
		||||
| 
						 | 
				
			
			@ -367,11 +366,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
 | 
			
		||||
		{
 | 
			
		||||
| 
						 | 
				
			
			@ -584,10 +584,10 @@ int16_t TCP_ProcessTCPPacket(void* IPHeaderInStart, void* TCPHeaderInStart, void
 | 
			
		|||
/** Calculates the appropriate TCP checksum, consisting of the addition of the one's compliment of each word,
 | 
			
		||||
 *  complimented.
 | 
			
		||||
 *
 | 
			
		||||
 *  \param[in] TCPHeaderOutStart  Pointer to the start of the packet's outgoing TCP header
 | 
			
		||||
 *  \param[in] SourceAddress      Source protocol IP address of the outgoing IP header
 | 
			
		||||
 *  \param[in] DestinationAddress Destination protocol IP address of the outgoing IP header
 | 
			
		||||
 *  \param[in] TCPOutSize         Size in bytes of the TCP data header and payload
 | 
			
		||||
 *  \param[in] TCPHeaderOutStart   Pointer to the start of the packet's outgoing TCP header
 | 
			
		||||
 *  \param[in] SourceAddress       Source protocol IP address of the outgoing IP header
 | 
			
		||||
 *  \param[in] DestinationAddress  Destination protocol IP address of the outgoing IP header
 | 
			
		||||
 *  \param[in] TCPOutSize          Size in bytes of the TCP data header and payload
 | 
			
		||||
 *
 | 
			
		||||
 *  \return A 16-bit TCP checksum value
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -55,12 +55,13 @@ int16_t UDP_ProcessUDPPacket(void* IPHeaderInStart, void* UDPHeaderInStart, void
 | 
			
		|||
	
 | 
			
		||||
	DecodeUDPHeader(UDPHeaderInStart);
 | 
			
		||||
	
 | 
			
		||||
	/* Check to see if the UDP packet is a DHCP packet */
 | 
			
		||||
	if (SwapEndian_16(UDPHeaderIN->DestinationPort) == UDP_PORT_DHCP_REQUEST)
 | 
			
		||||
	switch (SwapEndian_16(UDPHeaderIN->DestinationPort))
 | 
			
		||||
	{
 | 
			
		||||
		RetSize = DHCP_ProcessDHCPPacket(IPHeaderInStart,
 | 
			
		||||
		                                 &((uint8_t*)UDPHeaderInStart)[sizeof(UDP_Header_t)],
 | 
			
		||||
	                                     &((uint8_t*)UDPHeaderOutStart)[sizeof(UDP_Header_t)]);
 | 
			
		||||
		case UDP_PORT_DHCP_REQUEST:
 | 
			
		||||
			RetSize = DHCP_ProcessDHCPPacket(IPHeaderInStart,
 | 
			
		||||
			                                 &((uint8_t*)UDPHeaderInStart)[sizeof(UDP_Header_t)],
 | 
			
		||||
		                                     &((uint8_t*)UDPHeaderOutStart)[sizeof(UDP_Header_t)]);
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/* Check to see if the protocol processing routine has filled out a response */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,6 +42,7 @@
 | 
			
		|||
		#include "EthernetProtocols.h"
 | 
			
		||||
		#include "Ethernet.h"
 | 
			
		||||
		#include "ProtocolDecoders.h"
 | 
			
		||||
		#include "DHCP.h"
 | 
			
		||||
	
 | 
			
		||||
	/* Macros: */
 | 
			
		||||
		/** Source UDP port for a DHCP request */
 | 
			
		||||
| 
						 | 
				
			
			@ -49,7 +50,10 @@
 | 
			
		|||
 | 
			
		||||
		/** Destination UDP port for a DHCP reply */
 | 
			
		||||
		#define UDP_PORT_DHCP_REPLY   68
 | 
			
		||||
			
 | 
			
		||||
 | 
			
		||||
		/** Source UDP port for a DNS request/response */
 | 
			
		||||
		#define UDP_PORT_DNS          53
 | 
			
		||||
 | 
			
		||||
	/* Type Defines: */
 | 
			
		||||
		/** Type define for a UDP packet header */
 | 
			
		||||
		typedef struct
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue