Clean up Webserver project - add more Doxygen documentation for the new DHCP client...
[pub/USBasp.git] / Projects / Webserver / Lib / DHCPApp.c
index ec5a815..fe6c6f4 100644 (file)
@@ -36,7 +36,7 @@
  \r
 #include "DHCPApp.h"\r
 \r
-#if defined(ENABLE_DHCP)\r
+#if defined(ENABLE_DHCP) || defined(__DOXYGEN__)\r
 /** Timer for managing the timeout period for a DHCP server to respond */\r
 struct timer DHCPTimer;\r
 \r
@@ -90,10 +90,10 @@ void DHCPApp_Callback(void)
 \r
                        /* Reset the timeout timer, progress to next state */\r
                        timer_reset(&DHCPTimer);\r
-                       AppState->CurrentState = DHCP_STATE_WaitForResponse;                    \r
+                       AppState->CurrentState = DHCP_STATE_WaitForOffer;                       \r
                        \r
                        break;\r
-               case DHCP_STATE_WaitForResponse:\r
+               case DHCP_STATE_WaitForOffer:\r
                        if (!(uip_newdata()))\r
                        {\r
                                /* Check if the DHCP timeout period has expired while waiting for a response */\r
@@ -166,6 +166,15 @@ void DHCPApp_Callback(void)
        }\r
 }\r
 \r
+/** Fills the DHCP packet response with the appropriate BOOTP header for DHCP. This fills out all the required\r
+ *  fields, leaving only the additional DHCP options to be added to the packet before it is sent to the DHCP server.\r
+ *\r
+ *  \param[out] DHCPHeader  Location in the packet buffer where the BOOTP header should be written to\r
+ *  \param[in]  DHCPMessageType  DHCP Message type, such as DHCP_DISCOVER\r
+ *  \param[in]  AppState    Application state of the current UDP connection\r
+ *\r
+ *  \return Size in bytes of the created DHCP packet\r
+ */\r
 uint16_t DHCPApp_FillDHCPHeader(DHCP_Header_t* DHCPHeader, uint8_t DHCPMessageType, uip_udp_appstate_t* AppState)\r
 {\r
        /* Erase existing packet data so that we start will all 0x00 DHCP header data */\r
@@ -195,7 +204,17 @@ uint16_t DHCPApp_FillDHCPHeader(DHCP_Header_t* DHCPHeader, uint8_t DHCPMessageTy
        return (sizeof(DHCP_Header_t) + 4);\r
 }\r
 \r
-uint8_t DHCPApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataLen, void* Source)\r
+/** Sets the given DHCP option in the DHCP packet's option list. This automatically moves the\r
+ *  end of options terminator past the new option in the options list.\r
+ *\r
+ *  \param[in,out] DHCPOptionList  Pointer to the start of the DHCP packet's options list\r
+ *  \param[in]     Option          DHCP option to add to the list\r
+ *  \param[in]     DataLen         Size in bytes of the option data to add\r
+ *  \param[in]     OptionData      Buffer where the option's data is to be sourced from\r
+ *\r
+ *  \return Number of bytes added to the DHCP packet\r
+ */\r
+uint8_t DHCPApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataLen, void* OptionData)\r
 {\r
        /* Skip through the DHCP options list until the terminator option is found */\r
        while (*DHCPOptionList != DHCP_OPTION_END)\r
@@ -204,13 +223,21 @@ uint8_t DHCPApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataL
        /* Overwrite the existing terminator with the new option, add a new terminator at the end of the list */\r
        DHCPOptionList[0] = Option;\r
        DHCPOptionList[1] = DataLen;\r
-       memcpy(&DHCPOptionList[2], Source, DataLen);\r
+       memcpy(&DHCPOptionList[2], OptionData, DataLen);\r
        DHCPOptionList[2 + DataLen] = DHCP_OPTION_END;\r
        \r
        /* Calculate the total number of bytes added to the outgoing packet */\r
        return (2 + DataLen);\r
 }\r
 \r
+/** Retrieves the given option's data (if present) from the DHCP packet's options list.\r
+ *\r
+ *  \param[in,out] DHCPOptionList  Pointer to the start of the DHCP packet's options list\r
+ *  \param[in]     Option          DHCP option to retrieve to the list\r
+ *  \param[out]    Destination     Buffer where the option's data is to be written to if found\r
+ *\r
+ *  \return Boolean true if the option was found in the DHCP packet's options list, false otherwise\r
+ */\r
 bool DHCPApp_GetOption(uint8_t* DHCPOptionList, uint8_t Option, void* Destination)\r
 {\r
        /* Look through the incomming DHCP packet's options list for the requested option */\r
@@ -233,5 +260,4 @@ bool DHCPApp_GetOption(uint8_t* DHCPOptionList, uint8_t Option, void* Destinatio
        /* Requested option not found in the incomming packet's DHCP options list */\r
        return false;\r
 }\r
-\r
 #endif\r