X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/d11ed10c5314c44dc01c06954d1d73d4894cbff8..08e8d6393edeaf775b5c3fc3bf2a76e62698d129:/Projects/Webserver/Lib/uIPManagement.c diff --git a/Projects/Webserver/Lib/uIPManagement.c b/Projects/Webserver/Lib/uIPManagement.c index dd9f15f42..e207d9ce1 100644 --- a/Projects/Webserver/Lib/uIPManagement.c +++ b/Projects/Webserver/Lib/uIPManagement.c @@ -52,11 +52,12 @@ void uIPManagement_Init(void) { /* uIP Timing Initialization */ clock_init(); - timer_set(&ConnectionTimer, CLOCK_SECOND / 2); + timer_set(&ConnectionTimer, CLOCK_SECOND / 8); timer_set(&ARPTimer, CLOCK_SECOND * 10); /* uIP Stack Initialization */ uip_init(); + uip_arp_init(); /* DHCP/Server IP Settings Initialization */ #if defined(ENABLE_DHCP) @@ -74,7 +75,7 @@ void uIPManagement_Init(void) uip_setethaddr(MACAddress); /* HTTP Webserver Initialization */ - WebserverApp_Init(); + HTTPServerApp_Init(); } /** uIP Management function. This function manages the uIP stack when called while an RNDIS device has been @@ -92,53 +93,71 @@ 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[0], &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[0]; - 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[0], 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. */ static void uIPManagement_ManageConnections(void) { - /* Manage open connections */ + /* Poll TCP connections for more data to send back to the host */ + for (uint8_t i = 0; i < UIP_CONNS; i++) + { + uip_poll_conn(&uip_conns[i]); + + /* If a response was generated, send it */ + if (uip_len > 0) + { + /* Add destination MAC to outgoing packet */ + uip_arp_out(); + + RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len); + } + } + + /* Manage open connections for timeouts */ if (timer_expired(&ConnectionTimer)) { timer_reset(&ConnectionTimer); @@ -156,7 +175,7 @@ static void uIPManagement_ManageConnections(void) /* Add destination MAC to outgoing packet */ uip_arp_out(); - RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf[0], uip_len); + RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len); } } @@ -172,7 +191,7 @@ static void uIPManagement_ManageConnections(void) /* Add destination MAC to outgoing packet */ uip_arp_out(); - RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf[0], uip_len); + RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len); } } #endif