-/** Processes incomming packets to the server from the connected RNDIS device, creating responses as needed. */\r
-void ProcessIncommingPacket(void)\r
-{\r
- if (RNDIS_Host_IsPacketReceived(&Ethernet_RNDIS_Interface))\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[0], &uip_len);\r
-\r
- if (uip_len > 0)\r
- {\r
- bool PacketHandled = true;\r
-\r
- struct uip_eth_hdr* EthernetHeader = (struct uip_eth_hdr*)&uip_buf[0];\r
- if (EthernetHeader->type == HTONS(UIP_ETHTYPE_IP))\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 (uip_len > 0)\r
- uip_arp_out();\r
- }\r
- else if (EthernetHeader->type == HTONS(UIP_ETHTYPE_ARP))\r
- {\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[0], uip_len);\r
- }\r
-\r
- LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
- }\r
-}\r
-\r
-/** Manages the currently open network connections, including TCP and (if enabled) UDP. */\r
-void ManageConnections(void)\r
-{\r
- /* Manage open connections */\r
- if (timer_expired(&ConnectionTimer))\r
- {\r
- timer_reset(&ConnectionTimer);\r
-\r
- LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
- \r
- for (uint8_t i = 0; i < UIP_CONNS; i++)\r
- {\r
- /* Run periodic connection management for each TCP connection */\r
- uip_periodic(i);\r
-\r
- /* If a response was generated, send it */\r
- if (uip_len > 0)\r
- {\r
- /* Add destination MAC to outgoing packet */\r
- uip_arp_out();\r
-\r
- RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf[0], uip_len);\r
- }\r
- }\r
- \r
- #if defined(ENABLE_DHCP)\r
- for (uint8_t i = 0; i < UIP_UDP_CONNS; i++)\r
- {\r
- /* Run periodic connection management for each UDP connection */\r
- uip_udp_periodic(i);\r
-\r
- /* If a response was generated, send it */\r
- if (uip_len > 0)\r
- {\r
- /* Add destination MAC to outgoing packet */\r
- uip_arp_out();\r
-\r
- RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf[0], uip_len);\r
- }\r
- }\r
- #endif\r
-\r
- LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
- }\r
-\r
- /* Manage ARP cache refreshing */\r
- if (timer_expired(&ARPTimer))\r
- {\r
- timer_reset(&ARPTimer);\r
- uip_arp_timer();\r
- }\r
-}\r
-\r