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