]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Option.h
synced function header
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Option.h
index 9db2e0a721167d4faae3a22735b1e57bb82e3279..74d84b3f8148f2558b12c523170be8a1f6a503ea 100644 (file)
@@ -24,10 +24,10 @@ Abstract:
 #ifndef __EFI_DHCP4_OPTION_H__\r
 #define __EFI_DHCP4_OPTION_H__\r
 \r
-//\r
-// DHCP option tags (types)\r
-//\r
-enum {\r
+///\r
+/// DHCP option tags (types)\r
+///\r
+typedef enum {\r
   //\r
   // RFC1497 vendor extensions\r
   //\r
@@ -132,12 +132,12 @@ enum {
   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
@@ -146,29 +146,31 @@ enum {
   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
-// structure to support options longer than 255 bytes, such as classless route.\r
-//\r
+///\r
+/// The DHCP option structure. This structure extends the EFI_DHCP_OPTION\r
+/// structure to support options longer than 255 bytes, such as classless route.\r
+///\r
 typedef struct {\r
   UINT8                     Tag;\r
   UINT16                    Len;\r
   UINT8                     *Data;\r
 } DHCP_OPTION;\r
 \r
-//\r
-// Structures used to parse the DHCP options with RFC3396 support.\r
-//\r
+///\r
+/// Structures used to parse the DHCP options with RFC3396 support.\r
+///\r
 typedef struct {\r
   UINT8                     Index;\r
   UINT16                    Offset;\r
@@ -180,11 +182,11 @@ typedef struct {
   UINT8                     *Buf;\r
 } DHCP_OPTION_CONTEXT;\r
 \r
-//\r
-// The options that matters to DHCP driver itself. The user of\r
-// DHCP clients may be interested in other options, such as\r
-// classless route, who can parse the DHCP offer to get them.\r
-//\r
+///\r
+/// The options that matters to DHCP driver itself. The user of\r
+/// DHCP clients may be interested in other options, such as\r
+/// classless route, who can parse the DHCP offer to get them.\r
+///\r
 typedef struct {\r
   IP4_ADDR                  NetMask;  // DHCP_TAG_NETMASK\r
   IP4_ADDR                  Router;   // DHCP_TAG_ROUTER, only the first router is used\r
@@ -200,14 +202,14 @@ typedef struct {
   UINT32                    T2;       // DHCP_TAG_T2\r
 } DHCP_PARAMETER;\r
 \r
-//\r
-// Structure used to describe and validate the format of DHCP options.\r
-// Type is the options' data type, such as DHCP_OPTION_INT8. MinOccur\r
-// is the minium occurance of this data type. MaxOccur is defined\r
-// similarly. If MaxOccur is -1, it means that there is no limit on the\r
-// maximum occurance. Alert tells whether DHCP client should further\r
-// inspect the option to parse DHCP_PARAMETER.\r
-//\r
+///\r
+/// Structure used to describe and validate the format of DHCP options.\r
+/// Type is the options' data type, such as DHCP_OPTION_INT8. MinOccur\r
+/// is the minium occurance of this data type. MaxOccur is defined\r
+/// similarly. If MaxOccur is -1, it means that there is no limit on the\r
+/// maximum occurance. Alert tells whether DHCP client should further\r
+/// inspect the option to parse DHCP_PARAMETER.\r
+///\r
 typedef struct {\r
   UINT8                     Tag;\r
   INTN                      Type;\r
@@ -225,19 +227,73 @@ EFI_STATUS
   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 EFI_INVALID_PARAMETER  The DHCP packet's options are not well formated\r
+\r
+**/\r
 EFI_STATUS\r
 DhcpIterateOptions (\r
   IN  EFI_DHCP4_PACKET      *Packet,\r
-  IN  DHCP_CHECK_OPTION     Check,          OPTIONAL\r
+  IN  DHCP_CHECK_OPTION     Check,        OPTIONAL\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
+  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 continuous 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
@@ -245,22 +301,51 @@ DhcpParseOption (
   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                  Tag,\r
-  IN UINT16                 DataLen,\r
-  IN UINT8                  *Data\r
+  OUT UINT8                  *Buf,\r
+  IN  UINT8                  Tag,\r
+  IN  UINT16                 DataLen,\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_INVALID_PARAMETER  The options in SeekPacket are mal-formated\r
+  @retval EFI_SUCCESS            The packet is build.\r
+\r
+**/\r
 EFI_STATUS\r
 DhcpBuild (\r
-  IN  EFI_DHCP4_PACKET         *SeedPacket,\r
-  IN  UINT32                   DeleteCount,\r
-  IN  UINT8                    *DeleteList OPTIONAL,\r
-  IN  UINT32                   AppendCount,\r
-  IN  EFI_DHCP4_PACKET_OPTION  *AppendList[] OPTIONAL,\r
-  OUT EFI_DHCP4_PACKET         **NewPacket\r
+  IN  EFI_DHCP4_PACKET        *SeedPacket,\r
+  IN  UINT32                  DeleteCount,\r
+  IN  UINT8                   *DeleteList     OPTIONAL,\r
+  IN  UINT32                  AppendCount,\r
+  IN  EFI_DHCP4_PACKET_OPTION *AppendList[]   OPTIONAL,\r
+  OUT EFI_DHCP4_PACKET        **NewPacket\r
   );\r
 \r
 #endif\r