Make packet processing code in the Webserver project a bit neater using a switch...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 2 Feb 2010 05:56:47 +0000 (05:56 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 2 Feb 2010 05:56:47 +0000 (05:56 +0000)
Projects/Webserver/Lib/uIPManagement.c

index 44da609..2e8fa4f 100644 (file)
@@ -92,47 +92,50 @@ void uIPManagement_ManageNetwork(void)
 /** Processes incomming packets to the server from the connected RNDIS device, creating responses as needed. */\r
 static void uIPManagement_ProcessIncommingPacket(void)\r
 {\r
 /** Processes incomming packets to the server from the connected RNDIS device, creating responses as needed. */\r
 static void uIPManagement_ProcessIncommingPacket(void)\r
 {\r
-       if (RNDIS_Host_IsPacketReceived(&Ethernet_RNDIS_Interface))\r
-       {\r
-               LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
+       /* If no packet received, exit processing routine */\r
+       if (!(RNDIS_Host_IsPacketReceived(&Ethernet_RNDIS_Interface)))\r
+         return;\r
+         \r
+       LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
 \r
 \r
-               /* Read the incomming packet straight into the UIP packet buffer */\r
-               RNDIS_Host_ReadPacket(&Ethernet_RNDIS_Interface, uip_buf, &uip_len);\r
+       /* Read the incomming packet straight into the UIP packet buffer */\r
+       RNDIS_Host_ReadPacket(&Ethernet_RNDIS_Interface, uip_buf, &uip_len);\r
 \r
 \r
-               if (uip_len > 0)\r
+       /* If the packet contains an Ethernet frame, process it */\r
+       if (uip_len > 0)\r
+       {\r
+               switch (((struct uip_eth_hdr*)uip_buf)->type)\r
                {\r
                {\r
-                       bool PacketHandled = true;\r
-\r
-                       struct uip_eth_hdr* EthernetHeader = (struct uip_eth_hdr*)uip_buf;\r
-                       if (EthernetHeader->type == HTONS(UIP_ETHTYPE_IP))\r
-                       {\r
+                       case HTONS(UIP_ETHTYPE_IP):\r
                                /* Filter packet by MAC destination */\r
                                uip_arp_ipin();\r
 \r
                                /* Process incomming packet */\r
                                uip_input();\r
 \r
                                /* Filter packet by MAC destination */\r
                                uip_arp_ipin();\r
 \r
                                /* Process incomming packet */\r
                                uip_input();\r
 \r
-                               /* Add destination MAC to outgoing packet */\r
+                               /* If a response was generated, send it */\r
                                if (uip_len > 0)\r
                                if (uip_len > 0)\r
-                                 uip_arp_out();\r
-                       }\r
-                       else if (EthernetHeader->type == HTONS(UIP_ETHTYPE_ARP))\r
-                       {\r
+                               {\r
+                                       /* Add destination MAC to outgoing packet */\r
+                                       uip_arp_out();\r
+\r
+                                       RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);\r
+                               }\r
+                               \r
+                               break;\r
+                       case HTONS(UIP_ETHTYPE_ARP):\r
                                /* Process ARP packet */\r
                                uip_arp_arpin();\r
                                /* Process ARP packet */\r
                                uip_arp_arpin();\r
-                       }\r
-                       else\r
-                       {\r
-                               PacketHandled = false;\r
-                       }\r
-\r
-                       /* If a response was generated, send it */\r
-                       if ((uip_len > 0) && PacketHandled)\r
-                         RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);\r
+                               \r
+                               /* If a response was generated, send it */\r
+                               if (uip_len > 0)\r
+                                 RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);\r
+                               \r
+                               break;\r
                }\r
                }\r
-\r
-               LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
        }\r
        }\r
+\r
+       LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
 }\r
 \r
 /** Manages the currently open network connections, including TCP and (if enabled) UDP. */\r
 }\r
 \r
 /** Manages the currently open network connections, including TCP and (if enabled) UDP. */\r