]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
511e064873a246ce93d6a52bcc299e3b818fe458
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcImpl.c
1 /** @file
2 Interface routines for PxeBc.
3
4 Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
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.
12
13 **/
14
15
16 #include "PxeBcImpl.h"
17
18 UINT32 mPxeDhcpTimeout[4] = { 4, 8, 16, 32 };
19
20 /**
21 Get and record the arp cache.
22
23 @param This Pointer to EFI_PXE_BC_PROTOCOL
24
25 @retval EFI_SUCCESS Arp cache updated successfully
26 @retval others If error occurs when getting arp cache
27
28 **/
29 EFI_STATUS
30 UpdateArpCache (
31 IN EFI_PXE_BASE_CODE_PROTOCOL * This
32 )
33 {
34 PXEBC_PRIVATE_DATA *Private;
35 EFI_PXE_BASE_CODE_MODE *Mode;
36 EFI_STATUS Status;
37 UINT32 EntryLength;
38 UINT32 EntryCount;
39 EFI_ARP_FIND_DATA *Entries;
40 UINT32 Index;
41
42 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
43 Mode = Private->PxeBc.Mode;
44
45 Status = Private->Arp->Find (
46 Private->Arp,
47 TRUE,
48 NULL,
49 &EntryLength,
50 &EntryCount,
51 &Entries,
52 TRUE
53 );
54 if (EFI_ERROR (Status)) {
55 return Status;
56 }
57
58 Mode->ArpCacheEntries = MIN (
59 EntryCount,
60 EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES
61 );
62 for (Index = 0; Index < Mode->ArpCacheEntries; Index ++) {
63 CopyMem (
64 &Mode->ArpCache[Index].IpAddr,
65 Entries + 1,
66 Entries->SwAddressLength
67 );
68 CopyMem (
69 &Mode->ArpCache[Index].MacAddr,
70 (UINT8 *) (Entries + 1) + Entries->SwAddressLength,
71 Entries->HwAddressLength
72 );
73 //
74 // Slip to the next FindData.
75 //
76 Entries = (EFI_ARP_FIND_DATA *) ((UINT8 *) Entries + EntryLength);
77 }
78
79 return EFI_SUCCESS;
80 }
81
82 /**
83 Timeout routine to update arp cache.
84
85 @param Event Pointer to EFI_PXE_BC_PROTOCOL
86 @param Context Context of the timer event
87
88 **/
89 VOID
90 EFIAPI
91 ArpCacheUpdateTimeout (
92 IN EFI_EVENT Event,
93 IN VOID *Context
94 )
95 {
96 UpdateArpCache ((EFI_PXE_BASE_CODE_PROTOCOL *) Context);
97 }
98
99 /**
100 Do arp resolution from arp cache in PxeBcMode.
101
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.
106
107 @retval TRUE The resolution is successful.
108 @retval FALSE Otherwise.
109
110 **/
111 BOOLEAN
112 FindInArpCache (
113 IN EFI_PXE_BASE_CODE_MODE *PxeBcMode,
114 IN EFI_IPv4_ADDRESS *Ip4Addr,
115 OUT EFI_MAC_ADDRESS *MacAddress
116 )
117 {
118 UINT32 Index;
119
120 for (Index = 0; Index < PxeBcMode->ArpCacheEntries; Index ++) {
121 if (EFI_IP4_EQUAL (&PxeBcMode->ArpCache[Index].IpAddr.v4, Ip4Addr)) {
122 CopyMem (
123 MacAddress,
124 &PxeBcMode->ArpCache[Index].MacAddr,
125 sizeof (EFI_MAC_ADDRESS)
126 );
127 return TRUE;
128 }
129 }
130
131 return FALSE;
132 }
133
134 /**
135 Notify function for the ICMP receive token, used to process
136 the received ICMP packets.
137
138 @param Context The PXEBC private data.
139
140 **/
141 VOID
142 EFIAPI
143 IcmpErrorListenHandlerDpc (
144 IN VOID *Context
145 )
146 {
147 EFI_STATUS Status;
148 EFI_IP4_RECEIVE_DATA *RxData;
149 EFI_IP4_PROTOCOL *Ip4;
150 PXEBC_PRIVATE_DATA *Private;
151 EFI_PXE_BASE_CODE_MODE *Mode;
152 UINTN Index;
153 UINT32 CopiedLen;
154 UINT8 *CopiedPointer;
155
156 Private = (PXEBC_PRIVATE_DATA *) Context;
157 Mode = &Private->Mode;
158 Status = Private->IcmpErrorRcvToken.Status;
159 RxData = Private->IcmpErrorRcvToken.Packet.RxData;
160 Ip4 = Private->Ip4;
161
162 if (Status == EFI_ABORTED) {
163 //
164 // The reception is actively aborted by the consumer, directly return.
165 //
166 return;
167 }
168
169 if (EFI_ERROR (Status) || (RxData == NULL)) {
170 //
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).
174 //
175 goto Resume;
176 }
177
178 if (EFI_IP4 (RxData->Header->SourceAddress) != 0 &&
179 !NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), 0)) {
180 //
181 // The source address is not zero and it's not a unicast IP address, discard it.
182 //
183 goto CleanUp;
184 }
185
186 if (!EFI_IP4_EQUAL (&RxData->Header->DestinationAddress, &Mode->StationIp.v4)) {
187 //
188 // The dest address is not equal to Station Ip address, discard it.
189 //
190 goto CleanUp;
191 }
192
193 //
194 // Constructor ICMP error packet
195 //
196 CopiedLen = 0;
197 CopiedPointer = (UINT8 *) &Mode->IcmpError;
198
199 for (Index = 0; Index < RxData->FragmentCount; Index ++) {
200 CopiedLen += RxData->FragmentTable[Index].FragmentLength;
201 if (CopiedLen <= sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR)) {
202 CopyMem (
203 CopiedPointer,
204 RxData->FragmentTable[Index].FragmentBuffer,
205 RxData->FragmentTable[Index].FragmentLength
206 );
207 } else {
208 CopyMem (
209 CopiedPointer,
210 RxData->FragmentTable[Index].FragmentBuffer,
211 CopiedLen - sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR)
212 );
213 }
214 CopiedPointer += CopiedLen;
215 }
216
217 goto Resume;
218
219 CleanUp:
220 gBS->SignalEvent (RxData->RecycleSignal);
221
222 Resume:
223 Ip4->Receive (Ip4, &(Private->IcmpErrorRcvToken));
224 }
225
226 /**
227 Request IcmpErrorListenHandlerDpc as a DPC at TPL_CALLBACK
228
229 @param Event The event signaled.
230 @param Context The context passed in by the event notifier.
231
232 **/
233 VOID
234 EFIAPI
235 IcmpErrorListenHandler (
236 IN EFI_EVENT Event,
237 IN VOID *Context
238 )
239 {
240 //
241 // Request IpIoListenHandlerDpc as a DPC at TPL_CALLBACK
242 //
243 QueueDpc (TPL_CALLBACK, IcmpErrorListenHandlerDpc, Context);
244 }
245
246 /**
247 Enables the use of the PXE Base Code Protocol functions.
248
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:
259 StartedSet to TRUE.
260 Ipv6SupportedUnchanged.
261 Ipv6AvailableUnchanged.
262 UsingIpv6Set to UseIpv6.
263 BisSupportedUnchanged.
264 BisDetectedUnchanged.
265 AutoArpSet to TRUE.
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.
274 DhcpAckZero-filled.
275 ProxyOfferZero-filled.
276 PxeDiscoverValidSet to FALSE.
277 PxeDiscoverZero-filled.
278 PxeReplyValidSet to FALSE.
279 PxeReplyZero-filled.
280 PxeBisReplyValidSet to FALSE.
281 PxeBisReplyZero-filled.
282 IpFilterSet the Filters field to 0 and the IpCnt field to 0.
283 ArpCacheEntriesSet to 0.
284 ArpCacheZero-filled.
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.
293
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
297 IPv4 addresses.
298
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.
308
309 **/
310 EFI_STATUS
311 EFIAPI
312 EfiPxeBcStart (
313 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
314 IN BOOLEAN UseIpv6
315 )
316 {
317 PXEBC_PRIVATE_DATA *Private;
318 EFI_PXE_BASE_CODE_MODE *Mode;
319 EFI_STATUS Status;
320
321 if (This == NULL) {
322 return EFI_INVALID_PARAMETER;
323 }
324
325 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
326 Mode = Private->PxeBc.Mode;
327
328 if (Mode->Started) {
329 return EFI_ALREADY_STARTED;
330 }
331
332 if (UseIpv6) {
333 //
334 // IPv6 is not supported now.
335 //
336 return EFI_UNSUPPORTED;
337 }
338
339 //
340 // Configure the udp4 instance to let it receive data
341 //
342 Status = Private->Udp4Read->Configure (
343 Private->Udp4Read,
344 &Private->Udp4CfgData
345 );
346 if (EFI_ERROR (Status)) {
347 return Status;
348 }
349
350
351 //
352 // Configure block size for TFTP as a default value to handle all link layers.
353 //
354 Private->BlockSize = (UINTN) (MIN (Private->Ip4MaxPacketSize, PXEBC_DEFAULT_PACKET_SIZE) -
355 PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE);
356 //
357 // If PcdTftpBlockSize is set to non-zero, override the default value.
358 //
359 if (PcdGet64 (PcdTftpBlockSize) != 0) {
360 Private->BlockSize = (UINTN) PcdGet64 (PcdTftpBlockSize);
361 }
362
363 Private->AddressIsOk = FALSE;
364
365 ZeroMem (Mode, sizeof (EFI_PXE_BASE_CODE_MODE));
366
367 Mode->Started = TRUE;
368 Mode->TTL = DEFAULT_TTL;
369 Mode->ToS = DEFAULT_ToS;
370 Mode->AutoArp = TRUE;
371
372 //
373 // Create the event for Arp Cache checking.
374 //
375 Status = gBS->CreateEvent (
376 EVT_TIMER | EVT_NOTIFY_SIGNAL,
377 TPL_CALLBACK,
378 ArpCacheUpdateTimeout,
379 This,
380 &Private->GetArpCacheEvent
381 );
382 if (EFI_ERROR (Status)) {
383 goto ON_EXIT;
384 }
385
386 //
387 // Start the timeout timer event.
388 //
389 Status = gBS->SetTimer (
390 Private->GetArpCacheEvent,
391 TimerPeriodic,
392 TICKS_PER_SECOND
393 );
394
395 if (EFI_ERROR (Status)) {
396 goto ON_EXIT;
397 }
398
399 //
400 // Create ICMP error receiving event
401 //
402 Status = gBS->CreateEvent (
403 EVT_NOTIFY_SIGNAL,
404 TPL_NOTIFY,
405 IcmpErrorListenHandler,
406 Private,
407 &(Private->IcmpErrorRcvToken.Event)
408 );
409 if (EFI_ERROR (Status)) {
410 goto ON_EXIT;
411 }
412
413 Status = Private->Ip4->Configure (Private->Ip4, &Private->Ip4ConfigData);
414 if (EFI_ERROR (Status)) {
415 goto ON_EXIT;
416 }
417
418 //
419 // start to listen incoming packet
420 //
421 Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpErrorRcvToken);
422 if (!EFI_ERROR (Status)) {
423 return Status;
424 }
425
426 ON_EXIT:
427 Private->Ip4->Configure (Private->Ip4, NULL);
428
429 if (Private->IcmpErrorRcvToken.Event != NULL) {
430 gBS->CloseEvent (Private->IcmpErrorRcvToken.Event);
431 }
432
433 if (Private->GetArpCacheEvent != NULL) {
434 gBS->SetTimer (Private->GetArpCacheEvent, TimerCancel, 0);
435 gBS->CloseEvent (Private->GetArpCacheEvent);
436 }
437
438 Mode->Started = FALSE;
439 Mode->TTL = 0;
440 Mode->ToS = 0;
441 Mode->AutoArp = FALSE;
442
443 return Status;
444 }
445
446
447 /**
448 Disables the use of the PXE Base Code Protocol functions.
449
450 This function stops all activity on the network device. All the resources allocated
451 in Start() are released, the Started field of the EFI_PXE_BASE_CODE_MODE structure is
452 set to FALSE and EFI_SUCCESS is returned. If the Started field of the EFI_PXE_BASE_CODE_MODE
453 structure is already FALSE, then EFI_NOT_STARTED will be returned.
454
455 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
456
457 @retval EFI_SUCCESS The PXE Base Code Protocol was stopped.
458 @retval EFI_NOT_STARTED The PXE Base Code Protocol is already in the stopped state.
459 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
460 EFI_PXE_BASE_CODE_PROTOCOL structure.
461 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
462
463 **/
464 EFI_STATUS
465 EFIAPI
466 EfiPxeBcStop (
467 IN EFI_PXE_BASE_CODE_PROTOCOL *This
468 )
469 {
470 PXEBC_PRIVATE_DATA *Private;
471 EFI_PXE_BASE_CODE_MODE *Mode;
472
473 if (This == NULL) {
474 return EFI_INVALID_PARAMETER;
475 }
476
477 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
478 Mode = Private->PxeBc.Mode;
479
480 if (!Mode->Started) {
481 return EFI_NOT_STARTED;
482 }
483
484 Private->Ip4->Cancel (Private->Ip4, NULL);
485 //
486 // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's
487 // events.
488 //
489 DispatchDpc ();
490
491 Private->Ip4->Configure (Private->Ip4, NULL);
492
493 //
494 // Close the ICMP error receiving event.
495 //
496 gBS->CloseEvent (Private->IcmpErrorRcvToken.Event);
497
498 //
499 // Cancel the TimeoutEvent timer.
500 //
501 gBS->SetTimer (Private->GetArpCacheEvent, TimerCancel, 0);
502
503 //
504 // Close the TimeoutEvent event.
505 //
506 gBS->CloseEvent (Private->GetArpCacheEvent);
507
508 Mode->Started = FALSE;
509
510 Private->CurrentUdpSrcPort = 0;
511 Private->Udp4Write->Configure (Private->Udp4Write, NULL);
512 Private->Udp4Read->Groups (Private->Udp4Read, FALSE, NULL);
513 Private->Udp4Read->Configure (Private->Udp4Read, NULL);
514
515 Private->Dhcp4->Stop (Private->Dhcp4);
516 Private->Dhcp4->Configure (Private->Dhcp4, NULL);
517
518 Private->FileSize = 0;
519
520 return EFI_SUCCESS;
521 }
522
523
524 /**
525 Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request / acknowledge) or DHCPv6
526 S.A.R.R (solicit / advertise / request / reply) sequence.
527
528 This function attempts to complete the DHCP sequence. If this sequence is completed,
529 then EFI_SUCCESS is returned, and the DhcpCompleted, ProxyOfferReceived, StationIp,
530 SubnetMask, DhcpDiscover, DhcpAck, and ProxyOffer fields of the EFI_PXE_BASE_CODE_MODE
531 structure are filled in.
532 If SortOffers is TRUE, then the cached DHCP offer packets will be sorted before
533 they are tried. If SortOffers is FALSE, then the cached DHCP offer packets will
534 be tried in the order in which they are received. Please see the Preboot Execution
535 Environment (PXE) Specification for additional details on the implementation of DHCP.
536 This function can take at least 31 seconds to timeout and return control to the
537 caller. If the DHCP sequence does not complete, then EFI_TIMEOUT will be returned.
538 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
539 then the DHCP sequence will be stopped and EFI_ABORTED will be returned.
540
541 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
542 @param SortOffers TRUE if the offers received should be sorted. Set to FALSE to try the
543 offers in the order that they are received.
544
545 @retval EFI_SUCCESS Valid DHCP has completed.
546 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
547 @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid
548 EFI_PXE_BASE_CODE_PROTOCOL structure.
549 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
550 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete the DHCP Protocol.
551 @retval EFI_ABORTED The callback function aborted the DHCP Protocol.
552 @retval EFI_TIMEOUT The DHCP Protocol timed out.
553 @retval EFI_ICMP_ERROR An ICMP error packet was received during the DHCP session.
554 @retval EFI_NO_RESPONSE Valid PXE offer was not received.
555
556 **/
557 EFI_STATUS
558 EFIAPI
559 EfiPxeBcDhcp (
560 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
561 IN BOOLEAN SortOffers
562 )
563 {
564 PXEBC_PRIVATE_DATA *Private;
565 EFI_PXE_BASE_CODE_MODE *Mode;
566 EFI_DHCP4_PROTOCOL *Dhcp4;
567 EFI_DHCP4_CONFIG_DATA Dhcp4CfgData;
568 EFI_DHCP4_MODE_DATA Dhcp4Mode;
569 EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM];
570 UINT32 OptCount;
571 EFI_STATUS Status;
572 EFI_ARP_CONFIG_DATA ArpConfigData;
573 EFI_PXE_BASE_CODE_IP_FILTER IpFilter;
574
575 if (This == NULL) {
576 return EFI_INVALID_PARAMETER;
577 }
578
579 Status = EFI_SUCCESS;
580 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
581 Mode = Private->PxeBc.Mode;
582 Dhcp4 = Private->Dhcp4;
583 Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DHCP;
584 Private->SortOffers = SortOffers;
585
586 if (!Mode->Started) {
587 return EFI_NOT_STARTED;
588 }
589
590 Mode->IcmpErrorReceived = FALSE;
591
592 //
593 // Stop Udp4Read instance
594 //
595 Private->Udp4Read->Configure (Private->Udp4Read, NULL);
596
597 //
598 // Initialize the DHCP options and build the option list
599 //
600 OptCount = PxeBcBuildDhcpOptions (Private, OptList, TRUE);
601
602 //
603 // Set the DHCP4 config data.
604 // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.
605 //
606 ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));
607 Dhcp4CfgData.OptionCount = OptCount;
608 Dhcp4CfgData.OptionList = OptList;
609 Dhcp4CfgData.Dhcp4Callback = PxeBcDhcpCallBack;
610 Dhcp4CfgData.CallbackContext = Private;
611 Dhcp4CfgData.DiscoverTryCount = 4;
612 Dhcp4CfgData.DiscoverTimeout = mPxeDhcpTimeout;
613
614 Status = Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);
615 if (EFI_ERROR (Status)) {
616 goto ON_EXIT;
617 }
618
619 //
620 // Zero those arrays to record the varies numbers of DHCP OFFERS.
621 //
622 Private->GotProxyOffer = FALSE;
623 Private->NumOffers = 0;
624 Private->BootpIndex = 0;
625 ZeroMem (Private->ServerCount, sizeof (Private->ServerCount));
626 ZeroMem (Private->ProxyIndex, sizeof (Private->ProxyIndex));
627
628 Status = Dhcp4->Start (Dhcp4, NULL);
629 if (EFI_ERROR (Status)) {
630 if (Status == EFI_ICMP_ERROR) {
631 Mode->IcmpErrorReceived = TRUE;
632 }
633 goto ON_EXIT;
634 }
635
636 Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);
637 if (EFI_ERROR (Status)) {
638 goto ON_EXIT;
639 }
640
641 ASSERT (Dhcp4Mode.State == Dhcp4Bound);
642
643 CopyMem (&Private->StationIp, &Dhcp4Mode.ClientAddress, sizeof (EFI_IPv4_ADDRESS));
644 CopyMem (&Private->SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));
645 CopyMem (&Private->GatewayIp, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));
646
647 CopyMem (&Mode->StationIp, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));
648 CopyMem (&Mode->SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));
649
650 //
651 // Check the selected offer to see whether BINL is required, if no or BINL is
652 // finished, set the various Mode members.
653 //
654 Status = PxeBcCheckSelectedOffer (Private);
655 if (!EFI_ERROR (Status)) {
656 goto ON_EXIT;
657 }
658
659 ON_EXIT:
660 if (EFI_ERROR (Status)) {
661 Dhcp4->Stop (Dhcp4);
662 Dhcp4->Configure (Dhcp4, NULL);
663 } else {
664 //
665 // Remove the previously configured option list and callback function
666 //
667 ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));
668 Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);
669
670 Private->AddressIsOk = TRUE;
671
672 if (!Mode->UsingIpv6) {
673 //
674 // If in IPv4 mode, configure the corresponding ARP with this new
675 // station IP address.
676 //
677 ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA));
678
679 ArpConfigData.SwAddressType = 0x0800;
680 ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);
681 ArpConfigData.StationAddress = &Private->StationIp.v4;
682
683 Private->Arp->Configure (Private->Arp, NULL);
684 Private->Arp->Configure (Private->Arp, &ArpConfigData);
685
686 //
687 // Updated the route table. Fill the first entry.
688 //
689 Mode->RouteTableEntries = 1;
690 Mode->RouteTable[0].IpAddr.Addr[0] = Private->StationIp.Addr[0] & Private->SubnetMask.Addr[0];
691 Mode->RouteTable[0].SubnetMask.Addr[0] = Private->SubnetMask.Addr[0];
692 Mode->RouteTable[0].GwAddr.Addr[0] = 0;
693
694 //
695 // Create the default route entry if there is a default router.
696 //
697 if (Private->GatewayIp.Addr[0] != 0) {
698 Mode->RouteTableEntries = 2;
699 Mode->RouteTable[1].IpAddr.Addr[0] = 0;
700 Mode->RouteTable[1].SubnetMask.Addr[0] = 0;
701 Mode->RouteTable[1].GwAddr.Addr[0] = Private->GatewayIp.Addr[0];
702 }
703
704 //
705 // Flush new station IP address into Udp4CfgData and Ip4ConfigData
706 //
707 CopyMem (&Private->Udp4CfgData.StationAddress, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));
708 CopyMem (&Private->Udp4CfgData.SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));
709 CopyMem (&Private->Ip4ConfigData.StationAddress, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));
710 CopyMem (&Private->Ip4ConfigData.SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));
711
712 //
713 // Reconfigure the Ip4 instance to capture background ICMP packets with new station Ip address.
714 //
715 Private->Ip4->Cancel (Private->Ip4, &Private->IcmpErrorRcvToken);
716 Private->Ip4->Configure (Private->Ip4, NULL);
717
718 Status = Private->Ip4->Configure (Private->Ip4, &Private->Ip4ConfigData);
719 if (EFI_ERROR (Status)) {
720 goto ON_EXIT;
721 }
722
723 Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpErrorRcvToken);
724 if (EFI_ERROR (Status)) {
725 goto ON_EXIT;
726 }
727 }
728 }
729
730 Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);
731
732 //
733 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
734 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
735 //
736 ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));
737 IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;
738 This->SetIpFilter (This, &IpFilter);
739
740 return Status;
741 }
742
743
744 /**
745 Attempts to complete the PXE Boot Server and/or boot image discovery sequence.
746
747 This function attempts to complete the PXE Boot Server and/or boot image discovery
748 sequence. If this sequence is completed, then EFI_SUCCESS is returned, and the
749 PxeDiscoverValid, PxeDiscover, PxeReplyReceived, and PxeReply fields of the
750 EFI_PXE_BASE_CODE_MODE structure are filled in. If UseBis is TRUE, then the
751 PxeBisReplyReceived and PxeBisReply fields of the EFI_PXE_BASE_CODE_MODE structure
752 will also be filled in. If UseBis is FALSE, then PxeBisReplyValid will be set to FALSE.
753 In the structure referenced by parameter Info, the PXE Boot Server list, SrvList[],
754 has two uses: It is the Boot Server IP address list used for unicast discovery
755 (if the UseUCast field is TRUE), and it is the list used for Boot Server verification
756 (if the MustUseList field is TRUE). Also, if the MustUseList field in that structure
757 is TRUE and the AcceptAnyResponse field in the SrvList[] array is TRUE, any Boot
758 Server reply of that type will be accepted. If the AcceptAnyResponse field is
759 FALSE, only responses from Boot Servers with matching IP addresses will be accepted.
760 This function can take at least 10 seconds to timeout and return control to the
761 caller. If the Discovery sequence does not complete, then EFI_TIMEOUT will be
762 returned. Please see the Preboot Execution Environment (PXE) Specification for
763 additional details on the implementation of the Discovery sequence.
764 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
765 then the Discovery sequence is stopped and EFI_ABORTED will be returned.
766
767 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
768 @param Type The type of bootstrap to perform.
769 @param Layer Pointer to the boot server layer number to discover, which must be
770 PXE_BOOT_LAYER_INITIAL when a new server type is being
771 discovered.
772 @param UseBis TRUE if Boot Integrity Services are to be used. FALSE otherwise.
773 @param Info Pointer to a data structure that contains additional information on the
774 type of discovery operation that is to be performed.
775
776 @retval EFI_SUCCESS The Discovery sequence has been completed.
777 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
778 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
779 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
780 @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete Discovery.
781 @retval EFI_ABORTED The callback function aborted the Discovery sequence.
782 @retval EFI_TIMEOUT The Discovery sequence timed out.
783 @retval EFI_ICMP_ERROR An ICMP error packet was received during the PXE discovery
784 session.
785
786 **/
787 EFI_STATUS
788 EFIAPI
789 EfiPxeBcDiscover (
790 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
791 IN UINT16 Type,
792 IN UINT16 *Layer,
793 IN BOOLEAN UseBis,
794 IN EFI_PXE_BASE_CODE_DISCOVER_INFO *Info OPTIONAL
795 )
796 {
797 PXEBC_PRIVATE_DATA *Private;
798 EFI_PXE_BASE_CODE_MODE *Mode;
799 EFI_PXE_BASE_CODE_DISCOVER_INFO DefaultInfo;
800 EFI_PXE_BASE_CODE_DISCOVER_INFO *CreatedInfo;
801 EFI_PXE_BASE_CODE_SRVLIST *SrvList;
802 EFI_PXE_BASE_CODE_SRVLIST DefaultSrvList;
803 PXEBC_CACHED_DHCP4_PACKET *Packet;
804 PXEBC_VENDOR_OPTION *VendorOpt;
805 UINT16 Index;
806 EFI_STATUS Status;
807 PXEBC_BOOT_SVR_ENTRY *BootSvrEntry;
808 EFI_PXE_BASE_CODE_IP_FILTER IpFilter;
809
810 if (This == NULL) {
811 return EFI_INVALID_PARAMETER;
812 }
813
814 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
815 Mode = Private->PxeBc.Mode;
816 BootSvrEntry = NULL;
817 SrvList = NULL;
818 CreatedInfo = NULL;
819 Status = EFI_DEVICE_ERROR;
820 Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DISCOVER;
821
822 if (!Private->AddressIsOk) {
823 return EFI_INVALID_PARAMETER;
824 }
825
826 if (!Mode->Started) {
827 return EFI_NOT_STARTED;
828 }
829
830 //
831 // Stop Udp4Read instance
832 //
833 Private->Udp4Read->Configure (Private->Udp4Read, NULL);
834
835 Mode->IcmpErrorReceived = FALSE;
836
837 //
838 // If layer isn't EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL,
839 // use the previous setting;
840 // If info isn't offered,
841 // use the cached DhcpAck and ProxyOffer packets.
842 //
843 if (*Layer != EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL) {
844
845 if (!Mode->PxeDiscoverValid || !Mode->PxeReplyReceived || (!Mode->PxeBisReplyReceived && UseBis)) {
846
847 Status = EFI_INVALID_PARAMETER;
848 goto ON_EXIT;
849 }
850
851 DefaultInfo.IpCnt = 1;
852 DefaultInfo.UseUCast = TRUE;
853
854 DefaultSrvList.Type = Type;
855 DefaultSrvList.AcceptAnyResponse = FALSE;
856 DefaultSrvList.IpAddr.Addr[0] = Private->ServerIp.Addr[0];
857
858 SrvList = &DefaultSrvList;
859 Info = &DefaultInfo;
860 } else if (Info == NULL) {
861 //
862 // Create info by the cached packet before
863 //
864 Packet = (Mode->ProxyOfferReceived) ? &Private->ProxyOffer : &Private->Dhcp4Ack;
865 VendorOpt = &Packet->PxeVendorOption;
866
867 if (!Mode->DhcpAckReceived || !IS_VALID_DISCOVER_VENDOR_OPTION (VendorOpt->BitMap)) {
868 //
869 // Address is not acquired or no discovery options.
870 //
871 Status = EFI_INVALID_PARAMETER;
872 goto ON_EXIT;
873 }
874
875 DefaultInfo.UseMCast = (BOOLEAN)!IS_DISABLE_MCAST_DISCOVER (VendorOpt->DiscoverCtrl);
876 DefaultInfo.UseBCast = (BOOLEAN)!IS_DISABLE_BCAST_DISCOVER (VendorOpt->DiscoverCtrl);
877 DefaultInfo.MustUseList = (BOOLEAN) IS_ENABLE_USE_SERVER_LIST (VendorOpt->DiscoverCtrl);
878 DefaultInfo.UseUCast = DefaultInfo.MustUseList;
879
880 if (DefaultInfo.UseMCast) {
881 //
882 // Get the multicast discover ip address from vendor option.
883 //
884 CopyMem (
885 &DefaultInfo.ServerMCastIp.Addr,
886 &VendorOpt->DiscoverMcastIp,
887 sizeof (EFI_IPv4_ADDRESS)
888 );
889 }
890
891 DefaultInfo.IpCnt = 0;
892 Info = &DefaultInfo;
893 SrvList = Info->SrvList;
894
895 if (DefaultInfo.MustUseList) {
896 BootSvrEntry = VendorOpt->BootSvr;
897 Status = EFI_INVALID_PARAMETER;
898
899 while (((UINT8) (BootSvrEntry - VendorOpt->BootSvr)) < VendorOpt->BootSvrLen) {
900
901 if (BootSvrEntry->Type == HTONS (Type)) {
902 Status = EFI_SUCCESS;
903 break;
904 }
905
906 BootSvrEntry = GET_NEXT_BOOT_SVR_ENTRY (BootSvrEntry);
907 }
908
909 if (EFI_ERROR (Status)) {
910 goto ON_EXIT;
911 }
912
913 DefaultInfo.IpCnt = BootSvrEntry->IpCnt;
914
915 if (DefaultInfo.IpCnt >= 1) {
916 CreatedInfo = AllocatePool (sizeof (DefaultInfo) + (DefaultInfo.IpCnt - 1) * sizeof (*SrvList));
917 if (CreatedInfo == NULL) {
918 Status = EFI_OUT_OF_RESOURCES;
919 goto ON_EXIT;
920
921 }
922
923 CopyMem (CreatedInfo, &DefaultInfo, sizeof (DefaultInfo));
924 Info = CreatedInfo;
925 SrvList = Info->SrvList;
926 }
927
928 for (Index = 0; Index < DefaultInfo.IpCnt; Index++) {
929 CopyMem (&SrvList[Index].IpAddr, &BootSvrEntry->IpAddr[Index], sizeof (EFI_IPv4_ADDRESS));
930 SrvList[Index].AcceptAnyResponse = FALSE;
931 SrvList[Index].Type = BootSvrEntry->Type;
932 }
933 }
934
935 } else {
936
937 SrvList = Info->SrvList;
938
939 if (!SrvList[0].AcceptAnyResponse) {
940
941 for (Index = 1; Index < Info->IpCnt; Index++) {
942 if (SrvList[Index].AcceptAnyResponse) {
943 break;
944 }
945 }
946
947 if (Index != Info->IpCnt) {
948 Status = EFI_INVALID_PARAMETER;
949 goto ON_EXIT;
950 }
951 }
952 }
953
954 if ((!Info->UseUCast && !Info->UseBCast && !Info->UseMCast) || (Info->MustUseList && Info->IpCnt == 0)) {
955
956 Status = EFI_INVALID_PARAMETER;
957 goto ON_EXIT;
958 }
959 //
960 // Execute discover by UniCast/BroadCast/MultiCast
961 //
962 if (Info->UseUCast) {
963
964 for (Index = 0; Index < Info->IpCnt; Index++) {
965
966 if (BootSvrEntry == NULL) {
967 Private->ServerIp.Addr[0] = SrvList[Index].IpAddr.Addr[0];
968 } else {
969 CopyMem (
970 &Private->ServerIp,
971 &BootSvrEntry->IpAddr[Index],
972 sizeof (EFI_IPv4_ADDRESS)
973 );
974 }
975
976 Status = PxeBcDiscvBootService (
977 Private,
978 Type,
979 Layer,
980 UseBis,
981 &SrvList[Index].IpAddr,
982 0,
983 NULL,
984 TRUE,
985 &Private->PxeReply.Packet.Ack
986 );
987 if (!EFI_ERROR (Status)) {
988 break;
989 }
990 }
991
992 } else if (Info->UseMCast) {
993
994 Status = PxeBcDiscvBootService (
995 Private,
996 Type,
997 Layer,
998 UseBis,
999 &Info->ServerMCastIp,
1000 0,
1001 NULL,
1002 TRUE,
1003 &Private->PxeReply.Packet.Ack
1004 );
1005
1006 } else if (Info->UseBCast) {
1007
1008 Status = PxeBcDiscvBootService (
1009 Private,
1010 Type,
1011 Layer,
1012 UseBis,
1013 NULL,
1014 Info->IpCnt,
1015 SrvList,
1016 TRUE,
1017 &Private->PxeReply.Packet.Ack
1018 );
1019 }
1020
1021 if (EFI_ERROR (Status) || !Mode->PxeReplyReceived || (!Mode->PxeBisReplyReceived && UseBis)) {
1022 if (Status == EFI_ICMP_ERROR) {
1023 Mode->IcmpErrorReceived = TRUE;
1024 } else {
1025 Status = EFI_DEVICE_ERROR;
1026 }
1027 goto ON_EXIT;
1028 } else {
1029 PxeBcParseCachedDhcpPacket (&Private->PxeReply);
1030 }
1031
1032 if (Mode->PxeBisReplyReceived) {
1033 CopyMem (
1034 &Private->ServerIp,
1035 &Mode->PxeReply.Dhcpv4.BootpSiAddr,
1036 sizeof (EFI_IPv4_ADDRESS)
1037 );
1038 }
1039
1040 if (CreatedInfo != NULL) {
1041 FreePool (CreatedInfo);
1042 }
1043
1044 ON_EXIT:
1045
1046 Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);
1047
1048 //
1049 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
1050 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1051 //
1052 ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));
1053 IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;
1054 This->SetIpFilter (This, &IpFilter);
1055
1056 return Status;
1057 }
1058
1059
1060 /**
1061 Used to perform TFTP and MTFTP services.
1062
1063 This function is used to perform TFTP and MTFTP services. This includes the
1064 TFTP operations to get the size of a file, read a directory, read a file, and
1065 write a file. It also includes the MTFTP operations to get the size of a file,
1066 read a directory, and read a file. The type of operation is specified by Operation.
1067 If the callback function that is invoked during the TFTP/MTFTP operation does
1068 not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will
1069 be returned.
1070 For read operations, the return data will be placed in the buffer specified by
1071 BufferPtr. If BufferSize is too small to contain the entire downloaded file,
1072 then EFI_BUFFER_TOO_SMALL will be returned and BufferSize will be set to zero
1073 or the size of the requested file (the size of the requested file is only returned
1074 if the TFTP server supports TFTP options). If BufferSize is large enough for the
1075 read operation, then BufferSize will be set to the size of the downloaded file,
1076 and EFI_SUCCESS will be returned. Applications using the PxeBc.Mtftp() services
1077 should use the get-file-size operations to determine the size of the downloaded
1078 file prior to using the read-file operations-especially when downloading large
1079 (greater than 64 MB) files-instead of making two calls to the read-file operation.
1080 Following this recommendation will save time if the file is larger than expected
1081 and the TFTP server does not support TFTP option extensions. Without TFTP option
1082 extension support, the client has to download the entire file, counting and discarding
1083 the received packets, to determine the file size.
1084 For write operations, the data to be sent is in the buffer specified by BufferPtr.
1085 BufferSize specifies the number of bytes to send. If the write operation completes
1086 successfully, then EFI_SUCCESS will be returned.
1087 For TFTP "get file size" operations, the size of the requested file or directory
1088 is returned in BufferSize, and EFI_SUCCESS will be returned. If the TFTP server
1089 does not support options, the file will be downloaded into a bit bucket and the
1090 length of the downloaded file will be returned. For MTFTP "get file size" operations,
1091 if the MTFTP server does not support the "get file size" option, EFI_UNSUPPORTED
1092 will be returned.
1093 This function can take up to 10 seconds to timeout and return control to the caller.
1094 If the TFTP sequence does not complete, EFI_TIMEOUT will be returned.
1095 If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
1096 then the TFTP sequence is stopped and EFI_ABORTED will be returned.
1097 The format of the data returned from a TFTP read directory operation is a null-terminated
1098 filename followed by a null-terminated information string, of the form
1099 "size year-month-day hour:minute:second" (i.e. %d %d-%d-%d %d:%d:%f - note that
1100 the seconds field can be a decimal number), where the date and time are UTC. For
1101 an MTFTP read directory command, there is additionally a null-terminated multicast
1102 IP address preceding the filename of the form %d.%d.%d.%d for IP v4. The final
1103 entry is itself null-terminated, so that the final information string is terminated
1104 with two null octets.
1105
1106 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1107 @param Operation The type of operation to perform.
1108 @param BufferPtr A pointer to the data buffer.
1109 @param Overwrite Only used on write file operations. TRUE if a file on a remote server can
1110 be overwritten.
1111 @param BufferSize For get-file-size operations, *BufferSize returns the size of the
1112 requested file.
1113 @param BlockSize The requested block size to be used during a TFTP transfer.
1114 @param ServerIp The TFTP / MTFTP server IP address.
1115 @param Filename A Null-terminated ASCII string that specifies a directory name or a file
1116 name.
1117 @param Info Pointer to the MTFTP information.
1118 @param DontUseBuffer Set to FALSE for normal TFTP and MTFTP read file operation.
1119
1120 @retval EFI_SUCCESS The TFTP/MTFTP operation was completed.
1121 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1122 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1123 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1124 @retval EFI_BUFFER_TOO_SMALL The buffer is not large enough to complete the read operation.
1125 @retval EFI_ABORTED The callback function aborted the TFTP/MTFTP operation.
1126 @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.
1127 @retval EFI_ICMP_ERROR An ICMP error packet was received during the MTFTP session.
1128 @retval EFI_TFTP_ERROR A TFTP error packet was received during the MTFTP session.
1129
1130 **/
1131 EFI_STATUS
1132 EFIAPI
1133 EfiPxeBcMtftp (
1134 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
1135 IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation,
1136 IN OUT VOID *BufferPtr,
1137 IN BOOLEAN Overwrite,
1138 IN OUT UINT64 *BufferSize,
1139 IN UINTN *BlockSize OPTIONAL,
1140 IN EFI_IP_ADDRESS *ServerIp,
1141 IN UINT8 *Filename,
1142 IN EFI_PXE_BASE_CODE_MTFTP_INFO *Info OPTIONAL,
1143 IN BOOLEAN DontUseBuffer
1144 )
1145 {
1146 PXEBC_PRIVATE_DATA *Private;
1147 EFI_MTFTP4_CONFIG_DATA Mtftp4Config;
1148 EFI_STATUS Status;
1149 EFI_PXE_BASE_CODE_MODE *Mode;
1150 EFI_MAC_ADDRESS TempMacAddr;
1151 EFI_PXE_BASE_CODE_IP_FILTER IpFilter;
1152
1153 if ((This == NULL) ||
1154 (Filename == NULL) ||
1155 (BufferSize == NULL) ||
1156 ((ServerIp == NULL) || !NetIp4IsUnicast (NTOHL (ServerIp->Addr[0]), 0)) ||
1157 ((BufferPtr == NULL) && DontUseBuffer) ||
1158 ((BlockSize != NULL) && (*BlockSize < 512))) {
1159
1160 return EFI_INVALID_PARAMETER;
1161 }
1162
1163 Status = EFI_DEVICE_ERROR;
1164 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
1165 Mode = &Private->Mode;
1166
1167 if (!Mode->AutoArp) {
1168 //
1169 // If AutoArp is set false, check arp cache
1170 //
1171 UpdateArpCache (This);
1172 if (!FindInArpCache (Mode, &ServerIp->v4, &TempMacAddr)) {
1173 return EFI_DEVICE_ERROR;
1174 }
1175 }
1176
1177 //
1178 // Stop Udp4Read instance
1179 //
1180 Private->Udp4Read->Configure (Private->Udp4Read, NULL);
1181
1182 Mode->TftpErrorReceived = FALSE;
1183 Mode->IcmpErrorReceived = FALSE;
1184
1185 Mtftp4Config.UseDefaultSetting = FALSE;
1186 Mtftp4Config.TimeoutValue = PXEBC_MTFTP_TIMEOUT;
1187 Mtftp4Config.TryCount = PXEBC_MTFTP_RETRIES;
1188
1189 CopyMem (
1190 &Mtftp4Config.StationIp,
1191 &Private->StationIp,
1192 sizeof (EFI_IPv4_ADDRESS)
1193 );
1194 CopyMem (
1195 &Mtftp4Config.SubnetMask,
1196 &Private->SubnetMask,
1197 sizeof (EFI_IPv4_ADDRESS)
1198 );
1199 CopyMem (
1200 &Mtftp4Config.GatewayIp,
1201 &Private->GatewayIp,
1202 sizeof (EFI_IPv4_ADDRESS)
1203 );
1204 CopyMem (
1205 &Mtftp4Config.ServerIp,
1206 ServerIp,
1207 sizeof (EFI_IPv4_ADDRESS)
1208 );
1209
1210 switch (Operation) {
1211
1212 case EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE:
1213
1214 Status = PxeBcTftpGetFileSize (
1215 Private,
1216 &Mtftp4Config,
1217 Filename,
1218 BlockSize,
1219 BufferSize
1220 );
1221
1222 break;
1223
1224 case EFI_PXE_BASE_CODE_TFTP_READ_FILE:
1225
1226 Status = PxeBcTftpReadFile (
1227 Private,
1228 &Mtftp4Config,
1229 Filename,
1230 BlockSize,
1231 BufferPtr,
1232 BufferSize,
1233 DontUseBuffer
1234 );
1235
1236 break;
1237
1238 case EFI_PXE_BASE_CODE_TFTP_WRITE_FILE:
1239
1240 Status = PxeBcTftpWriteFile (
1241 Private,
1242 &Mtftp4Config,
1243 Filename,
1244 Overwrite,
1245 BlockSize,
1246 BufferPtr,
1247 BufferSize
1248 );
1249
1250 break;
1251
1252 case EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY:
1253
1254 Status = PxeBcTftpReadDirectory (
1255 Private,
1256 &Mtftp4Config,
1257 Filename,
1258 BlockSize,
1259 BufferPtr,
1260 BufferSize,
1261 DontUseBuffer
1262 );
1263
1264 break;
1265
1266 case EFI_PXE_BASE_CODE_MTFTP_GET_FILE_SIZE:
1267 case EFI_PXE_BASE_CODE_MTFTP_READ_FILE:
1268 case EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY:
1269 Status = EFI_UNSUPPORTED;
1270 break;
1271
1272 default:
1273
1274 Status = EFI_INVALID_PARAMETER;
1275 break;
1276 }
1277
1278 if (Status == EFI_ICMP_ERROR) {
1279 Mode->IcmpErrorReceived = TRUE;
1280 }
1281
1282 if (EFI_ERROR (Status)) {
1283 goto ON_EXIT;
1284 }
1285
1286 ON_EXIT:
1287 Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);
1288 //
1289 // Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP
1290 // receive filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1291 //
1292 ZeroMem(&IpFilter, sizeof (EFI_PXE_BASE_CODE_IP_FILTER));
1293 IpFilter.Filters = EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP;
1294 This->SetIpFilter (This, &IpFilter);
1295
1296 return Status;
1297 }
1298
1299
1300 /**
1301 Writes a UDP packet to the network interface.
1302
1303 This function writes a UDP packet specified by the (optional HeaderPtr and)
1304 BufferPtr parameters to the network interface. The UDP header is automatically
1305 built by this routine. It uses the parameters OpFlags, DestIp, DestPort, GatewayIp,
1306 SrcIp, and SrcPort to build this header. If the packet is successfully built and
1307 transmitted through the network interface, then EFI_SUCCESS will be returned.
1308 If a timeout occurs during the transmission of the packet, then EFI_TIMEOUT will
1309 be returned. If an ICMP error occurs during the transmission of the packet, then
1310 the IcmpErrorReceived field is set to TRUE, the IcmpError field is filled in and
1311 EFI_ICMP_ERROR will be returned. If the Callback Protocol does not return
1312 EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will be returned.
1313
1314 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1315 @param OpFlags The UDP operation flags.
1316 @param DestIp The destination IP address.
1317 @param DestPort The destination UDP port number.
1318 @param GatewayIp The gateway IP address.
1319 @param SrcIp The source IP address.
1320 @param SrcPort The source UDP port number.
1321 @param HeaderSize An optional field which may be set to the length of a header at
1322 HeaderPtr to be prefixed to the data at BufferPtr.
1323 @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the
1324 data at BufferPtr.
1325 @param BufferSize A pointer to the size of the data at BufferPtr.
1326 @param BufferPtr A pointer to the data to be written.
1327
1328 @retval EFI_SUCCESS The UDP Write operation was completed.
1329 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1330 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1331 @retval EFI_BAD_BUFFER_SIZE The buffer is too long to be transmitted.
1332 @retval EFI_ABORTED The callback function aborted the UDP Write operation.
1333 @retval EFI_TIMEOUT The UDP Write operation timed out.
1334 @retval EFI_ICMP_ERROR An ICMP error packet was received during the UDP write session.
1335
1336 **/
1337 EFI_STATUS
1338 EFIAPI
1339 EfiPxeBcUdpWrite (
1340 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
1341 IN UINT16 OpFlags,
1342 IN EFI_IP_ADDRESS *DestIp,
1343 IN EFI_PXE_BASE_CODE_UDP_PORT *DestPort,
1344 IN EFI_IP_ADDRESS *GatewayIp OPTIONAL,
1345 IN EFI_IP_ADDRESS *SrcIp OPTIONAL,
1346 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,
1347 IN UINTN *HeaderSize OPTIONAL,
1348 IN VOID *HeaderPtr OPTIONAL,
1349 IN UINTN *BufferSize,
1350 IN VOID *BufferPtr
1351 )
1352 {
1353 PXEBC_PRIVATE_DATA *Private;
1354 EFI_UDP4_PROTOCOL *Udp4;
1355 EFI_UDP4_COMPLETION_TOKEN Token;
1356 EFI_UDP4_TRANSMIT_DATA *Udp4TxData;
1357 UINT32 FragCount;
1358 UINT32 DataLength;
1359 EFI_UDP4_SESSION_DATA Udp4Session;
1360 EFI_STATUS Status;
1361 BOOLEAN IsDone;
1362 EFI_PXE_BASE_CODE_MODE *Mode;
1363 EFI_MAC_ADDRESS TempMacAddr;
1364
1365 IsDone = FALSE;
1366
1367 if ((This == NULL) || (DestIp == NULL) || (DestPort == NULL)) {
1368 return EFI_INVALID_PARAMETER;
1369 }
1370
1371 if ((GatewayIp != NULL) && !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]), 0)) {
1372 //
1373 // Gateway is provided but it's not a unicast IP address.
1374 //
1375 return EFI_INVALID_PARAMETER;
1376 }
1377
1378 if ((HeaderSize != NULL) && ((*HeaderSize == 0) || (HeaderPtr == NULL))) {
1379 //
1380 // The HeaderSize ptr isn't NULL and: 1. the value is zero; or 2. the HeaderPtr
1381 // is NULL.
1382 //
1383 return EFI_INVALID_PARAMETER;
1384 }
1385
1386 if ((BufferSize == NULL) || ((*BufferSize != 0) && (BufferPtr == NULL))) {
1387 return EFI_INVALID_PARAMETER;
1388 }
1389
1390 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
1391 Udp4 = Private->Udp4Write;
1392 Mode = &Private->Mode;
1393 if (!Mode->Started) {
1394 return EFI_NOT_STARTED;
1395 }
1396
1397 if (!Private->AddressIsOk && (SrcIp == NULL)) {
1398 return EFI_INVALID_PARAMETER;
1399 }
1400
1401 if (!Mode->AutoArp) {
1402 //
1403 // If AutoArp is set false, check arp cache
1404 //
1405 UpdateArpCache (This);
1406 if (!FindInArpCache (Mode, &DestIp->v4, &TempMacAddr)) {
1407 return EFI_DEVICE_ERROR;
1408 }
1409 }
1410
1411 Mode->IcmpErrorReceived = FALSE;
1412
1413 if ((Private->CurrentUdpSrcPort == 0) ||
1414 ((SrcPort != NULL) && (*SrcPort != Private->CurrentUdpSrcPort))) {
1415 //
1416 // Port is changed, (re)configure the Udp4Write instance
1417 //
1418 if (SrcPort != NULL) {
1419 Private->CurrentUdpSrcPort = *SrcPort;
1420 }
1421 }
1422
1423 Status = PxeBcConfigureUdpWriteInstance (
1424 Udp4,
1425 &Private->StationIp.v4,
1426 &Private->SubnetMask.v4,
1427 &Private->GatewayIp.v4,
1428 &Private->CurrentUdpSrcPort
1429 );
1430 if (EFI_ERROR (Status)) {
1431 Private->CurrentUdpSrcPort = 0;
1432 return EFI_INVALID_PARAMETER;
1433 }
1434
1435 ZeroMem (&Token, sizeof (EFI_UDP4_COMPLETION_TOKEN));
1436 ZeroMem (&Udp4Session, sizeof (EFI_UDP4_SESSION_DATA));
1437
1438 CopyMem (&Udp4Session.DestinationAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));
1439 Udp4Session.DestinationPort = *DestPort;
1440 if (SrcIp != NULL) {
1441 CopyMem (&Udp4Session.SourceAddress, SrcIp, sizeof (EFI_IPv4_ADDRESS));
1442 }
1443 if (SrcPort != NULL) {
1444 Udp4Session.SourcePort = *SrcPort;
1445 }
1446
1447 FragCount = (HeaderSize != NULL) ? 2 : 1;
1448 Udp4TxData = (EFI_UDP4_TRANSMIT_DATA *) AllocateZeroPool (sizeof (EFI_UDP4_TRANSMIT_DATA) + (FragCount - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA));
1449 if (Udp4TxData == NULL) {
1450 return EFI_OUT_OF_RESOURCES;
1451 }
1452
1453 Udp4TxData->FragmentCount = FragCount;
1454 Udp4TxData->FragmentTable[FragCount - 1].FragmentLength = (UINT32) *BufferSize;
1455 Udp4TxData->FragmentTable[FragCount - 1].FragmentBuffer = BufferPtr;
1456 DataLength = (UINT32) *BufferSize;
1457
1458 if (FragCount == 2) {
1459
1460 Udp4TxData->FragmentTable[0].FragmentLength = (UINT32) *HeaderSize;
1461 Udp4TxData->FragmentTable[0].FragmentBuffer = HeaderPtr;
1462 DataLength += (UINT32) *HeaderSize;
1463 }
1464
1465 if (GatewayIp != NULL) {
1466 Udp4TxData->GatewayAddress = (EFI_IPv4_ADDRESS *) GatewayIp;
1467 }
1468 Udp4TxData->UdpSessionData = &Udp4Session;
1469 Udp4TxData->DataLength = DataLength;
1470 Token.Packet.TxData = Udp4TxData;
1471
1472 Status = gBS->CreateEvent (
1473 EVT_NOTIFY_SIGNAL,
1474 TPL_NOTIFY,
1475 PxeBcCommonNotify,
1476 &IsDone,
1477 &Token.Event
1478 );
1479 if (EFI_ERROR (Status)) {
1480 goto ON_EXIT;
1481 }
1482
1483 Status = Udp4->Transmit (Udp4, &Token);
1484 if (EFI_ERROR (Status)) {
1485 if (Status == EFI_ICMP_ERROR) {
1486 Mode->IcmpErrorReceived = TRUE;
1487 }
1488 goto ON_EXIT;
1489 }
1490
1491 while (!IsDone) {
1492
1493 Udp4->Poll (Udp4);
1494 }
1495
1496 Status = Token.Status;
1497
1498 ON_EXIT:
1499
1500 if (Token.Event != NULL) {
1501 gBS->CloseEvent (Token.Event);
1502 }
1503
1504 FreePool (Udp4TxData);
1505
1506 //
1507 // Reset the instance.
1508 //
1509 Udp4->Configure (Udp4, NULL);
1510 return Status;
1511 }
1512
1513 /**
1514 Decide whether the incoming UDP packet is acceptable per IP filter settings
1515 in provided PxeBcMode.
1516
1517 @param PxeBcMode Pointer to EFI_PXE_BASE_CODE_MODE.
1518 @param Session Received UDP session.
1519
1520 @retval TRUE The UDP package matches IP filters.
1521 @retval FALSE The UDP package doesn't matches IP filters.
1522
1523 **/
1524 BOOLEAN
1525 CheckIpByFilter (
1526 IN EFI_PXE_BASE_CODE_MODE *PxeBcMode,
1527 IN EFI_UDP4_SESSION_DATA *Session
1528 )
1529 {
1530 UINTN Index;
1531 EFI_IPv4_ADDRESS Ip4Address;
1532 EFI_IPv4_ADDRESS DestIp4Address;
1533
1534 if ((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS) != 0) {
1535 return TRUE;
1536 }
1537
1538 CopyMem (&DestIp4Address, &Session->DestinationAddress, sizeof (DestIp4Address));
1539 if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST) != 0) &&
1540 IP4_IS_MULTICAST (EFI_NTOHL (DestIp4Address))
1541 ) {
1542 return TRUE;
1543 }
1544
1545 if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST) != 0) &&
1546 IP4_IS_LOCAL_BROADCAST (EFI_NTOHL (DestIp4Address))
1547 ) {
1548 return TRUE;
1549 }
1550
1551 CopyMem (&Ip4Address, &PxeBcMode->StationIp.v4, sizeof (Ip4Address));
1552 if (((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0) &&
1553 EFI_IP4_EQUAL (&Ip4Address, &DestIp4Address)
1554 ) {
1555 return TRUE;
1556 }
1557
1558 ASSERT (PxeBcMode->IpFilter.IpCnt < EFI_PXE_BASE_CODE_MAX_IPCNT);
1559
1560 for (Index = 0; Index < PxeBcMode->IpFilter.IpCnt; Index++) {
1561 CopyMem (
1562 &Ip4Address,
1563 &PxeBcMode->IpFilter.IpList[Index].v4,
1564 sizeof (Ip4Address)
1565 );
1566 if (EFI_IP4_EQUAL (&Ip4Address, &DestIp4Address)) {
1567 return TRUE;
1568 }
1569 }
1570
1571 return FALSE;
1572 }
1573
1574 /**
1575 Reads a UDP packet from the network interface.
1576
1577 This function reads a UDP packet from a network interface. The data contents
1578 are returned in (the optional HeaderPtr and) BufferPtr, and the size of the
1579 buffer received is returned in BufferSize . If the input BufferSize is smaller
1580 than the UDP packet received (less optional HeaderSize), it will be set to the
1581 required size, and EFI_BUFFER_TOO_SMALL will be returned. In this case, the
1582 contents of BufferPtr are undefined, and the packet is lost. If a UDP packet is
1583 successfully received, then EFI_SUCCESS will be returned, and the information
1584 from the UDP header will be returned in DestIp, DestPort, SrcIp, and SrcPort if
1585 they are not NULL. Depending on the values of OpFlags and the DestIp, DestPort,
1586 SrcIp, and SrcPort input values, different types of UDP packet receive filtering
1587 will be performed. The following tables summarize these receive filter operations.
1588
1589 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1590 @param OpFlags The UDP operation flags.
1591 @param DestIp The destination IP address.
1592 @param DestPort The destination UDP port number.
1593 @param SrcIp The source IP address.
1594 @param SrcPort The source UDP port number.
1595 @param HeaderSize An optional field which may be set to the length of a header at
1596 HeaderPtr to be prefixed to the data at BufferPtr.
1597 @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the
1598 data at BufferPtr.
1599 @param BufferSize A pointer to the size of the data at BufferPtr.
1600 @param BufferPtr A pointer to the data to be read.
1601
1602 @retval EFI_SUCCESS The UDP Read operation was completed.
1603 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1604 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1605 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
1606 @retval EFI_BUFFER_TOO_SMALL The packet is larger than Buffer can hold.
1607 @retval EFI_ABORTED The callback function aborted the UDP Read operation.
1608 @retval EFI_TIMEOUT The UDP Read operation timed out.
1609
1610 **/
1611 EFI_STATUS
1612 EFIAPI
1613 EfiPxeBcUdpRead (
1614 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
1615 IN UINT16 OpFlags,
1616 IN OUT EFI_IP_ADDRESS *DestIp OPTIONAL,
1617 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort OPTIONAL,
1618 IN OUT EFI_IP_ADDRESS *SrcIp OPTIONAL,
1619 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,
1620 IN UINTN *HeaderSize OPTIONAL,
1621 IN VOID *HeaderPtr OPTIONAL,
1622 IN OUT UINTN *BufferSize,
1623 IN VOID *BufferPtr
1624 )
1625 {
1626 PXEBC_PRIVATE_DATA *Private;
1627 EFI_PXE_BASE_CODE_MODE *Mode;
1628 EFI_UDP4_PROTOCOL *Udp4;
1629 EFI_UDP4_COMPLETION_TOKEN Token;
1630 EFI_UDP4_RECEIVE_DATA *RxData;
1631 EFI_UDP4_SESSION_DATA *Session;
1632 EFI_STATUS Status;
1633 BOOLEAN IsDone;
1634 BOOLEAN Matched;
1635 UINTN CopiedLen;
1636 UINTN HeaderLen;
1637 UINTN HeaderCopiedLen;
1638 UINTN BufferCopiedLen;
1639 UINT32 FragmentLength;
1640 UINTN FragmentIndex;
1641 UINT8 *FragmentBuffer;
1642
1643 if (This == NULL || DestIp == NULL || DestPort == NULL) {
1644 return EFI_INVALID_PARAMETER;
1645 }
1646
1647 if (((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) == 0 && (DestPort == NULL)) ||
1648 ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) == 0 && (SrcIp == NULL)) ||
1649 ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) == 0 && (SrcPort == NULL))) {
1650 return EFI_INVALID_PARAMETER;
1651 }
1652
1653 if (((HeaderSize != NULL) && (*HeaderSize == 0)) || ((HeaderSize != NULL) && (HeaderPtr == NULL))) {
1654 return EFI_INVALID_PARAMETER;
1655 }
1656
1657 if ((BufferSize == NULL) || (BufferPtr == NULL)) {
1658 return EFI_INVALID_PARAMETER;
1659 }
1660
1661 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
1662 Mode = Private->PxeBc.Mode;
1663 Udp4 = Private->Udp4Read;
1664
1665 if (!Mode->Started) {
1666 return EFI_NOT_STARTED;
1667 }
1668
1669 Mode->IcmpErrorReceived = FALSE;
1670
1671 Status = gBS->CreateEvent (
1672 EVT_NOTIFY_SIGNAL,
1673 TPL_NOTIFY,
1674 PxeBcCommonNotify,
1675 &IsDone,
1676 &Token.Event
1677 );
1678 if (EFI_ERROR (Status)) {
1679 return EFI_OUT_OF_RESOURCES;
1680 }
1681
1682 TRY_AGAIN:
1683
1684 IsDone = FALSE;
1685 Status = Udp4->Receive (Udp4, &Token);
1686 if (EFI_ERROR (Status)) {
1687 if (Status == EFI_ICMP_ERROR) {
1688 Mode->IcmpErrorReceived = TRUE;
1689 }
1690 goto ON_EXIT;
1691 }
1692
1693 Udp4->Poll (Udp4);
1694
1695 if (!IsDone) {
1696 Status = EFI_TIMEOUT;
1697 } else {
1698
1699 //
1700 // check whether this packet matches the filters
1701 //
1702 if (EFI_ERROR (Token.Status)){
1703 goto ON_EXIT;
1704 }
1705
1706 RxData = Token.Packet.RxData;
1707 Session = &RxData->UdpSession;
1708
1709 Matched = TRUE;
1710
1711 if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER) != 0) {
1712 Matched = FALSE;
1713 //
1714 // Check UDP package by IP filter settings
1715 //
1716 if (CheckIpByFilter (Mode, Session)) {
1717 Matched = TRUE;
1718 }
1719 }
1720
1721 if (Matched) {
1722 Matched = FALSE;
1723
1724 //
1725 // Match the destination ip of the received udp dgram
1726 //
1727 if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP) != 0) {
1728 Matched = TRUE;
1729
1730 if (DestIp != NULL) {
1731 CopyMem (DestIp, &Session->DestinationAddress, sizeof (EFI_IPv4_ADDRESS));
1732 }
1733 } else {
1734 if (DestIp != NULL) {
1735 if (EFI_IP4_EQUAL (DestIp, &Session->DestinationAddress)) {
1736 Matched = TRUE;
1737 }
1738 } else {
1739 if (EFI_IP4_EQUAL (&Private->StationIp, &Session->DestinationAddress)) {
1740 Matched = TRUE;
1741 }
1742 }
1743 }
1744 }
1745
1746 if (Matched) {
1747 //
1748 // Match the destination port of the received udp dgram
1749 //
1750 if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) != 0) {
1751
1752 if (DestPort != NULL) {
1753 *DestPort = Session->DestinationPort;
1754 }
1755 } else {
1756
1757 if (*DestPort != Session->DestinationPort) {
1758 Matched = FALSE;
1759 }
1760 }
1761 }
1762
1763 if (Matched) {
1764 //
1765 // Match the source ip of the received udp dgram
1766 //
1767 if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP) != 0) {
1768
1769 if (SrcIp != NULL) {
1770 CopyMem (SrcIp, &Session->SourceAddress, sizeof (EFI_IPv4_ADDRESS));
1771 }
1772 } else {
1773
1774 if (!EFI_IP4_EQUAL (SrcIp, &Session->SourceAddress)) {
1775 Matched = FALSE;
1776 }
1777 }
1778 }
1779
1780 if (Matched) {
1781 //
1782 // Match the source port of the received udp dgram
1783 //
1784 if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) != 0) {
1785
1786 if (SrcPort != NULL) {
1787 *SrcPort = Session->SourcePort;
1788 }
1789 } else {
1790
1791 if (*SrcPort != Session->SourcePort) {
1792 Matched = FALSE;
1793 }
1794 }
1795 }
1796
1797 if (Matched) {
1798 ASSERT (RxData != NULL);
1799
1800 HeaderLen = 0;
1801 if (HeaderSize != NULL) {
1802 HeaderLen = MIN (*HeaderSize, RxData->DataLength);
1803 }
1804
1805 if (RxData->DataLength - HeaderLen > *BufferSize) {
1806 Status = EFI_BUFFER_TOO_SMALL;
1807 } else {
1808 *HeaderSize = HeaderLen;
1809 *BufferSize = RxData->DataLength - HeaderLen;
1810
1811 HeaderCopiedLen = 0;
1812 BufferCopiedLen = 0;
1813 for (FragmentIndex = 0; FragmentIndex < RxData->FragmentCount; FragmentIndex++) {
1814 FragmentLength = RxData->FragmentTable[FragmentIndex].FragmentLength;
1815 FragmentBuffer = RxData->FragmentTable[FragmentIndex].FragmentBuffer;
1816 if (HeaderCopiedLen + FragmentLength < HeaderLen) {
1817 //
1818 // Copy the header part of received data.
1819 //
1820 CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer, FragmentLength);
1821 HeaderCopiedLen += FragmentLength;
1822 } else if (HeaderCopiedLen < HeaderLen) {
1823 //
1824 // Copy the header part of received data.
1825 //
1826 CopiedLen = HeaderLen - HeaderCopiedLen;
1827 CopyMem ((UINT8 *) HeaderPtr + HeaderCopiedLen, FragmentBuffer, CopiedLen);
1828 HeaderCopiedLen += CopiedLen;
1829
1830 //
1831 // Copy the other part of received data.
1832 //
1833 CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer + CopiedLen, FragmentLength - CopiedLen);
1834 BufferCopiedLen += (FragmentLength - CopiedLen);
1835 } else {
1836 //
1837 // Copy the other part of received data.
1838 //
1839 CopyMem ((UINT8 *) BufferPtr + BufferCopiedLen, FragmentBuffer, FragmentLength);
1840 BufferCopiedLen += FragmentLength;
1841 }
1842 }
1843 }
1844 } else {
1845
1846 Status = EFI_TIMEOUT;
1847 }
1848
1849 //
1850 // Recycle the RxData
1851 //
1852 gBS->SignalEvent (RxData->RecycleSignal);
1853
1854 if (!Matched) {
1855 goto TRY_AGAIN;
1856 }
1857 }
1858
1859 ON_EXIT:
1860
1861 Udp4->Cancel (Udp4, &Token);
1862
1863 gBS->CloseEvent (Token.Event);
1864
1865 return Status;
1866 }
1867
1868 /**
1869 Updates the IP receive filters of a network device and enables software filtering.
1870
1871 The NewFilter field is used to modify the network device's current IP receive
1872 filter settings and to enable a software filter. This function updates the IpFilter
1873 field of the EFI_PXE_BASE_CODE_MODE structure with the contents of NewIpFilter.
1874 The software filter is used when the USE_FILTER in OpFlags is set to UdpRead().
1875 The current hardware filter remains in effect no matter what the settings of OpFlags
1876 are, so that the meaning of ANY_DEST_IP set in OpFlags to UdpRead() is from those
1877 packets whose reception is enabled in hardware-physical NIC address (unicast),
1878 broadcast address, logical address or addresses (multicast), or all (promiscuous).
1879 UdpRead() does not modify the IP filter settings.
1880 Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP receive
1881 filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.
1882 If an application or driver wishes to preserve the IP receive filter settings,
1883 it will have to preserve the IP receive filter settings before these calls, and
1884 use SetIpFilter() to restore them after the calls. If incompatible filtering is
1885 requested (for example, PROMISCUOUS with anything else) or if the device does not
1886 support a requested filter setting and it cannot be accommodated in software
1887 (for example, PROMISCUOUS not supported), EFI_INVALID_PARAMETER will be returned.
1888 The IPlist field is used to enable IPs other than the StationIP. They may be
1889 multicast or unicast. If IPcnt is set as well as EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP,
1890 then both the StationIP and the IPs from the IPlist will be used.
1891
1892 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
1893 @param NewFilter Pointer to the new set of IP receive filters.
1894
1895 @retval EFI_SUCCESS The IP receive filter settings were updated.
1896 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
1897 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
1898
1899 **/
1900 EFI_STATUS
1901 EFIAPI
1902 EfiPxeBcSetIpFilter (
1903 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
1904 IN EFI_PXE_BASE_CODE_IP_FILTER *NewFilter
1905 )
1906 {
1907 EFI_STATUS Status;
1908 PXEBC_PRIVATE_DATA *Private;
1909 EFI_PXE_BASE_CODE_MODE *Mode;
1910 UINTN Index;
1911 EFI_UDP4_CONFIG_DATA *Udp4Cfg;
1912 BOOLEAN PromiscuousNeed;
1913 BOOLEAN AcceptPromiscuous;
1914 BOOLEAN AcceptBroadcast;
1915 BOOLEAN MultiCastUpdate;
1916
1917 if (This == NULL) {
1918 DEBUG ((EFI_D_ERROR, "This == NULL.\n"));
1919 return EFI_INVALID_PARAMETER;
1920 }
1921
1922 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
1923 Mode = Private->PxeBc.Mode;
1924
1925 if (NewFilter == NULL) {
1926 DEBUG ((EFI_D_ERROR, "NewFilter == NULL.\n"));
1927 return EFI_INVALID_PARAMETER;
1928 }
1929
1930 if (NewFilter->IpCnt > EFI_PXE_BASE_CODE_MAX_IPCNT) {
1931 DEBUG ((EFI_D_ERROR, "NewFilter->IpCnt > %d.\n", EFI_PXE_BASE_CODE_MAX_IPCNT));
1932 return EFI_INVALID_PARAMETER;
1933 }
1934
1935 if (!Mode->Started) {
1936 DEBUG ((EFI_D_ERROR, "BC was not started.\n"));
1937 return EFI_NOT_STARTED;
1938 }
1939
1940 if (Mode->UsingIpv6) {
1941 DEBUG ((EFI_D_ERROR, "This driver is PXE for IPv4 Only.\n"));
1942 return EFI_INVALID_PARAMETER;
1943 }
1944
1945 PromiscuousNeed = FALSE;
1946
1947 for (Index = 0; Index < NewFilter->IpCnt; ++Index) {
1948 if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (NewFilter->IpList[Index].v4))) {
1949 //
1950 // The IP is a broadcast address.
1951 //
1952 DEBUG ((EFI_D_ERROR, "There is broadcast address in NewFilter.\n"));
1953 return EFI_INVALID_PARAMETER;
1954 }
1955 if (NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), 0) &&
1956 ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0)
1957 ) {
1958 //
1959 // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList,
1960 // promiscuous mode is needed.
1961 //
1962 PromiscuousNeed = TRUE;
1963 }
1964 }
1965
1966 AcceptPromiscuous = FALSE;
1967 AcceptBroadcast = FALSE;
1968 MultiCastUpdate = FALSE;
1969
1970 if (PromiscuousNeed ||
1971 ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS) != 0) ||
1972 ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST) != 0)
1973 ) {
1974 //
1975 // Configure the udp4 filter to receive all packages.
1976 //
1977 AcceptPromiscuous = TRUE;
1978 } else if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST) != 0) {
1979 //
1980 // Configure the udp4 filter to receive all broadcast packages.
1981 //
1982 AcceptBroadcast = TRUE;
1983 }
1984
1985 //
1986 // In multicast condition when Promiscuous FALSE and IpCnt no-zero.
1987 // Here check if there is any update of the multicast ip address. If yes,
1988 // we need leave the old multicast group (by Config UDP instance to NULL),
1989 // and join the new multicast group.
1990 //
1991 if (!AcceptPromiscuous) {
1992 if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0) {
1993 if (Mode->IpFilter.IpCnt != NewFilter->IpCnt) {
1994 MultiCastUpdate = TRUE;
1995 } else if (CompareMem (Mode->IpFilter.IpList, NewFilter->IpList, NewFilter->IpCnt * sizeof (EFI_IP_ADDRESS)) != 0 ) {
1996 MultiCastUpdate = TRUE;
1997 }
1998 }
1999 }
2000
2001 //
2002 // Check whether we need reconfigure the UDP instance.
2003 //
2004 Udp4Cfg = &Private->Udp4CfgData;
2005 if ((AcceptPromiscuous != Udp4Cfg->AcceptPromiscuous) ||
2006 (AcceptBroadcast != Udp4Cfg->AcceptBroadcast) || MultiCastUpdate) {
2007 //
2008 // Clear the UDP instance configuration, all joined groups will be left
2009 // during the operation.
2010 //
2011 Private->Udp4Read->Configure (Private->Udp4Read, NULL);
2012
2013 //
2014 // Configure the UDP instance with the new configuration.
2015 //
2016 Udp4Cfg->AcceptPromiscuous = AcceptPromiscuous;
2017 Udp4Cfg->AcceptBroadcast = AcceptBroadcast;
2018 Status = Private->Udp4Read->Configure (Private->Udp4Read, Udp4Cfg);
2019 if (EFI_ERROR (Status)) {
2020 return Status;
2021 }
2022
2023 //
2024 // In not Promiscuous mode, need to join the new multicast group.
2025 //
2026 if (!AcceptPromiscuous) {
2027 for (Index = 0; Index < NewFilter->IpCnt; ++Index) {
2028 if (IP4_IS_MULTICAST (EFI_NTOHL (NewFilter->IpList[Index].v4))) {
2029 //
2030 // Join the mutilcast group.
2031 //
2032 Status = Private->Udp4Read->Groups (Private->Udp4Read, TRUE, &NewFilter->IpList[Index].v4);
2033 if (EFI_ERROR (Status)) {
2034 return Status;
2035 }
2036 }
2037 }
2038 }
2039 }
2040
2041
2042 //
2043 // Save the new filter.
2044 //
2045 CopyMem (&Mode->IpFilter, NewFilter, sizeof (Mode->IpFilter));
2046
2047 return EFI_SUCCESS;
2048 }
2049
2050
2051 /**
2052 Uses the ARP protocol to resolve a MAC address.
2053
2054 This function uses the ARP protocol to resolve a MAC address. The UsingIpv6 field
2055 of the EFI_PXE_BASE_CODE_MODE structure is used to determine if IPv4 or IPv6
2056 addresses are being used. The IP address specified by IpAddr is used to resolve
2057 a MAC address. If the ARP protocol succeeds in resolving the specified address,
2058 then the ArpCacheEntries and ArpCache fields of the EFI_PXE_BASE_CODE_MODE structure
2059 are updated, and EFI_SUCCESS is returned. If MacAddr is not NULL, the resolved
2060 MAC address is placed there as well. If the PXE Base Code protocol is in the
2061 stopped state, then EFI_NOT_STARTED is returned. If the ARP protocol encounters
2062 a timeout condition while attempting to resolve an address, then EFI_TIMEOUT is
2063 returned. If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,
2064 then EFI_ABORTED is returned.
2065
2066 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2067 @param IpAddr Pointer to the IP address that is used to resolve a MAC address.
2068 @param MacAddr If not NULL, a pointer to the MAC address that was resolved with the
2069 ARP protocol.
2070
2071 @retval EFI_SUCCESS The IP or MAC address was resolved.
2072 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2073 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2074 @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.
2075 @retval EFI_ICMP_ERROR Something error occur with the ICMP packet message.
2076
2077 **/
2078 EFI_STATUS
2079 EFIAPI
2080 EfiPxeBcArp (
2081 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
2082 IN EFI_IP_ADDRESS * IpAddr,
2083 IN EFI_MAC_ADDRESS * MacAddr OPTIONAL
2084 )
2085 {
2086 PXEBC_PRIVATE_DATA *Private;
2087 EFI_PXE_BASE_CODE_MODE *Mode;
2088 EFI_STATUS Status;
2089 EFI_MAC_ADDRESS TempMacAddr;
2090
2091 if (This == NULL || IpAddr == NULL) {
2092 return EFI_INVALID_PARAMETER;
2093 }
2094
2095 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
2096 Mode = Private->PxeBc.Mode;
2097
2098 if (!Mode->Started) {
2099 return EFI_NOT_STARTED;
2100 }
2101
2102 if (!Private->AddressIsOk || Mode->UsingIpv6) {
2103 //
2104 // We can't resolve the IP address if we don't have a local address now.
2105 // Don't have ARP for IPv6.
2106 //
2107 return EFI_INVALID_PARAMETER;
2108 }
2109
2110 Mode->IcmpErrorReceived = FALSE;
2111
2112 if (!Mode->AutoArp) {
2113 //
2114 // If AutoArp is set false, check arp cache
2115 //
2116 UpdateArpCache (This);
2117 if (!FindInArpCache (Mode, &IpAddr->v4, &TempMacAddr)) {
2118 return EFI_DEVICE_ERROR;
2119 }
2120 } else {
2121 Status = Private->Arp->Request (Private->Arp, &IpAddr->v4, NULL, &TempMacAddr);
2122 if (EFI_ERROR (Status)) {
2123 if (Status == EFI_ICMP_ERROR) {
2124 Mode->IcmpErrorReceived = TRUE;
2125 }
2126 return Status;
2127 }
2128 }
2129
2130 if (MacAddr != NULL) {
2131 CopyMem (MacAddr, &TempMacAddr, sizeof (EFI_MAC_ADDRESS));
2132 }
2133
2134 return EFI_SUCCESS;
2135 }
2136
2137 /**
2138 Updates the parameters that affect the operation of the PXE Base Code Protocol.
2139
2140 This function sets parameters that affect the operation of the PXE Base Code Protocol.
2141 The parameter specified by NewAutoArp is used to control the generation of ARP
2142 protocol packets. If NewAutoArp is TRUE, then ARP Protocol packets will be generated
2143 as required by the PXE Base Code Protocol. If NewAutoArp is FALSE, then no ARP
2144 Protocol packets will be generated. In this case, the only mappings that are
2145 available are those stored in the ArpCache of the EFI_PXE_BASE_CODE_MODE structure.
2146 If there are not enough mappings in the ArpCache to perform a PXE Base Code Protocol
2147 service, then the service will fail. This function updates the AutoArp field of
2148 the EFI_PXE_BASE_CODE_MODE structure to NewAutoArp.
2149 The SetParameters() call must be invoked after a Callback Protocol is installed
2150 to enable the use of callbacks.
2151
2152 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2153 @param NewAutoArp If not NULL, a pointer to a value that specifies whether to replace the
2154 current value of AutoARP.
2155 @param NewSendGUID If not NULL, a pointer to a value that specifies whether to replace the
2156 current value of SendGUID.
2157 @param NewTTL If not NULL, a pointer to be used in place of the current value of TTL,
2158 the "time to live" field of the IP header.
2159 @param NewToS If not NULL, a pointer to be used in place of the current value of ToS,
2160 the "type of service" field of the IP header.
2161 @param NewMakeCallback If not NULL, a pointer to a value that specifies whether to replace the
2162 current value of the MakeCallback field of the Mode structure.
2163
2164 @retval EFI_SUCCESS The new parameters values were updated.
2165 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2166 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2167
2168 **/
2169 EFI_STATUS
2170 EFIAPI
2171 EfiPxeBcSetParameters (
2172 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
2173 IN BOOLEAN *NewAutoArp OPTIONAL,
2174 IN BOOLEAN *NewSendGUID OPTIONAL,
2175 IN UINT8 *NewTTL OPTIONAL,
2176 IN UINT8 *NewToS OPTIONAL,
2177 IN BOOLEAN *NewMakeCallback // OPTIONAL
2178 )
2179 {
2180 PXEBC_PRIVATE_DATA *Private;
2181 EFI_PXE_BASE_CODE_MODE *Mode;
2182 EFI_STATUS Status;
2183
2184 Status = EFI_SUCCESS;
2185
2186 if (This == NULL) {
2187 Status = EFI_INVALID_PARAMETER;
2188 goto ON_EXIT;
2189 }
2190
2191 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
2192 Mode = Private->PxeBc.Mode;
2193
2194 if (NewSendGUID != NULL && *NewSendGUID) {
2195 //
2196 // FixMe, cann't locate SendGuid
2197 //
2198 }
2199
2200 if (NewMakeCallback != NULL && *NewMakeCallback) {
2201
2202 Status = gBS->HandleProtocol (
2203 Private->Controller,
2204 &gEfiPxeBaseCodeCallbackProtocolGuid,
2205 (VOID **) &Private->PxeBcCallback
2206 );
2207 if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback == NULL)) {
2208
2209 Status = EFI_INVALID_PARAMETER;
2210 goto ON_EXIT;
2211 }
2212 }
2213
2214 if (!Mode->Started) {
2215 Status = EFI_NOT_STARTED;
2216 goto ON_EXIT;
2217 }
2218
2219 if (NewMakeCallback != NULL) {
2220
2221 if (*NewMakeCallback) {
2222 //
2223 // Update the Callback protocol.
2224 //
2225 Status = gBS->HandleProtocol (
2226 Private->Controller,
2227 &gEfiPxeBaseCodeCallbackProtocolGuid,
2228 (VOID **) &Private->PxeBcCallback
2229 );
2230
2231 if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback == NULL)) {
2232 Status = EFI_INVALID_PARAMETER;
2233 goto ON_EXIT;
2234 }
2235 } else {
2236 Private->PxeBcCallback = NULL;
2237 }
2238
2239 Mode->MakeCallbacks = *NewMakeCallback;
2240 }
2241
2242 if (NewAutoArp != NULL) {
2243 Mode->AutoArp = *NewAutoArp;
2244 }
2245
2246 if (NewSendGUID != NULL) {
2247 Mode->SendGUID = *NewSendGUID;
2248 }
2249
2250 if (NewTTL != NULL) {
2251 Mode->TTL = *NewTTL;
2252 }
2253
2254 if (NewToS != NULL) {
2255 Mode->ToS = *NewToS;
2256 }
2257
2258 ON_EXIT:
2259 return Status;
2260 }
2261
2262 /**
2263 Updates the station IP address and/or subnet mask values of a network device.
2264
2265 This function updates the station IP address and/or subnet mask values of a network
2266 device. The NewStationIp field is used to modify the network device's current IP address.
2267 If NewStationIP is NULL, then the current IP address will not be modified. Otherwise,
2268 this function updates the StationIp field of the EFI_PXE_BASE_CODE_MODE structure
2269 with NewStationIp. The NewSubnetMask field is used to modify the network device's current subnet
2270 mask. If NewSubnetMask is NULL, then the current subnet mask will not be modified.
2271 Otherwise, this function updates the SubnetMask field of the EFI_PXE_BASE_CODE_MODE
2272 structure with NewSubnetMask.
2273
2274 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2275 @param NewStationIp Pointer to the new IP address to be used by the network device.
2276 @param NewSubnetMask Pointer to the new subnet mask to be used by the network device.
2277
2278 @retval EFI_SUCCESS The new station IP address and/or subnet mask were updated.
2279 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2280 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
2281
2282 **/
2283 EFI_STATUS
2284 EFIAPI
2285 EfiPxeBcSetStationIP (
2286 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
2287 IN EFI_IP_ADDRESS * NewStationIp OPTIONAL,
2288 IN EFI_IP_ADDRESS * NewSubnetMask OPTIONAL
2289 )
2290 {
2291 PXEBC_PRIVATE_DATA *Private;
2292 EFI_PXE_BASE_CODE_MODE *Mode;
2293 EFI_ARP_CONFIG_DATA ArpConfigData;
2294
2295 if (This == NULL) {
2296 return EFI_INVALID_PARAMETER;
2297 }
2298
2299 if (NewStationIp != NULL && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), 0)) {
2300 return EFI_INVALID_PARAMETER;
2301 }
2302
2303 if (NewSubnetMask != NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) {
2304 return EFI_INVALID_PARAMETER;
2305 }
2306
2307 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
2308 Mode = Private->PxeBc.Mode;
2309
2310 if (!Mode->Started) {
2311 return EFI_NOT_STARTED;
2312 }
2313
2314 if (NewStationIp != NULL) {
2315 CopyMem (&Mode->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));
2316 CopyMem (&Private->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));
2317 }
2318
2319 if (NewSubnetMask != NULL) {
2320 CopyMem (&Mode->SubnetMask, NewSubnetMask, sizeof (EFI_IP_ADDRESS));
2321 CopyMem (&Private->SubnetMask ,NewSubnetMask, sizeof (EFI_IP_ADDRESS));
2322 }
2323
2324 Private->AddressIsOk = TRUE;
2325
2326 if (!Mode->UsingIpv6) {
2327 //
2328 // If in IPv4 mode, configure the corresponding ARP with this new
2329 // station IP address.
2330 //
2331 ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA));
2332
2333 ArpConfigData.SwAddressType = 0x0800;
2334 ArpConfigData.SwAddressLength = (UINT8) sizeof (EFI_IPv4_ADDRESS);
2335 ArpConfigData.StationAddress = &Private->StationIp.v4;
2336
2337 Private->Arp->Configure (Private->Arp, NULL);
2338 Private->Arp->Configure (Private->Arp, &ArpConfigData);
2339
2340 //
2341 // Update the route table.
2342 //
2343 Mode->RouteTableEntries = 1;
2344 Mode->RouteTable[0].IpAddr.Addr[0] = Private->StationIp.Addr[0] & Private->SubnetMask.Addr[0];
2345 Mode->RouteTable[0].SubnetMask.Addr[0] = Private->SubnetMask.Addr[0];
2346 Mode->RouteTable[0].GwAddr.Addr[0] = 0;
2347 }
2348
2349 return EFI_SUCCESS;
2350 }
2351
2352 /**
2353 Updates the contents of the cached DHCP and Discover packets.
2354
2355 The pointers to the new packets are used to update the contents of the cached
2356 packets in the EFI_PXE_BASE_CODE_MODE structure.
2357
2358 @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.
2359 @param NewDhcpDiscoverValid Pointer to a value that will replace the current
2360 DhcpDiscoverValid field.
2361 @param NewDhcpAckReceived Pointer to a value that will replace the current
2362 DhcpAckReceived field.
2363 @param NewProxyOfferReceived Pointer to a value that will replace the current
2364 ProxyOfferReceived field.
2365 @param NewPxeDiscoverValid Pointer to a value that will replace the current
2366 ProxyOfferReceived field.
2367 @param NewPxeReplyReceived Pointer to a value that will replace the current
2368 PxeReplyReceived field.
2369 @param NewPxeBisReplyReceived Pointer to a value that will replace the current
2370 PxeBisReplyReceived field.
2371 @param NewDhcpDiscover Pointer to the new cached DHCP Discover packet contents.
2372 @param NewDhcpAck Pointer to the new cached DHCP Ack packet contents.
2373 @param NewProxyOffer Pointer to the new cached Proxy Offer packet contents.
2374 @param NewPxeDiscover Pointer to the new cached PXE Discover packet contents.
2375 @param NewPxeReply Pointer to the new cached PXE Reply packet contents.
2376 @param NewPxeBisReply Pointer to the new cached PXE BIS Reply packet contents.
2377
2378 @retval EFI_SUCCESS The cached packet contents were updated.
2379 @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.
2380 @retval EFI_INVALID_PARAMETER This is NULL or not point to a valid EFI_PXE_BASE_CODE_PROTOCOL structure.
2381
2382 **/
2383 EFI_STATUS
2384 EFIAPI
2385 EfiPxeBcSetPackets (
2386 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
2387 IN BOOLEAN * NewDhcpDiscoverValid OPTIONAL,
2388 IN BOOLEAN * NewDhcpAckReceived OPTIONAL,
2389 IN BOOLEAN * NewProxyOfferReceived OPTIONAL,
2390 IN BOOLEAN * NewPxeDiscoverValid OPTIONAL,
2391 IN BOOLEAN * NewPxeReplyReceived OPTIONAL,
2392 IN BOOLEAN * NewPxeBisReplyReceived OPTIONAL,
2393 IN EFI_PXE_BASE_CODE_PACKET * NewDhcpDiscover OPTIONAL,
2394 IN EFI_PXE_BASE_CODE_PACKET * NewDhcpAck OPTIONAL,
2395 IN EFI_PXE_BASE_CODE_PACKET * NewProxyOffer OPTIONAL,
2396 IN EFI_PXE_BASE_CODE_PACKET * NewPxeDiscover OPTIONAL,
2397 IN EFI_PXE_BASE_CODE_PACKET * NewPxeReply OPTIONAL,
2398 IN EFI_PXE_BASE_CODE_PACKET * NewPxeBisReply OPTIONAL
2399 )
2400 {
2401 PXEBC_PRIVATE_DATA *Private;
2402 EFI_PXE_BASE_CODE_MODE *Mode;
2403
2404 if (This == NULL) {
2405 return EFI_INVALID_PARAMETER;
2406 }
2407
2408 Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
2409 Mode = Private->PxeBc.Mode;
2410
2411 if (!Mode->Started) {
2412 return EFI_NOT_STARTED;
2413 }
2414
2415 if (NewDhcpDiscoverValid != NULL) {
2416 Mode->DhcpDiscoverValid = *NewDhcpDiscoverValid;
2417 }
2418
2419 if (NewDhcpAckReceived != NULL) {
2420 Mode->DhcpAckReceived = *NewDhcpAckReceived;
2421 }
2422
2423 if (NewProxyOfferReceived != NULL) {
2424 Mode->ProxyOfferReceived = *NewProxyOfferReceived;
2425 }
2426
2427 if (NewPxeDiscoverValid != NULL) {
2428 Mode->PxeDiscoverValid = *NewPxeDiscoverValid;
2429 }
2430
2431 if (NewPxeReplyReceived != NULL) {
2432 Mode->PxeReplyReceived = *NewPxeReplyReceived;
2433 }
2434
2435 if (NewPxeBisReplyReceived != NULL) {
2436 Mode->PxeBisReplyReceived = *NewPxeBisReplyReceived;
2437 }
2438
2439 if (NewDhcpDiscover != NULL) {
2440 CopyMem (&Mode->DhcpDiscover, NewDhcpDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));
2441 }
2442
2443 if (NewDhcpAck != NULL) {
2444 CopyMem (&Mode->DhcpAck, NewDhcpAck, sizeof (EFI_PXE_BASE_CODE_PACKET));
2445 }
2446
2447 if (NewProxyOffer != NULL) {
2448 CopyMem (&Mode->ProxyOffer, NewProxyOffer, sizeof (EFI_PXE_BASE_CODE_PACKET));
2449 }
2450
2451 if (NewPxeDiscover != NULL) {
2452 CopyMem (&Mode->PxeDiscover, NewPxeDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));
2453 }
2454
2455 if (NewPxeReply != NULL) {
2456 CopyMem (&Mode->PxeReply, NewPxeReply, sizeof (EFI_PXE_BASE_CODE_PACKET));
2457 }
2458
2459 if (NewPxeBisReply != NULL) {
2460 CopyMem (&Mode->PxeBisReply, NewPxeBisReply, sizeof (EFI_PXE_BASE_CODE_PACKET));
2461 }
2462
2463 return EFI_SUCCESS;
2464 }
2465
2466 EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate = {
2467 EFI_PXE_BASE_CODE_PROTOCOL_REVISION,
2468 EfiPxeBcStart,
2469 EfiPxeBcStop,
2470 EfiPxeBcDhcp,
2471 EfiPxeBcDiscover,
2472 EfiPxeBcMtftp,
2473 EfiPxeBcUdpWrite,
2474 EfiPxeBcUdpRead,
2475 EfiPxeBcSetIpFilter,
2476 EfiPxeBcArp,
2477 EfiPxeBcSetParameters,
2478 EfiPxeBcSetStationIP,
2479 EfiPxeBcSetPackets,
2480 NULL
2481 };
2482
2483 /**
2484 Callback function that is invoked when the PXE Base Code Protocol is about to transmit, has
2485 received, or is waiting to receive a packet.
2486
2487 This function is invoked when the PXE Base Code Protocol is about to transmit, has received,
2488 or is waiting to receive a packet. Parameters Function and Received specify the type of event.
2489 Parameters PacketLen and Packet specify the packet that generated the event. If these fields
2490 are zero and NULL respectively, then this is a status update callback. If the operation specified
2491 by Function is to continue, then CALLBACK_STATUS_CONTINUE should be returned. If the operation
2492 specified by Function should be aborted, then CALLBACK_STATUS_ABORT should be returned. Due to
2493 the polling nature of UEFI device drivers, a callback function should not execute for more than 5 ms.
2494 The SetParameters() function must be called after a Callback Protocol is installed to enable the
2495 use of callbacks.
2496
2497 @param This Pointer to the EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL instance.
2498 @param Function The PXE Base Code Protocol function that is waiting for an event.
2499 @param Received TRUE if the callback is being invoked due to a receive event. FALSE if
2500 the callback is being invoked due to a transmit event.
2501 @param PacketLength The length, in bytes, of Packet. This field will have a value of zero if
2502 this is a wait for receive event.
2503 @param PacketPtr If Received is TRUE, a pointer to the packet that was just received;
2504 otherwise a pointer to the packet that is about to be transmitted.
2505
2506 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE if Function specifies a continue operation
2507 @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT if Function specifies an abort operation
2508
2509 **/
2510 EFI_PXE_BASE_CODE_CALLBACK_STATUS
2511 EFIAPI
2512 EfiPxeLoadFileCallback (
2513 IN EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL * This,
2514 IN EFI_PXE_BASE_CODE_FUNCTION Function,
2515 IN BOOLEAN Received,
2516 IN UINT32 PacketLength,
2517 IN EFI_PXE_BASE_CODE_PACKET * PacketPtr OPTIONAL
2518 )
2519 {
2520 EFI_INPUT_KEY Key;
2521 EFI_STATUS Status;
2522
2523 //
2524 // Catch Ctrl-C or ESC to abort.
2525 //
2526 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
2527
2528 if (!EFI_ERROR (Status)) {
2529
2530 if (Key.ScanCode == SCAN_ESC || Key.UnicodeChar == (0x1F & 'c')) {
2531
2532 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT;
2533 }
2534 }
2535 //
2536 // No print if receive packet
2537 //
2538 if (Received) {
2539 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
2540 }
2541 //
2542 // Print only for three functions
2543 //
2544 switch (Function) {
2545
2546 case EFI_PXE_BASE_CODE_FUNCTION_MTFTP:
2547 //
2548 // Print only for open MTFTP packets, not every MTFTP packets
2549 //
2550 if (PacketLength != 0 && PacketPtr != NULL) {
2551 if (PacketPtr->Raw[0x1C] != 0x00 || PacketPtr->Raw[0x1D] != 0x01) {
2552 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
2553 }
2554 }
2555 break;
2556
2557 case EFI_PXE_BASE_CODE_FUNCTION_DHCP:
2558 case EFI_PXE_BASE_CODE_FUNCTION_DISCOVER:
2559 break;
2560
2561 default:
2562 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
2563 }
2564
2565 if (PacketLength != 0 && PacketPtr != NULL) {
2566 //
2567 // Print '.' when transmit a packet
2568 //
2569 AsciiPrint (".");
2570
2571 }
2572
2573 return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;
2574 }
2575
2576 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL mPxeBcCallBackTemplate = {
2577 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_REVISION,
2578 EfiPxeLoadFileCallback
2579 };
2580
2581
2582 /**
2583 Find the boot file.
2584
2585 @param Private Pointer to PxeBc private data.
2586 @param BufferSize Pointer to buffer size.
2587 @param Buffer Pointer to buffer.
2588
2589 @retval EFI_SUCCESS Discover the boot file successfully.
2590 @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.
2591 @retval EFI_ABORTED PXE bootstrap server, so local boot need abort.
2592 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to load the boot file.
2593
2594 **/
2595 EFI_STATUS
2596 DiscoverBootFile (
2597 IN PXEBC_PRIVATE_DATA *Private,
2598 IN OUT UINT64 *BufferSize,
2599 IN VOID *Buffer
2600 )
2601 {
2602 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
2603 EFI_PXE_BASE_CODE_MODE *Mode;
2604 EFI_STATUS Status;
2605 UINT16 Type;
2606 UINT16 Layer;
2607 BOOLEAN UseBis;
2608 PXEBC_CACHED_DHCP4_PACKET *Packet;
2609 UINT16 Value;
2610
2611 PxeBc = &Private->PxeBc;
2612 Mode = PxeBc->Mode;
2613 Type = EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP;
2614 Layer = EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL;
2615
2616 //
2617 // do DHCP.
2618 //
2619 Status = PxeBc->Dhcp (PxeBc, TRUE);
2620 if (EFI_ERROR (Status)) {
2621 return Status;
2622 }
2623
2624 //
2625 // Select a boot server
2626 //
2627 Status = PxeBcSelectBootPrompt (Private);
2628
2629 if (Status == EFI_SUCCESS) {
2630 Status = PxeBcSelectBootMenu (Private, &Type, TRUE);
2631 } else if (Status == EFI_TIMEOUT) {
2632 Status = PxeBcSelectBootMenu (Private, &Type, FALSE);
2633 }
2634
2635 if (!EFI_ERROR (Status)) {
2636
2637 if (Type == EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP) {
2638 //
2639 // Local boot(PXE bootstrap server) need abort
2640 //
2641 return EFI_ABORTED;
2642 }
2643
2644 UseBis = (BOOLEAN) (Mode->BisSupported && Mode->BisDetected);
2645 Status = PxeBc->Discover (PxeBc, Type, &Layer, UseBis, NULL);
2646 if (EFI_ERROR (Status)) {
2647 return Status;
2648 }
2649 }
2650
2651 *BufferSize = 0;
2652
2653 //
2654 // Get bootfile name and (m)tftp server ip addresss
2655 //
2656 if (Mode->PxeReplyReceived) {
2657 Packet = &Private->PxeReply;
2658 } else if (Mode->ProxyOfferReceived) {
2659 Packet = &Private->ProxyOffer;
2660 } else {
2661 Packet = &Private->Dhcp4Ack;
2662 }
2663
2664 //
2665 // Use siaddr(next server) in DHCPOFFER packet header, if zero, use option 54(server identifier)
2666 // in DHCPOFFER packet.
2667 // (It does not comply with PXE Spec, Ver2.1)
2668 //
2669 if (EFI_IP4_EQUAL (&Packet->Packet.Offer.Dhcp4.Header.ServerAddr, &mZeroIp4Addr)) {
2670 CopyMem (
2671 &Private->ServerIp,
2672 Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER_ID]->Data,
2673 sizeof (EFI_IPv4_ADDRESS)
2674 );
2675 } else {
2676 CopyMem (
2677 &Private->ServerIp,
2678 &Packet->Packet.Offer.Dhcp4.Header.ServerAddr,
2679 sizeof (EFI_IPv4_ADDRESS)
2680 );
2681 }
2682 if (Private->ServerIp.Addr[0] == 0) {
2683 return EFI_DEVICE_ERROR;
2684 }
2685
2686 ASSERT (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL);
2687
2688 //
2689 // bootlfile name
2690 //
2691 Private->BootFileName = (CHAR8 *) (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data);
2692
2693 if (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN] != NULL) {
2694 //
2695 // Already have the bootfile length option, compute the file size
2696 //
2697 CopyMem (&Value, Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN]->Data, sizeof (Value));
2698 Value = NTOHS (Value);
2699 *BufferSize = 512 * Value;
2700 Status = EFI_BUFFER_TOO_SMALL;
2701 } else {
2702 //
2703 // Get the bootfile size from tftp
2704 //
2705 Status = PxeBc->Mtftp (
2706 PxeBc,
2707 EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,
2708 Buffer,
2709 FALSE,
2710 BufferSize,
2711 &Private->BlockSize,
2712 &Private->ServerIp,
2713 (UINT8 *) Private->BootFileName,
2714 NULL,
2715 FALSE
2716 );
2717 }
2718
2719 Private->FileSize = (UINTN) *BufferSize;
2720
2721 return Status;
2722 }
2723
2724 /**
2725 Causes the driver to load a specified file.
2726
2727 @param This Protocol instance pointer.
2728 @param FilePath The device specific path of the file to load.
2729 @param BootPolicy If TRUE, indicates that the request originates from the
2730 boot manager is attempting to load FilePath as a boot
2731 selection. If FALSE, then FilePath must match as exact file
2732 to be loaded.
2733 @param BufferSize On input the size of Buffer in bytes. On output with a return
2734 code of EFI_SUCCESS, the amount of data transferred to
2735 Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
2736 the size of Buffer required to retrieve the requested file.
2737 @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
2738 then no the size of the requested file is returned in
2739 BufferSize.
2740
2741 @retval EFI_SUCCESS The file was loaded.
2742 @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy
2743 @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or
2744 BufferSize is NULL.
2745 @retval EFI_NO_MEDIA No medium was present to load the file.
2746 @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.
2747 @retval EFI_NO_RESPONSE The remote system did not respond.
2748 @retval EFI_NOT_FOUND The file was not found.
2749 @retval EFI_ABORTED The file load process was manually cancelled.
2750
2751 **/
2752 EFI_STATUS
2753 EFIAPI
2754 EfiPxeLoadFile (
2755 IN EFI_LOAD_FILE_PROTOCOL * This,
2756 IN EFI_DEVICE_PATH_PROTOCOL * FilePath,
2757 IN BOOLEAN BootPolicy,
2758 IN OUT UINTN *BufferSize,
2759 IN VOID *Buffer OPTIONAL
2760 )
2761 {
2762 PXEBC_PRIVATE_DATA *Private;
2763 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;
2764 BOOLEAN NewMakeCallback;
2765 EFI_STATUS Status;
2766 UINT64 TmpBufSize;
2767 BOOLEAN MediaPresent;
2768
2769 Private = PXEBC_PRIVATE_DATA_FROM_LOADFILE (This);
2770 PxeBc = &Private->PxeBc;
2771 NewMakeCallback = FALSE;
2772 Status = EFI_DEVICE_ERROR;
2773
2774 if (This == NULL || BufferSize == NULL) {
2775
2776 return EFI_INVALID_PARAMETER;
2777 }
2778
2779 //
2780 // Only support BootPolicy
2781 //
2782 if (!BootPolicy) {
2783 return EFI_UNSUPPORTED;
2784 }
2785
2786 //
2787 // Check media status before PXE start
2788 //
2789 MediaPresent = TRUE;
2790 NetLibDetectMedia (Private->Controller, &MediaPresent);
2791 if (!MediaPresent) {
2792 return EFI_NO_MEDIA;
2793 }
2794
2795 Status = PxeBc->Start (PxeBc, FALSE);
2796 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
2797 return Status;
2798 }
2799
2800 Status = gBS->HandleProtocol (
2801 Private->Controller,
2802 &gEfiPxeBaseCodeCallbackProtocolGuid,
2803 (VOID **) &Private->PxeBcCallback
2804 );
2805 if (Status == EFI_UNSUPPORTED) {
2806
2807 CopyMem (&Private->LoadFileCallback, &mPxeBcCallBackTemplate, sizeof (Private->LoadFileCallback));
2808
2809 Status = gBS->InstallProtocolInterface (
2810 &Private->Controller,
2811 &gEfiPxeBaseCodeCallbackProtocolGuid,
2812 EFI_NATIVE_INTERFACE,
2813 &Private->LoadFileCallback
2814 );
2815
2816 NewMakeCallback = (BOOLEAN) (Status == EFI_SUCCESS);
2817
2818 Status = PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);
2819 if (EFI_ERROR (Status)) {
2820 PxeBc->Stop (PxeBc);
2821 return Status;
2822 }
2823 }
2824
2825 if (Private->FileSize == 0) {
2826 TmpBufSize = 0;
2827 Status = DiscoverBootFile (Private, &TmpBufSize, Buffer);
2828
2829 if (sizeof (UINTN) < sizeof (UINT64) && (TmpBufSize > 0xFFFFFFFF)) {
2830 Status = EFI_DEVICE_ERROR;
2831 } else if (TmpBufSize > 0 && *BufferSize >= (UINTN) TmpBufSize && Buffer != NULL) {
2832 *BufferSize = (UINTN) TmpBufSize;
2833 Status = PxeBc->Mtftp (
2834 PxeBc,
2835 EFI_PXE_BASE_CODE_TFTP_READ_FILE,
2836 Buffer,
2837 FALSE,
2838 &TmpBufSize,
2839 &Private->BlockSize,
2840 &Private->ServerIp,
2841 (UINT8 *) Private->BootFileName,
2842 NULL,
2843 FALSE
2844 );
2845 } else if (TmpBufSize > 0) {
2846 *BufferSize = (UINTN) TmpBufSize;
2847 Status = EFI_BUFFER_TOO_SMALL;
2848 }
2849 } else if (Buffer == NULL || Private->FileSize > *BufferSize) {
2850 *BufferSize = Private->FileSize;
2851 Status = EFI_BUFFER_TOO_SMALL;
2852 } else {
2853 //
2854 // Download the file.
2855 //
2856 TmpBufSize = (UINT64) (*BufferSize);
2857 Status = PxeBc->Mtftp (
2858 PxeBc,
2859 EFI_PXE_BASE_CODE_TFTP_READ_FILE,
2860 Buffer,
2861 FALSE,
2862 &TmpBufSize,
2863 &Private->BlockSize,
2864 &Private->ServerIp,
2865 (UINT8 *) Private->BootFileName,
2866 NULL,
2867 FALSE
2868 );
2869 }
2870 //
2871 // If we added a callback protocol, now is the time to remove it.
2872 //
2873 if (NewMakeCallback) {
2874
2875 NewMakeCallback = FALSE;
2876
2877 PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);
2878
2879 gBS->UninstallProtocolInterface (
2880 Private->Controller,
2881 &gEfiPxeBaseCodeCallbackProtocolGuid,
2882 &Private->LoadFileCallback
2883 );
2884 }
2885
2886 //
2887 // Check download status
2888 //
2889 if (Status == EFI_SUCCESS) {
2890 //
2891 // The functionality of PXE Base Code protocol will not be stopped,
2892 // when downloading is successfully.
2893 //
2894 return EFI_SUCCESS;
2895
2896 } else if (Status == EFI_BUFFER_TOO_SMALL) {
2897 if (Buffer != NULL) {
2898 AsciiPrint ("PXE-E05: Download buffer is smaller than requested file.\n");
2899 } else {
2900 //
2901 // The functionality of PXE Base Code protocol will not be stopped.
2902 //
2903 return Status;
2904 }
2905
2906 } else if (Status == EFI_DEVICE_ERROR) {
2907 AsciiPrint ("PXE-E07: Network device error.\n");
2908
2909 } else if (Status == EFI_OUT_OF_RESOURCES) {
2910 AsciiPrint ("PXE-E09: Could not allocate I/O buffers.\n");
2911
2912 } else if (Status == EFI_NO_MEDIA) {
2913 AsciiPrint ("PXE-E12: Could not detect network connection.\n");
2914
2915 } else if (Status == EFI_NO_RESPONSE) {
2916 AsciiPrint ("PXE-E16: No offer received.\n");
2917
2918 } else if (Status == EFI_TIMEOUT) {
2919 AsciiPrint ("PXE-E18: Server response timeout.\n");
2920
2921 } else if (Status == EFI_ABORTED) {
2922 AsciiPrint ("PXE-E21: Remote boot cancelled.\n");
2923
2924 } else if (Status == EFI_ICMP_ERROR) {
2925 AsciiPrint ("PXE-E22: Client received ICMP error from server.\n");
2926
2927 } else if (Status == EFI_TFTP_ERROR) {
2928 AsciiPrint ("PXE-E23: Client received TFTP error from server.\n");
2929
2930 } else {
2931 AsciiPrint ("PXE-E99: Unexpected network error.\n");
2932 }
2933
2934 PxeBc->Stop (PxeBc);
2935
2936 return Status;
2937 }
2938
2939 EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate = { EfiPxeLoadFile };
2940