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.

pull/1469/head
Dean Camera 15 years ago
parent 41ef05a6e5
commit 8154331da6

@ -64,13 +64,14 @@
* - BAP, A tiny LUFA based AVR Programmer: http://www.busware.de/tiki-index.php?page=BAP * - 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/ * - 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 * - 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/ * - 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 * - 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/ * - 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 * \section Sec_LUFAPublications Publications Mentioning LUFA
* - Elektor Magazine, "My First AVR-USB" by Antoine Authier (feature), January 2010 Issue * - 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, "USB is Cool/Sucks" by Jerry Jacobs and Chris Vossen (minor mention), January 2010 Issue
* - Elektor Magazine, "20 x Open Source", March 2010 Issue
*/ */

@ -33,12 +33,10 @@
* DHCP Client Application. When connected to the uIP stack, this will retrieve IP configuration settings from the * DHCP Client Application. When connected to the uIP stack, this will retrieve IP configuration settings from the
* DHCP server on the network. * DHCP server on the network.
*/ */
#include "DHCPClientApp.h" #include "DHCPClientApp.h"
#if defined(ENABLE_DHCP_CLIENT) || defined(__DOXYGEN__) #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. */ /** Initialization function for the DHCP client. */
void DHCPClientApp_Init(void) void DHCPClientApp_Init(void)
@ -54,13 +52,14 @@ void DHCPClientApp_Init(void)
if (Connection != NULL) if (Connection != NULL)
{ {
uip_udp_appstate_t* const AppState = &Connection->appstate; uip_udp_appstate_t* const AppState = &Connection->appstate;
uip_udp_bind(Connection, HTONS(DHCPC_CLIENT_PORT)); uip_udp_bind(Connection, HTONS(DHCPC_CLIENT_PORT));
/* Set the initial client state */
AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover; AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover;
}
/* Set timeout period to half a second for a DHCP server to respond */ /* Set timeout period to half a second for a DHCP server to respond */
timer_set(&DHCPTimer, CLOCK_SECOND / 2); 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 /** 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); uip_udp_send(AppDataSize);
/* Reset the timeout timer, progress to next state */ /* Reset the timeout timer, progress to next state */
timer_reset(&DHCPTimer); timer_reset(&AppState->DHCPClient.Timeout);
AppState->DHCPClient.CurrentState = DHCP_STATE_WaitForOffer; AppState->DHCPClient.CurrentState = DHCP_STATE_WaitForOffer;
break; break;
@ -99,7 +98,7 @@ void DHCPClientApp_Callback(void)
if (!(uip_newdata())) if (!(uip_newdata()))
{ {
/* Check if the DHCP timeout period has expired while waiting for a response */ /* 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; AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover;
break; 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_ROUTER, &AppState->DHCPClient.DHCPOffer_Data.GatewayIP);
DHCPClientApp_GetOption(AppData->Options, DHCP_OPTION_SERVER_ID, &AppState->DHCPClient.DHCPOffer_Data.ServerIP); 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; AppState->DHCPClient.CurrentState = DHCP_STATE_SendRequest;
} }
@ -137,7 +136,7 @@ void DHCPClientApp_Callback(void)
uip_udp_send(AppDataSize); uip_udp_send(AppDataSize);
/* Reset the timeout timer, progress to next state */ /* Reset the timeout timer, progress to next state */
timer_reset(&DHCPTimer); timer_reset(&AppState->DHCPClient.Timeout);
AppState->DHCPClient.CurrentState = DHCP_STATE_WaitForACK; AppState->DHCPClient.CurrentState = DHCP_STATE_WaitForACK;
break; break;
@ -145,7 +144,7 @@ void DHCPClientApp_Callback(void)
if (!(uip_newdata())) if (!(uip_newdata()))
{ {
/* Check if the DHCP timeout period has expired while waiting for a response */ /* 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; AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover;
break; break;

@ -14,7 +14,7 @@
/ Function and Buffer Configurations / 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 /* 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 / object instead of the sector buffer in the individual file object for file
/ data transfer. This reduces memory consumption 512 bytes each file object. */ / 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 /** 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. * given location, and gives extra connection information.
*/ */
char PROGMEM HTTP200Header[] = "HTTP/1.1 200 OK\r\n" const char PROGMEM HTTP200Header[] = "HTTP/1.1 200 OK\r\n"
"Server: LUFA " LUFA_VERSION_STRING "\r\n" "Server: LUFA " LUFA_VERSION_STRING "\r\n"
"Connection: close\r\n" "Connection: close\r\n"
"MIME-version: 1.0\r\n" "MIME-version: 1.0\r\n"
"Content-Type: "; "Content-Type: ";
/** HTTP server response header, for transmission before a resource not found error. This indicates to the host that the given /** 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. * given URL is invalid, and gives extra error information.
*/ */
char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n" const char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n"
"Server: LUFA " LUFA_VERSION_STRING "\r\n" "Server: LUFA " LUFA_VERSION_STRING "\r\n"
"Connection: close\r\n" "Connection: close\r\n"
"MIME-version: 1.0\r\n" "MIME-version: 1.0\r\n"
"Content-Type: text/plain\r\n\r\n" "Content-Type: text/plain\r\n\r\n"
"Error 404: File Not Found"; "Error 404: File Not Found";
/** Default MIME type sent if no other MIME type can be determined */ /** Default MIME type sent if no other MIME type can be determined. */
char PROGMEM DefaultMIMEType[] = "text/plain"; const char PROGMEM DefaultMIMEType[] = "text/plain";
/** List of MIME types for each supported file extension. */ /** 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 = "htm", .MIMEType = "text/html"},
{.Extension = "jpg", .MIMEType = "image/jpeg"}, {.Extension = "jpg", .MIMEType = "image/jpeg"},
@ -198,7 +198,7 @@ static void HTTPServerApp_SendResponseHeader(void)
uip_tcp_appstate_t* const AppState = &uip_conn->appstate; uip_tcp_appstate_t* const AppState = &uip_conn->appstate;
char* const AppData = (char*)uip_appdata; char* const AppData = (char*)uip_appdata;
char* HeaderToSend; const char* HeaderToSend;
/* Determine which HTTP header should be sent to the client */ /* Determine which HTTP header should be sent to the client */
if (AppState->HTTPServer.FileOpen) 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 */ /* 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++) 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); MIMEHeaderLength = strlen(MIMETypes[i].MIMEType);
strncpy_P(AppData, MIMETypes[i].MIMEType, MIMEHeaderLength); strncpy(AppData, MIMETypes[i].MIMEType, MIMEHeaderLength);
break; break;
} }
} }

@ -61,8 +61,8 @@
/** Type define for a MIME type handler. */ /** Type define for a MIME type handler. */
typedef struct typedef struct
{ {
char Extension[4]; /**< 3 or less character file extension */ char* Extension; /**< File extension (no leading '.' character) */
char MIMEType[30]; /**< Appropriate MIME type to send when the extension is encountered */ char* MIMEType; /**< Appropriate MIME type to send when the extension is encountered */
} MIME_Type_t; } MIME_Type_t;
/* Macros: */ /* Macros: */

@ -38,15 +38,15 @@
#include "TELNETServerApp.h" #include "TELNETServerApp.h"
/** Welcome message to send to a TELNET client when a connection is first made. */ /** Welcome message to send to a TELNET client when a connection is first made. */
char PROGMEM WelcomeHeader[] = "********************************************\r\n" const char PROGMEM WelcomeHeader[] = "********************************************\r\n"
"* LUFA uIP Webserver (TELNET) *\r\n" "* LUFA uIP Webserver (TELNET) *\r\n"
"********************************************\r\n"; "********************************************\r\n";
/** Main TELNET menu, giving the user the list of available commands they may issue */ /** Main TELNET menu, giving the user the list of available commands they may issue */
char PROGMEM TELNETMenu[] = "\r\n" const char PROGMEM TELNETMenu[] = "\r\n"
" Available Commands:\r\n" " Available Commands:\r\n"
" c) List Active TCP Connections\r\n" " c) List Active TCP Connections\r\n"
"\r\nCommand>"; "\r\nCommand>";
/** Initialization function for the simple HTTP webserver. */ /** Initialization function for the simple HTTP webserver. */
void TELNETServerApp_Init(void) void TELNETServerApp_Init(void)

@ -61,7 +61,7 @@ void uIPManagement_Init(void)
uip_setethaddr(MACAddress); uip_setethaddr(MACAddress);
/* DHCP/Server IP Settings Initialization */ /* DHCP/Server IP Settings Initialization */
#if defined(ENABLE_DHCP) #if defined(ENABLE_DHCP_CLIENT)
DHCPClientApp_Init(); DHCPClientApp_Init();
#else #else
uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress; uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress;

@ -626,6 +626,8 @@ void uip_log(char *msg);
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "timer.h"
typedef uint8_t u8_t; typedef uint8_t u8_t;
typedef uint16_t u16_t; typedef uint16_t u16_t;
typedef uint32_t u32_t; typedef uint32_t u32_t;
@ -716,7 +718,8 @@ typedef union
{ {
struct struct
{ {
uint8_t CurrentState; uint8_t CurrentState;
struct timer Timeout;
struct struct
{ {

@ -78,26 +78,25 @@
* <td><b>Description:</b></td> * <td><b>Description:</b></td>
* </tr> * </tr>
* <tr> * <tr>
* <td>ENABLE_DHCP_CLIENT=<i>x</i></td> * <td>ENABLE_DHCP_CLIENT</td>
* <td>Makefile CDEFS</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. * <td>When defined, this enables the DHCP client for dynamic IP allocation of the network settings from a DHCP server.</td>
* To disable DHCP and use the fixed address settings set elsewhere, set this to zero (do not undefine it).</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>DEVICE_IP_ADDRESS</td> * <td>DEVICE_IP_ADDRESS</td>
* <td>Lib/uIPManagement.h</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>
* <tr> * <tr>
* <td>DEVICE_NETMASK</td> * <td>DEVICE_NETMASK</td>
* <td>Lib/uIPManagement.h</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>
* <tr> * <tr>
* <td>DEVICE_GATEWAY</td> * <td>DEVICE_GATEWAY</td>
* <td>Lib/uIPManagement.h</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 * <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> * </tr>
* </table> * </table>
*/ */

@ -199,9 +199,9 @@ CSTANDARD = -std=gnu99
# Place -D or -U options here for C sources # 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 = -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_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_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 CDEFS += -DUIP_ARCH_ADD32=0 -DUIP_CONF_ICMP_DEST_UNREACH=1 -DUIP_NEIGHBOR_CONF_ADDRTYPE=0

Loading…
Cancel
Save