/** 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
- /* 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
- 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
- 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
- /* Add destination MAC to outgoing packet */\r
+ /* If a response was generated, send it */\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
- }\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
- LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
}\r
+\r
+ LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
}\r
\r
/** Manages the currently open network connections, including TCP and (if enabled) UDP. */\r