2 Interface routines for PxeBc.
4 Copyright (c) 2007 - 2016, 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
,
1442 if (EFI_ERROR (Status
)) {
1443 Private
->CurrentUdpSrcPort
= 0;
1444 return EFI_INVALID_PARAMETER
;
1447 ZeroMem (&Token
, sizeof (EFI_UDP4_COMPLETION_TOKEN
));
1448 ZeroMem (&Udp4Session
, sizeof (EFI_UDP4_SESSION_DATA
));
1450 CopyMem (&Udp4Session
.DestinationAddress
, DestIp
, sizeof (EFI_IPv4_ADDRESS
));
1451 Udp4Session
.DestinationPort
= *DestPort
;
1452 if (SrcIp
!= NULL
) {
1453 CopyMem (&Udp4Session
.SourceAddress
, SrcIp
, sizeof (EFI_IPv4_ADDRESS
));
1455 if (SrcPort
!= NULL
) {
1456 Udp4Session
.SourcePort
= *SrcPort
;
1459 FragCount
= (HeaderSize
!= NULL
) ? 2 : 1;
1460 Udp4TxData
= (EFI_UDP4_TRANSMIT_DATA
*) AllocateZeroPool (sizeof (EFI_UDP4_TRANSMIT_DATA
) + (FragCount
- 1) * sizeof (EFI_UDP4_FRAGMENT_DATA
));
1461 if (Udp4TxData
== NULL
) {
1462 return EFI_OUT_OF_RESOURCES
;
1465 Udp4TxData
->FragmentCount
= FragCount
;
1466 Udp4TxData
->FragmentTable
[FragCount
- 1].FragmentLength
= (UINT32
) *BufferSize
;
1467 Udp4TxData
->FragmentTable
[FragCount
- 1].FragmentBuffer
= BufferPtr
;
1468 DataLength
= (UINT32
) *BufferSize
;
1470 if (FragCount
== 2) {
1472 Udp4TxData
->FragmentTable
[0].FragmentLength
= (UINT32
) *HeaderSize
;
1473 Udp4TxData
->FragmentTable
[0].FragmentBuffer
= HeaderPtr
;
1474 DataLength
+= (UINT32
) *HeaderSize
;
1477 if (GatewayIp
!= NULL
) {
1478 Udp4TxData
->GatewayAddress
= (EFI_IPv4_ADDRESS
*) GatewayIp
;
1480 Udp4TxData
->UdpSessionData
= &Udp4Session
;
1481 Udp4TxData
->DataLength
= DataLength
;
1482 Token
.Packet
.TxData
= Udp4TxData
;
1484 Status
= gBS
->CreateEvent (
1491 if (EFI_ERROR (Status
)) {
1495 Status
= Udp4
->Transmit (Udp4
, &Token
);
1496 if (EFI_ERROR (Status
)) {
1497 if (Status
== EFI_ICMP_ERROR
) {
1498 Mode
->IcmpErrorReceived
= TRUE
;
1508 Status
= Token
.Status
;
1512 if (Token
.Event
!= NULL
) {
1513 gBS
->CloseEvent (Token
.Event
);
1516 FreePool (Udp4TxData
);
1519 // Reset the instance.
1521 Udp4
->Configure (Udp4
, NULL
);
1526 Decide whether the incoming UDP packet is acceptable per IP filter settings
1527 in provided PxeBcMode.
1529 @param PxeBcMode Pointer to EFI_PXE_BASE_CODE_MODE.
1530 @param Session Received UDP session.
1532 @retval TRUE The UDP package matches IP filters.
1533 @retval FALSE The UDP package doesn't matches IP filters.
1538 IN EFI_PXE_BASE_CODE_MODE
*PxeBcMode
,
1539 IN EFI_UDP4_SESSION_DATA
*Session
1543 EFI_IPv4_ADDRESS Ip4Address
;
1544 EFI_IPv4_ADDRESS DestIp4Address
;
1546 if ((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) != 0) {
1550 CopyMem (&DestIp4Address
, &Session
->DestinationAddress
, sizeof (DestIp4Address
));
1551 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
) != 0) &&
1552 IP4_IS_MULTICAST (EFI_NTOHL (DestIp4Address
))
1557 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST
) != 0) &&
1558 IP4_IS_LOCAL_BROADCAST (EFI_NTOHL (DestIp4Address
))
1563 CopyMem (&Ip4Address
, &PxeBcMode
->StationIp
.v4
, sizeof (Ip4Address
));
1564 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0) &&
1565 EFI_IP4_EQUAL (&Ip4Address
, &DestIp4Address
)
1570 ASSERT (PxeBcMode
->IpFilter
.IpCnt
< EFI_PXE_BASE_CODE_MAX_IPCNT
);
1572 for (Index
= 0; Index
< PxeBcMode
->IpFilter
.IpCnt
; Index
++) {
1575 &PxeBcMode
->IpFilter
.IpList
[Index
].v4
,
1578 if (EFI_IP4_EQUAL (&Ip4Address
, &DestIp4Address
)) {
1587 Reads a UDP packet from the network interface.
1589 This function reads a UDP packet from a network interface. The data contents
1590 are returned in (the optional HeaderPtr and) BufferPtr, and the size of the
1591 buffer received is returned in BufferSize . If the input BufferSize is smaller
1592 than the UDP packet received (less optional HeaderSize), it will be set to the
1593 required size, and EFI_BUFFER_TOO_SMALL will be returned. In this case, the
1594 contents of BufferPtr are undefined, and the packet is lost. If a UDP packet is
1595 successfully received, then EFI_SUCCESS will be returned, and the information
1596 from the UDP header will be returned in DestIp, DestPort, SrcIp, and SrcPort if
1597 they are not NULL. Depending on the values of OpFlags and the DestIp, DestPort,
1598 SrcIp, and SrcPort input values, different types of UDP packet receive filtering
1599 will be performed. The following tables summarize these receive filter operations.
1601 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1602 @param OpFlags The UDP operation flags.
1603 @param DestIp The destination IP address.
1604 @param DestPort The destination UDP port number.
1605 @param SrcIp The source IP address.
1606 @param SrcPort The source UDP port number.
1607 @param HeaderSize An optional field which may be set to the length of a header at
1608 HeaderPtr to be prefixed to the data at BufferPtr.
1609 @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the
1611 @param BufferSize A pointer to the size of the data at BufferPtr.
1612 @param BufferPtr A pointer to the data to be read.
1614 @retval EFI_SUCCESS The UDP Read operation was completed.
1615 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1616 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1617 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1618 @retval EFI_BUFFER_TOO_SMALL The packet is larger than Buffer can hold.
1619 @retval EFI_ABORTED The callback function aborted the UDP Read operation.
1620 @retval EFI_TIMEOUT The UDP Read operation timed out.
1626 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1628 IN OUT EFI_IP_ADDRESS
*DestIp OPTIONAL
,
1629 IN OUT EFI_PXE_BASE_CODE_UDP_PORT
*DestPort OPTIONAL
,
1630 IN OUT EFI_IP_ADDRESS
*SrcIp OPTIONAL
,
1631 IN OUT EFI_PXE_BASE_CODE_UDP_PORT
*SrcPort OPTIONAL
,
1632 IN UINTN
*HeaderSize OPTIONAL
,
1633 IN VOID
*HeaderPtr OPTIONAL
,
1634 IN OUT UINTN
*BufferSize
,
1638 PXEBC_PRIVATE_DATA
*Private
;
1639 EFI_PXE_BASE_CODE_MODE
*Mode
;
1640 EFI_UDP4_PROTOCOL
*Udp4
;
1641 EFI_UDP4_COMPLETION_TOKEN Token
;
1642 EFI_UDP4_RECEIVE_DATA
*RxData
;
1643 EFI_UDP4_SESSION_DATA
*Session
;
1649 UINTN HeaderCopiedLen
;
1650 UINTN BufferCopiedLen
;
1651 UINT32 FragmentLength
;
1652 UINTN FragmentIndex
;
1653 UINT8
*FragmentBuffer
;
1655 if (This
== NULL
|| DestIp
== NULL
|| DestPort
== NULL
) {
1656 return EFI_INVALID_PARAMETER
;
1659 if (((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) == 0 && (DestPort
== NULL
)) ||
1660 ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) == 0 && (SrcIp
== NULL
)) ||
1661 ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT
) == 0 && (SrcPort
== NULL
))) {
1662 return EFI_INVALID_PARAMETER
;
1665 if (((HeaderSize
!= NULL
) && (*HeaderSize
== 0)) || ((HeaderSize
!= NULL
) && (HeaderPtr
== NULL
))) {
1666 return EFI_INVALID_PARAMETER
;
1669 if ((BufferSize
== NULL
) || (BufferPtr
== NULL
)) {
1670 return EFI_INVALID_PARAMETER
;
1673 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1674 Mode
= Private
->PxeBc
.Mode
;
1675 Udp4
= Private
->Udp4Read
;
1677 if (!Mode
->Started
) {
1678 return EFI_NOT_STARTED
;
1681 Mode
->IcmpErrorReceived
= FALSE
;
1683 Status
= gBS
->CreateEvent (
1690 if (EFI_ERROR (Status
)) {
1691 return EFI_OUT_OF_RESOURCES
;
1697 Status
= Udp4
->Receive (Udp4
, &Token
);
1698 if (EFI_ERROR (Status
)) {
1699 if (Status
== EFI_ICMP_ERROR
) {
1700 Mode
->IcmpErrorReceived
= TRUE
;
1708 Status
= EFI_TIMEOUT
;
1712 // check whether this packet matches the filters
1714 if (EFI_ERROR (Token
.Status
)){
1718 RxData
= Token
.Packet
.RxData
;
1719 Session
= &RxData
->UdpSession
;
1723 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER
) != 0) {
1726 // Check UDP package by IP filter settings
1728 if (CheckIpByFilter (Mode
, Session
)) {
1737 // Match the destination ip of the received udp dgram
1739 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP
) != 0) {
1742 if (DestIp
!= NULL
) {
1743 CopyMem (DestIp
, &Session
->DestinationAddress
, sizeof (EFI_IPv4_ADDRESS
));
1746 if (DestIp
!= NULL
) {
1747 if (EFI_IP4_EQUAL (DestIp
, &Session
->DestinationAddress
)) {
1751 if (EFI_IP4_EQUAL (&Private
->StationIp
, &Session
->DestinationAddress
)) {
1760 // Match the destination port of the received udp dgram
1762 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) != 0) {
1764 if (DestPort
!= NULL
) {
1765 *DestPort
= Session
->DestinationPort
;
1769 if (*DestPort
!= Session
->DestinationPort
) {
1777 // Match the source ip of the received udp dgram
1779 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP
) != 0) {
1781 if (SrcIp
!= NULL
) {
1782 CopyMem (SrcIp
, &Session
->SourceAddress
, sizeof (EFI_IPv4_ADDRESS
));
1786 if (!EFI_IP4_EQUAL (SrcIp
, &Session
->SourceAddress
)) {
1794 // Match the source port of the received udp dgram
1796 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT
) != 0) {
1798 if (SrcPort
!= NULL
) {
1799 *SrcPort
= Session
->SourcePort
;
1803 if (*SrcPort
!= Session
->SourcePort
) {
1810 ASSERT (RxData
!= NULL
);
1813 if (HeaderSize
!= NULL
) {
1814 HeaderLen
= MIN (*HeaderSize
, RxData
->DataLength
);
1817 if (RxData
->DataLength
- HeaderLen
> *BufferSize
) {
1818 Status
= EFI_BUFFER_TOO_SMALL
;
1820 *HeaderSize
= HeaderLen
;
1821 *BufferSize
= RxData
->DataLength
- HeaderLen
;
1823 HeaderCopiedLen
= 0;
1824 BufferCopiedLen
= 0;
1825 for (FragmentIndex
= 0; FragmentIndex
< RxData
->FragmentCount
; FragmentIndex
++) {
1826 FragmentLength
= RxData
->FragmentTable
[FragmentIndex
].FragmentLength
;
1827 FragmentBuffer
= RxData
->FragmentTable
[FragmentIndex
].FragmentBuffer
;
1828 if (HeaderCopiedLen
+ FragmentLength
< HeaderLen
) {
1830 // Copy the header part of received data.
1832 CopyMem ((UINT8
*) HeaderPtr
+ HeaderCopiedLen
, FragmentBuffer
, FragmentLength
);
1833 HeaderCopiedLen
+= FragmentLength
;
1834 } else if (HeaderCopiedLen
< HeaderLen
) {
1836 // Copy the header part of received data.
1838 CopiedLen
= HeaderLen
- HeaderCopiedLen
;
1839 CopyMem ((UINT8
*) HeaderPtr
+ HeaderCopiedLen
, FragmentBuffer
, CopiedLen
);
1840 HeaderCopiedLen
+= CopiedLen
;
1843 // Copy the other part of received data.
1845 CopyMem ((UINT8
*) BufferPtr
+ BufferCopiedLen
, FragmentBuffer
+ CopiedLen
, FragmentLength
- CopiedLen
);
1846 BufferCopiedLen
+= (FragmentLength
- CopiedLen
);
1849 // Copy the other part of received data.
1851 CopyMem ((UINT8
*) BufferPtr
+ BufferCopiedLen
, FragmentBuffer
, FragmentLength
);
1852 BufferCopiedLen
+= FragmentLength
;
1858 Status
= EFI_TIMEOUT
;
1862 // Recycle the RxData
1864 gBS
->SignalEvent (RxData
->RecycleSignal
);
1873 Udp4
->Cancel (Udp4
, &Token
);
1875 gBS
->CloseEvent (Token
.Event
);
1881 Updates the IP receive filters of a network device and enables software filtering.
1883 The NewFilter field is used to modify the network device's current IP receive
1884 filter settings and to enable a software filter. This function updates the IpFilter
1885 field of the EFI_PXE_BASE_CODE_MODE structure with the contents of NewIpFilter.
1886 The software filter is used when the USE_FILTER in OpFlags is set to UdpRead().
1887 The current hardware filter remains in effect no matter what the settings of OpFlags
1888 are, so that the meaning of ANY_DEST_IP set in OpFlags to UdpRead() is from those
1889 packets whose reception is enabled in hardware-physical NIC address (unicast),
1890 broadcast address, logical address or addresses (multicast), or all (promiscuous).
1891 UdpRead() does not modify the IP filter settings.
1892 Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP receive
1893 filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1894 If an application or driver wishes to preserve the IP receive filter settings,
1895 it will have to preserve the IP receive filter settings before these calls, and
1896 use SetIpFilter() to restore them after the calls. If incompatible filtering is
1897 requested (for example, PROMISCUOUS with anything else) or if the device does not
1898 support a requested filter setting and it cannot be accommodated in software
1899 (for example, PROMISCUOUS not supported), EFI_INVALID_PARAMETER will be returned.
1900 The IPlist field is used to enable IPs other than the StationIP. They may be
1901 multicast or unicast. If IPcnt is set as well as EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP,
1902 then both the StationIP and the IPs from the IPlist will be used.
1904 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1905 @param NewFilter Pointer to the new set of IP receive filters.
1907 @retval EFI_SUCCESS The IP receive filter settings were updated.
1908 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1909 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1914 EfiPxeBcSetIpFilter (
1915 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1916 IN EFI_PXE_BASE_CODE_IP_FILTER
*NewFilter
1920 PXEBC_PRIVATE_DATA
*Private
;
1921 EFI_PXE_BASE_CODE_MODE
*Mode
;
1923 EFI_UDP4_CONFIG_DATA
*Udp4Cfg
;
1924 BOOLEAN PromiscuousNeed
;
1925 BOOLEAN AcceptPromiscuous
;
1926 BOOLEAN AcceptBroadcast
;
1927 BOOLEAN MultiCastUpdate
;
1930 DEBUG ((EFI_D_ERROR
, "This == NULL.\n"));
1931 return EFI_INVALID_PARAMETER
;
1934 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1935 Mode
= Private
->PxeBc
.Mode
;
1937 if (NewFilter
== NULL
) {
1938 DEBUG ((EFI_D_ERROR
, "NewFilter == NULL.\n"));
1939 return EFI_INVALID_PARAMETER
;
1942 if (NewFilter
->IpCnt
> EFI_PXE_BASE_CODE_MAX_IPCNT
) {
1943 DEBUG ((EFI_D_ERROR
, "NewFilter->IpCnt > %d.\n", EFI_PXE_BASE_CODE_MAX_IPCNT
));
1944 return EFI_INVALID_PARAMETER
;
1947 if (!Mode
->Started
) {
1948 DEBUG ((EFI_D_ERROR
, "BC was not started.\n"));
1949 return EFI_NOT_STARTED
;
1952 if (Mode
->UsingIpv6
) {
1953 DEBUG ((EFI_D_ERROR
, "This driver is PXE for IPv4 Only.\n"));
1954 return EFI_INVALID_PARAMETER
;
1957 PromiscuousNeed
= FALSE
;
1959 for (Index
= 0; Index
< NewFilter
->IpCnt
; ++Index
) {
1960 if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (NewFilter
->IpList
[Index
].v4
))) {
1962 // The IP is a broadcast address.
1964 DEBUG ((EFI_D_ERROR
, "There is broadcast address in NewFilter.\n"));
1965 return EFI_INVALID_PARAMETER
;
1967 if (NetIp4IsUnicast (EFI_IP4 (NewFilter
->IpList
[Index
].v4
), 0) &&
1968 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0)
1971 // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList,
1972 // promiscuous mode is needed.
1974 PromiscuousNeed
= TRUE
;
1978 AcceptPromiscuous
= FALSE
;
1979 AcceptBroadcast
= FALSE
;
1980 MultiCastUpdate
= FALSE
;
1982 if (PromiscuousNeed
||
1983 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) != 0) ||
1984 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
) != 0)
1987 // Configure the udp4 filter to receive all packages.
1989 AcceptPromiscuous
= TRUE
;
1990 } else if ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST
) != 0) {
1992 // Configure the udp4 filter to receive all broadcast packages.
1994 AcceptBroadcast
= TRUE
;
1998 // In multicast condition when Promiscuous FALSE and IpCnt no-zero.
1999 // Here check if there is any update of the multicast ip address. If yes,
2000 // we need leave the old multicast group (by Config UDP instance to NULL),
2001 // and join the new multicast group.
2003 if (!AcceptPromiscuous
) {
2004 if ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0) {
2005 if (Mode
->IpFilter
.IpCnt
!= NewFilter
->IpCnt
) {
2006 MultiCastUpdate
= TRUE
;
2007 } else if (CompareMem (Mode
->IpFilter
.IpList
, NewFilter
->IpList
, NewFilter
->IpCnt
* sizeof (EFI_IP_ADDRESS
)) != 0 ) {
2008 MultiCastUpdate
= TRUE
;
2014 // Check whether we need reconfigure the UDP instance.
2016 Udp4Cfg
= &Private
->Udp4CfgData
;
2017 if ((AcceptPromiscuous
!= Udp4Cfg
->AcceptPromiscuous
) ||
2018 (AcceptBroadcast
!= Udp4Cfg
->AcceptBroadcast
) || MultiCastUpdate
) {
2020 // Clear the UDP instance configuration, all joined groups will be left
2021 // during the operation.
2023 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
2026 // Configure the UDP instance with the new configuration.
2028 Udp4Cfg
->AcceptPromiscuous
= AcceptPromiscuous
;
2029 Udp4Cfg
->AcceptBroadcast
= AcceptBroadcast
;
2030 Status
= Private
->Udp4Read
->Configure (Private
->Udp4Read
, Udp4Cfg
);
2031 if (EFI_ERROR (Status
)) {
2036 // In not Promiscuous mode, need to join the new multicast group.
2038 if (!AcceptPromiscuous
) {
2039 for (Index
= 0; Index
< NewFilter
->IpCnt
; ++Index
) {
2040 if (IP4_IS_MULTICAST (EFI_NTOHL (NewFilter
->IpList
[Index
].v4
))) {
2042 // Join the mutilcast group.
2044 Status
= Private
->Udp4Read
->Groups (Private
->Udp4Read
, TRUE
, &NewFilter
->IpList
[Index
].v4
);
2045 if (EFI_ERROR (Status
)) {
2055 // Save the new filter.
2057 CopyMem (&Mode
->IpFilter
, NewFilter
, sizeof (Mode
->IpFilter
));
2064 Uses the ARP protocol to resolve a MAC address.
2066 This function uses the ARP protocol to resolve a MAC address. The UsingIpv6 field
2067 of the EFI_PXE_BASE_CODE_MODE structure is used to determine if IPv4 or IPv6
2068 addresses are being used. The IP address specified by IpAddr is used to resolve
2069 a MAC address. If the ARP protocol succeeds in resolving the specified address,
2070 then the ArpCacheEntries and ArpCache fields of the EFI_PXE_BASE_CODE_MODE structure
2071 are updated, and EFI_SUCCESS is returned. If MacAddr is not NULL, the resolved
2072 MAC address is placed there as well. If the PXE Base Code protocol is in the
2073 stopped state, then EFI_NOT_STARTED is returned. If the ARP protocol encounters
2074 a timeout condition while attempting to resolve an address, then EFI_TIMEOUT is
2075 returned. If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
2076 then EFI_ABORTED is returned.
2078 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2079 @param IpAddr Pointer to the IP address that is used to resolve a MAC address.
2080 @param MacAddr If not NULL, a pointer to the MAC address that was resolved with the
2083 @retval EFI_SUCCESS The IP or MAC address was resolved.
2084 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2085 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2086 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
2087 @retval EFI_ICMP_ERROR Something error occur with the ICMP packet message.
2093 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2094 IN EFI_IP_ADDRESS
* IpAddr
,
2095 IN EFI_MAC_ADDRESS
* MacAddr OPTIONAL
2098 PXEBC_PRIVATE_DATA
*Private
;
2099 EFI_PXE_BASE_CODE_MODE
*Mode
;
2101 EFI_MAC_ADDRESS TempMacAddr
;
2103 if (This
== NULL
|| IpAddr
== NULL
) {
2104 return EFI_INVALID_PARAMETER
;
2107 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2108 Mode
= Private
->PxeBc
.Mode
;
2110 if (!Mode
->Started
) {
2111 return EFI_NOT_STARTED
;
2114 if (!Private
->AddressIsOk
|| Mode
->UsingIpv6
) {
2116 // We can't resolve the IP address if we don't have a local address now.
2117 // Don't have ARP for IPv6.
2119 return EFI_INVALID_PARAMETER
;
2122 Mode
->IcmpErrorReceived
= FALSE
;
2124 if (!Mode
->AutoArp
) {
2126 // If AutoArp is set false, check arp cache
2128 UpdateArpCache (This
);
2129 if (!FindInArpCache (Mode
, &IpAddr
->v4
, &TempMacAddr
)) {
2130 return EFI_DEVICE_ERROR
;
2133 Status
= Private
->Arp
->Request (Private
->Arp
, &IpAddr
->v4
, NULL
, &TempMacAddr
);
2134 if (EFI_ERROR (Status
)) {
2135 if (Status
== EFI_ICMP_ERROR
) {
2136 Mode
->IcmpErrorReceived
= TRUE
;
2142 if (MacAddr
!= NULL
) {
2143 CopyMem (MacAddr
, &TempMacAddr
, sizeof (EFI_MAC_ADDRESS
));
2150 Updates the parameters that affect the operation of the PXE Base Code Protocol.
2152 This function sets parameters that affect the operation of the PXE Base Code Protocol.
2153 The parameter specified by NewAutoArp is used to control the generation of ARP
2154 protocol packets. If NewAutoArp is TRUE, then ARP Protocol packets will be generated
2155 as required by the PXE Base Code Protocol. If NewAutoArp is FALSE, then no ARP
2156 Protocol packets will be generated. In this case, the only mappings that are
2157 available are those stored in the ArpCache of the EFI_PXE_BASE_CODE_MODE structure.
2158 If there are not enough mappings in the ArpCache to perform a PXE Base Code Protocol
2159 service, then the service will fail. This function updates the AutoArp field of
2160 the EFI_PXE_BASE_CODE_MODE structure to NewAutoArp.
2161 The SetParameters() call must be invoked after a Callback Protocol is installed
2162 to enable the use of callbacks.
2164 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2165 @param NewAutoArp If not NULL, a pointer to a value that specifies whether to replace the
2166 current value of AutoARP.
2167 @param NewSendGUID If not NULL, a pointer to a value that specifies whether to replace the
2168 current value of SendGUID.
2169 @param NewTTL If not NULL, a pointer to be used in place of the current value of TTL,
2170 the "time to live" field of the IP header.
2171 @param NewToS If not NULL, a pointer to be used in place of the current value of ToS,
2172 the "type of service" field of the IP header.
2173 @param NewMakeCallback If not NULL, a pointer to a value that specifies whether to replace the
2174 current value of the MakeCallback field of the Mode structure.
2176 @retval EFI_SUCCESS The new parameters values were updated.
2177 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2178 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2183 EfiPxeBcSetParameters (
2184 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
2185 IN BOOLEAN
*NewAutoArp OPTIONAL
,
2186 IN BOOLEAN
*NewSendGUID OPTIONAL
,
2187 IN UINT8
*NewTTL OPTIONAL
,
2188 IN UINT8
*NewToS OPTIONAL
,
2189 IN BOOLEAN
*NewMakeCallback
// OPTIONAL
2192 PXEBC_PRIVATE_DATA
*Private
;
2193 EFI_PXE_BASE_CODE_MODE
*Mode
;
2196 Status
= EFI_SUCCESS
;
2199 Status
= EFI_INVALID_PARAMETER
;
2203 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2204 Mode
= Private
->PxeBc
.Mode
;
2206 if (NewSendGUID
!= NULL
&& *NewSendGUID
) {
2208 // FixMe, cann't locate SendGuid
2212 if (NewMakeCallback
!= NULL
&& *NewMakeCallback
) {
2214 Status
= gBS
->HandleProtocol (
2215 Private
->Controller
,
2216 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2217 (VOID
**) &Private
->PxeBcCallback
2219 if (EFI_ERROR (Status
) || (Private
->PxeBcCallback
->Callback
== NULL
)) {
2221 Status
= EFI_INVALID_PARAMETER
;
2226 if (!Mode
->Started
) {
2227 Status
= EFI_NOT_STARTED
;
2231 if (NewMakeCallback
!= NULL
) {
2233 if (*NewMakeCallback
) {
2235 // Update the Callback protocol.
2237 Status
= gBS
->HandleProtocol (
2238 Private
->Controller
,
2239 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2240 (VOID
**) &Private
->PxeBcCallback
2243 if (EFI_ERROR (Status
) || (Private
->PxeBcCallback
->Callback
== NULL
)) {
2244 Status
= EFI_INVALID_PARAMETER
;
2248 Private
->PxeBcCallback
= NULL
;
2251 Mode
->MakeCallbacks
= *NewMakeCallback
;
2254 if (NewAutoArp
!= NULL
) {
2255 Mode
->AutoArp
= *NewAutoArp
;
2258 if (NewSendGUID
!= NULL
) {
2259 Mode
->SendGUID
= *NewSendGUID
;
2262 if (NewTTL
!= NULL
) {
2263 Mode
->TTL
= *NewTTL
;
2266 if (NewToS
!= NULL
) {
2267 Mode
->ToS
= *NewToS
;
2275 Updates the station IP address and/or subnet mask values of a network device.
2277 This function updates the station IP address and/or subnet mask values of a network
2278 device. The NewStationIp field is used to modify the network device's current IP address.
2279 If NewStationIP is NULL, then the current IP address will not be modified. Otherwise,
2280 this function updates the StationIp field of the EFI_PXE_BASE_CODE_MODE structure
2281 with NewStationIp. The NewSubnetMask field is used to modify the network device's current subnet
2282 mask. If NewSubnetMask is NULL, then the current subnet mask will not be modified.
2283 Otherwise, this function updates the SubnetMask field of the EFI_PXE_BASE_CODE_MODE
2284 structure with NewSubnetMask.
2286 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2287 @param NewStationIp Pointer to the new IP address to be used by the network device.
2288 @param NewSubnetMask Pointer to the new subnet mask to be used by the network device.
2290 @retval EFI_SUCCESS The new station IP address and/or subnet mask were updated.
2291 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2292 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2297 EfiPxeBcSetStationIP (
2298 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2299 IN EFI_IP_ADDRESS
* NewStationIp OPTIONAL
,
2300 IN EFI_IP_ADDRESS
* NewSubnetMask OPTIONAL
2303 PXEBC_PRIVATE_DATA
*Private
;
2304 EFI_PXE_BASE_CODE_MODE
*Mode
;
2305 EFI_ARP_CONFIG_DATA ArpConfigData
;
2308 return EFI_INVALID_PARAMETER
;
2311 if (NewStationIp
!= NULL
&& !NetIp4IsUnicast (NTOHL (NewStationIp
->Addr
[0]), 0)) {
2312 return EFI_INVALID_PARAMETER
;
2315 if (NewSubnetMask
!= NULL
&& !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask
->Addr
[0]))) {
2316 return EFI_INVALID_PARAMETER
;
2319 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2320 Mode
= Private
->PxeBc
.Mode
;
2322 if (!Mode
->Started
) {
2323 return EFI_NOT_STARTED
;
2326 if (NewStationIp
!= NULL
) {
2327 CopyMem (&Mode
->StationIp
, NewStationIp
, sizeof (EFI_IP_ADDRESS
));
2328 CopyMem (&Private
->StationIp
, NewStationIp
, sizeof (EFI_IP_ADDRESS
));
2331 if (NewSubnetMask
!= NULL
) {
2332 CopyMem (&Mode
->SubnetMask
, NewSubnetMask
, sizeof (EFI_IP_ADDRESS
));
2333 CopyMem (&Private
->SubnetMask
,NewSubnetMask
, sizeof (EFI_IP_ADDRESS
));
2336 Private
->AddressIsOk
= TRUE
;
2338 if (!Mode
->UsingIpv6
) {
2340 // If in IPv4 mode, configure the corresponding ARP with this new
2341 // station IP address.
2343 ZeroMem (&ArpConfigData
, sizeof (EFI_ARP_CONFIG_DATA
));
2345 ArpConfigData
.SwAddressType
= 0x0800;
2346 ArpConfigData
.SwAddressLength
= (UINT8
) sizeof (EFI_IPv4_ADDRESS
);
2347 ArpConfigData
.StationAddress
= &Private
->StationIp
.v4
;
2349 Private
->Arp
->Configure (Private
->Arp
, NULL
);
2350 Private
->Arp
->Configure (Private
->Arp
, &ArpConfigData
);
2353 // Update the route table.
2355 Mode
->RouteTableEntries
= 1;
2356 Mode
->RouteTable
[0].IpAddr
.Addr
[0] = Private
->StationIp
.Addr
[0] & Private
->SubnetMask
.Addr
[0];
2357 Mode
->RouteTable
[0].SubnetMask
.Addr
[0] = Private
->SubnetMask
.Addr
[0];
2358 Mode
->RouteTable
[0].GwAddr
.Addr
[0] = 0;
2365 Updates the contents of the cached DHCP and Discover packets.
2367 The pointers to the new packets are used to update the contents of the cached
2368 packets in the EFI_PXE_BASE_CODE_MODE structure.
2370 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2371 @param NewDhcpDiscoverValid Pointer to a value that will replace the current
2372 DhcpDiscoverValid field.
2373 @param NewDhcpAckReceived Pointer to a value that will replace the current
2374 DhcpAckReceived field.
2375 @param NewProxyOfferReceived Pointer to a value that will replace the current
2376 ProxyOfferReceived field.
2377 @param NewPxeDiscoverValid Pointer to a value that will replace the current
2378 ProxyOfferReceived field.
2379 @param NewPxeReplyReceived Pointer to a value that will replace the current
2380 PxeReplyReceived field.
2381 @param NewPxeBisReplyReceived Pointer to a value that will replace the current
2382 PxeBisReplyReceived field.
2383 @param NewDhcpDiscover Pointer to the new cached DHCP Discover packet contents.
2384 @param NewDhcpAck Pointer to the new cached DHCP Ack packet contents.
2385 @param NewProxyOffer Pointer to the new cached Proxy Offer packet contents.
2386 @param NewPxeDiscover Pointer to the new cached PXE Discover packet contents.
2387 @param NewPxeReply Pointer to the new cached PXE Reply packet contents.
2388 @param NewPxeBisReply Pointer to the new cached PXE BIS Reply packet contents.
2390 @retval EFI_SUCCESS The cached packet contents were updated.
2391 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2392 @retval EFI_INVALID_PARAMETER This is NULL or not point to a valid EFI_PXE_BASE_CODE_PROTOCOL structure.
2397 EfiPxeBcSetPackets (
2398 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2399 IN BOOLEAN
* NewDhcpDiscoverValid OPTIONAL
,
2400 IN BOOLEAN
* NewDhcpAckReceived OPTIONAL
,
2401 IN BOOLEAN
* NewProxyOfferReceived OPTIONAL
,
2402 IN BOOLEAN
* NewPxeDiscoverValid OPTIONAL
,
2403 IN BOOLEAN
* NewPxeReplyReceived OPTIONAL
,
2404 IN BOOLEAN
* NewPxeBisReplyReceived OPTIONAL
,
2405 IN EFI_PXE_BASE_CODE_PACKET
* NewDhcpDiscover OPTIONAL
,
2406 IN EFI_PXE_BASE_CODE_PACKET
* NewDhcpAck OPTIONAL
,
2407 IN EFI_PXE_BASE_CODE_PACKET
* NewProxyOffer OPTIONAL
,
2408 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeDiscover OPTIONAL
,
2409 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeReply OPTIONAL
,
2410 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeBisReply OPTIONAL
2413 PXEBC_PRIVATE_DATA
*Private
;
2414 EFI_PXE_BASE_CODE_MODE
*Mode
;
2417 return EFI_INVALID_PARAMETER
;
2420 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2421 Mode
= Private
->PxeBc
.Mode
;
2423 if (!Mode
->Started
) {
2424 return EFI_NOT_STARTED
;
2427 if (NewDhcpDiscoverValid
!= NULL
) {
2428 Mode
->DhcpDiscoverValid
= *NewDhcpDiscoverValid
;
2431 if (NewDhcpAckReceived
!= NULL
) {
2432 Mode
->DhcpAckReceived
= *NewDhcpAckReceived
;
2435 if (NewProxyOfferReceived
!= NULL
) {
2436 Mode
->ProxyOfferReceived
= *NewProxyOfferReceived
;
2439 if (NewPxeDiscoverValid
!= NULL
) {
2440 Mode
->PxeDiscoverValid
= *NewPxeDiscoverValid
;
2443 if (NewPxeReplyReceived
!= NULL
) {
2444 Mode
->PxeReplyReceived
= *NewPxeReplyReceived
;
2447 if (NewPxeBisReplyReceived
!= NULL
) {
2448 Mode
->PxeBisReplyReceived
= *NewPxeBisReplyReceived
;
2451 if (NewDhcpDiscover
!= NULL
) {
2452 CopyMem (&Mode
->DhcpDiscover
, NewDhcpDiscover
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2455 if (NewDhcpAck
!= NULL
) {
2456 CopyMem (&Mode
->DhcpAck
, NewDhcpAck
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2459 if (NewProxyOffer
!= NULL
) {
2460 CopyMem (&Mode
->ProxyOffer
, NewProxyOffer
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2463 if (NewPxeDiscover
!= NULL
) {
2464 CopyMem (&Mode
->PxeDiscover
, NewPxeDiscover
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2467 if (NewPxeReply
!= NULL
) {
2468 CopyMem (&Mode
->PxeReply
, NewPxeReply
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2471 if (NewPxeBisReply
!= NULL
) {
2472 CopyMem (&Mode
->PxeBisReply
, NewPxeBisReply
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2478 EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate
= {
2479 EFI_PXE_BASE_CODE_PROTOCOL_REVISION
,
2487 EfiPxeBcSetIpFilter
,
2489 EfiPxeBcSetParameters
,
2490 EfiPxeBcSetStationIP
,
2496 Callback function that is invoked when the PXE Base Code Protocol is about to transmit, has
2497 received, or is waiting to receive a packet.
2499 This function is invoked when the PXE Base Code Protocol is about to transmit, has received,
2500 or is waiting to receive a packet. Parameters Function and Received specify the type of event.
2501 Parameters PacketLen and Packet specify the packet that generated the event. If these fields
2502 are zero and NULL respectively, then this is a status update callback. If the operation specified
2503 by Function is to continue, then CALLBACK_STATUS_CONTINUE should be returned. If the operation
2504 specified by Function should be aborted, then CALLBACK_STATUS_ABORT should be returned. Due to
2505 the polling nature of UEFI device drivers, a callback function should not execute for more than 5 ms.
2506 The SetParameters() function must be called after a Callback Protocol is installed to enable the
2509 @param This Pointer to the EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL instance.
2510 @param Function The PXE Base Code Protocol function that is waiting for an event.
2511 @param Received TRUE if the callback is being invoked due to a receive event. FALSE if
2512 the callback is being invoked due to a transmit event.
2513 @param PacketLength The length, in bytes, of Packet. This field will have a value of zero if
2514 this is a wait for receive event.
2515 @param PacketPtr If Received is TRUE, a pointer to the packet that was just received;
2516 otherwise a pointer to the packet that is about to be transmitted.
2518 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE if Function specifies a continue operation
2519 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT if Function specifies an abort operation
2522 EFI_PXE_BASE_CODE_CALLBACK_STATUS
2524 EfiPxeLoadFileCallback (
2525 IN EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL
* This
,
2526 IN EFI_PXE_BASE_CODE_FUNCTION Function
,
2527 IN BOOLEAN Received
,
2528 IN UINT32 PacketLength
,
2529 IN EFI_PXE_BASE_CODE_PACKET
* PacketPtr OPTIONAL
2536 // Catch Ctrl-C or ESC to abort.
2538 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2540 if (!EFI_ERROR (Status
)) {
2542 if (Key
.ScanCode
== SCAN_ESC
|| Key
.UnicodeChar
== (0x1F & 'c')) {
2544 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT
;
2548 // No print if receive packet
2551 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2554 // Print only for three functions
2558 case EFI_PXE_BASE_CODE_FUNCTION_MTFTP
:
2560 // Print only for open MTFTP packets, not every MTFTP packets
2562 if (PacketLength
!= 0 && PacketPtr
!= NULL
) {
2563 if (PacketPtr
->Raw
[0x1C] != 0x00 || PacketPtr
->Raw
[0x1D] != 0x01) {
2564 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2569 case EFI_PXE_BASE_CODE_FUNCTION_DHCP
:
2570 case EFI_PXE_BASE_CODE_FUNCTION_DISCOVER
:
2574 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2577 if (PacketLength
!= 0 && PacketPtr
!= NULL
) {
2579 // Print '.' when transmit a packet
2585 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2588 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL mPxeBcCallBackTemplate
= {
2589 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_REVISION
,
2590 EfiPxeLoadFileCallback
2597 @param Private Pointer to PxeBc private data.
2598 @param BufferSize Pointer to buffer size.
2599 @param Buffer Pointer to buffer.
2601 @retval EFI_SUCCESS Discover the boot file successfully.
2602 @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.
2603 @retval EFI_ABORTED PXE bootstrap server, so local boot need abort.
2604 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to load the boot file.
2609 IN PXEBC_PRIVATE_DATA
*Private
,
2610 IN OUT UINT64
*BufferSize
,
2614 EFI_PXE_BASE_CODE_PROTOCOL
*PxeBc
;
2615 EFI_PXE_BASE_CODE_MODE
*Mode
;
2620 PXEBC_CACHED_DHCP4_PACKET
*Packet
;
2623 PxeBc
= &Private
->PxeBc
;
2625 Type
= EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP
;
2626 Layer
= EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL
;
2631 Status
= PxeBc
->Dhcp (PxeBc
, TRUE
);
2632 if (EFI_ERROR (Status
)) {
2637 // Select a boot server
2639 Status
= PxeBcSelectBootPrompt (Private
);
2641 if (Status
== EFI_SUCCESS
) {
2642 Status
= PxeBcSelectBootMenu (Private
, &Type
, TRUE
);
2643 } else if (Status
== EFI_TIMEOUT
) {
2644 Status
= PxeBcSelectBootMenu (Private
, &Type
, FALSE
);
2647 if (!EFI_ERROR (Status
)) {
2649 if (Type
== EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP
) {
2651 // Local boot(PXE bootstrap server) need abort
2656 UseBis
= (BOOLEAN
) (Mode
->BisSupported
&& Mode
->BisDetected
);
2657 Status
= PxeBc
->Discover (PxeBc
, Type
, &Layer
, UseBis
, NULL
);
2658 if (EFI_ERROR (Status
)) {
2666 // Get bootfile name and (m)tftp server ip addresss
2668 if (Mode
->PxeReplyReceived
) {
2669 Packet
= &Private
->PxeReply
;
2670 } else if (Mode
->ProxyOfferReceived
) {
2671 Packet
= &Private
->ProxyOffer
;
2673 Packet
= &Private
->Dhcp4Ack
;
2677 // Use siaddr(next server) in DHCPOFFER packet header, if zero, use option 54(server identifier)
2678 // in DHCPOFFER packet.
2679 // (It does not comply with PXE Spec, Ver2.1)
2681 if (EFI_IP4_EQUAL (&Packet
->Packet
.Offer
.Dhcp4
.Header
.ServerAddr
, &mZeroIp4Addr
)) {
2684 Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_SERVER_ID
]->Data
,
2685 sizeof (EFI_IPv4_ADDRESS
)
2690 &Packet
->Packet
.Offer
.Dhcp4
.Header
.ServerAddr
,
2691 sizeof (EFI_IPv4_ADDRESS
)
2694 if (Private
->ServerIp
.Addr
[0] == 0) {
2695 return EFI_DEVICE_ERROR
;
2698 ASSERT (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE
] != NULL
);
2703 Private
->BootFileName
= (CHAR8
*) (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE
]->Data
);
2705 if (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN
] != NULL
) {
2707 // Already have the bootfile length option, compute the file size
2709 CopyMem (&Value
, Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN
]->Data
, sizeof (Value
));
2710 Value
= NTOHS (Value
);
2711 *BufferSize
= 512 * Value
;
2712 Status
= EFI_BUFFER_TOO_SMALL
;
2715 // Get the bootfile size from tftp
2717 Status
= PxeBc
->Mtftp (
2719 EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE
,
2723 &Private
->BlockSize
,
2725 (UINT8
*) Private
->BootFileName
,
2731 Private
->FileSize
= (UINTN
) *BufferSize
;
2737 Causes the driver to load a specified file.
2739 @param This Protocol instance pointer.
2740 @param FilePath The device specific path of the file to load.
2741 @param BootPolicy If TRUE, indicates that the request originates from the
2742 boot manager is attempting to load FilePath as a boot
2743 selection. If FALSE, then FilePath must match as exact file
2745 @param BufferSize On input the size of Buffer in bytes. On output with a return
2746 code of EFI_SUCCESS, the amount of data transferred to
2747 Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
2748 the size of Buffer required to retrieve the requested file.
2749 @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
2750 then no the size of the requested file is returned in
2753 @retval EFI_SUCCESS The file was loaded.
2754 @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy
2755 @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or
2757 @retval EFI_NO_MEDIA No medium was present to load the file.
2758 @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.
2759 @retval EFI_NO_RESPONSE The remote system did not respond.
2760 @retval EFI_NOT_FOUND The file was not found.
2761 @retval EFI_ABORTED The file load process was manually cancelled.
2767 IN EFI_LOAD_FILE_PROTOCOL
* This
,
2768 IN EFI_DEVICE_PATH_PROTOCOL
* FilePath
,
2769 IN BOOLEAN BootPolicy
,
2770 IN OUT UINTN
*BufferSize
,
2771 IN VOID
*Buffer OPTIONAL
2774 PXEBC_PRIVATE_DATA
*Private
;
2775 EFI_PXE_BASE_CODE_PROTOCOL
*PxeBc
;
2776 BOOLEAN NewMakeCallback
;
2779 BOOLEAN MediaPresent
;
2781 if (FilePath
== NULL
|| !IsDevicePathEnd (FilePath
)) {
2782 return EFI_INVALID_PARAMETER
;
2785 Private
= PXEBC_PRIVATE_DATA_FROM_LOADFILE (This
);
2786 PxeBc
= &Private
->PxeBc
;
2787 NewMakeCallback
= FALSE
;
2788 Status
= EFI_DEVICE_ERROR
;
2790 if (This
== NULL
|| BufferSize
== NULL
) {
2792 return EFI_INVALID_PARAMETER
;
2796 // Only support BootPolicy
2799 return EFI_UNSUPPORTED
;
2803 // Check media status before PXE start
2805 MediaPresent
= TRUE
;
2806 NetLibDetectMedia (Private
->Controller
, &MediaPresent
);
2807 if (!MediaPresent
) {
2808 return EFI_NO_MEDIA
;
2811 Status
= PxeBc
->Start (PxeBc
, FALSE
);
2812 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
2816 Status
= gBS
->HandleProtocol (
2817 Private
->Controller
,
2818 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2819 (VOID
**) &Private
->PxeBcCallback
2821 if (Status
== EFI_UNSUPPORTED
) {
2823 CopyMem (&Private
->LoadFileCallback
, &mPxeBcCallBackTemplate
, sizeof (Private
->LoadFileCallback
));
2825 Status
= gBS
->InstallProtocolInterface (
2826 &Private
->Controller
,
2827 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2828 EFI_NATIVE_INTERFACE
,
2829 &Private
->LoadFileCallback
2832 NewMakeCallback
= (BOOLEAN
) (Status
== EFI_SUCCESS
);
2834 Status
= PxeBc
->SetParameters (PxeBc
, NULL
, NULL
, NULL
, NULL
, &NewMakeCallback
);
2835 if (EFI_ERROR (Status
)) {
2836 PxeBc
->Stop (PxeBc
);
2841 if (Private
->FileSize
== 0) {
2843 Status
= DiscoverBootFile (Private
, &TmpBufSize
, Buffer
);
2845 if (sizeof (UINTN
) < sizeof (UINT64
) && (TmpBufSize
> 0xFFFFFFFF)) {
2846 Status
= EFI_DEVICE_ERROR
;
2847 } else if (TmpBufSize
> 0 && *BufferSize
>= (UINTN
) TmpBufSize
&& Buffer
!= NULL
) {
2848 *BufferSize
= (UINTN
) TmpBufSize
;
2849 Status
= PxeBc
->Mtftp (
2851 EFI_PXE_BASE_CODE_TFTP_READ_FILE
,
2855 &Private
->BlockSize
,
2857 (UINT8
*) Private
->BootFileName
,
2861 } else if (TmpBufSize
> 0) {
2862 *BufferSize
= (UINTN
) TmpBufSize
;
2863 Status
= EFI_BUFFER_TOO_SMALL
;
2865 } else if (Buffer
== NULL
|| Private
->FileSize
> *BufferSize
) {
2866 *BufferSize
= Private
->FileSize
;
2867 Status
= EFI_BUFFER_TOO_SMALL
;
2870 // Download the file.
2872 TmpBufSize
= (UINT64
) (*BufferSize
);
2873 Status
= PxeBc
->Mtftp (
2875 EFI_PXE_BASE_CODE_TFTP_READ_FILE
,
2879 &Private
->BlockSize
,
2881 (UINT8
*) Private
->BootFileName
,
2887 // If we added a callback protocol, now is the time to remove it.
2889 if (NewMakeCallback
) {
2891 NewMakeCallback
= FALSE
;
2893 PxeBc
->SetParameters (PxeBc
, NULL
, NULL
, NULL
, NULL
, &NewMakeCallback
);
2895 gBS
->UninstallProtocolInterface (
2896 Private
->Controller
,
2897 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2898 &Private
->LoadFileCallback
2903 // Check download status
2905 if (Status
== EFI_SUCCESS
) {
2907 // The DHCP4 can have only one configured child instance so we need to stop
2908 // reset the DHCP4 child before we return. Otherwise the other programs which
2909 // also need to use DHCP4 will be impacted.
2910 // The functionality of PXE Base Code protocol will not be stopped,
2911 // when downloading is successfully.
2913 Private
->Dhcp4
->Stop (Private
->Dhcp4
);
2914 Private
->Dhcp4
->Configure (Private
->Dhcp4
, NULL
);
2917 } else if (Status
== EFI_BUFFER_TOO_SMALL
) {
2918 if (Buffer
!= NULL
) {
2919 AsciiPrint ("PXE-E05: Download buffer is smaller than requested file.\n");
2922 // The functionality of PXE Base Code protocol will not be stopped.
2927 } else if (Status
== EFI_DEVICE_ERROR
) {
2928 AsciiPrint ("PXE-E07: Network device error.\n");
2930 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
2931 AsciiPrint ("PXE-E09: Could not allocate I/O buffers.\n");
2933 } else if (Status
== EFI_NO_MEDIA
) {
2934 AsciiPrint ("PXE-E12: Could not detect network connection.\n");
2936 } else if (Status
== EFI_NO_RESPONSE
) {
2937 AsciiPrint ("PXE-E16: No offer received.\n");
2939 } else if (Status
== EFI_TIMEOUT
) {
2940 AsciiPrint ("PXE-E18: Server response timeout.\n");
2942 } else if (Status
== EFI_ABORTED
) {
2943 AsciiPrint ("PXE-E21: Remote boot cancelled.\n");
2945 } else if (Status
== EFI_ICMP_ERROR
) {
2946 AsciiPrint ("PXE-E22: Client received ICMP error from server.\n");
2948 } else if (Status
== EFI_TFTP_ERROR
) {
2949 AsciiPrint ("PXE-E23: Client received TFTP error from server.\n");
2952 AsciiPrint ("PXE-E99: Unexpected network error.\n");
2955 PxeBc
->Stop (PxeBc
);
2960 EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate
= { EfiPxeLoadFile
};