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