2 Interface routines for PxeBc.
4 Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
5 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.
16 #include "PxeBcImpl.h"
18 UINT32 mPxeDhcpTimeout
[4] = { 4, 8, 16, 32 };
21 Get and record the arp cache.
23 @param This Pointer to EFI_PXE_BC_PROTOCOL
25 @retval EFI_SUCCESS Arp cache updated successfully
26 @retval others If error occurs when getting arp cache
31 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
34 PXEBC_PRIVATE_DATA
*Private
;
35 EFI_PXE_BASE_CODE_MODE
*Mode
;
39 EFI_ARP_FIND_DATA
*Entries
;
42 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
43 Mode
= Private
->PxeBc
.Mode
;
45 Status
= Private
->Arp
->Find (
54 if (EFI_ERROR (Status
)) {
58 Mode
->ArpCacheEntries
= MIN (
60 EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES
62 for (Index
= 0; Index
< Mode
->ArpCacheEntries
; Index
++) {
64 &Mode
->ArpCache
[Index
].IpAddr
,
66 Entries
->SwAddressLength
69 &Mode
->ArpCache
[Index
].MacAddr
,
70 (UINT8
*) (Entries
+ 1) + Entries
->SwAddressLength
,
71 Entries
->HwAddressLength
74 // Slip to the next FindData.
76 Entries
= (EFI_ARP_FIND_DATA
*) ((UINT8
*) Entries
+ EntryLength
);
83 Timeout routine to update arp cache.
85 @param Event Pointer to EFI_PXE_BC_PROTOCOL
86 @param Context Context of the timer event
91 ArpCacheUpdateTimeout (
96 UpdateArpCache ((EFI_PXE_BASE_CODE_PROTOCOL
*) Context
);
100 Do arp resolution from arp cache in PxeBcMode.
102 @param PxeBcMode The PXE BC mode to look into.
103 @param Ip4Addr The Ip4 address for resolution.
104 @param MacAddress The resoluted MAC address if the resolution is successful.
105 The value is undefined if resolution fails.
107 @retval TRUE The resolution is successful.
108 @retval FALSE Otherwise.
113 IN EFI_PXE_BASE_CODE_MODE
*PxeBcMode
,
114 IN EFI_IPv4_ADDRESS
*Ip4Addr
,
115 OUT EFI_MAC_ADDRESS
*MacAddress
120 for (Index
= 0; Index
< PxeBcMode
->ArpCacheEntries
; Index
++) {
121 if (EFI_IP4_EQUAL (&PxeBcMode
->ArpCache
[Index
].IpAddr
.v4
, Ip4Addr
)) {
124 &PxeBcMode
->ArpCache
[Index
].MacAddr
,
125 sizeof (EFI_MAC_ADDRESS
)
135 Notify function for the ICMP receive token, used to process
136 the received ICMP packets.
138 @param Context The PXEBC private data.
143 IcmpErrorListenHandlerDpc (
148 EFI_IP4_RECEIVE_DATA
*RxData
;
149 EFI_IP4_PROTOCOL
*Ip4
;
150 PXEBC_PRIVATE_DATA
*Private
;
151 EFI_PXE_BASE_CODE_MODE
*Mode
;
154 UINT8
*CopiedPointer
;
156 Private
= (PXEBC_PRIVATE_DATA
*) Context
;
157 Mode
= &Private
->Mode
;
158 Status
= Private
->IcmpErrorRcvToken
.Status
;
159 RxData
= Private
->IcmpErrorRcvToken
.Packet
.RxData
;
162 if (Status
== EFI_ABORTED
) {
164 // The reception is actively aborted by the consumer, directly return.
169 if (EFI_ERROR (Status
) || (RxData
== NULL
)) {
171 // Only process the normal packets and the icmp error packets, if RxData is NULL
172 // with Status == EFI_SUCCESS or EFI_ICMP_ERROR, just resume the receive although
173 // this should be a bug of the low layer (IP).
178 if (EFI_IP4 (RxData
->Header
->SourceAddress
) != 0 &&
179 !NetIp4IsUnicast (EFI_NTOHL (RxData
->Header
->SourceAddress
), 0)) {
181 // The source address is not zero and it's not a unicast IP address, discard it.
186 if (!EFI_IP4_EQUAL (&RxData
->Header
->DestinationAddress
, &Mode
->StationIp
.v4
)) {
188 // The dest address is not equal to Station Ip address, discard it.
194 // Constructor ICMP error packet
197 CopiedPointer
= (UINT8
*) &Mode
->IcmpError
;
199 for (Index
= 0; Index
< RxData
->FragmentCount
; Index
++) {
200 CopiedLen
+= RxData
->FragmentTable
[Index
].FragmentLength
;
201 if (CopiedLen
<= sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR
)) {
204 RxData
->FragmentTable
[Index
].FragmentBuffer
,
205 RxData
->FragmentTable
[Index
].FragmentLength
210 RxData
->FragmentTable
[Index
].FragmentBuffer
,
211 CopiedLen
- sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR
)
214 CopiedPointer
+= CopiedLen
;
220 gBS
->SignalEvent (RxData
->RecycleSignal
);
223 Ip4
->Receive (Ip4
, &(Private
->IcmpErrorRcvToken
));
227 Request IcmpErrorListenHandlerDpc as a DPC at TPL_CALLBACK
229 @param Event The event signaled.
230 @param Context The context passed in by the event notifier.
235 IcmpErrorListenHandler (
241 // Request IpIoListenHandlerDpc as a DPC at TPL_CALLBACK
243 QueueDpc (TPL_CALLBACK
, IcmpErrorListenHandlerDpc
, Context
);
247 Enables the use of the PXE Base Code Protocol functions.
249 This function enables the use of the PXE Base Code Protocol functions. If the
250 Started field of the EFI_PXE_BASE_CODE_MODE structure is already TRUE, then
251 EFI_ALREADY_STARTED will be returned. If UseIpv6 is TRUE, then IPv6 formatted
252 addresses will be used in this session. If UseIpv6 is FALSE, then IPv4 formatted
253 addresses will be used in this session. If UseIpv6 is TRUE, and the Ipv6Supported
254 field of the EFI_PXE_BASE_CODE_MODE structure is FALSE, then EFI_UNSUPPORTED will
255 be returned. If there is not enough memory or other resources to start the PXE
256 Base Code Protocol, then EFI_OUT_OF_RESOURCES will be returned. Otherwise, the
257 PXE Base Code Protocol will be started, and all of the fields of the EFI_PXE_BASE_CODE_MODE
258 structure will be initialized as follows:
260 Ipv6SupportedUnchanged.
261 Ipv6AvailableUnchanged.
262 UsingIpv6Set to UseIpv6.
263 BisSupportedUnchanged.
264 BisDetectedUnchanged.
266 SendGUIDSet to FALSE.
267 TTLSet to DEFAULT_TTL.
268 ToSSet to DEFAULT_ToS.
269 DhcpCompletedSet to FALSE.
270 ProxyOfferReceivedSet to FALSE.
271 StationIpSet to an address of all zeros.
272 SubnetMaskSet to a subnet mask of all zeros.
273 DhcpDiscoverZero-filled.
275 ProxyOfferZero-filled.
276 PxeDiscoverValidSet to FALSE.
277 PxeDiscoverZero-filled.
278 PxeReplyValidSet to FALSE.
280 PxeBisReplyValidSet to FALSE.
281 PxeBisReplyZero-filled.
282 IpFilterSet the Filters field to 0 and the IpCnt field to 0.
283 ArpCacheEntriesSet to 0.
285 RouteTableEntriesSet to 0.
286 RouteTableZero-filled.
287 IcmpErrorReceivedSet to FALSE.
288 IcmpErrorZero-filled.
289 TftpErroReceivedSet to FALSE.
290 TftpErrorZero-filled.
291 MakeCallbacksSet to TRUE if the PXE Base Code Callback Protocol is available.
292 Set to FALSE if the PXE Base Code Callback Protocol is not available.
294 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
295 @param UseIpv6 Specifies the type of IP addresses that are to be used during the session
296 that is being started. Set to TRUE for IPv6 addresses, and FALSE for
299 @retval EFI_SUCCESS The PXE Base Code Protocol was started.
300 @retval EFI_DEVICE_ERROR The network device encountered an error during this oper
301 @retval EFI_UNSUPPORTED UseIpv6 is TRUE, but the Ipv6Supported field of the
302 EFI_PXE_BASE_CODE_MODE structure is FALSE.
303 @retval EFI_ALREADY_STARTED The PXE Base Code Protocol is already in the started state.
304 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
305 EFI_PXE_BASE_CODE_PROTOCOL structure.
306 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory or other resources to start the
307 PXE Base Code Protocol.
313 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
317 PXEBC_PRIVATE_DATA
*Private
;
318 EFI_PXE_BASE_CODE_MODE
*Mode
;
322 return EFI_INVALID_PARAMETER
;
325 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
326 Mode
= Private
->PxeBc
.Mode
;
329 return EFI_ALREADY_STARTED
;
334 // IPv6 is not supported now.
336 return EFI_UNSUPPORTED
;
340 // Configure the udp4 instance to let it receive data
342 Status
= Private
->Udp4Read
->Configure (
344 &Private
->Udp4CfgData
346 if (EFI_ERROR (Status
)) {
352 // Configure block size for TFTP as a default value to handle all link layers.
354 Private
->BlockSize
= (UINTN
) (MIN (Private
->Ip4MaxPacketSize
, PXEBC_DEFAULT_PACKET_SIZE
) -
355 PXEBC_DEFAULT_UDP_OVERHEAD_SIZE
- PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE
);
357 // If PcdTftpBlockSize is set to non-zero, override the default value.
359 if (PcdGet64 (PcdTftpBlockSize
) != 0) {
360 Private
->BlockSize
= (UINTN
) PcdGet64 (PcdTftpBlockSize
);
363 Private
->AddressIsOk
= FALSE
;
365 ZeroMem (Mode
, sizeof (EFI_PXE_BASE_CODE_MODE
));
367 Mode
->Started
= TRUE
;
368 Mode
->TTL
= DEFAULT_TTL
;
369 Mode
->ToS
= DEFAULT_ToS
;
370 Mode
->AutoArp
= TRUE
;
373 // Create the event for Arp Cache checking.
375 Status
= gBS
->CreateEvent (
376 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
378 ArpCacheUpdateTimeout
,
380 &Private
->GetArpCacheEvent
382 if (EFI_ERROR (Status
)) {
387 // Start the timeout timer event.
389 Status
= gBS
->SetTimer (
390 Private
->GetArpCacheEvent
,
395 if (EFI_ERROR (Status
)) {
400 // Create ICMP error receiving event
402 Status
= gBS
->CreateEvent (
405 IcmpErrorListenHandler
,
407 &(Private
->IcmpErrorRcvToken
.Event
)
409 if (EFI_ERROR (Status
)) {
413 Status
= Private
->Ip4
->Configure (Private
->Ip4
, &Private
->Ip4ConfigData
);
414 if (EFI_ERROR (Status
)) {
419 // start to listen incoming packet
421 Status
= Private
->Ip4
->Receive (Private
->Ip4
, &Private
->IcmpErrorRcvToken
);
422 if (!EFI_ERROR (Status
)) {
427 Private
->Ip4
->Configure (Private
->Ip4
, NULL
);
429 if (Private
->IcmpErrorRcvToken
.Event
!= NULL
) {
430 gBS
->CloseEvent (Private
->IcmpErrorRcvToken
.Event
);
433 if (Private
->GetArpCacheEvent
!= NULL
) {
434 gBS
->SetTimer (Private
->GetArpCacheEvent
, TimerCancel
, 0);
435 gBS
->CloseEvent (Private
->GetArpCacheEvent
);
438 Mode
->Started
= FALSE
;
441 Mode
->AutoArp
= FALSE
;
448 Disables the use of the PXE Base Code Protocol functions.
450 This function stops all activity on the network device. All the resources allocated
451 in Start() are released, the Started field of the EFI_PXE_BASE_CODE_MODE structure is
452 set to FALSE and EFI_SUCCESS is returned. If the Started field of the EFI_PXE_BASE_CODE_MODE
453 structure is already FALSE, then EFI_NOT_STARTED will be returned.
455 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
457 @retval EFI_SUCCESS The PXE Base Code Protocol was stopped.
458 @retval EFI_NOT_STARTED The PXE Base Code Protocol is already in the stopped state.
459 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
460 EFI_PXE_BASE_CODE_PROTOCOL structure.
461 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
467 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
470 PXEBC_PRIVATE_DATA
*Private
;
471 EFI_PXE_BASE_CODE_MODE
*Mode
;
474 return EFI_INVALID_PARAMETER
;
477 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
478 Mode
= Private
->PxeBc
.Mode
;
480 if (!Mode
->Started
) {
481 return EFI_NOT_STARTED
;
484 Private
->Ip4
->Cancel (Private
->Ip4
, NULL
);
486 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
491 Private
->Ip4
->Configure (Private
->Ip4
, NULL
);
494 // Close the ICMP error receiving event.
496 gBS
->CloseEvent (Private
->IcmpErrorRcvToken
.Event
);
499 // Cancel the TimeoutEvent timer.
501 gBS
->SetTimer (Private
->GetArpCacheEvent
, TimerCancel
, 0);
504 // Close the TimeoutEvent event.
506 gBS
->CloseEvent (Private
->GetArpCacheEvent
);
508 Mode
->Started
= FALSE
;
510 Private
->CurrentUdpSrcPort
= 0;
511 Private
->Udp4Write
->Configure (Private
->Udp4Write
, NULL
);
512 Private
->Udp4Read
->Groups (Private
->Udp4Read
, FALSE
, NULL
);
513 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
515 Private
->Dhcp4
->Stop (Private
->Dhcp4
);
516 Private
->Dhcp4
->Configure (Private
->Dhcp4
, NULL
);
518 Private
->FileSize
= 0;
525 Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request / acknowledge) or DHCPv6
526 S.A.R.R (solicit / advertise / request / reply) sequence.
528 This function attempts to complete the DHCP sequence. If this sequence is completed,
529 then EFI_SUCCESS is returned, and the DhcpCompleted, ProxyOfferReceived, StationIp,
530 SubnetMask, DhcpDiscover, DhcpAck, and ProxyOffer fields of the EFI_PXE_BASE_CODE_MODE
531 structure are filled in.
532 If SortOffers is TRUE, then the cached DHCP offer packets will be sorted before
533 they are tried. If SortOffers is FALSE, then the cached DHCP offer packets will
534 be tried in the order in which they are received. Please see the Preboot Execution
535 Environment (PXE) Specification for additional details on the implementation of DHCP.
536 This function can take at least 31 seconds to timeout and return control to the
537 caller. If the DHCP sequence does not complete, then EFI_TIMEOUT will be returned.
538 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
539 then the DHCP sequence will be stopped and EFI_ABORTED will be returned.
541 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
542 @param SortOffers TRUE if the offers received should be sorted. Set to FALSE to try the
543 offers in the order that they are received.
545 @retval EFI_SUCCESS Valid DHCP has completed.
546 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
547 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
548 EFI_PXE_BASE_CODE_PROTOCOL structure.
549 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
550 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete the DHCP Protocol.
551 @retval EFI_ABORTED The callback function aborted the DHCP Protocol.
552 @retval EFI_TIMEOUT The DHCP Protocol timed out.
553 @retval EFI_ICMP_ERROR An ICMP error packet was received during the DHCP session.
554 @retval EFI_NO_RESPONSE Valid PXE offer was not received.
560 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
561 IN BOOLEAN SortOffers
564 PXEBC_PRIVATE_DATA
*Private
;
565 EFI_PXE_BASE_CODE_MODE
*Mode
;
566 EFI_DHCP4_PROTOCOL
*Dhcp4
;
567 EFI_DHCP4_CONFIG_DATA Dhcp4CfgData
;
568 EFI_DHCP4_MODE_DATA Dhcp4Mode
;
569 EFI_DHCP4_PACKET_OPTION
*OptList
[PXEBC_DHCP4_MAX_OPTION_NUM
];
572 EFI_ARP_CONFIG_DATA ArpConfigData
;
573 EFI_PXE_BASE_CODE_IP_FILTER IpFilter
;
576 return EFI_INVALID_PARAMETER
;
579 Status
= EFI_SUCCESS
;
580 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
581 Mode
= Private
->PxeBc
.Mode
;
582 Dhcp4
= Private
->Dhcp4
;
583 Private
->Function
= EFI_PXE_BASE_CODE_FUNCTION_DHCP
;
584 Private
->SortOffers
= SortOffers
;
586 if (!Mode
->Started
) {
587 return EFI_NOT_STARTED
;
590 Mode
->IcmpErrorReceived
= FALSE
;
593 // Stop Udp4Read instance
595 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
598 // Initialize the DHCP options and build the option list
600 OptCount
= PxeBcBuildDhcpOptions (Private
, OptList
, TRUE
);
603 // Set the DHCP4 config data.
604 // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.
606 ZeroMem (&Dhcp4CfgData
, sizeof (EFI_DHCP4_CONFIG_DATA
));
607 Dhcp4CfgData
.OptionCount
= OptCount
;
608 Dhcp4CfgData
.OptionList
= OptList
;
609 Dhcp4CfgData
.Dhcp4Callback
= PxeBcDhcpCallBack
;
610 Dhcp4CfgData
.CallbackContext
= Private
;
611 Dhcp4CfgData
.DiscoverTryCount
= 4;
612 Dhcp4CfgData
.DiscoverTimeout
= mPxeDhcpTimeout
;
614 Status
= Dhcp4
->Configure (Dhcp4
, &Dhcp4CfgData
);
615 if (EFI_ERROR (Status
)) {
620 // Zero those arrays to record the varies numbers of DHCP OFFERS.
622 Private
->GotProxyOffer
= FALSE
;
623 Private
->NumOffers
= 0;
624 Private
->BootpIndex
= 0;
625 ZeroMem (Private
->ServerCount
, sizeof (Private
->ServerCount
));
626 ZeroMem (Private
->ProxyIndex
, sizeof (Private
->ProxyIndex
));
628 Status
= Dhcp4
->Start (Dhcp4
, NULL
);
629 if (EFI_ERROR (Status
)) {
630 if (Status
== EFI_ICMP_ERROR
) {
631 Mode
->IcmpErrorReceived
= TRUE
;
636 Status
= Dhcp4
->GetModeData (Dhcp4
, &Dhcp4Mode
);
637 if (EFI_ERROR (Status
)) {
641 ASSERT (Dhcp4Mode
.State
== Dhcp4Bound
);
643 CopyMem (&Private
->StationIp
, &Dhcp4Mode
.ClientAddress
, sizeof (EFI_IPv4_ADDRESS
));
644 CopyMem (&Private
->SubnetMask
, &Dhcp4Mode
.SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
645 CopyMem (&Private
->GatewayIp
, &Dhcp4Mode
.RouterAddress
, sizeof (EFI_IPv4_ADDRESS
));
647 CopyMem (&Mode
->StationIp
, &Private
->StationIp
, sizeof (EFI_IPv4_ADDRESS
));
648 CopyMem (&Mode
->SubnetMask
, &Private
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
651 // Check the selected offer to see whether BINL is required, if no or BINL is
652 // finished, set the various Mode members.
654 Status
= PxeBcCheckSelectedOffer (Private
);
655 if (!EFI_ERROR (Status
)) {
660 if (EFI_ERROR (Status
)) {
662 Dhcp4
->Configure (Dhcp4
, NULL
);
665 // Remove the previously configured option list and callback function
667 ZeroMem (&Dhcp4CfgData
, sizeof (EFI_DHCP4_CONFIG_DATA
));
668 Dhcp4
->Configure (Dhcp4
, &Dhcp4CfgData
);
670 Private
->AddressIsOk
= TRUE
;
672 if (!Mode
->UsingIpv6
) {
674 // If in IPv4 mode, configure the corresponding ARP with this new
675 // station IP address.
677 ZeroMem (&ArpConfigData
, sizeof (EFI_ARP_CONFIG_DATA
));
679 ArpConfigData
.SwAddressType
= 0x0800;
680 ArpConfigData
.SwAddressLength
= (UINT8
) sizeof (EFI_IPv4_ADDRESS
);
681 ArpConfigData
.StationAddress
= &Private
->StationIp
.v4
;
683 Private
->Arp
->Configure (Private
->Arp
, NULL
);
684 Private
->Arp
->Configure (Private
->Arp
, &ArpConfigData
);
687 // Updated the route table. Fill the first entry.
689 Mode
->RouteTableEntries
= 1;
690 Mode
->RouteTable
[0].IpAddr
.Addr
[0] = Private
->StationIp
.Addr
[0] & Private
->SubnetMask
.Addr
[0];
691 Mode
->RouteTable
[0].SubnetMask
.Addr
[0] = Private
->SubnetMask
.Addr
[0];
692 Mode
->RouteTable
[0].GwAddr
.Addr
[0] = 0;
695 // Create the default route entry if there is a default router.
697 if (Private
->GatewayIp
.Addr
[0] != 0) {
698 Mode
->RouteTableEntries
= 2;
699 Mode
->RouteTable
[1].IpAddr
.Addr
[0] = 0;
700 Mode
->RouteTable
[1].SubnetMask
.Addr
[0] = 0;
701 Mode
->RouteTable
[1].GwAddr
.Addr
[0] = Private
->GatewayIp
.Addr
[0];
705 // Flush new station IP address into Udp4CfgData and Ip4ConfigData
707 CopyMem (&Private
->Udp4CfgData
.StationAddress
, &Private
->StationIp
, sizeof (EFI_IPv4_ADDRESS
));
708 CopyMem (&Private
->Udp4CfgData
.SubnetMask
, &Private
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
709 CopyMem (&Private
->Ip4ConfigData
.StationAddress
, &Private
->StationIp
, sizeof (EFI_IPv4_ADDRESS
));
710 CopyMem (&Private
->Ip4ConfigData
.SubnetMask
, &Private
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
713 // Reconfigure the Ip4 instance to capture background ICMP packets with new station Ip address.
715 Private
->Ip4
->Cancel (Private
->Ip4
, &Private
->IcmpErrorRcvToken
);
716 Private
->Ip4
->Configure (Private
->Ip4
, NULL
);
718 Status
= Private
->Ip4
->Configure (Private
->Ip4
, &Private
->Ip4ConfigData
);
719 if (EFI_ERROR (Status
)) {
723 Status
= Private
->Ip4
->Receive (Private
->Ip4
, &Private
->IcmpErrorRcvToken
);
724 if (EFI_ERROR (Status
)) {
730 Status
= Private
->Udp4Read
->Configure (Private
->Udp4Read
, &Private
->Udp4CfgData
);
733 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
734 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
736 ZeroMem(&IpFilter
, sizeof (EFI_PXE_BASE_CODE_IP_FILTER
));
737 IpFilter
.Filters
= EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
;
738 This
->SetIpFilter (This
, &IpFilter
);
745 Attempts to complete the PXE Boot Server and/or boot image discovery sequence.
747 This function attempts to complete the PXE Boot Server and/or boot image discovery
748 sequence. If this sequence is completed, then EFI_SUCCESS is returned, and the
749 PxeDiscoverValid, PxeDiscover, PxeReplyReceived, and PxeReply fields of the
750 EFI_PXE_BASE_CODE_MODE structure are filled in. If UseBis is TRUE, then the
751 PxeBisReplyReceived and PxeBisReply fields of the EFI_PXE_BASE_CODE_MODE structure
752 will also be filled in. If UseBis is FALSE, then PxeBisReplyValid will be set to FALSE.
753 In the structure referenced by parameter Info, the PXE Boot Server list, SrvList[],
754 has two uses: It is the Boot Server IP address list used for unicast discovery
755 (if the UseUCast field is TRUE), and it is the list used for Boot Server verification
756 (if the MustUseList field is TRUE). Also, if the MustUseList field in that structure
757 is TRUE and the AcceptAnyResponse field in the SrvList[] array is TRUE, any Boot
758 Server reply of that type will be accepted. If the AcceptAnyResponse field is
759 FALSE, only responses from Boot Servers with matching IP addresses will be accepted.
760 This function can take at least 10 seconds to timeout and return control to the
761 caller. If the Discovery sequence does not complete, then EFI_TIMEOUT will be
762 returned. Please see the Preboot Execution Environment (PXE) Specification for
763 additional details on the implementation of the Discovery sequence.
764 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
765 then the Discovery sequence is stopped and EFI_ABORTED will be returned.
767 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
768 @param Type The type of bootstrap to perform.
769 @param Layer Pointer to the boot server layer number to discover, which must be
770 PXE_BOOT_LAYER_INITIAL when a new server type is being
772 @param UseBis TRUE if Boot Integrity Services are to be used. FALSE otherwise.
773 @param Info Pointer to a data structure that contains additional information on the
774 type of discovery operation that is to be performed.
776 @retval EFI_SUCCESS The Discovery sequence has been completed.
777 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
778 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
779 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
780 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete Discovery.
781 @retval EFI_ABORTED The callback function aborted the Discovery sequence.
782 @retval EFI_TIMEOUT The Discovery sequence timed out.
783 @retval EFI_ICMP_ERROR An ICMP error packet was received during the PXE discovery
790 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
794 IN EFI_PXE_BASE_CODE_DISCOVER_INFO
*Info OPTIONAL
797 PXEBC_PRIVATE_DATA
*Private
;
798 EFI_PXE_BASE_CODE_MODE
*Mode
;
799 EFI_PXE_BASE_CODE_DISCOVER_INFO DefaultInfo
;
800 EFI_PXE_BASE_CODE_DISCOVER_INFO
*CreatedInfo
;
801 EFI_PXE_BASE_CODE_SRVLIST
*SrvList
;
802 EFI_PXE_BASE_CODE_SRVLIST DefaultSrvList
;
803 PXEBC_CACHED_DHCP4_PACKET
*Packet
;
804 PXEBC_VENDOR_OPTION
*VendorOpt
;
807 PXEBC_BOOT_SVR_ENTRY
*BootSvrEntry
;
808 EFI_PXE_BASE_CODE_IP_FILTER IpFilter
;
811 return EFI_INVALID_PARAMETER
;
814 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
815 Mode
= Private
->PxeBc
.Mode
;
819 Status
= EFI_DEVICE_ERROR
;
820 Private
->Function
= EFI_PXE_BASE_CODE_FUNCTION_DISCOVER
;
822 if (!Private
->AddressIsOk
) {
823 return EFI_INVALID_PARAMETER
;
826 if (!Mode
->Started
) {
827 return EFI_NOT_STARTED
;
831 // Stop Udp4Read instance
833 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
835 Mode
->IcmpErrorReceived
= FALSE
;
838 // If layer isn't EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL,
839 // use the previous setting;
840 // If info isn't offered,
841 // use the cached DhcpAck and ProxyOffer packets.
843 if (*Layer
!= EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL
) {
845 if (!Mode
->PxeDiscoverValid
|| !Mode
->PxeReplyReceived
|| (!Mode
->PxeBisReplyReceived
&& UseBis
)) {
847 Status
= EFI_INVALID_PARAMETER
;
851 DefaultInfo
.IpCnt
= 1;
852 DefaultInfo
.UseUCast
= TRUE
;
854 DefaultSrvList
.Type
= Type
;
855 DefaultSrvList
.AcceptAnyResponse
= FALSE
;
856 DefaultSrvList
.IpAddr
.Addr
[0] = Private
->ServerIp
.Addr
[0];
858 SrvList
= &DefaultSrvList
;
860 } else if (Info
== NULL
) {
862 // Create info by the cached packet before
864 Packet
= (Mode
->ProxyOfferReceived
) ? &Private
->ProxyOffer
: &Private
->Dhcp4Ack
;
865 VendorOpt
= &Packet
->PxeVendorOption
;
867 if (!Mode
->DhcpAckReceived
|| !IS_VALID_DISCOVER_VENDOR_OPTION (VendorOpt
->BitMap
)) {
869 // Address is not acquired or no discovery options.
871 Status
= EFI_INVALID_PARAMETER
;
875 DefaultInfo
.UseMCast
= (BOOLEAN
)!IS_DISABLE_MCAST_DISCOVER (VendorOpt
->DiscoverCtrl
);
876 DefaultInfo
.UseBCast
= (BOOLEAN
)!IS_DISABLE_BCAST_DISCOVER (VendorOpt
->DiscoverCtrl
);
877 DefaultInfo
.MustUseList
= (BOOLEAN
) IS_ENABLE_USE_SERVER_LIST (VendorOpt
->DiscoverCtrl
);
878 DefaultInfo
.UseUCast
= DefaultInfo
.MustUseList
;
880 if (DefaultInfo
.UseMCast
) {
882 // Get the multicast discover ip address from vendor option.
885 &DefaultInfo
.ServerMCastIp
.Addr
,
886 &VendorOpt
->DiscoverMcastIp
,
887 sizeof (EFI_IPv4_ADDRESS
)
891 DefaultInfo
.IpCnt
= 0;
893 SrvList
= Info
->SrvList
;
895 if (DefaultInfo
.MustUseList
) {
896 BootSvrEntry
= VendorOpt
->BootSvr
;
897 Status
= EFI_INVALID_PARAMETER
;
899 while (((UINT8
) (BootSvrEntry
- VendorOpt
->BootSvr
)) < VendorOpt
->BootSvrLen
) {
901 if (BootSvrEntry
->Type
== HTONS (Type
)) {
902 Status
= EFI_SUCCESS
;
906 BootSvrEntry
= GET_NEXT_BOOT_SVR_ENTRY (BootSvrEntry
);
909 if (EFI_ERROR (Status
)) {
913 DefaultInfo
.IpCnt
= BootSvrEntry
->IpCnt
;
915 if (DefaultInfo
.IpCnt
>= 1) {
916 CreatedInfo
= AllocatePool (sizeof (DefaultInfo
) + (DefaultInfo
.IpCnt
- 1) * sizeof (*SrvList
));
917 if (CreatedInfo
== NULL
) {
918 Status
= EFI_OUT_OF_RESOURCES
;
923 CopyMem (CreatedInfo
, &DefaultInfo
, sizeof (DefaultInfo
));
925 SrvList
= Info
->SrvList
;
928 for (Index
= 0; Index
< DefaultInfo
.IpCnt
; Index
++) {
929 CopyMem (&SrvList
[Index
].IpAddr
, &BootSvrEntry
->IpAddr
[Index
], sizeof (EFI_IPv4_ADDRESS
));
930 SrvList
[Index
].AcceptAnyResponse
= FALSE
;
931 SrvList
[Index
].Type
= BootSvrEntry
->Type
;
937 SrvList
= Info
->SrvList
;
939 if (!SrvList
[0].AcceptAnyResponse
) {
941 for (Index
= 1; Index
< Info
->IpCnt
; Index
++) {
942 if (SrvList
[Index
].AcceptAnyResponse
) {
947 if (Index
!= Info
->IpCnt
) {
948 Status
= EFI_INVALID_PARAMETER
;
954 if ((!Info
->UseUCast
&& !Info
->UseBCast
&& !Info
->UseMCast
) || (Info
->MustUseList
&& Info
->IpCnt
== 0)) {
956 Status
= EFI_INVALID_PARAMETER
;
960 // Execute discover by UniCast/BroadCast/MultiCast
962 if (Info
->UseUCast
) {
964 for (Index
= 0; Index
< Info
->IpCnt
; Index
++) {
966 if (BootSvrEntry
== NULL
) {
967 Private
->ServerIp
.Addr
[0] = SrvList
[Index
].IpAddr
.Addr
[0];
971 &BootSvrEntry
->IpAddr
[Index
],
972 sizeof (EFI_IPv4_ADDRESS
)
976 Status
= PxeBcDiscvBootService (
981 &SrvList
[Index
].IpAddr
,
985 &Private
->PxeReply
.Packet
.Ack
987 if (!EFI_ERROR (Status
)) {
992 } else if (Info
->UseMCast
) {
994 Status
= PxeBcDiscvBootService (
999 &Info
->ServerMCastIp
,
1003 &Private
->PxeReply
.Packet
.Ack
1006 } else if (Info
->UseBCast
) {
1008 Status
= PxeBcDiscvBootService (
1017 &Private
->PxeReply
.Packet
.Ack
1021 if (EFI_ERROR (Status
) || !Mode
->PxeReplyReceived
|| (!Mode
->PxeBisReplyReceived
&& UseBis
)) {
1022 if (Status
== EFI_ICMP_ERROR
) {
1023 Mode
->IcmpErrorReceived
= TRUE
;
1025 Status
= EFI_DEVICE_ERROR
;
1028 PxeBcParseCachedDhcpPacket (&Private
->PxeReply
);
1031 if (Mode
->PxeBisReplyReceived
) {
1034 &Mode
->PxeReply
.Dhcpv4
.BootpSiAddr
,
1035 sizeof (EFI_IPv4_ADDRESS
)
1039 if (CreatedInfo
!= NULL
) {
1040 FreePool (CreatedInfo
);
1045 Status
= Private
->Udp4Read
->Configure (Private
->Udp4Read
, &Private
->Udp4CfgData
);
1048 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
1049 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1051 ZeroMem(&IpFilter
, sizeof (EFI_PXE_BASE_CODE_IP_FILTER
));
1052 IpFilter
.Filters
= EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
;
1053 This
->SetIpFilter (This
, &IpFilter
);
1060 Used to perform TFTP and MTFTP services.
1062 This function is used to perform TFTP and MTFTP services. This includes the
1063 TFTP operations to get the size of a file, read a directory, read a file, and
1064 write a file. It also includes the MTFTP operations to get the size of a file,
1065 read a directory, and read a file. The type of operation is specified by Operation.
1066 If the callback function that is invoked during the TFTP/MTFTP operation does
1067 not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will
1069 For read operations, the return data will be placed in the buffer specified by
1070 BufferPtr. If BufferSize is too small to contain the entire downloaded file,
1071 then EFI_BUFFER_TOO_SMALL will be returned and BufferSize will be set to zero
1072 or the size of the requested file (the size of the requested file is only returned
1073 if the TFTP server supports TFTP options). If BufferSize is large enough for the
1074 read operation, then BufferSize will be set to the size of the downloaded file,
1075 and EFI_SUCCESS will be returned. Applications using the PxeBc.Mtftp() services
1076 should use the get-file-size operations to determine the size of the downloaded
1077 file prior to using the read-file operations-especially when downloading large
1078 (greater than 64 MB) files-instead of making two calls to the read-file operation.
1079 Following this recommendation will save time if the file is larger than expected
1080 and the TFTP server does not support TFTP option extensions. Without TFTP option
1081 extension support, the client has to download the entire file, counting and discarding
1082 the received packets, to determine the file size.
1083 For write operations, the data to be sent is in the buffer specified by BufferPtr.
1084 BufferSize specifies the number of bytes to send. If the write operation completes
1085 successfully, then EFI_SUCCESS will be returned.
1086 For TFTP "get file size" operations, the size of the requested file or directory
1087 is returned in BufferSize, and EFI_SUCCESS will be returned. If the TFTP server
1088 does not support options, the file will be downloaded into a bit bucket and the
1089 length of the downloaded file will be returned. For MTFTP "get file size" operations,
1090 if the MTFTP server does not support the "get file size" option, EFI_UNSUPPORTED
1092 This function can take up to 10 seconds to timeout and return control to the caller.
1093 If the TFTP sequence does not complete, EFI_TIMEOUT will be returned.
1094 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
1095 then the TFTP sequence is stopped and EFI_ABORTED will be returned.
1096 The format of the data returned from a TFTP read directory operation is a null-terminated
1097 filename followed by a null-terminated information string, of the form
1098 "size year-month-day hour:minute:second" (i.e. %d %d-%d-%d %d:%d:%f - note that
1099 the seconds field can be a decimal number), where the date and time are UTC. For
1100 an MTFTP read directory command, there is additionally a null-terminated multicast
1101 IP address preceding the filename of the form %d.%d.%d.%d for IP v4. The final
1102 entry is itself null-terminated, so that the final information string is terminated
1103 with two null octets.
1105 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1106 @param Operation The type of operation to perform.
1107 @param BufferPtr A pointer to the data buffer.
1108 @param Overwrite Only used on write file operations. TRUE if a file on a remote server can
1110 @param BufferSize For get-file-size operations, *BufferSize returns the size of the
1112 @param BlockSize The requested block size to be used during a TFTP transfer.
1113 @param ServerIp The TFTP / MTFTP server IP address.
1114 @param Filename A Null-terminated ASCII string that specifies a directory name or a file
1116 @param Info Pointer to the MTFTP information.
1117 @param DontUseBuffer Set to FALSE for normal TFTP and MTFTP read file operation.
1119 @retval EFI_SUCCESS The TFTP/MTFTP operation was completed.
1120 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1121 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1122 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1123 @retval EFI_BUFFER_TOO_SMALL The buffer is not large enough to complete the read operation.
1124 @retval EFI_ABORTED The callback function aborted the TFTP/MTFTP operation.
1125 @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.
1126 @retval EFI_ICMP_ERROR An ICMP error packet was received during the MTFTP session.
1127 @retval EFI_TFTP_ERROR A TFTP error packet was received during the MTFTP session.
1133 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1134 IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation
,
1135 IN OUT VOID
*BufferPtr
,
1136 IN BOOLEAN Overwrite
,
1137 IN OUT UINT64
*BufferSize
,
1138 IN UINTN
*BlockSize OPTIONAL
,
1139 IN EFI_IP_ADDRESS
*ServerIp
,
1141 IN EFI_PXE_BASE_CODE_MTFTP_INFO
*Info OPTIONAL
,
1142 IN BOOLEAN DontUseBuffer
1145 PXEBC_PRIVATE_DATA
*Private
;
1146 EFI_MTFTP4_CONFIG_DATA Mtftp4Config
;
1148 EFI_PXE_BASE_CODE_MODE
*Mode
;
1149 EFI_MAC_ADDRESS TempMacAddr
;
1150 EFI_PXE_BASE_CODE_IP_FILTER IpFilter
;
1152 if ((This
== NULL
) ||
1153 (Filename
== NULL
) ||
1154 (BufferSize
== NULL
) ||
1155 ((ServerIp
== NULL
) || !NetIp4IsUnicast (NTOHL (ServerIp
->Addr
[0]), 0)) ||
1156 ((BufferPtr
== NULL
) && DontUseBuffer
) ||
1157 ((BlockSize
!= NULL
) && (*BlockSize
< 512))) {
1159 return EFI_INVALID_PARAMETER
;
1162 Status
= EFI_DEVICE_ERROR
;
1163 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1164 Mode
= &Private
->Mode
;
1166 if (!Mode
->AutoArp
) {
1168 // If AutoArp is set false, check arp cache
1170 UpdateArpCache (This
);
1171 if (!FindInArpCache (Mode
, &ServerIp
->v4
, &TempMacAddr
)) {
1172 return EFI_DEVICE_ERROR
;
1177 // Stop Udp4Read instance
1179 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
1181 Mode
->TftpErrorReceived
= FALSE
;
1182 Mode
->IcmpErrorReceived
= FALSE
;
1184 Mtftp4Config
.UseDefaultSetting
= FALSE
;
1185 Mtftp4Config
.TimeoutValue
= PXEBC_MTFTP_TIMEOUT
;
1186 Mtftp4Config
.TryCount
= PXEBC_MTFTP_RETRIES
;
1189 &Mtftp4Config
.StationIp
,
1190 &Private
->StationIp
,
1191 sizeof (EFI_IPv4_ADDRESS
)
1194 &Mtftp4Config
.SubnetMask
,
1195 &Private
->SubnetMask
,
1196 sizeof (EFI_IPv4_ADDRESS
)
1199 &Mtftp4Config
.GatewayIp
,
1200 &Private
->GatewayIp
,
1201 sizeof (EFI_IPv4_ADDRESS
)
1204 &Mtftp4Config
.ServerIp
,
1206 sizeof (EFI_IPv4_ADDRESS
)
1209 switch (Operation
) {
1211 case EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE
:
1213 Status
= PxeBcTftpGetFileSize (
1223 case EFI_PXE_BASE_CODE_TFTP_READ_FILE
:
1225 Status
= PxeBcTftpReadFile (
1237 case EFI_PXE_BASE_CODE_TFTP_WRITE_FILE
:
1239 Status
= PxeBcTftpWriteFile (
1251 case EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY
:
1253 Status
= PxeBcTftpReadDirectory (
1265 case EFI_PXE_BASE_CODE_MTFTP_GET_FILE_SIZE
:
1266 case EFI_PXE_BASE_CODE_MTFTP_READ_FILE
:
1267 case EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY
:
1268 Status
= EFI_UNSUPPORTED
;
1273 Status
= EFI_INVALID_PARAMETER
;
1277 if (Status
== EFI_ICMP_ERROR
) {
1278 Mode
->IcmpErrorReceived
= TRUE
;
1281 Status
= Private
->Udp4Read
->Configure (Private
->Udp4Read
, &Private
->Udp4CfgData
);
1283 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
1284 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1286 ZeroMem(&IpFilter
, sizeof (EFI_PXE_BASE_CODE_IP_FILTER
));
1287 IpFilter
.Filters
= EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
;
1288 This
->SetIpFilter (This
, &IpFilter
);
1295 Writes a UDP packet to the network interface.
1297 This function writes a UDP packet specified by the (optional HeaderPtr and)
1298 BufferPtr parameters to the network interface. The UDP header is automatically
1299 built by this routine. It uses the parameters OpFlags, DestIp, DestPort, GatewayIp,
1300 SrcIp, and SrcPort to build this header. If the packet is successfully built and
1301 transmitted through the network interface, then EFI_SUCCESS will be returned.
1302 If a timeout occurs during the transmission of the packet, then EFI_TIMEOUT will
1303 be returned. If an ICMP error occurs during the transmission of the packet, then
1304 the IcmpErrorReceived field is set to TRUE, the IcmpError field is filled in and
1305 EFI_ICMP_ERROR will be returned. If the Callback Protocol does not return
1306 EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will be returned.
1308 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1309 @param OpFlags The UDP operation flags.
1310 @param DestIp The destination IP address.
1311 @param DestPort The destination UDP port number.
1312 @param GatewayIp The gateway IP address.
1313 @param SrcIp The source IP address.
1314 @param SrcPort The source UDP port number.
1315 @param HeaderSize An optional field which may be set to the length of a header at
1316 HeaderPtr to be prefixed to the data at BufferPtr.
1317 @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the
1319 @param BufferSize A pointer to the size of the data at BufferPtr.
1320 @param BufferPtr A pointer to the data to be written.
1322 @retval EFI_SUCCESS The UDP Write operation was completed.
1323 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1324 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1325 @retval EFI_BAD_BUFFER_SIZE The buffer is too long to be transmitted.
1326 @retval EFI_ABORTED The callback function aborted the UDP Write operation.
1327 @retval EFI_TIMEOUT The UDP Write operation timed out.
1328 @retval EFI_ICMP_ERROR An ICMP error packet was received during the UDP write session.
1334 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1336 IN EFI_IP_ADDRESS
*DestIp
,
1337 IN EFI_PXE_BASE_CODE_UDP_PORT
*DestPort
,
1338 IN EFI_IP_ADDRESS
*GatewayIp OPTIONAL
,
1339 IN EFI_IP_ADDRESS
*SrcIp OPTIONAL
,
1340 IN OUT EFI_PXE_BASE_CODE_UDP_PORT
*SrcPort OPTIONAL
,
1341 IN UINTN
*HeaderSize OPTIONAL
,
1342 IN VOID
*HeaderPtr OPTIONAL
,
1343 IN UINTN
*BufferSize
,
1347 PXEBC_PRIVATE_DATA
*Private
;
1348 EFI_UDP4_PROTOCOL
*Udp4
;
1349 EFI_UDP4_COMPLETION_TOKEN Token
;
1350 EFI_UDP4_TRANSMIT_DATA
*Udp4TxData
;
1353 EFI_UDP4_SESSION_DATA Udp4Session
;
1356 EFI_PXE_BASE_CODE_MODE
*Mode
;
1357 EFI_MAC_ADDRESS TempMacAddr
;
1361 if ((This
== NULL
) || (DestIp
== NULL
) || (DestPort
== NULL
)) {
1362 return EFI_INVALID_PARAMETER
;
1365 if ((GatewayIp
!= NULL
) && !NetIp4IsUnicast (NTOHL (GatewayIp
->Addr
[0]), 0)) {
1367 // Gateway is provided but it's not a unicast IP address.
1369 return EFI_INVALID_PARAMETER
;
1372 if ((HeaderSize
!= NULL
) && ((*HeaderSize
== 0) || (HeaderPtr
== NULL
))) {
1374 // The HeaderSize ptr isn't NULL and: 1. the value is zero; or 2. the HeaderPtr
1377 return EFI_INVALID_PARAMETER
;
1380 if ((BufferSize
== NULL
) || ((*BufferSize
!= 0) && (BufferPtr
== NULL
))) {
1381 return EFI_INVALID_PARAMETER
;
1384 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1385 Udp4
= Private
->Udp4Write
;
1386 Mode
= &Private
->Mode
;
1387 if (!Mode
->Started
) {
1388 return EFI_NOT_STARTED
;
1391 if (!Private
->AddressIsOk
&& (SrcIp
== NULL
)) {
1392 return EFI_INVALID_PARAMETER
;
1395 if (!Mode
->AutoArp
) {
1397 // If AutoArp is set false, check arp cache
1399 UpdateArpCache (This
);
1400 if (!FindInArpCache (Mode
, &DestIp
->v4
, &TempMacAddr
)) {
1401 return EFI_DEVICE_ERROR
;
1405 Mode
->IcmpErrorReceived
= FALSE
;
1407 if ((Private
->CurrentUdpSrcPort
== 0) ||
1408 ((SrcPort
!= NULL
) && (*SrcPort
!= Private
->CurrentUdpSrcPort
))) {
1410 // Port is changed, (re)configure the Udp4Write instance
1412 if (SrcPort
!= NULL
) {
1413 Private
->CurrentUdpSrcPort
= *SrcPort
;
1417 Status
= PxeBcConfigureUdpWriteInstance (
1419 &Private
->StationIp
.v4
,
1420 &Private
->SubnetMask
.v4
,
1421 &Private
->GatewayIp
.v4
,
1422 &Private
->CurrentUdpSrcPort
1424 if (EFI_ERROR (Status
)) {
1425 Private
->CurrentUdpSrcPort
= 0;
1426 return EFI_INVALID_PARAMETER
;
1429 ZeroMem (&Token
, sizeof (EFI_UDP4_COMPLETION_TOKEN
));
1430 ZeroMem (&Udp4Session
, sizeof (EFI_UDP4_SESSION_DATA
));
1432 CopyMem (&Udp4Session
.DestinationAddress
, DestIp
, sizeof (EFI_IPv4_ADDRESS
));
1433 Udp4Session
.DestinationPort
= *DestPort
;
1434 if (SrcIp
!= NULL
) {
1435 CopyMem (&Udp4Session
.SourceAddress
, SrcIp
, sizeof (EFI_IPv4_ADDRESS
));
1437 if (SrcPort
!= NULL
) {
1438 Udp4Session
.SourcePort
= *SrcPort
;
1441 FragCount
= (HeaderSize
!= NULL
) ? 2 : 1;
1442 Udp4TxData
= (EFI_UDP4_TRANSMIT_DATA
*) AllocateZeroPool (sizeof (EFI_UDP4_TRANSMIT_DATA
) + (FragCount
- 1) * sizeof (EFI_UDP4_FRAGMENT_DATA
));
1443 if (Udp4TxData
== NULL
) {
1444 return EFI_OUT_OF_RESOURCES
;
1447 Udp4TxData
->FragmentCount
= FragCount
;
1448 Udp4TxData
->FragmentTable
[FragCount
- 1].FragmentLength
= (UINT32
) *BufferSize
;
1449 Udp4TxData
->FragmentTable
[FragCount
- 1].FragmentBuffer
= BufferPtr
;
1450 DataLength
= (UINT32
) *BufferSize
;
1452 if (FragCount
== 2) {
1454 Udp4TxData
->FragmentTable
[0].FragmentLength
= (UINT32
) *HeaderSize
;
1455 Udp4TxData
->FragmentTable
[0].FragmentBuffer
= HeaderPtr
;
1456 DataLength
+= (UINT32
) *HeaderSize
;
1459 if (GatewayIp
!= NULL
) {
1460 Udp4TxData
->GatewayAddress
= (EFI_IPv4_ADDRESS
*) GatewayIp
;
1462 Udp4TxData
->UdpSessionData
= &Udp4Session
;
1463 Udp4TxData
->DataLength
= DataLength
;
1464 Token
.Packet
.TxData
= Udp4TxData
;
1466 Status
= gBS
->CreateEvent (
1473 if (EFI_ERROR (Status
)) {
1477 Status
= Udp4
->Transmit (Udp4
, &Token
);
1478 if (EFI_ERROR (Status
)) {
1479 if (Status
== EFI_ICMP_ERROR
) {
1480 Mode
->IcmpErrorReceived
= TRUE
;
1490 Status
= Token
.Status
;
1494 if (Token
.Event
!= NULL
) {
1495 gBS
->CloseEvent (Token
.Event
);
1498 FreePool (Udp4TxData
);
1501 // Reset the instance.
1503 Udp4
->Configure (Udp4
, NULL
);
1508 Decide whether the incoming UDP packet is acceptable per IP filter settings
1509 in provided PxeBcMode.
1511 @param PxeBcMode Pointer to EFI_PXE_BASE_CODE_MODE.
1512 @param Session Received UDP session.
1514 @retval TRUE The UDP package matches IP filters.
1515 @retval FALSE The UDP package doesn't matches IP filters.
1520 IN EFI_PXE_BASE_CODE_MODE
*PxeBcMode
,
1521 IN EFI_UDP4_SESSION_DATA
*Session
1525 EFI_IPv4_ADDRESS Ip4Address
;
1526 EFI_IPv4_ADDRESS DestIp4Address
;
1528 if ((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) != 0) {
1532 CopyMem (&DestIp4Address
, &Session
->DestinationAddress
, sizeof (DestIp4Address
));
1533 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
) != 0) &&
1534 IP4_IS_MULTICAST (EFI_NTOHL (DestIp4Address
))
1539 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST
) != 0) &&
1540 IP4_IS_LOCAL_BROADCAST (EFI_NTOHL (DestIp4Address
))
1545 CopyMem (&Ip4Address
, &PxeBcMode
->StationIp
.v4
, sizeof (Ip4Address
));
1546 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0) &&
1547 EFI_IP4_EQUAL (&Ip4Address
, &DestIp4Address
)
1552 ASSERT (PxeBcMode
->IpFilter
.IpCnt
< EFI_PXE_BASE_CODE_MAX_IPCNT
);
1554 for (Index
= 0; Index
< PxeBcMode
->IpFilter
.IpCnt
; Index
++) {
1557 &PxeBcMode
->IpFilter
.IpList
[Index
].v4
,
1560 if (EFI_IP4_EQUAL (&Ip4Address
, &DestIp4Address
)) {
1569 Reads a UDP packet from the network interface.
1571 This function reads a UDP packet from a network interface. The data contents
1572 are returned in (the optional HeaderPtr and) BufferPtr, and the size of the
1573 buffer received is returned in BufferSize . If the input BufferSize is smaller
1574 than the UDP packet received (less optional HeaderSize), it will be set to the
1575 required size, and EFI_BUFFER_TOO_SMALL will be returned. In this case, the
1576 contents of BufferPtr are undefined, and the packet is lost. If a UDP packet is
1577 successfully received, then EFI_SUCCESS will be returned, and the information
1578 from the UDP header will be returned in DestIp, DestPort, SrcIp, and SrcPort if
1579 they are not NULL. Depending on the values of OpFlags and the DestIp, DestPort,
1580 SrcIp, and SrcPort input values, different types of UDP packet receive filtering
1581 will be performed. The following tables summarize these receive filter operations.
1583 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1584 @param OpFlags The UDP operation flags.
1585 @param DestIp The destination IP address.
1586 @param DestPort The destination UDP port number.
1587 @param SrcIp The source IP address.
1588 @param SrcPort The source UDP port number.
1589 @param HeaderSize An optional field which may be set to the length of a header at
1590 HeaderPtr to be prefixed to the data at BufferPtr.
1591 @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the
1593 @param BufferSize A pointer to the size of the data at BufferPtr.
1594 @param BufferPtr A pointer to the data to be read.
1596 @retval EFI_SUCCESS The UDP Read operation was completed.
1597 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1598 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1599 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1600 @retval EFI_BUFFER_TOO_SMALL The packet is larger than Buffer can hold.
1601 @retval EFI_ABORTED The callback function aborted the UDP Read operation.
1602 @retval EFI_TIMEOUT The UDP Read operation timed out.
1608 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1610 IN OUT EFI_IP_ADDRESS
*DestIp OPTIONAL
,
1611 IN OUT EFI_PXE_BASE_CODE_UDP_PORT
*DestPort OPTIONAL
,
1612 IN OUT EFI_IP_ADDRESS
*SrcIp OPTIONAL
,
1613 IN OUT EFI_PXE_BASE_CODE_UDP_PORT
*SrcPort OPTIONAL
,
1614 IN UINTN
*HeaderSize OPTIONAL
,
1615 IN VOID
*HeaderPtr OPTIONAL
,
1616 IN OUT UINTN
*BufferSize
,
1620 PXEBC_PRIVATE_DATA
*Private
;
1621 EFI_PXE_BASE_CODE_MODE
*Mode
;
1622 EFI_UDP4_PROTOCOL
*Udp4
;
1623 EFI_UDP4_COMPLETION_TOKEN Token
;
1624 EFI_UDP4_RECEIVE_DATA
*RxData
;
1625 EFI_UDP4_SESSION_DATA
*Session
;
1631 if (This
== NULL
|| DestIp
== NULL
|| DestPort
== NULL
) {
1632 return EFI_INVALID_PARAMETER
;
1635 if (((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) == 0 && (DestPort
== NULL
)) ||
1636 ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) == 0 && (SrcIp
== NULL
)) ||
1637 ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT
) == 0 && (SrcPort
== NULL
))) {
1638 return EFI_INVALID_PARAMETER
;
1641 if (((HeaderSize
!= NULL
) && (*HeaderSize
== 0)) || ((HeaderSize
!= NULL
) && (HeaderPtr
== NULL
))) {
1642 return EFI_INVALID_PARAMETER
;
1645 if ((BufferSize
== NULL
) || (BufferPtr
== NULL
)) {
1646 return EFI_INVALID_PARAMETER
;
1649 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1650 Mode
= Private
->PxeBc
.Mode
;
1651 Udp4
= Private
->Udp4Read
;
1653 if (!Mode
->Started
) {
1654 return EFI_NOT_STARTED
;
1657 Mode
->IcmpErrorReceived
= FALSE
;
1659 Status
= gBS
->CreateEvent (
1666 if (EFI_ERROR (Status
)) {
1667 return EFI_OUT_OF_RESOURCES
;
1673 Status
= Udp4
->Receive (Udp4
, &Token
);
1674 if (EFI_ERROR (Status
)) {
1675 if (Status
== EFI_ICMP_ERROR
) {
1676 Mode
->IcmpErrorReceived
= TRUE
;
1684 Status
= EFI_TIMEOUT
;
1688 // check whether this packet matches the filters
1690 if (EFI_ERROR (Token
.Status
)){
1694 RxData
= Token
.Packet
.RxData
;
1695 Session
= &RxData
->UdpSession
;
1699 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER
) != 0) {
1702 // Check UDP package by IP filter settings
1704 if (CheckIpByFilter (Mode
, Session
)) {
1713 // Match the destination ip of the received udp dgram
1715 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP
) != 0) {
1718 if (DestIp
!= NULL
) {
1719 CopyMem (DestIp
, &Session
->DestinationAddress
, sizeof (EFI_IPv4_ADDRESS
));
1722 if (DestIp
!= NULL
) {
1723 if (EFI_IP4_EQUAL (DestIp
, &Session
->DestinationAddress
)) {
1727 if (EFI_IP4_EQUAL (&Private
->StationIp
, &Session
->DestinationAddress
)) {
1736 // Match the destination port of the received udp dgram
1738 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) != 0) {
1740 if (DestPort
!= NULL
) {
1741 *DestPort
= Session
->DestinationPort
;
1745 if (*DestPort
!= Session
->DestinationPort
) {
1753 // Match the source ip of the received udp dgram
1755 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP
) != 0) {
1757 if (SrcIp
!= NULL
) {
1758 CopyMem (SrcIp
, &Session
->SourceAddress
, sizeof (EFI_IPv4_ADDRESS
));
1762 if (!EFI_IP4_EQUAL (SrcIp
, &Session
->SourceAddress
)) {
1770 // Match the source port of the received udp dgram
1772 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT
) != 0) {
1774 if (SrcPort
!= NULL
) {
1775 *SrcPort
= Session
->SourcePort
;
1779 if (*SrcPort
!= Session
->SourcePort
) {
1789 if (HeaderSize
!= NULL
) {
1790 CopyLen
= MIN (*HeaderSize
, RxData
->DataLength
);
1791 CopyMem (HeaderPtr
, RxData
->FragmentTable
[0].FragmentBuffer
, CopyLen
);
1792 *HeaderSize
= CopyLen
;
1795 if (RxData
->DataLength
- CopyLen
> *BufferSize
) {
1797 Status
= EFI_BUFFER_TOO_SMALL
;
1800 *BufferSize
= RxData
->DataLength
- CopyLen
;
1803 (UINT8
*) RxData
->FragmentTable
[0].FragmentBuffer
+ CopyLen
,
1809 Status
= EFI_TIMEOUT
;
1813 // Recycle the RxData
1815 gBS
->SignalEvent (RxData
->RecycleSignal
);
1824 Udp4
->Cancel (Udp4
, &Token
);
1826 gBS
->CloseEvent (Token
.Event
);
1832 Updates the IP receive filters of a network device and enables software filtering.
1834 The NewFilter field is used to modify the network device's current IP receive
1835 filter settings and to enable a software filter. This function updates the IpFilter
1836 field of the EFI_PXE_BASE_CODE_MODE structure with the contents of NewIpFilter.
1837 The software filter is used when the USE_FILTER in OpFlags is set to UdpRead().
1838 The current hardware filter remains in effect no matter what the settings of OpFlags
1839 are, so that the meaning of ANY_DEST_IP set in OpFlags to UdpRead() is from those
1840 packets whose reception is enabled in hardware-physical NIC address (unicast),
1841 broadcast address, logical address or addresses (multicast), or all (promiscuous).
1842 UdpRead() does not modify the IP filter settings.
1843 Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP receive
1844 filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1845 If an application or driver wishes to preserve the IP receive filter settings,
1846 it will have to preserve the IP receive filter settings before these calls, and
1847 use SetIpFilter() to restore them after the calls. If incompatible filtering is
1848 requested (for example, PROMISCUOUS with anything else) or if the device does not
1849 support a requested filter setting and it cannot be accommodated in software
1850 (for example, PROMISCUOUS not supported), EFI_INVALID_PARAMETER will be returned.
1851 The IPlist field is used to enable IPs other than the StationIP. They may be
1852 multicast or unicast. If IPcnt is set as well as EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP,
1853 then both the StationIP and the IPs from the IPlist will be used.
1855 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1856 @param NewFilter Pointer to the new set of IP receive filters.
1858 @retval EFI_SUCCESS The IP receive filter settings were updated.
1859 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1860 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1865 EfiPxeBcSetIpFilter (
1866 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1867 IN EFI_PXE_BASE_CODE_IP_FILTER
*NewFilter
1871 PXEBC_PRIVATE_DATA
*Private
;
1872 EFI_PXE_BASE_CODE_MODE
*Mode
;
1874 EFI_UDP4_CONFIG_DATA
*Udp4Cfg
;
1875 BOOLEAN PromiscuousNeed
;
1876 BOOLEAN AcceptPromiscuous
;
1877 BOOLEAN AcceptBroadcast
;
1878 BOOLEAN MultiCastUpdate
;
1881 DEBUG ((EFI_D_ERROR
, "This == NULL.\n"));
1882 return EFI_INVALID_PARAMETER
;
1885 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1886 Mode
= Private
->PxeBc
.Mode
;
1888 if (NewFilter
== NULL
) {
1889 DEBUG ((EFI_D_ERROR
, "NewFilter == NULL.\n"));
1890 return EFI_INVALID_PARAMETER
;
1893 if (NewFilter
->IpCnt
> EFI_PXE_BASE_CODE_MAX_IPCNT
) {
1894 DEBUG ((EFI_D_ERROR
, "NewFilter->IpCnt > %d.\n", EFI_PXE_BASE_CODE_MAX_IPCNT
));
1895 return EFI_INVALID_PARAMETER
;
1898 if (!Mode
->Started
) {
1899 DEBUG ((EFI_D_ERROR
, "BC was not started.\n"));
1900 return EFI_NOT_STARTED
;
1903 if (Mode
->UsingIpv6
) {
1904 DEBUG ((EFI_D_ERROR
, "This driver is PXE for IPv4 Only.\n"));
1905 return EFI_INVALID_PARAMETER
;
1908 PromiscuousNeed
= FALSE
;
1910 for (Index
= 0; Index
< NewFilter
->IpCnt
; ++Index
) {
1911 if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (NewFilter
->IpList
[Index
].v4
))) {
1913 // The IP is a broadcast address.
1915 DEBUG ((EFI_D_ERROR
, "There is broadcast address in NewFilter.\n"));
1916 return EFI_INVALID_PARAMETER
;
1918 if (NetIp4IsUnicast (EFI_IP4 (NewFilter
->IpList
[Index
].v4
), 0) &&
1919 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0)
1922 // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList,
1923 // promiscuous mode is needed.
1925 PromiscuousNeed
= TRUE
;
1929 AcceptPromiscuous
= FALSE
;
1930 AcceptBroadcast
= FALSE
;
1931 MultiCastUpdate
= FALSE
;
1933 if (PromiscuousNeed
||
1934 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) != 0) ||
1935 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
) != 0)
1938 // Configure the udp4 filter to receive all packages.
1940 AcceptPromiscuous
= TRUE
;
1941 } else if ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST
) != 0) {
1943 // Configure the udp4 filter to receive all broadcast packages.
1945 AcceptBroadcast
= TRUE
;
1949 // In multicast condition when Promiscuous FALSE and IpCnt no-zero.
1950 // Here check if there is any update of the multicast ip address. If yes,
1951 // we need leave the old multicast group (by Config UDP instance to NULL),
1952 // and join the new multicast group.
1954 if (!AcceptPromiscuous
) {
1955 if ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0) {
1956 if (Mode
->IpFilter
.IpCnt
!= NewFilter
->IpCnt
) {
1957 MultiCastUpdate
= TRUE
;
1958 } else if (CompareMem (Mode
->IpFilter
.IpList
, NewFilter
->IpList
, NewFilter
->IpCnt
* sizeof (EFI_IP_ADDRESS
)) != 0 ) {
1959 MultiCastUpdate
= TRUE
;
1965 // Check whether we need reconfigure the UDP instance.
1967 Udp4Cfg
= &Private
->Udp4CfgData
;
1968 if ((AcceptPromiscuous
!= Udp4Cfg
->AcceptPromiscuous
) ||
1969 (AcceptBroadcast
!= Udp4Cfg
->AcceptBroadcast
) || MultiCastUpdate
) {
1971 // Clear the UDP instance configuration, all joined groups will be left
1972 // during the operation.
1974 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
1977 // Configure the UDP instance with the new configuration.
1979 Udp4Cfg
->AcceptPromiscuous
= AcceptPromiscuous
;
1980 Udp4Cfg
->AcceptBroadcast
= AcceptBroadcast
;
1981 Status
= Private
->Udp4Read
->Configure (Private
->Udp4Read
, Udp4Cfg
);
1982 if (EFI_ERROR (Status
)) {
1987 // In not Promiscuous mode, need to join the new multicast group.
1989 if (!AcceptPromiscuous
) {
1990 for (Index
= 0; Index
< NewFilter
->IpCnt
; ++Index
) {
1991 if (IP4_IS_MULTICAST (EFI_NTOHL (NewFilter
->IpList
[Index
].v4
))) {
1993 // Join the mutilcast group.
1995 Status
= Private
->Udp4Read
->Groups (Private
->Udp4Read
, TRUE
, &NewFilter
->IpList
[Index
].v4
);
1996 if (EFI_ERROR (Status
)) {
2006 // Save the new filter.
2008 CopyMem (&Mode
->IpFilter
, NewFilter
, sizeof (Mode
->IpFilter
));
2015 Uses the ARP protocol to resolve a MAC address.
2017 This function uses the ARP protocol to resolve a MAC address. The UsingIpv6 field
2018 of the EFI_PXE_BASE_CODE_MODE structure is used to determine if IPv4 or IPv6
2019 addresses are being used. The IP address specified by IpAddr is used to resolve
2020 a MAC address. If the ARP protocol succeeds in resolving the specified address,
2021 then the ArpCacheEntries and ArpCache fields of the EFI_PXE_BASE_CODE_MODE structure
2022 are updated, and EFI_SUCCESS is returned. If MacAddr is not NULL, the resolved
2023 MAC address is placed there as well. If the PXE Base Code protocol is in the
2024 stopped state, then EFI_NOT_STARTED is returned. If the ARP protocol encounters
2025 a timeout condition while attempting to resolve an address, then EFI_TIMEOUT is
2026 returned. If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
2027 then EFI_ABORTED is returned.
2029 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2030 @param IpAddr Pointer to the IP address that is used to resolve a MAC address.
2031 @param MacAddr If not NULL, a pointer to the MAC address that was resolved with the
2034 @retval EFI_SUCCESS The IP or MAC address was resolved.
2035 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2036 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2037 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
2038 @retval EFI_ICMP_ERROR Something error occur with the ICMP packet message.
2044 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2045 IN EFI_IP_ADDRESS
* IpAddr
,
2046 IN EFI_MAC_ADDRESS
* MacAddr OPTIONAL
2049 PXEBC_PRIVATE_DATA
*Private
;
2050 EFI_PXE_BASE_CODE_MODE
*Mode
;
2052 EFI_MAC_ADDRESS TempMacAddr
;
2054 if (This
== NULL
|| IpAddr
== NULL
) {
2055 return EFI_INVALID_PARAMETER
;
2058 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2059 Mode
= Private
->PxeBc
.Mode
;
2061 if (!Mode
->Started
) {
2062 return EFI_NOT_STARTED
;
2065 if (!Private
->AddressIsOk
|| Mode
->UsingIpv6
) {
2067 // We can't resolve the IP address if we don't have a local address now.
2068 // Don't have ARP for IPv6.
2070 return EFI_INVALID_PARAMETER
;
2073 Mode
->IcmpErrorReceived
= FALSE
;
2075 if (!Mode
->AutoArp
) {
2077 // If AutoArp is set false, check arp cache
2079 UpdateArpCache (This
);
2080 if (!FindInArpCache (Mode
, &IpAddr
->v4
, &TempMacAddr
)) {
2081 return EFI_DEVICE_ERROR
;
2084 Status
= Private
->Arp
->Request (Private
->Arp
, &IpAddr
->v4
, NULL
, &TempMacAddr
);
2085 if (EFI_ERROR (Status
)) {
2086 if (Status
== EFI_ICMP_ERROR
) {
2087 Mode
->IcmpErrorReceived
= TRUE
;
2093 if (MacAddr
!= NULL
) {
2094 CopyMem (MacAddr
, &TempMacAddr
, sizeof (EFI_MAC_ADDRESS
));
2101 Updates the parameters that affect the operation of the PXE Base Code Protocol.
2103 This function sets parameters that affect the operation of the PXE Base Code Protocol.
2104 The parameter specified by NewAutoArp is used to control the generation of ARP
2105 protocol packets. If NewAutoArp is TRUE, then ARP Protocol packets will be generated
2106 as required by the PXE Base Code Protocol. If NewAutoArp is FALSE, then no ARP
2107 Protocol packets will be generated. In this case, the only mappings that are
2108 available are those stored in the ArpCache of the EFI_PXE_BASE_CODE_MODE structure.
2109 If there are not enough mappings in the ArpCache to perform a PXE Base Code Protocol
2110 service, then the service will fail. This function updates the AutoArp field of
2111 the EFI_PXE_BASE_CODE_MODE structure to NewAutoArp.
2112 The SetParameters() call must be invoked after a Callback Protocol is installed
2113 to enable the use of callbacks.
2115 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2116 @param NewAutoArp If not NULL, a pointer to a value that specifies whether to replace the
2117 current value of AutoARP.
2118 @param NewSendGUID If not NULL, a pointer to a value that specifies whether to replace the
2119 current value of SendGUID.
2120 @param NewTTL If not NULL, a pointer to be used in place of the current value of TTL,
2121 the "time to live" field of the IP header.
2122 @param NewToS If not NULL, a pointer to be used in place of the current value of ToS,
2123 the "type of service" field of the IP header.
2124 @param NewMakeCallback If not NULL, a pointer to a value that specifies whether to replace the
2125 current value of the MakeCallback field of the Mode structure.
2127 @retval EFI_SUCCESS The new parameters values were updated.
2128 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2129 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2134 EfiPxeBcSetParameters (
2135 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
2136 IN BOOLEAN
*NewAutoArp OPTIONAL
,
2137 IN BOOLEAN
*NewSendGUID OPTIONAL
,
2138 IN UINT8
*NewTTL OPTIONAL
,
2139 IN UINT8
*NewToS OPTIONAL
,
2140 IN BOOLEAN
*NewMakeCallback
// OPTIONAL
2143 PXEBC_PRIVATE_DATA
*Private
;
2144 EFI_PXE_BASE_CODE_MODE
*Mode
;
2147 Status
= EFI_SUCCESS
;
2150 Status
= EFI_INVALID_PARAMETER
;
2154 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2155 Mode
= Private
->PxeBc
.Mode
;
2157 if (NewSendGUID
!= NULL
&& *NewSendGUID
) {
2159 // FixMe, cann't locate SendGuid
2163 if (NewMakeCallback
!= NULL
&& *NewMakeCallback
) {
2165 Status
= gBS
->HandleProtocol (
2166 Private
->Controller
,
2167 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2168 (VOID
**) &Private
->PxeBcCallback
2170 if (EFI_ERROR (Status
) || (Private
->PxeBcCallback
->Callback
== NULL
)) {
2172 Status
= EFI_INVALID_PARAMETER
;
2177 if (!Mode
->Started
) {
2178 Status
= EFI_NOT_STARTED
;
2182 if (NewMakeCallback
!= NULL
) {
2184 if (*NewMakeCallback
) {
2186 // Update the Callback protocol.
2188 Status
= gBS
->HandleProtocol (
2189 Private
->Controller
,
2190 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2191 (VOID
**) &Private
->PxeBcCallback
2194 if (EFI_ERROR (Status
) || (Private
->PxeBcCallback
->Callback
== NULL
)) {
2195 Status
= EFI_INVALID_PARAMETER
;
2199 Private
->PxeBcCallback
= NULL
;
2202 Mode
->MakeCallbacks
= *NewMakeCallback
;
2205 if (NewAutoArp
!= NULL
) {
2206 Mode
->AutoArp
= *NewAutoArp
;
2209 if (NewSendGUID
!= NULL
) {
2210 Mode
->SendGUID
= *NewSendGUID
;
2213 if (NewTTL
!= NULL
) {
2214 Mode
->TTL
= *NewTTL
;
2217 if (NewToS
!= NULL
) {
2218 Mode
->ToS
= *NewToS
;
2226 Updates the station IP address and/or subnet mask values of a network device.
2228 This function updates the station IP address and/or subnet mask values of a network
2229 device. The NewStationIp field is used to modify the network device's current IP address.
2230 If NewStationIP is NULL, then the current IP address will not be modified. Otherwise,
2231 this function updates the StationIp field of the EFI_PXE_BASE_CODE_MODE structure
2232 with NewStationIp. The NewSubnetMask field is used to modify the network device's current subnet
2233 mask. If NewSubnetMask is NULL, then the current subnet mask will not be modified.
2234 Otherwise, this function updates the SubnetMask field of the EFI_PXE_BASE_CODE_MODE
2235 structure with NewSubnetMask.
2237 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2238 @param NewStationIp Pointer to the new IP address to be used by the network device.
2239 @param NewSubnetMask Pointer to the new subnet mask to be used by the network device.
2241 @retval EFI_SUCCESS The new station IP address and/or subnet mask were updated.
2242 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2243 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2248 EfiPxeBcSetStationIP (
2249 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2250 IN EFI_IP_ADDRESS
* NewStationIp OPTIONAL
,
2251 IN EFI_IP_ADDRESS
* NewSubnetMask OPTIONAL
2254 PXEBC_PRIVATE_DATA
*Private
;
2255 EFI_PXE_BASE_CODE_MODE
*Mode
;
2256 EFI_ARP_CONFIG_DATA ArpConfigData
;
2259 return EFI_INVALID_PARAMETER
;
2262 if (NewStationIp
!= NULL
&& !NetIp4IsUnicast (NTOHL (NewStationIp
->Addr
[0]), 0)) {
2263 return EFI_INVALID_PARAMETER
;
2266 if (NewSubnetMask
!= NULL
&& !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask
->Addr
[0]))) {
2267 return EFI_INVALID_PARAMETER
;
2270 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2271 Mode
= Private
->PxeBc
.Mode
;
2273 if (!Mode
->Started
) {
2274 return EFI_NOT_STARTED
;
2277 if (NewStationIp
!= NULL
) {
2278 CopyMem (&Mode
->StationIp
, NewStationIp
, sizeof (EFI_IP_ADDRESS
));
2279 CopyMem (&Private
->StationIp
, NewStationIp
, sizeof (EFI_IP_ADDRESS
));
2282 if (NewSubnetMask
!= NULL
) {
2283 CopyMem (&Mode
->SubnetMask
, NewSubnetMask
, sizeof (EFI_IP_ADDRESS
));
2284 CopyMem (&Private
->SubnetMask
,NewSubnetMask
, sizeof (EFI_IP_ADDRESS
));
2287 Private
->AddressIsOk
= TRUE
;
2289 if (!Mode
->UsingIpv6
) {
2291 // If in IPv4 mode, configure the corresponding ARP with this new
2292 // station IP address.
2294 ZeroMem (&ArpConfigData
, sizeof (EFI_ARP_CONFIG_DATA
));
2296 ArpConfigData
.SwAddressType
= 0x0800;
2297 ArpConfigData
.SwAddressLength
= (UINT8
) sizeof (EFI_IPv4_ADDRESS
);
2298 ArpConfigData
.StationAddress
= &Private
->StationIp
.v4
;
2300 Private
->Arp
->Configure (Private
->Arp
, NULL
);
2301 Private
->Arp
->Configure (Private
->Arp
, &ArpConfigData
);
2304 // Update the route table.
2306 Mode
->RouteTableEntries
= 1;
2307 Mode
->RouteTable
[0].IpAddr
.Addr
[0] = Private
->StationIp
.Addr
[0] & Private
->SubnetMask
.Addr
[0];
2308 Mode
->RouteTable
[0].SubnetMask
.Addr
[0] = Private
->SubnetMask
.Addr
[0];
2309 Mode
->RouteTable
[0].GwAddr
.Addr
[0] = 0;
2316 Updates the contents of the cached DHCP and Discover packets.
2318 The pointers to the new packets are used to update the contents of the cached
2319 packets in the EFI_PXE_BASE_CODE_MODE structure.
2321 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2322 @param NewDhcpDiscoverValid Pointer to a value that will replace the current
2323 DhcpDiscoverValid field.
2324 @param NewDhcpAckReceived Pointer to a value that will replace the current
2325 DhcpAckReceived field.
2326 @param NewProxyOfferReceived Pointer to a value that will replace the current
2327 ProxyOfferReceived field.
2328 @param NewPxeDiscoverValid Pointer to a value that will replace the current
2329 ProxyOfferReceived field.
2330 @param NewPxeReplyReceived Pointer to a value that will replace the current
2331 PxeReplyReceived field.
2332 @param NewPxeBisReplyReceived Pointer to a value that will replace the current
2333 PxeBisReplyReceived field.
2334 @param NewDhcpDiscover Pointer to the new cached DHCP Discover packet contents.
2335 @param NewDhcpAck Pointer to the new cached DHCP Ack packet contents.
2336 @param NewProxyOffer Pointer to the new cached Proxy Offer packet contents.
2337 @param NewPxeDiscover Pointer to the new cached PXE Discover packet contents.
2338 @param NewPxeReply Pointer to the new cached PXE Reply packet contents.
2339 @param NewPxeBisReply Pointer to the new cached PXE BIS Reply packet contents.
2341 @retval EFI_SUCCESS The cached packet contents were updated.
2342 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2343 @retval EFI_INVALID_PARAMETER This is NULL or not point to a valid EFI_PXE_BASE_CODE_PROTOCOL structure.
2348 EfiPxeBcSetPackets (
2349 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2350 IN BOOLEAN
* NewDhcpDiscoverValid OPTIONAL
,
2351 IN BOOLEAN
* NewDhcpAckReceived OPTIONAL
,
2352 IN BOOLEAN
* NewProxyOfferReceived OPTIONAL
,
2353 IN BOOLEAN
* NewPxeDiscoverValid OPTIONAL
,
2354 IN BOOLEAN
* NewPxeReplyReceived OPTIONAL
,
2355 IN BOOLEAN
* NewPxeBisReplyReceived OPTIONAL
,
2356 IN EFI_PXE_BASE_CODE_PACKET
* NewDhcpDiscover OPTIONAL
,
2357 IN EFI_PXE_BASE_CODE_PACKET
* NewDhcpAck OPTIONAL
,
2358 IN EFI_PXE_BASE_CODE_PACKET
* NewProxyOffer OPTIONAL
,
2359 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeDiscover OPTIONAL
,
2360 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeReply OPTIONAL
,
2361 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeBisReply OPTIONAL
2364 PXEBC_PRIVATE_DATA
*Private
;
2365 EFI_PXE_BASE_CODE_MODE
*Mode
;
2368 return EFI_INVALID_PARAMETER
;
2371 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2372 Mode
= Private
->PxeBc
.Mode
;
2374 if (!Mode
->Started
) {
2375 return EFI_NOT_STARTED
;
2378 if (NewDhcpDiscoverValid
!= NULL
) {
2379 Mode
->DhcpDiscoverValid
= *NewDhcpDiscoverValid
;
2382 if (NewDhcpAckReceived
!= NULL
) {
2383 Mode
->DhcpAckReceived
= *NewDhcpAckReceived
;
2386 if (NewProxyOfferReceived
!= NULL
) {
2387 Mode
->ProxyOfferReceived
= *NewProxyOfferReceived
;
2390 if (NewPxeDiscoverValid
!= NULL
) {
2391 Mode
->PxeDiscoverValid
= *NewPxeDiscoverValid
;
2394 if (NewPxeReplyReceived
!= NULL
) {
2395 Mode
->PxeReplyReceived
= *NewPxeReplyReceived
;
2398 if (NewPxeBisReplyReceived
!= NULL
) {
2399 Mode
->PxeBisReplyReceived
= *NewPxeBisReplyReceived
;
2402 if (NewDhcpDiscover
!= NULL
) {
2403 CopyMem (&Mode
->DhcpDiscover
, NewDhcpDiscover
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2406 if (NewDhcpAck
!= NULL
) {
2407 CopyMem (&Mode
->DhcpAck
, NewDhcpAck
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2410 if (NewProxyOffer
!= NULL
) {
2411 CopyMem (&Mode
->ProxyOffer
, NewProxyOffer
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2414 if (NewPxeDiscover
!= NULL
) {
2415 CopyMem (&Mode
->PxeDiscover
, NewPxeDiscover
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2418 if (NewPxeReply
!= NULL
) {
2419 CopyMem (&Mode
->PxeReply
, NewPxeReply
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2422 if (NewPxeBisReply
!= NULL
) {
2423 CopyMem (&Mode
->PxeBisReply
, NewPxeBisReply
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2429 EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate
= {
2430 EFI_PXE_BASE_CODE_PROTOCOL_REVISION
,
2438 EfiPxeBcSetIpFilter
,
2440 EfiPxeBcSetParameters
,
2441 EfiPxeBcSetStationIP
,
2447 Callback function that is invoked when the PXE Base Code Protocol is about to transmit, has
2448 received, or is waiting to receive a packet.
2450 This function is invoked when the PXE Base Code Protocol is about to transmit, has received,
2451 or is waiting to receive a packet. Parameters Function and Received specify the type of event.
2452 Parameters PacketLen and Packet specify the packet that generated the event. If these fields
2453 are zero and NULL respectively, then this is a status update callback. If the operation specified
2454 by Function is to continue, then CALLBACK_STATUS_CONTINUE should be returned. If the operation
2455 specified by Function should be aborted, then CALLBACK_STATUS_ABORT should be returned. Due to
2456 the polling nature of UEFI device drivers, a callback function should not execute for more than 5 ms.
2457 The SetParameters() function must be called after a Callback Protocol is installed to enable the
2460 @param This Pointer to the EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL instance.
2461 @param Function The PXE Base Code Protocol function that is waiting for an event.
2462 @param Received TRUE if the callback is being invoked due to a receive event. FALSE if
2463 the callback is being invoked due to a transmit event.
2464 @param PacketLength The length, in bytes, of Packet. This field will have a value of zero if
2465 this is a wait for receive event.
2466 @param PacketPtr If Received is TRUE, a pointer to the packet that was just received;
2467 otherwise a pointer to the packet that is about to be transmitted.
2469 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE if Function specifies a continue operation
2470 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT if Function specifies an abort operation
2473 EFI_PXE_BASE_CODE_CALLBACK_STATUS
2475 EfiPxeLoadFileCallback (
2476 IN EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL
* This
,
2477 IN EFI_PXE_BASE_CODE_FUNCTION Function
,
2478 IN BOOLEAN Received
,
2479 IN UINT32 PacketLength
,
2480 IN EFI_PXE_BASE_CODE_PACKET
* PacketPtr OPTIONAL
2487 // Catch Ctrl-C or ESC to abort.
2489 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2491 if (!EFI_ERROR (Status
)) {
2493 if (Key
.ScanCode
== SCAN_ESC
|| Key
.UnicodeChar
== (0x1F & 'c')) {
2495 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT
;
2499 // No print if receive packet
2502 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2505 // Print only for three functions
2509 case EFI_PXE_BASE_CODE_FUNCTION_MTFTP
:
2511 // Print only for open MTFTP packets, not every MTFTP packets
2513 if (PacketLength
!= 0 && PacketPtr
!= NULL
) {
2514 if (PacketPtr
->Raw
[0x1C] != 0x00 || PacketPtr
->Raw
[0x1D] != 0x01) {
2515 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2520 case EFI_PXE_BASE_CODE_FUNCTION_DHCP
:
2521 case EFI_PXE_BASE_CODE_FUNCTION_DISCOVER
:
2525 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2528 if (PacketLength
!= 0 && PacketPtr
!= NULL
) {
2530 // Print '.' when transmit a packet
2536 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2539 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL mPxeBcCallBackTemplate
= {
2540 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_REVISION
,
2541 EfiPxeLoadFileCallback
2548 @param Private Pointer to PxeBc private data.
2549 @param BufferSize Pointer to buffer size.
2550 @param Buffer Pointer to buffer.
2552 @retval EFI_SUCCESS Discover the boot file successfully.
2553 @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.
2554 @retval EFI_ABORTED PXE bootstrap server, so local boot need abort.
2555 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to load the boot file.
2560 IN PXEBC_PRIVATE_DATA
*Private
,
2561 IN OUT UINT64
*BufferSize
,
2565 EFI_PXE_BASE_CODE_PROTOCOL
*PxeBc
;
2566 EFI_PXE_BASE_CODE_MODE
*Mode
;
2571 PXEBC_CACHED_DHCP4_PACKET
*Packet
;
2574 PxeBc
= &Private
->PxeBc
;
2576 Type
= EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP
;
2577 Layer
= EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL
;
2582 Status
= PxeBc
->Dhcp (PxeBc
, TRUE
);
2583 if (EFI_ERROR (Status
)) {
2588 // Select a boot server
2590 Status
= PxeBcSelectBootPrompt (Private
);
2592 if (Status
== EFI_SUCCESS
) {
2593 Status
= PxeBcSelectBootMenu (Private
, &Type
, TRUE
);
2594 } else if (Status
== EFI_TIMEOUT
) {
2595 Status
= PxeBcSelectBootMenu (Private
, &Type
, FALSE
);
2598 if (!EFI_ERROR (Status
)) {
2600 if (Type
== EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP
) {
2602 // Local boot(PXE bootstrap server) need abort
2607 UseBis
= (BOOLEAN
) (Mode
->BisSupported
&& Mode
->BisDetected
);
2608 Status
= PxeBc
->Discover (PxeBc
, Type
, &Layer
, UseBis
, NULL
);
2609 if (EFI_ERROR (Status
)) {
2617 // Get bootfile name and (m)tftp server ip addresss
2619 if (Mode
->PxeReplyReceived
) {
2620 Packet
= &Private
->PxeReply
;
2621 } else if (Mode
->ProxyOfferReceived
) {
2622 Packet
= &Private
->ProxyOffer
;
2624 Packet
= &Private
->Dhcp4Ack
;
2628 // Use siaddr(next server) in DHCPOFFER packet header, if zero, use option 54(server identifier)
2629 // in DHCPOFFER packet.
2630 // (It does not comply with PXE Spec, Ver2.1)
2632 if (EFI_IP4_EQUAL (&Packet
->Packet
.Offer
.Dhcp4
.Header
.ServerAddr
, &mZeroIp4Addr
)) {
2635 Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_SERVER_ID
]->Data
,
2636 sizeof (EFI_IPv4_ADDRESS
)
2641 &Packet
->Packet
.Offer
.Dhcp4
.Header
.ServerAddr
,
2642 sizeof (EFI_IPv4_ADDRESS
)
2645 if (Private
->ServerIp
.Addr
[0] == 0) {
2646 return EFI_DEVICE_ERROR
;
2649 ASSERT (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE
] != NULL
);
2654 Private
->BootFileName
= (CHAR8
*) (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE
]->Data
);
2656 if (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN
] != NULL
) {
2658 // Already have the bootfile length option, compute the file size
2660 CopyMem (&Value
, Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN
]->Data
, sizeof (Value
));
2661 Value
= NTOHS (Value
);
2662 *BufferSize
= 512 * Value
;
2663 Status
= EFI_BUFFER_TOO_SMALL
;
2666 // Get the bootfile size from tftp
2668 Status
= PxeBc
->Mtftp (
2670 EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE
,
2674 &Private
->BlockSize
,
2676 (UINT8
*) Private
->BootFileName
,
2682 Private
->FileSize
= (UINTN
) *BufferSize
;
2688 Causes the driver to load a specified file.
2690 @param This Protocol instance pointer.
2691 @param FilePath The device specific path of the file to load.
2692 @param BootPolicy If TRUE, indicates that the request originates from the
2693 boot manager is attempting to load FilePath as a boot
2694 selection. If FALSE, then FilePath must match as exact file
2696 @param BufferSize On input the size of Buffer in bytes. On output with a return
2697 code of EFI_SUCCESS, the amount of data transferred to
2698 Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
2699 the size of Buffer required to retrieve the requested file.
2700 @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
2701 then no the size of the requested file is returned in
2704 @retval EFI_SUCCESS The file was loaded.
2705 @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy
2706 @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or
2708 @retval EFI_NO_MEDIA No medium was present to load the file.
2709 @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.
2710 @retval EFI_NO_RESPONSE The remote system did not respond.
2711 @retval EFI_NOT_FOUND The file was not found.
2712 @retval EFI_ABORTED The file load process was manually cancelled.
2718 IN EFI_LOAD_FILE_PROTOCOL
* This
,
2719 IN EFI_DEVICE_PATH_PROTOCOL
* FilePath
,
2720 IN BOOLEAN BootPolicy
,
2721 IN OUT UINTN
*BufferSize
,
2722 IN VOID
*Buffer OPTIONAL
2725 PXEBC_PRIVATE_DATA
*Private
;
2726 EFI_PXE_BASE_CODE_PROTOCOL
*PxeBc
;
2727 BOOLEAN NewMakeCallback
;
2730 BOOLEAN MediaPresent
;
2732 Private
= PXEBC_PRIVATE_DATA_FROM_LOADFILE (This
);
2733 PxeBc
= &Private
->PxeBc
;
2734 NewMakeCallback
= FALSE
;
2735 Status
= EFI_DEVICE_ERROR
;
2737 if (This
== NULL
|| BufferSize
== NULL
) {
2739 return EFI_INVALID_PARAMETER
;
2743 // Only support BootPolicy
2746 return EFI_UNSUPPORTED
;
2750 // Check media status before PXE start
2752 MediaPresent
= TRUE
;
2753 NetLibDetectMedia (Private
->Controller
, &MediaPresent
);
2754 if (!MediaPresent
) {
2755 return EFI_NO_MEDIA
;
2758 Status
= PxeBc
->Start (PxeBc
, FALSE
);
2759 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
2763 Status
= gBS
->HandleProtocol (
2764 Private
->Controller
,
2765 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2766 (VOID
**) &Private
->PxeBcCallback
2768 if (Status
== EFI_UNSUPPORTED
) {
2770 CopyMem (&Private
->LoadFileCallback
, &mPxeBcCallBackTemplate
, sizeof (Private
->LoadFileCallback
));
2772 Status
= gBS
->InstallProtocolInterface (
2773 &Private
->Controller
,
2774 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2775 EFI_NATIVE_INTERFACE
,
2776 &Private
->LoadFileCallback
2779 NewMakeCallback
= (BOOLEAN
) (Status
== EFI_SUCCESS
);
2781 Status
= PxeBc
->SetParameters (PxeBc
, NULL
, NULL
, NULL
, NULL
, &NewMakeCallback
);
2782 if (EFI_ERROR (Status
)) {
2783 PxeBc
->Stop (PxeBc
);
2788 if (Private
->FileSize
== 0) {
2790 Status
= DiscoverBootFile (Private
, &TmpBufSize
, Buffer
);
2792 if (sizeof (UINTN
) < sizeof (UINT64
) && (TmpBufSize
> 0xFFFFFFFF)) {
2793 Status
= EFI_DEVICE_ERROR
;
2794 } else if (TmpBufSize
> 0 && *BufferSize
>= (UINTN
) TmpBufSize
&& Buffer
!= NULL
) {
2795 *BufferSize
= (UINTN
) TmpBufSize
;
2796 Status
= PxeBc
->Mtftp (
2798 EFI_PXE_BASE_CODE_TFTP_READ_FILE
,
2802 &Private
->BlockSize
,
2804 (UINT8
*) Private
->BootFileName
,
2808 } else if (TmpBufSize
> 0) {
2809 *BufferSize
= (UINTN
) TmpBufSize
;
2810 Status
= EFI_BUFFER_TOO_SMALL
;
2812 } else if (Buffer
== NULL
|| Private
->FileSize
> *BufferSize
) {
2813 *BufferSize
= Private
->FileSize
;
2814 Status
= EFI_BUFFER_TOO_SMALL
;
2817 // Download the file.
2819 TmpBufSize
= (UINT64
) (*BufferSize
);
2820 Status
= PxeBc
->Mtftp (
2822 EFI_PXE_BASE_CODE_TFTP_READ_FILE
,
2826 &Private
->BlockSize
,
2828 (UINT8
*) Private
->BootFileName
,
2834 // If we added a callback protocol, now is the time to remove it.
2836 if (NewMakeCallback
) {
2838 NewMakeCallback
= FALSE
;
2840 PxeBc
->SetParameters (PxeBc
, NULL
, NULL
, NULL
, NULL
, &NewMakeCallback
);
2842 gBS
->UninstallProtocolInterface (
2843 Private
->Controller
,
2844 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2845 &Private
->LoadFileCallback
2850 // Check download status
2852 if (Status
== EFI_SUCCESS
) {
2854 // The functionality of PXE Base Code protocol will not be stopped,
2855 // when downloading is successfully.
2859 } else if (Status
== EFI_BUFFER_TOO_SMALL
) {
2860 if (Buffer
!= NULL
) {
2861 AsciiPrint ("PXE-E05: Download buffer is smaller than requested file.\n");
2864 // The functionality of PXE Base Code protocol will not be stopped.
2869 } else if (Status
== EFI_DEVICE_ERROR
) {
2870 AsciiPrint ("PXE-E07: Network device error.\n");
2872 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
2873 AsciiPrint ("PXE-E09: Could not allocate I/O buffers.\n");
2875 } else if (Status
== EFI_NO_MEDIA
) {
2876 AsciiPrint ("PXE-E12: Could not detect network connection.\n");
2878 } else if (Status
== EFI_NO_RESPONSE
) {
2879 AsciiPrint ("PXE-E16: No offer received.\n");
2881 } else if (Status
== EFI_TIMEOUT
) {
2882 AsciiPrint ("PXE-E18: Server response timeout.\n");
2884 } else if (Status
== EFI_ABORTED
) {
2885 AsciiPrint ("PXE-E21: Remote boot cancelled.\n");
2887 } else if (Status
== EFI_ICMP_ERROR
) {
2888 AsciiPrint ("PXE-E22: Client received ICMP error from server.\n");
2890 } else if (Status
== EFI_TFTP_ERROR
) {
2891 AsciiPrint ("PXE-E23: Client received TFTP error from server.\n");
2894 AsciiPrint ("PXE-E99: Unexpected network error.\n");
2897 PxeBc
->Stop (PxeBc
);
2902 EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate
= { EfiPxeLoadFile
};