1. Import UEFI PxeBc module in MdeModulePkg
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcDhcp.h
1 /** @file
2
3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 PxeBcDhcp.h
15
16 Abstract:
17
18 Dhcp and Discover routines for PxeBc
19
20
21 **/
22
23 #ifndef __EFI_PXEBC_DHCP_H__
24 #define __EFI_PXEBC_DHCP_H__
25
26 enum {
27 PXEBC_DHCP4_MAX_OPTION_NUM = 16,
28 PXEBC_DHCP4_MAX_OPTION_SIZE = 312,
29 PXEBC_DHCP4_MAX_PACKET_SIZE = 1472,
30
31 PXEBC_DHCP4_S_PORT = 67,
32 PXEBC_DHCP4_C_PORT = 68,
33 PXEBC_BS_DOWNLOAD_PORT = 69,
34 PXEBC_BS_DISCOVER_PORT = 4011,
35
36 PXEBC_DHCP4_OPCODE_REQUEST = 1,
37 PXEBC_DHCP4_OPCODE_REPLY = 2,
38 PXEBC_DHCP4_MSG_TYPE_REQUEST = 3,
39 PXEBC_DHCP4_MAGIC = 0x63538263, // network byte order
40 //
41 // Dhcp Options
42 //
43 PXEBC_DHCP4_TAG_PAD = 0, // Pad Option
44 PXEBC_DHCP4_TAG_EOP = 255, // End Option
45 PXEBC_DHCP4_TAG_NETMASK = 1, // Subnet Mask
46 PXEBC_DHCP4_TAG_TIME_OFFSET = 2, // Time Offset from UTC
47 PXEBC_DHCP4_TAG_ROUTER = 3, // Router option,
48 PXEBC_DHCP4_TAG_TIME_SERVER = 4, // Time Server
49 PXEBC_DHCP4_TAG_NAME_SERVER = 5, // Name Server
50 PXEBC_DHCP4_TAG_DNS_SERVER = 6, // Domain Name Server
51 PXEBC_DHCP4_TAG_HOSTNAME = 12, // Host Name
52 PXEBC_DHCP4_TAG_BOOTFILE_LEN = 13, // Boot File Size
53 PXEBC_DHCP4_TAG_DUMP = 14, // Merit Dump File
54 PXEBC_DHCP4_TAG_DOMAINNAME = 15, // Domain Name
55 PXEBC_DHCP4_TAG_ROOTPATH = 17, // Root path
56 PXEBC_DHCP4_TAG_EXTEND_PATH = 18, // Extensions Path
57 PXEBC_DHCP4_TAG_EMTU = 22, // Maximum Datagram Reassembly Size
58 PXEBC_DHCP4_TAG_TTL = 23, // Default IP Time-to-live
59 PXEBC_DHCP4_TAG_BROADCAST = 28, // Broadcast Address
60 PXEBC_DHCP4_TAG_NIS_DOMAIN = 40, // Network Information Service Domain
61 PXEBC_DHCP4_TAG_NIS_SERVER = 41, // Network Information Servers
62 PXEBC_DHCP4_TAG_NTP_SERVER = 42, // Network Time Protocol Servers
63 PXEBC_DHCP4_TAG_VENDOR = 43, // Vendor Specific Information
64 PXEBC_DHCP4_TAG_REQUEST_IP = 50, // Requested IP Address
65 PXEBC_DHCP4_TAG_LEASE = 51, // IP Address Lease Time
66 PXEBC_DHCP4_TAG_OVERLOAD = 52, // Option Overload
67 PXEBC_DHCP4_TAG_MSG_TYPE = 53, // DHCP Message Type
68 PXEBC_DHCP4_TAG_SERVER_ID = 54, // Server Identifier
69 PXEBC_DHCP4_TAG_PARA_LIST = 55, // Parameter Request List
70 PXEBC_DHCP4_TAG_MAXMSG = 57, // Maximum DHCP Message Size
71 PXEBC_DHCP4_TAG_T1 = 58, // Renewal (T1) Time Value
72 PXEBC_DHCP4_TAG_T2 = 59, // Rebinding (T2) Time Value
73 PXEBC_DHCP4_TAG_CLASS_ID = 60, // Vendor class identifier
74 PXEBC_DHCP4_TAG_CLIENT_ID = 61, // Client-identifier
75 PXEBC_DHCP4_TAG_TFTP = 66, // TFTP server name
76 PXEBC_DHCP4_TAG_BOOTFILE = 67, // Bootfile name
77 PXEBC_PXE_DHCP4_TAG_ARCH = 93,
78 PXEBC_PXE_DHCP4_TAG_UNDI = 94,
79 PXEBC_PXE_DHCP4_TAG_UUID = 97,
80 //
81 // Sub-Options in Dhcp Vendor Option
82 //
83 PXEBC_VENDOR_TAG_MTFTP_IP = 1,
84 PXEBC_VENDOR_TAG_MTFTP_CPORT = 2,
85 PXEBC_VENDOR_TAG_MTFTP_SPORT = 3,
86 PXEBC_VENDOR_TAG_MTFTP_TIMEOUT = 4,
87 PXEBC_VENDOR_TAG_MTFTP_DELAY = 5,
88 PXEBC_VENDOR_TAG_DISCOVER_CTRL = 6,
89 PXEBC_VENDOR_TAG_DISCOVER_MCAST = 7,
90 PXEBC_VENDOR_TAG_BOOT_SERVERS = 8,
91 PXEBC_VENDOR_TAG_BOOT_MENU = 9,
92 PXEBC_VENDOR_TAG_MENU_PROMPT = 10,
93 PXEBC_VENDOR_TAG_MCAST_ALLOC = 11,
94 PXEBC_VENDOR_TAG_CREDENTIAL_TYPES = 12,
95 PXEBC_VENDOR_TAG_BOOT_ITEM = 71,
96
97 PXEBC_DHCP4_DISCOVER_INIT_TIMEOUT = 4,
98 PXEBC_DHCP4_DISCOVER_RETRIES = 4,
99
100 PXEBC_MAX_MENU_NUM = 24,
101 PXEBC_MAX_OFFER_NUM = 16,
102
103 PXEBC_BOOT_REQUEST_TIMEOUT = 1,
104 PXEBC_BOOT_REQUEST_RETRIES = 4,
105
106 PXEBC_DHCP4_OVERLOAD_FILE = 1,
107 PXEBC_DHCP4_OVERLOAD_SERVER_NAME = 2
108 };
109
110 //
111 // The array index of the DHCP4 option tag interested
112 //
113 enum {
114 PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN,
115 PXEBC_DHCP4_TAG_INDEX_VENDOR,
116 PXEBC_DHCP4_TAG_INDEX_OVERLOAD,
117 PXEBC_DHCP4_TAG_INDEX_MSG_TYPE,
118 PXEBC_DHCP4_TAG_INDEX_SERVER_ID,
119 PXEBC_DHCP4_TAG_INDEX_CLASS_ID,
120 PXEBC_DHCP4_TAG_INDEX_BOOTFILE,
121 PXEBC_DHCP4_TAG_INDEX_MAX
122 };
123
124 //
125 // The type of DHCP OFFER, arranged by priority, PXE10 has the highest priority.
126 //
127 enum {
128 DHCP4_PACKET_TYPE_PXE10,
129 DHCP4_PACKET_TYPE_WFM11A,
130 DHCP4_PACKET_TYPE_BINL,
131 DHCP4_PACKET_TYPE_DHCP_ONLY,
132 DHCP4_PACKET_TYPE_MAX,
133 DHCP4_PACKET_TYPE_BOOTP = DHCP4_PACKET_TYPE_MAX
134 };
135
136 #define BIT(x) (1 << x)
137 #define CTRL(x) (0x1F & (x))
138
139 //
140 // WfM11a options
141 //
142 #define MTFTP_VENDOR_OPTION_BIT_MAP (BIT (PXEBC_VENDOR_TAG_MTFTP_IP) | \
143 BIT (PXEBC_VENDOR_TAG_MTFTP_CPORT) | \
144 BIT (PXEBC_VENDOR_TAG_MTFTP_SPORT) | \
145 BIT (PXEBC_VENDOR_TAG_MTFTP_TIMEOUT) | \
146 BIT (PXEBC_VENDOR_TAG_MTFTP_DELAY))
147 //
148 // Discoverty options
149 //
150 #define DISCOVER_VENDOR_OPTION_BIT_MAP (BIT (PXEBC_VENDOR_TAG_DISCOVER_CTRL) | \
151 BIT (PXEBC_VENDOR_TAG_DISCOVER_MCAST) | \
152 BIT (PXEBC_VENDOR_TAG_BOOT_SERVERS) | \
153 BIT (PXEBC_VENDOR_TAG_BOOT_MENU) | \
154 BIT (PXEBC_VENDOR_TAG_MENU_PROMPT))
155
156 #define IS_VALID_BOOT_PROMPT(x) \
157 ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_MENU_PROMPT)) == BIT (PXEBC_VENDOR_TAG_MENU_PROMPT))
158
159 #define IS_VALID_BOOT_MENU(x) \
160 ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_BOOT_MENU)) == BIT (PXEBC_VENDOR_TAG_BOOT_MENU))
161
162 #define IS_VALID_MTFTP_VENDOR_OPTION(x) \
163 (((UINT32) ((x)[0]) & MTFTP_VENDOR_OPTION_BIT_MAP) == MTFTP_VENDOR_OPTION_BIT_MAP)
164
165 #define IS_VALID_DISCOVER_VENDOR_OPTION(x) (((UINT32) ((x)[0]) & DISCOVER_VENDOR_OPTION_BIT_MAP) != 0)
166
167 #define IS_VALID_CREDENTIAL_VENDOR_OPTION(x) \
168 (((UINT32) ((x)[0]) & BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES)) == BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES))
169
170 #define IS_VALID_BOOTITEM_VENDOR_OPTION(x) \
171 (((UINT32) ((x)[PXEBC_VENDOR_TAG_BOOT_ITEM / 32]) & BIT (PXEBC_VENDOR_TAG_BOOT_ITEM % 32)) \
172 == BIT (PXEBC_VENDOR_TAG_BOOT_ITEM % 32))
173
174 #define IS_DISABLE_BCAST_DISCOVER(x) (((x) & BIT (0)) == BIT (0))
175 #define IS_DISABLE_MCAST_DISCOVER(x) (((x) & BIT (1)) == BIT (1))
176 #define IS_ENABLE_USE_SERVER_LIST(x) (((x) & BIT (2)) == BIT (2))
177 #define IS_ENABLE_BOOT_FILE_NAME(x) (((x) & BIT (3)) == BIT (3))
178
179 #define SET_VENDOR_OPTION_BIT_MAP(x, y) ((UINT32) ((x)[(y) / 32]) = (UINT32) ((x)[(y) / 32]) | BIT ((y) % 32))
180
181 #pragma pack(1)
182 typedef struct {
183 UINT8 ParaList[135];
184 } PXEBC_DHCP4_OPTION_PARA;
185
186 typedef struct {
187 UINT16 Size;
188 } PXEBC_DHCP4_OPTION_MAX_MESG_SIZE;
189
190 typedef struct {
191 UINT8 Type;
192 UINT8 MajorVer;
193 UINT8 MinorVer;
194 } PXEBC_DHCP4_OPTION_UNDI;
195
196 typedef struct {
197 UINT8 Type;
198 } PXEBC_DHCP4_OPTION_MESG;
199
200 typedef struct {
201 UINT16 Type;
202 } PXEBC_DHCP4_OPTION_ARCH;
203
204 #define DEFAULT_CLASS_ID_DATA "PXEClient:Arch:?????:????:??????"
205
206 typedef struct {
207 UINT8 ClassIdentifier[10];
208 UINT8 ArchitecturePrefix[5];
209 UINT8 ArchitectureType[5];
210 UINT8 Lit3[1];
211 UINT8 InterfaceName[4];
212 UINT8 Lit4[1];
213 UINT8 UndiMajor[3];
214 UINT8 UndiMinor[3];
215 } PXEBC_DHCP4_OPTION_CLID;
216
217 typedef struct {
218 UINT8 Type;
219 UINT8 Guid[16];
220 } PXEBC_DHCP4_OPTION_UUID;
221
222 typedef struct {
223 UINT16 Type;
224 UINT16 Layer;
225 } PXEBC_OPTION_BOOT_ITEM;
226
227 #pragma pack()
228
229 typedef union {
230 PXEBC_DHCP4_OPTION_PARA *Para;
231 PXEBC_DHCP4_OPTION_UNDI *Undi;
232 PXEBC_DHCP4_OPTION_ARCH *Arch;
233 PXEBC_DHCP4_OPTION_CLID *Clid;
234 PXEBC_DHCP4_OPTION_UUID *Uuid;
235 PXEBC_DHCP4_OPTION_MESG *Mesg;
236 PXEBC_DHCP4_OPTION_MAX_MESG_SIZE *MaxMesgSize;
237 } PXEBC_DHCP4_OPTION_ENTRY;
238
239 typedef struct {
240 UINT16 Type;
241 UINT8 IpCnt;
242 EFI_IPv4_ADDRESS IpAddr[1];
243 } PXEBC_BOOT_SVR_ENTRY;
244
245 typedef struct {
246 UINT16 Type;
247 UINT8 DescLen;
248 UINT8 DescStr[1];
249 } PXEBC_BOOT_MENU_ENTRY;
250
251 typedef struct {
252 UINT8 Timeout;
253 UINT8 Prompt[1];
254 } PXEBC_MENU_PROMPT;
255
256 typedef struct {
257 UINT32 BitMap[8];
258 EFI_IPv4_ADDRESS MtftpIp;
259 UINT16 MtftpCPort;
260 UINT16 MtftpSPort;
261 UINT8 MtftpTimeout;
262 UINT8 MtftpDelay;
263 UINT8 DiscoverCtrl;
264 EFI_IPv4_ADDRESS DiscoverMcastIp;
265 EFI_IPv4_ADDRESS McastIpBase;
266 UINT16 McastIpBlock;
267 UINT16 McastIpRange;
268 UINT16 BootSrvType;
269 UINT16 BootSrvLayer;
270 PXEBC_BOOT_SVR_ENTRY *BootSvr;
271 UINT8 BootSvrLen;
272 PXEBC_BOOT_MENU_ENTRY *BootMenu;
273 UINT8 BootMenuLen;
274 PXEBC_MENU_PROMPT *MenuPrompt;
275 UINT8 MenuPromptLen;
276 UINT32 *CredType;
277 UINT8 CredTypeLen;
278 } PXEBC_VENDOR_OPTION;
279
280 #define PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE (EFI_FIELD_OFFSET (EFI_DHCP4_PACKET, Dhcp4) + PXEBC_DHCP4_MAX_PACKET_SIZE)
281
282 typedef struct {
283 union {
284 EFI_DHCP4_PACKET Offer;
285 EFI_DHCP4_PACKET Ack;
286 UINT8 Buffer[PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE];
287 } Packet;
288
289 BOOLEAN IsPxeOffer;
290 UINT8 OfferType;
291 EFI_DHCP4_PACKET_OPTION *Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_MAX];
292 PXEBC_VENDOR_OPTION PxeVendorOption;
293 } PXEBC_CACHED_DHCP4_PACKET;
294
295 #define GET_NEXT_DHCP_OPTION(Opt) \
296 (EFI_DHCP4_PACKET_OPTION *) ((UINT8 *) (Opt) + sizeof (EFI_DHCP4_PACKET_OPTION) + (Opt)->Length - 1)
297
298 #define GET_OPTION_BUFFER_LEN(Pkt) ((Pkt)->Length - sizeof (EFI_DHCP4_HEADER) - 4)
299 #define IS_PROXY_DHCP_OFFER(Offer) EFI_IP4_EQUAL (&((Offer)->Dhcp4.Header.YourAddr), &mZeroIp4Addr)
300
301 #define GET_NEXT_BOOT_SVR_ENTRY(Ent) \
302 (PXEBC_BOOT_SVR_ENTRY *) ((UINT8 *) Ent + sizeof (*(Ent)) + ((Ent)->IpCnt - 1) * sizeof (EFI_IPv4_ADDRESS))
303
304 VOID
305 PxeBcInitSeedPacket (
306 IN EFI_DHCP4_PACKET *Seed,
307 IN EFI_UDP4_PROTOCOL *Udp4
308 )
309 /*++
310
311 Routine Description:
312
313 GC_NOTO: Add function description
314
315 Arguments:
316
317 Seed - GC_NOTO: add argument description
318 Udp4 - GC_NOTO: add argument description
319
320 Returns:
321
322 GC_NOTO: add return values
323
324 --*/
325 ;
326
327
328 /**
329 GC_NOTO: Add function description
330
331 @param CachedPacket GC_NOTO: add argument description
332
333 @return GC_NOTO: add return values
334
335 **/
336 BOOLEAN
337 PxeBcParseCachedDhcpPacket (
338 IN PXEBC_CACHED_DHCP4_PACKET *CachedPacket
339 )
340 ;
341
342
343 /**
344 GC_NOTO: Add function description
345
346 @param Private GC_NOTO: add argument description
347
348 @return GC_NOTO: add return values
349
350 **/
351 EFI_STATUS
352 PxeBcCheckSelectedOffer (
353 IN PXEBC_PRIVATE_DATA *Private
354 )
355 ;
356
357
358 /**
359 GC_NOTO: Add function description
360
361 @param This GC_NOTO: add argument description
362 @param Context GC_NOTO: add argument description
363 @param CurrentState GC_NOTO: add argument description
364 @param Dhcp4Event GC_NOTO: add argument description
365 @param Packet GC_NOTO: add argument description
366 @param NewPacket GC_NOTO: add argument description
367
368 @return GC_NOTO: add return values
369
370 **/
371 EFI_STATUS
372 PxeBcDhcpCallBack (
373 IN EFI_DHCP4_PROTOCOL * This,
374 IN VOID *Context,
375 IN EFI_DHCP4_STATE CurrentState,
376 IN EFI_DHCP4_EVENT Dhcp4Event,
377 IN EFI_DHCP4_PACKET * Packet OPTIONAL,
378 OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL
379 )
380 ;
381
382
383 /**
384 GC_NOTO: Add function description
385
386 @param Private GC_NOTO: add argument description
387 @param Type GC_NOTO: add argument description
388 @param Layer GC_NOTO: add argument description
389 @param UseBis GC_NOTO: add argument description
390 @param DestIp GC_NOTO: add argument description
391 @param IpCount GC_NOTO: add argument description
392 @param SrvList GC_NOTO: add argument description
393 @param IsDiscv GC_NOTO: add argument description
394 @param Reply GC_NOTO: add argument description
395
396 @return GC_NOTO: add return values
397
398 **/
399 EFI_STATUS
400 PxeBcDiscvBootService (
401 IN PXEBC_PRIVATE_DATA * Private,
402 IN UINT16 Type,
403 IN UINT16 *Layer,
404 IN BOOLEAN UseBis,
405 IN EFI_IP_ADDRESS * DestIp,
406 IN UINT16 IpCount,
407 IN EFI_PXE_BASE_CODE_SRVLIST * SrvList,
408 IN BOOLEAN IsDiscv,
409 OUT EFI_DHCP4_PACKET * Reply OPTIONAL
410 )
411 ;
412
413
414 /**
415 GC_NOTO: Add function description
416
417 @param Private GC_NOTO: add argument description
418 @param OptList GC_NOTO: add argument description
419 @param IsDhcpDiscover GC_NOTO: add argument description
420
421 @return GC_NOTO: add return values
422
423 **/
424 UINT32
425 PxeBcBuildDhcpOptions (
426 IN PXEBC_PRIVATE_DATA *Private,
427 IN EFI_DHCP4_PACKET_OPTION **OptList,
428 IN BOOLEAN IsDhcpDiscover
429 )
430 ;
431
432
433 /**
434 GC_NOTO: Add function description
435
436 @param OptList GC_NOTO: add argument description
437 @param Type GC_NOTO: add argument description
438 @param Layer GC_NOTO: add argument description
439 @param OptLen GC_NOTO: add argument description
440
441 @return GC_NOTO: add return values
442
443 **/
444 VOID
445 PxeBcCreateBootOptions (
446 IN EFI_DHCP4_PACKET_OPTION *OptList,
447 IN UINT16 Type,
448 IN UINT16 *Layer,
449 OUT UINT32 *OptLen
450 )
451 ;
452
453
454 /**
455 GC_NOTO: Add function description
456
457 @param Buffer GC_NOTO: add argument description
458 @param Length GC_NOTO: add argument description
459 @param OptTag GC_NOTO: add argument description
460
461 @return GC_NOTO: add return values
462
463 **/
464 EFI_DHCP4_PACKET_OPTION *
465 PxeBcParseExtendOptions (
466 IN UINT8 *Buffer,
467 IN UINT32 Length,
468 IN UINT8 OptTag
469 )
470 ;
471
472
473 /**
474 GC_NOTO: Add function description
475
476 @param Dhcp4Option GC_NOTO: add argument description
477 @param VendorOption GC_NOTO: add argument description
478
479 @return GC_NOTO: add return values
480
481 **/
482 BOOLEAN
483 PxeBcParseVendorOptions (
484 IN EFI_DHCP4_PACKET_OPTION *Dhcp4Option,
485 IN PXEBC_VENDOR_OPTION *VendorOption
486 )
487 ;
488
489
490 /**
491 GC_NOTO: Add function description
492
493 @param Private GC_NOTO: add argument description
494 @param Info GC_NOTO: add argument description
495 @param Type GC_NOTO: add argument description
496
497 @return GC_NOTO: add return values
498
499 **/
500 EFI_STATUS
501 PxeBcSelectBootServers (
502 IN PXEBC_PRIVATE_DATA *Private,
503 OUT EFI_PXE_BASE_CODE_DISCOVER_INFO **Info,
504 OUT UINT16 *Type
505 )
506 ;
507
508
509 /**
510 GC_NOTO: Add function description
511
512 @param Private GC_NOTO: add argument description
513
514 @return GC_NOTO: add return values
515
516 **/
517 EFI_STATUS
518 PxeBcSelectBootPrompt (
519 IN PXEBC_PRIVATE_DATA *Private
520 )
521 ;
522
523
524 /**
525 GC_NOTO: Add function description
526
527 @param Private GC_NOTO: add argument description
528 @param Type GC_NOTO: add argument description
529
530 @return GC_NOTO: add return values
531
532 **/
533 EFI_STATUS
534 PxeBcSelectBootMenu (
535 IN PXEBC_PRIVATE_DATA *Private,
536 OUT UINT16 *Type,
537 IN BOOLEAN UseDefaultItem
538 )
539 ;
540
541 #endif
542