/** \file\r
*\r
* Main source file for the Webserver project. This file contains the main tasks of\r
- * the demo and is responsible for the initial application hardware configuration.\r
+ * the project and is responsible for the initial application hardware configuration.\r
*/\r
\r
#include "Webserver.h"\r
},\r
};\r
\r
-struct timer ConnectionTimer, ARPTimer;\r
-uint16_t MillisecondTickCount;\r
+/** Connection timer, to retain the time elapsed since the last time the uIP connections were managed. */\r
+struct timer ConnectionTimer;\r
+\r
+/** ARP timer, to retain the time elapsed since the ARP cache was last updated. */\r
+struct timer ARPTimer;\r
\r
-/** ISR for the management of the connection management timeout counter */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
-{\r
- MillisecondTickCount++;\r
-}\r
\r
-void TCPCallback(void)\r
-{\r
- printf("Callback!\r\n");\r
-}\r
- \r
/** Main program entry point. This routine configures the hardware required by the application, then\r
* enters a loop to run the application tasks in sequence.\r
*/\r
\r
printf("Device Max Transfer Size: %lu bytes.\r\n", Ethernet_RNDIS_Interface.State.DeviceMaxPacketSize);\r
\r
- uint32_t PacketFilter = (REMOTE_NDIS_PACKET_DIRECTED | REMOTE_NDIS_PACKET_BROADCAST | REMOTE_NDIS_PACKET_ALL_MULTICAST);\r
+ uint32_t PacketFilter = (REMOTE_NDIS_PACKET_DIRECTED | REMOTE_NDIS_PACKET_BROADCAST);\r
if (RNDIS_Host_SetRNDISProperty(&Ethernet_RNDIS_Interface, OID_GEN_CURRENT_PACKET_FILTER,\r
&PacketFilter, sizeof(PacketFilter)) != HOST_SENDCONTROL_Successful)\r
{\r
\r
uip_setethaddr(MACAddress);\r
\r
+ LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
+\r
printf("RNDIS Device Enumerated.\r\n");\r
USB_HostState = HOST_STATE_Configured;\r
break;\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
- \r
- printf("RECEIVED PACKET (%d):\r\n", uip_len);\r
- for (uint16_t i = 0; i < uip_len; i++)\r
- printf("0x%02X ", uip_buf[i]);\r
- printf("\r\n\r\n");\r
+ printf("L=%d R=%d\r\n", uip_len, RNDIS_Host_ReadPacket(&Ethernet_RNDIS_Interface, &uip_buf[0], &uip_len));\r
\r
- struct uip_eth_hdr* EthernetHeader = (struct uip_eth_hdr*)&uip_buf[0];\r
- if (EthernetHeader->type == HTONS(UIP_ETHTYPE_IP))\r
+ if (uip_len > 0)\r
{\r
- /* Filter packet by MAC destination */\r
- uip_arp_ipin();\r
+ bool PacketHandled = true;\r
\r
- /* Process incomming packet */\r
- uip_input();\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
- /* 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
+ /* Process incomming packet */\r
+ uip_input();\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
+ /* 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
- printf("SENT PACKET (%d):\r\n", uip_len);\r
- for (uint16_t i = 0; i < uip_len; i++)\r
- printf("0x%02X ", uip_buf[i]);\r
- printf("\r\n\r\n");\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
/* If a response was generated, send it */\r
if (uip_len > 0)\r
- RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);\r
+ RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf[0], uip_len);\r
}\r
\r
LEDs_SetAllLEDs(LEDMASK_USB_READY);\r