Commit 8154331d authored by Dean Camera's avatar Dean Camera
Browse files

Move DHCP negotiation timer into the DHCP connection application state...

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.
parent 41ef05a6
......@@ -64,13 +64,14 @@
* - BAP, A tiny LUFA based AVR Programmer: http://www.busware.de/tiki-index.php?page=BAP
* - Digital Survey Instruments Magnetometer and Pointer: http://www.digitalsurveyinstruments.com/
* - Lightweight CC110x USB dongle for 868MHz Protocols: http://busware.de/tiki-index.php?page=CUL
* - Penguino, an Arduino Board With On-Board LUFA Powered Debugger/Programmer: http://wiki.icy.com.au/PenguinoAVR
* - MIDIFighter, a USB-MIDI controller: http://www.midifighter.com/
* - Mobo 4.3, a USB controlled all band (160-10m) HF SDR transceiver: http://sites.google.com/site/lofturj/mobo4_3
* - SEGA Megadrive/Super Nintendo Cartridge Reader: http://www.snega2usb.com
* - Retrode, a USB Games Console Cartridge Reader: http://www.snega2usb.com
* - XMEGA Development Board, using LUFA as an On-Board Programmer: http://xmega.mattair.net/
* - Penguino, an Arduino Board With On-Board LUFA Powered Debugger/Programmer: http://wiki.icy.com.au/PenguinoAVR
*
* \section Sec_LUFAPublications Publications Mentioning LUFA
* - Elektor Magazine, "My First AVR-USB" by Antoine Authier (feature), January 2010 Issue
* - Elektor Magazine, "USB is Cool/Sucks" by Jerry Jacobs and Chris Vossen (minor mention), January 2010 Issue
* - Elektor Magazine, "20 x Open Source", March 2010 Issue
*/
\ No newline at end of file
......@@ -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;
......
......@@ -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. */
......
......@@ -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;
}
}
......
......@@ -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: */
......
......@@ -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)
......
......@@ -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;
......
......@@ -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
{
......
......@@ -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
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment