diff options
| author | Dean Camera <dean@fourwalledcubicle.com> | 2010-02-02 05:56:47 +0000 | 
|---|---|---|
| committer | Dean Camera <dean@fourwalledcubicle.com> | 2010-02-02 05:56:47 +0000 | 
| commit | 1008260985a50df686bb6c0b73c6a0b10fd24b2b (patch) | |
| tree | 6aea31bcfcdfc7f11ad69436b01a0d60f38b87c9 /Projects/Webserver/Lib/uIPManagement.c | |
| parent | 5687ac7316335009160ccd7f56fce5e7746c5889 (diff) | |
| download | lufa-1008260985a50df686bb6c0b73c6a0b10fd24b2b.tar.gz lufa-1008260985a50df686bb6c0b73c6a0b10fd24b2b.tar.bz2 lufa-1008260985a50df686bb6c0b73c6a0b10fd24b2b.zip  | |
Make packet processing code in the Webserver project a bit neater using a switch statement instead of an if-else-if chain.
Diffstat (limited to 'Projects/Webserver/Lib/uIPManagement.c')
| -rw-r--r-- | Projects/Webserver/Lib/uIPManagement.c | 57 | 
1 files changed, 30 insertions, 27 deletions
diff --git a/Projects/Webserver/Lib/uIPManagement.c b/Projects/Webserver/Lib/uIPManagement.c index 44da609dd..2e8fa4f31 100644 --- a/Projects/Webserver/Lib/uIPManagement.c +++ b/Projects/Webserver/Lib/uIPManagement.c @@ -92,47 +92,50 @@ void uIPManagement_ManageNetwork(void)  /** Processes incomming packets to the server from the connected RNDIS device, creating responses as needed. */
  static void uIPManagement_ProcessIncommingPacket(void)
  {
 -	if (RNDIS_Host_IsPacketReceived(&Ethernet_RNDIS_Interface))
 -	{
 -		LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
 +	/* If no packet received, exit processing routine */
 +	if (!(RNDIS_Host_IsPacketReceived(&Ethernet_RNDIS_Interface)))
 +	  return;
 +	  
 +	LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
 -		/* Read the incomming packet straight into the UIP packet buffer */
 -		RNDIS_Host_ReadPacket(&Ethernet_RNDIS_Interface, uip_buf, &uip_len);
 +	/* Read the incomming packet straight into the UIP packet buffer */
 +	RNDIS_Host_ReadPacket(&Ethernet_RNDIS_Interface, uip_buf, &uip_len);
 -		if (uip_len > 0)
 +	/* If the packet contains an Ethernet frame, process it */
 +	if (uip_len > 0)
 +	{
 +		switch (((struct uip_eth_hdr*)uip_buf)->type)
  		{
 -			bool PacketHandled = true;
 -
 -			struct uip_eth_hdr* EthernetHeader = (struct uip_eth_hdr*)uip_buf;
 -			if (EthernetHeader->type == HTONS(UIP_ETHTYPE_IP))
 -			{
 +			case HTONS(UIP_ETHTYPE_IP):
  				/* Filter packet by MAC destination */
  				uip_arp_ipin();
  				/* Process incomming packet */
  				uip_input();
 -				/* Add destination MAC to outgoing packet */
 +				/* If a response was generated, send it */
  				if (uip_len > 0)
 -				  uip_arp_out();
 -			}
 -			else if (EthernetHeader->type == HTONS(UIP_ETHTYPE_ARP))
 -			{
 +				{
 +					/* Add destination MAC to outgoing packet */
 +					uip_arp_out();
 +
 +					RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);
 +				}
 +				
 +				break;
 +			case HTONS(UIP_ETHTYPE_ARP):
  				/* Process ARP packet */
  				uip_arp_arpin();
 -			}
 -			else
 -			{
 -				PacketHandled = false;
 -			}
 -
 -			/* If a response was generated, send it */
 -			if ((uip_len > 0) && PacketHandled)
 -			  RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);
 +				
 +				/* If a response was generated, send it */
 +				if (uip_len > 0)
 +				  RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);
 +				
 +				break;
  		}
 -
 -		LEDs_SetAllLEDs(LEDMASK_USB_READY);
  	}
 +
 +	LEDs_SetAllLEDs(LEDMASK_USB_READY);
  }
  /** Manages the currently open network connections, including TCP and (if enabled) UDP. */
  | 
