//\r
// DHCP option tags (types)\r
//\r
-enum {\r
+typedef enum {\r
//\r
// RFC1497 vendor extensions\r
//\r
DHCP_TAG_T2 = 59, // Rebinding (T2) Time Value\r
DHCP_TAG_VENDOR_CLASS = 60, // Vendor class identifier\r
DHCP_TAG_CLIENT_ID = 61 // Client-identifier\r
-};\r
+} DHCP_TAGS;\r
\r
-enum {\r
- DHCP_OPTION_MAGIC = 0x63538263, // Network byte order\r
- DHCP_MAX_OPTIONS = 256,\r
+#define DHCP_OPTION_MAGIC 0x63538263 // Network byte order\r
+#define DHCP_MAX_OPTIONS 256\r
\r
+typedef enum {\r
//\r
// DHCP option types, this is used to validate the DHCP options.\r
//\r
DHCP_OPTION_INT16,\r
DHCP_OPTION_INT32,\r
DHCP_OPTION_IP,\r
- DHCP_OPTION_IPPAIR,\r
+ DHCP_OPTION_IPPAIR\r
+} DHCP_OPTION_TYPE; \r
\r
+typedef enum {\r
//\r
// Value of DHCP overload option\r
//\r
DHCP_OVERLOAD_FILENAME = 1,\r
DHCP_OVERLOAD_SVRNAME = 2,\r
DHCP_OVERLOAD_BOTH = 3\r
-};\r
+} DHCP_OVERLOAD_TYPE;\r
\r
//\r
// The DHCP option structure. This structure extends the EFI_DHCP_OPTION\r
IN VOID *Context\r
);\r
\r
+/**\r
+ Iterate through a DHCP message to visit each option. First inspect\r
+ all the options in the OPTION field. Then if overloaded, inspect\r
+ the options in FILENAME and SERVERNAME fields. One option may be\r
+ encoded in several places. See RFC 3396 Encoding Long Options in DHCP\r
+\r
+ @param Packet The DHCP packet to check the options for\r
+ @param Check The callback function to be called for each option\r
+ found\r
+ @param Context The opaque parameter for Check\r
+\r
+ @retval EFI_SUCCESS The DHCP packet's options are well formated\r
+ @retval Others The DHCP packet's options are not well formated\r
+\r
+**/\r
EFI_STATUS\r
DhcpIterateOptions (\r
IN EFI_DHCP4_PACKET *Packet,\r
IN VOID *Context\r
);\r
\r
+/**\r
+ Validate the packet's options. If necessary, allocate\r
+ and fill in the interested parameters.\r
+\r
+ @param Packet The packet to validate the options\r
+ @param Para The variable to save the DHCP parameters.\r
+\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory to validate the packet.\r
+ @retval EFI_INVALID_PARAMETER The options are mal-formated\r
+ @retval EFI_SUCCESS The options are parsed into OptionPoint\r
+\r
+**/\r
EFI_STATUS\r
DhcpValidateOptions (\r
IN EFI_DHCP4_PACKET *Packet,\r
OUT DHCP_PARAMETER **Para OPTIONAL\r
);\r
\r
+/**\r
+ Parse the options of a DHCP packet. It supports RFC 3396: Encoding\r
+ Long Options in DHCP. That is, it will combine all the option value\r
+ of all the occurances of each option.\r
+ A little bit of implemenation:\r
+ It adopts the "Key indexed counting" algorithm. First, it allocates\r
+ an array of 256 DHCP_OPTION_COUNTs because DHCP option tag is encoded\r
+ as a UINT8. It then iterates the DHCP packet to get data length of\r
+ each option by calling DhcpIterOptions with DhcpGetOptionLen. Now, it\r
+ knows the number of present options and their length. It allocates a\r
+ array of DHCP_OPTION and a continous buffer after the array to put\r
+ all the options' data. Each option's data is pointed to by the Data\r
+ field in DHCP_OPTION structure. At last, it call DhcpIterateOptions\r
+ with DhcpFillOption to fill each option's data to its position in the\r
+ buffer.\r
+\r
+ @param Packet The DHCP packet to parse the options\r
+ @param Count The number of valid dhcp options present in the\r
+ packet\r
+ @param OptionPoint The array that contains the DHCP options. Caller\r
+ should free it.\r
+\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory to parse the packet.\r
+ @retval EFI_INVALID_PARAMETER The options are mal-formated\r
+ @retval EFI_SUCCESS The options are parsed into OptionPoint\r
+\r
+**/\r
EFI_STATUS\r
DhcpParseOption (\r
IN EFI_DHCP4_PACKET *Packet,\r
OUT DHCP_OPTION **OptionPoint\r
);\r
\r
+/**\r
+ Append an option to the memory, if the option is longer than\r
+ 255 bytes, splits it into several options.\r
+\r
+ @param Buf The buffer to append the option to\r
+ @param Tag The option's tag\r
+ @param DataLen The length of the option's data\r
+ @param Data The option's data\r
+\r
+ @return The position to append the next option\r
+\r
+**/\r
UINT8 *\r
DhcpAppendOption (\r
IN UINT8 *Buf,\r
IN UINT8 *Data\r
);\r
\r
+/**\r
+ Build a new DHCP packet from a seed packet. Options may be deleted or\r
+ appended. The caller should free the NewPacket when finished using it.\r
+\r
+ @param SeedPacket The seed packet to start with\r
+ @param DeleteCount The number of options to delete\r
+ @param DeleteList The options to delete from the packet\r
+ @param AppendCount The number of options to append\r
+ @param AppendList The options to append to the packet\r
+ @param NewPacket The new packet, allocated and built by this\r
+ function.\r
+\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory\r
+ @retval EFI_SUCCESS The packet is build.\r
+\r
+**/\r
EFI_STATUS\r
DhcpBuild (\r
IN EFI_DHCP4_PACKET *SeedPacket,\r