Move DHCP negotiation timer into the DHCP connection application state structure...
authorDean Camera <dean@fourwalledcubicle.com>
Fri, 12 Feb 2010 07:27:26 +0000 (07:27 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Fri, 12 Feb 2010 07:27:26 +0000 (07:27 +0000)
LUFA/ManPages/LUFAPoweredProjects.txt
Projects/Webserver/Lib/DHCPClientApp.c
Projects/Webserver/Lib/FATFs/ffconf.h
Projects/Webserver/Lib/HTTPServerApp.c
Projects/Webserver/Lib/HTTPServerApp.h
Projects/Webserver/Lib/TELNETServerApp.c
Projects/Webserver/Lib/uIPManagement.c
Projects/Webserver/Lib/uip/uipopt.h
Projects/Webserver/Webserver.txt
Projects/Webserver/makefile

index bf61e9d..454962a 100644 (file)
  *  - BAP, A tiny LUFA based AVR Programmer: http://www.busware.de/tiki-index.php?page=BAP\r
  *  - Digital Survey Instruments Magnetometer and Pointer: http://www.digitalsurveyinstruments.com/\r
  *  - Lightweight CC110x USB dongle for 868MHz Protocols: http://busware.de/tiki-index.php?page=CUL\r
+ *  - Penguino, an Arduino Board With On-Board LUFA Powered Debugger/Programmer: http://wiki.icy.com.au/PenguinoAVR\r
  *  - MIDIFighter, a USB-MIDI controller: http://www.midifighter.com/\r
  *  - Mobo 4.3, a USB controlled all band (160-10m) HF SDR transceiver: http://sites.google.com/site/lofturj/mobo4_3\r
- *  - SEGA Megadrive/Super Nintendo Cartridge Reader: http://www.snega2usb.com\r
+ *  - Retrode, a USB Games Console Cartridge Reader: http://www.snega2usb.com\r
  *  - XMEGA Development Board, using LUFA as an On-Board Programmer: http://xmega.mattair.net/\r
- *  - Penguino, an Arduino Board With On-Board LUFA Powered Debugger/Programmer: http://wiki.icy.com.au/PenguinoAVR\r
  *\r
  *  \section Sec_LUFAPublications Publications Mentioning LUFA\r
  *  - Elektor Magazine, "My First AVR-USB" by Antoine Authier (feature), January 2010 Issue\r
  *  - Elektor Magazine, "USB is Cool/Sucks" by Jerry Jacobs and Chris Vossen (minor mention), January 2010 Issue\r
+ *  - Elektor Magazine, "20 x Open Source", March 2010 Issue\r
  */
\ No newline at end of file
index 0e51d57..09bae73 100644 (file)
  *  DHCP Client Application. When connected to the uIP stack, this will retrieve IP configuration settings from the\r
  *  DHCP server on the network.\r
  */\r
\r
+\r
 #include "DHCPClientApp.h"\r
 \r
 #if defined(ENABLE_DHCP_CLIENT) || defined(__DOXYGEN__)\r
-/** Timer for managing the timeout period for a DHCP server to respond */\r
-struct timer DHCPTimer;\r
 \r
 /** Initialization function for the DHCP client. */\r
 void DHCPClientApp_Init(void)\r
@@ -54,13 +52,14 @@ void DHCPClientApp_Init(void)
        if (Connection != NULL)\r
        {\r
                uip_udp_appstate_t* const AppState = &Connection->appstate;\r
-\r
                uip_udp_bind(Connection, HTONS(DHCPC_CLIENT_PORT));\r
+               \r
+               /* Set the initial client state */\r
                AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover;\r
-       }\r
 \r
-       /* Set timeout period to half a second for a DHCP server to respond */\r
-       timer_set(&DHCPTimer, CLOCK_SECOND / 2);\r
+               /* Set timeout period to half a second for a DHCP server to respond */\r
+               timer_set(&AppState->DHCPClient.Timeout, CLOCK_SECOND / 2);\r
+       }\r
 }\r
  \r
 /** uIP stack application callback for the DHCP client. This function must be called each time the TCP/IP stack \r
@@ -91,7 +90,7 @@ void DHCPClientApp_Callback(void)
                        uip_udp_send(AppDataSize);\r
 \r
                        /* Reset the timeout timer, progress to next state */\r
-                       timer_reset(&DHCPTimer);\r
+                       timer_reset(&AppState->DHCPClient.Timeout);\r
                        AppState->DHCPClient.CurrentState = DHCP_STATE_WaitForOffer;                    \r
                        \r
                        break;\r
@@ -99,7 +98,7 @@ void DHCPClientApp_Callback(void)
                        if (!(uip_newdata()))\r
                        {\r
                                /* Check if the DHCP timeout period has expired while waiting for a response */\r
-                               if (timer_expired(&DHCPTimer))\r
+                               if (timer_expired(&AppState->DHCPClient.Timeout))\r
                                  AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover;\r
                                \r
                                break;\r
@@ -116,7 +115,7 @@ void DHCPClientApp_Callback(void)
                                DHCPClientApp_GetOption(AppData->Options, DHCP_OPTION_ROUTER,      &AppState->DHCPClient.DHCPOffer_Data.GatewayIP);\r
                                DHCPClientApp_GetOption(AppData->Options, DHCP_OPTION_SERVER_ID,   &AppState->DHCPClient.DHCPOffer_Data.ServerIP);\r
                                \r
-                               timer_reset(&DHCPTimer);\r
+                               timer_reset(&AppState->DHCPClient.Timeout);\r
                                AppState->DHCPClient.CurrentState = DHCP_STATE_SendRequest;\r
                        }\r
 \r
@@ -137,7 +136,7 @@ void DHCPClientApp_Callback(void)
                        uip_udp_send(AppDataSize);\r
                        \r
                        /* Reset the timeout timer, progress to next state */\r
-                       timer_reset(&DHCPTimer);\r
+                       timer_reset(&AppState->DHCPClient.Timeout);\r
                        AppState->DHCPClient.CurrentState = DHCP_STATE_WaitForACK;\r
 \r
                        break;\r
@@ -145,7 +144,7 @@ void DHCPClientApp_Callback(void)
                        if (!(uip_newdata()))\r
                        {\r
                                /* Check if the DHCP timeout period has expired while waiting for a response */\r
-                               if (timer_expired(&DHCPTimer))\r
+                               if (timer_expired(&AppState->DHCPClient.Timeout))\r
                                  AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover;\r
                                \r
                                break;\r
index 3ad7a56..4b19f13 100644 (file)
@@ -14,7 +14,7 @@
 / Function and Buffer Configurations\r
 /----------------------------------------------------------------------------*/\r
 \r
-#define        _FS_TINY        0               /* 0 or 1 */\r
+#define        _FS_TINY        1               /* 0 or 1 */\r
 /* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system\r
 /  object instead of the sector buffer in the individual file object for file\r
 /  data transfer. This reduces memory consumption 512 bytes each file object. */\r
index ad768c8..e781beb 100644 (file)
 /** HTTP server response header, for transmission before the page contents. This indicates to the host that a page exists at the\r
  *  given location, and gives extra connection information.\r
  */\r
-char PROGMEM HTTP200Header[] = "HTTP/1.1 200 OK\r\n"\r
-                               "Server: LUFA " LUFA_VERSION_STRING "\r\n"\r
-                               "Connection: close\r\n"\r
-                               "MIME-version: 1.0\r\n"\r
-                               "Content-Type: ";\r
+const char PROGMEM HTTP200Header[] = "HTTP/1.1 200 OK\r\n"\r
+                                     "Server: LUFA " LUFA_VERSION_STRING "\r\n"\r
+                                     "Connection: close\r\n"\r
+                                     "MIME-version: 1.0\r\n"\r
+                                     "Content-Type: ";\r
 \r
 /** HTTP server response header, for transmission before a resource not found error. This indicates to the host that the given\r
  *  given URL is invalid, and gives extra error information.\r
  */\r
-char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n"\r
-                               "Server: LUFA " LUFA_VERSION_STRING "\r\n"\r
-                               "Connection: close\r\n"\r
-                               "MIME-version: 1.0\r\n"\r
-                               "Content-Type: text/plain\r\n\r\n"\r
-                               "Error 404: File Not Found";\r
+const char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n"\r
+                                     "Server: LUFA " LUFA_VERSION_STRING "\r\n"\r
+                                     "Connection: close\r\n"\r
+                                     "MIME-version: 1.0\r\n"\r
+                                     "Content-Type: text/plain\r\n\r\n"\r
+                                     "Error 404: File Not Found";\r
 \r
-/** Default MIME type sent if no other MIME type can be determined */\r
-char PROGMEM DefaultMIMEType[] = "text/plain";\r
+/** Default MIME type sent if no other MIME type can be determined. */\r
+const char PROGMEM DefaultMIMEType[] = "text/plain";\r
 \r
 /** List of MIME types for each supported file extension. */\r
-MIME_Type_t PROGMEM MIMETypes[] =\r
+const MIME_Type_t MIMETypes[] =\r
        {\r
                {.Extension = "htm", .MIMEType = "text/html"},\r
                {.Extension = "jpg", .MIMEType = "image/jpeg"},\r
@@ -198,7 +198,7 @@ static void HTTPServerApp_SendResponseHeader(void)
        uip_tcp_appstate_t* const AppState    = &uip_conn->appstate;\r
        char*               const AppData     = (char*)uip_appdata;\r
 \r
-       char* HeaderToSend;\r
+       const char* HeaderToSend;\r
 \r
        /* Determine which HTTP header should be sent to the client */\r
        if (AppState->HTTPServer.FileOpen)\r
@@ -234,10 +234,10 @@ static void HTTPServerApp_SendMIMETypeHeader(void)
                /* Look through the MIME type list, copy over the required MIME type if found */\r
                for (int i = 0; i < (sizeof(MIMETypes) / sizeof(MIMETypes[0])); i++)\r
                {\r
-                       if (strcmp_P(&Extension[1], MIMETypes[i].Extension) == 0)\r
+                       if (strcmp(&Extension[1], MIMETypes[i].Extension) == 0)\r
                        {\r
-                               MIMEHeaderLength = strlen_P(MIMETypes[i].MIMEType);\r
-                               strncpy_P(AppData, MIMETypes[i].MIMEType, MIMEHeaderLength);                                            \r
+                               MIMEHeaderLength = strlen(MIMETypes[i].MIMEType);\r
+                               strncpy(AppData, MIMETypes[i].MIMEType, MIMEHeaderLength);                                              \r
                                break;\r
                        }\r
                } \r
index b113928..d212cf2 100644 (file)
@@ -61,8 +61,8 @@
                /** Type define for a MIME type handler. */\r
                typedef struct\r
                {\r
-                       char Extension[4]; /**< 3 or less character file extension */\r
-                       char MIMEType[30]; /**< Appropriate MIME type to send when the extension is encountered */\r
+                       char* Extension; /**< File extension (no leading '.' character) */\r
+                       char* MIMEType;  /**< Appropriate MIME type to send when the extension is encountered */\r
                } MIME_Type_t;\r
        \r
        /* Macros: */\r
index 291351a..7d8c907 100644 (file)
 #include "TELNETServerApp.h"\r
 \r
 /** Welcome message to send to a TELNET client when a connection is first made. */\r
-char PROGMEM WelcomeHeader[] = "********************************************\r\n"\r
-                               "*       LUFA uIP Webserver (TELNET)        *\r\n"\r
-                               "********************************************\r\n";\r
+const char PROGMEM WelcomeHeader[] = "********************************************\r\n"\r
+                                     "*       LUFA uIP Webserver (TELNET)        *\r\n"\r
+                                     "********************************************\r\n";\r
 \r
 /** Main TELNET menu, giving the user the list of available commands they may issue */\r
-char PROGMEM TELNETMenu[] = "\r\n"\r
-                            "   Available Commands:\r\n"\r
-                            "     c) List Active TCP Connections\r\n"\r
-                                               "\r\nCommand>";\r
+const char PROGMEM TELNETMenu[] = "\r\n"\r
+                                  "   Available Commands:\r\n"\r
+                                  "     c) List Active TCP Connections\r\n"\r
+                                                     "\r\nCommand>";\r
 \r
 /** Initialization function for the simple HTTP webserver. */\r
 void TELNETServerApp_Init(void)\r
index ba2a505..18e355b 100644 (file)
@@ -61,7 +61,7 @@ void uIPManagement_Init(void)
        uip_setethaddr(MACAddress);\r
 \r
        /* DHCP/Server IP Settings Initialization */\r
-       #if defined(ENABLE_DHCP)\r
+       #if defined(ENABLE_DHCP_CLIENT)\r
        DHCPClientApp_Init();\r
        #else\r
        uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress;\r
index 8a09c72..5fca686 100644 (file)
@@ -626,6 +626,8 @@ void uip_log(char *msg);
 #include <stdbool.h>
 #include <stdint.h>
 
+#include "timer.h"
+
 typedef uint8_t u8_t;
 typedef uint16_t u16_t;
 typedef uint32_t u32_t;
@@ -716,7 +718,8 @@ typedef union
 {
        struct
        {
-               uint8_t CurrentState;
+               uint8_t      CurrentState;
+               struct timer Timeout;
                
                struct
                {
index 9cee32e..3ea167f 100644 (file)
  *    <td><b>Description:</b></td>\r
  *   </tr>\r
  *   <tr>\r
- *    <td>ENABLE_DHCP_CLIENT=<i>x</i></td>\r
+ *    <td>ENABLE_DHCP_CLIENT</td>\r
  *    <td>Makefile CDEFS</td>\r
- *    <td>When set to 1, this enables the DHCP client for dynamic IP allocation of the network settings from a DHCP server.\r
- *        To disable DHCP and use the fixed address settings set elsewhere, set this to zero (do not undefine it).</td>\r
+ *    <td>When defined, this enables the DHCP client for dynamic IP allocation of the network settings from a DHCP server.</td>\r
  *   </tr>\r
  *   <tr>\r
  *    <td>DEVICE_IP_ADDRESS</td>\r
  *    <td>Lib/uIPManagement.h</td>\r
- *    <td>IP address that the webserver should use when connected to a RNDIS device (when ENABLE_DHCP_CLIENT is zero).</td>\r
+ *    <td>IP address that the webserver should use when connected to a RNDIS device (when ENABLE_DHCP_CLIENT is not defined).</td>\r
  *   </tr>\r
  *   <tr>\r
  *    <td>DEVICE_NETMASK</td>\r
  *    <td>Lib/uIPManagement.h</td>\r
- *    <td>Netmask that the webserver should use when connected to a RNDIS device (when ENABLE_DHCP_CLIENT is zero).</td>\r
+ *    <td>Netmask that the webserver should use when connected to a RNDIS device (when ENABLE_DHCP_CLIENT is not defined).</td>\r
  *   </tr>\r
  *   <tr>\r
  *    <td>DEVICE_GATEWAY</td>\r
  *    <td>Lib/uIPManagement.h</td>\r
  *    <td>Default routing gateway that the webserver should use when connected to a RNDIS device (when ENABLE_DHCP_CLIENT\r
- *        is zero).</td>\r
+ *        is not defined).</td>\r
  *   </tr>\r
  *  </table>\r
  */
\ No newline at end of file
index b0e26f3..d5eda4c 100644 (file)
@@ -199,9 +199,9 @@ CSTANDARD = -std=gnu99
 \r
 # Place -D or -U options here for C sources\r
 CDEFS  = -DF_CPU=$(F_CPU)UL -DF_CLOCK=$(F_CLOCK)UL -DBOARD=BOARD_$(BOARD) $(LUFA_OPTS)\r
-CDEFS += -DENABLE_DHCP_CLIENT=1\r
+CDEFS += -DENABLE_DHCP_CLIENT\r
 \r
-CDEFS += -DUIP_CONF_UDP=ENABLE_DHCP_CLIENT -DUIP_CONF_TCP=1 -DUIP_CONF_UDP_CONNS=1 -DUIP_CONF_MAX_CONNECTIONS=5\r
+CDEFS += -DUIP_CONF_UDP="defined(ENABLE_DHCP_CLIENT)" -DUIP_CONF_TCP=1 -DUIP_CONF_UDP_CONNS=1 -DUIP_CONF_MAX_CONNECTIONS=5\r
 CDEFS += -DUIP_CONF_MAX_LISTENPORTS=5 -DUIP_URGDATA=0 -DUIP_CONF_BUFFER_SIZE=1514 -DUIP_ARCH_CHKSUM=0 \r
 CDEFS += -DUIP_CONF_LL_802154=0 -DUIP_CONF_LL_80211=0 -DUIP_CONF_ROUTER=0 -DUIP_CONF_ICMP6=0\r
 CDEFS += -DUIP_ARCH_ADD32=0 -DUIP_CONF_ICMP_DEST_UNREACH=1 -DUIP_NEIGHBOR_CONF_ADDRTYPE=0\r