2 Interface routines for PxeBc.
4 Copyright (c) 2007 - 2015, 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
)) {
414 //DHCP4 service allows only one of its children to be configured in
415 //the active state, If the DHCP4 D.O.R.A started by IP4 auto
416 //configuration and has not been completed, the Dhcp4 state machine
417 //will not be in the right state for the PXE to start a new round D.O.R.A.
418 //so we need to switch it's policy to static.
420 Status
= PxeBcSetIp4Policy (Private
);
421 if (EFI_ERROR (Status
)) {
425 Status
= Private
->Ip4
->Configure (Private
->Ip4
, &Private
->Ip4ConfigData
);
426 if (EFI_ERROR (Status
)) {
431 // start to listen incoming packet
433 Status
= Private
->Ip4
->Receive (Private
->Ip4
, &Private
->IcmpErrorRcvToken
);
434 if (!EFI_ERROR (Status
)) {
439 Private
->Ip4
->Configure (Private
->Ip4
, NULL
);
441 if (Private
->IcmpErrorRcvToken
.Event
!= NULL
) {
442 gBS
->CloseEvent (Private
->IcmpErrorRcvToken
.Event
);
445 if (Private
->GetArpCacheEvent
!= NULL
) {
446 gBS
->SetTimer (Private
->GetArpCacheEvent
, TimerCancel
, 0);
447 gBS
->CloseEvent (Private
->GetArpCacheEvent
);
450 Mode
->Started
= FALSE
;
453 Mode
->AutoArp
= FALSE
;
460 Disables the use of the PXE Base Code Protocol functions.
462 This function stops all activity on the network device. All the resources allocated
463 in Start() are released, the Started field of the EFI_PXE_BASE_CODE_MODE structure is
464 set to FALSE and EFI_SUCCESS is returned. If the Started field of the EFI_PXE_BASE_CODE_MODE
465 structure is already FALSE, then EFI_NOT_STARTED will be returned.
467 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
469 @retval EFI_SUCCESS The PXE Base Code Protocol was stopped.
470 @retval EFI_NOT_STARTED The PXE Base Code Protocol is already in the stopped state.
471 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
472 EFI_PXE_BASE_CODE_PROTOCOL structure.
473 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
479 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
482 PXEBC_PRIVATE_DATA
*Private
;
483 EFI_PXE_BASE_CODE_MODE
*Mode
;
486 return EFI_INVALID_PARAMETER
;
489 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
490 Mode
= Private
->PxeBc
.Mode
;
492 if (!Mode
->Started
) {
493 return EFI_NOT_STARTED
;
496 Private
->Ip4
->Cancel (Private
->Ip4
, NULL
);
498 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
503 Private
->Ip4
->Configure (Private
->Ip4
, NULL
);
506 // Close the ICMP error receiving event.
508 gBS
->CloseEvent (Private
->IcmpErrorRcvToken
.Event
);
511 // Cancel the TimeoutEvent timer.
513 gBS
->SetTimer (Private
->GetArpCacheEvent
, TimerCancel
, 0);
516 // Close the TimeoutEvent event.
518 gBS
->CloseEvent (Private
->GetArpCacheEvent
);
520 Mode
->Started
= FALSE
;
522 Private
->CurrentUdpSrcPort
= 0;
523 Private
->Udp4Write
->Configure (Private
->Udp4Write
, NULL
);
524 Private
->Udp4Read
->Groups (Private
->Udp4Read
, FALSE
, NULL
);
525 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
527 Private
->Dhcp4
->Stop (Private
->Dhcp4
);
528 Private
->Dhcp4
->Configure (Private
->Dhcp4
, NULL
);
530 Private
->FileSize
= 0;
537 Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request / acknowledge) or DHCPv6
538 S.A.R.R (solicit / advertise / request / reply) sequence.
540 This function attempts to complete the DHCP sequence. If this sequence is completed,
541 then EFI_SUCCESS is returned, and the DhcpCompleted, ProxyOfferReceived, StationIp,
542 SubnetMask, DhcpDiscover, DhcpAck, and ProxyOffer fields of the EFI_PXE_BASE_CODE_MODE
543 structure are filled in.
544 If SortOffers is TRUE, then the cached DHCP offer packets will be sorted before
545 they are tried. If SortOffers is FALSE, then the cached DHCP offer packets will
546 be tried in the order in which they are received. Please see the Preboot Execution
547 Environment (PXE) Specification for additional details on the implementation of DHCP.
548 This function can take at least 31 seconds to timeout and return control to the
549 caller. If the DHCP sequence does not complete, then EFI_TIMEOUT will be returned.
550 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
551 then the DHCP sequence will be stopped and EFI_ABORTED will be returned.
553 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
554 @param SortOffers TRUE if the offers received should be sorted. Set to FALSE to try the
555 offers in the order that they are received.
557 @retval EFI_SUCCESS Valid DHCP has completed.
558 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
559 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
560 EFI_PXE_BASE_CODE_PROTOCOL structure.
561 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
562 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete the DHCP Protocol.
563 @retval EFI_ABORTED The callback function aborted the DHCP Protocol.
564 @retval EFI_TIMEOUT The DHCP Protocol timed out.
565 @retval EFI_ICMP_ERROR An ICMP error packet was received during the DHCP session.
566 @retval EFI_NO_RESPONSE Valid PXE offer was not received.
572 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
573 IN BOOLEAN SortOffers
576 PXEBC_PRIVATE_DATA
*Private
;
577 EFI_PXE_BASE_CODE_MODE
*Mode
;
578 EFI_DHCP4_PROTOCOL
*Dhcp4
;
579 EFI_DHCP4_CONFIG_DATA Dhcp4CfgData
;
580 EFI_DHCP4_MODE_DATA Dhcp4Mode
;
581 EFI_DHCP4_PACKET_OPTION
*OptList
[PXEBC_DHCP4_MAX_OPTION_NUM
];
584 EFI_ARP_CONFIG_DATA ArpConfigData
;
585 EFI_PXE_BASE_CODE_IP_FILTER IpFilter
;
588 return EFI_INVALID_PARAMETER
;
591 Status
= EFI_SUCCESS
;
592 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
593 Mode
= Private
->PxeBc
.Mode
;
594 Dhcp4
= Private
->Dhcp4
;
595 Private
->Function
= EFI_PXE_BASE_CODE_FUNCTION_DHCP
;
596 Private
->SortOffers
= SortOffers
;
598 if (!Mode
->Started
) {
599 return EFI_NOT_STARTED
;
602 Mode
->IcmpErrorReceived
= FALSE
;
605 // Stop Udp4Read instance
607 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
610 // Initialize the DHCP options and build the option list
612 OptCount
= PxeBcBuildDhcpOptions (Private
, OptList
, TRUE
);
615 // Set the DHCP4 config data.
616 // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.
618 ZeroMem (&Dhcp4CfgData
, sizeof (EFI_DHCP4_CONFIG_DATA
));
619 Dhcp4CfgData
.OptionCount
= OptCount
;
620 Dhcp4CfgData
.OptionList
= OptList
;
621 Dhcp4CfgData
.Dhcp4Callback
= PxeBcDhcpCallBack
;
622 Dhcp4CfgData
.CallbackContext
= Private
;
623 Dhcp4CfgData
.DiscoverTryCount
= 4;
624 Dhcp4CfgData
.DiscoverTimeout
= mPxeDhcpTimeout
;
626 Status
= Dhcp4
->Configure (Dhcp4
, &Dhcp4CfgData
);
627 if (EFI_ERROR (Status
)) {
632 // Zero those arrays to record the varies numbers of DHCP OFFERS.
634 Private
->GotProxyOffer
= FALSE
;
635 Private
->NumOffers
= 0;
636 Private
->BootpIndex
= 0;
637 ZeroMem (Private
->ServerCount
, sizeof (Private
->ServerCount
));
638 ZeroMem (Private
->ProxyIndex
, sizeof (Private
->ProxyIndex
));
640 Status
= Dhcp4
->Start (Dhcp4
, NULL
);
641 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
642 if (Status
== EFI_ICMP_ERROR
) {
643 Mode
->IcmpErrorReceived
= TRUE
;
648 Status
= Dhcp4
->GetModeData (Dhcp4
, &Dhcp4Mode
);
649 if (EFI_ERROR (Status
)) {
653 ASSERT (Dhcp4Mode
.State
== Dhcp4Bound
);
655 CopyMem (&Private
->StationIp
, &Dhcp4Mode
.ClientAddress
, sizeof (EFI_IPv4_ADDRESS
));
656 CopyMem (&Private
->SubnetMask
, &Dhcp4Mode
.SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
657 CopyMem (&Private
->GatewayIp
, &Dhcp4Mode
.RouterAddress
, sizeof (EFI_IPv4_ADDRESS
));
659 CopyMem (&Mode
->StationIp
, &Private
->StationIp
, sizeof (EFI_IPv4_ADDRESS
));
660 CopyMem (&Mode
->SubnetMask
, &Private
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
663 // Check the selected offer to see whether BINL is required, if no or BINL is
664 // finished, set the various Mode members.
666 Status
= PxeBcCheckSelectedOffer (Private
);
669 if (EFI_ERROR (Status
)) {
671 Dhcp4
->Configure (Dhcp4
, NULL
);
674 // Remove the previously configured option list and callback function
676 ZeroMem (&Dhcp4CfgData
, sizeof (EFI_DHCP4_CONFIG_DATA
));
677 Dhcp4
->Configure (Dhcp4
, &Dhcp4CfgData
);
679 Private
->AddressIsOk
= TRUE
;
681 if (!Mode
->UsingIpv6
) {
683 // If in IPv4 mode, configure the corresponding ARP with this new
684 // station IP address.
686 ZeroMem (&ArpConfigData
, sizeof (EFI_ARP_CONFIG_DATA
));
688 ArpConfigData
.SwAddressType
= 0x0800;
689 ArpConfigData
.SwAddressLength
= (UINT8
) sizeof (EFI_IPv4_ADDRESS
);
690 ArpConfigData
.StationAddress
= &Private
->StationIp
.v4
;
692 Private
->Arp
->Configure (Private
->Arp
, NULL
);
693 Private
->Arp
->Configure (Private
->Arp
, &ArpConfigData
);
696 // Updated the route table. Fill the first entry.
698 Mode
->RouteTableEntries
= 1;
699 Mode
->RouteTable
[0].IpAddr
.Addr
[0] = Private
->StationIp
.Addr
[0] & Private
->SubnetMask
.Addr
[0];
700 Mode
->RouteTable
[0].SubnetMask
.Addr
[0] = Private
->SubnetMask
.Addr
[0];
701 Mode
->RouteTable
[0].GwAddr
.Addr
[0] = 0;
704 // Create the default route entry if there is a default router.
706 if (Private
->GatewayIp
.Addr
[0] != 0) {
707 Mode
->RouteTableEntries
= 2;
708 Mode
->RouteTable
[1].IpAddr
.Addr
[0] = 0;
709 Mode
->RouteTable
[1].SubnetMask
.Addr
[0] = 0;
710 Mode
->RouteTable
[1].GwAddr
.Addr
[0] = Private
->GatewayIp
.Addr
[0];
714 // Flush new station IP address into Udp4CfgData and Ip4ConfigData
716 CopyMem (&Private
->Udp4CfgData
.StationAddress
, &Private
->StationIp
, sizeof (EFI_IPv4_ADDRESS
));
717 CopyMem (&Private
->Udp4CfgData
.SubnetMask
, &Private
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
718 CopyMem (&Private
->Ip4ConfigData
.StationAddress
, &Private
->StationIp
, sizeof (EFI_IPv4_ADDRESS
));
719 CopyMem (&Private
->Ip4ConfigData
.SubnetMask
, &Private
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
722 // Reconfigure the Ip4 instance to capture background ICMP packets with new station Ip address.
724 Private
->Ip4
->Cancel (Private
->Ip4
, &Private
->IcmpErrorRcvToken
);
725 Private
->Ip4
->Configure (Private
->Ip4
, NULL
);
727 Status
= Private
->Ip4
->Configure (Private
->Ip4
, &Private
->Ip4ConfigData
);
728 if (EFI_ERROR (Status
)) {
732 Status
= Private
->Ip4
->Receive (Private
->Ip4
, &Private
->IcmpErrorRcvToken
);
733 if (EFI_ERROR (Status
)) {
739 Private
->Udp4Read
->Configure (Private
->Udp4Read
, &Private
->Udp4CfgData
);
742 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
743 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
745 ZeroMem(&IpFilter
, sizeof (EFI_PXE_BASE_CODE_IP_FILTER
));
746 IpFilter
.Filters
= EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
;
747 This
->SetIpFilter (This
, &IpFilter
);
754 Attempts to complete the PXE Boot Server and/or boot image discovery sequence.
756 This function attempts to complete the PXE Boot Server and/or boot image discovery
757 sequence. If this sequence is completed, then EFI_SUCCESS is returned, and the
758 PxeDiscoverValid, PxeDiscover, PxeReplyReceived, and PxeReply fields of the
759 EFI_PXE_BASE_CODE_MODE structure are filled in. If UseBis is TRUE, then the
760 PxeBisReplyReceived and PxeBisReply fields of the EFI_PXE_BASE_CODE_MODE structure
761 will also be filled in. If UseBis is FALSE, then PxeBisReplyValid will be set to FALSE.
762 In the structure referenced by parameter Info, the PXE Boot Server list, SrvList[],
763 has two uses: It is the Boot Server IP address list used for unicast discovery
764 (if the UseUCast field is TRUE), and it is the list used for Boot Server verification
765 (if the MustUseList field is TRUE). Also, if the MustUseList field in that structure
766 is TRUE and the AcceptAnyResponse field in the SrvList[] array is TRUE, any Boot
767 Server reply of that type will be accepted. If the AcceptAnyResponse field is
768 FALSE, only responses from Boot Servers with matching IP addresses will be accepted.
769 This function can take at least 10 seconds to timeout and return control to the
770 caller. If the Discovery sequence does not complete, then EFI_TIMEOUT will be
771 returned. Please see the Preboot Execution Environment (PXE) Specification for
772 additional details on the implementation of the Discovery sequence.
773 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
774 then the Discovery sequence is stopped and EFI_ABORTED will be returned.
776 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
777 @param Type The type of bootstrap to perform.
778 @param Layer Pointer to the boot server layer number to discover, which must be
779 PXE_BOOT_LAYER_INITIAL when a new server type is being
781 @param UseBis TRUE if Boot Integrity Services are to be used. FALSE otherwise.
782 @param Info Pointer to a data structure that contains additional information on the
783 type of discovery operation that is to be performed.
785 @retval EFI_SUCCESS The Discovery sequence has been completed.
786 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
787 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
788 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
789 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete Discovery.
790 @retval EFI_ABORTED The callback function aborted the Discovery sequence.
791 @retval EFI_TIMEOUT The Discovery sequence timed out.
792 @retval EFI_ICMP_ERROR An ICMP error packet was received during the PXE discovery
799 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
803 IN EFI_PXE_BASE_CODE_DISCOVER_INFO
*Info OPTIONAL
806 PXEBC_PRIVATE_DATA
*Private
;
807 EFI_PXE_BASE_CODE_MODE
*Mode
;
808 EFI_PXE_BASE_CODE_DISCOVER_INFO DefaultInfo
;
809 EFI_PXE_BASE_CODE_DISCOVER_INFO
*CreatedInfo
;
810 EFI_PXE_BASE_CODE_SRVLIST
*SrvList
;
811 EFI_PXE_BASE_CODE_SRVLIST DefaultSrvList
;
812 PXEBC_CACHED_DHCP4_PACKET
*Packet
;
813 PXEBC_VENDOR_OPTION
*VendorOpt
;
816 PXEBC_BOOT_SVR_ENTRY
*BootSvrEntry
;
817 EFI_PXE_BASE_CODE_IP_FILTER IpFilter
;
820 return EFI_INVALID_PARAMETER
;
823 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
824 Mode
= Private
->PxeBc
.Mode
;
828 Status
= EFI_DEVICE_ERROR
;
829 Private
->Function
= EFI_PXE_BASE_CODE_FUNCTION_DISCOVER
;
831 if (!Private
->AddressIsOk
) {
832 return EFI_INVALID_PARAMETER
;
835 if (!Mode
->Started
) {
836 return EFI_NOT_STARTED
;
840 // Stop Udp4Read instance
842 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
844 Mode
->IcmpErrorReceived
= FALSE
;
847 // If layer isn't EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL,
848 // use the previous setting;
849 // If info isn't offered,
850 // use the cached DhcpAck and ProxyOffer packets.
852 ZeroMem (&DefaultInfo
, sizeof (EFI_PXE_BASE_CODE_DISCOVER_INFO
));
853 if (*Layer
!= EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL
) {
855 if (!Mode
->PxeDiscoverValid
|| !Mode
->PxeReplyReceived
|| (!Mode
->PxeBisReplyReceived
&& UseBis
)) {
857 Status
= EFI_INVALID_PARAMETER
;
861 DefaultInfo
.IpCnt
= 1;
862 DefaultInfo
.UseUCast
= TRUE
;
864 DefaultSrvList
.Type
= Type
;
865 DefaultSrvList
.AcceptAnyResponse
= FALSE
;
866 DefaultSrvList
.IpAddr
.Addr
[0] = Private
->ServerIp
.Addr
[0];
868 SrvList
= &DefaultSrvList
;
870 } else if (Info
== NULL
) {
872 // Create info by the cached packet before
874 Packet
= (Mode
->ProxyOfferReceived
) ? &Private
->ProxyOffer
: &Private
->Dhcp4Ack
;
875 VendorOpt
= &Packet
->PxeVendorOption
;
877 if (!Mode
->DhcpAckReceived
|| !IS_VALID_DISCOVER_VENDOR_OPTION (VendorOpt
->BitMap
)) {
879 // Address is not acquired or no discovery options.
881 Status
= EFI_INVALID_PARAMETER
;
885 DefaultInfo
.UseMCast
= (BOOLEAN
)!IS_DISABLE_MCAST_DISCOVER (VendorOpt
->DiscoverCtrl
);
886 DefaultInfo
.UseBCast
= (BOOLEAN
)!IS_DISABLE_BCAST_DISCOVER (VendorOpt
->DiscoverCtrl
);
887 DefaultInfo
.MustUseList
= (BOOLEAN
) IS_ENABLE_USE_SERVER_LIST (VendorOpt
->DiscoverCtrl
);
888 DefaultInfo
.UseUCast
= DefaultInfo
.MustUseList
;
890 if (DefaultInfo
.UseMCast
) {
892 // Get the multicast discover ip address from vendor option.
895 &DefaultInfo
.ServerMCastIp
.Addr
,
896 &VendorOpt
->DiscoverMcastIp
,
897 sizeof (EFI_IPv4_ADDRESS
)
901 DefaultInfo
.IpCnt
= 0;
903 SrvList
= Info
->SrvList
;
905 if (DefaultInfo
.MustUseList
) {
906 BootSvrEntry
= VendorOpt
->BootSvr
;
907 Status
= EFI_INVALID_PARAMETER
;
909 while (((UINT8
) (BootSvrEntry
- VendorOpt
->BootSvr
)) < VendorOpt
->BootSvrLen
) {
911 if (BootSvrEntry
->Type
== HTONS (Type
)) {
912 Status
= EFI_SUCCESS
;
916 BootSvrEntry
= GET_NEXT_BOOT_SVR_ENTRY (BootSvrEntry
);
919 if (EFI_ERROR (Status
)) {
923 DefaultInfo
.IpCnt
= BootSvrEntry
->IpCnt
;
925 if (DefaultInfo
.IpCnt
>= 1) {
926 CreatedInfo
= AllocatePool (sizeof (DefaultInfo
) + (DefaultInfo
.IpCnt
- 1) * sizeof (*SrvList
));
927 if (CreatedInfo
== NULL
) {
928 Status
= EFI_OUT_OF_RESOURCES
;
933 CopyMem (CreatedInfo
, &DefaultInfo
, sizeof (DefaultInfo
));
935 SrvList
= Info
->SrvList
;
938 for (Index
= 0; Index
< DefaultInfo
.IpCnt
; Index
++) {
939 CopyMem (&SrvList
[Index
].IpAddr
, &BootSvrEntry
->IpAddr
[Index
], sizeof (EFI_IPv4_ADDRESS
));
940 SrvList
[Index
].AcceptAnyResponse
= FALSE
;
941 SrvList
[Index
].Type
= BootSvrEntry
->Type
;
947 SrvList
= Info
->SrvList
;
949 if (!SrvList
[0].AcceptAnyResponse
) {
951 for (Index
= 1; Index
< Info
->IpCnt
; Index
++) {
952 if (SrvList
[Index
].AcceptAnyResponse
) {
957 if (Index
!= Info
->IpCnt
) {
958 Status
= EFI_INVALID_PARAMETER
;
964 if ((!Info
->UseUCast
&& !Info
->UseBCast
&& !Info
->UseMCast
) || (Info
->MustUseList
&& Info
->IpCnt
== 0)) {
966 Status
= EFI_INVALID_PARAMETER
;
970 // Execute discover by UniCast/BroadCast/MultiCast
972 if (Info
->UseUCast
) {
974 for (Index
= 0; Index
< Info
->IpCnt
; Index
++) {
976 if (BootSvrEntry
== NULL
) {
977 Private
->ServerIp
.Addr
[0] = SrvList
[Index
].IpAddr
.Addr
[0];
981 &BootSvrEntry
->IpAddr
[Index
],
982 sizeof (EFI_IPv4_ADDRESS
)
986 Status
= PxeBcDiscvBootService (
991 &SrvList
[Index
].IpAddr
,
995 &Private
->PxeReply
.Packet
.Ack
997 if (!EFI_ERROR (Status
)) {
1002 } else if (Info
->UseMCast
) {
1004 Status
= PxeBcDiscvBootService (
1009 &Info
->ServerMCastIp
,
1013 &Private
->PxeReply
.Packet
.Ack
1016 } else if (Info
->UseBCast
) {
1018 Status
= PxeBcDiscvBootService (
1027 &Private
->PxeReply
.Packet
.Ack
1031 if (EFI_ERROR (Status
) || !Mode
->PxeReplyReceived
|| (!Mode
->PxeBisReplyReceived
&& UseBis
)) {
1032 if (Status
== EFI_ICMP_ERROR
) {
1033 Mode
->IcmpErrorReceived
= TRUE
;
1035 Status
= EFI_DEVICE_ERROR
;
1039 PxeBcParseCachedDhcpPacket (&Private
->PxeReply
);
1042 if (Mode
->PxeBisReplyReceived
) {
1045 &Mode
->PxeReply
.Dhcpv4
.BootpSiAddr
,
1046 sizeof (EFI_IPv4_ADDRESS
)
1050 if (CreatedInfo
!= NULL
) {
1051 FreePool (CreatedInfo
);
1056 Private
->Udp4Read
->Configure (Private
->Udp4Read
, &Private
->Udp4CfgData
);
1059 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
1060 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1062 ZeroMem(&IpFilter
, sizeof (EFI_PXE_BASE_CODE_IP_FILTER
));
1063 IpFilter
.Filters
= EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
;
1064 This
->SetIpFilter (This
, &IpFilter
);
1071 Used to perform TFTP and MTFTP services.
1073 This function is used to perform TFTP and MTFTP services. This includes the
1074 TFTP operations to get the size of a file, read a directory, read a file, and
1075 write a file. It also includes the MTFTP operations to get the size of a file,
1076 read a directory, and read a file. The type of operation is specified by Operation.
1077 If the callback function that is invoked during the TFTP/MTFTP operation does
1078 not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will
1080 For read operations, the return data will be placed in the buffer specified by
1081 BufferPtr. If BufferSize is too small to contain the entire downloaded file,
1082 then EFI_BUFFER_TOO_SMALL will be returned and BufferSize will be set to zero
1083 or the size of the requested file (the size of the requested file is only returned
1084 if the TFTP server supports TFTP options). If BufferSize is large enough for the
1085 read operation, then BufferSize will be set to the size of the downloaded file,
1086 and EFI_SUCCESS will be returned. Applications using the PxeBc.Mtftp() services
1087 should use the get-file-size operations to determine the size of the downloaded
1088 file prior to using the read-file operations-especially when downloading large
1089 (greater than 64 MB) files-instead of making two calls to the read-file operation.
1090 Following this recommendation will save time if the file is larger than expected
1091 and the TFTP server does not support TFTP option extensions. Without TFTP option
1092 extension support, the client has to download the entire file, counting and discarding
1093 the received packets, to determine the file size.
1094 For write operations, the data to be sent is in the buffer specified by BufferPtr.
1095 BufferSize specifies the number of bytes to send. If the write operation completes
1096 successfully, then EFI_SUCCESS will be returned.
1097 For TFTP "get file size" operations, the size of the requested file or directory
1098 is returned in BufferSize, and EFI_SUCCESS will be returned. If the TFTP server
1099 does not support options, the file will be downloaded into a bit bucket and the
1100 length of the downloaded file will be returned. For MTFTP "get file size" operations,
1101 if the MTFTP server does not support the "get file size" option, EFI_UNSUPPORTED
1103 This function can take up to 10 seconds to timeout and return control to the caller.
1104 If the TFTP sequence does not complete, EFI_TIMEOUT will be returned.
1105 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
1106 then the TFTP sequence is stopped and EFI_ABORTED will be returned.
1107 The format of the data returned from a TFTP read directory operation is a null-terminated
1108 filename followed by a null-terminated information string, of the form
1109 "size year-month-day hour:minute:second" (i.e. %d %d-%d-%d %d:%d:%f - note that
1110 the seconds field can be a decimal number), where the date and time are UTC. For
1111 an MTFTP read directory command, there is additionally a null-terminated multicast
1112 IP address preceding the filename of the form %d.%d.%d.%d for IP v4. The final
1113 entry is itself null-terminated, so that the final information string is terminated
1114 with two null octets.
1116 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1117 @param Operation The type of operation to perform.
1118 @param BufferPtr A pointer to the data buffer.
1119 @param Overwrite Only used on write file operations. TRUE if a file on a remote server can
1121 @param BufferSize For get-file-size operations, *BufferSize returns the size of the
1123 @param BlockSize The requested block size to be used during a TFTP transfer.
1124 @param ServerIp The TFTP / MTFTP server IP address.
1125 @param Filename A Null-terminated ASCII string that specifies a directory name or a file
1127 @param Info Pointer to the MTFTP information.
1128 @param DontUseBuffer Set to FALSE for normal TFTP and MTFTP read file operation.
1130 @retval EFI_SUCCESS The TFTP/MTFTP operation was completed.
1131 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1132 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1133 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1134 @retval EFI_BUFFER_TOO_SMALL The buffer is not large enough to complete the read operation.
1135 @retval EFI_ABORTED The callback function aborted the TFTP/MTFTP operation.
1136 @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.
1137 @retval EFI_ICMP_ERROR An ICMP error packet was received during the MTFTP session.
1138 @retval EFI_TFTP_ERROR A TFTP error packet was received during the MTFTP session.
1144 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1145 IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation
,
1146 IN OUT VOID
*BufferPtr
,
1147 IN BOOLEAN Overwrite
,
1148 IN OUT UINT64
*BufferSize
,
1149 IN UINTN
*BlockSize OPTIONAL
,
1150 IN EFI_IP_ADDRESS
*ServerIp
,
1152 IN EFI_PXE_BASE_CODE_MTFTP_INFO
*Info OPTIONAL
,
1153 IN BOOLEAN DontUseBuffer
1156 PXEBC_PRIVATE_DATA
*Private
;
1157 EFI_MTFTP4_CONFIG_DATA Mtftp4Config
;
1159 EFI_PXE_BASE_CODE_MODE
*Mode
;
1160 EFI_MAC_ADDRESS TempMacAddr
;
1161 EFI_PXE_BASE_CODE_IP_FILTER IpFilter
;
1163 if ((This
== NULL
) ||
1164 (Filename
== NULL
) ||
1165 (BufferSize
== NULL
) ||
1166 ((ServerIp
== NULL
) || !NetIp4IsUnicast (NTOHL (ServerIp
->Addr
[0]), 0)) ||
1167 ((BufferPtr
== NULL
) && DontUseBuffer
) ||
1168 ((BlockSize
!= NULL
) && (*BlockSize
< 512))) {
1170 return EFI_INVALID_PARAMETER
;
1173 Status
= EFI_DEVICE_ERROR
;
1174 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1175 Mode
= &Private
->Mode
;
1177 if (!Mode
->AutoArp
) {
1179 // If AutoArp is set false, check arp cache
1181 UpdateArpCache (This
);
1182 if (!FindInArpCache (Mode
, &ServerIp
->v4
, &TempMacAddr
)) {
1183 return EFI_DEVICE_ERROR
;
1188 // Stop Udp4Read instance
1190 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
1192 Mode
->TftpErrorReceived
= FALSE
;
1193 Mode
->IcmpErrorReceived
= FALSE
;
1195 Mtftp4Config
.UseDefaultSetting
= FALSE
;
1196 Mtftp4Config
.TimeoutValue
= PXEBC_MTFTP_TIMEOUT
;
1197 Mtftp4Config
.TryCount
= PXEBC_MTFTP_RETRIES
;
1200 &Mtftp4Config
.StationIp
,
1201 &Private
->StationIp
,
1202 sizeof (EFI_IPv4_ADDRESS
)
1205 &Mtftp4Config
.SubnetMask
,
1206 &Private
->SubnetMask
,
1207 sizeof (EFI_IPv4_ADDRESS
)
1210 &Mtftp4Config
.GatewayIp
,
1211 &Private
->GatewayIp
,
1212 sizeof (EFI_IPv4_ADDRESS
)
1215 &Mtftp4Config
.ServerIp
,
1217 sizeof (EFI_IPv4_ADDRESS
)
1220 switch (Operation
) {
1222 case EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE
:
1224 Status
= PxeBcTftpGetFileSize (
1234 case EFI_PXE_BASE_CODE_TFTP_READ_FILE
:
1236 Status
= PxeBcTftpReadFile (
1248 case EFI_PXE_BASE_CODE_TFTP_WRITE_FILE
:
1250 Status
= PxeBcTftpWriteFile (
1262 case EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY
:
1264 Status
= PxeBcTftpReadDirectory (
1276 case EFI_PXE_BASE_CODE_MTFTP_GET_FILE_SIZE
:
1277 case EFI_PXE_BASE_CODE_MTFTP_READ_FILE
:
1278 case EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY
:
1279 Status
= EFI_UNSUPPORTED
;
1284 Status
= EFI_INVALID_PARAMETER
;
1288 if (Status
== EFI_ICMP_ERROR
) {
1289 Mode
->IcmpErrorReceived
= TRUE
;
1292 if (EFI_ERROR (Status
)) {
1297 Private
->Udp4Read
->Configure (Private
->Udp4Read
, &Private
->Udp4CfgData
);
1299 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
1300 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1302 ZeroMem(&IpFilter
, sizeof (EFI_PXE_BASE_CODE_IP_FILTER
));
1303 IpFilter
.Filters
= EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
;
1304 This
->SetIpFilter (This
, &IpFilter
);
1311 Writes a UDP packet to the network interface.
1313 This function writes a UDP packet specified by the (optional HeaderPtr and)
1314 BufferPtr parameters to the network interface. The UDP header is automatically
1315 built by this routine. It uses the parameters OpFlags, DestIp, DestPort, GatewayIp,
1316 SrcIp, and SrcPort to build this header. If the packet is successfully built and
1317 transmitted through the network interface, then EFI_SUCCESS will be returned.
1318 If a timeout occurs during the transmission of the packet, then EFI_TIMEOUT will
1319 be returned. If an ICMP error occurs during the transmission of the packet, then
1320 the IcmpErrorReceived field is set to TRUE, the IcmpError field is filled in and
1321 EFI_ICMP_ERROR will be returned. If the Callback Protocol does not return
1322 EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will be returned.
1324 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1325 @param OpFlags The UDP operation flags.
1326 @param DestIp The destination IP address.
1327 @param DestPort The destination UDP port number.
1328 @param GatewayIp The gateway IP address.
1329 @param SrcIp The source IP address.
1330 @param SrcPort The source UDP port number.
1331 @param HeaderSize An optional field which may be set to the length of a header at
1332 HeaderPtr to be prefixed to the data at BufferPtr.
1333 @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the
1335 @param BufferSize A pointer to the size of the data at BufferPtr.
1336 @param BufferPtr A pointer to the data to be written.
1338 @retval EFI_SUCCESS The UDP Write operation was completed.
1339 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1340 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1341 @retval EFI_BAD_BUFFER_SIZE The buffer is too long to be transmitted.
1342 @retval EFI_ABORTED The callback function aborted the UDP Write operation.
1343 @retval EFI_TIMEOUT The UDP Write operation timed out.
1344 @retval EFI_ICMP_ERROR An ICMP error packet was received during the UDP write session.
1350 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1352 IN EFI_IP_ADDRESS
*DestIp
,
1353 IN EFI_PXE_BASE_CODE_UDP_PORT
*DestPort
,
1354 IN EFI_IP_ADDRESS
*GatewayIp OPTIONAL
,
1355 IN EFI_IP_ADDRESS
*SrcIp OPTIONAL
,
1356 IN OUT EFI_PXE_BASE_CODE_UDP_PORT
*SrcPort OPTIONAL
,
1357 IN UINTN
*HeaderSize OPTIONAL
,
1358 IN VOID
*HeaderPtr OPTIONAL
,
1359 IN UINTN
*BufferSize
,
1363 PXEBC_PRIVATE_DATA
*Private
;
1364 EFI_UDP4_PROTOCOL
*Udp4
;
1365 EFI_UDP4_COMPLETION_TOKEN Token
;
1366 EFI_UDP4_TRANSMIT_DATA
*Udp4TxData
;
1369 EFI_UDP4_SESSION_DATA Udp4Session
;
1372 EFI_PXE_BASE_CODE_MODE
*Mode
;
1373 EFI_MAC_ADDRESS TempMacAddr
;
1377 if ((This
== NULL
) || (DestIp
== NULL
) || (DestPort
== NULL
)) {
1378 return EFI_INVALID_PARAMETER
;
1381 if ((GatewayIp
!= NULL
) && !NetIp4IsUnicast (NTOHL (GatewayIp
->Addr
[0]), 0)) {
1383 // Gateway is provided but it's not a unicast IP address.
1385 return EFI_INVALID_PARAMETER
;
1388 if ((HeaderSize
!= NULL
) && ((*HeaderSize
== 0) || (HeaderPtr
== NULL
))) {
1390 // The HeaderSize ptr isn't NULL and: 1. the value is zero; or 2. the HeaderPtr
1393 return EFI_INVALID_PARAMETER
;
1396 if ((BufferSize
== NULL
) || ((*BufferSize
!= 0) && (BufferPtr
== NULL
))) {
1397 return EFI_INVALID_PARAMETER
;
1400 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1401 Udp4
= Private
->Udp4Write
;
1402 Mode
= &Private
->Mode
;
1403 if (!Mode
->Started
) {
1404 return EFI_NOT_STARTED
;
1407 if (!Private
->AddressIsOk
&& (SrcIp
== NULL
)) {
1408 return EFI_INVALID_PARAMETER
;
1411 if (!Mode
->AutoArp
) {
1413 // If AutoArp is set false, check arp cache
1415 UpdateArpCache (This
);
1416 if (!FindInArpCache (Mode
, &DestIp
->v4
, &TempMacAddr
)) {
1417 return EFI_DEVICE_ERROR
;
1421 Mode
->IcmpErrorReceived
= FALSE
;
1423 if ((Private
->CurrentUdpSrcPort
== 0) ||
1424 ((SrcPort
!= NULL
) && (*SrcPort
!= Private
->CurrentUdpSrcPort
))) {
1426 // Port is changed, (re)configure the Udp4Write instance
1428 if (SrcPort
!= NULL
) {
1429 Private
->CurrentUdpSrcPort
= *SrcPort
;
1433 Status
= PxeBcConfigureUdpWriteInstance (
1435 &Private
->StationIp
.v4
,
1436 &Private
->SubnetMask
.v4
,
1437 &Private
->GatewayIp
.v4
,
1438 &Private
->CurrentUdpSrcPort
1440 if (EFI_ERROR (Status
)) {
1441 Private
->CurrentUdpSrcPort
= 0;
1442 return EFI_INVALID_PARAMETER
;
1445 ZeroMem (&Token
, sizeof (EFI_UDP4_COMPLETION_TOKEN
));
1446 ZeroMem (&Udp4Session
, sizeof (EFI_UDP4_SESSION_DATA
));
1448 CopyMem (&Udp4Session
.DestinationAddress
, DestIp
, sizeof (EFI_IPv4_ADDRESS
));
1449 Udp4Session
.DestinationPort
= *DestPort
;
1450 if (SrcIp
!= NULL
) {
1451 CopyMem (&Udp4Session
.SourceAddress
, SrcIp
, sizeof (EFI_IPv4_ADDRESS
));
1453 if (SrcPort
!= NULL
) {
1454 Udp4Session
.SourcePort
= *SrcPort
;
1457 FragCount
= (HeaderSize
!= NULL
) ? 2 : 1;
1458 Udp4TxData
= (EFI_UDP4_TRANSMIT_DATA
*) AllocateZeroPool (sizeof (EFI_UDP4_TRANSMIT_DATA
) + (FragCount
- 1) * sizeof (EFI_UDP4_FRAGMENT_DATA
));
1459 if (Udp4TxData
== NULL
) {
1460 return EFI_OUT_OF_RESOURCES
;
1463 Udp4TxData
->FragmentCount
= FragCount
;
1464 Udp4TxData
->FragmentTable
[FragCount
- 1].FragmentLength
= (UINT32
) *BufferSize
;
1465 Udp4TxData
->FragmentTable
[FragCount
- 1].FragmentBuffer
= BufferPtr
;
1466 DataLength
= (UINT32
) *BufferSize
;
1468 if (FragCount
== 2) {
1470 Udp4TxData
->FragmentTable
[0].FragmentLength
= (UINT32
) *HeaderSize
;
1471 Udp4TxData
->FragmentTable
[0].FragmentBuffer
= HeaderPtr
;
1472 DataLength
+= (UINT32
) *HeaderSize
;
1475 if (GatewayIp
!= NULL
) {
1476 Udp4TxData
->GatewayAddress
= (EFI_IPv4_ADDRESS
*) GatewayIp
;
1478 Udp4TxData
->UdpSessionData
= &Udp4Session
;
1479 Udp4TxData
->DataLength
= DataLength
;
1480 Token
.Packet
.TxData
= Udp4TxData
;
1482 Status
= gBS
->CreateEvent (
1489 if (EFI_ERROR (Status
)) {
1493 Status
= Udp4
->Transmit (Udp4
, &Token
);
1494 if (EFI_ERROR (Status
)) {
1495 if (Status
== EFI_ICMP_ERROR
) {
1496 Mode
->IcmpErrorReceived
= TRUE
;
1506 Status
= Token
.Status
;
1510 if (Token
.Event
!= NULL
) {
1511 gBS
->CloseEvent (Token
.Event
);
1514 FreePool (Udp4TxData
);
1517 // Reset the instance.
1519 Udp4
->Configure (Udp4
, NULL
);
1524 Decide whether the incoming UDP packet is acceptable per IP filter settings
1525 in provided PxeBcMode.
1527 @param PxeBcMode Pointer to EFI_PXE_BASE_CODE_MODE.
1528 @param Session Received UDP session.
1530 @retval TRUE The UDP package matches IP filters.
1531 @retval FALSE The UDP package doesn't matches IP filters.
1536 IN EFI_PXE_BASE_CODE_MODE
*PxeBcMode
,
1537 IN EFI_UDP4_SESSION_DATA
*Session
1541 EFI_IPv4_ADDRESS Ip4Address
;
1542 EFI_IPv4_ADDRESS DestIp4Address
;
1544 if ((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) != 0) {
1548 CopyMem (&DestIp4Address
, &Session
->DestinationAddress
, sizeof (DestIp4Address
));
1549 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
) != 0) &&
1550 IP4_IS_MULTICAST (EFI_NTOHL (DestIp4Address
))
1555 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST
) != 0) &&
1556 IP4_IS_LOCAL_BROADCAST (EFI_NTOHL (DestIp4Address
))
1561 CopyMem (&Ip4Address
, &PxeBcMode
->StationIp
.v4
, sizeof (Ip4Address
));
1562 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0) &&
1563 EFI_IP4_EQUAL (&Ip4Address
, &DestIp4Address
)
1568 ASSERT (PxeBcMode
->IpFilter
.IpCnt
< EFI_PXE_BASE_CODE_MAX_IPCNT
);
1570 for (Index
= 0; Index
< PxeBcMode
->IpFilter
.IpCnt
; Index
++) {
1573 &PxeBcMode
->IpFilter
.IpList
[Index
].v4
,
1576 if (EFI_IP4_EQUAL (&Ip4Address
, &DestIp4Address
)) {
1585 Reads a UDP packet from the network interface.
1587 This function reads a UDP packet from a network interface. The data contents
1588 are returned in (the optional HeaderPtr and) BufferPtr, and the size of the
1589 buffer received is returned in BufferSize . If the input BufferSize is smaller
1590 than the UDP packet received (less optional HeaderSize), it will be set to the
1591 required size, and EFI_BUFFER_TOO_SMALL will be returned. In this case, the
1592 contents of BufferPtr are undefined, and the packet is lost. If a UDP packet is
1593 successfully received, then EFI_SUCCESS will be returned, and the information
1594 from the UDP header will be returned in DestIp, DestPort, SrcIp, and SrcPort if
1595 they are not NULL. Depending on the values of OpFlags and the DestIp, DestPort,
1596 SrcIp, and SrcPort input values, different types of UDP packet receive filtering
1597 will be performed. The following tables summarize these receive filter operations.
1599 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1600 @param OpFlags The UDP operation flags.
1601 @param DestIp The destination IP address.
1602 @param DestPort The destination UDP port number.
1603 @param SrcIp The source IP address.
1604 @param SrcPort The source UDP port number.
1605 @param HeaderSize An optional field which may be set to the length of a header at
1606 HeaderPtr to be prefixed to the data at BufferPtr.
1607 @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the
1609 @param BufferSize A pointer to the size of the data at BufferPtr.
1610 @param BufferPtr A pointer to the data to be read.
1612 @retval EFI_SUCCESS The UDP Read operation was completed.
1613 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1614 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1615 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1616 @retval EFI_BUFFER_TOO_SMALL The packet is larger than Buffer can hold.
1617 @retval EFI_ABORTED The callback function aborted the UDP Read operation.
1618 @retval EFI_TIMEOUT The UDP Read operation timed out.
1624 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1626 IN OUT EFI_IP_ADDRESS
*DestIp OPTIONAL
,
1627 IN OUT EFI_PXE_BASE_CODE_UDP_PORT
*DestPort OPTIONAL
,
1628 IN OUT EFI_IP_ADDRESS
*SrcIp OPTIONAL
,
1629 IN OUT EFI_PXE_BASE_CODE_UDP_PORT
*SrcPort OPTIONAL
,
1630 IN UINTN
*HeaderSize OPTIONAL
,
1631 IN VOID
*HeaderPtr OPTIONAL
,
1632 IN OUT UINTN
*BufferSize
,
1636 PXEBC_PRIVATE_DATA
*Private
;
1637 EFI_PXE_BASE_CODE_MODE
*Mode
;
1638 EFI_UDP4_PROTOCOL
*Udp4
;
1639 EFI_UDP4_COMPLETION_TOKEN Token
;
1640 EFI_UDP4_RECEIVE_DATA
*RxData
;
1641 EFI_UDP4_SESSION_DATA
*Session
;
1647 UINTN HeaderCopiedLen
;
1648 UINTN BufferCopiedLen
;
1649 UINT32 FragmentLength
;
1650 UINTN FragmentIndex
;
1651 UINT8
*FragmentBuffer
;
1653 if (This
== NULL
|| DestIp
== NULL
|| DestPort
== NULL
) {
1654 return EFI_INVALID_PARAMETER
;
1657 if (((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) == 0 && (DestPort
== NULL
)) ||
1658 ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) == 0 && (SrcIp
== NULL
)) ||
1659 ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT
) == 0 && (SrcPort
== NULL
))) {
1660 return EFI_INVALID_PARAMETER
;
1663 if (((HeaderSize
!= NULL
) && (*HeaderSize
== 0)) || ((HeaderSize
!= NULL
) && (HeaderPtr
== NULL
))) {
1664 return EFI_INVALID_PARAMETER
;
1667 if ((BufferSize
== NULL
) || (BufferPtr
== NULL
)) {
1668 return EFI_INVALID_PARAMETER
;
1671 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1672 Mode
= Private
->PxeBc
.Mode
;
1673 Udp4
= Private
->Udp4Read
;
1675 if (!Mode
->Started
) {
1676 return EFI_NOT_STARTED
;
1679 Mode
->IcmpErrorReceived
= FALSE
;
1681 Status
= gBS
->CreateEvent (
1688 if (EFI_ERROR (Status
)) {
1689 return EFI_OUT_OF_RESOURCES
;
1695 Status
= Udp4
->Receive (Udp4
, &Token
);
1696 if (EFI_ERROR (Status
)) {
1697 if (Status
== EFI_ICMP_ERROR
) {
1698 Mode
->IcmpErrorReceived
= TRUE
;
1706 Status
= EFI_TIMEOUT
;
1710 // check whether this packet matches the filters
1712 if (EFI_ERROR (Token
.Status
)){
1716 RxData
= Token
.Packet
.RxData
;
1717 Session
= &RxData
->UdpSession
;
1721 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER
) != 0) {
1724 // Check UDP package by IP filter settings
1726 if (CheckIpByFilter (Mode
, Session
)) {
1735 // Match the destination ip of the received udp dgram
1737 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP
) != 0) {
1740 if (DestIp
!= NULL
) {
1741 CopyMem (DestIp
, &Session
->DestinationAddress
, sizeof (EFI_IPv4_ADDRESS
));
1744 if (DestIp
!= NULL
) {
1745 if (EFI_IP4_EQUAL (DestIp
, &Session
->DestinationAddress
)) {
1749 if (EFI_IP4_EQUAL (&Private
->StationIp
, &Session
->DestinationAddress
)) {
1758 // Match the destination port of the received udp dgram
1760 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) != 0) {
1762 if (DestPort
!= NULL
) {
1763 *DestPort
= Session
->DestinationPort
;
1767 if (*DestPort
!= Session
->DestinationPort
) {
1775 // Match the source ip of the received udp dgram
1777 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP
) != 0) {
1779 if (SrcIp
!= NULL
) {
1780 CopyMem (SrcIp
, &Session
->SourceAddress
, sizeof (EFI_IPv4_ADDRESS
));
1784 if (!EFI_IP4_EQUAL (SrcIp
, &Session
->SourceAddress
)) {
1792 // Match the source port of the received udp dgram
1794 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT
) != 0) {
1796 if (SrcPort
!= NULL
) {
1797 *SrcPort
= Session
->SourcePort
;
1801 if (*SrcPort
!= Session
->SourcePort
) {
1808 ASSERT (RxData
!= NULL
);
1811 if (HeaderSize
!= NULL
) {
1812 HeaderLen
= MIN (*HeaderSize
, RxData
->DataLength
);
1815 if (RxData
->DataLength
- HeaderLen
> *BufferSize
) {
1816 Status
= EFI_BUFFER_TOO_SMALL
;
1818 *HeaderSize
= HeaderLen
;
1819 *BufferSize
= RxData
->DataLength
- HeaderLen
;
1821 HeaderCopiedLen
= 0;
1822 BufferCopiedLen
= 0;
1823 for (FragmentIndex
= 0; FragmentIndex
< RxData
->FragmentCount
; FragmentIndex
++) {
1824 FragmentLength
= RxData
->FragmentTable
[FragmentIndex
].FragmentLength
;
1825 FragmentBuffer
= RxData
->FragmentTable
[FragmentIndex
].FragmentBuffer
;
1826 if (HeaderCopiedLen
+ FragmentLength
< HeaderLen
) {
1828 // Copy the header part of received data.
1830 CopyMem ((UINT8
*) HeaderPtr
+ HeaderCopiedLen
, FragmentBuffer
, FragmentLength
);
1831 HeaderCopiedLen
+= FragmentLength
;
1832 } else if (HeaderCopiedLen
< HeaderLen
) {
1834 // Copy the header part of received data.
1836 CopiedLen
= HeaderLen
- HeaderCopiedLen
;
1837 CopyMem ((UINT8
*) HeaderPtr
+ HeaderCopiedLen
, FragmentBuffer
, CopiedLen
);
1838 HeaderCopiedLen
+= CopiedLen
;
1841 // Copy the other part of received data.
1843 CopyMem ((UINT8
*) BufferPtr
+ BufferCopiedLen
, FragmentBuffer
+ CopiedLen
, FragmentLength
- CopiedLen
);
1844 BufferCopiedLen
+= (FragmentLength
- CopiedLen
);
1847 // Copy the other part of received data.
1849 CopyMem ((UINT8
*) BufferPtr
+ BufferCopiedLen
, FragmentBuffer
, FragmentLength
);
1850 BufferCopiedLen
+= FragmentLength
;
1856 Status
= EFI_TIMEOUT
;
1860 // Recycle the RxData
1862 gBS
->SignalEvent (RxData
->RecycleSignal
);
1871 Udp4
->Cancel (Udp4
, &Token
);
1873 gBS
->CloseEvent (Token
.Event
);
1879 Updates the IP receive filters of a network device and enables software filtering.
1881 The NewFilter field is used to modify the network device's current IP receive
1882 filter settings and to enable a software filter. This function updates the IpFilter
1883 field of the EFI_PXE_BASE_CODE_MODE structure with the contents of NewIpFilter.
1884 The software filter is used when the USE_FILTER in OpFlags is set to UdpRead().
1885 The current hardware filter remains in effect no matter what the settings of OpFlags
1886 are, so that the meaning of ANY_DEST_IP set in OpFlags to UdpRead() is from those
1887 packets whose reception is enabled in hardware-physical NIC address (unicast),
1888 broadcast address, logical address or addresses (multicast), or all (promiscuous).
1889 UdpRead() does not modify the IP filter settings.
1890 Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP receive
1891 filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1892 If an application or driver wishes to preserve the IP receive filter settings,
1893 it will have to preserve the IP receive filter settings before these calls, and
1894 use SetIpFilter() to restore them after the calls. If incompatible filtering is
1895 requested (for example, PROMISCUOUS with anything else) or if the device does not
1896 support a requested filter setting and it cannot be accommodated in software
1897 (for example, PROMISCUOUS not supported), EFI_INVALID_PARAMETER will be returned.
1898 The IPlist field is used to enable IPs other than the StationIP. They may be
1899 multicast or unicast. If IPcnt is set as well as EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP,
1900 then both the StationIP and the IPs from the IPlist will be used.
1902 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1903 @param NewFilter Pointer to the new set of IP receive filters.
1905 @retval EFI_SUCCESS The IP receive filter settings were updated.
1906 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1907 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1912 EfiPxeBcSetIpFilter (
1913 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1914 IN EFI_PXE_BASE_CODE_IP_FILTER
*NewFilter
1918 PXEBC_PRIVATE_DATA
*Private
;
1919 EFI_PXE_BASE_CODE_MODE
*Mode
;
1921 EFI_UDP4_CONFIG_DATA
*Udp4Cfg
;
1922 BOOLEAN PromiscuousNeed
;
1923 BOOLEAN AcceptPromiscuous
;
1924 BOOLEAN AcceptBroadcast
;
1925 BOOLEAN MultiCastUpdate
;
1928 DEBUG ((EFI_D_ERROR
, "This == NULL.\n"));
1929 return EFI_INVALID_PARAMETER
;
1932 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1933 Mode
= Private
->PxeBc
.Mode
;
1935 if (NewFilter
== NULL
) {
1936 DEBUG ((EFI_D_ERROR
, "NewFilter == NULL.\n"));
1937 return EFI_INVALID_PARAMETER
;
1940 if (NewFilter
->IpCnt
> EFI_PXE_BASE_CODE_MAX_IPCNT
) {
1941 DEBUG ((EFI_D_ERROR
, "NewFilter->IpCnt > %d.\n", EFI_PXE_BASE_CODE_MAX_IPCNT
));
1942 return EFI_INVALID_PARAMETER
;
1945 if (!Mode
->Started
) {
1946 DEBUG ((EFI_D_ERROR
, "BC was not started.\n"));
1947 return EFI_NOT_STARTED
;
1950 if (Mode
->UsingIpv6
) {
1951 DEBUG ((EFI_D_ERROR
, "This driver is PXE for IPv4 Only.\n"));
1952 return EFI_INVALID_PARAMETER
;
1955 PromiscuousNeed
= FALSE
;
1957 for (Index
= 0; Index
< NewFilter
->IpCnt
; ++Index
) {
1958 if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (NewFilter
->IpList
[Index
].v4
))) {
1960 // The IP is a broadcast address.
1962 DEBUG ((EFI_D_ERROR
, "There is broadcast address in NewFilter.\n"));
1963 return EFI_INVALID_PARAMETER
;
1965 if (NetIp4IsUnicast (EFI_IP4 (NewFilter
->IpList
[Index
].v4
), 0) &&
1966 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0)
1969 // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList,
1970 // promiscuous mode is needed.
1972 PromiscuousNeed
= TRUE
;
1976 AcceptPromiscuous
= FALSE
;
1977 AcceptBroadcast
= FALSE
;
1978 MultiCastUpdate
= FALSE
;
1980 if (PromiscuousNeed
||
1981 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) != 0) ||
1982 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
) != 0)
1985 // Configure the udp4 filter to receive all packages.
1987 AcceptPromiscuous
= TRUE
;
1988 } else if ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST
) != 0) {
1990 // Configure the udp4 filter to receive all broadcast packages.
1992 AcceptBroadcast
= TRUE
;
1996 // In multicast condition when Promiscuous FALSE and IpCnt no-zero.
1997 // Here check if there is any update of the multicast ip address. If yes,
1998 // we need leave the old multicast group (by Config UDP instance to NULL),
1999 // and join the new multicast group.
2001 if (!AcceptPromiscuous
) {
2002 if ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0) {
2003 if (Mode
->IpFilter
.IpCnt
!= NewFilter
->IpCnt
) {
2004 MultiCastUpdate
= TRUE
;
2005 } else if (CompareMem (Mode
->IpFilter
.IpList
, NewFilter
->IpList
, NewFilter
->IpCnt
* sizeof (EFI_IP_ADDRESS
)) != 0 ) {
2006 MultiCastUpdate
= TRUE
;
2012 // Check whether we need reconfigure the UDP instance.
2014 Udp4Cfg
= &Private
->Udp4CfgData
;
2015 if ((AcceptPromiscuous
!= Udp4Cfg
->AcceptPromiscuous
) ||
2016 (AcceptBroadcast
!= Udp4Cfg
->AcceptBroadcast
) || MultiCastUpdate
) {
2018 // Clear the UDP instance configuration, all joined groups will be left
2019 // during the operation.
2021 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
2024 // Configure the UDP instance with the new configuration.
2026 Udp4Cfg
->AcceptPromiscuous
= AcceptPromiscuous
;
2027 Udp4Cfg
->AcceptBroadcast
= AcceptBroadcast
;
2028 Status
= Private
->Udp4Read
->Configure (Private
->Udp4Read
, Udp4Cfg
);
2029 if (EFI_ERROR (Status
)) {
2034 // In not Promiscuous mode, need to join the new multicast group.
2036 if (!AcceptPromiscuous
) {
2037 for (Index
= 0; Index
< NewFilter
->IpCnt
; ++Index
) {
2038 if (IP4_IS_MULTICAST (EFI_NTOHL (NewFilter
->IpList
[Index
].v4
))) {
2040 // Join the mutilcast group.
2042 Status
= Private
->Udp4Read
->Groups (Private
->Udp4Read
, TRUE
, &NewFilter
->IpList
[Index
].v4
);
2043 if (EFI_ERROR (Status
)) {
2053 // Save the new filter.
2055 CopyMem (&Mode
->IpFilter
, NewFilter
, sizeof (Mode
->IpFilter
));
2062 Uses the ARP protocol to resolve a MAC address.
2064 This function uses the ARP protocol to resolve a MAC address. The UsingIpv6 field
2065 of the EFI_PXE_BASE_CODE_MODE structure is used to determine if IPv4 or IPv6
2066 addresses are being used. The IP address specified by IpAddr is used to resolve
2067 a MAC address. If the ARP protocol succeeds in resolving the specified address,
2068 then the ArpCacheEntries and ArpCache fields of the EFI_PXE_BASE_CODE_MODE structure
2069 are updated, and EFI_SUCCESS is returned. If MacAddr is not NULL, the resolved
2070 MAC address is placed there as well. If the PXE Base Code protocol is in the
2071 stopped state, then EFI_NOT_STARTED is returned. If the ARP protocol encounters
2072 a timeout condition while attempting to resolve an address, then EFI_TIMEOUT is
2073 returned. If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
2074 then EFI_ABORTED is returned.
2076 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2077 @param IpAddr Pointer to the IP address that is used to resolve a MAC address.
2078 @param MacAddr If not NULL, a pointer to the MAC address that was resolved with the
2081 @retval EFI_SUCCESS The IP or MAC address was resolved.
2082 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2083 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2084 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
2085 @retval EFI_ICMP_ERROR Something error occur with the ICMP packet message.
2091 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2092 IN EFI_IP_ADDRESS
* IpAddr
,
2093 IN EFI_MAC_ADDRESS
* MacAddr OPTIONAL
2096 PXEBC_PRIVATE_DATA
*Private
;
2097 EFI_PXE_BASE_CODE_MODE
*Mode
;
2099 EFI_MAC_ADDRESS TempMacAddr
;
2101 if (This
== NULL
|| IpAddr
== NULL
) {
2102 return EFI_INVALID_PARAMETER
;
2105 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2106 Mode
= Private
->PxeBc
.Mode
;
2108 if (!Mode
->Started
) {
2109 return EFI_NOT_STARTED
;
2112 if (!Private
->AddressIsOk
|| Mode
->UsingIpv6
) {
2114 // We can't resolve the IP address if we don't have a local address now.
2115 // Don't have ARP for IPv6.
2117 return EFI_INVALID_PARAMETER
;
2120 Mode
->IcmpErrorReceived
= FALSE
;
2122 if (!Mode
->AutoArp
) {
2124 // If AutoArp is set false, check arp cache
2126 UpdateArpCache (This
);
2127 if (!FindInArpCache (Mode
, &IpAddr
->v4
, &TempMacAddr
)) {
2128 return EFI_DEVICE_ERROR
;
2131 Status
= Private
->Arp
->Request (Private
->Arp
, &IpAddr
->v4
, NULL
, &TempMacAddr
);
2132 if (EFI_ERROR (Status
)) {
2133 if (Status
== EFI_ICMP_ERROR
) {
2134 Mode
->IcmpErrorReceived
= TRUE
;
2140 if (MacAddr
!= NULL
) {
2141 CopyMem (MacAddr
, &TempMacAddr
, sizeof (EFI_MAC_ADDRESS
));
2148 Updates the parameters that affect the operation of the PXE Base Code Protocol.
2150 This function sets parameters that affect the operation of the PXE Base Code Protocol.
2151 The parameter specified by NewAutoArp is used to control the generation of ARP
2152 protocol packets. If NewAutoArp is TRUE, then ARP Protocol packets will be generated
2153 as required by the PXE Base Code Protocol. If NewAutoArp is FALSE, then no ARP
2154 Protocol packets will be generated. In this case, the only mappings that are
2155 available are those stored in the ArpCache of the EFI_PXE_BASE_CODE_MODE structure.
2156 If there are not enough mappings in the ArpCache to perform a PXE Base Code Protocol
2157 service, then the service will fail. This function updates the AutoArp field of
2158 the EFI_PXE_BASE_CODE_MODE structure to NewAutoArp.
2159 The SetParameters() call must be invoked after a Callback Protocol is installed
2160 to enable the use of callbacks.
2162 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2163 @param NewAutoArp If not NULL, a pointer to a value that specifies whether to replace the
2164 current value of AutoARP.
2165 @param NewSendGUID If not NULL, a pointer to a value that specifies whether to replace the
2166 current value of SendGUID.
2167 @param NewTTL If not NULL, a pointer to be used in place of the current value of TTL,
2168 the "time to live" field of the IP header.
2169 @param NewToS If not NULL, a pointer to be used in place of the current value of ToS,
2170 the "type of service" field of the IP header.
2171 @param NewMakeCallback If not NULL, a pointer to a value that specifies whether to replace the
2172 current value of the MakeCallback field of the Mode structure.
2174 @retval EFI_SUCCESS The new parameters values were updated.
2175 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2176 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2181 EfiPxeBcSetParameters (
2182 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
2183 IN BOOLEAN
*NewAutoArp OPTIONAL
,
2184 IN BOOLEAN
*NewSendGUID OPTIONAL
,
2185 IN UINT8
*NewTTL OPTIONAL
,
2186 IN UINT8
*NewToS OPTIONAL
,
2187 IN BOOLEAN
*NewMakeCallback
// OPTIONAL
2190 PXEBC_PRIVATE_DATA
*Private
;
2191 EFI_PXE_BASE_CODE_MODE
*Mode
;
2194 Status
= EFI_SUCCESS
;
2197 Status
= EFI_INVALID_PARAMETER
;
2201 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2202 Mode
= Private
->PxeBc
.Mode
;
2204 if (NewSendGUID
!= NULL
&& *NewSendGUID
) {
2206 // FixMe, cann't locate SendGuid
2210 if (NewMakeCallback
!= NULL
&& *NewMakeCallback
) {
2212 Status
= gBS
->HandleProtocol (
2213 Private
->Controller
,
2214 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2215 (VOID
**) &Private
->PxeBcCallback
2217 if (EFI_ERROR (Status
) || (Private
->PxeBcCallback
->Callback
== NULL
)) {
2219 Status
= EFI_INVALID_PARAMETER
;
2224 if (!Mode
->Started
) {
2225 Status
= EFI_NOT_STARTED
;
2229 if (NewMakeCallback
!= NULL
) {
2231 if (*NewMakeCallback
) {
2233 // Update the Callback protocol.
2235 Status
= gBS
->HandleProtocol (
2236 Private
->Controller
,
2237 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2238 (VOID
**) &Private
->PxeBcCallback
2241 if (EFI_ERROR (Status
) || (Private
->PxeBcCallback
->Callback
== NULL
)) {
2242 Status
= EFI_INVALID_PARAMETER
;
2246 Private
->PxeBcCallback
= NULL
;
2249 Mode
->MakeCallbacks
= *NewMakeCallback
;
2252 if (NewAutoArp
!= NULL
) {
2253 Mode
->AutoArp
= *NewAutoArp
;
2256 if (NewSendGUID
!= NULL
) {
2257 Mode
->SendGUID
= *NewSendGUID
;
2260 if (NewTTL
!= NULL
) {
2261 Mode
->TTL
= *NewTTL
;
2264 if (NewToS
!= NULL
) {
2265 Mode
->ToS
= *NewToS
;
2273 Updates the station IP address and/or subnet mask values of a network device.
2275 This function updates the station IP address and/or subnet mask values of a network
2276 device. The NewStationIp field is used to modify the network device's current IP address.
2277 If NewStationIP is NULL, then the current IP address will not be modified. Otherwise,
2278 this function updates the StationIp field of the EFI_PXE_BASE_CODE_MODE structure
2279 with NewStationIp. The NewSubnetMask field is used to modify the network device's current subnet
2280 mask. If NewSubnetMask is NULL, then the current subnet mask will not be modified.
2281 Otherwise, this function updates the SubnetMask field of the EFI_PXE_BASE_CODE_MODE
2282 structure with NewSubnetMask.
2284 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2285 @param NewStationIp Pointer to the new IP address to be used by the network device.
2286 @param NewSubnetMask Pointer to the new subnet mask to be used by the network device.
2288 @retval EFI_SUCCESS The new station IP address and/or subnet mask were updated.
2289 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2290 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2295 EfiPxeBcSetStationIP (
2296 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2297 IN EFI_IP_ADDRESS
* NewStationIp OPTIONAL
,
2298 IN EFI_IP_ADDRESS
* NewSubnetMask OPTIONAL
2301 PXEBC_PRIVATE_DATA
*Private
;
2302 EFI_PXE_BASE_CODE_MODE
*Mode
;
2303 EFI_ARP_CONFIG_DATA ArpConfigData
;
2306 return EFI_INVALID_PARAMETER
;
2309 if (NewStationIp
!= NULL
&& !NetIp4IsUnicast (NTOHL (NewStationIp
->Addr
[0]), 0)) {
2310 return EFI_INVALID_PARAMETER
;
2313 if (NewSubnetMask
!= NULL
&& !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask
->Addr
[0]))) {
2314 return EFI_INVALID_PARAMETER
;
2317 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2318 Mode
= Private
->PxeBc
.Mode
;
2320 if (!Mode
->Started
) {
2321 return EFI_NOT_STARTED
;
2324 if (NewStationIp
!= NULL
) {
2325 CopyMem (&Mode
->StationIp
, NewStationIp
, sizeof (EFI_IP_ADDRESS
));
2326 CopyMem (&Private
->StationIp
, NewStationIp
, sizeof (EFI_IP_ADDRESS
));
2329 if (NewSubnetMask
!= NULL
) {
2330 CopyMem (&Mode
->SubnetMask
, NewSubnetMask
, sizeof (EFI_IP_ADDRESS
));
2331 CopyMem (&Private
->SubnetMask
,NewSubnetMask
, sizeof (EFI_IP_ADDRESS
));
2334 Private
->AddressIsOk
= TRUE
;
2336 if (!Mode
->UsingIpv6
) {
2338 // If in IPv4 mode, configure the corresponding ARP with this new
2339 // station IP address.
2341 ZeroMem (&ArpConfigData
, sizeof (EFI_ARP_CONFIG_DATA
));
2343 ArpConfigData
.SwAddressType
= 0x0800;
2344 ArpConfigData
.SwAddressLength
= (UINT8
) sizeof (EFI_IPv4_ADDRESS
);
2345 ArpConfigData
.StationAddress
= &Private
->StationIp
.v4
;
2347 Private
->Arp
->Configure (Private
->Arp
, NULL
);
2348 Private
->Arp
->Configure (Private
->Arp
, &ArpConfigData
);
2351 // Update the route table.
2353 Mode
->RouteTableEntries
= 1;
2354 Mode
->RouteTable
[0].IpAddr
.Addr
[0] = Private
->StationIp
.Addr
[0] & Private
->SubnetMask
.Addr
[0];
2355 Mode
->RouteTable
[0].SubnetMask
.Addr
[0] = Private
->SubnetMask
.Addr
[0];
2356 Mode
->RouteTable
[0].GwAddr
.Addr
[0] = 0;
2363 Updates the contents of the cached DHCP and Discover packets.
2365 The pointers to the new packets are used to update the contents of the cached
2366 packets in the EFI_PXE_BASE_CODE_MODE structure.
2368 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2369 @param NewDhcpDiscoverValid Pointer to a value that will replace the current
2370 DhcpDiscoverValid field.
2371 @param NewDhcpAckReceived Pointer to a value that will replace the current
2372 DhcpAckReceived field.
2373 @param NewProxyOfferReceived Pointer to a value that will replace the current
2374 ProxyOfferReceived field.
2375 @param NewPxeDiscoverValid Pointer to a value that will replace the current
2376 ProxyOfferReceived field.
2377 @param NewPxeReplyReceived Pointer to a value that will replace the current
2378 PxeReplyReceived field.
2379 @param NewPxeBisReplyReceived Pointer to a value that will replace the current
2380 PxeBisReplyReceived field.
2381 @param NewDhcpDiscover Pointer to the new cached DHCP Discover packet contents.
2382 @param NewDhcpAck Pointer to the new cached DHCP Ack packet contents.
2383 @param NewProxyOffer Pointer to the new cached Proxy Offer packet contents.
2384 @param NewPxeDiscover Pointer to the new cached PXE Discover packet contents.
2385 @param NewPxeReply Pointer to the new cached PXE Reply packet contents.
2386 @param NewPxeBisReply Pointer to the new cached PXE BIS Reply packet contents.
2388 @retval EFI_SUCCESS The cached packet contents were updated.
2389 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2390 @retval EFI_INVALID_PARAMETER This is NULL or not point to a valid EFI_PXE_BASE_CODE_PROTOCOL structure.
2395 EfiPxeBcSetPackets (
2396 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2397 IN BOOLEAN
* NewDhcpDiscoverValid OPTIONAL
,
2398 IN BOOLEAN
* NewDhcpAckReceived OPTIONAL
,
2399 IN BOOLEAN
* NewProxyOfferReceived OPTIONAL
,
2400 IN BOOLEAN
* NewPxeDiscoverValid OPTIONAL
,
2401 IN BOOLEAN
* NewPxeReplyReceived OPTIONAL
,
2402 IN BOOLEAN
* NewPxeBisReplyReceived OPTIONAL
,
2403 IN EFI_PXE_BASE_CODE_PACKET
* NewDhcpDiscover OPTIONAL
,
2404 IN EFI_PXE_BASE_CODE_PACKET
* NewDhcpAck OPTIONAL
,
2405 IN EFI_PXE_BASE_CODE_PACKET
* NewProxyOffer OPTIONAL
,
2406 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeDiscover OPTIONAL
,
2407 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeReply OPTIONAL
,
2408 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeBisReply OPTIONAL
2411 PXEBC_PRIVATE_DATA
*Private
;
2412 EFI_PXE_BASE_CODE_MODE
*Mode
;
2415 return EFI_INVALID_PARAMETER
;
2418 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2419 Mode
= Private
->PxeBc
.Mode
;
2421 if (!Mode
->Started
) {
2422 return EFI_NOT_STARTED
;
2425 if (NewDhcpDiscoverValid
!= NULL
) {
2426 Mode
->DhcpDiscoverValid
= *NewDhcpDiscoverValid
;
2429 if (NewDhcpAckReceived
!= NULL
) {
2430 Mode
->DhcpAckReceived
= *NewDhcpAckReceived
;
2433 if (NewProxyOfferReceived
!= NULL
) {
2434 Mode
->ProxyOfferReceived
= *NewProxyOfferReceived
;
2437 if (NewPxeDiscoverValid
!= NULL
) {
2438 Mode
->PxeDiscoverValid
= *NewPxeDiscoverValid
;
2441 if (NewPxeReplyReceived
!= NULL
) {
2442 Mode
->PxeReplyReceived
= *NewPxeReplyReceived
;
2445 if (NewPxeBisReplyReceived
!= NULL
) {
2446 Mode
->PxeBisReplyReceived
= *NewPxeBisReplyReceived
;
2449 if (NewDhcpDiscover
!= NULL
) {
2450 CopyMem (&Mode
->DhcpDiscover
, NewDhcpDiscover
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2453 if (NewDhcpAck
!= NULL
) {
2454 CopyMem (&Mode
->DhcpAck
, NewDhcpAck
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2457 if (NewProxyOffer
!= NULL
) {
2458 CopyMem (&Mode
->ProxyOffer
, NewProxyOffer
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2461 if (NewPxeDiscover
!= NULL
) {
2462 CopyMem (&Mode
->PxeDiscover
, NewPxeDiscover
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2465 if (NewPxeReply
!= NULL
) {
2466 CopyMem (&Mode
->PxeReply
, NewPxeReply
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2469 if (NewPxeBisReply
!= NULL
) {
2470 CopyMem (&Mode
->PxeBisReply
, NewPxeBisReply
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2476 EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate
= {
2477 EFI_PXE_BASE_CODE_PROTOCOL_REVISION
,
2485 EfiPxeBcSetIpFilter
,
2487 EfiPxeBcSetParameters
,
2488 EfiPxeBcSetStationIP
,
2494 Callback function that is invoked when the PXE Base Code Protocol is about to transmit, has
2495 received, or is waiting to receive a packet.
2497 This function is invoked when the PXE Base Code Protocol is about to transmit, has received,
2498 or is waiting to receive a packet. Parameters Function and Received specify the type of event.
2499 Parameters PacketLen and Packet specify the packet that generated the event. If these fields
2500 are zero and NULL respectively, then this is a status update callback. If the operation specified
2501 by Function is to continue, then CALLBACK_STATUS_CONTINUE should be returned. If the operation
2502 specified by Function should be aborted, then CALLBACK_STATUS_ABORT should be returned. Due to
2503 the polling nature of UEFI device drivers, a callback function should not execute for more than 5 ms.
2504 The SetParameters() function must be called after a Callback Protocol is installed to enable the
2507 @param This Pointer to the EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL instance.
2508 @param Function The PXE Base Code Protocol function that is waiting for an event.
2509 @param Received TRUE if the callback is being invoked due to a receive event. FALSE if
2510 the callback is being invoked due to a transmit event.
2511 @param PacketLength The length, in bytes, of Packet. This field will have a value of zero if
2512 this is a wait for receive event.
2513 @param PacketPtr If Received is TRUE, a pointer to the packet that was just received;
2514 otherwise a pointer to the packet that is about to be transmitted.
2516 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE if Function specifies a continue operation
2517 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT if Function specifies an abort operation
2520 EFI_PXE_BASE_CODE_CALLBACK_STATUS
2522 EfiPxeLoadFileCallback (
2523 IN EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL
* This
,
2524 IN EFI_PXE_BASE_CODE_FUNCTION Function
,
2525 IN BOOLEAN Received
,
2526 IN UINT32 PacketLength
,
2527 IN EFI_PXE_BASE_CODE_PACKET
* PacketPtr OPTIONAL
2534 // Catch Ctrl-C or ESC to abort.
2536 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2538 if (!EFI_ERROR (Status
)) {
2540 if (Key
.ScanCode
== SCAN_ESC
|| Key
.UnicodeChar
== (0x1F & 'c')) {
2542 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT
;
2546 // No print if receive packet
2549 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2552 // Print only for three functions
2556 case EFI_PXE_BASE_CODE_FUNCTION_MTFTP
:
2558 // Print only for open MTFTP packets, not every MTFTP packets
2560 if (PacketLength
!= 0 && PacketPtr
!= NULL
) {
2561 if (PacketPtr
->Raw
[0x1C] != 0x00 || PacketPtr
->Raw
[0x1D] != 0x01) {
2562 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2567 case EFI_PXE_BASE_CODE_FUNCTION_DHCP
:
2568 case EFI_PXE_BASE_CODE_FUNCTION_DISCOVER
:
2572 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2575 if (PacketLength
!= 0 && PacketPtr
!= NULL
) {
2577 // Print '.' when transmit a packet
2583 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2586 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL mPxeBcCallBackTemplate
= {
2587 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_REVISION
,
2588 EfiPxeLoadFileCallback
2595 @param Private Pointer to PxeBc private data.
2596 @param BufferSize Pointer to buffer size.
2597 @param Buffer Pointer to buffer.
2599 @retval EFI_SUCCESS Discover the boot file successfully.
2600 @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.
2601 @retval EFI_ABORTED PXE bootstrap server, so local boot need abort.
2602 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to load the boot file.
2607 IN PXEBC_PRIVATE_DATA
*Private
,
2608 IN OUT UINT64
*BufferSize
,
2612 EFI_PXE_BASE_CODE_PROTOCOL
*PxeBc
;
2613 EFI_PXE_BASE_CODE_MODE
*Mode
;
2618 PXEBC_CACHED_DHCP4_PACKET
*Packet
;
2621 PxeBc
= &Private
->PxeBc
;
2623 Type
= EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP
;
2624 Layer
= EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL
;
2629 Status
= PxeBc
->Dhcp (PxeBc
, TRUE
);
2630 if (EFI_ERROR (Status
)) {
2635 // Select a boot server
2637 Status
= PxeBcSelectBootPrompt (Private
);
2639 if (Status
== EFI_SUCCESS
) {
2640 Status
= PxeBcSelectBootMenu (Private
, &Type
, TRUE
);
2641 } else if (Status
== EFI_TIMEOUT
) {
2642 Status
= PxeBcSelectBootMenu (Private
, &Type
, FALSE
);
2645 if (!EFI_ERROR (Status
)) {
2647 if (Type
== EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP
) {
2649 // Local boot(PXE bootstrap server) need abort
2654 UseBis
= (BOOLEAN
) (Mode
->BisSupported
&& Mode
->BisDetected
);
2655 Status
= PxeBc
->Discover (PxeBc
, Type
, &Layer
, UseBis
, NULL
);
2656 if (EFI_ERROR (Status
)) {
2664 // Get bootfile name and (m)tftp server ip addresss
2666 if (Mode
->PxeReplyReceived
) {
2667 Packet
= &Private
->PxeReply
;
2668 } else if (Mode
->ProxyOfferReceived
) {
2669 Packet
= &Private
->ProxyOffer
;
2671 Packet
= &Private
->Dhcp4Ack
;
2675 // Use siaddr(next server) in DHCPOFFER packet header, if zero, use option 54(server identifier)
2676 // in DHCPOFFER packet.
2677 // (It does not comply with PXE Spec, Ver2.1)
2679 if (EFI_IP4_EQUAL (&Packet
->Packet
.Offer
.Dhcp4
.Header
.ServerAddr
, &mZeroIp4Addr
)) {
2682 Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_SERVER_ID
]->Data
,
2683 sizeof (EFI_IPv4_ADDRESS
)
2688 &Packet
->Packet
.Offer
.Dhcp4
.Header
.ServerAddr
,
2689 sizeof (EFI_IPv4_ADDRESS
)
2692 if (Private
->ServerIp
.Addr
[0] == 0) {
2693 return EFI_DEVICE_ERROR
;
2696 ASSERT (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE
] != NULL
);
2701 Private
->BootFileName
= (CHAR8
*) (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE
]->Data
);
2703 if (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN
] != NULL
) {
2705 // Already have the bootfile length option, compute the file size
2707 CopyMem (&Value
, Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN
]->Data
, sizeof (Value
));
2708 Value
= NTOHS (Value
);
2709 *BufferSize
= 512 * Value
;
2710 Status
= EFI_BUFFER_TOO_SMALL
;
2713 // Get the bootfile size from tftp
2715 Status
= PxeBc
->Mtftp (
2717 EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE
,
2721 &Private
->BlockSize
,
2723 (UINT8
*) Private
->BootFileName
,
2729 Private
->FileSize
= (UINTN
) *BufferSize
;
2735 Causes the driver to load a specified file.
2737 @param This Protocol instance pointer.
2738 @param FilePath The device specific path of the file to load.
2739 @param BootPolicy If TRUE, indicates that the request originates from the
2740 boot manager is attempting to load FilePath as a boot
2741 selection. If FALSE, then FilePath must match as exact file
2743 @param BufferSize On input the size of Buffer in bytes. On output with a return
2744 code of EFI_SUCCESS, the amount of data transferred to
2745 Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
2746 the size of Buffer required to retrieve the requested file.
2747 @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
2748 then no the size of the requested file is returned in
2751 @retval EFI_SUCCESS The file was loaded.
2752 @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy
2753 @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or
2755 @retval EFI_NO_MEDIA No medium was present to load the file.
2756 @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.
2757 @retval EFI_NO_RESPONSE The remote system did not respond.
2758 @retval EFI_NOT_FOUND The file was not found.
2759 @retval EFI_ABORTED The file load process was manually cancelled.
2765 IN EFI_LOAD_FILE_PROTOCOL
* This
,
2766 IN EFI_DEVICE_PATH_PROTOCOL
* FilePath
,
2767 IN BOOLEAN BootPolicy
,
2768 IN OUT UINTN
*BufferSize
,
2769 IN VOID
*Buffer OPTIONAL
2772 PXEBC_PRIVATE_DATA
*Private
;
2773 EFI_PXE_BASE_CODE_PROTOCOL
*PxeBc
;
2774 BOOLEAN NewMakeCallback
;
2777 BOOLEAN MediaPresent
;
2779 if (FilePath
== NULL
|| !IsDevicePathEnd (FilePath
)) {
2780 return EFI_INVALID_PARAMETER
;
2783 Private
= PXEBC_PRIVATE_DATA_FROM_LOADFILE (This
);
2784 PxeBc
= &Private
->PxeBc
;
2785 NewMakeCallback
= FALSE
;
2786 Status
= EFI_DEVICE_ERROR
;
2788 if (This
== NULL
|| BufferSize
== NULL
) {
2790 return EFI_INVALID_PARAMETER
;
2794 // Only support BootPolicy
2797 return EFI_UNSUPPORTED
;
2801 // Check media status before PXE start
2803 MediaPresent
= TRUE
;
2804 NetLibDetectMedia (Private
->Controller
, &MediaPresent
);
2805 if (!MediaPresent
) {
2806 return EFI_NO_MEDIA
;
2809 Status
= PxeBc
->Start (PxeBc
, FALSE
);
2810 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
2814 Status
= gBS
->HandleProtocol (
2815 Private
->Controller
,
2816 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2817 (VOID
**) &Private
->PxeBcCallback
2819 if (Status
== EFI_UNSUPPORTED
) {
2821 CopyMem (&Private
->LoadFileCallback
, &mPxeBcCallBackTemplate
, sizeof (Private
->LoadFileCallback
));
2823 Status
= gBS
->InstallProtocolInterface (
2824 &Private
->Controller
,
2825 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2826 EFI_NATIVE_INTERFACE
,
2827 &Private
->LoadFileCallback
2830 NewMakeCallback
= (BOOLEAN
) (Status
== EFI_SUCCESS
);
2832 Status
= PxeBc
->SetParameters (PxeBc
, NULL
, NULL
, NULL
, NULL
, &NewMakeCallback
);
2833 if (EFI_ERROR (Status
)) {
2834 PxeBc
->Stop (PxeBc
);
2839 if (Private
->FileSize
== 0) {
2841 Status
= DiscoverBootFile (Private
, &TmpBufSize
, Buffer
);
2843 if (sizeof (UINTN
) < sizeof (UINT64
) && (TmpBufSize
> 0xFFFFFFFF)) {
2844 Status
= EFI_DEVICE_ERROR
;
2845 } else if (TmpBufSize
> 0 && *BufferSize
>= (UINTN
) TmpBufSize
&& Buffer
!= NULL
) {
2846 *BufferSize
= (UINTN
) TmpBufSize
;
2847 Status
= PxeBc
->Mtftp (
2849 EFI_PXE_BASE_CODE_TFTP_READ_FILE
,
2853 &Private
->BlockSize
,
2855 (UINT8
*) Private
->BootFileName
,
2859 } else if (TmpBufSize
> 0) {
2860 *BufferSize
= (UINTN
) TmpBufSize
;
2861 Status
= EFI_BUFFER_TOO_SMALL
;
2863 } else if (Buffer
== NULL
|| Private
->FileSize
> *BufferSize
) {
2864 *BufferSize
= Private
->FileSize
;
2865 Status
= EFI_BUFFER_TOO_SMALL
;
2868 // Download the file.
2870 TmpBufSize
= (UINT64
) (*BufferSize
);
2871 Status
= PxeBc
->Mtftp (
2873 EFI_PXE_BASE_CODE_TFTP_READ_FILE
,
2877 &Private
->BlockSize
,
2879 (UINT8
*) Private
->BootFileName
,
2885 // If we added a callback protocol, now is the time to remove it.
2887 if (NewMakeCallback
) {
2889 NewMakeCallback
= FALSE
;
2891 PxeBc
->SetParameters (PxeBc
, NULL
, NULL
, NULL
, NULL
, &NewMakeCallback
);
2893 gBS
->UninstallProtocolInterface (
2894 Private
->Controller
,
2895 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2896 &Private
->LoadFileCallback
2901 // Check download status
2903 if (Status
== EFI_SUCCESS
) {
2905 // The functionality of PXE Base Code protocol will not be stopped,
2906 // when downloading is successfully.
2910 } else if (Status
== EFI_BUFFER_TOO_SMALL
) {
2911 if (Buffer
!= NULL
) {
2912 AsciiPrint ("PXE-E05: Download buffer is smaller than requested file.\n");
2915 // The functionality of PXE Base Code protocol will not be stopped.
2920 } else if (Status
== EFI_DEVICE_ERROR
) {
2921 AsciiPrint ("PXE-E07: Network device error.\n");
2923 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
2924 AsciiPrint ("PXE-E09: Could not allocate I/O buffers.\n");
2926 } else if (Status
== EFI_NO_MEDIA
) {
2927 AsciiPrint ("PXE-E12: Could not detect network connection.\n");
2929 } else if (Status
== EFI_NO_RESPONSE
) {
2930 AsciiPrint ("PXE-E16: No offer received.\n");
2932 } else if (Status
== EFI_TIMEOUT
) {
2933 AsciiPrint ("PXE-E18: Server response timeout.\n");
2935 } else if (Status
== EFI_ABORTED
) {
2936 AsciiPrint ("PXE-E21: Remote boot cancelled.\n");
2938 } else if (Status
== EFI_ICMP_ERROR
) {
2939 AsciiPrint ("PXE-E22: Client received ICMP error from server.\n");
2941 } else if (Status
== EFI_TFTP_ERROR
) {
2942 AsciiPrint ("PXE-E23: Client received TFTP error from server.\n");
2945 AsciiPrint ("PXE-E99: Unexpected network error.\n");
2948 PxeBc
->Stop (PxeBc
);
2953 EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate
= { EfiPxeLoadFile
};