Move DHCP negotiation timer into the DHCP connection application state structure...
[pub/USBasp.git] / Projects / Webserver / Lib / DHCPClientApp.c
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