]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.h
BaseTools: Get Pcd DatumType from DEC file for --pcd
[mirror_edk2.git] / NetworkPkg / UefiPxeBcDxe / PxeBcDhcp4.h
... / ...
CommitLineData
1/** @file\r
2 Functions declaration related with DHCPv4 for UefiPxeBc Driver.\r
3\r
4 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef __EFI_PXEBC_DHCP4_H__\r
17#define __EFI_PXEBC_DHCP4_H__\r
18\r
19#define PXEBC_DHCP4_OPTION_MAX_NUM 16\r
20#define PXEBC_DHCP4_OPTION_MAX_SIZE 312\r
21#define PXEBC_DHCP4_PACKET_MAX_SIZE (sizeof (EFI_PXE_BASE_CODE_PACKET))\r
22#define PXEBC_DHCP4_S_PORT 67\r
23#define PXEBC_DHCP4_C_PORT 68\r
24#define PXEBC_BS_DOWNLOAD_PORT 69\r
25#define PXEBC_BS_DISCOVER_PORT 4011\r
26#define PXEBC_DHCP4_OPCODE_REQUEST 1\r
27#define PXEBC_DHCP4_OPCODE_REPLY 2\r
28#define PXEBC_DHCP4_MSG_TYPE_REQUEST 3\r
29#define PXEBC_DHCP4_MAGIC 0x63538263 // network byte order\r
30\r
31//\r
32// Sub-Options in Dhcp Vendor Option\r
33//\r
34#define PXEBC_VENDOR_TAG_MTFTP_IP 1\r
35#define PXEBC_VENDOR_TAG_MTFTP_CPORT 2\r
36#define PXEBC_VENDOR_TAG_MTFTP_SPORT 3\r
37#define PXEBC_VENDOR_TAG_MTFTP_TIMEOUT 4\r
38#define PXEBC_VENDOR_TAG_MTFTP_DELAY 5\r
39#define PXEBC_VENDOR_TAG_DISCOVER_CTRL 6\r
40#define PXEBC_VENDOR_TAG_DISCOVER_MCAST 7\r
41#define PXEBC_VENDOR_TAG_BOOT_SERVERS 8\r
42#define PXEBC_VENDOR_TAG_BOOT_MENU 9\r
43#define PXEBC_VENDOR_TAG_MENU_PROMPT 10\r
44#define PXEBC_VENDOR_TAG_MCAST_ALLOC 11\r
45#define PXEBC_VENDOR_TAG_CREDENTIAL_TYPES 12\r
46#define PXEBC_VENDOR_TAG_BOOT_ITEM 71\r
47\r
48#define PXEBC_BOOT_REQUEST_TIMEOUT 1\r
49#define PXEBC_BOOT_REQUEST_RETRIES 4\r
50\r
51#define PXEBC_DHCP4_OVERLOAD_FILE 1\r
52#define PXEBC_DHCP4_OVERLOAD_SERVER_NAME 2\r
53\r
54\r
55//\r
56// The array index of the DHCP4 option tag interested\r
57//\r
58#define PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN 0\r
59#define PXEBC_DHCP4_TAG_INDEX_VENDOR 1\r
60#define PXEBC_DHCP4_TAG_INDEX_OVERLOAD 2\r
61#define PXEBC_DHCP4_TAG_INDEX_MSG_TYPE 3\r
62#define PXEBC_DHCP4_TAG_INDEX_SERVER_ID 4\r
63#define PXEBC_DHCP4_TAG_INDEX_CLASS_ID 5\r
64#define PXEBC_DHCP4_TAG_INDEX_BOOTFILE 6\r
65#define PXEBC_DHCP4_TAG_INDEX_MAX 7\r
66\r
67//\r
68// Dhcp4 and Dhcp6 share this definition, and corresponding\r
69// relatioinship is as follows:\r
70//\r
71// Dhcp4Discover <> Dhcp6Solicit\r
72// Dhcp4Offer <> Dhcp6Advertise\r
73// Dhcp4Request <> Dhcp6Request\r
74// Dhcp4Ack <> DHcp6Reply\r
75//\r
76typedef enum {\r
77 PxeOfferTypeDhcpOnly,\r
78 PxeOfferTypeDhcpPxe10,\r
79 PxeOfferTypeDhcpWfm11a,\r
80 PxeOfferTypeDhcpBinl,\r
81 PxeOfferTypeProxyPxe10,\r
82 PxeOfferTypeProxyWfm11a,\r
83 PxeOfferTypeProxyBinl,\r
84 PxeOfferTypeBootp,\r
85 PxeOfferTypeMax\r
86} PXEBC_OFFER_TYPE;\r
87\r
88#define BIT(x) (1 << x)\r
89#define CTRL(x) (0x1F & (x))\r
90#define DEFAULT_CLASS_ID_DATA "PXEClient:Arch:xxxxx:UNDI:003000"\r
91#define DEFAULT_UNDI_TYPE 1\r
92#define DEFAULT_UNDI_MAJOR 3\r
93#define DEFAULT_UNDI_MINOR 0\r
94\r
95#define MTFTP_VENDOR_OPTION_BIT_MAP \\r
96 (BIT (PXEBC_VENDOR_TAG_MTFTP_IP) | \\r
97 BIT (PXEBC_VENDOR_TAG_MTFTP_CPORT) | \\r
98 BIT (PXEBC_VENDOR_TAG_MTFTP_SPORT) | \\r
99 BIT (PXEBC_VENDOR_TAG_MTFTP_TIMEOUT) | \\r
100 BIT (PXEBC_VENDOR_TAG_MTFTP_DELAY))\r
101\r
102#define DISCOVER_VENDOR_OPTION_BIT_MAP \\r
103 (BIT (PXEBC_VENDOR_TAG_DISCOVER_CTRL) | \\r
104 BIT (PXEBC_VENDOR_TAG_DISCOVER_MCAST) | \\r
105 BIT (PXEBC_VENDOR_TAG_BOOT_SERVERS) | \\r
106 BIT (PXEBC_VENDOR_TAG_BOOT_MENU) | \\r
107 BIT (PXEBC_VENDOR_TAG_MENU_PROMPT))\r
108\r
109#define IS_VALID_BOOT_SERVERS(x) \\r
110 ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_BOOT_SERVERS)) \\r
111 == BIT (PXEBC_VENDOR_TAG_BOOT_SERVERS)) \r
112\r
113#define IS_VALID_BOOT_PROMPT(x) \\r
114 ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_MENU_PROMPT)) \\r
115 == BIT (PXEBC_VENDOR_TAG_MENU_PROMPT))\r
116\r
117#define IS_VALID_BOOT_MENU(x) \\r
118 ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_BOOT_MENU)) \\r
119 == BIT (PXEBC_VENDOR_TAG_BOOT_MENU))\r
120\r
121#define IS_VALID_MTFTP_VENDOR_OPTION(x) \\r
122 (((UINT32) ((x)[0]) & MTFTP_VENDOR_OPTION_BIT_MAP) \\r
123 == MTFTP_VENDOR_OPTION_BIT_MAP)\r
124\r
125#define IS_VALID_DISCOVER_VENDOR_OPTION(x) \\r
126 (((UINT32) ((x)[0]) & DISCOVER_VENDOR_OPTION_BIT_MAP) != 0)\r
127\r
128#define IS_VALID_CREDENTIAL_VENDOR_OPTION(x) \\r
129 (((UINT32) ((x)[0]) & BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES)) \\r
130 == BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES))\r
131\r
132#define IS_VALID_BOOTITEM_VENDOR_OPTION(x) \\r
133 (((UINT32) ((x)[PXEBC_VENDOR_TAG_BOOT_ITEM / 32]) & \\r
134 BIT (PXEBC_VENDOR_TAG_BOOT_ITEM % 32)) \\r
135 == BIT (PXEBC_VENDOR_TAG_BOOT_ITEM % 32))\r
136\r
137#define SET_VENDOR_OPTION_BIT_MAP(x, y) \\r
138 (*(x + ((y) / 32)) = (UINT32) ((UINT32) ((x)[(y) / 32]) | BIT ((y) % 32)))\r
139\r
140#define GET_NEXT_DHCP_OPTION(Opt) \\r
141 (EFI_DHCP4_PACKET_OPTION *) ((UINT8 *) (Opt) + \\r
142 sizeof (EFI_DHCP4_PACKET_OPTION) + (Opt)->Length - 1)\r
143\r
144#define GET_OPTION_BUFFER_LEN(Pkt) \\r
145 ((Pkt)->Length - sizeof (EFI_DHCP4_HEADER) - 4)\r
146\r
147#define GET_NEXT_BOOT_SVR_ENTRY(Ent) \\r
148 (PXEBC_BOOT_SVR_ENTRY *) ((UINT8 *) Ent + sizeof (*(Ent)) + \\r
149 ((Ent)->IpCnt - 1) * sizeof (EFI_IPv4_ADDRESS))\r
150\r
151#define IS_PROXY_DHCP_OFFER(Offer) \\r
152 EFI_IP4_EQUAL (&(Offer)->Dhcp4.Header.YourAddr, &mZeroIp4Addr)\r
153\r
154#define IS_DISABLE_BCAST_DISCOVER(x) \\r
155 (((x) & BIT (0)) == BIT (0))\r
156\r
157#define IS_DISABLE_MCAST_DISCOVER(x) \\r
158 (((x) & BIT (1)) == BIT (1))\r
159\r
160#define IS_ENABLE_USE_SERVER_LIST(x) \\r
161 (((x) & BIT (2)) == BIT (2))\r
162\r
163#define IS_DISABLE_PROMPT_MENU(x) \\r
164 (((x) & BIT (3)) == BIT (3))\r
165\r
166\r
167#pragma pack(1)\r
168typedef struct {\r
169 UINT8 ParaList[135];\r
170} PXEBC_DHCP4_OPTION_PARA;\r
171\r
172typedef struct {\r
173 UINT16 Size;\r
174} PXEBC_DHCP4_OPTION_MAX_MESG_SIZE;\r
175\r
176typedef struct {\r
177 UINT8 Type;\r
178 UINT8 MajorVer;\r
179 UINT8 MinorVer;\r
180} PXEBC_DHCP4_OPTION_UNDI;\r
181\r
182typedef struct {\r
183 UINT8 Type;\r
184} PXEBC_DHCP4_OPTION_MESG;\r
185\r
186typedef struct {\r
187 UINT16 Type;\r
188} PXEBC_DHCP4_OPTION_ARCH;\r
189\r
190typedef struct {\r
191 UINT8 ClassIdentifier[10];\r
192 UINT8 ArchitecturePrefix[5];\r
193 UINT8 ArchitectureType[5];\r
194 UINT8 Lit3[1];\r
195 UINT8 InterfaceName[4];\r
196 UINT8 Lit4[1];\r
197 UINT8 UndiMajor[3];\r
198 UINT8 UndiMinor[3];\r
199} PXEBC_DHCP4_OPTION_CLID;\r
200\r
201typedef struct {\r
202 UINT8 Type;\r
203 UINT8 Guid[16];\r
204} PXEBC_DHCP4_OPTION_UUID;\r
205\r
206typedef struct {\r
207 UINT16 Type;\r
208 UINT16 Layer;\r
209} PXEBC_OPTION_BOOT_ITEM;\r
210\r
211#pragma pack()\r
212\r
213typedef union {\r
214 PXEBC_DHCP4_OPTION_PARA *Para;\r
215 PXEBC_DHCP4_OPTION_UNDI *Undi;\r
216 PXEBC_DHCP4_OPTION_ARCH *Arch;\r
217 PXEBC_DHCP4_OPTION_CLID *Clid;\r
218 PXEBC_DHCP4_OPTION_UUID *Uuid;\r
219 PXEBC_DHCP4_OPTION_MESG *Mesg;\r
220 PXEBC_DHCP4_OPTION_MAX_MESG_SIZE *MaxMesgSize;\r
221} PXEBC_DHCP4_OPTION_ENTRY;\r
222\r
223#pragma pack(1)\r
224typedef struct {\r
225 UINT16 Type;\r
226 UINT8 IpCnt;\r
227 EFI_IPv4_ADDRESS IpAddr[1];\r
228} PXEBC_BOOT_SVR_ENTRY;\r
229\r
230typedef struct {\r
231 UINT16 Type;\r
232 UINT8 DescLen;\r
233 UINT8 DescStr[1];\r
234} PXEBC_BOOT_MENU_ENTRY;\r
235\r
236typedef struct {\r
237 UINT8 Timeout;\r
238 UINT8 Prompt[1];\r
239} PXEBC_MENU_PROMPT;\r
240#pragma pack()\r
241\r
242typedef struct {\r
243 UINT32 BitMap[8];\r
244 EFI_IPv4_ADDRESS MtftpIp;\r
245 UINT16 MtftpCPort;\r
246 UINT16 MtftpSPort;\r
247 UINT8 MtftpTimeout;\r
248 UINT8 MtftpDelay;\r
249 UINT8 DiscoverCtrl;\r
250 EFI_IPv4_ADDRESS DiscoverMcastIp;\r
251 EFI_IPv4_ADDRESS McastIpBase;\r
252 UINT16 McastIpBlock;\r
253 UINT16 McastIpRange;\r
254 UINT16 BootSrvType;\r
255 UINT16 BootSrvLayer;\r
256 PXEBC_BOOT_SVR_ENTRY *BootSvr;\r
257 UINT8 BootSvrLen;\r
258 PXEBC_BOOT_MENU_ENTRY *BootMenu;\r
259 UINT8 BootMenuLen;\r
260 PXEBC_MENU_PROMPT *MenuPrompt;\r
261 UINT8 MenuPromptLen;\r
262 UINT32 *CredType;\r
263 UINT8 CredTypeLen;\r
264} PXEBC_VENDOR_OPTION;\r
265\r
266#define PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE (OFFSET_OF (EFI_DHCP4_PACKET, Dhcp4) + PXEBC_DHCP4_PACKET_MAX_SIZE)\r
267\r
268typedef union {\r
269 EFI_DHCP4_PACKET Offer;\r
270 EFI_DHCP4_PACKET Ack;\r
271 UINT8 Buffer[PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE];\r
272} PXEBC_DHCP4_PACKET;\r
273\r
274typedef struct {\r
275 PXEBC_DHCP4_PACKET Packet;\r
276 PXEBC_OFFER_TYPE OfferType;\r
277 EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_TAG_INDEX_MAX];\r
278 PXEBC_VENDOR_OPTION VendorOpt;\r
279} PXEBC_DHCP4_PACKET_CACHE;\r
280\r
281\r
282/**\r
283 Create a template DHCPv4 packet as a seed.\r
284\r
285 @param[out] Seed Pointer to the seed packet.\r
286 @param[in] Udp4 Pointer to EFI_UDP4_PROTOCOL.\r
287\r
288**/\r
289VOID\r
290PxeBcSeedDhcp4Packet (\r
291 OUT EFI_DHCP4_PACKET *Seed,\r
292 IN EFI_UDP4_PROTOCOL *Udp4\r
293 );\r
294\r
295\r
296/**\r
297 Parse the cached DHCPv4 packet, including all the options.\r
298\r
299 @param[in] Cache4 Pointer to cached DHCPv4 packet.\r
300\r
301 @retval EFI_SUCCESS Parsed the DHCPv4 packet successfully.\r
302 @retval EFI_DEVICE_ERROR Failed to parse and invalid packet.\r
303\r
304**/\r
305EFI_STATUS\r
306PxeBcParseDhcp4Packet (\r
307 IN PXEBC_DHCP4_PACKET_CACHE *Cache4\r
308 );\r
309\r
310\r
311/**\r
312 Build and send out the request packet for the bootfile, and parse the reply.\r
313\r
314 @param[in] Private Pointer to PxeBc private data.\r
315 @param[in] Type PxeBc option boot item type.\r
316 @param[in] Layer Pointer to option boot item layer.\r
317 @param[in] UseBis Use BIS or not.\r
318 @param[in] DestIp Pointer to the server address.\r
319 @param[in] IpCount The total count of the server address.\r
320 @param[in] SrvList Pointer to EFI_PXE_BASE_CODE_SRVLIST.\r
321\r
322 @retval EFI_SUCCESS Successfully discovered boot file.\r
323 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource.\r
324 @retval EFI_NOT_FOUND Can't get the PXE reply packet.\r
325 @retval Others Failed to discover boot file.\r
326\r
327**/\r
328EFI_STATUS\r
329PxeBcDhcp4Discover (\r
330 IN PXEBC_PRIVATE_DATA *Private,\r
331 IN UINT16 Type,\r
332 IN UINT16 *Layer,\r
333 IN BOOLEAN UseBis,\r
334 IN EFI_IP_ADDRESS *DestIp,\r
335 IN UINT16 IpCount,\r
336 IN EFI_PXE_BASE_CODE_SRVLIST *SrvList\r
337 );\r
338\r
339/**\r
340 Switch the Ip4 policy to static.\r
341\r
342 @param[in] Private The pointer to PXEBC_PRIVATE_DATA.\r
343\r
344 @retval EFI_SUCCESS The policy is already configured to static.\r
345 @retval Others Other error as indicated..\r
346\r
347**/\r
348EFI_STATUS\r
349PxeBcSetIp4Policy ( \r
350 IN PXEBC_PRIVATE_DATA *Private\r
351 );\r
352\r
353\r
354/**\r
355 Start the D.O.R.A DHCPv4 process to acquire the IPv4 address and other PXE boot information.\r
356\r
357 @param[in] Private Pointer to PxeBc private data.\r
358 @param[in] Dhcp4 Pointer to the EFI_DHCP4_PROTOCOL\r
359\r
360 @retval EFI_SUCCESS The D.O.R.A process successfully finished.\r
361 @retval Others Failed to finish the D.O.R.A process.\r
362\r
363**/\r
364EFI_STATUS\r
365PxeBcDhcp4Dora (\r
366 IN PXEBC_PRIVATE_DATA *Private,\r
367 IN EFI_DHCP4_PROTOCOL *Dhcp4\r
368 );\r
369\r
370#endif\r
371\r