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