aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/Webserver
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-02-12 07:27:26 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-02-12 07:27:26 +0000
commit8154331da60ac08b0e2b09ca67008ec4a8c7698b (patch)
tree4eb3824afd288039b995f6f607bed6f0129d74ab /Projects/Webserver
parent41ef05a6e559a10134967e8a899aab78c556b645 (diff)
downloadlufa-8154331da60ac08b0e2b09ca67008ec4a8c7698b.tar.gz
lufa-8154331da60ac08b0e2b09ca67008ec4a8c7698b.tar.bz2
lufa-8154331da60ac08b0e2b09ca67008ec4a8c7698b.zip
Move DHCP negotiation timer into the DHCP connection application state structure, so that each connection gets its own timeout counter (only one connection currently used, but this way is more correct). Add const correctness to static data in the TELNETServerApp.c and HTTPServerApp.c files.
Diffstat (limited to 'Projects/Webserver')
-rw-r--r--Projects/Webserver/Lib/DHCPClientApp.c23
-rw-r--r--Projects/Webserver/Lib/FATFs/ffconf.h2
-rw-r--r--Projects/Webserver/Lib/HTTPServerApp.c36
-rw-r--r--Projects/Webserver/Lib/HTTPServerApp.h4
-rw-r--r--Projects/Webserver/Lib/TELNETServerApp.c14
-rw-r--r--Projects/Webserver/Lib/uIPManagement.c2
-rw-r--r--Projects/Webserver/Lib/uip/uipopt.h5
-rw-r--r--Projects/Webserver/Webserver.txt11
-rw-r--r--Projects/Webserver/makefile4
9 files changed, 51 insertions, 50 deletions
diff --git a/Projects/Webserver/Lib/DHCPClientApp.c b/Projects/Webserver/Lib/DHCPClientApp.c
index 0e51d5707..09bae7368 100644
--- a/Projects/Webserver/Lib/DHCPClientApp.c
+++ b/Projects/Webserver/Lib/DHCPClientApp.c
@@ -33,12 +33,10 @@
* DHCP Client Application. When connected to the uIP stack, this will retrieve IP configuration settings from the
* DHCP server on the network.
*/
-
+
#include "DHCPClientApp.h"
#if defined(ENABLE_DHCP_CLIENT) || defined(__DOXYGEN__)
-/** Timer for managing the timeout period for a DHCP server to respond */
-struct timer DHCPTimer;
/** Initialization function for the DHCP client. */
void DHCPClientApp_Init(void)
@@ -54,13 +52,14 @@ void DHCPClientApp_Init(void)
if (Connection != NULL)
{
uip_udp_appstate_t* const AppState = &Connection->appstate;
-
uip_udp_bind(Connection, HTONS(DHCPC_CLIENT_PORT));
+
+ /* Set the initial client state */
AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover;
- }
- /* Set timeout period to half a second for a DHCP server to respond */
- timer_set(&DHCPTimer, CLOCK_SECOND / 2);
+ /* Set timeout period to half a second for a DHCP server to respond */
+ timer_set(&AppState->DHCPClient.Timeout, CLOCK_SECOND / 2);
+ }
}
/** uIP stack application callback for the DHCP client. This function must be called each time the TCP/IP stack
@@ -91,7 +90,7 @@ void DHCPClientApp_Callback(void)
uip_udp_send(AppDataSize);
/* Reset the timeout timer, progress to next state */
- timer_reset(&DHCPTimer);
+ timer_reset(&AppState->DHCPClient.Timeout);
AppState->DHCPClient.CurrentState = DHCP_STATE_WaitForOffer;
break;
@@ -99,7 +98,7 @@ void DHCPClientApp_Callback(void)
if (!(uip_newdata()))
{
/* Check if the DHCP timeout period has expired while waiting for a response */
- if (timer_expired(&DHCPTimer))
+ if (timer_expired(&AppState->DHCPClient.Timeout))
AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover;
break;
@@ -116,7 +115,7 @@ void DHCPClientApp_Callback(void)
DHCPClientApp_GetOption(AppData->Options, DHCP_OPTION_ROUTER, &AppState->DHCPClient.DHCPOffer_Data.GatewayIP);
DHCPClientApp_GetOption(AppData->Options, DHCP_OPTION_SERVER_ID, &AppState->DHCPClient.DHCPOffer_Data.ServerIP);
- timer_reset(&DHCPTimer);
+ timer_reset(&AppState->DHCPClient.Timeout);
AppState->DHCPClient.CurrentState = DHCP_STATE_SendRequest;
}
@@ -137,7 +136,7 @@ void DHCPClientApp_Callback(void)
uip_udp_send(AppDataSize);
/* Reset the timeout timer, progress to next state */
- timer_reset(&DHCPTimer);
+ timer_reset(&AppState->DHCPClient.Timeout);
AppState->DHCPClient.CurrentState = DHCP_STATE_WaitForACK;
break;
@@ -145,7 +144,7 @@ void DHCPClientApp_Callback(void)
if (!(uip_newdata()))
{
/* Check if the DHCP timeout period has expired while waiting for a response */
- if (timer_expired(&DHCPTimer))
+ if (timer_expired(&AppState->DHCPClient.Timeout))
AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover;
break;
diff --git a/Projects/Webserver/Lib/FATFs/ffconf.h b/Projects/Webserver/Lib/FATFs/ffconf.h
index 3ad7a56af..4b19f1326 100644
--- a/Projects/Webserver/Lib/FATFs/ffconf.h
+++ b/Projects/Webserver/Lib/FATFs/ffconf.h
@@ -14,7 +14,7 @@
/ Function and Buffer Configurations
/----------------------------------------------------------------------------*/
-#define _FS_TINY 0 /* 0 or 1 */
+#define _FS_TINY 1 /* 0 or 1 */
/* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system
/ object instead of the sector buffer in the individual file object for file
/ data transfer. This reduces memory consumption 512 bytes each file object. */
diff --git a/Projects/Webserver/Lib/HTTPServerApp.c b/Projects/Webserver/Lib/HTTPServerApp.c
index ad768c89b..e781beb22 100644
--- a/Projects/Webserver/Lib/HTTPServerApp.c
+++ b/Projects/Webserver/Lib/HTTPServerApp.c
@@ -40,27 +40,27 @@
/** HTTP server response header, for transmission before the page contents. This indicates to the host that a page exists at the
* given location, and gives extra connection information.
*/
-char PROGMEM HTTP200Header[] = "HTTP/1.1 200 OK\r\n"
- "Server: LUFA " LUFA_VERSION_STRING "\r\n"
- "Connection: close\r\n"
- "MIME-version: 1.0\r\n"
- "Content-Type: ";
+const char PROGMEM HTTP200Header[] = "HTTP/1.1 200 OK\r\n"
+ "Server: LUFA " LUFA_VERSION_STRING "\r\n"
+ "Connection: close\r\n"
+ "MIME-version: 1.0\r\n"
+ "Content-Type: ";
/** HTTP server response header, for transmission before a resource not found error. This indicates to the host that the given
* given URL is invalid, and gives extra error information.
*/
-char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n"
- "Server: LUFA " LUFA_VERSION_STRING "\r\n"
- "Connection: close\r\n"
- "MIME-version: 1.0\r\n"
- "Content-Type: text/plain\r\n\r\n"
- "Error 404: File Not Found";
+const char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n"
+ "Server: LUFA " LUFA_VERSION_STRING "\r\n"
+ "Connection: close\r\n"
+ "MIME-version: 1.0\r\n"
+ "Content-Type: text/plain\r\n\r\n"
+ "Error 404: File Not Found";
-/** Default MIME type sent if no other MIME type can be determined */
-char PROGMEM DefaultMIMEType[] = "text/plain";
+/** Default MIME type sent if no other MIME type can be determined. */
+const char PROGMEM DefaultMIMEType[] = "text/plain";
/** List of MIME types for each supported file extension. */
-MIME_Type_t PROGMEM MIMETypes[] =
+const MIME_Type_t MIMETypes[] =
{
{.Extension = "htm", .MIMEType = "text/html"},
{.Extension = "jpg", .MIMEType = "image/jpeg"},
@@ -198,7 +198,7 @@ static void HTTPServerApp_SendResponseHeader(void)
uip_tcp_appstate_t* const AppState = &uip_conn->appstate;
char* const AppData = (char*)uip_appdata;
- char* HeaderToSend;
+ const char* HeaderToSend;
/* Determine which HTTP header should be sent to the client */
if (AppState->HTTPServer.FileOpen)
@@ -234,10 +234,10 @@ static void HTTPServerApp_SendMIMETypeHeader(void)
/* Look through the MIME type list, copy over the required MIME type if found */
for (int i = 0; i < (sizeof(MIMETypes) / sizeof(MIMETypes[0])); i++)
{
- if (strcmp_P(&Extension[1], MIMETypes[i].Extension) == 0)
+ if (strcmp(&Extension[1], MIMETypes[i].Extension) == 0)
{
- MIMEHeaderLength = strlen_P(MIMETypes[i].MIMEType);
- strncpy_P(AppData, MIMETypes[i].MIMEType, MIMEHeaderLength);
+ MIMEHeaderLength = strlen(MIMETypes[i].MIMEType);
+ strncpy(AppData, MIMETypes[i].MIMEType, MIMEHeaderLength);
break;
}
}
diff --git a/Projects/Webserver/Lib/HTTPServerApp.h b/Projects/Webserver/Lib/HTTPServerApp.h
index b1139280c..d212cf250 100644
--- a/Projects/Webserver/Lib/HTTPServerApp.h
+++ b/Projects/Webserver/Lib/HTTPServerApp.h
@@ -61,8 +61,8 @@
/** Type define for a MIME type handler. */
typedef struct
{
- char Extension[4]; /**< 3 or less character file extension */
- char MIMEType[30]; /**< Appropriate MIME type to send when the extension is encountered */
+ char* Extension; /**< File extension (no leading '.' character) */
+ char* MIMEType; /**< Appropriate MIME type to send when the extension is encountered */
} MIME_Type_t;
/* Macros: */
diff --git a/Projects/Webserver/Lib/TELNETServerApp.c b/Projects/Webserver/Lib/TELNETServerApp.c
index 291351ae8..7d8c907fe 100644
--- a/Projects/Webserver/Lib/TELNETServerApp.c
+++ b/Projects/Webserver/Lib/TELNETServerApp.c
@@ -38,15 +38,15 @@
#include "TELNETServerApp.h"
/** Welcome message to send to a TELNET client when a connection is first made. */
-char PROGMEM WelcomeHeader[] = "********************************************\r\n"
- "* LUFA uIP Webserver (TELNET) *\r\n"
- "********************************************\r\n";
+const char PROGMEM WelcomeHeader[] = "********************************************\r\n"
+ "* LUFA uIP Webserver (TELNET) *\r\n"
+ "********************************************\r\n";
/** Main TELNET menu, giving the user the list of available commands they may issue */
-char PROGMEM TELNETMenu[] = "\r\n"
- " Available Commands:\r\n"
- " c) List Active TCP Connections\r\n"
- "\r\nCommand>";
+const char PROGMEM TELNETMenu[] = "\r\n"
+ " Available Commands:\r\n"
+ " c) List Active TCP Connections\r\n"
+ "\r\nCommand>";
/** Initialization function for the simple HTTP webserver. */
void TELNETServerApp_Init(void)
diff --git a/Projects/Webserver/Lib/uIPManagement.c b/Projects/Webserver/Lib/uIPManagement.c
index ba2a505e9..18e355bde 100644
--- a/Projects/Webserver/Lib/uIPManagement.c
+++ b/Projects/Webserver/Lib/uIPManagement.c
@@ -61,7 +61,7 @@ void uIPManagement_Init(void)
uip_setethaddr(MACAddress);
/* DHCP/Server IP Settings Initialization */
- #if defined(ENABLE_DHCP)
+ #if defined(ENABLE_DHCP_CLIENT)
DHCPClientApp_Init();
#else
uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress;
diff --git a/Projects/Webserver/Lib/uip/uipopt.h b/Projects/Webserver/Lib/uip/uipopt.h
index 8a09c7248..5fca686a2 100644
--- a/Projects/Webserver/Lib/uip/uipopt.h
+++ b/Projects/Webserver/Lib/uip/uipopt.h
@@ -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
{
diff --git a/Projects/Webserver/Webserver.txt b/Projects/Webserver/Webserver.txt
index 9cee32e8a..3ea167f55 100644
--- a/Projects/Webserver/Webserver.txt
+++ b/Projects/Webserver/Webserver.txt
@@ -78,26 +78,25 @@
* <td><b>Description:</b></td>
* </tr>
* <tr>
- * <td>ENABLE_DHCP_CLIENT=<i>x</i></td>
+ * <td>ENABLE_DHCP_CLIENT</td>
* <td>Makefile CDEFS</td>
- * <td>When set to 1, this enables the DHCP client for dynamic IP allocation of the network settings from a DHCP server.
- * To disable DHCP and use the fixed address settings set elsewhere, set this to zero (do not undefine it).</td>
+ * <td>When defined, this enables the DHCP client for dynamic IP allocation of the network settings from a DHCP server.</td>
* </tr>
* <tr>
* <td>DEVICE_IP_ADDRESS</td>
* <td>Lib/uIPManagement.h</td>
- * <td>IP address that the webserver should use when connected to a RNDIS device (when ENABLE_DHCP_CLIENT is zero).</td>
+ * <td>IP address that the webserver should use when connected to a RNDIS device (when ENABLE_DHCP_CLIENT is not defined).</td>
* </tr>
* <tr>
* <td>DEVICE_NETMASK</td>
* <td>Lib/uIPManagement.h</td>
- * <td>Netmask that the webserver should use when connected to a RNDIS device (when ENABLE_DHCP_CLIENT is zero).</td>
+ * <td>Netmask that the webserver should use when connected to a RNDIS device (when ENABLE_DHCP_CLIENT is not defined).</td>
* </tr>
* <tr>
* <td>DEVICE_GATEWAY</td>
* <td>Lib/uIPManagement.h</td>
* <td>Default routing gateway that the webserver should use when connected to a RNDIS device (when ENABLE_DHCP_CLIENT
- * is zero).</td>
+ * is not defined).</td>
* </tr>
* </table>
*/ \ No newline at end of file
diff --git a/Projects/Webserver/makefile b/Projects/Webserver/makefile
index b0e26f3a4..d5eda4c44 100644
--- a/Projects/Webserver/makefile
+++ b/Projects/Webserver/makefile
@@ -199,9 +199,9 @@ CSTANDARD = -std=gnu99
# Place -D or -U options here for C sources
CDEFS = -DF_CPU=$(F_CPU)UL -DF_CLOCK=$(F_CLOCK)UL -DBOARD=BOARD_$(BOARD) $(LUFA_OPTS)
-CDEFS += -DENABLE_DHCP_CLIENT=1
+CDEFS += -DENABLE_DHCP_CLIENT
-CDEFS += -DUIP_CONF_UDP=ENABLE_DHCP_CLIENT -DUIP_CONF_TCP=1 -DUIP_CONF_UDP_CONNS=1 -DUIP_CONF_MAX_CONNECTIONS=5
+CDEFS += -DUIP_CONF_UDP="defined(ENABLE_DHCP_CLIENT)" -DUIP_CONF_TCP=1 -DUIP_CONF_UDP_CONNS=1 -DUIP_CONF_MAX_CONNECTIONS=5
CDEFS += -DUIP_CONF_MAX_LISTENPORTS=5 -DUIP_URGDATA=0 -DUIP_CONF_BUFFER_SIZE=1514 -DUIP_ARCH_CHKSUM=0
CDEFS += -DUIP_CONF_LL_802154=0 -DUIP_CONF_LL_80211=0 -DUIP_CONF_ROUTER=0 -DUIP_CONF_ICMP6=0
CDEFS += -DUIP_ARCH_ADD32=0 -DUIP_CONF_ICMP_DEST_UNREACH=1 -DUIP_NEIGHBOR_CONF_ADDRTYPE=0