2 Dhcp and Discover routines for PxeBc.
4 Copyright (c) 2007, Intel Corporation.<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef __EFI_PXEBC_DHCP_H__
16 #define __EFI_PXEBC_DHCP_H__
19 PXEBC_DHCP4_MAX_OPTION_NUM
= 16,
20 PXEBC_DHCP4_MAX_OPTION_SIZE
= 312,
21 PXEBC_DHCP4_MAX_PACKET_SIZE
= 1472,
23 PXEBC_DHCP4_S_PORT
= 67,
24 PXEBC_DHCP4_C_PORT
= 68,
25 PXEBC_BS_DOWNLOAD_PORT
= 69,
26 PXEBC_BS_DISCOVER_PORT
= 4011,
28 PXEBC_DHCP4_OPCODE_REQUEST
= 1,
29 PXEBC_DHCP4_OPCODE_REPLY
= 2,
30 PXEBC_DHCP4_MSG_TYPE_REQUEST
= 3,
31 PXEBC_DHCP4_MAGIC
= 0x63538263, // network byte order
35 PXEBC_DHCP4_TAG_PAD
= 0, // Pad Option
36 PXEBC_DHCP4_TAG_EOP
= 255, // End Option
37 PXEBC_DHCP4_TAG_NETMASK
= 1, // Subnet Mask
38 PXEBC_DHCP4_TAG_TIME_OFFSET
= 2, // Time Offset from UTC
39 PXEBC_DHCP4_TAG_ROUTER
= 3, // Router option,
40 PXEBC_DHCP4_TAG_TIME_SERVER
= 4, // Time Server
41 PXEBC_DHCP4_TAG_NAME_SERVER
= 5, // Name Server
42 PXEBC_DHCP4_TAG_DNS_SERVER
= 6, // Domain Name Server
43 PXEBC_DHCP4_TAG_HOSTNAME
= 12, // Host Name
44 PXEBC_DHCP4_TAG_BOOTFILE_LEN
= 13, // Boot File Size
45 PXEBC_DHCP4_TAG_DUMP
= 14, // Merit Dump File
46 PXEBC_DHCP4_TAG_DOMAINNAME
= 15, // Domain Name
47 PXEBC_DHCP4_TAG_ROOTPATH
= 17, // Root path
48 PXEBC_DHCP4_TAG_EXTEND_PATH
= 18, // Extensions Path
49 PXEBC_DHCP4_TAG_EMTU
= 22, // Maximum Datagram Reassembly Size
50 PXEBC_DHCP4_TAG_TTL
= 23, // Default IP Time-to-live
51 PXEBC_DHCP4_TAG_BROADCAST
= 28, // Broadcast Address
52 PXEBC_DHCP4_TAG_NIS_DOMAIN
= 40, // Network Information Service Domain
53 PXEBC_DHCP4_TAG_NIS_SERVER
= 41, // Network Information Servers
54 PXEBC_DHCP4_TAG_NTP_SERVER
= 42, // Network Time Protocol Servers
55 PXEBC_DHCP4_TAG_VENDOR
= 43, // Vendor Specific Information
56 PXEBC_DHCP4_TAG_REQUEST_IP
= 50, // Requested IP Address
57 PXEBC_DHCP4_TAG_LEASE
= 51, // IP Address Lease Time
58 PXEBC_DHCP4_TAG_OVERLOAD
= 52, // Option Overload
59 PXEBC_DHCP4_TAG_MSG_TYPE
= 53, // DHCP Message Type
60 PXEBC_DHCP4_TAG_SERVER_ID
= 54, // Server Identifier
61 PXEBC_DHCP4_TAG_PARA_LIST
= 55, // Parameter Request List
62 PXEBC_DHCP4_TAG_MAXMSG
= 57, // Maximum DHCP Message Size
63 PXEBC_DHCP4_TAG_T1
= 58, // Renewal (T1) Time Value
64 PXEBC_DHCP4_TAG_T2
= 59, // Rebinding (T2) Time Value
65 PXEBC_DHCP4_TAG_CLASS_ID
= 60, // Vendor class identifier
66 PXEBC_DHCP4_TAG_CLIENT_ID
= 61, // Client-identifier
67 PXEBC_DHCP4_TAG_TFTP
= 66, // TFTP server name
68 PXEBC_DHCP4_TAG_BOOTFILE
= 67, // Bootfile name
69 PXEBC_PXE_DHCP4_TAG_ARCH
= 93,
70 PXEBC_PXE_DHCP4_TAG_UNDI
= 94,
71 PXEBC_PXE_DHCP4_TAG_UUID
= 97,
73 // Sub-Options in Dhcp Vendor Option
75 PXEBC_VENDOR_TAG_MTFTP_IP
= 1,
76 PXEBC_VENDOR_TAG_MTFTP_CPORT
= 2,
77 PXEBC_VENDOR_TAG_MTFTP_SPORT
= 3,
78 PXEBC_VENDOR_TAG_MTFTP_TIMEOUT
= 4,
79 PXEBC_VENDOR_TAG_MTFTP_DELAY
= 5,
80 PXEBC_VENDOR_TAG_DISCOVER_CTRL
= 6,
81 PXEBC_VENDOR_TAG_DISCOVER_MCAST
= 7,
82 PXEBC_VENDOR_TAG_BOOT_SERVERS
= 8,
83 PXEBC_VENDOR_TAG_BOOT_MENU
= 9,
84 PXEBC_VENDOR_TAG_MENU_PROMPT
= 10,
85 PXEBC_VENDOR_TAG_MCAST_ALLOC
= 11,
86 PXEBC_VENDOR_TAG_CREDENTIAL_TYPES
= 12,
87 PXEBC_VENDOR_TAG_BOOT_ITEM
= 71,
89 PXEBC_DHCP4_DISCOVER_INIT_TIMEOUT
= 4,
90 PXEBC_DHCP4_DISCOVER_RETRIES
= 4,
92 PXEBC_MAX_MENU_NUM
= 24,
93 PXEBC_MAX_OFFER_NUM
= 16,
95 PXEBC_BOOT_REQUEST_TIMEOUT
= 1,
96 PXEBC_BOOT_REQUEST_RETRIES
= 4,
98 PXEBC_DHCP4_OVERLOAD_FILE
= 1,
99 PXEBC_DHCP4_OVERLOAD_SERVER_NAME
= 2
103 // The array index of the DHCP4 option tag interested
106 PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN
,
107 PXEBC_DHCP4_TAG_INDEX_VENDOR
,
108 PXEBC_DHCP4_TAG_INDEX_OVERLOAD
,
109 PXEBC_DHCP4_TAG_INDEX_MSG_TYPE
,
110 PXEBC_DHCP4_TAG_INDEX_SERVER_ID
,
111 PXEBC_DHCP4_TAG_INDEX_CLASS_ID
,
112 PXEBC_DHCP4_TAG_INDEX_BOOTFILE
,
113 PXEBC_DHCP4_TAG_INDEX_MAX
114 } PXEBC_DHCP4_TAG_INDEX_ENUM_TYPES
;
117 // The type of DHCP OFFER, arranged by priority, PXE10 has the highest priority.
120 DHCP4_PACKET_TYPE_PXE10
,
121 DHCP4_PACKET_TYPE_WFM11A
,
122 DHCP4_PACKET_TYPE_BINL
,
123 DHCP4_PACKET_TYPE_DHCP_ONLY
,
124 DHCP4_PACKET_TYPE_MAX
,
125 DHCP4_PACKET_TYPE_BOOTP
= DHCP4_PACKET_TYPE_MAX
126 } DHCP4_PACKET_TYPE_ENUM_TYPES
;
128 #define BIT(x) (1 << x)
129 #define CTRL(x) (0x1F & (x))
134 #define MTFTP_VENDOR_OPTION_BIT_MAP (BIT (PXEBC_VENDOR_TAG_MTFTP_IP) | \
135 BIT (PXEBC_VENDOR_TAG_MTFTP_CPORT) | \
136 BIT (PXEBC_VENDOR_TAG_MTFTP_SPORT) | \
137 BIT (PXEBC_VENDOR_TAG_MTFTP_TIMEOUT) | \
138 BIT (PXEBC_VENDOR_TAG_MTFTP_DELAY))
140 // Discoverty options
142 #define DISCOVER_VENDOR_OPTION_BIT_MAP (BIT (PXEBC_VENDOR_TAG_DISCOVER_CTRL) | \
143 BIT (PXEBC_VENDOR_TAG_DISCOVER_MCAST) | \
144 BIT (PXEBC_VENDOR_TAG_BOOT_SERVERS) | \
145 BIT (PXEBC_VENDOR_TAG_BOOT_MENU) | \
146 BIT (PXEBC_VENDOR_TAG_MENU_PROMPT))
148 #define IS_VALID_BOOT_PROMPT(x) \
149 ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_MENU_PROMPT)) == BIT (PXEBC_VENDOR_TAG_MENU_PROMPT))
151 #define IS_VALID_BOOT_MENU(x) \
152 ((((x)[0]) & BIT (PXEBC_VENDOR_TAG_BOOT_MENU)) == BIT (PXEBC_VENDOR_TAG_BOOT_MENU))
154 #define IS_VALID_MTFTP_VENDOR_OPTION(x) \
155 (((UINT32) ((x)[0]) & MTFTP_VENDOR_OPTION_BIT_MAP) == MTFTP_VENDOR_OPTION_BIT_MAP)
157 #define IS_VALID_DISCOVER_VENDOR_OPTION(x) (((UINT32) ((x)[0]) & DISCOVER_VENDOR_OPTION_BIT_MAP) != 0)
159 #define IS_VALID_CREDENTIAL_VENDOR_OPTION(x) \
160 (((UINT32) ((x)[0]) & BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES)) == BIT (PXEBC_VENDOR_TAG_CREDENTIAL_TYPES))
162 #define IS_VALID_BOOTITEM_VENDOR_OPTION(x) \
163 (((UINT32) ((x)[PXEBC_VENDOR_TAG_BOOT_ITEM / 32]) & BIT (PXEBC_VENDOR_TAG_BOOT_ITEM % 32)) \
164 == BIT (PXEBC_VENDOR_TAG_BOOT_ITEM % 32))
166 #define IS_DISABLE_BCAST_DISCOVER(x) (((x) & BIT (0)) == BIT (0))
167 #define IS_DISABLE_MCAST_DISCOVER(x) (((x) & BIT (1)) == BIT (1))
168 #define IS_ENABLE_USE_SERVER_LIST(x) (((x) & BIT (2)) == BIT (2))
169 #define IS_ENABLE_BOOT_FILE_NAME(x) (((x) & BIT (3)) == BIT (3))
171 #define SET_VENDOR_OPTION_BIT_MAP(x, y) (((x)[(y) / 32]) = (UINT32) ((x)[(y) / 32]) | BIT ((y) % 32))
176 } PXEBC_DHCP4_OPTION_PARA
;
180 } PXEBC_DHCP4_OPTION_MAX_MESG_SIZE
;
186 } PXEBC_DHCP4_OPTION_UNDI
;
190 } PXEBC_DHCP4_OPTION_MESG
;
194 } PXEBC_DHCP4_OPTION_ARCH
;
196 #define DEFAULT_CLASS_ID_DATA "PXEClient:Arch:?????:????:??????"
199 UINT8 ClassIdentifier
[10];
200 UINT8 ArchitecturePrefix
[5];
201 UINT8 ArchitectureType
[5];
203 UINT8 InterfaceName
[4];
207 } PXEBC_DHCP4_OPTION_CLID
;
212 } PXEBC_DHCP4_OPTION_UUID
;
217 } PXEBC_OPTION_BOOT_ITEM
;
222 PXEBC_DHCP4_OPTION_PARA
*Para
;
223 PXEBC_DHCP4_OPTION_UNDI
*Undi
;
224 PXEBC_DHCP4_OPTION_ARCH
*Arch
;
225 PXEBC_DHCP4_OPTION_CLID
*Clid
;
226 PXEBC_DHCP4_OPTION_UUID
*Uuid
;
227 PXEBC_DHCP4_OPTION_MESG
*Mesg
;
228 PXEBC_DHCP4_OPTION_MAX_MESG_SIZE
*MaxMesgSize
;
229 } PXEBC_DHCP4_OPTION_ENTRY
;
234 EFI_IPv4_ADDRESS IpAddr
[1];
235 } PXEBC_BOOT_SVR_ENTRY
;
241 } PXEBC_BOOT_MENU_ENTRY
;
250 EFI_IPv4_ADDRESS MtftpIp
;
256 EFI_IPv4_ADDRESS DiscoverMcastIp
;
257 EFI_IPv4_ADDRESS McastIpBase
;
262 PXEBC_BOOT_SVR_ENTRY
*BootSvr
;
264 PXEBC_BOOT_MENU_ENTRY
*BootMenu
;
266 PXEBC_MENU_PROMPT
*MenuPrompt
;
270 } PXEBC_VENDOR_OPTION
;
272 #define PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE (OFFSET_OF (EFI_DHCP4_PACKET, Dhcp4) + PXEBC_DHCP4_MAX_PACKET_SIZE)
276 EFI_DHCP4_PACKET Offer
;
277 EFI_DHCP4_PACKET Ack
;
278 UINT8 Buffer
[PXEBC_CACHED_DHCP4_PACKET_MAX_SIZE
];
283 EFI_DHCP4_PACKET_OPTION
*Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_MAX
];
284 PXEBC_VENDOR_OPTION PxeVendorOption
;
285 } PXEBC_CACHED_DHCP4_PACKET
;
287 #define GET_NEXT_DHCP_OPTION(Opt) \
288 (EFI_DHCP4_PACKET_OPTION *) ((UINT8 *) (Opt) + sizeof (EFI_DHCP4_PACKET_OPTION) + (Opt)->Length - 1)
290 #define GET_OPTION_BUFFER_LEN(Pkt) ((Pkt)->Length - sizeof (EFI_DHCP4_HEADER) - 4)
291 #define IS_PROXY_DHCP_OFFER(Offer) EFI_IP4_EQUAL (&((Offer)->Dhcp4.Header.YourAddr), &mZeroIp4Addr)
293 #define GET_NEXT_BOOT_SVR_ENTRY(Ent) \
294 (PXEBC_BOOT_SVR_ENTRY *) ((UINT8 *) Ent + sizeof (*(Ent)) + ((Ent)->IpCnt - 1) * sizeof (EFI_IPv4_ADDRESS))
298 This function initialize the DHCP4 message instance.
300 This function will pad each item of dhcp4 message packet.
302 @param Seed Pointer to the message instance of the DHCP4 packet.
303 @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance.
309 PxeBcInitSeedPacket (
310 IN EFI_DHCP4_PACKET
*Seed
,
311 IN EFI_UDP4_PROTOCOL
*Udp4
316 Parse the cached dhcp packet.
318 @param CachedPacket Pointer to cached dhcp packet.
320 @retval TRUE Succeed to parse and validation.
321 @retval FALSE Fail to parse or validation.
325 PxeBcParseCachedDhcpPacket (
326 IN PXEBC_CACHED_DHCP4_PACKET
*CachedPacket
330 This function is to check the selected proxy offer (include BINL dhcp offer and
331 DHCP_ONLY offer ) and set the flag and copy the DHCP packets to the Pxe base code
334 @param Private Pointer to PxeBc private data.
336 @retval EFI_SUCCESS Operational successful.
337 @retval EFI_NO_RESPONSE Offer dhcp service failed.
341 PxeBcCheckSelectedOffer (
342 IN PXEBC_PRIVATE_DATA
*Private
349 EFI_DHCP4_CALLBACK is provided by the consumer of the EFI DHCPv4 Protocol driver
350 to intercept events that occurred in the configuration process. This structure
351 provides advanced control of each state transition of the DHCP process. The
352 returned status code determines the behavior of the EFI DHCPv4 Protocol driver.
353 There are three possible returned values, which are described in the following
356 @param This Pointer to the EFI DHCPv4 Protocol instance that is used to
357 configure this callback function.
358 @param Context Pointer to the context that is initialized by
359 EFI_DHCP4_PROTOCOL.Configure().
360 @param CurrentState The current operational state of the EFI DHCPv4 Protocol
362 @param Dhcp4Event The event that occurs in the current state, which usually means a
364 @param Packet The DHCP packet that is going to be sent or already received.
365 @param NewPacket The packet that is used to replace the above Packet.
367 @retval EFI_SUCCESS Tells the EFI DHCPv4 Protocol driver to continue the DHCP process.
368 @retval EFI_NOT_READY Only used in the Dhcp4Selecting state. The EFI DHCPv4 Protocol
369 driver will continue to wait for more DHCPOFFER packets until the retry
371 @retval EFI_ABORTED Tells the EFI DHCPv4 Protocol driver to abort the current process and
372 return to the Dhcp4Init or Dhcp4InitReboot state.
377 IN EFI_DHCP4_PROTOCOL
* This
,
379 IN EFI_DHCP4_STATE CurrentState
,
380 IN EFI_DHCP4_EVENT Dhcp4Event
,
381 IN EFI_DHCP4_PACKET
* Packet OPTIONAL
,
382 OUT EFI_DHCP4_PACKET
**NewPacket OPTIONAL
387 Discover the boot of service and initialize the vendor option if exists.
389 @param Private Pointer to PxeBc private data.
390 @param Type PxeBc option boot item type
391 @param Layer PxeBc option boot item layer
392 @param UseBis Use BIS or not
393 @param DestIp Ip address for server
394 @param IpCount The total count of the server ip address
395 @param SrvList Server list
396 @param IsDiscv Discover the vendor or not
397 @param Reply The dhcp4 packet of Pxe reply
399 @retval EFI_SUCCESS Operation succeeds.
400 @retval EFI_OUT_OF_RESOURCES Allocate memory pool failed.
401 @retval EFI_NOT_FOUND There is no vendor option exists.
402 @retval EFI_TIMEOUT Send Pxe Discover time out.
406 PxeBcDiscvBootService (
407 IN PXEBC_PRIVATE_DATA
* Private
,
411 IN EFI_IP_ADDRESS
* DestIp
,
413 IN EFI_PXE_BASE_CODE_SRVLIST
* SrvList
,
415 OUT EFI_DHCP4_PACKET
* Reply OPTIONAL
420 Initialize the DHCP options and build the option list.
422 @param Private Pointer to PxeBc private data.
423 @param OptList Pointer to a DHCP option list.
425 @param IsDhcpDiscover Discover dhcp option or not.
427 @return The index item number of the option list.
431 PxeBcBuildDhcpOptions (
432 IN PXEBC_PRIVATE_DATA
*Private
,
433 IN EFI_DHCP4_PACKET_OPTION
**OptList
,
434 IN BOOLEAN IsDhcpDiscover
439 Create the boot options
441 @param OptList Pointer to the list of the options
442 @param Type the type of option
443 @param Layer the layer of the boot options
444 @param OptLen length of opotion
450 PxeBcCreateBootOptions (
451 IN EFI_DHCP4_PACKET_OPTION
*OptList
,
459 Parse interested dhcp options.
461 @param Buffer Pointer to the dhcp options packet.
462 @param Length The length of the dhcp options.
463 @param OptTag The option OpCode.
465 @return NULL if the buffer length is 0 and OpCode is not
466 PXEBC_DHCP4_TAG_EOP, or the pointer to the buffer.
469 EFI_DHCP4_PACKET_OPTION
*
470 PxeBcParseExtendOptions (
478 This function is to parse and check vendor options.
480 @param Dhcp4Option Pointer to dhcp options
481 @param VendorOption Pointer to vendor options
483 @return TRUE if valid for vendor options, or FALSE.
487 PxeBcParseVendorOptions (
488 IN EFI_DHCP4_PACKET_OPTION
*Dhcp4Option
,
489 IN PXEBC_VENDOR_OPTION
*VendorOption
494 Choose the boot prompt.
496 @param Private Pointer to PxeBc private data.
498 @retval EFI_SUCCESS Select boot prompt done.
499 @retval EFI_TIMEOUT Select boot prompt time out.
500 @retval EFI_NOT_FOUND The proxy offer is not Pxe10.
501 @retval EFI_ABORTED User cancel the operation.
502 @retval EFI_NOT_READY Read the input key from the keybroad has not finish.
506 PxeBcSelectBootPrompt (
507 IN PXEBC_PRIVATE_DATA
*Private
512 Select the boot menu.
514 @param Private Pointer to PxeBc private data.
515 @param Type The type of the menu.
516 @param UseDefaultItem Use default item or not.
518 @retval EFI_ABORTED User cancel operation.
519 @retval EFI_SUCCESS Select the boot menu success.
520 @retval EFI_NOT_READY Read the input key from the keybroad has not finish.
524 PxeBcSelectBootMenu (
525 IN PXEBC_PRIVATE_DATA
*Private
,
527 IN BOOLEAN UseDefaultItem