2 Interface routines for PxeBc.
4 Copyright (c) 2007 - 2017, 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 (RxData
== NULL
) {
173 if (Status
!= EFI_ICMP_ERROR
) {
175 // The return status should be recognized as EFI_ICMP_ERROR.
180 if (EFI_IP4 (RxData
->Header
->SourceAddress
) != 0 &&
181 (NTOHL (Mode
->SubnetMask
.Addr
[0]) != 0) &&
182 IP4_NET_EQUAL (NTOHL(Mode
->StationIp
.Addr
[0]), EFI_NTOHL (RxData
->Header
->SourceAddress
), NTOHL (Mode
->SubnetMask
.Addr
[0])) &&
183 !NetIp4IsUnicast (EFI_NTOHL (RxData
->Header
->SourceAddress
), NTOHL (Mode
->SubnetMask
.Addr
[0]))) {
185 // The source address is not zero and it's not a unicast IP address, discard it.
190 if (!EFI_IP4_EQUAL (&RxData
->Header
->DestinationAddress
, &Mode
->StationIp
.v4
)) {
192 // The dest address is not equal to Station Ip address, discard it.
198 // Constructor ICMP error packet
201 CopiedPointer
= (UINT8
*) &Mode
->IcmpError
;
203 for (Index
= 0; Index
< RxData
->FragmentCount
; Index
++) {
204 CopiedLen
+= RxData
->FragmentTable
[Index
].FragmentLength
;
205 if (CopiedLen
<= sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR
)) {
208 RxData
->FragmentTable
[Index
].FragmentBuffer
,
209 RxData
->FragmentTable
[Index
].FragmentLength
214 RxData
->FragmentTable
[Index
].FragmentBuffer
,
215 CopiedLen
- sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR
)
218 CopiedPointer
+= CopiedLen
;
222 gBS
->SignalEvent (RxData
->RecycleSignal
);
225 Ip4
->Receive (Ip4
, &(Private
->IcmpErrorRcvToken
));
229 Request IcmpErrorListenHandlerDpc as a DPC at TPL_CALLBACK
231 @param Event The event signaled.
232 @param Context The context passed in by the event notifier.
237 IcmpErrorListenHandler (
243 // Request IpIoListenHandlerDpc as a DPC at TPL_CALLBACK
245 QueueDpc (TPL_CALLBACK
, IcmpErrorListenHandlerDpc
, Context
);
249 Enables the use of the PXE Base Code Protocol functions.
251 This function enables the use of the PXE Base Code Protocol functions. If the
252 Started field of the EFI_PXE_BASE_CODE_MODE structure is already TRUE, then
253 EFI_ALREADY_STARTED will be returned. If UseIpv6 is TRUE, then IPv6 formatted
254 addresses will be used in this session. If UseIpv6 is FALSE, then IPv4 formatted
255 addresses will be used in this session. If UseIpv6 is TRUE, and the Ipv6Supported
256 field of the EFI_PXE_BASE_CODE_MODE structure is FALSE, then EFI_UNSUPPORTED will
257 be returned. If there is not enough memory or other resources to start the PXE
258 Base Code Protocol, then EFI_OUT_OF_RESOURCES will be returned. Otherwise, the
259 PXE Base Code Protocol will be started, and all of the fields of the EFI_PXE_BASE_CODE_MODE
260 structure will be initialized as follows:
262 Ipv6SupportedUnchanged.
263 Ipv6AvailableUnchanged.
264 UsingIpv6Set to UseIpv6.
265 BisSupportedUnchanged.
266 BisDetectedUnchanged.
268 SendGUIDSet to FALSE.
269 TTLSet to DEFAULT_TTL.
270 ToSSet to DEFAULT_ToS.
271 DhcpCompletedSet to FALSE.
272 ProxyOfferReceivedSet to FALSE.
273 StationIpSet to an address of all zeros.
274 SubnetMaskSet to a subnet mask of all zeros.
275 DhcpDiscoverZero-filled.
277 ProxyOfferZero-filled.
278 PxeDiscoverValidSet to FALSE.
279 PxeDiscoverZero-filled.
280 PxeReplyValidSet to FALSE.
282 PxeBisReplyValidSet to FALSE.
283 PxeBisReplyZero-filled.
284 IpFilterSet the Filters field to 0 and the IpCnt field to 0.
285 ArpCacheEntriesSet to 0.
287 RouteTableEntriesSet to 0.
288 RouteTableZero-filled.
289 IcmpErrorReceivedSet to FALSE.
290 IcmpErrorZero-filled.
291 TftpErroReceivedSet to FALSE.
292 TftpErrorZero-filled.
293 MakeCallbacksSet to TRUE if the PXE Base Code Callback Protocol is available.
294 Set to FALSE if the PXE Base Code Callback Protocol is not available.
296 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
297 @param UseIpv6 Specifies the type of IP addresses that are to be used during the session
298 that is being started. Set to TRUE for IPv6 addresses, and FALSE for
301 @retval EFI_SUCCESS The PXE Base Code Protocol was started.
302 @retval EFI_DEVICE_ERROR The network device encountered an error during this oper
303 @retval EFI_UNSUPPORTED UseIpv6 is TRUE, but the Ipv6Supported field of the
304 EFI_PXE_BASE_CODE_MODE structure is FALSE.
305 @retval EFI_ALREADY_STARTED The PXE Base Code Protocol is already in the started state.
306 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
307 EFI_PXE_BASE_CODE_PROTOCOL structure.
308 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory or other resources to start the
309 PXE Base Code Protocol.
315 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
319 PXEBC_PRIVATE_DATA
*Private
;
320 EFI_PXE_BASE_CODE_MODE
*Mode
;
324 return EFI_INVALID_PARAMETER
;
327 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
328 Mode
= Private
->PxeBc
.Mode
;
331 return EFI_ALREADY_STARTED
;
336 // IPv6 is not supported now.
338 return EFI_UNSUPPORTED
;
341 AsciiPrint ("\n>>Start PXE over IPv4");
344 // Configure the udp4 instance to let it receive data
346 Status
= Private
->Udp4Read
->Configure (
348 &Private
->Udp4CfgData
350 if (EFI_ERROR (Status
)) {
356 // Configure block size for TFTP as a default value to handle all link layers.
358 Private
->BlockSize
= MIN (Private
->Ip4MaxPacketSize
, PXEBC_DEFAULT_PACKET_SIZE
) -
359 PXEBC_DEFAULT_UDP_OVERHEAD_SIZE
- PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE
;
361 // If PcdTftpBlockSize is set to non-zero, override the default value.
363 if (PcdGet64 (PcdTftpBlockSize
) != 0) {
364 Private
->BlockSize
= (UINTN
) PcdGet64 (PcdTftpBlockSize
);
367 Private
->AddressIsOk
= FALSE
;
369 ZeroMem (Mode
, sizeof (EFI_PXE_BASE_CODE_MODE
));
371 Mode
->Started
= TRUE
;
372 Mode
->TTL
= DEFAULT_TTL
;
373 Mode
->ToS
= DEFAULT_ToS
;
374 Mode
->AutoArp
= TRUE
;
377 // Create the event for Arp Cache checking.
379 Status
= gBS
->CreateEvent (
380 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
382 ArpCacheUpdateTimeout
,
384 &Private
->GetArpCacheEvent
386 if (EFI_ERROR (Status
)) {
391 // Start the timeout timer event.
393 Status
= gBS
->SetTimer (
394 Private
->GetArpCacheEvent
,
399 if (EFI_ERROR (Status
)) {
404 // Create ICMP error receiving event
406 Status
= gBS
->CreateEvent (
409 IcmpErrorListenHandler
,
411 &(Private
->IcmpErrorRcvToken
.Event
)
413 if (EFI_ERROR (Status
)) {
418 //DHCP4 service allows only one of its children to be configured in
419 //the active state, If the DHCP4 D.O.R.A started by IP4 auto
420 //configuration and has not been completed, the Dhcp4 state machine
421 //will not be in the right state for the PXE to start a new round D.O.R.A.
422 //so we need to switch it's policy to static.
424 Status
= PxeBcSetIp4Policy (Private
);
425 if (EFI_ERROR (Status
)) {
429 Status
= Private
->Ip4
->Configure (Private
->Ip4
, &Private
->Ip4ConfigData
);
430 if (EFI_ERROR (Status
)) {
435 // start to listen incoming packet
437 Status
= Private
->Ip4
->Receive (Private
->Ip4
, &Private
->IcmpErrorRcvToken
);
438 if (!EFI_ERROR (Status
)) {
443 Private
->Ip4
->Configure (Private
->Ip4
, NULL
);
445 if (Private
->IcmpErrorRcvToken
.Event
!= NULL
) {
446 gBS
->CloseEvent (Private
->IcmpErrorRcvToken
.Event
);
449 if (Private
->GetArpCacheEvent
!= NULL
) {
450 gBS
->SetTimer (Private
->GetArpCacheEvent
, TimerCancel
, 0);
451 gBS
->CloseEvent (Private
->GetArpCacheEvent
);
454 Mode
->Started
= FALSE
;
457 Mode
->AutoArp
= FALSE
;
464 Disables the use of the PXE Base Code Protocol functions.
466 This function stops all activity on the network device. All the resources allocated
467 in Start() are released, the Started field of the EFI_PXE_BASE_CODE_MODE structure is
468 set to FALSE and EFI_SUCCESS is returned. If the Started field of the EFI_PXE_BASE_CODE_MODE
469 structure is already FALSE, then EFI_NOT_STARTED will be returned.
471 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
473 @retval EFI_SUCCESS The PXE Base Code Protocol was stopped.
474 @retval EFI_NOT_STARTED The PXE Base Code Protocol is already in the stopped state.
475 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
476 EFI_PXE_BASE_CODE_PROTOCOL structure.
477 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
483 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
486 PXEBC_PRIVATE_DATA
*Private
;
487 EFI_PXE_BASE_CODE_MODE
*Mode
;
490 return EFI_INVALID_PARAMETER
;
493 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
494 Mode
= Private
->PxeBc
.Mode
;
496 if (!Mode
->Started
) {
497 return EFI_NOT_STARTED
;
500 Private
->Ip4
->Cancel (Private
->Ip4
, NULL
);
502 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
507 Private
->Ip4
->Configure (Private
->Ip4
, NULL
);
510 // Close the ICMP error receiving event.
512 gBS
->CloseEvent (Private
->IcmpErrorRcvToken
.Event
);
515 // Cancel the TimeoutEvent timer.
517 gBS
->SetTimer (Private
->GetArpCacheEvent
, TimerCancel
, 0);
520 // Close the TimeoutEvent event.
522 gBS
->CloseEvent (Private
->GetArpCacheEvent
);
524 Mode
->Started
= FALSE
;
526 Private
->CurrentUdpSrcPort
= 0;
527 Private
->Udp4Write
->Configure (Private
->Udp4Write
, NULL
);
528 Private
->Udp4Read
->Groups (Private
->Udp4Read
, FALSE
, NULL
);
529 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
531 Private
->Dhcp4
->Stop (Private
->Dhcp4
);
532 Private
->Dhcp4
->Configure (Private
->Dhcp4
, NULL
);
534 Private
->FileSize
= 0;
541 Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request / acknowledge) or DHCPv6
542 S.A.R.R (solicit / advertise / request / reply) sequence.
544 This function attempts to complete the DHCP sequence. If this sequence is completed,
545 then EFI_SUCCESS is returned, and the DhcpCompleted, ProxyOfferReceived, StationIp,
546 SubnetMask, DhcpDiscover, DhcpAck, and ProxyOffer fields of the EFI_PXE_BASE_CODE_MODE
547 structure are filled in.
548 If SortOffers is TRUE, then the cached DHCP offer packets will be sorted before
549 they are tried. If SortOffers is FALSE, then the cached DHCP offer packets will
550 be tried in the order in which they are received. Please see the Preboot Execution
551 Environment (PXE) Specification for additional details on the implementation of DHCP.
552 This function can take at least 31 seconds to timeout and return control to the
553 caller. If the DHCP sequence does not complete, then EFI_TIMEOUT will be returned.
554 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
555 then the DHCP sequence will be stopped and EFI_ABORTED will be returned.
557 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
558 @param SortOffers TRUE if the offers received should be sorted. Set to FALSE to try the
559 offers in the order that they are received.
561 @retval EFI_SUCCESS Valid DHCP has completed.
562 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
563 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
564 EFI_PXE_BASE_CODE_PROTOCOL structure.
565 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
566 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete the DHCP Protocol.
567 @retval EFI_ABORTED The callback function aborted the DHCP Protocol.
568 @retval EFI_TIMEOUT The DHCP Protocol timed out.
569 @retval EFI_ICMP_ERROR An ICMP error packet was received during the DHCP session.
570 @retval EFI_NO_RESPONSE Valid PXE offer was not received.
576 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
577 IN BOOLEAN SortOffers
580 PXEBC_PRIVATE_DATA
*Private
;
581 EFI_PXE_BASE_CODE_MODE
*Mode
;
582 EFI_DHCP4_PROTOCOL
*Dhcp4
;
583 EFI_DHCP4_CONFIG_DATA Dhcp4CfgData
;
584 EFI_DHCP4_MODE_DATA Dhcp4Mode
;
585 EFI_DHCP4_PACKET_OPTION
*OptList
[PXEBC_DHCP4_MAX_OPTION_NUM
];
588 EFI_ARP_CONFIG_DATA ArpConfigData
;
589 EFI_PXE_BASE_CODE_IP_FILTER IpFilter
;
592 return EFI_INVALID_PARAMETER
;
595 Status
= EFI_SUCCESS
;
596 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
597 Mode
= Private
->PxeBc
.Mode
;
598 Dhcp4
= Private
->Dhcp4
;
599 Private
->Function
= EFI_PXE_BASE_CODE_FUNCTION_DHCP
;
600 Private
->SortOffers
= SortOffers
;
602 if (!Mode
->Started
) {
603 return EFI_NOT_STARTED
;
606 Mode
->IcmpErrorReceived
= FALSE
;
609 // Stop Udp4Read instance
611 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
614 // Initialize the DHCP options and build the option list
616 OptCount
= PxeBcBuildDhcpOptions (Private
, OptList
, TRUE
);
619 // Set the DHCP4 config data.
620 // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.
622 ZeroMem (&Dhcp4CfgData
, sizeof (EFI_DHCP4_CONFIG_DATA
));
623 Dhcp4CfgData
.OptionCount
= OptCount
;
624 Dhcp4CfgData
.OptionList
= OptList
;
625 Dhcp4CfgData
.Dhcp4Callback
= PxeBcDhcpCallBack
;
626 Dhcp4CfgData
.CallbackContext
= Private
;
627 Dhcp4CfgData
.DiscoverTryCount
= 4;
628 Dhcp4CfgData
.DiscoverTimeout
= mPxeDhcpTimeout
;
630 Status
= Dhcp4
->Configure (Dhcp4
, &Dhcp4CfgData
);
631 if (EFI_ERROR (Status
)) {
636 // Zero those arrays to record the varies numbers of DHCP OFFERS.
638 Private
->GotProxyOffer
= FALSE
;
639 Private
->NumOffers
= 0;
640 Private
->BootpIndex
= 0;
641 ZeroMem (Private
->ServerCount
, sizeof (Private
->ServerCount
));
642 ZeroMem (Private
->ProxyIndex
, sizeof (Private
->ProxyIndex
));
644 Status
= Dhcp4
->Start (Dhcp4
, NULL
);
645 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
646 if (Status
== EFI_ICMP_ERROR
) {
647 Mode
->IcmpErrorReceived
= TRUE
;
652 Status
= Dhcp4
->GetModeData (Dhcp4
, &Dhcp4Mode
);
653 if (EFI_ERROR (Status
)) {
657 ASSERT (Dhcp4Mode
.State
== Dhcp4Bound
);
659 CopyMem (&Private
->StationIp
, &Dhcp4Mode
.ClientAddress
, sizeof (EFI_IPv4_ADDRESS
));
660 CopyMem (&Private
->SubnetMask
, &Dhcp4Mode
.SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
661 CopyMem (&Private
->GatewayIp
, &Dhcp4Mode
.RouterAddress
, sizeof (EFI_IPv4_ADDRESS
));
663 CopyMem (&Mode
->StationIp
, &Private
->StationIp
, sizeof (EFI_IPv4_ADDRESS
));
664 CopyMem (&Mode
->SubnetMask
, &Private
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
667 // Check the selected offer to see whether BINL is required, if no or BINL is
668 // finished, set the various Mode members.
670 Status
= PxeBcCheckSelectedOffer (Private
);
672 AsciiPrint ("\n Station IP address is ");
674 PxeBcShowIp4Addr (&Private
->StationIp
.v4
);
678 if (EFI_ERROR (Status
)) {
680 Dhcp4
->Configure (Dhcp4
, NULL
);
683 // Remove the previously configured option list and callback function
685 ZeroMem (&Dhcp4CfgData
, sizeof (EFI_DHCP4_CONFIG_DATA
));
686 Dhcp4
->Configure (Dhcp4
, &Dhcp4CfgData
);
688 Private
->AddressIsOk
= TRUE
;
690 if (!Mode
->UsingIpv6
) {
692 // If in IPv4 mode, configure the corresponding ARP with this new
693 // station IP address.
695 ZeroMem (&ArpConfigData
, sizeof (EFI_ARP_CONFIG_DATA
));
697 ArpConfigData
.SwAddressType
= 0x0800;
698 ArpConfigData
.SwAddressLength
= (UINT8
) sizeof (EFI_IPv4_ADDRESS
);
699 ArpConfigData
.StationAddress
= &Private
->StationIp
.v4
;
701 Private
->Arp
->Configure (Private
->Arp
, NULL
);
702 Private
->Arp
->Configure (Private
->Arp
, &ArpConfigData
);
705 // Updated the route table. Fill the first entry.
707 Mode
->RouteTableEntries
= 1;
708 Mode
->RouteTable
[0].IpAddr
.Addr
[0] = Private
->StationIp
.Addr
[0] & Private
->SubnetMask
.Addr
[0];
709 Mode
->RouteTable
[0].SubnetMask
.Addr
[0] = Private
->SubnetMask
.Addr
[0];
710 Mode
->RouteTable
[0].GwAddr
.Addr
[0] = 0;
713 // Create the default route entry if there is a default router.
715 if (Private
->GatewayIp
.Addr
[0] != 0) {
716 Mode
->RouteTableEntries
= 2;
717 Mode
->RouteTable
[1].IpAddr
.Addr
[0] = 0;
718 Mode
->RouteTable
[1].SubnetMask
.Addr
[0] = 0;
719 Mode
->RouteTable
[1].GwAddr
.Addr
[0] = Private
->GatewayIp
.Addr
[0];
723 // Flush new station IP address into Udp4CfgData and Ip4ConfigData
725 CopyMem (&Private
->Udp4CfgData
.StationAddress
, &Private
->StationIp
, sizeof (EFI_IPv4_ADDRESS
));
726 CopyMem (&Private
->Udp4CfgData
.SubnetMask
, &Private
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
727 CopyMem (&Private
->Ip4ConfigData
.StationAddress
, &Private
->StationIp
, sizeof (EFI_IPv4_ADDRESS
));
728 CopyMem (&Private
->Ip4ConfigData
.SubnetMask
, &Private
->SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
731 // Reconfigure the Ip4 instance to capture background ICMP packets with new station Ip address.
733 Private
->Ip4
->Cancel (Private
->Ip4
, &Private
->IcmpErrorRcvToken
);
734 Private
->Ip4
->Configure (Private
->Ip4
, NULL
);
736 Status
= Private
->Ip4
->Configure (Private
->Ip4
, &Private
->Ip4ConfigData
);
737 if (EFI_ERROR (Status
)) {
741 Status
= Private
->Ip4
->Receive (Private
->Ip4
, &Private
->IcmpErrorRcvToken
);
742 if (EFI_ERROR (Status
)) {
748 Private
->Udp4Read
->Configure (Private
->Udp4Read
, &Private
->Udp4CfgData
);
751 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
752 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
754 ZeroMem(&IpFilter
, sizeof (EFI_PXE_BASE_CODE_IP_FILTER
));
755 IpFilter
.Filters
= EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
;
756 This
->SetIpFilter (This
, &IpFilter
);
763 Attempts to complete the PXE Boot Server and/or boot image discovery sequence.
765 This function attempts to complete the PXE Boot Server and/or boot image discovery
766 sequence. If this sequence is completed, then EFI_SUCCESS is returned, and the
767 PxeDiscoverValid, PxeDiscover, PxeReplyReceived, and PxeReply fields of the
768 EFI_PXE_BASE_CODE_MODE structure are filled in. If UseBis is TRUE, then the
769 PxeBisReplyReceived and PxeBisReply fields of the EFI_PXE_BASE_CODE_MODE structure
770 will also be filled in. If UseBis is FALSE, then PxeBisReplyValid will be set to FALSE.
771 In the structure referenced by parameter Info, the PXE Boot Server list, SrvList[],
772 has two uses: It is the Boot Server IP address list used for unicast discovery
773 (if the UseUCast field is TRUE), and it is the list used for Boot Server verification
774 (if the MustUseList field is TRUE). Also, if the MustUseList field in that structure
775 is TRUE and the AcceptAnyResponse field in the SrvList[] array is TRUE, any Boot
776 Server reply of that type will be accepted. If the AcceptAnyResponse field is
777 FALSE, only responses from Boot Servers with matching IP addresses will be accepted.
778 This function can take at least 10 seconds to timeout and return control to the
779 caller. If the Discovery sequence does not complete, then EFI_TIMEOUT will be
780 returned. Please see the Preboot Execution Environment (PXE) Specification for
781 additional details on the implementation of the Discovery sequence.
782 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
783 then the Discovery sequence is stopped and EFI_ABORTED will be returned.
785 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
786 @param Type The type of bootstrap to perform.
787 @param Layer Pointer to the boot server layer number to discover, which must be
788 PXE_BOOT_LAYER_INITIAL when a new server type is being
790 @param UseBis TRUE if Boot Integrity Services are to be used. FALSE otherwise.
791 @param Info Pointer to a data structure that contains additional information on the
792 type of discovery operation that is to be performed.
794 @retval EFI_SUCCESS The Discovery sequence has been completed.
795 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
796 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
797 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
798 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete Discovery.
799 @retval EFI_ABORTED The callback function aborted the Discovery sequence.
800 @retval EFI_TIMEOUT The Discovery sequence timed out.
801 @retval EFI_ICMP_ERROR An ICMP error packet was received during the PXE discovery
808 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
812 IN EFI_PXE_BASE_CODE_DISCOVER_INFO
*Info OPTIONAL
815 PXEBC_PRIVATE_DATA
*Private
;
816 EFI_PXE_BASE_CODE_MODE
*Mode
;
817 EFI_PXE_BASE_CODE_DISCOVER_INFO DefaultInfo
;
818 EFI_PXE_BASE_CODE_DISCOVER_INFO
*CreatedInfo
;
819 EFI_PXE_BASE_CODE_SRVLIST
*SrvList
;
820 EFI_PXE_BASE_CODE_SRVLIST DefaultSrvList
;
821 PXEBC_CACHED_DHCP4_PACKET
*Packet
;
822 PXEBC_VENDOR_OPTION
*VendorOpt
;
825 PXEBC_BOOT_SVR_ENTRY
*BootSvrEntry
;
826 EFI_PXE_BASE_CODE_IP_FILTER IpFilter
;
829 return EFI_INVALID_PARAMETER
;
832 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
833 Mode
= Private
->PxeBc
.Mode
;
837 Status
= EFI_DEVICE_ERROR
;
838 Private
->Function
= EFI_PXE_BASE_CODE_FUNCTION_DISCOVER
;
840 if (!Private
->AddressIsOk
) {
841 return EFI_INVALID_PARAMETER
;
844 if (!Mode
->Started
) {
845 return EFI_NOT_STARTED
;
849 // Stop Udp4Read instance
851 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
853 Mode
->IcmpErrorReceived
= FALSE
;
856 // If layer isn't EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL,
857 // use the previous setting;
858 // If info isn't offered,
859 // use the cached DhcpAck and ProxyOffer packets.
861 ZeroMem (&DefaultInfo
, sizeof (EFI_PXE_BASE_CODE_DISCOVER_INFO
));
862 if (*Layer
!= EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL
) {
864 if (!Mode
->PxeDiscoverValid
|| !Mode
->PxeReplyReceived
|| (!Mode
->PxeBisReplyReceived
&& UseBis
)) {
866 Status
= EFI_INVALID_PARAMETER
;
870 DefaultInfo
.IpCnt
= 1;
871 DefaultInfo
.UseUCast
= TRUE
;
873 DefaultSrvList
.Type
= Type
;
874 DefaultSrvList
.AcceptAnyResponse
= FALSE
;
875 DefaultSrvList
.IpAddr
.Addr
[0] = Private
->ServerIp
.Addr
[0];
877 SrvList
= &DefaultSrvList
;
879 } else if (Info
== NULL
) {
881 // Create info by the cached packet before
883 Packet
= (Mode
->ProxyOfferReceived
) ? &Private
->ProxyOffer
: &Private
->Dhcp4Ack
;
884 VendorOpt
= &Packet
->PxeVendorOption
;
886 if (!Mode
->DhcpAckReceived
|| !IS_VALID_DISCOVER_VENDOR_OPTION (VendorOpt
->BitMap
)) {
888 // Address is not acquired or no discovery options.
890 Status
= EFI_INVALID_PARAMETER
;
894 DefaultInfo
.UseMCast
= (BOOLEAN
)!IS_DISABLE_MCAST_DISCOVER (VendorOpt
->DiscoverCtrl
);
895 DefaultInfo
.UseBCast
= (BOOLEAN
)!IS_DISABLE_BCAST_DISCOVER (VendorOpt
->DiscoverCtrl
);
896 DefaultInfo
.MustUseList
= (BOOLEAN
) IS_ENABLE_USE_SERVER_LIST (VendorOpt
->DiscoverCtrl
);
897 DefaultInfo
.UseUCast
= DefaultInfo
.MustUseList
;
899 if (DefaultInfo
.UseMCast
) {
901 // Get the multicast discover ip address from vendor option.
904 &DefaultInfo
.ServerMCastIp
.Addr
,
905 &VendorOpt
->DiscoverMcastIp
,
906 sizeof (EFI_IPv4_ADDRESS
)
910 DefaultInfo
.IpCnt
= 0;
912 SrvList
= Info
->SrvList
;
914 if (DefaultInfo
.MustUseList
) {
915 BootSvrEntry
= VendorOpt
->BootSvr
;
916 Status
= EFI_INVALID_PARAMETER
;
918 while (((UINT8
) (BootSvrEntry
- VendorOpt
->BootSvr
)) < VendorOpt
->BootSvrLen
) {
920 if (BootSvrEntry
->Type
== HTONS (Type
)) {
921 Status
= EFI_SUCCESS
;
925 BootSvrEntry
= GET_NEXT_BOOT_SVR_ENTRY (BootSvrEntry
);
928 if (EFI_ERROR (Status
)) {
932 DefaultInfo
.IpCnt
= BootSvrEntry
->IpCnt
;
934 if (DefaultInfo
.IpCnt
>= 1) {
935 CreatedInfo
= AllocatePool (sizeof (DefaultInfo
) + (DefaultInfo
.IpCnt
- 1) * sizeof (*SrvList
));
936 if (CreatedInfo
== NULL
) {
937 Status
= EFI_OUT_OF_RESOURCES
;
942 CopyMem (CreatedInfo
, &DefaultInfo
, sizeof (DefaultInfo
));
944 SrvList
= Info
->SrvList
;
947 for (Index
= 0; Index
< DefaultInfo
.IpCnt
; Index
++) {
948 CopyMem (&SrvList
[Index
].IpAddr
, &BootSvrEntry
->IpAddr
[Index
], sizeof (EFI_IPv4_ADDRESS
));
949 SrvList
[Index
].AcceptAnyResponse
= FALSE
;
950 SrvList
[Index
].Type
= BootSvrEntry
->Type
;
956 SrvList
= Info
->SrvList
;
958 if (!SrvList
[0].AcceptAnyResponse
) {
960 for (Index
= 1; Index
< Info
->IpCnt
; Index
++) {
961 if (SrvList
[Index
].AcceptAnyResponse
) {
966 if (Index
!= Info
->IpCnt
) {
967 Status
= EFI_INVALID_PARAMETER
;
973 if ((!Info
->UseUCast
&& !Info
->UseBCast
&& !Info
->UseMCast
) || (Info
->MustUseList
&& Info
->IpCnt
== 0)) {
975 Status
= EFI_INVALID_PARAMETER
;
979 // Execute discover by UniCast/BroadCast/MultiCast
981 if (Info
->UseUCast
) {
983 for (Index
= 0; Index
< Info
->IpCnt
; Index
++) {
985 if (BootSvrEntry
== NULL
) {
986 Private
->ServerIp
.Addr
[0] = SrvList
[Index
].IpAddr
.Addr
[0];
990 &BootSvrEntry
->IpAddr
[Index
],
991 sizeof (EFI_IPv4_ADDRESS
)
995 Status
= PxeBcDiscvBootService (
1000 &SrvList
[Index
].IpAddr
,
1004 &Private
->PxeReply
.Packet
.Ack
1006 if (!EFI_ERROR (Status
)) {
1011 } else if (Info
->UseMCast
) {
1013 Status
= PxeBcDiscvBootService (
1018 &Info
->ServerMCastIp
,
1022 &Private
->PxeReply
.Packet
.Ack
1025 } else if (Info
->UseBCast
) {
1027 Status
= PxeBcDiscvBootService (
1036 &Private
->PxeReply
.Packet
.Ack
1040 if (EFI_ERROR (Status
) || !Mode
->PxeReplyReceived
|| (!Mode
->PxeBisReplyReceived
&& UseBis
)) {
1041 if (Status
== EFI_ICMP_ERROR
) {
1042 Mode
->IcmpErrorReceived
= TRUE
;
1044 Status
= EFI_DEVICE_ERROR
;
1048 PxeBcParseCachedDhcpPacket (&Private
->PxeReply
);
1051 if (Mode
->PxeBisReplyReceived
) {
1054 &Mode
->PxeReply
.Dhcpv4
.BootpSiAddr
,
1055 sizeof (EFI_IPv4_ADDRESS
)
1059 if (CreatedInfo
!= NULL
) {
1060 FreePool (CreatedInfo
);
1065 Private
->Udp4Read
->Configure (Private
->Udp4Read
, &Private
->Udp4CfgData
);
1068 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
1069 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1071 ZeroMem(&IpFilter
, sizeof (EFI_PXE_BASE_CODE_IP_FILTER
));
1072 IpFilter
.Filters
= EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
;
1073 This
->SetIpFilter (This
, &IpFilter
);
1080 Used to perform TFTP and MTFTP services.
1082 This function is used to perform TFTP and MTFTP services. This includes the
1083 TFTP operations to get the size of a file, read a directory, read a file, and
1084 write a file. It also includes the MTFTP operations to get the size of a file,
1085 read a directory, and read a file. The type of operation is specified by Operation.
1086 If the callback function that is invoked during the TFTP/MTFTP operation does
1087 not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will
1089 For read operations, the return data will be placed in the buffer specified by
1090 BufferPtr. If BufferSize is too small to contain the entire downloaded file,
1091 then EFI_BUFFER_TOO_SMALL will be returned and BufferSize will be set to zero
1092 or the size of the requested file (the size of the requested file is only returned
1093 if the TFTP server supports TFTP options). If BufferSize is large enough for the
1094 read operation, then BufferSize will be set to the size of the downloaded file,
1095 and EFI_SUCCESS will be returned. Applications using the PxeBc.Mtftp() services
1096 should use the get-file-size operations to determine the size of the downloaded
1097 file prior to using the read-file operations-especially when downloading large
1098 (greater than 64 MB) files-instead of making two calls to the read-file operation.
1099 Following this recommendation will save time if the file is larger than expected
1100 and the TFTP server does not support TFTP option extensions. Without TFTP option
1101 extension support, the client has to download the entire file, counting and discarding
1102 the received packets, to determine the file size.
1103 For write operations, the data to be sent is in the buffer specified by BufferPtr.
1104 BufferSize specifies the number of bytes to send. If the write operation completes
1105 successfully, then EFI_SUCCESS will be returned.
1106 For TFTP "get file size" operations, the size of the requested file or directory
1107 is returned in BufferSize, and EFI_SUCCESS will be returned. If the TFTP server
1108 does not support options, the file will be downloaded into a bit bucket and the
1109 length of the downloaded file will be returned. For MTFTP "get file size" operations,
1110 if the MTFTP server does not support the "get file size" option, EFI_UNSUPPORTED
1112 This function can take up to 10 seconds to timeout and return control to the caller.
1113 If the TFTP sequence does not complete, EFI_TIMEOUT will be returned.
1114 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
1115 then the TFTP sequence is stopped and EFI_ABORTED will be returned.
1116 The format of the data returned from a TFTP read directory operation is a null-terminated
1117 filename followed by a null-terminated information string, of the form
1118 "size year-month-day hour:minute:second" (i.e. %d %d-%d-%d %d:%d:%f - note that
1119 the seconds field can be a decimal number), where the date and time are UTC. For
1120 an MTFTP read directory command, there is additionally a null-terminated multicast
1121 IP address preceding the filename of the form %d.%d.%d.%d for IP v4. The final
1122 entry is itself null-terminated, so that the final information string is terminated
1123 with two null octets.
1125 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1126 @param Operation The type of operation to perform.
1127 @param BufferPtr A pointer to the data buffer.
1128 @param Overwrite Only used on write file operations. TRUE if a file on a remote server can
1130 @param BufferSize For get-file-size operations, *BufferSize returns the size of the
1132 @param BlockSize The requested block size to be used during a TFTP transfer.
1133 @param ServerIp The TFTP / MTFTP server IP address.
1134 @param Filename A Null-terminated ASCII string that specifies a directory name or a file
1136 @param Info Pointer to the MTFTP information.
1137 @param DontUseBuffer Set to FALSE for normal TFTP and MTFTP read file operation.
1139 @retval EFI_SUCCESS The TFTP/MTFTP operation was completed.
1140 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1141 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1142 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1143 @retval EFI_BUFFER_TOO_SMALL The buffer is not large enough to complete the read operation.
1144 @retval EFI_ABORTED The callback function aborted the TFTP/MTFTP operation.
1145 @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.
1146 @retval EFI_ICMP_ERROR An ICMP error packet was received during the MTFTP session.
1147 @retval EFI_TFTP_ERROR A TFTP error packet was received during the MTFTP session.
1153 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1154 IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation
,
1155 IN OUT VOID
*BufferPtr
,
1156 IN BOOLEAN Overwrite
,
1157 IN OUT UINT64
*BufferSize
,
1158 IN UINTN
*BlockSize OPTIONAL
,
1159 IN EFI_IP_ADDRESS
*ServerIp
,
1161 IN EFI_PXE_BASE_CODE_MTFTP_INFO
*Info OPTIONAL
,
1162 IN BOOLEAN DontUseBuffer
1165 PXEBC_PRIVATE_DATA
*Private
;
1166 EFI_MTFTP4_CONFIG_DATA Mtftp4Config
;
1168 EFI_PXE_BASE_CODE_MODE
*Mode
;
1169 EFI_MAC_ADDRESS TempMacAddr
;
1170 EFI_PXE_BASE_CODE_IP_FILTER IpFilter
;
1172 if ((This
== NULL
) ||
1173 (Filename
== NULL
) ||
1174 (BufferSize
== NULL
) ||
1175 ((ServerIp
== NULL
) ||
1176 (IP4_IS_UNSPECIFIED (NTOHL (ServerIp
->Addr
[0])) ||
1177 IP4_IS_LOCAL_BROADCAST (NTOHL (ServerIp
->Addr
[0])))) ||
1178 ((BufferPtr
== NULL
) && DontUseBuffer
) ||
1179 ((BlockSize
!= NULL
) && (*BlockSize
< 512))) {
1181 return EFI_INVALID_PARAMETER
;
1184 Status
= EFI_DEVICE_ERROR
;
1185 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1186 Mode
= &Private
->Mode
;
1188 if (!Mode
->AutoArp
) {
1190 // If AutoArp is set false, check arp cache
1192 UpdateArpCache (This
);
1193 if (!FindInArpCache (Mode
, &ServerIp
->v4
, &TempMacAddr
)) {
1194 return EFI_DEVICE_ERROR
;
1199 // Stop Udp4Read instance
1201 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
1203 Mode
->TftpErrorReceived
= FALSE
;
1204 Mode
->IcmpErrorReceived
= FALSE
;
1206 Mtftp4Config
.UseDefaultSetting
= FALSE
;
1207 Mtftp4Config
.TimeoutValue
= PXEBC_MTFTP_TIMEOUT
;
1208 Mtftp4Config
.TryCount
= PXEBC_MTFTP_RETRIES
;
1211 &Mtftp4Config
.StationIp
,
1212 &Private
->StationIp
,
1213 sizeof (EFI_IPv4_ADDRESS
)
1216 &Mtftp4Config
.SubnetMask
,
1217 &Private
->SubnetMask
,
1218 sizeof (EFI_IPv4_ADDRESS
)
1221 &Mtftp4Config
.GatewayIp
,
1222 &Private
->GatewayIp
,
1223 sizeof (EFI_IPv4_ADDRESS
)
1226 &Mtftp4Config
.ServerIp
,
1228 sizeof (EFI_IPv4_ADDRESS
)
1231 switch (Operation
) {
1233 case EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE
:
1235 Status
= PxeBcTftpGetFileSize (
1245 case EFI_PXE_BASE_CODE_TFTP_READ_FILE
:
1247 Status
= PxeBcTftpReadFile (
1259 case EFI_PXE_BASE_CODE_TFTP_WRITE_FILE
:
1261 Status
= PxeBcTftpWriteFile (
1273 case EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY
:
1275 Status
= PxeBcTftpReadDirectory (
1287 case EFI_PXE_BASE_CODE_MTFTP_GET_FILE_SIZE
:
1288 case EFI_PXE_BASE_CODE_MTFTP_READ_FILE
:
1289 case EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY
:
1290 Status
= EFI_UNSUPPORTED
;
1295 Status
= EFI_INVALID_PARAMETER
;
1299 if (Status
== EFI_ICMP_ERROR
) {
1300 Mode
->IcmpErrorReceived
= TRUE
;
1303 if (EFI_ERROR (Status
)) {
1308 Private
->Udp4Read
->Configure (Private
->Udp4Read
, &Private
->Udp4CfgData
);
1310 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
1311 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1313 ZeroMem(&IpFilter
, sizeof (EFI_PXE_BASE_CODE_IP_FILTER
));
1314 IpFilter
.Filters
= EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
;
1315 This
->SetIpFilter (This
, &IpFilter
);
1322 Writes a UDP packet to the network interface.
1324 This function writes a UDP packet specified by the (optional HeaderPtr and)
1325 BufferPtr parameters to the network interface. The UDP header is automatically
1326 built by this routine. It uses the parameters OpFlags, DestIp, DestPort, GatewayIp,
1327 SrcIp, and SrcPort to build this header. If the packet is successfully built and
1328 transmitted through the network interface, then EFI_SUCCESS will be returned.
1329 If a timeout occurs during the transmission of the packet, then EFI_TIMEOUT will
1330 be returned. If an ICMP error occurs during the transmission of the packet, then
1331 the IcmpErrorReceived field is set to TRUE, the IcmpError field is filled in and
1332 EFI_ICMP_ERROR will be returned. If the Callback Protocol does not return
1333 EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will be returned.
1335 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1336 @param OpFlags The UDP operation flags.
1337 @param DestIp The destination IP address.
1338 @param DestPort The destination UDP port number.
1339 @param GatewayIp The gateway IP address.
1340 @param SrcIp The source IP address.
1341 @param SrcPort The source UDP port number.
1342 @param HeaderSize An optional field which may be set to the length of a header at
1343 HeaderPtr to be prefixed to the data at BufferPtr.
1344 @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the
1346 @param BufferSize A pointer to the size of the data at BufferPtr.
1347 @param BufferPtr A pointer to the data to be written.
1349 @retval EFI_SUCCESS The UDP Write operation was completed.
1350 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1351 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1352 @retval EFI_BAD_BUFFER_SIZE The buffer is too long to be transmitted.
1353 @retval EFI_ABORTED The callback function aborted the UDP Write operation.
1354 @retval EFI_TIMEOUT The UDP Write operation timed out.
1355 @retval EFI_ICMP_ERROR An ICMP error packet was received during the UDP write session.
1361 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1363 IN EFI_IP_ADDRESS
*DestIp
,
1364 IN EFI_PXE_BASE_CODE_UDP_PORT
*DestPort
,
1365 IN EFI_IP_ADDRESS
*GatewayIp OPTIONAL
,
1366 IN EFI_IP_ADDRESS
*SrcIp OPTIONAL
,
1367 IN OUT EFI_PXE_BASE_CODE_UDP_PORT
*SrcPort OPTIONAL
,
1368 IN UINTN
*HeaderSize OPTIONAL
,
1369 IN VOID
*HeaderPtr OPTIONAL
,
1370 IN UINTN
*BufferSize
,
1374 PXEBC_PRIVATE_DATA
*Private
;
1375 EFI_UDP4_PROTOCOL
*Udp4
;
1376 EFI_UDP4_COMPLETION_TOKEN Token
;
1377 EFI_UDP4_TRANSMIT_DATA
*Udp4TxData
;
1380 EFI_UDP4_SESSION_DATA Udp4Session
;
1383 EFI_PXE_BASE_CODE_MODE
*Mode
;
1384 EFI_MAC_ADDRESS TempMacAddr
;
1388 if ((This
== NULL
) || (DestIp
== NULL
) || (DestPort
== NULL
)) {
1389 return EFI_INVALID_PARAMETER
;
1392 if ((GatewayIp
!= NULL
) && (IP4_IS_UNSPECIFIED (NTOHL (GatewayIp
->Addr
[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (GatewayIp
->Addr
[0])))) {
1394 // Gateway is provided but it's not a unicast IP address.
1396 return EFI_INVALID_PARAMETER
;
1399 if ((HeaderSize
!= NULL
) && ((*HeaderSize
== 0) || (HeaderPtr
== NULL
))) {
1401 // The HeaderSize ptr isn't NULL and: 1. the value is zero; or 2. the HeaderPtr
1404 return EFI_INVALID_PARAMETER
;
1407 if ((BufferSize
== NULL
) || ((*BufferSize
!= 0) && (BufferPtr
== NULL
))) {
1408 return EFI_INVALID_PARAMETER
;
1411 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1412 Udp4
= Private
->Udp4Write
;
1413 Mode
= &Private
->Mode
;
1414 if (!Mode
->Started
) {
1415 return EFI_NOT_STARTED
;
1418 if (!Private
->AddressIsOk
&& (SrcIp
== NULL
)) {
1419 return EFI_INVALID_PARAMETER
;
1422 if (!Mode
->AutoArp
) {
1424 // If AutoArp is set false, check arp cache
1426 UpdateArpCache (This
);
1427 if (!FindInArpCache (Mode
, &DestIp
->v4
, &TempMacAddr
)) {
1428 return EFI_DEVICE_ERROR
;
1432 Mode
->IcmpErrorReceived
= FALSE
;
1434 if ((Private
->CurrentUdpSrcPort
== 0) ||
1435 ((SrcPort
!= NULL
) && (*SrcPort
!= Private
->CurrentUdpSrcPort
))) {
1437 // Port is changed, (re)configure the Udp4Write instance
1439 if (SrcPort
!= NULL
) {
1440 Private
->CurrentUdpSrcPort
= *SrcPort
;
1444 Status
= PxeBcConfigureUdpWriteInstance (
1446 &Private
->StationIp
.v4
,
1447 &Private
->SubnetMask
.v4
,
1448 &Private
->GatewayIp
.v4
,
1449 &Private
->CurrentUdpSrcPort
,
1453 if (EFI_ERROR (Status
)) {
1454 Private
->CurrentUdpSrcPort
= 0;
1455 return EFI_INVALID_PARAMETER
;
1458 ZeroMem (&Token
, sizeof (EFI_UDP4_COMPLETION_TOKEN
));
1459 ZeroMem (&Udp4Session
, sizeof (EFI_UDP4_SESSION_DATA
));
1461 CopyMem (&Udp4Session
.DestinationAddress
, DestIp
, sizeof (EFI_IPv4_ADDRESS
));
1462 Udp4Session
.DestinationPort
= *DestPort
;
1463 if (SrcIp
!= NULL
) {
1464 CopyMem (&Udp4Session
.SourceAddress
, SrcIp
, sizeof (EFI_IPv4_ADDRESS
));
1466 if (SrcPort
!= NULL
) {
1467 Udp4Session
.SourcePort
= *SrcPort
;
1470 FragCount
= (HeaderSize
!= NULL
) ? 2 : 1;
1471 Udp4TxData
= (EFI_UDP4_TRANSMIT_DATA
*) AllocateZeroPool (sizeof (EFI_UDP4_TRANSMIT_DATA
) + (FragCount
- 1) * sizeof (EFI_UDP4_FRAGMENT_DATA
));
1472 if (Udp4TxData
== NULL
) {
1473 return EFI_OUT_OF_RESOURCES
;
1476 Udp4TxData
->FragmentCount
= FragCount
;
1477 Udp4TxData
->FragmentTable
[FragCount
- 1].FragmentLength
= (UINT32
) *BufferSize
;
1478 Udp4TxData
->FragmentTable
[FragCount
- 1].FragmentBuffer
= BufferPtr
;
1479 DataLength
= (UINT32
) *BufferSize
;
1481 if (FragCount
== 2) {
1483 Udp4TxData
->FragmentTable
[0].FragmentLength
= (UINT32
) *HeaderSize
;
1484 Udp4TxData
->FragmentTable
[0].FragmentBuffer
= HeaderPtr
;
1485 DataLength
+= (UINT32
) *HeaderSize
;
1488 if (GatewayIp
!= NULL
) {
1489 Udp4TxData
->GatewayAddress
= (EFI_IPv4_ADDRESS
*) GatewayIp
;
1491 Udp4TxData
->UdpSessionData
= &Udp4Session
;
1492 Udp4TxData
->DataLength
= DataLength
;
1493 Token
.Packet
.TxData
= Udp4TxData
;
1495 Status
= gBS
->CreateEvent (
1502 if (EFI_ERROR (Status
)) {
1506 Status
= Udp4
->Transmit (Udp4
, &Token
);
1507 if (EFI_ERROR (Status
)) {
1508 if (Status
== EFI_ICMP_ERROR
) {
1509 Mode
->IcmpErrorReceived
= TRUE
;
1519 Status
= Token
.Status
;
1523 if (Token
.Event
!= NULL
) {
1524 gBS
->CloseEvent (Token
.Event
);
1527 FreePool (Udp4TxData
);
1530 // Reset the instance.
1532 Udp4
->Configure (Udp4
, NULL
);
1537 Decide whether the incoming UDP packet is acceptable per IP filter settings
1538 in provided PxeBcMode.
1540 @param PxeBcMode Pointer to EFI_PXE_BASE_CODE_MODE.
1541 @param Session Received UDP session.
1543 @retval TRUE The UDP package matches IP filters.
1544 @retval FALSE The UDP package doesn't matches IP filters.
1549 IN EFI_PXE_BASE_CODE_MODE
*PxeBcMode
,
1550 IN EFI_UDP4_SESSION_DATA
*Session
1554 EFI_IPv4_ADDRESS Ip4Address
;
1555 EFI_IPv4_ADDRESS DestIp4Address
;
1557 if ((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) != 0) {
1561 CopyMem (&DestIp4Address
, &Session
->DestinationAddress
, sizeof (DestIp4Address
));
1562 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
) != 0) &&
1563 IP4_IS_MULTICAST (EFI_NTOHL (DestIp4Address
))
1568 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST
) != 0) &&
1569 IP4_IS_LOCAL_BROADCAST (EFI_NTOHL (DestIp4Address
))
1574 CopyMem (&Ip4Address
, &PxeBcMode
->StationIp
.v4
, sizeof (Ip4Address
));
1575 if (((PxeBcMode
->IpFilter
.Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0) &&
1576 EFI_IP4_EQUAL (&Ip4Address
, &DestIp4Address
)
1581 ASSERT (PxeBcMode
->IpFilter
.IpCnt
< EFI_PXE_BASE_CODE_MAX_IPCNT
);
1583 for (Index
= 0; Index
< PxeBcMode
->IpFilter
.IpCnt
; Index
++) {
1586 &PxeBcMode
->IpFilter
.IpList
[Index
].v4
,
1589 if (EFI_IP4_EQUAL (&Ip4Address
, &DestIp4Address
)) {
1598 Reads a UDP packet from the network interface.
1600 This function reads a UDP packet from a network interface. The data contents
1601 are returned in (the optional HeaderPtr and) BufferPtr, and the size of the
1602 buffer received is returned in BufferSize . If the input BufferSize is smaller
1603 than the UDP packet received (less optional HeaderSize), it will be set to the
1604 required size, and EFI_BUFFER_TOO_SMALL will be returned. In this case, the
1605 contents of BufferPtr are undefined, and the packet is lost. If a UDP packet is
1606 successfully received, then EFI_SUCCESS will be returned, and the information
1607 from the UDP header will be returned in DestIp, DestPort, SrcIp, and SrcPort if
1608 they are not NULL. Depending on the values of OpFlags and the DestIp, DestPort,
1609 SrcIp, and SrcPort input values, different types of UDP packet receive filtering
1610 will be performed. The following tables summarize these receive filter operations.
1612 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1613 @param OpFlags The UDP operation flags.
1614 @param DestIp The destination IP address.
1615 @param DestPort The destination UDP port number.
1616 @param SrcIp The source IP address.
1617 @param SrcPort The source UDP port number.
1618 @param HeaderSize An optional field which may be set to the length of a header at
1619 HeaderPtr to be prefixed to the data at BufferPtr.
1620 @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the
1622 @param BufferSize A pointer to the size of the data at BufferPtr.
1623 @param BufferPtr A pointer to the data to be read.
1625 @retval EFI_SUCCESS The UDP Read operation was completed.
1626 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1627 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1628 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1629 @retval EFI_BUFFER_TOO_SMALL The packet is larger than Buffer can hold.
1630 @retval EFI_ABORTED The callback function aborted the UDP Read operation.
1631 @retval EFI_TIMEOUT The UDP Read operation timed out.
1637 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1639 IN OUT EFI_IP_ADDRESS
*DestIp OPTIONAL
,
1640 IN OUT EFI_PXE_BASE_CODE_UDP_PORT
*DestPort OPTIONAL
,
1641 IN OUT EFI_IP_ADDRESS
*SrcIp OPTIONAL
,
1642 IN OUT EFI_PXE_BASE_CODE_UDP_PORT
*SrcPort OPTIONAL
,
1643 IN UINTN
*HeaderSize OPTIONAL
,
1644 IN VOID
*HeaderPtr OPTIONAL
,
1645 IN OUT UINTN
*BufferSize
,
1649 PXEBC_PRIVATE_DATA
*Private
;
1650 EFI_PXE_BASE_CODE_MODE
*Mode
;
1651 EFI_UDP4_PROTOCOL
*Udp4
;
1652 EFI_UDP4_COMPLETION_TOKEN Token
;
1653 EFI_UDP4_RECEIVE_DATA
*RxData
;
1654 EFI_UDP4_SESSION_DATA
*Session
;
1660 UINTN HeaderCopiedLen
;
1661 UINTN BufferCopiedLen
;
1662 UINT32 FragmentLength
;
1663 UINTN FragmentIndex
;
1664 UINT8
*FragmentBuffer
;
1666 if (This
== NULL
|| DestIp
== NULL
|| DestPort
== NULL
) {
1667 return EFI_INVALID_PARAMETER
;
1670 if (((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) == 0 && (DestPort
== NULL
)) ||
1671 ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) == 0 && (SrcIp
== NULL
)) ||
1672 ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT
) == 0 && (SrcPort
== NULL
))) {
1673 return EFI_INVALID_PARAMETER
;
1676 if (((HeaderSize
!= NULL
) && (*HeaderSize
== 0)) || ((HeaderSize
!= NULL
) && (HeaderPtr
== NULL
))) {
1677 return EFI_INVALID_PARAMETER
;
1680 if ((BufferSize
== NULL
) || (BufferPtr
== NULL
)) {
1681 return EFI_INVALID_PARAMETER
;
1684 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1685 Mode
= Private
->PxeBc
.Mode
;
1686 Udp4
= Private
->Udp4Read
;
1688 if (!Mode
->Started
) {
1689 return EFI_NOT_STARTED
;
1692 Mode
->IcmpErrorReceived
= FALSE
;
1694 Status
= gBS
->CreateEvent (
1701 if (EFI_ERROR (Status
)) {
1702 return EFI_OUT_OF_RESOURCES
;
1708 Status
= Udp4
->Receive (Udp4
, &Token
);
1709 if (EFI_ERROR (Status
)) {
1710 if (Status
== EFI_ICMP_ERROR
) {
1711 Mode
->IcmpErrorReceived
= TRUE
;
1719 Status
= EFI_TIMEOUT
;
1723 // check whether this packet matches the filters
1725 if (EFI_ERROR (Token
.Status
)){
1729 RxData
= Token
.Packet
.RxData
;
1730 Session
= &RxData
->UdpSession
;
1734 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER
) != 0) {
1737 // Check UDP package by IP filter settings
1739 if (CheckIpByFilter (Mode
, Session
)) {
1748 // Match the destination ip of the received udp dgram
1750 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP
) != 0) {
1753 if (DestIp
!= NULL
) {
1754 CopyMem (DestIp
, &Session
->DestinationAddress
, sizeof (EFI_IPv4_ADDRESS
));
1757 if (DestIp
!= NULL
) {
1758 if (EFI_IP4_EQUAL (DestIp
, &Session
->DestinationAddress
)) {
1762 if (EFI_IP4_EQUAL (&Private
->StationIp
, &Session
->DestinationAddress
)) {
1771 // Match the destination port of the received udp dgram
1773 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT
) != 0) {
1775 if (DestPort
!= NULL
) {
1776 *DestPort
= Session
->DestinationPort
;
1780 if (*DestPort
!= Session
->DestinationPort
) {
1788 // Match the source ip of the received udp dgram
1790 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP
) != 0) {
1792 if (SrcIp
!= NULL
) {
1793 CopyMem (SrcIp
, &Session
->SourceAddress
, sizeof (EFI_IPv4_ADDRESS
));
1797 if (!EFI_IP4_EQUAL (SrcIp
, &Session
->SourceAddress
)) {
1805 // Match the source port of the received udp dgram
1807 if ((OpFlags
& EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT
) != 0) {
1809 if (SrcPort
!= NULL
) {
1810 *SrcPort
= Session
->SourcePort
;
1814 if (*SrcPort
!= Session
->SourcePort
) {
1821 ASSERT (RxData
!= NULL
);
1824 if (HeaderSize
!= NULL
) {
1825 HeaderLen
= MIN (*HeaderSize
, RxData
->DataLength
);
1828 if (RxData
->DataLength
- HeaderLen
> *BufferSize
) {
1829 Status
= EFI_BUFFER_TOO_SMALL
;
1831 *HeaderSize
= HeaderLen
;
1832 *BufferSize
= RxData
->DataLength
- HeaderLen
;
1834 HeaderCopiedLen
= 0;
1835 BufferCopiedLen
= 0;
1836 for (FragmentIndex
= 0; FragmentIndex
< RxData
->FragmentCount
; FragmentIndex
++) {
1837 FragmentLength
= RxData
->FragmentTable
[FragmentIndex
].FragmentLength
;
1838 FragmentBuffer
= RxData
->FragmentTable
[FragmentIndex
].FragmentBuffer
;
1839 if (HeaderCopiedLen
+ FragmentLength
< HeaderLen
) {
1841 // Copy the header part of received data.
1843 CopyMem ((UINT8
*) HeaderPtr
+ HeaderCopiedLen
, FragmentBuffer
, FragmentLength
);
1844 HeaderCopiedLen
+= FragmentLength
;
1845 } else if (HeaderCopiedLen
< HeaderLen
) {
1847 // Copy the header part of received data.
1849 CopiedLen
= HeaderLen
- HeaderCopiedLen
;
1850 CopyMem ((UINT8
*) HeaderPtr
+ HeaderCopiedLen
, FragmentBuffer
, CopiedLen
);
1851 HeaderCopiedLen
+= CopiedLen
;
1854 // Copy the other part of received data.
1856 CopyMem ((UINT8
*) BufferPtr
+ BufferCopiedLen
, FragmentBuffer
+ CopiedLen
, FragmentLength
- CopiedLen
);
1857 BufferCopiedLen
+= (FragmentLength
- CopiedLen
);
1860 // Copy the other part of received data.
1862 CopyMem ((UINT8
*) BufferPtr
+ BufferCopiedLen
, FragmentBuffer
, FragmentLength
);
1863 BufferCopiedLen
+= FragmentLength
;
1869 Status
= EFI_TIMEOUT
;
1873 // Recycle the RxData
1875 gBS
->SignalEvent (RxData
->RecycleSignal
);
1884 Udp4
->Cancel (Udp4
, &Token
);
1886 gBS
->CloseEvent (Token
.Event
);
1892 Updates the IP receive filters of a network device and enables software filtering.
1894 The NewFilter field is used to modify the network device's current IP receive
1895 filter settings and to enable a software filter. This function updates the IpFilter
1896 field of the EFI_PXE_BASE_CODE_MODE structure with the contents of NewIpFilter.
1897 The software filter is used when the USE_FILTER in OpFlags is set to UdpRead().
1898 The current hardware filter remains in effect no matter what the settings of OpFlags
1899 are, so that the meaning of ANY_DEST_IP set in OpFlags to UdpRead() is from those
1900 packets whose reception is enabled in hardware-physical NIC address (unicast),
1901 broadcast address, logical address or addresses (multicast), or all (promiscuous).
1902 UdpRead() does not modify the IP filter settings.
1903 Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP receive
1904 filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1905 If an application or driver wishes to preserve the IP receive filter settings,
1906 it will have to preserve the IP receive filter settings before these calls, and
1907 use SetIpFilter() to restore them after the calls. If incompatible filtering is
1908 requested (for example, PROMISCUOUS with anything else) or if the device does not
1909 support a requested filter setting and it cannot be accommodated in software
1910 (for example, PROMISCUOUS not supported), EFI_INVALID_PARAMETER will be returned.
1911 The IPlist field is used to enable IPs other than the StationIP. They may be
1912 multicast or unicast. If IPcnt is set as well as EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP,
1913 then both the StationIP and the IPs from the IPlist will be used.
1915 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1916 @param NewFilter Pointer to the new set of IP receive filters.
1918 @retval EFI_SUCCESS The IP receive filter settings were updated.
1919 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1920 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1925 EfiPxeBcSetIpFilter (
1926 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1927 IN EFI_PXE_BASE_CODE_IP_FILTER
*NewFilter
1931 PXEBC_PRIVATE_DATA
*Private
;
1932 EFI_PXE_BASE_CODE_MODE
*Mode
;
1934 EFI_UDP4_CONFIG_DATA
*Udp4Cfg
;
1935 BOOLEAN PromiscuousNeed
;
1936 BOOLEAN AcceptPromiscuous
;
1937 BOOLEAN AcceptBroadcast
;
1938 BOOLEAN MultiCastUpdate
;
1941 DEBUG ((EFI_D_ERROR
, "This == NULL.\n"));
1942 return EFI_INVALID_PARAMETER
;
1945 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
1946 Mode
= Private
->PxeBc
.Mode
;
1948 if (NewFilter
== NULL
) {
1949 DEBUG ((EFI_D_ERROR
, "NewFilter == NULL.\n"));
1950 return EFI_INVALID_PARAMETER
;
1953 if (NewFilter
->IpCnt
> EFI_PXE_BASE_CODE_MAX_IPCNT
) {
1954 DEBUG ((EFI_D_ERROR
, "NewFilter->IpCnt > %d.\n", EFI_PXE_BASE_CODE_MAX_IPCNT
));
1955 return EFI_INVALID_PARAMETER
;
1958 if (!Mode
->Started
) {
1959 DEBUG ((EFI_D_ERROR
, "BC was not started.\n"));
1960 return EFI_NOT_STARTED
;
1963 if (Mode
->UsingIpv6
) {
1964 DEBUG ((EFI_D_ERROR
, "This driver is PXE for IPv4 Only.\n"));
1965 return EFI_INVALID_PARAMETER
;
1968 PromiscuousNeed
= FALSE
;
1970 for (Index
= 0; Index
< NewFilter
->IpCnt
; ++Index
) {
1971 if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (NewFilter
->IpList
[Index
].v4
))) {
1973 // The IP is a broadcast address.
1975 DEBUG ((EFI_D_ERROR
, "There is broadcast address in NewFilter.\n"));
1976 return EFI_INVALID_PARAMETER
;
1978 if ((EFI_NTOHL(Mode
->StationIp
) != 0) &&
1979 (EFI_NTOHL(Mode
->SubnetMask
) != 0) &&
1980 IP4_NET_EQUAL(EFI_NTOHL(Mode
->StationIp
), EFI_NTOHL(NewFilter
->IpList
[Index
].v4
), EFI_NTOHL(Mode
->SubnetMask
)) &&
1981 NetIp4IsUnicast (EFI_IP4 (NewFilter
->IpList
[Index
].v4
), EFI_NTOHL(Mode
->SubnetMask
)) &&
1982 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0)) {
1984 // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList,
1985 // promiscuous mode is needed.
1987 PromiscuousNeed
= TRUE
;
1991 AcceptPromiscuous
= FALSE
;
1992 AcceptBroadcast
= FALSE
;
1993 MultiCastUpdate
= FALSE
;
1995 if (PromiscuousNeed
||
1996 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) != 0) ||
1997 ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
) != 0)
2000 // Configure the udp4 filter to receive all packages.
2002 AcceptPromiscuous
= TRUE
;
2003 } else if ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST
) != 0) {
2005 // Configure the udp4 filter to receive all broadcast packages.
2007 AcceptBroadcast
= TRUE
;
2011 // In multicast condition when Promiscuous FALSE and IpCnt no-zero.
2012 // Here check if there is any update of the multicast ip address. If yes,
2013 // we need leave the old multicast group (by Config UDP instance to NULL),
2014 // and join the new multicast group.
2016 if (!AcceptPromiscuous
) {
2017 if ((NewFilter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) != 0) {
2018 if (Mode
->IpFilter
.IpCnt
!= NewFilter
->IpCnt
) {
2019 MultiCastUpdate
= TRUE
;
2020 } else if (CompareMem (Mode
->IpFilter
.IpList
, NewFilter
->IpList
, NewFilter
->IpCnt
* sizeof (EFI_IP_ADDRESS
)) != 0 ) {
2021 MultiCastUpdate
= TRUE
;
2027 // Check whether we need reconfigure the UDP instance.
2029 Udp4Cfg
= &Private
->Udp4CfgData
;
2030 if ((AcceptPromiscuous
!= Udp4Cfg
->AcceptPromiscuous
) ||
2031 (AcceptBroadcast
!= Udp4Cfg
->AcceptBroadcast
) || MultiCastUpdate
) {
2033 // Clear the UDP instance configuration, all joined groups will be left
2034 // during the operation.
2036 Private
->Udp4Read
->Configure (Private
->Udp4Read
, NULL
);
2039 // Configure the UDP instance with the new configuration.
2041 Udp4Cfg
->AcceptPromiscuous
= AcceptPromiscuous
;
2042 Udp4Cfg
->AcceptBroadcast
= AcceptBroadcast
;
2043 Status
= Private
->Udp4Read
->Configure (Private
->Udp4Read
, Udp4Cfg
);
2044 if (EFI_ERROR (Status
)) {
2049 // In not Promiscuous mode, need to join the new multicast group.
2051 if (!AcceptPromiscuous
) {
2052 for (Index
= 0; Index
< NewFilter
->IpCnt
; ++Index
) {
2053 if (IP4_IS_MULTICAST (EFI_NTOHL (NewFilter
->IpList
[Index
].v4
))) {
2055 // Join the mutilcast group.
2057 Status
= Private
->Udp4Read
->Groups (Private
->Udp4Read
, TRUE
, &NewFilter
->IpList
[Index
].v4
);
2058 if (EFI_ERROR (Status
)) {
2068 // Save the new filter.
2070 CopyMem (&Mode
->IpFilter
, NewFilter
, sizeof (Mode
->IpFilter
));
2077 Uses the ARP protocol to resolve a MAC address.
2079 This function uses the ARP protocol to resolve a MAC address. The UsingIpv6 field
2080 of the EFI_PXE_BASE_CODE_MODE structure is used to determine if IPv4 or IPv6
2081 addresses are being used. The IP address specified by IpAddr is used to resolve
2082 a MAC address. If the ARP protocol succeeds in resolving the specified address,
2083 then the ArpCacheEntries and ArpCache fields of the EFI_PXE_BASE_CODE_MODE structure
2084 are updated, and EFI_SUCCESS is returned. If MacAddr is not NULL, the resolved
2085 MAC address is placed there as well. If the PXE Base Code protocol is in the
2086 stopped state, then EFI_NOT_STARTED is returned. If the ARP protocol encounters
2087 a timeout condition while attempting to resolve an address, then EFI_TIMEOUT is
2088 returned. If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
2089 then EFI_ABORTED is returned.
2091 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2092 @param IpAddr Pointer to the IP address that is used to resolve a MAC address.
2093 @param MacAddr If not NULL, a pointer to the MAC address that was resolved with the
2096 @retval EFI_SUCCESS The IP or MAC address was resolved.
2097 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2098 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2099 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
2100 @retval EFI_ICMP_ERROR Something error occur with the ICMP packet message.
2106 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2107 IN EFI_IP_ADDRESS
* IpAddr
,
2108 IN EFI_MAC_ADDRESS
* MacAddr OPTIONAL
2111 PXEBC_PRIVATE_DATA
*Private
;
2112 EFI_PXE_BASE_CODE_MODE
*Mode
;
2114 EFI_MAC_ADDRESS TempMacAddr
;
2116 if (This
== NULL
|| IpAddr
== NULL
) {
2117 return EFI_INVALID_PARAMETER
;
2120 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2121 Mode
= Private
->PxeBc
.Mode
;
2123 if (!Mode
->Started
) {
2124 return EFI_NOT_STARTED
;
2127 if (!Private
->AddressIsOk
|| Mode
->UsingIpv6
) {
2129 // We can't resolve the IP address if we don't have a local address now.
2130 // Don't have ARP for IPv6.
2132 return EFI_INVALID_PARAMETER
;
2135 Mode
->IcmpErrorReceived
= FALSE
;
2137 if (!Mode
->AutoArp
) {
2139 // If AutoArp is set false, check arp cache
2141 UpdateArpCache (This
);
2142 if (!FindInArpCache (Mode
, &IpAddr
->v4
, &TempMacAddr
)) {
2143 return EFI_DEVICE_ERROR
;
2146 Status
= Private
->Arp
->Request (Private
->Arp
, &IpAddr
->v4
, NULL
, &TempMacAddr
);
2147 if (EFI_ERROR (Status
)) {
2148 if (Status
== EFI_ICMP_ERROR
) {
2149 Mode
->IcmpErrorReceived
= TRUE
;
2155 if (MacAddr
!= NULL
) {
2156 CopyMem (MacAddr
, &TempMacAddr
, sizeof (EFI_MAC_ADDRESS
));
2163 Updates the parameters that affect the operation of the PXE Base Code Protocol.
2165 This function sets parameters that affect the operation of the PXE Base Code Protocol.
2166 The parameter specified by NewAutoArp is used to control the generation of ARP
2167 protocol packets. If NewAutoArp is TRUE, then ARP Protocol packets will be generated
2168 as required by the PXE Base Code Protocol. If NewAutoArp is FALSE, then no ARP
2169 Protocol packets will be generated. In this case, the only mappings that are
2170 available are those stored in the ArpCache of the EFI_PXE_BASE_CODE_MODE structure.
2171 If there are not enough mappings in the ArpCache to perform a PXE Base Code Protocol
2172 service, then the service will fail. This function updates the AutoArp field of
2173 the EFI_PXE_BASE_CODE_MODE structure to NewAutoArp.
2174 The SetParameters() call must be invoked after a Callback Protocol is installed
2175 to enable the use of callbacks.
2177 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2178 @param NewAutoArp If not NULL, a pointer to a value that specifies whether to replace the
2179 current value of AutoARP.
2180 @param NewSendGUID If not NULL, a pointer to a value that specifies whether to replace the
2181 current value of SendGUID.
2182 @param NewTTL If not NULL, a pointer to be used in place of the current value of TTL,
2183 the "time to live" field of the IP header.
2184 @param NewToS If not NULL, a pointer to be used in place of the current value of ToS,
2185 the "type of service" field of the IP header.
2186 @param NewMakeCallback If not NULL, a pointer to a value that specifies whether to replace the
2187 current value of the MakeCallback field of the Mode structure.
2189 @retval EFI_SUCCESS The new parameters values were updated.
2190 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2191 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2196 EfiPxeBcSetParameters (
2197 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
2198 IN BOOLEAN
*NewAutoArp OPTIONAL
,
2199 IN BOOLEAN
*NewSendGUID OPTIONAL
,
2200 IN UINT8
*NewTTL OPTIONAL
,
2201 IN UINT8
*NewToS OPTIONAL
,
2202 IN BOOLEAN
*NewMakeCallback
// OPTIONAL
2205 PXEBC_PRIVATE_DATA
*Private
;
2206 EFI_PXE_BASE_CODE_MODE
*Mode
;
2209 Status
= EFI_SUCCESS
;
2212 Status
= EFI_INVALID_PARAMETER
;
2216 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2217 Mode
= Private
->PxeBc
.Mode
;
2219 if (NewSendGUID
!= NULL
&& *NewSendGUID
) {
2221 // FixMe, cann't locate SendGuid
2225 if (NewMakeCallback
!= NULL
&& *NewMakeCallback
) {
2227 Status
= gBS
->HandleProtocol (
2228 Private
->Controller
,
2229 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2230 (VOID
**) &Private
->PxeBcCallback
2232 if (EFI_ERROR (Status
) || (Private
->PxeBcCallback
->Callback
== NULL
)) {
2234 Status
= EFI_INVALID_PARAMETER
;
2239 if (!Mode
->Started
) {
2240 Status
= EFI_NOT_STARTED
;
2244 if (NewMakeCallback
!= NULL
) {
2246 if (*NewMakeCallback
) {
2248 // Update the Callback protocol.
2250 Status
= gBS
->HandleProtocol (
2251 Private
->Controller
,
2252 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2253 (VOID
**) &Private
->PxeBcCallback
2256 if (EFI_ERROR (Status
) || (Private
->PxeBcCallback
->Callback
== NULL
)) {
2257 Status
= EFI_INVALID_PARAMETER
;
2261 Private
->PxeBcCallback
= NULL
;
2264 Mode
->MakeCallbacks
= *NewMakeCallback
;
2267 if (NewAutoArp
!= NULL
) {
2268 Mode
->AutoArp
= *NewAutoArp
;
2271 if (NewSendGUID
!= NULL
) {
2272 Mode
->SendGUID
= *NewSendGUID
;
2275 if (NewTTL
!= NULL
) {
2276 Mode
->TTL
= *NewTTL
;
2279 if (NewToS
!= NULL
) {
2280 Mode
->ToS
= *NewToS
;
2288 Updates the station IP address and/or subnet mask values of a network device.
2290 This function updates the station IP address and/or subnet mask values of a network
2291 device. The NewStationIp field is used to modify the network device's current IP address.
2292 If NewStationIP is NULL, then the current IP address will not be modified. Otherwise,
2293 this function updates the StationIp field of the EFI_PXE_BASE_CODE_MODE structure
2294 with NewStationIp. The NewSubnetMask field is used to modify the network device's current subnet
2295 mask. If NewSubnetMask is NULL, then the current subnet mask will not be modified.
2296 Otherwise, this function updates the SubnetMask field of the EFI_PXE_BASE_CODE_MODE
2297 structure with NewSubnetMask.
2299 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2300 @param NewStationIp Pointer to the new IP address to be used by the network device.
2301 @param NewSubnetMask Pointer to the new subnet mask to be used by the network device.
2303 @retval EFI_SUCCESS The new station IP address and/or subnet mask were updated.
2304 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2305 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2310 EfiPxeBcSetStationIP (
2311 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2312 IN EFI_IP_ADDRESS
* NewStationIp OPTIONAL
,
2313 IN EFI_IP_ADDRESS
* NewSubnetMask OPTIONAL
2316 PXEBC_PRIVATE_DATA
*Private
;
2317 EFI_PXE_BASE_CODE_MODE
*Mode
;
2318 EFI_ARP_CONFIG_DATA ArpConfigData
;
2321 return EFI_INVALID_PARAMETER
;
2324 if (NewSubnetMask
!= NULL
&& !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask
->Addr
[0]))) {
2325 return EFI_INVALID_PARAMETER
;
2328 if (NewStationIp
!= NULL
) {
2329 if (IP4_IS_UNSPECIFIED(NTOHL (NewStationIp
->Addr
[0])) ||
2330 IP4_IS_LOCAL_BROADCAST(NTOHL (NewStationIp
->Addr
[0])) ||
2331 (NewSubnetMask
!= NULL
&& NewSubnetMask
->Addr
[0] != 0 && !NetIp4IsUnicast (NTOHL (NewStationIp
->Addr
[0]), NTOHL (NewSubnetMask
->Addr
[0])))) {
2332 return EFI_INVALID_PARAMETER
;
2336 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2337 Mode
= Private
->PxeBc
.Mode
;
2339 if (!Mode
->Started
) {
2340 return EFI_NOT_STARTED
;
2343 if (NewStationIp
!= NULL
) {
2344 CopyMem (&Mode
->StationIp
, NewStationIp
, sizeof (EFI_IP_ADDRESS
));
2345 CopyMem (&Private
->StationIp
, NewStationIp
, sizeof (EFI_IP_ADDRESS
));
2348 if (NewSubnetMask
!= NULL
) {
2349 CopyMem (&Mode
->SubnetMask
, NewSubnetMask
, sizeof (EFI_IP_ADDRESS
));
2350 CopyMem (&Private
->SubnetMask
,NewSubnetMask
, sizeof (EFI_IP_ADDRESS
));
2353 Private
->AddressIsOk
= TRUE
;
2355 if (!Mode
->UsingIpv6
) {
2357 // If in IPv4 mode, configure the corresponding ARP with this new
2358 // station IP address.
2360 ZeroMem (&ArpConfigData
, sizeof (EFI_ARP_CONFIG_DATA
));
2362 ArpConfigData
.SwAddressType
= 0x0800;
2363 ArpConfigData
.SwAddressLength
= (UINT8
) sizeof (EFI_IPv4_ADDRESS
);
2364 ArpConfigData
.StationAddress
= &Private
->StationIp
.v4
;
2366 Private
->Arp
->Configure (Private
->Arp
, NULL
);
2367 Private
->Arp
->Configure (Private
->Arp
, &ArpConfigData
);
2370 // Update the route table.
2372 Mode
->RouteTableEntries
= 1;
2373 Mode
->RouteTable
[0].IpAddr
.Addr
[0] = Private
->StationIp
.Addr
[0] & Private
->SubnetMask
.Addr
[0];
2374 Mode
->RouteTable
[0].SubnetMask
.Addr
[0] = Private
->SubnetMask
.Addr
[0];
2375 Mode
->RouteTable
[0].GwAddr
.Addr
[0] = 0;
2382 Updates the contents of the cached DHCP and Discover packets.
2384 The pointers to the new packets are used to update the contents of the cached
2385 packets in the EFI_PXE_BASE_CODE_MODE structure.
2387 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2388 @param NewDhcpDiscoverValid Pointer to a value that will replace the current
2389 DhcpDiscoverValid field.
2390 @param NewDhcpAckReceived Pointer to a value that will replace the current
2391 DhcpAckReceived field.
2392 @param NewProxyOfferReceived Pointer to a value that will replace the current
2393 ProxyOfferReceived field.
2394 @param NewPxeDiscoverValid Pointer to a value that will replace the current
2395 ProxyOfferReceived field.
2396 @param NewPxeReplyReceived Pointer to a value that will replace the current
2397 PxeReplyReceived field.
2398 @param NewPxeBisReplyReceived Pointer to a value that will replace the current
2399 PxeBisReplyReceived field.
2400 @param NewDhcpDiscover Pointer to the new cached DHCP Discover packet contents.
2401 @param NewDhcpAck Pointer to the new cached DHCP Ack packet contents.
2402 @param NewProxyOffer Pointer to the new cached Proxy Offer packet contents.
2403 @param NewPxeDiscover Pointer to the new cached PXE Discover packet contents.
2404 @param NewPxeReply Pointer to the new cached PXE Reply packet contents.
2405 @param NewPxeBisReply Pointer to the new cached PXE BIS Reply packet contents.
2407 @retval EFI_SUCCESS The cached packet contents were updated.
2408 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2409 @retval EFI_INVALID_PARAMETER This is NULL or not point to a valid EFI_PXE_BASE_CODE_PROTOCOL structure.
2414 EfiPxeBcSetPackets (
2415 IN EFI_PXE_BASE_CODE_PROTOCOL
* This
,
2416 IN BOOLEAN
* NewDhcpDiscoverValid OPTIONAL
,
2417 IN BOOLEAN
* NewDhcpAckReceived OPTIONAL
,
2418 IN BOOLEAN
* NewProxyOfferReceived OPTIONAL
,
2419 IN BOOLEAN
* NewPxeDiscoverValid OPTIONAL
,
2420 IN BOOLEAN
* NewPxeReplyReceived OPTIONAL
,
2421 IN BOOLEAN
* NewPxeBisReplyReceived OPTIONAL
,
2422 IN EFI_PXE_BASE_CODE_PACKET
* NewDhcpDiscover OPTIONAL
,
2423 IN EFI_PXE_BASE_CODE_PACKET
* NewDhcpAck OPTIONAL
,
2424 IN EFI_PXE_BASE_CODE_PACKET
* NewProxyOffer OPTIONAL
,
2425 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeDiscover OPTIONAL
,
2426 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeReply OPTIONAL
,
2427 IN EFI_PXE_BASE_CODE_PACKET
* NewPxeBisReply OPTIONAL
2430 PXEBC_PRIVATE_DATA
*Private
;
2431 EFI_PXE_BASE_CODE_MODE
*Mode
;
2434 return EFI_INVALID_PARAMETER
;
2437 Private
= PXEBC_PRIVATE_DATA_FROM_PXEBC (This
);
2438 Mode
= Private
->PxeBc
.Mode
;
2440 if (!Mode
->Started
) {
2441 return EFI_NOT_STARTED
;
2444 if (NewDhcpDiscoverValid
!= NULL
) {
2445 Mode
->DhcpDiscoverValid
= *NewDhcpDiscoverValid
;
2448 if (NewDhcpAckReceived
!= NULL
) {
2449 Mode
->DhcpAckReceived
= *NewDhcpAckReceived
;
2452 if (NewProxyOfferReceived
!= NULL
) {
2453 Mode
->ProxyOfferReceived
= *NewProxyOfferReceived
;
2456 if (NewPxeDiscoverValid
!= NULL
) {
2457 Mode
->PxeDiscoverValid
= *NewPxeDiscoverValid
;
2460 if (NewPxeReplyReceived
!= NULL
) {
2461 Mode
->PxeReplyReceived
= *NewPxeReplyReceived
;
2464 if (NewPxeBisReplyReceived
!= NULL
) {
2465 Mode
->PxeBisReplyReceived
= *NewPxeBisReplyReceived
;
2468 if (NewDhcpDiscover
!= NULL
) {
2469 CopyMem (&Mode
->DhcpDiscover
, NewDhcpDiscover
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2472 if (NewDhcpAck
!= NULL
) {
2473 CopyMem (&Mode
->DhcpAck
, NewDhcpAck
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2476 if (NewProxyOffer
!= NULL
) {
2477 CopyMem (&Mode
->ProxyOffer
, NewProxyOffer
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2480 if (NewPxeDiscover
!= NULL
) {
2481 CopyMem (&Mode
->PxeDiscover
, NewPxeDiscover
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2484 if (NewPxeReply
!= NULL
) {
2485 CopyMem (&Mode
->PxeReply
, NewPxeReply
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2488 if (NewPxeBisReply
!= NULL
) {
2489 CopyMem (&Mode
->PxeBisReply
, NewPxeBisReply
, sizeof (EFI_PXE_BASE_CODE_PACKET
));
2495 EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate
= {
2496 EFI_PXE_BASE_CODE_PROTOCOL_REVISION
,
2504 EfiPxeBcSetIpFilter
,
2506 EfiPxeBcSetParameters
,
2507 EfiPxeBcSetStationIP
,
2513 Callback function that is invoked when the PXE Base Code Protocol is about to transmit, has
2514 received, or is waiting to receive a packet.
2516 This function is invoked when the PXE Base Code Protocol is about to transmit, has received,
2517 or is waiting to receive a packet. Parameters Function and Received specify the type of event.
2518 Parameters PacketLen and Packet specify the packet that generated the event. If these fields
2519 are zero and NULL respectively, then this is a status update callback. If the operation specified
2520 by Function is to continue, then CALLBACK_STATUS_CONTINUE should be returned. If the operation
2521 specified by Function should be aborted, then CALLBACK_STATUS_ABORT should be returned. Due to
2522 the polling nature of UEFI device drivers, a callback function should not execute for more than 5 ms.
2523 The SetParameters() function must be called after a Callback Protocol is installed to enable the
2526 @param This Pointer to the EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL instance.
2527 @param Function The PXE Base Code Protocol function that is waiting for an event.
2528 @param Received TRUE if the callback is being invoked due to a receive event. FALSE if
2529 the callback is being invoked due to a transmit event.
2530 @param PacketLength The length, in bytes, of Packet. This field will have a value of zero if
2531 this is a wait for receive event.
2532 @param PacketPtr If Received is TRUE, a pointer to the packet that was just received;
2533 otherwise a pointer to the packet that is about to be transmitted.
2535 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE if Function specifies a continue operation
2536 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT if Function specifies an abort operation
2539 EFI_PXE_BASE_CODE_CALLBACK_STATUS
2541 EfiPxeLoadFileCallback (
2542 IN EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL
* This
,
2543 IN EFI_PXE_BASE_CODE_FUNCTION Function
,
2544 IN BOOLEAN Received
,
2545 IN UINT32 PacketLength
,
2546 IN EFI_PXE_BASE_CODE_PACKET
* PacketPtr OPTIONAL
2553 // Catch Ctrl-C or ESC to abort.
2555 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2557 if (!EFI_ERROR (Status
)) {
2559 if (Key
.ScanCode
== SCAN_ESC
|| Key
.UnicodeChar
== (0x1F & 'c')) {
2561 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT
;
2565 // No print if receive packet
2568 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2571 // Print only for three functions
2575 case EFI_PXE_BASE_CODE_FUNCTION_MTFTP
:
2577 // Print only for open MTFTP packets, not every MTFTP packets
2579 if (PacketLength
!= 0 && PacketPtr
!= NULL
) {
2580 if (PacketPtr
->Raw
[0x1C] != 0x00 || PacketPtr
->Raw
[0x1D] != 0x01) {
2581 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2586 case EFI_PXE_BASE_CODE_FUNCTION_DHCP
:
2587 case EFI_PXE_BASE_CODE_FUNCTION_DISCOVER
:
2591 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2594 if (PacketLength
!= 0 && PacketPtr
!= NULL
) {
2596 // Print '.' when transmit a packet
2602 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
;
2605 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL mPxeBcCallBackTemplate
= {
2606 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_REVISION
,
2607 EfiPxeLoadFileCallback
2614 @param Private Pointer to PxeBc private data.
2615 @param BufferSize Pointer to buffer size.
2616 @param Buffer Pointer to buffer.
2618 @retval EFI_SUCCESS Discover the boot file successfully.
2619 @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.
2620 @retval EFI_ABORTED PXE bootstrap server, so local boot need abort.
2621 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to load the boot file.
2626 IN PXEBC_PRIVATE_DATA
*Private
,
2627 IN OUT UINT64
*BufferSize
,
2631 EFI_PXE_BASE_CODE_PROTOCOL
*PxeBc
;
2632 EFI_PXE_BASE_CODE_MODE
*Mode
;
2637 PXEBC_CACHED_DHCP4_PACKET
*Packet
;
2640 PxeBc
= &Private
->PxeBc
;
2642 Type
= EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP
;
2643 Layer
= EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL
;
2648 Status
= PxeBc
->Dhcp (PxeBc
, TRUE
);
2649 if (EFI_ERROR (Status
)) {
2654 // Select a boot server
2656 Status
= PxeBcSelectBootPrompt (Private
);
2658 if (Status
== EFI_SUCCESS
) {
2659 Status
= PxeBcSelectBootMenu (Private
, &Type
, TRUE
);
2660 } else if (Status
== EFI_TIMEOUT
) {
2661 Status
= PxeBcSelectBootMenu (Private
, &Type
, FALSE
);
2664 if (!EFI_ERROR (Status
)) {
2666 if (Type
== EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP
) {
2668 // Local boot(PXE bootstrap server) need abort
2673 UseBis
= (BOOLEAN
) (Mode
->BisSupported
&& Mode
->BisDetected
);
2674 Status
= PxeBc
->Discover (PxeBc
, Type
, &Layer
, UseBis
, NULL
);
2675 if (EFI_ERROR (Status
)) {
2683 // Get bootfile name and (m)tftp server ip addresss
2685 if (Mode
->PxeReplyReceived
) {
2686 Packet
= &Private
->PxeReply
;
2687 } else if (Mode
->ProxyOfferReceived
) {
2688 Packet
= &Private
->ProxyOffer
;
2690 Packet
= &Private
->Dhcp4Ack
;
2694 // Use siaddr(next server) in DHCPOFFER packet header, if zero, use option 54(server identifier)
2695 // in DHCPOFFER packet.
2696 // (It does not comply with PXE Spec, Ver2.1)
2698 if (EFI_IP4_EQUAL (&Packet
->Packet
.Offer
.Dhcp4
.Header
.ServerAddr
, &mZeroIp4Addr
)) {
2701 Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_SERVER_ID
]->Data
,
2702 sizeof (EFI_IPv4_ADDRESS
)
2707 &Packet
->Packet
.Offer
.Dhcp4
.Header
.ServerAddr
,
2708 sizeof (EFI_IPv4_ADDRESS
)
2711 if (Private
->ServerIp
.Addr
[0] == 0) {
2712 return EFI_DEVICE_ERROR
;
2715 ASSERT (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE
] != NULL
);
2720 Private
->BootFileName
= (CHAR8
*) (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE
]->Data
);
2722 if (Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN
] != NULL
) {
2724 // Already have the bootfile length option, compute the file size
2726 CopyMem (&Value
, Packet
->Dhcp4Option
[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN
]->Data
, sizeof (Value
));
2727 Value
= NTOHS (Value
);
2728 *BufferSize
= 512 * Value
;
2729 Status
= EFI_BUFFER_TOO_SMALL
;
2732 // Get the bootfile size from tftp
2734 Status
= PxeBc
->Mtftp (
2736 EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE
,
2740 &Private
->BlockSize
,
2742 (UINT8
*) Private
->BootFileName
,
2748 Private
->FileSize
= (UINTN
) *BufferSize
;
2751 // Display all the information: boot server address, boot file name and boot file size.
2753 AsciiPrint ("\n Server IP address is ");
2754 PxeBcShowIp4Addr (&Private
->ServerIp
.v4
);
2755 AsciiPrint ("\n NBP filename is %a", Private
->BootFileName
);
2756 AsciiPrint ("\n NBP filesize is %d Bytes", Private
->FileSize
);
2762 Causes the driver to load a specified file.
2764 @param This Protocol instance pointer.
2765 @param FilePath The device specific path of the file to load.
2766 @param BootPolicy If TRUE, indicates that the request originates from the
2767 boot manager is attempting to load FilePath as a boot
2768 selection. If FALSE, then FilePath must match as exact file
2770 @param BufferSize On input the size of Buffer in bytes. On output with a return
2771 code of EFI_SUCCESS, the amount of data transferred to
2772 Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
2773 the size of Buffer required to retrieve the requested file.
2774 @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
2775 then no the size of the requested file is returned in
2778 @retval EFI_SUCCESS The file was loaded.
2779 @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy
2780 @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or
2782 @retval EFI_NO_MEDIA No medium was present to load the file.
2783 @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.
2784 @retval EFI_NO_RESPONSE The remote system did not respond.
2785 @retval EFI_NOT_FOUND The file was not found.
2786 @retval EFI_ABORTED The file load process was manually cancelled.
2792 IN EFI_LOAD_FILE_PROTOCOL
* This
,
2793 IN EFI_DEVICE_PATH_PROTOCOL
* FilePath
,
2794 IN BOOLEAN BootPolicy
,
2795 IN OUT UINTN
*BufferSize
,
2796 IN VOID
*Buffer OPTIONAL
2799 PXEBC_PRIVATE_DATA
*Private
;
2800 EFI_PXE_BASE_CODE_PROTOCOL
*PxeBc
;
2801 BOOLEAN NewMakeCallback
;
2804 EFI_STATUS MediaStatus
;
2806 if (FilePath
== NULL
|| !IsDevicePathEnd (FilePath
)) {
2807 return EFI_INVALID_PARAMETER
;
2810 Private
= PXEBC_PRIVATE_DATA_FROM_LOADFILE (This
);
2811 PxeBc
= &Private
->PxeBc
;
2812 NewMakeCallback
= FALSE
;
2813 Status
= EFI_DEVICE_ERROR
;
2815 if (This
== NULL
|| BufferSize
== NULL
) {
2817 return EFI_INVALID_PARAMETER
;
2821 // Only support BootPolicy
2824 return EFI_UNSUPPORTED
;
2828 // Check media status before PXE start
2830 MediaStatus
= EFI_SUCCESS
;
2831 NetLibDetectMediaWaitTimeout (Private
->Controller
, PXEBC_CHECK_MEDIA_WAITING_TIME
, &MediaStatus
);
2832 if (MediaStatus
!= EFI_SUCCESS
) {
2833 return EFI_NO_MEDIA
;
2836 Status
= PxeBc
->Start (PxeBc
, FALSE
);
2837 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
2841 Status
= gBS
->HandleProtocol (
2842 Private
->Controller
,
2843 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2844 (VOID
**) &Private
->PxeBcCallback
2846 if (Status
== EFI_UNSUPPORTED
) {
2848 CopyMem (&Private
->LoadFileCallback
, &mPxeBcCallBackTemplate
, sizeof (Private
->LoadFileCallback
));
2850 Status
= gBS
->InstallProtocolInterface (
2851 &Private
->Controller
,
2852 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2853 EFI_NATIVE_INTERFACE
,
2854 &Private
->LoadFileCallback
2857 NewMakeCallback
= (BOOLEAN
) (Status
== EFI_SUCCESS
);
2859 Status
= PxeBc
->SetParameters (PxeBc
, NULL
, NULL
, NULL
, NULL
, &NewMakeCallback
);
2860 if (EFI_ERROR (Status
)) {
2861 PxeBc
->Stop (PxeBc
);
2866 if (Private
->FileSize
== 0) {
2868 Status
= DiscoverBootFile (Private
, &TmpBufSize
, Buffer
);
2870 if (sizeof (UINTN
) < sizeof (UINT64
) && (TmpBufSize
> 0xFFFFFFFF)) {
2871 Status
= EFI_DEVICE_ERROR
;
2872 } else if (TmpBufSize
> 0 && *BufferSize
>= (UINTN
) TmpBufSize
&& Buffer
!= NULL
) {
2873 AsciiPrint ("\n Downloading NBP file...\n");
2874 *BufferSize
= (UINTN
) TmpBufSize
;
2875 Status
= PxeBc
->Mtftp (
2877 EFI_PXE_BASE_CODE_TFTP_READ_FILE
,
2881 &Private
->BlockSize
,
2883 (UINT8
*) Private
->BootFileName
,
2887 } else if (TmpBufSize
> 0) {
2888 *BufferSize
= (UINTN
) TmpBufSize
;
2889 Status
= EFI_BUFFER_TOO_SMALL
;
2891 } else if (Buffer
== NULL
|| Private
->FileSize
> *BufferSize
) {
2892 *BufferSize
= Private
->FileSize
;
2893 Status
= EFI_BUFFER_TOO_SMALL
;
2896 // Download the file.
2898 AsciiPrint ("\n Downloading NBP file...\n");
2899 TmpBufSize
= (UINT64
) (*BufferSize
);
2900 Status
= PxeBc
->Mtftp (
2902 EFI_PXE_BASE_CODE_TFTP_READ_FILE
,
2906 &Private
->BlockSize
,
2908 (UINT8
*) Private
->BootFileName
,
2914 // If we added a callback protocol, now is the time to remove it.
2916 if (NewMakeCallback
) {
2918 NewMakeCallback
= FALSE
;
2920 PxeBc
->SetParameters (PxeBc
, NULL
, NULL
, NULL
, NULL
, &NewMakeCallback
);
2922 gBS
->UninstallProtocolInterface (
2923 Private
->Controller
,
2924 &gEfiPxeBaseCodeCallbackProtocolGuid
,
2925 &Private
->LoadFileCallback
2930 // Check download status
2932 if (Status
== EFI_SUCCESS
) {
2933 AsciiPrint ("\n NBP file downloaded successfully.\n");
2935 // The DHCP4 can have only one configured child instance so we need to stop
2936 // reset the DHCP4 child before we return. Otherwise the other programs which
2937 // also need to use DHCP4 will be impacted.
2938 // The functionality of PXE Base Code protocol will not be stopped,
2939 // when downloading is successfully.
2941 Private
->Dhcp4
->Stop (Private
->Dhcp4
);
2942 Private
->Dhcp4
->Configure (Private
->Dhcp4
, NULL
);
2945 } else if (Status
== EFI_BUFFER_TOO_SMALL
) {
2946 if (Buffer
!= NULL
) {
2947 AsciiPrint ("PXE-E05: Download buffer is smaller than requested file.\n");
2950 // The functionality of PXE Base Code protocol will not be stopped.
2955 } else if (Status
== EFI_DEVICE_ERROR
) {
2956 AsciiPrint ("PXE-E07: Network device error.\n");
2958 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
2959 AsciiPrint ("PXE-E09: Could not allocate I/O buffers.\n");
2961 } else if (Status
== EFI_NO_MEDIA
) {
2962 AsciiPrint ("PXE-E12: Could not detect network connection.\n");
2964 } else if (Status
== EFI_NO_RESPONSE
) {
2965 AsciiPrint ("PXE-E16: No offer received.\n");
2967 } else if (Status
== EFI_TIMEOUT
) {
2968 AsciiPrint ("PXE-E18: Server response timeout.\n");
2970 } else if (Status
== EFI_ABORTED
) {
2971 AsciiPrint ("PXE-E21: Remote boot cancelled.\n");
2973 } else if (Status
== EFI_ICMP_ERROR
) {
2974 AsciiPrint ("PXE-E22: Client received ICMP error from server.\n");
2976 } else if (Status
== EFI_TFTP_ERROR
) {
2977 AsciiPrint ("PXE-E23: Client received TFTP error from server.\n");
2980 AsciiPrint ("PXE-E99: Unexpected network error.\n");
2983 PxeBc
->Stop (PxeBc
);
2988 EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate
= { EfiPxeLoadFile
};