]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/UefiPxeBcDxe/PxeBcBoot.c
MdePkg: add missing #defines for decoding PCIe 2.1 extended capability structures
[mirror_edk2.git] / NetworkPkg / UefiPxeBcDxe / PxeBcBoot.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 Boot functions implementation for UefiPxeBc Driver.\r
3\r
ecec4204 4 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
a3bcde70
HT
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "PxeBcImpl.h"\r
17\r
18\r
19/**\r
20 Display the string of the boot item.\r
21\r
22 If the length of the boot item string beyond 70 Char, just display 70 Char.\r
23\r
24 @param[in] Str The pointer to the string.\r
25 @param[in] Len The length of the string.\r
26\r
27**/\r
28VOID\r
29PxeBcDisplayBootItem (\r
30 IN UINT8 *Str,\r
31 IN UINT8 Len\r
32 )\r
33{\r
34 UINT8 Tmp;\r
35\r
36 //\r
37 // Cut off the chars behind 70th.\r
38 //\r
39 Len = (UINT8) MIN (PXEBC_DISPLAY_MAX_LINE, Len);\r
40 Tmp = Str[Len];\r
41 Str[Len] = 0;\r
42 AsciiPrint ("%a \n", Str);\r
43\r
44 //\r
45 // Restore the original 70th char.\r
46 //\r
47 Str[Len] = Tmp;\r
48}\r
49\r
50\r
51/**\r
52 Select and maintain the boot prompt if needed.\r
53\r
54 @param[in] Private Pointer to PxeBc private data.\r
55\r
56 @retval EFI_SUCCESS Selected boot prompt done.\r
57 @retval EFI_TIMEOUT Selected boot prompt timed out.\r
58 @retval EFI_NOT_FOUND The proxy offer is not Pxe10.\r
59 @retval EFI_ABORTED User cancelled the operation.\r
60 @retval EFI_NOT_READY Reading the input key from the keyboard has not finish.\r
61\r
62**/\r
63EFI_STATUS\r
64PxeBcSelectBootPrompt (\r
65 IN PXEBC_PRIVATE_DATA *Private\r
66 )\r
67{\r
68 PXEBC_DHCP_PACKET_CACHE *Cache;\r
69 PXEBC_VENDOR_OPTION *VendorOpt;\r
70 EFI_PXE_BASE_CODE_MODE *Mode;\r
71 EFI_EVENT TimeoutEvent;\r
72 EFI_EVENT DescendEvent;\r
73 EFI_INPUT_KEY InputKey;\r
74 EFI_STATUS Status;\r
75 UINT32 OfferType;\r
76 UINT8 Timeout;\r
77 UINT8 *Prompt;\r
78 UINT8 PromptLen;\r
79 INT32 SecCol;\r
80 INT32 SecRow;\r
81\r
82 TimeoutEvent = NULL;\r
83 DescendEvent = NULL;\r
84 Mode = Private->PxeBc.Mode;\r
85 Cache = Mode->ProxyOfferReceived ? &Private->ProxyOffer : &Private->DhcpAck;\r
86 OfferType = Mode->UsingIpv6 ? Cache->Dhcp6.OfferType : Cache->Dhcp4.OfferType;\r
87\r
88 //\r
9063c328 89 // Only DhcpPxe10 and ProxyPxe10 offer needs boot prompt.\r
a3bcde70 90 //\r
9063c328 91 if (OfferType != PxeOfferTypeProxyPxe10 && OfferType != PxeOfferTypeDhcpPxe10) {\r
a3bcde70
HT
92 return EFI_NOT_FOUND;\r
93 }\r
94\r
95 //\r
96 // There is no specified ProxyPxe10 for IPv6 in PXE and UEFI spec.\r
97 //\r
98 ASSERT (!Mode->UsingIpv6);\r
99\r
100 VendorOpt = &Cache->Dhcp4.VendorOpt;\r
30a95d4d 101 //\r
102 // According to the PXE specification 2.1, Table 2-1 PXE DHCP Options,\r
103 // we must not consider a boot prompt or boot menu if all of the following hold:\r
104 // - the PXE_DISCOVERY_CONTROL tag(6) is present inside the Vendor Options(43), and has bit 3 set \r
105 // - a boot file name has been presented in the initial DHCP or ProxyDHCP offer packet.\r
106 //\r
107 if (IS_DISABLE_PROMPT_MENU (VendorOpt->DiscoverCtrl) &&\r
108 Cache->Dhcp4.OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {\r
109 return EFI_ABORTED;\r
110 }\r
111 \r
a3bcde70 112 if (!IS_VALID_BOOT_PROMPT (VendorOpt->BitMap)) {\r
9063c328 113 return EFI_TIMEOUT;\r
a3bcde70
HT
114 }\r
115\r
116 Timeout = VendorOpt->MenuPrompt->Timeout;\r
117 Prompt = VendorOpt->MenuPrompt->Prompt;\r
118 PromptLen = (UINT8) (VendorOpt->MenuPromptLen - 1);\r
119\r
120 //\r
121 // The valid scope of Timeout refers to PXE2.1 spec.\r
122 //\r
123 if (Timeout == 0) {\r
9063c328 124 return EFI_TIMEOUT;\r
a3bcde70
HT
125 }\r
126 if (Timeout == 255) {\r
9063c328 127 return EFI_SUCCESS;\r
a3bcde70
HT
128 }\r
129\r
130 //\r
131 // Create and start a timer as timeout event.\r
132 //\r
133 Status = gBS->CreateEvent (\r
134 EVT_TIMER,\r
135 TPL_CALLBACK,\r
136 NULL,\r
137 NULL,\r
138 &TimeoutEvent\r
139 );\r
140 if (EFI_ERROR (Status)) {\r
141 return Status;\r
142 }\r
143\r
144 Status = gBS->SetTimer (\r
145 TimeoutEvent,\r
146 TimerRelative,\r
147 Timeout * TICKS_PER_SECOND\r
148 );\r
149 if (EFI_ERROR (Status)) {\r
150 goto ON_EXIT;\r
151 }\r
152\r
153 //\r
154 // Create and start a periodic timer as descend event by second.\r
155 //\r
156 Status = gBS->CreateEvent (\r
157 EVT_TIMER,\r
158 TPL_CALLBACK,\r
159 NULL,\r
160 NULL,\r
161 &DescendEvent\r
162 );\r
163 if (EFI_ERROR (Status)) {\r
164 goto ON_EXIT;\r
165 }\r
166\r
167 Status = gBS->SetTimer (\r
168 DescendEvent,\r
169 TimerPeriodic,\r
170 TICKS_PER_SECOND\r
171 );\r
172 if (EFI_ERROR (Status)) {\r
173 goto ON_EXIT;\r
174 }\r
175\r
176 //\r
177 // Display the boot item and cursor on the screen.\r
178 //\r
179 SecCol = gST->ConOut->Mode->CursorColumn;\r
180 SecRow = gST->ConOut->Mode->CursorRow;\r
181\r
182 PxeBcDisplayBootItem (Prompt, PromptLen);\r
183\r
184 gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);\r
185 AsciiPrint ("(%d) ", Timeout--);\r
186\r
9063c328 187 Status = EFI_TIMEOUT;\r
a3bcde70
HT
188 while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))) {\r
189 if (!EFI_ERROR (gBS->CheckEvent (DescendEvent))) {\r
190 gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);\r
191 AsciiPrint ("(%d) ", Timeout--);\r
192 }\r
193 if (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {\r
194 gBS->Stall (10 * TICKS_PER_MS);\r
195 continue;\r
196 }\r
197 //\r
198 // Parse the input key by user.\r
9063c328 199 // If <F8> or <Ctrl> + <M> is pressed, return success to display the boot menu.\r
a3bcde70
HT
200 //\r
201 if (InputKey.ScanCode == 0) {\r
202\r
203 switch (InputKey.UnicodeChar) {\r
204\r
205 case CTRL ('c'):\r
206 Status = EFI_ABORTED;\r
207 break;\r
208\r
209 case CTRL ('m'):\r
210 case 'm':\r
211 case 'M':\r
9063c328 212 Status = EFI_SUCCESS;\r
a3bcde70
HT
213 break;\r
214\r
215 default:\r
216 continue;\r
217 }\r
218\r
219 } else {\r
220\r
221 switch (InputKey.ScanCode) {\r
222\r
223 case SCAN_F8:\r
9063c328 224 Status = EFI_SUCCESS;\r
a3bcde70
HT
225 break;\r
226\r
227 case SCAN_ESC:\r
228 Status = EFI_ABORTED;\r
229 break;\r
230\r
231 default:\r
232 continue;\r
233 }\r
234 }\r
235\r
236 break;\r
237 }\r
238\r
239 //\r
240 // Reset the cursor on the screen.\r
241 //\r
242 gST->ConOut->SetCursorPosition (gST->ConOut, 0 , SecRow + 1);\r
243\r
244ON_EXIT:\r
245 if (DescendEvent != NULL) {\r
246 gBS->CloseEvent (DescendEvent);\r
247 }\r
248 if (TimeoutEvent != NULL) {\r
249 gBS->CloseEvent (TimeoutEvent);\r
250 }\r
251\r
252 return Status;\r
253}\r
254\r
255\r
256/**\r
257 Select the boot menu by user's input.\r
258\r
259 @param[in] Private Pointer to PxeBc private data.\r
260 @param[out] Type The type of the menu.\r
261 @param[in] UseDefaultItem Use default item or not.\r
262\r
263 @retval EFI_ABORTED User cancel operation.\r
264 @retval EFI_SUCCESS Select the boot menu success.\r
265 @retval EFI_NOT_READY Read the input key from the keybroad has not finish.\r
266\r
267**/\r
268EFI_STATUS\r
269PxeBcSelectBootMenu (\r
270 IN PXEBC_PRIVATE_DATA *Private,\r
271 OUT UINT16 *Type,\r
272 IN BOOLEAN UseDefaultItem\r
273 )\r
274{\r
275 EFI_PXE_BASE_CODE_MODE *Mode;\r
276 PXEBC_DHCP_PACKET_CACHE *Cache;\r
277 PXEBC_VENDOR_OPTION *VendorOpt;\r
278 EFI_INPUT_KEY InputKey;\r
279 UINT32 OfferType;\r
280 UINT8 MenuSize;\r
281 UINT8 MenuNum;\r
282 INT32 TopRow;\r
283 UINT16 Select;\r
284 UINT16 LastSelect;\r
285 UINT8 Index;\r
286 BOOLEAN Finish;\r
287 CHAR8 Blank[PXEBC_DISPLAY_MAX_LINE];\r
288 PXEBC_BOOT_MENU_ENTRY *MenuItem;\r
289 PXEBC_BOOT_MENU_ENTRY *MenuArray[PXEBC_MENU_MAX_NUM];\r
290\r
291 Finish = FALSE;\r
a1c0d0fb 292 Select = 0;\r
a3bcde70
HT
293 Index = 0;\r
294 *Type = 0;\r
295 Mode = Private->PxeBc.Mode;\r
296 Cache = Mode->ProxyOfferReceived ? &Private->ProxyOffer : &Private->DhcpAck;\r
297 OfferType = Mode->UsingIpv6 ? Cache->Dhcp6.OfferType : Cache->Dhcp4.OfferType;\r
298\r
299 //\r
9063c328 300 // There is no specified DhcpPxe10/ProxyPxe10 for IPv6 in PXE and UEFI spec.\r
a3bcde70
HT
301 //\r
302 ASSERT (!Mode->UsingIpv6);\r
9063c328 303 ASSERT (OfferType == PxeOfferTypeProxyPxe10 || OfferType == PxeOfferTypeDhcpPxe10);\r
a3bcde70
HT
304\r
305 VendorOpt = &Cache->Dhcp4.VendorOpt;\r
306 if (!IS_VALID_BOOT_MENU (VendorOpt->BitMap)) {\r
307 return EFI_SUCCESS;\r
308 }\r
309\r
310 //\r
311 // Display the boot menu on the screen.\r
312 //\r
313 SetMem (Blank, sizeof(Blank), ' ');\r
314\r
315 MenuSize = VendorOpt->BootMenuLen;\r
316 MenuItem = VendorOpt->BootMenu;\r
317\r
318 if (MenuSize == 0) {\r
319 return EFI_DEVICE_ERROR;\r
320 }\r
321\r
322 while (MenuSize > 0 && Index < PXEBC_MENU_MAX_NUM) {\r
323 ASSERT (MenuItem != NULL);\r
324 MenuArray[Index] = MenuItem;\r
325 MenuSize = (UINT8) (MenuSize - (MenuItem->DescLen + 3));\r
326 MenuItem = (PXEBC_BOOT_MENU_ENTRY *) ((UINT8 *) MenuItem + MenuItem->DescLen + 3);\r
327 Index++;\r
328 }\r
329\r
330 if (UseDefaultItem) {\r
331 ASSERT (MenuArray[0] != NULL);\r
332 CopyMem (Type, &MenuArray[0]->Type, sizeof (UINT16));\r
333 *Type = NTOHS (*Type);\r
334 return EFI_SUCCESS;\r
335 }\r
336\r
337 MenuNum = Index;\r
338\r
339 for (Index = 0; Index < MenuNum; Index++) {\r
340 ASSERT (MenuArray[Index] != NULL);\r
341 PxeBcDisplayBootItem (MenuArray[Index]->DescStr, MenuArray[Index]->DescLen);\r
342 }\r
343\r
344 TopRow = gST->ConOut->Mode->CursorRow - MenuNum;\r
345\r
346 //\r
347 // Select the boot item by user in the boot menu.\r
348 //\r
349 do {\r
350 //\r
351 // Highlight selected row.\r
352 //\r
353 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));\r
354 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + Select);\r
355 ASSERT (Select < PXEBC_MENU_MAX_NUM);\r
356 ASSERT (MenuArray[Select] != NULL);\r
357 Blank[MenuArray[Select]->DescLen] = 0;\r
358 AsciiPrint ("%a\r", Blank);\r
359 PxeBcDisplayBootItem (MenuArray[Select]->DescStr, MenuArray[Select]->DescLen);\r
360 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);\r
361 LastSelect = Select;\r
362\r
363 while (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {\r
364 gBS->Stall (10 * TICKS_PER_MS);\r
365 }\r
366\r
9063c328 367 if (InputKey.ScanCode == 0) {\r
a3bcde70
HT
368 switch (InputKey.UnicodeChar) {\r
369 case CTRL ('c'):\r
370 InputKey.ScanCode = SCAN_ESC;\r
371 break;\r
372\r
373 case CTRL ('j'): /* linefeed */\r
374 case CTRL ('m'): /* return */\r
375 Finish = TRUE;\r
376 break;\r
377\r
378 case CTRL ('i'): /* tab */\r
379 case ' ':\r
380 case 'd':\r
381 case 'D':\r
382 InputKey.ScanCode = SCAN_DOWN;\r
383 break;\r
384\r
385 case CTRL ('h'): /* backspace */\r
386 case 'u':\r
387 case 'U':\r
388 InputKey.ScanCode = SCAN_UP;\r
389 break;\r
390\r
391 default:\r
392 InputKey.ScanCode = 0;\r
393 }\r
394 }\r
395\r
396 switch (InputKey.ScanCode) {\r
397 case SCAN_LEFT:\r
398 case SCAN_UP:\r
399 if (Select != 0) {\r
400 Select--;\r
401 }\r
402 break;\r
403\r
404 case SCAN_DOWN:\r
405 case SCAN_RIGHT:\r
406 if (++Select == MenuNum) {\r
407 Select--;\r
408 }\r
409 break;\r
410\r
411 case SCAN_PAGE_UP:\r
412 case SCAN_HOME:\r
413 Select = 0;\r
414 break;\r
415\r
416 case SCAN_PAGE_DOWN:\r
417 case SCAN_END:\r
418 Select = (UINT16) (MenuNum - 1);\r
419 break;\r
420\r
421 case SCAN_ESC:\r
422 return EFI_ABORTED;\r
423 }\r
424\r
425 //\r
426 // Unhighlight the last selected row.\r
427 //\r
428 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
429 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + LastSelect);\r
430 ASSERT (LastSelect < PXEBC_MENU_MAX_NUM);\r
431 ASSERT (MenuArray[LastSelect] != NULL);\r
432 Blank[MenuArray[LastSelect]->DescLen] = 0;\r
433 AsciiPrint ("%a\r", Blank);\r
434 PxeBcDisplayBootItem (MenuArray[LastSelect]->DescStr, MenuArray[LastSelect]->DescLen);\r
435 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);\r
436 } while (!Finish);\r
437\r
438 //\r
439 // Swap the byte order.\r
440 //\r
441 ASSERT (Select < PXEBC_MENU_MAX_NUM);\r
442 ASSERT (MenuArray[Select] != NULL);\r
443 CopyMem (Type, &MenuArray[Select]->Type, sizeof (UINT16));\r
444 *Type = NTOHS (*Type);\r
445\r
446 return EFI_SUCCESS;\r
447}\r
448\r
449\r
450/**\r
451 Parse out the boot information from the last Dhcp4 reply packet.\r
452\r
453 @param[in, out] Private Pointer to PxeBc private data.\r
454 @param[out] BufferSize Size of the boot file to be downloaded.\r
455\r
456 @retval EFI_SUCCESS Successfully parsed out all the boot information.\r
457 @retval Others Failed to parse out the boot information.\r
458\r
459**/\r
460EFI_STATUS\r
461PxeBcDhcp4BootInfo (\r
462 IN OUT PXEBC_PRIVATE_DATA *Private,\r
463 OUT UINT64 *BufferSize\r
464 )\r
465{\r
466 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
467 EFI_PXE_BASE_CODE_MODE *Mode;\r
468 EFI_STATUS Status;\r
469 PXEBC_DHCP4_PACKET_CACHE *Cache4;\r
470 UINT16 Value;\r
ecec4204
FS
471 PXEBC_VENDOR_OPTION *VendorOpt;\r
472 PXEBC_BOOT_SVR_ENTRY *Entry;\r
473 \r
a3bcde70
HT
474 PxeBc = &Private->PxeBc;\r
475 Mode = PxeBc->Mode;\r
476 Status = EFI_SUCCESS;\r
477 *BufferSize = 0;\r
478\r
479 //\r
480 // Get the last received Dhcp4 reply packet.\r
481 //\r
482 if (Mode->PxeReplyReceived) {\r
483 Cache4 = &Private->PxeReply.Dhcp4;\r
484 } else if (Mode->ProxyOfferReceived) {\r
485 Cache4 = &Private->ProxyOffer.Dhcp4;\r
486 } else {\r
487 Cache4 = &Private->DhcpAck.Dhcp4;\r
488 }\r
489\r
ecec4204 490 ASSERT (Cache4->OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL);\r
a3bcde70 491\r
ecec4204
FS
492 //\r
493 // Parse the boot server address.\r
494 // If prompt/discover is disabled, get the first boot server from the boot servers list.\r
495 // Otherwise, parse the boot server Ipv4 address from next server address field in DHCP header.\r
496 // If all these fields are not available, use option 54 instead.\r
497 //\r
498 VendorOpt = &Cache4->VendorOpt;\r
499 if (IS_DISABLE_PROMPT_MENU (VendorOpt->DiscoverCtrl) && IS_VALID_BOOT_SERVERS (VendorOpt->BitMap)) {\r
500 Entry = VendorOpt->BootSvr;\r
501 if (VendorOpt->BootSvrLen >= sizeof (PXEBC_BOOT_SVR_ENTRY) && Entry->IpCnt > 0) {\r
502 CopyMem (\r
503 &Private->ServerIp,\r
504 &Entry->IpAddr[0],\r
505 sizeof (EFI_IPv4_ADDRESS)\r
506 );\r
507 }\r
508 }\r
a3bcde70 509 if (Private->ServerIp.Addr[0] == 0) {\r
ecec4204
FS
510 //\r
511 // ServerIp.Addr[0] equals zero means we failed to get IP address from boot server list.\r
512 // Try to use next server address field.\r
513 //\r
514 CopyMem (\r
515 &Private->ServerIp,\r
516 &Cache4->Packet.Offer.Dhcp4.Header.ServerAddr,\r
517 sizeof (EFI_IPv4_ADDRESS)\r
518 );\r
519 }\r
520 if (Private->ServerIp.Addr[0] == 0) {\r
521 //\r
522 // Still failed , use the IP address from option 54.\r
523 //\r
a3bcde70
HT
524 CopyMem (\r
525 &Private->ServerIp,\r
526 Cache4->OptList[PXEBC_DHCP4_TAG_INDEX_SERVER_ID]->Data,\r
527 sizeof (EFI_IPv4_ADDRESS)\r
528 );\r
529 }\r
530\r
531 //\r
532 // Parse the boot file name by option.\r
533 //\r
a3bcde70
HT
534 Private->BootFileName = Cache4->OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data;\r
535\r
536 if (Cache4->OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN] != NULL) {\r
537 //\r
538 // Parse the boot file size by option.\r
539 //\r
540 CopyMem (&Value, Cache4->OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN]->Data, sizeof (Value));\r
541 Value = NTOHS (Value);\r
542 //\r
543 // The field of boot file size is 512 bytes in unit.\r
544 //\r
545 *BufferSize = 512 * Value;\r
546 } else {\r
547 //\r
548 // Get the bootfile size by tftp command if no option available.\r
549 //\r
550 Status = PxeBc->Mtftp (\r
551 PxeBc,\r
552 EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,\r
553 NULL,\r
554 FALSE,\r
555 BufferSize,\r
556 &Private->BlockSize,\r
557 &Private->ServerIp,\r
558 Private->BootFileName,\r
559 NULL,\r
560 FALSE\r
561 );\r
562 }\r
563\r
564 //\r
565 // Save the value of boot file size.\r
566 //\r
567 Private->BootFileSize = (UINTN) *BufferSize;\r
568\r
569 //\r
570 // Display all the information: boot server address, boot file name and boot file size.\r
571 //\r
572 AsciiPrint ("\n Server IP address is ");\r
573 PxeBcShowIp4Addr (&Private->ServerIp.v4);\r
574 AsciiPrint ("\n NBP filename is %a", Private->BootFileName);\r
575 AsciiPrint ("\n NBP filesize is %d Bytes", Private->BootFileSize);\r
576\r
577 return Status;\r
578}\r
579\r
580\r
581/**\r
582 Parse out the boot information from the last Dhcp6 reply packet.\r
583\r
584 @param[in, out] Private Pointer to PxeBc private data.\r
585 @param[out] BufferSize Size of the boot file to be downloaded.\r
586\r
587 @retval EFI_SUCCESS Successfully parsed out all the boot information.\r
588 @retval EFI_BUFFER_TOO_SMALL\r
589 @retval Others Failed to parse out the boot information.\r
590\r
591**/\r
592EFI_STATUS\r
593PxeBcDhcp6BootInfo (\r
594 IN OUT PXEBC_PRIVATE_DATA *Private,\r
595 OUT UINT64 *BufferSize\r
596 )\r
597{\r
598 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
599 EFI_PXE_BASE_CODE_MODE *Mode;\r
600 EFI_STATUS Status;\r
601 PXEBC_DHCP6_PACKET_CACHE *Cache6;\r
602 UINT16 Value;\r
603\r
604 PxeBc = &Private->PxeBc;\r
605 Mode = PxeBc->Mode;\r
606 Status = EFI_SUCCESS;\r
607 *BufferSize = 0;\r
608\r
609 //\r
610 // Get the last received Dhcp6 reply packet.\r
611 //\r
612 if (Mode->PxeReplyReceived) {\r
613 Cache6 = &Private->PxeReply.Dhcp6;\r
614 } else if (Mode->ProxyOfferReceived) {\r
615 Cache6 = &Private->ProxyOffer.Dhcp6;\r
616 } else {\r
617 Cache6 = &Private->DhcpAck.Dhcp6;\r
618 }\r
619\r
620 ASSERT (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] != NULL);\r
621\r
622 //\r
623 // Parse (m)tftp server ip address and bootfile name.\r
624 //\r
625 Status = PxeBcExtractBootFileUrl (\r
626 &Private->BootFileName,\r
627 &Private->ServerIp.v6,\r
628 (CHAR8 *) (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL]->Data),\r
629 NTOHS (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL]->OpLen)\r
630 );\r
631 if (EFI_ERROR (Status)) {\r
632 return Status;\r
633 }\r
634\r
635 //\r
636 // Parse the value of boot file size.\r
637 //\r
638 if (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_PARAM] != NULL) {\r
639 //\r
640 // Parse it out if have the boot file parameter option.\r
641 //\r
642 Status = PxeBcExtractBootFileParam ((CHAR8 *) Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_PARAM]->Data, &Value);\r
643 if (EFI_ERROR (Status)) {\r
644 return Status;\r
645 }\r
646 //\r
647 // The field of boot file size is 512 bytes in unit.\r
648 //\r
649 *BufferSize = 512 * Value;\r
650 } else {\r
651 //\r
652 // Send get file size command by tftp if option unavailable.\r
653 //\r
654 Status = PxeBc->Mtftp (\r
655 PxeBc,\r
656 EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,\r
657 NULL,\r
658 FALSE,\r
659 BufferSize,\r
660 &Private->BlockSize,\r
661 &Private->ServerIp,\r
662 Private->BootFileName,\r
663 NULL,\r
664 FALSE\r
665 );\r
666 }\r
667\r
668 //\r
669 // Save the value of boot file size.\r
670 //\r
671 Private->BootFileSize = (UINTN) *BufferSize;\r
672\r
673 //\r
674 // Display all the information: boot server address, boot file name and boot file size.\r
675 //\r
676 AsciiPrint ("\n Server IP address is ");\r
677 PxeBcShowIp6Addr (&Private->ServerIp.v6);\r
678 AsciiPrint ("\n NBP filename is %a", Private->BootFileName);\r
679 AsciiPrint ("\n NBP filesize is %d Bytes", Private->BootFileSize);\r
680\r
681 return Status;\r
682}\r
683\r
684\r
685/**\r
686 Extract the discover information and boot server entry from the\r
687 cached packets if unspecified.\r
688\r
689 @param[in] Private Pointer to PxeBc private data.\r
690 @param[in] Type The type of bootstrap to perform.\r
9063c328 691 @param[in, out] DiscoverInfo Pointer to EFI_PXE_BASE_CODE_DISCOVER_INFO.\r
a3bcde70
HT
692 @param[out] BootEntry Pointer to PXEBC_BOOT_SVR_ENTRY.\r
693 @param[out] SrvList Pointer to EFI_PXE_BASE_CODE_SRVLIST.\r
694\r
695 @retval EFI_SUCCESS Successfully extracted the information.\r
696 @retval EFI_DEVICE_ERROR Failed to extract the information.\r
697\r
698**/\r
699EFI_STATUS\r
700PxeBcExtractDiscoverInfo (\r
701 IN PXEBC_PRIVATE_DATA *Private,\r
702 IN UINT16 Type,\r
9063c328 703 IN OUT EFI_PXE_BASE_CODE_DISCOVER_INFO **DiscoverInfo,\r
a3bcde70
HT
704 OUT PXEBC_BOOT_SVR_ENTRY **BootEntry,\r
705 OUT EFI_PXE_BASE_CODE_SRVLIST **SrvList\r
706 )\r
707{\r
708 EFI_PXE_BASE_CODE_MODE *Mode;\r
709 PXEBC_DHCP4_PACKET_CACHE *Cache4;\r
710 PXEBC_VENDOR_OPTION *VendorOpt;\r
711 PXEBC_BOOT_SVR_ENTRY *Entry;\r
712 BOOLEAN IsFound;\r
9063c328 713 EFI_PXE_BASE_CODE_DISCOVER_INFO *Info;\r
714 UINT16 Index;\r
a3bcde70
HT
715\r
716 Mode = Private->PxeBc.Mode;\r
9063c328 717 Info = *DiscoverInfo;\r
a3bcde70
HT
718\r
719 if (Mode->UsingIpv6) {\r
720 Info->IpCnt = 1;\r
721 Info->UseUCast = TRUE;\r
722\r
723 Info->SrvList[0].Type = Type;\r
724 Info->SrvList[0].AcceptAnyResponse = FALSE;\r
725\r
726 //\r
727 // There is no vendor options specified in DHCPv6, so take BootFileUrl in the last cached packet.\r
728 //\r
729 CopyMem (&Info->SrvList[0].IpAddr, &Private->ServerIp, sizeof (EFI_IP_ADDRESS));\r
730\r
731 *SrvList = Info->SrvList;\r
732 } else {\r
733 Entry = NULL;\r
734 IsFound = FALSE;\r
735 Cache4 = (Mode->ProxyOfferReceived) ? &Private->ProxyOffer.Dhcp4 : &Private->DhcpAck.Dhcp4;\r
736 VendorOpt = &Cache4->VendorOpt;\r
737\r
738 if (!Mode->DhcpAckReceived || !IS_VALID_DISCOVER_VENDOR_OPTION (VendorOpt->BitMap)) {\r
739 //\r
740 // Address is not acquired or no discovery options.\r
741 //\r
742 return EFI_INVALID_PARAMETER;\r
743 }\r
744\r
745 //\r
746 // Parse the boot server entry from the vendor option in the last cached packet.\r
747 //\r
748 Info->UseMCast = (BOOLEAN) !IS_DISABLE_MCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r
749 Info->UseBCast = (BOOLEAN) !IS_DISABLE_BCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r
750 Info->MustUseList = (BOOLEAN) IS_ENABLE_USE_SERVER_LIST (VendorOpt->DiscoverCtrl);\r
9063c328 751 Info->UseUCast = (BOOLEAN) IS_VALID_BOOT_SERVERS (VendorOpt->BitMap);\r
a3bcde70
HT
752\r
753 if (Info->UseMCast) {\r
754 //\r
755 // Get the multicast discover ip address from vendor option if has.\r
756 //\r
757 CopyMem (&Info->ServerMCastIp.v4, &VendorOpt->DiscoverMcastIp, sizeof (EFI_IPv4_ADDRESS));\r
758 }\r
759\r
760 Info->IpCnt = 0;\r
761\r
9063c328 762 if (Info->UseUCast) {\r
a3bcde70
HT
763 Entry = VendorOpt->BootSvr;\r
764\r
765 while (((UINT8) (Entry - VendorOpt->BootSvr)) < VendorOpt->BootSvrLen) {\r
766 if (Entry->Type == HTONS (Type)) {\r
767 IsFound = TRUE;\r
768 break;\r
769 }\r
770 Entry = GET_NEXT_BOOT_SVR_ENTRY (Entry);\r
771 }\r
772\r
773 if (!IsFound) {\r
774 return EFI_DEVICE_ERROR;\r
775 }\r
776\r
777 Info->IpCnt = Entry->IpCnt;\r
9063c328 778 if (Info->IpCnt >= 1) {\r
779 *DiscoverInfo = AllocatePool (sizeof (*Info) + (Info->IpCnt - 1) * sizeof (**SrvList));\r
780 if (*DiscoverInfo == NULL) {\r
781 return EFI_OUT_OF_RESOURCES; \r
782 } \r
783 CopyMem (*DiscoverInfo, Info, sizeof (*Info));\r
784 Info = *DiscoverInfo;\r
785 }\r
786\r
787 for (Index = 0; Index < Info->IpCnt; Index++) {\r
788 CopyMem (&Info->SrvList[Index].IpAddr, &Entry->IpAddr[Index], sizeof (EFI_IPv4_ADDRESS));\r
789 Info->SrvList[Index].AcceptAnyResponse = !Info->MustUseList;\r
790 Info->SrvList[Index].Type = NTOHS (Entry->Type);\r
791 }\r
a3bcde70
HT
792 }\r
793\r
794 *BootEntry = Entry;\r
9063c328 795 *SrvList = Info->SrvList;\r
a3bcde70
HT
796 }\r
797\r
798 return EFI_SUCCESS;\r
799}\r
800\r
801\r
802/**\r
803 Build the discover packet and send out for boot server.\r
804\r
805 @param[in] Private Pointer to PxeBc private data.\r
806 @param[in] Type PxeBc option boot item type.\r
807 @param[in] Layer Pointer to option boot item layer.\r
808 @param[in] UseBis Use BIS or not.\r
809 @param[in] DestIp Pointer to the destination address.\r
810 @param[in] IpCount The count of the server address.\r
811 @param[in] SrvList Pointer to the server address list.\r
812\r
813 @retval EFI_SUCCESS Successfully discovered boot file.\r
814 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource.\r
815 @retval EFI_NOT_FOUND Can't get the PXE reply packet.\r
816 @retval Others Failed to discover boot file.\r
817\r
818**/\r
819EFI_STATUS\r
820PxeBcDiscoverBootServer (\r
821 IN PXEBC_PRIVATE_DATA *Private,\r
822 IN UINT16 Type,\r
823 IN UINT16 *Layer,\r
824 IN BOOLEAN UseBis,\r
825 IN EFI_IP_ADDRESS *DestIp,\r
826 IN UINT16 IpCount,\r
827 IN EFI_PXE_BASE_CODE_SRVLIST *SrvList\r
828 )\r
829{\r
830 if (Private->PxeBc.Mode->UsingIpv6) {\r
831 return PxeBcDhcp6Discover (\r
832 Private,\r
833 Type,\r
834 Layer,\r
835 UseBis,\r
836 DestIp\r
837 );\r
838 } else {\r
839 return PxeBcDhcp4Discover (\r
840 Private,\r
841 Type,\r
842 Layer,\r
843 UseBis,\r
844 DestIp,\r
845 IpCount,\r
846 SrvList\r
847 );\r
848 }\r
849}\r
850\r
851\r
852/**\r
853 Discover all the boot information for boot file.\r
854\r
855 @param[in, out] Private Pointer to PxeBc private data.\r
856 @param[out] BufferSize Size of the boot file to be downloaded.\r
857\r
858 @retval EFI_SUCCESS Successfully obtained all the boot information .\r
859 @retval EFI_BUFFER_TOO_SMALL The buffer size is not enough for boot file.\r
860 @retval EFI_ABORTED User cancel current operation.\r
861 @retval Others Failed to parse out the boot information.\r
862\r
863**/\r
864EFI_STATUS\r
865PxeBcDiscoverBootFile (\r
866 IN OUT PXEBC_PRIVATE_DATA *Private,\r
867 OUT UINT64 *BufferSize\r
868 )\r
869{\r
870 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
871 EFI_PXE_BASE_CODE_MODE *Mode;\r
872 EFI_STATUS Status;\r
873 UINT16 Type;\r
874 UINT16 Layer;\r
875 BOOLEAN UseBis;\r
876\r
877 PxeBc = &Private->PxeBc;\r
878 Mode = PxeBc->Mode;\r
879 Type = EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP;\r
880 Layer = EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL;\r
881\r
882 //\r
883 // Start D.O.R.A/S.A.R.R exchange to acquire station ip address and\r
884 // other pxe boot information.\r
885 //\r
886 Status = PxeBc->Dhcp (PxeBc, TRUE);\r
887 if (EFI_ERROR (Status)) {\r
888 return Status;\r
889 }\r
890\r
891 //\r
892 // Select a boot server from boot server list.\r
893 //\r
894 Status = PxeBcSelectBootPrompt (Private);\r
895\r
896 if (Status == EFI_SUCCESS) {\r
897 //\r
898 // Choose by user's input.\r
899 //\r
9063c328 900 Status = PxeBcSelectBootMenu (Private, &Type, FALSE);\r
a3bcde70
HT
901 } else if (Status == EFI_TIMEOUT) {\r
902 //\r
903 // Choose by default item.\r
904 //\r
9063c328 905 Status = PxeBcSelectBootMenu (Private, &Type, TRUE);\r
a3bcde70
HT
906 }\r
907\r
908 if (!EFI_ERROR (Status)) {\r
909\r
910 if (Type == EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP) {\r
911 //\r
912 // Local boot(PXE bootstrap server) need abort\r
913 //\r
914 return EFI_ABORTED;\r
915 }\r
916\r
917 //\r
918 // Start to discover the boot server to get (m)tftp server ip address, bootfile\r
919 // name and bootfile size.\r
920 //\r
921 UseBis = (BOOLEAN) (Mode->BisSupported && Mode->BisDetected);\r
922 Status = PxeBc->Discover (PxeBc, Type, &Layer, UseBis, NULL);\r
923 if (EFI_ERROR (Status)) {\r
924 return Status;\r
925 }\r
9063c328 926\r
927 if (Mode->PxeReplyReceived && !Mode->ProxyOfferReceived) {\r
928 //\r
929 // Some network boot loader only search the packet in Mode.ProxyOffer to get its server\r
930 // IP address, so we need to store a copy of Mode.PxeReply packet into Mode.ProxyOffer.\r
931 //\r
932 if (Mode->UsingIpv6) {\r
933 CopyMem (\r
934 &Mode->ProxyOffer.Dhcpv6,\r
935 &Mode->PxeReply.Dhcpv6,\r
936 Private->PxeReply.Dhcp6.Packet.Ack.Length\r
937 );\r
938 } else {\r
939 CopyMem (\r
940 &Mode->ProxyOffer.Dhcpv4,\r
941 &Mode->PxeReply.Dhcpv4,\r
942 Private->PxeReply.Dhcp4.Packet.Ack.Length\r
943 ); \r
944 }\r
945 Mode->ProxyOfferReceived = TRUE;\r
946 }\r
a3bcde70
HT
947 }\r
948\r
949 //\r
950 // Parse the boot information.\r
951 //\r
952 if (Mode->UsingIpv6) {\r
953 Status = PxeBcDhcp6BootInfo (Private, BufferSize);\r
954 } else {\r
955 Status = PxeBcDhcp4BootInfo (Private, BufferSize);\r
956 }\r
957\r
958 return Status;\r
959}\r
960\r
961\r
962/**\r
963 Install PxeBaseCodeCallbackProtocol if not installed before.\r
964\r
965 @param[in, out] Private Pointer to PxeBc private data.\r
966 @param[out] NewMakeCallback If TRUE, it is a new callback.\r
967 Otherwise, it is not new callback.\r
968 @retval EFI_SUCCESS PxeBaseCodeCallbackProtocol installed succesfully.\r
969 @retval Others Failed to install PxeBaseCodeCallbackProtocol.\r
970\r
971**/\r
972EFI_STATUS\r
973PxeBcInstallCallback (\r
974 IN OUT PXEBC_PRIVATE_DATA *Private,\r
975 OUT BOOLEAN *NewMakeCallback\r
976 )\r
977{\r
978 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
979 EFI_STATUS Status;\r
980\r
981 //\r
982 // Check whether PxeBaseCodeCallbackProtocol already installed.\r
983 //\r
984 PxeBc = &Private->PxeBc;\r
985 Status = gBS->HandleProtocol (\r
986 Private->Controller,\r
987 &gEfiPxeBaseCodeCallbackProtocolGuid,\r
988 (VOID **) &Private->PxeBcCallback\r
989 );\r
990 if (Status == EFI_UNSUPPORTED) {\r
991\r
992 CopyMem (\r
993 &Private->LoadFileCallback,\r
994 &gPxeBcCallBackTemplate,\r
995 sizeof (EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL)\r
996 );\r
997\r
998 //\r
999 // Install a default callback if user didn't offer one.\r
1000 //\r
1001 Status = gBS->InstallProtocolInterface (\r
1002 &Private->Controller,\r
1003 &gEfiPxeBaseCodeCallbackProtocolGuid,\r
1004 EFI_NATIVE_INTERFACE,\r
1005 &Private->LoadFileCallback\r
1006 );\r
1007\r
1008 (*NewMakeCallback) = (BOOLEAN) (Status == EFI_SUCCESS);\r
1009\r
1010 Status = PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, NewMakeCallback);\r
1011 if (EFI_ERROR (Status)) {\r
1012 PxeBc->Stop (PxeBc);\r
1013 return Status;\r
1014 }\r
1015 }\r
1016\r
1017 return EFI_SUCCESS;\r
1018}\r
1019\r
1020\r
1021/**\r
1022 Uninstall PxeBaseCodeCallbackProtocol.\r
1023\r
1024 @param[in] Private Pointer to PxeBc private data.\r
1025 @param[in] NewMakeCallback If TRUE, it is a new callback.\r
1026 Otherwise, it is not new callback.\r
1027\r
1028**/\r
1029VOID\r
1030PxeBcUninstallCallback (\r
1031 IN PXEBC_PRIVATE_DATA *Private,\r
1032 IN BOOLEAN NewMakeCallback\r
1033 )\r
1034{\r
1035 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
1036\r
1037 PxeBc = &Private->PxeBc;\r
1038\r
1039 if (NewMakeCallback) {\r
1040\r
1041 NewMakeCallback = FALSE;\r
1042\r
1043 PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);\r
1044\r
1045 gBS->UninstallProtocolInterface (\r
1046 Private->Controller,\r
1047 &gEfiPxeBaseCodeCallbackProtocolGuid,\r
1048 &Private->LoadFileCallback\r
1049 );\r
1050 }\r
1051}\r
1052\r
1053\r
1054/**\r
1055 Download one of boot file in the list, and it's special for IPv6.\r
1056\r
1057 @param[in] Private Pointer to PxeBc private data.\r
1058 @param[in, out] BufferSize Size of user buffer for input;\r
1059 required buffer size for output.\r
1060 @param[in] Buffer Pointer to user buffer.\r
1061\r
1062 @retval EFI_SUCCESS Read one of boot file in the list successfully.\r
1063 @retval EFI_BUFFER_TOO_SMALL The buffer size is not enough for boot file.\r
1064 @retval EFI_NOT_FOUND There is no proper boot file available.\r
1065 @retval Others Failed to download boot file in the list.\r
1066\r
1067**/\r
1068EFI_STATUS\r
1069PxeBcReadBootFileList (\r
1070 IN PXEBC_PRIVATE_DATA *Private,\r
1071 IN OUT UINT64 *BufferSize,\r
1072 IN VOID *Buffer OPTIONAL\r
1073 )\r
1074{\r
1075 EFI_STATUS Status;\r
1076 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
1077\r
1078 PxeBc = &Private->PxeBc;\r
1079\r
1080 //\r
1081 // Try to download the boot file if everything is ready.\r
1082 //\r
1083 if (Buffer != NULL) {\r
1084 Status = PxeBc->Mtftp (\r
1085 PxeBc,\r
1086 EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r
1087 Buffer,\r
1088 FALSE,\r
1089 BufferSize,\r
1090 &Private->BlockSize,\r
1091 &Private->ServerIp,\r
1092 Private->BootFileName,\r
1093 NULL,\r
1094 FALSE\r
1095 );\r
1096\r
1097\r
1098 } else {\r
1099 Status = EFI_BUFFER_TOO_SMALL;\r
1100 }\r
1101\r
1102 return Status;\r
1103}\r
1104\r
1105\r
1106/**\r
1107 Load boot file into user buffer.\r
1108\r
1109 @param[in] Private Pointer to PxeBc private data.\r
1110 @param[in, out] BufferSize Size of user buffer for input;\r
1111 required buffer size for output.\r
1112 @param[in] Buffer Pointer to user buffer.\r
1113\r
1114 @retval EFI_SUCCESS Get all the boot information successfully.\r
1115 @retval EFI_BUFFER_TOO_SMALL The buffer size is not enough for boot file.\r
1116 @retval EFI_ABORTED User cancelled the current operation.\r
1117 @retval Others Failed to parse out the boot information.\r
1118\r
1119**/\r
1120EFI_STATUS\r
1121PxeBcLoadBootFile (\r
1122 IN PXEBC_PRIVATE_DATA *Private,\r
1123 IN OUT UINTN *BufferSize,\r
1124 IN VOID *Buffer OPTIONAL\r
1125 )\r
1126{\r
1127 BOOLEAN NewMakeCallback;\r
1128 UINT64 RequiredSize;\r
1129 UINT64 CurrentSize;\r
1130 EFI_STATUS Status;\r
1131 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r
1132 EFI_PXE_BASE_CODE_MODE *PxeBcMode;\r
1133\r
1134 NewMakeCallback = FALSE;\r
1135 PxeBc = &Private->PxeBc;\r
1136 PxeBcMode = &Private->Mode;\r
1137 CurrentSize = *BufferSize;\r
1138 RequiredSize = 0;\r
1139\r
1140 //\r
1141 // Install pxebc callback protocol if hasn't been installed yet.\r
1142 //\r
1143 Status = PxeBcInstallCallback (Private, &NewMakeCallback);\r
1144 if (EFI_ERROR(Status)) {\r
1145 return Status;\r
1146 }\r
1147\r
1148 if (Private->BootFileSize == 0) {\r
1149 //\r
1150 // Discover the boot information about the bootfile if hasn't.\r
1151 //\r
1152 Status = PxeBcDiscoverBootFile (Private, &RequiredSize);\r
278c6019 1153 if (EFI_ERROR (Status)) {\r
1154 goto ON_EXIT;\r
1155 }\r
a3bcde70
HT
1156\r
1157 if (PXEBC_IS_SIZE_OVERFLOWED (RequiredSize)) {\r
1158 //\r
1159 // It's error if the required buffer size is beyond the system scope.\r
1160 //\r
1161 Status = EFI_DEVICE_ERROR;\r
1162 goto ON_EXIT;\r
1163 } else if (RequiredSize > 0) {\r
1164 //\r
1165 // Get the right buffer size of the bootfile required.\r
1166 //\r
1167 if (CurrentSize < RequiredSize || Buffer == NULL) {\r
1168 //\r
1169 // It's buffer too small if the size of user buffer is smaller than the required.\r
1170 //\r
1171 CurrentSize = RequiredSize;\r
1172 Status = EFI_BUFFER_TOO_SMALL;\r
1173 goto ON_EXIT;\r
1174 }\r
1175 CurrentSize = RequiredSize;\r
1176 } else if (RequiredSize == 0 && PxeBcMode->UsingIpv6) {\r
1177 //\r
1178 // Try to download another bootfile in list if failed to get the filesize of the last one.\r
1179 // It's special for the case of IPv6.\r
1180 //\r
1181 Status = PxeBcReadBootFileList (Private, &CurrentSize, Buffer);\r
1182 goto ON_EXIT;\r
1183 }\r
1184 } else if (CurrentSize < Private->BootFileSize || Buffer == NULL ) {\r
1185 //\r
1186 // It's buffer too small if the size of user buffer is smaller than the required.\r
1187 //\r
1188 CurrentSize = Private->BootFileSize;\r
1189 Status = EFI_BUFFER_TOO_SMALL;\r
1190 goto ON_EXIT;\r
1191 }\r
1192\r
1193 //\r
1194 // Begin to download the bootfile if everything is ready.\r
1195 //\r
1196 AsciiPrint ("\n Downloading NBP file...\n");\r
1197 if (PxeBcMode->UsingIpv6) {\r
1198 Status = PxeBcReadBootFileList (\r
1199 Private,\r
1200 &CurrentSize,\r
1201 Buffer\r
1202 );\r
1203 } else {\r
1204 Status = PxeBc->Mtftp (\r
1205 PxeBc,\r
1206 EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r
1207 Buffer,\r
1208 FALSE,\r
1209 &CurrentSize,\r
1210 &Private->BlockSize,\r
1211 &Private->ServerIp,\r
1212 Private->BootFileName,\r
1213 NULL,\r
1214 FALSE\r
1215 );\r
1216 }\r
1217\r
1218ON_EXIT:\r
1219 *BufferSize = (UINTN) CurrentSize;\r
1220 PxeBcUninstallCallback(Private, NewMakeCallback);\r
1221\r
1222 if (Status == EFI_SUCCESS) {\r
1223 AsciiPrint ("\n Succeed to download NBP file.\n");\r
1224 return EFI_SUCCESS;\r
1225 } else if (Status == EFI_BUFFER_TOO_SMALL && Buffer != NULL) {\r
1226 AsciiPrint ("\n PXE-E05: Buffer size is smaller than the requested file.\n");\r
1227 } else if (Status == EFI_DEVICE_ERROR) {\r
1228 AsciiPrint ("\n PXE-E07: Network device error.\n");\r
1229 } else if (Status == EFI_OUT_OF_RESOURCES) {\r
1230 AsciiPrint ("\n PXE-E09: Could not allocate I/O buffers.\n");\r
1231 } else if (Status == EFI_NO_MEDIA) {\r
1232 AsciiPrint ("\n PXE-E12: Could not detect network connection.\n");\r
1233 } else if (Status == EFI_NO_RESPONSE) {\r
1234 AsciiPrint ("\n PXE-E16: No offer received.\n");\r
1235 } else if (Status == EFI_TIMEOUT) {\r
1236 AsciiPrint ("\n PXE-E18: Server response timeout.\n");\r
1237 } else if (Status == EFI_ABORTED) {\r
1238 AsciiPrint ("\n PXE-E21: Remote boot cancelled.\n");\r
1239 } else if (Status == EFI_ICMP_ERROR) {\r
1240 AsciiPrint ("\n PXE-E22: Client received ICMP error from server.\n");\r
1241 } else if (Status == EFI_TFTP_ERROR) {\r
1242 AsciiPrint ("\n PXE-E23: Client received TFTP error from server.\n");\r
4496ff75 1243 } else if (Status == EFI_NOT_FOUND) {\r
1244 AsciiPrint ("\n PXE-E53: No boot filename received.\n");\r
a3bcde70
HT
1245 } else if (Status != EFI_BUFFER_TOO_SMALL) {\r
1246 AsciiPrint ("\n PXE-E99: Unexpected network error.\n");\r
1247 }\r
1248\r
1249 return Status;\r
1250}\r
1251\r