]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
a9c86dc042bf1c2672843af73245a5a65a9d06e7
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcDhcp.c
1 /** @file
2 Support for PxeBc dhcp functions.
3
4 Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15
16 #include "PxeBcImpl.h"
17
18 //
19 // This is a map from the interested DHCP4 option tags' index to the tag value.
20 //
21 UINT8 mInterestedDhcp4Tags[PXEBC_DHCP4_TAG_INDEX_MAX] = {
22 PXEBC_DHCP4_TAG_BOOTFILE_LEN,
23 PXEBC_DHCP4_TAG_VENDOR,
24 PXEBC_DHCP4_TAG_OVERLOAD,
25 PXEBC_DHCP4_TAG_MSG_TYPE,
26 PXEBC_DHCP4_TAG_SERVER_ID,
27 PXEBC_DHCP4_TAG_CLASS_ID,
28 PXEBC_DHCP4_TAG_BOOTFILE
29 };
30
31
32 /**
33 This function initialize the DHCP4 message instance.
34
35 This function will pad each item of dhcp4 message packet.
36
37 @param Seed Pointer to the message instance of the DHCP4 packet.
38 @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance.
39
40 **/
41 VOID
42 PxeBcInitSeedPacket (
43 IN EFI_DHCP4_PACKET *Seed,
44 IN EFI_UDP4_PROTOCOL *Udp4
45 )
46 {
47 EFI_SIMPLE_NETWORK_MODE Mode;
48 EFI_DHCP4_HEADER *Header;
49
50 Udp4->GetModeData (Udp4, NULL, NULL, NULL, &Mode);
51
52 Seed->Size = sizeof (EFI_DHCP4_PACKET);
53 Seed->Length = sizeof (Seed->Dhcp4);
54
55 Header = &Seed->Dhcp4.Header;
56
57 ZeroMem (Header, sizeof (EFI_DHCP4_HEADER));
58 Header->OpCode = PXEBC_DHCP4_OPCODE_REQUEST;
59 Header->HwType = Mode.IfType;
60 Header->HwAddrLen = (UINT8) Mode.HwAddressSize;
61 CopyMem (Header->ClientHwAddr, &Mode.CurrentAddress, Header->HwAddrLen);
62
63 Seed->Dhcp4.Magik = PXEBC_DHCP4_MAGIC;
64 Seed->Dhcp4.Option[0] = PXEBC_DHCP4_TAG_EOP;
65 }
66
67
68 /**
69 Copy the DCHP4 packet from srouce to destination.
70
71 @param Dst Pointer to the EFI_DHCP4_PROTOCOL instance.
72 @param Src Pointer to the EFI_DHCP4_PROTOCOL instance.
73
74 **/
75 VOID
76 PxeBcCopyEfiDhcp4Packet (
77 IN EFI_DHCP4_PACKET *Dst,
78 IN EFI_DHCP4_PACKET *Src
79 )
80 {
81 ASSERT (Dst->Size >= Src->Length);
82
83 CopyMem (&Dst->Dhcp4, &Src->Dhcp4, Src->Length);
84 Dst->Length = Src->Length;
85 }
86
87
88 /**
89 Copy the dhcp4 packet to the PxeBc private data and parse the dhcp4 packet.
90
91 @param Private Pointer to PxeBc private data.
92 @param OfferIndex Index of cached packets as complements of pxe mode data,
93 the index is maximum offer number.
94
95 **/
96 VOID
97 PxeBcCopyProxyOffer (
98 IN PXEBC_PRIVATE_DATA *Private,
99 IN UINT32 OfferIndex
100 )
101 {
102 EFI_PXE_BASE_CODE_MODE *Mode;
103 EFI_DHCP4_PACKET *Offer;
104
105 ASSERT (OfferIndex < Private->NumOffers);
106 ASSERT (OfferIndex < PXEBC_MAX_OFFER_NUM);
107
108 Mode = Private->PxeBc.Mode;
109 Offer = &Private->Dhcp4Offers[OfferIndex].Packet.Offer;
110
111 PxeBcCopyEfiDhcp4Packet (&Private->ProxyOffer.Packet.Offer, Offer);
112 CopyMem (&Mode->ProxyOffer, &Offer->Dhcp4, Offer->Length);
113 Mode->ProxyOfferReceived = TRUE;
114
115 PxeBcParseCachedDhcpPacket (&Private->ProxyOffer);
116 }
117
118
119 /**
120 Parse the cached dhcp packet.
121
122 @param CachedPacket Pointer to cached dhcp packet.
123
124 @retval TRUE Succeed to parse and validation.
125 @retval FALSE Fail to parse or validation.
126
127 **/
128 BOOLEAN
129 PxeBcParseCachedDhcpPacket (
130 IN PXEBC_CACHED_DHCP4_PACKET *CachedPacket
131 )
132 {
133 EFI_DHCP4_PACKET *Offer;
134 EFI_DHCP4_PACKET_OPTION **Options;
135 EFI_DHCP4_PACKET_OPTION *Option;
136 UINT8 OfferType;
137 UINTN Index;
138 UINT8 *Ptr8;
139
140 CachedPacket->IsPxeOffer = FALSE;
141 ZeroMem (CachedPacket->Dhcp4Option, sizeof (CachedPacket->Dhcp4Option));
142 ZeroMem (&CachedPacket->PxeVendorOption, sizeof (CachedPacket->PxeVendorOption));
143
144 Offer = &CachedPacket->Packet.Offer;
145 Options = CachedPacket->Dhcp4Option;
146
147 //
148 // Parse interested dhcp options and store their pointers in CachedPacket->Dhcp4Option.
149 //
150 for (Index = 0; Index < PXEBC_DHCP4_TAG_INDEX_MAX; Index++) {
151 Options[Index] = PxeBcParseExtendOptions (
152 Offer->Dhcp4.Option,
153 GET_OPTION_BUFFER_LEN (Offer),
154 mInterestedDhcp4Tags[Index]
155 );
156 }
157
158 //
159 // Check whether is an offer with PXEClient or not.
160 //
161 Option = Options[PXEBC_DHCP4_TAG_INDEX_CLASS_ID];
162 if ((Option != NULL) && (Option->Length >= 9) &&
163 (CompareMem (Option->Data, DEFAULT_CLASS_ID_DATA, 9) == 0)) {
164
165 CachedPacket->IsPxeOffer = TRUE;
166 }
167
168 //
169 // Parse pxe vendor options and store their content/pointers in CachedPacket->PxeVendorOption.
170 //
171 Option = Options[PXEBC_DHCP4_TAG_INDEX_VENDOR];
172 if (CachedPacket->IsPxeOffer && (Option != NULL)) {
173
174 if (!PxeBcParseVendorOptions (Option, &CachedPacket->PxeVendorOption)) {
175 return FALSE;
176 }
177 }
178
179 //
180 // Check whether bootfilename/serverhostname overloaded (See details in dhcp spec).
181 // If overloaded, parse this buffer as nested dhcp options, or just parse bootfilename/
182 // serverhostname option.
183 //
184 Option = Options[PXEBC_DHCP4_TAG_INDEX_OVERLOAD];
185 if ((Option != NULL) && ((Option->Data[0] & PXEBC_DHCP4_OVERLOAD_FILE) != 0)) {
186
187 Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = PxeBcParseExtendOptions (
188 (UINT8 *) Offer->Dhcp4.Header.BootFileName,
189 sizeof (Offer->Dhcp4.Header.BootFileName),
190 PXEBC_DHCP4_TAG_BOOTFILE
191 );
192 //
193 // RFC 2132, Section 9.5 does not strictly state Bootfile name (option 67) is null
194 // terminated string. So force to append null terminated character at the end of string.
195 //
196 if (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {
197 Ptr8 = (UINT8*)&Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data[0];
198 Ptr8 += Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Length;
199 *Ptr8 = '\0';
200 }
201
202 } else if ((Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL) &&
203 (Offer->Dhcp4.Header.BootFileName[0] != 0)) {
204 //
205 // If the bootfile is not present and bootfilename is present in dhcp packet, just parse it.
206 // And do not count dhcp option header, or else will destory the serverhostname.
207 //
208 Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] = (EFI_DHCP4_PACKET_OPTION *) (&Offer->Dhcp4.Header.BootFileName[0] -
209 OFFSET_OF (EFI_DHCP4_PACKET_OPTION, Data[0]));
210
211 }
212
213 //
214 // Determine offer type of the dhcp packet.
215 //
216 Option = Options[PXEBC_DHCP4_TAG_INDEX_MSG_TYPE];
217 if ((Option == NULL) || (Option->Data[0] == 0)) {
218 //
219 // It's a bootp offer
220 //
221 Option = CachedPacket->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE];
222 if (Option == NULL) {
223 //
224 // bootp offer without bootfilename, discard it.
225 //
226 return FALSE;
227 }
228
229 OfferType = DHCP4_PACKET_TYPE_BOOTP;
230
231 } else {
232
233 if (IS_VALID_DISCOVER_VENDOR_OPTION (CachedPacket->PxeVendorOption.BitMap)) {
234 //
235 // It's a pxe10 offer with PXEClient and discover vendor option.
236 //
237 OfferType = DHCP4_PACKET_TYPE_PXE10;
238 } else if (IS_VALID_MTFTP_VENDOR_OPTION (CachedPacket->PxeVendorOption.BitMap)) {
239 //
240 // It's a wfm11a offer with PXEClient and mtftp vendor option, and
241 // return false since mtftp not supported currently.
242 //
243 return FALSE;
244 } else {
245 //
246 // If the binl offer with only PXEClient.
247 //
248 OfferType = (UINT8) ((CachedPacket->IsPxeOffer) ? DHCP4_PACKET_TYPE_BINL : DHCP4_PACKET_TYPE_DHCP_ONLY);
249 }
250 }
251
252 CachedPacket->OfferType = OfferType;
253
254 return TRUE;
255 }
256
257
258 /**
259 Offer dhcp service with a BINL dhcp offer.
260
261 @param Private Pointer to PxeBc private data.
262 @param Index Index of cached packets as complements of pxe mode data,
263 the index is maximum offer number.
264
265 @retval TRUE Offer the service successfully under priority BINL.
266 @retval FALSE Boot Service failed, parse cached dhcp packet failed or this
267 BINL ack cannot find options set or bootfile name specified.
268
269 **/
270 BOOLEAN
271 PxeBcTryBinl (
272 IN PXEBC_PRIVATE_DATA *Private,
273 IN UINT32 Index
274 )
275 {
276 EFI_DHCP4_PACKET *Offer;
277 EFI_IP_ADDRESS ServerIp;
278 EFI_STATUS Status;
279 PXEBC_CACHED_DHCP4_PACKET *CachedPacket;
280 EFI_DHCP4_PACKET *Reply;
281
282 ASSERT (Index < PXEBC_MAX_OFFER_NUM);
283 ASSERT (Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_BINL);
284
285 Offer = &Private->Dhcp4Offers[Index].Packet.Offer;
286
287 //
288 // Use siaddr(next server) in DHCPOFFER packet header, if zero, use option 54(server identifier)
289 // in DHCPOFFER packet.
290 // (It does not comply with PXE Spec, Ver2.1)
291 //
292 if (EFI_IP4_EQUAL (&Offer->Dhcp4.Header.ServerAddr.Addr, &mZeroIp4Addr)) {
293 CopyMem (
294 &ServerIp.Addr[0],
295 Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER_ID]->Data,
296 sizeof (EFI_IPv4_ADDRESS)
297 );
298 } else {
299 CopyMem (
300 &ServerIp.Addr[0],
301 &Offer->Dhcp4.Header.ServerAddr,
302 sizeof (EFI_IPv4_ADDRESS)
303 );
304 }
305 if (ServerIp.Addr[0] == 0) {
306 return FALSE;
307 }
308
309 CachedPacket = &Private->ProxyOffer;
310 Reply = &CachedPacket->Packet.Offer;
311
312 Status = PxeBcDiscvBootService (
313 Private,
314 0,
315 NULL,
316 FALSE,
317 &ServerIp,
318 0,
319 NULL,
320 FALSE,
321 Reply
322 );
323 if (EFI_ERROR (Status)) {
324 return FALSE;
325 }
326
327 if (!PxeBcParseCachedDhcpPacket (CachedPacket)) {
328 return FALSE;
329 }
330
331 if ((CachedPacket->OfferType != DHCP4_PACKET_TYPE_PXE10) &&
332 (CachedPacket->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL)) {
333 //
334 // This BINL ack doesn't have discovery options set or bootfile name
335 // specified.
336 //
337 return FALSE;
338 }
339
340 Private->PxeBc.Mode->ProxyOfferReceived = TRUE;
341 CopyMem (&Private->PxeBc.Mode->ProxyOffer, &Reply->Dhcp4, Reply->Length);
342
343 return TRUE;
344 }
345
346
347 /**
348 Offer dhcp service for each proxy with a BINL dhcp offer.
349
350 @param Private Pointer to PxeBc private data
351 @param OfferIndex Pointer to the index of cached packets as complements of
352 pxe mode data, the index is maximum offer number.
353
354 @return If there is no service needed offer return FALSE, otherwise TRUE.
355
356 **/
357 BOOLEAN
358 PxeBcTryBinlProxy (
359 IN PXEBC_PRIVATE_DATA *Private,
360 OUT UINT32 *OfferIndex
361 )
362 {
363 UINT32 Index;
364
365 for (Index = 0; Index < Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]; Index++) {
366
367 *OfferIndex = Private->BinlIndex[Index];
368 //
369 // Try this BINL proxy offer
370 //
371 if (PxeBcTryBinl (Private, *OfferIndex)) {
372 return TRUE;
373 }
374 }
375
376 return FALSE;
377 }
378
379
380 /**
381 This function is to check the selected proxy offer (include BINL dhcp offer and
382 DHCP_ONLY offer ) and set the flag and copy the DHCP packets to the Pxe base code
383 mode structure.
384
385 @param Private Pointer to PxeBc private data.
386
387 @retval EFI_SUCCESS Operational successful.
388 @retval EFI_NO_RESPONSE Offer dhcp service failed.
389
390 **/
391 EFI_STATUS
392 PxeBcCheckSelectedOffer (
393 IN PXEBC_PRIVATE_DATA *Private
394 )
395 {
396 PXEBC_CACHED_DHCP4_PACKET *SelectedOffer;
397 EFI_DHCP4_PACKET_OPTION **Options;
398 UINT32 Index;
399 EFI_DHCP4_PACKET *Offer;
400 UINT32 ProxyOfferIndex;
401 EFI_STATUS Status;
402 EFI_PXE_BASE_CODE_MODE *Mode;
403 EFI_DHCP4_PACKET *Ack;
404
405 ASSERT (Private->SelectedOffer != 0);
406
407 Status = EFI_SUCCESS;
408 SelectedOffer = &Private->Dhcp4Offers[Private->SelectedOffer - 1];
409 Options = SelectedOffer->Dhcp4Option;
410
411 if (SelectedOffer->OfferType == DHCP4_PACKET_TYPE_BINL) {
412 //
413 // The addresses are acquired from a BINL dhcp offer, try BINL to get
414 // the bootfile name
415 //
416 if (!PxeBcTryBinl (Private, Private->SelectedOffer - 1)) {
417 Status = EFI_NO_RESPONSE;
418 }
419 } else if (SelectedOffer->OfferType == DHCP4_PACKET_TYPE_DHCP_ONLY) {
420 //
421 // The selected offer to finish the D.O.R.A. is a DHCP only offer, we need
422 // try proxy offers if there are some, othewise the bootfile name must be
423 // set in this DHCP only offer.
424 //
425 if (Private->GotProxyOffer) {
426 //
427 // Get rid of the compiler warning.
428 //
429 ProxyOfferIndex = 0;
430 if (Private->SortOffers) {
431 //
432 // The offers are sorted before selecting, the proxy offer type must be
433 // already determined.
434 //
435 ASSERT (Private->ProxyIndex[Private->ProxyOfferType] > 0);
436
437 if (Private->ProxyOfferType == DHCP4_PACKET_TYPE_BINL) {
438 //
439 // We buffer all received BINL proxy offers, try them all one by one
440 //
441 if (!PxeBcTryBinlProxy (Private, &ProxyOfferIndex)) {
442 Status = EFI_NO_RESPONSE;
443 }
444 } else {
445 //
446 // For other types, only one proxy offer is buffered.
447 //
448 ProxyOfferIndex = Private->ProxyIndex[Private->ProxyOfferType] - 1;
449 }
450 } else {
451 //
452 // The proxy offer type is not determined, choose proxy offer in the
453 // received order.
454 //
455 Status = EFI_NO_RESPONSE;
456
457 for (Index = 0; Index < Private->NumOffers; Index++) {
458
459 Offer = &Private->Dhcp4Offers[Index].Packet.Offer;
460 if (!IS_PROXY_DHCP_OFFER (Offer)) {
461 //
462 // Skip non proxy dhcp offers.
463 //
464 continue;
465 }
466
467 if (Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_BINL) {
468 //
469 // Try BINL
470 //
471 if (!PxeBcTryBinl (Private, Index)) {
472 //
473 // Failed, skip to the next offer
474 //
475 continue;
476 }
477 }
478
479 Private->ProxyOfferType = Private->Dhcp4Offers[Index].OfferType;
480 ProxyOfferIndex = Index;
481 Status = EFI_SUCCESS;
482 break;
483 }
484 }
485
486 if (!EFI_ERROR (Status) && (Private->ProxyOfferType != DHCP4_PACKET_TYPE_BINL)) {
487 //
488 // Copy the proxy offer to Mode and set the flag
489 //
490 PxeBcCopyProxyOffer (Private, ProxyOfferIndex);
491 }
492 } else {
493 //
494 // No proxy offer is received, the bootfile name MUST be set.
495 //
496 ASSERT (Options[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL);
497 }
498 }
499
500 if (!EFI_ERROR (Status)) {
501 //
502 // Everything is OK, set the flag and copy the DHCP packets.
503 //
504 Mode = Private->PxeBc.Mode;
505 Offer = &SelectedOffer->Packet.Offer;
506
507 //
508 // The discover packet is already copied, just set flag here.
509 //
510 Mode->DhcpDiscoverValid = TRUE;
511
512 Ack = &Private->Dhcp4Ack.Packet.Ack;
513 if (SelectedOffer->OfferType == DHCP4_PACKET_TYPE_BOOTP) {
514 //
515 // Other type of ACK is already cached. Bootp is special that we should
516 // use the bootp reply as the ACK and put it into the DHCP_ONLY buffer.
517 //
518 PxeBcCopyEfiDhcp4Packet (&Private->Dhcp4Ack.Packet.Ack, Offer);
519 }
520
521 PxeBcParseCachedDhcpPacket (&Private->Dhcp4Ack);
522
523 Mode->DhcpAckReceived = TRUE;
524
525 //
526 // Copy the dhcp ack.
527 //
528 CopyMem (&Mode->DhcpAck, &Ack->Dhcp4, Ack->Length);
529 }
530
531 return Status;
532 }
533
534
535 /**
536 Cache the Dhcp4 packet offer, Parse and validate each option of the packet.
537
538 @param Private Pointer to PxeBc private data.
539 @param RcvdOffer Pointer to the received Dhcp proxy offer packet.
540
541 **/
542 VOID
543 PxeBcCacheDhcpOffer (
544 IN PXEBC_PRIVATE_DATA *Private,
545 IN EFI_DHCP4_PACKET *RcvdOffer
546 )
547 {
548 PXEBC_CACHED_DHCP4_PACKET *CachedOffer;
549 EFI_DHCP4_PACKET *Offer;
550 UINT8 OfferType;
551
552 CachedOffer = &Private->Dhcp4Offers[Private->NumOffers];
553 Offer = &CachedOffer->Packet.Offer;
554
555 //
556 // Cache the orignal dhcp packet
557 //
558 PxeBcCopyEfiDhcp4Packet (Offer, RcvdOffer);
559
560 //
561 // Parse and validate the options (including dhcp option and vendor option)
562 //
563 if (!PxeBcParseCachedDhcpPacket (CachedOffer)) {
564 return ;
565 }
566
567 OfferType = CachedOffer->OfferType;
568 ASSERT (OfferType < DHCP4_PACKET_TYPE_MAX);
569
570 if (OfferType == DHCP4_PACKET_TYPE_BOOTP) {
571
572 if (Private->BootpIndex != 0) {
573 //
574 // Only cache the first bootp offer, discard others.
575 //
576 return ;
577 } else {
578 //
579 // Take as a dhcp only offer, but record index specifically.
580 //
581 Private->BootpIndex = Private->NumOffers + 1;
582 }
583 } else {
584
585 if (IS_PROXY_DHCP_OFFER (Offer)) {
586 //
587 // It's a proxy dhcp offer with no your address, including pxe10, wfm11a or binl offer.
588 //
589 Private->GotProxyOffer = TRUE;
590
591 if (OfferType == DHCP4_PACKET_TYPE_BINL) {
592 //
593 // Cache all binl offers.
594 //
595 Private->BinlIndex[Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]] = Private->NumOffers;
596 Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]++;
597 } else if (Private->ProxyIndex[OfferType] != 0) {
598 //
599 // Only cache the first pxe10/wfm11a offers each, discard the others.
600 //
601 return ;
602 } else {
603 //
604 // Record index of the proxy dhcp offer with type other than binl.
605 //
606 Private->ProxyIndex[OfferType] = Private->NumOffers + 1;
607 }
608 } else {
609 //
610 // It's a dhcp offer with your address.
611 //
612 ASSERT (Private->ServerCount[OfferType] < PXEBC_MAX_OFFER_NUM);
613 Private->OfferIndex[OfferType][Private->ServerCount[OfferType]] = Private->NumOffers;
614 Private->ServerCount[OfferType]++;
615 }
616 }
617
618 //
619 // Count the accepted offers.
620 //
621 Private->NumOffers++;
622 }
623
624
625 /**
626 Select the specified proxy offer, such as BINL, DHCP_ONLY and so on.
627 If the proxy does not exist, try offers with bootfile.
628
629 @param Private Pointer to PxeBc private data.
630
631 **/
632 VOID
633 PxeBcSelectOffer (
634 IN PXEBC_PRIVATE_DATA *Private
635 )
636 {
637 UINT32 Index;
638 UINT32 OfferIndex;
639 EFI_DHCP4_PACKET *Offer;
640
641 Private->SelectedOffer = 0;
642
643 if (Private->SortOffers) {
644 //
645 // Select offer according to the priority
646 //
647 if (Private->ServerCount[DHCP4_PACKET_TYPE_PXE10] > 0) {
648 //
649 // DHCP with PXE10
650 //
651 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_PXE10][0] + 1;
652
653 } else if (Private->ServerCount[DHCP4_PACKET_TYPE_WFM11A] > 0) {
654 //
655 // DHCP with WfM
656 //
657 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_WFM11A][0] + 1;
658
659 } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_PXE10] > 0) &&
660 (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)
661 ) {
662 //
663 // DHCP only and proxy DHCP with PXE10
664 //
665 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;
666 Private->ProxyOfferType = DHCP4_PACKET_TYPE_PXE10;
667
668 } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_WFM11A] > 0) &&
669 (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)
670 ) {
671 //
672 // DHCP only and proxy DHCP with WfM
673 //
674 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;
675 Private->ProxyOfferType = DHCP4_PACKET_TYPE_WFM11A;
676
677 } else if (Private->ServerCount[DHCP4_PACKET_TYPE_BINL] > 0) {
678 //
679 // DHCP with BINL
680 //
681 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_BINL][0] + 1;
682
683 } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL] > 0) &&
684 (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)
685 ) {
686 //
687 // DHCP only and proxy DHCP with BINL
688 //
689 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;
690 Private->ProxyOfferType = DHCP4_PACKET_TYPE_BINL;
691
692 } else {
693 //
694 // Try offers with bootfile
695 //
696 for (Index = 0; Index < Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY]; Index++) {
697 //
698 // Select the first DHCP only offer with bootfile
699 //
700 OfferIndex = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][Index];
701 if (Private->Dhcp4Offers[OfferIndex].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {
702 Private->SelectedOffer = OfferIndex + 1;
703 break;
704 }
705 }
706
707 if (Private->SelectedOffer == 0) {
708 //
709 // Select the Bootp reply with bootfile if any
710 //
711 Private->SelectedOffer = Private->BootpIndex;
712 }
713 }
714 } else {
715 //
716 // Try the offers in the received order.
717 //
718 for (Index = 0; Index < Private->NumOffers; Index++) {
719
720 Offer = &Private->Dhcp4Offers[Index].Packet.Offer;
721
722 if (IS_PROXY_DHCP_OFFER (Offer)) {
723 //
724 // Skip proxy offers
725 //
726 continue;
727 }
728
729 if ((Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_DHCP_ONLY) &&
730 ((!Private->GotProxyOffer) && (Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL))) {
731 //
732 // DHCP only offer but no proxy offer received and no bootfile option in this offer
733 //
734 continue;
735 }
736
737 Private->SelectedOffer = Index + 1;
738 break;
739 }
740 }
741 }
742
743
744 /**
745 Callback routine.
746
747 EFI_DHCP4_CALLBACK is provided by the consumer of the EFI DHCPv4 Protocol driver
748 to intercept events that occurred in the configuration process. This structure
749 provides advanced control of each state transition of the DHCP process. The
750 returned status code determines the behavior of the EFI DHCPv4 Protocol driver.
751 There are three possible returned values, which are described in the following
752 table.
753
754 @param This Pointer to the EFI DHCPv4 Protocol instance that is used to
755 configure this callback function.
756 @param Context Pointer to the context that is initialized by
757 EFI_DHCP4_PROTOCOL.Configure().
758 @param CurrentState The current operational state of the EFI DHCPv4 Protocol
759 driver.
760 @param Dhcp4Event The event that occurs in the current state, which usually means a
761 state transition.
762 @param Packet The DHCP packet that is going to be sent or already received.
763 @param NewPacket The packet that is used to replace the above Packet.
764
765 @retval EFI_SUCCESS Tells the EFI DHCPv4 Protocol driver to continue the DHCP process.
766 @retval EFI_NOT_READY Only used in the Dhcp4Selecting state. The EFI DHCPv4 Protocol
767 driver will continue to wait for more DHCPOFFER packets until the retry
768 timeout expires.
769 @retval EFI_ABORTED Tells the EFI DHCPv4 Protocol driver to abort the current process and
770 return to the Dhcp4Init or Dhcp4InitReboot state.
771
772 **/
773 EFI_STATUS
774 EFIAPI
775 PxeBcDhcpCallBack (
776 IN EFI_DHCP4_PROTOCOL * This,
777 IN VOID *Context,
778 IN EFI_DHCP4_STATE CurrentState,
779 IN EFI_DHCP4_EVENT Dhcp4Event,
780 IN EFI_DHCP4_PACKET * Packet OPTIONAL,
781 OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL
782 )
783 {
784 PXEBC_PRIVATE_DATA *Private;
785 EFI_PXE_BASE_CODE_MODE *Mode;
786 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *Callback;
787 EFI_DHCP4_PACKET_OPTION *MaxMsgSize;
788 UINT16 Value;
789 EFI_STATUS Status;
790 BOOLEAN Received;
791 EFI_DHCP4_HEADER *DhcpHeader;
792
793 if ((Dhcp4Event != Dhcp4RcvdOffer) &&
794 (Dhcp4Event != Dhcp4SelectOffer) &&
795 (Dhcp4Event != Dhcp4SendDiscover) &&
796 (Dhcp4Event != Dhcp4RcvdAck) &&
797 (Dhcp4Event != Dhcp4SendRequest)) {
798 return EFI_SUCCESS;
799 }
800
801 Private = (PXEBC_PRIVATE_DATA *) Context;
802 Mode = Private->PxeBc.Mode;
803 Callback = Private->PxeBcCallback;
804
805 //
806 // Override the Maximum DHCP Message Size.
807 //
808 MaxMsgSize = PxeBcParseExtendOptions (
809 Packet->Dhcp4.Option,
810 GET_OPTION_BUFFER_LEN (Packet),
811 PXEBC_DHCP4_TAG_MAXMSG
812 );
813 if (MaxMsgSize != NULL) {
814 Value = HTONS (PXEBC_DHCP4_MAX_PACKET_SIZE);
815 CopyMem (MaxMsgSize->Data, &Value, sizeof (Value));
816 }
817
818 if ((Dhcp4Event != Dhcp4SelectOffer) && (Callback != NULL)) {
819 Received = (BOOLEAN) ((Dhcp4Event == Dhcp4RcvdOffer) || (Dhcp4Event == Dhcp4RcvdAck));
820 Status = Callback->Callback (
821 Callback,
822 Private->Function,
823 Received,
824 Packet->Length,
825 (EFI_PXE_BASE_CODE_PACKET *) &Packet->Dhcp4
826 );
827 if (Status != EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE) {
828 return EFI_ABORTED;
829 }
830 }
831
832 Status = EFI_SUCCESS;
833
834 switch (Dhcp4Event) {
835
836 case Dhcp4SendDiscover:
837 case Dhcp4SendRequest:
838 if (Mode->SendGUID) {
839 //
840 // send the system GUID instead of the MAC address as the hardware address
841 // in the DHCP packet header.
842 //
843 DhcpHeader = &Packet->Dhcp4.Header;
844
845 if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) {
846 //
847 // GUID not yet set - send all 0xff's to show programable (via SetVariable)
848 // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff);
849 // GUID not yet set - send all 0's to show not programable
850 //
851 ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID));
852 }
853
854 DhcpHeader->HwAddrLen = (UINT8) sizeof (EFI_GUID);
855 }
856
857 if (Dhcp4Event == Dhcp4SendDiscover) {
858 //
859 // Cache the dhcp discover packet, of which some information will be used later.
860 //
861 CopyMem (Mode->DhcpDiscover.Raw, &Packet->Dhcp4, Packet->Length);
862 }
863
864 break;
865
866 case Dhcp4RcvdOffer:
867 Status = EFI_NOT_READY;
868 if (Private->NumOffers < PXEBC_MAX_OFFER_NUM) {
869 //
870 // Cache the dhcp offers in Private->Dhcp4Offers[]
871 //
872 PxeBcCacheDhcpOffer (Private, Packet);
873 }
874
875 break;
876
877 case Dhcp4SelectOffer:
878 //
879 // Select an offer, if succeeded, Private->SelectedOffer points to
880 // the index of the selected one.
881 //
882 PxeBcSelectOffer (Private);
883
884 if (Private->SelectedOffer == 0) {
885 Status = EFI_ABORTED;
886 } else {
887 *NewPacket = &Private->Dhcp4Offers[Private->SelectedOffer - 1].Packet.Offer;
888 }
889
890 break;
891
892 case Dhcp4RcvdAck:
893 //
894 // Cache Ack
895 //
896 ASSERT (Private->SelectedOffer != 0);
897
898 PxeBcCopyEfiDhcp4Packet (&Private->Dhcp4Ack.Packet.Ack, Packet);
899 break;
900
901 default:
902 break;
903 }
904
905 return Status;
906 }
907
908
909 /**
910 Initialize the DHCP options and build the option list.
911
912 @param Private Pointer to PxeBc private data.
913 @param OptList Pointer to a DHCP option list.
914
915 @param IsDhcpDiscover Discover dhcp option or not.
916
917 @return The index item number of the option list.
918
919 **/
920 UINT32
921 PxeBcBuildDhcpOptions (
922 IN PXEBC_PRIVATE_DATA *Private,
923 IN EFI_DHCP4_PACKET_OPTION **OptList,
924 IN BOOLEAN IsDhcpDiscover
925 )
926 {
927 UINT32 Index;
928 PXEBC_DHCP4_OPTION_ENTRY OptEnt;
929 UINT16 Value;
930
931 Index = 0;
932 OptList[0] = (EFI_DHCP4_PACKET_OPTION *) Private->OptionBuffer;
933
934 if (!IsDhcpDiscover) {
935 //
936 // Append message type.
937 //
938 OptList[Index]->OpCode = PXEBC_DHCP4_TAG_MSG_TYPE;
939 OptList[Index]->Length = 1;
940 OptEnt.Mesg = (PXEBC_DHCP4_OPTION_MESG *) OptList[Index]->Data;
941 OptEnt.Mesg->Type = PXEBC_DHCP4_MSG_TYPE_REQUEST;
942 Index++;
943 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
944
945 //
946 // Append max message size.
947 //
948 OptList[Index]->OpCode = PXEBC_DHCP4_TAG_MAXMSG;
949 OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE);
950 OptEnt.MaxMesgSize = (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE *) OptList[Index]->Data;
951 Value = NTOHS (PXEBC_DHCP4_MAX_PACKET_SIZE);
952 CopyMem (&OptEnt.MaxMesgSize->Size, &Value, sizeof (UINT16));
953 Index++;
954 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
955 }
956 //
957 // Parameter request list option.
958 //
959 OptList[Index]->OpCode = PXEBC_DHCP4_TAG_PARA_LIST;
960 OptList[Index]->Length = 35;
961 OptEnt.Para = (PXEBC_DHCP4_OPTION_PARA *) OptList[Index]->Data;
962 OptEnt.Para->ParaList[0] = PXEBC_DHCP4_TAG_NETMASK;
963 OptEnt.Para->ParaList[1] = PXEBC_DHCP4_TAG_TIME_OFFSET;
964 OptEnt.Para->ParaList[2] = PXEBC_DHCP4_TAG_ROUTER;
965 OptEnt.Para->ParaList[3] = PXEBC_DHCP4_TAG_TIME_SERVER;
966 OptEnt.Para->ParaList[4] = PXEBC_DHCP4_TAG_NAME_SERVER;
967 OptEnt.Para->ParaList[5] = PXEBC_DHCP4_TAG_DNS_SERVER;
968 OptEnt.Para->ParaList[6] = PXEBC_DHCP4_TAG_HOSTNAME;
969 OptEnt.Para->ParaList[7] = PXEBC_DHCP4_TAG_BOOTFILE_LEN;
970 OptEnt.Para->ParaList[8] = PXEBC_DHCP4_TAG_DOMAINNAME;
971 OptEnt.Para->ParaList[9] = PXEBC_DHCP4_TAG_ROOTPATH;
972 OptEnt.Para->ParaList[10] = PXEBC_DHCP4_TAG_EXTEND_PATH;
973 OptEnt.Para->ParaList[11] = PXEBC_DHCP4_TAG_EMTU;
974 OptEnt.Para->ParaList[12] = PXEBC_DHCP4_TAG_TTL;
975 OptEnt.Para->ParaList[13] = PXEBC_DHCP4_TAG_BROADCAST;
976 OptEnt.Para->ParaList[14] = PXEBC_DHCP4_TAG_NIS_DOMAIN;
977 OptEnt.Para->ParaList[15] = PXEBC_DHCP4_TAG_NIS_SERVER;
978 OptEnt.Para->ParaList[16] = PXEBC_DHCP4_TAG_NTP_SERVER;
979 OptEnt.Para->ParaList[17] = PXEBC_DHCP4_TAG_VENDOR;
980 OptEnt.Para->ParaList[18] = PXEBC_DHCP4_TAG_REQUEST_IP;
981 OptEnt.Para->ParaList[19] = PXEBC_DHCP4_TAG_LEASE;
982 OptEnt.Para->ParaList[20] = PXEBC_DHCP4_TAG_SERVER_ID;
983 OptEnt.Para->ParaList[21] = PXEBC_DHCP4_TAG_T1;
984 OptEnt.Para->ParaList[22] = PXEBC_DHCP4_TAG_T2;
985 OptEnt.Para->ParaList[23] = PXEBC_DHCP4_TAG_CLASS_ID;
986 OptEnt.Para->ParaList[24] = PXEBC_DHCP4_TAG_TFTP;
987 OptEnt.Para->ParaList[25] = PXEBC_DHCP4_TAG_BOOTFILE;
988 OptEnt.Para->ParaList[26] = PXEBC_PXE_DHCP4_TAG_UUID;
989 OptEnt.Para->ParaList[27] = 0x80;
990 OptEnt.Para->ParaList[28] = 0x81;
991 OptEnt.Para->ParaList[29] = 0x82;
992 OptEnt.Para->ParaList[30] = 0x83;
993 OptEnt.Para->ParaList[31] = 0x84;
994 OptEnt.Para->ParaList[32] = 0x85;
995 OptEnt.Para->ParaList[33] = 0x86;
996 OptEnt.Para->ParaList[34] = 0x87;
997 Index++;
998 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
999
1000 //
1001 // Append UUID/Guid-based client identifier option
1002 //
1003 OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_UUID;
1004 OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_UUID);
1005 OptEnt.Uuid = (PXEBC_DHCP4_OPTION_UUID *) OptList[Index]->Data;
1006 OptEnt.Uuid->Type = 0;
1007 Index++;
1008 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
1009
1010 if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) OptEnt.Uuid->Guid))) {
1011 //
1012 // GUID not yet set - send all 0xff's to show programable (via SetVariable)
1013 // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff);
1014 // GUID not yet set - send all 0's to show not programable
1015 //
1016 ZeroMem (OptEnt.Uuid->Guid, sizeof (EFI_GUID));
1017 }
1018
1019 //
1020 // Append client network device interface option
1021 //
1022 OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_UNDI;
1023 OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_UNDI);
1024 OptEnt.Undi = (PXEBC_DHCP4_OPTION_UNDI *) OptList[Index]->Data;
1025 if (Private->Nii != NULL) {
1026 OptEnt.Undi->Type = Private->Nii->Type;
1027 OptEnt.Undi->MajorVer = Private->Nii->MajorVer;
1028 OptEnt.Undi->MinorVer = Private->Nii->MinorVer;
1029 } else {
1030 OptEnt.Undi->Type = DEFAULT_UNDI_TYPE;
1031 OptEnt.Undi->MajorVer = DEFAULT_UNDI_MAJOR;
1032 OptEnt.Undi->MinorVer = DEFAULT_UNDI_MINOR;
1033 }
1034
1035 Index++;
1036 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
1037
1038 //
1039 // Append client system architecture option
1040 //
1041 OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_ARCH;
1042 OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_ARCH);
1043 OptEnt.Arch = (PXEBC_DHCP4_OPTION_ARCH *) OptList[Index]->Data;
1044 Value = HTONS (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE);
1045 CopyMem (&OptEnt.Arch->Type, &Value, sizeof (UINT16));
1046 Index++;
1047 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
1048
1049 //
1050 // Append client system architecture option
1051 //
1052 OptList[Index]->OpCode = PXEBC_DHCP4_TAG_CLASS_ID;
1053 OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_CLID);
1054 OptEnt.Clid = (PXEBC_DHCP4_OPTION_CLID *) OptList[Index]->Data;
1055 CopyMem (OptEnt.Clid, DEFAULT_CLASS_ID_DATA, sizeof (PXEBC_DHCP4_OPTION_CLID));
1056 CvtNum (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE, OptEnt.Clid->ArchitectureType, sizeof (OptEnt.Clid->ArchitectureType));
1057
1058 if (Private->Nii != NULL) {
1059 //
1060 // If NII protocol exists, update DHCP option data
1061 //
1062 CopyMem (OptEnt.Clid->InterfaceName, Private->Nii->StringId, sizeof (OptEnt.Clid->InterfaceName));
1063 CvtNum (Private->Nii->MajorVer, OptEnt.Clid->UndiMajor, sizeof (OptEnt.Clid->UndiMajor));
1064 CvtNum (Private->Nii->MinorVer, OptEnt.Clid->UndiMinor, sizeof (OptEnt.Clid->UndiMinor));
1065 }
1066
1067 Index++;
1068
1069 return Index;
1070 }
1071
1072
1073 /**
1074 Discover the boot of service and initialize the vendor option if exists.
1075
1076 @param Private Pointer to PxeBc private data.
1077 @param Type PxeBc option boot item type
1078 @param Layer PxeBc option boot item layer
1079 @param UseBis Use BIS or not
1080 @param DestIp Ip address for server
1081 @param IpCount The total count of the server ip address
1082 @param SrvList Server list
1083 @param IsDiscv Discover the vendor or not
1084 @param Reply The dhcp4 packet of Pxe reply
1085
1086 @retval EFI_SUCCESS Operation succeeds.
1087 @retval EFI_OUT_OF_RESOURCES Allocate memory pool failed.
1088 @retval EFI_NOT_FOUND There is no vendor option exists.
1089 @retval EFI_TIMEOUT Send Pxe Discover time out.
1090
1091 **/
1092 EFI_STATUS
1093 PxeBcDiscvBootService (
1094 IN PXEBC_PRIVATE_DATA * Private,
1095 IN UINT16 Type,
1096 IN UINT16 *Layer,
1097 IN BOOLEAN UseBis,
1098 IN EFI_IP_ADDRESS * DestIp,
1099 IN UINT16 IpCount,
1100 IN EFI_PXE_BASE_CODE_SRVLIST * SrvList,
1101 IN BOOLEAN IsDiscv,
1102 OUT EFI_DHCP4_PACKET * Reply OPTIONAL
1103 )
1104 {
1105 EFI_PXE_BASE_CODE_UDP_PORT Sport;
1106 EFI_PXE_BASE_CODE_MODE *Mode;
1107 EFI_DHCP4_PROTOCOL *Dhcp4;
1108 EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN Token;
1109 BOOLEAN IsBCast;
1110 EFI_STATUS Status;
1111 UINT16 RepIndex;
1112 UINT16 SrvIndex;
1113 UINT16 TryIndex;
1114 EFI_DHCP4_LISTEN_POINT ListenPoint;
1115 EFI_DHCP4_PACKET *Response;
1116 EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM];
1117 UINT32 OptCount;
1118 EFI_DHCP4_PACKET_OPTION *PxeOpt;
1119 PXEBC_OPTION_BOOT_ITEM *PxeBootItem;
1120 UINT8 VendorOptLen;
1121 EFI_DHCP4_HEADER *DhcpHeader;
1122 UINT32 Xid;
1123
1124 Mode = Private->PxeBc.Mode;
1125 Dhcp4 = Private->Dhcp4;
1126 Status = EFI_SUCCESS;
1127
1128 ZeroMem (&Token, sizeof (EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN));
1129
1130 if (DestIp == NULL) {
1131 Sport = PXEBC_DHCP4_S_PORT;
1132 IsBCast = TRUE;
1133 } else {
1134 Sport = PXEBC_BS_DISCOVER_PORT;
1135 IsBCast = FALSE;
1136 }
1137
1138 if (!UseBis && Layer != NULL) {
1139 *Layer &= EFI_PXE_BASE_CODE_BOOT_LAYER_MASK;
1140 }
1141
1142 OptCount = PxeBcBuildDhcpOptions (Private, OptList, FALSE);
1143
1144 if (IsDiscv) {
1145 ASSERT (Layer != NULL);
1146 //
1147 // Add vendor option of PXE_BOOT_ITEM
1148 //
1149 VendorOptLen = (UINT8) ((sizeof (EFI_DHCP4_PACKET_OPTION) - 1) * 2 + sizeof (PXEBC_OPTION_BOOT_ITEM) + 1);
1150 OptList[OptCount] = AllocatePool (VendorOptLen);
1151 if (OptList[OptCount] == NULL) {
1152 return EFI_OUT_OF_RESOURCES;
1153 }
1154
1155 OptList[OptCount]->OpCode = PXEBC_DHCP4_TAG_VENDOR;
1156 OptList[OptCount]->Length = (UINT8) (VendorOptLen - 2);
1157 PxeOpt = (EFI_DHCP4_PACKET_OPTION *) OptList[OptCount]->Data;
1158 PxeOpt->OpCode = PXEBC_VENDOR_TAG_BOOT_ITEM;
1159 PxeOpt->Length = (UINT8) sizeof (PXEBC_OPTION_BOOT_ITEM);
1160 PxeBootItem = (PXEBC_OPTION_BOOT_ITEM *) PxeOpt->Data;
1161 PxeBootItem->Type = HTONS (Type);
1162 PxeBootItem->Layer = HTONS (*Layer);
1163 PxeOpt->Data[PxeOpt->Length] = PXEBC_DHCP4_TAG_EOP;
1164
1165 OptCount++;
1166 }
1167
1168 Status = Dhcp4->Build (Dhcp4, &Private->SeedPacket, 0, NULL, OptCount, OptList, &Token.Packet);
1169
1170 if (IsDiscv) {
1171 FreePool (OptList[OptCount - 1]);
1172 }
1173
1174 if (EFI_ERROR (Status)) {
1175 return Status;
1176 }
1177
1178 DhcpHeader = &Token.Packet->Dhcp4.Header;
1179 if (Mode->SendGUID) {
1180 if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) {
1181 //
1182 // GUID not yet set - send all 0's to show not programable
1183 //
1184 ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID));
1185 }
1186
1187 DhcpHeader->HwAddrLen = (UINT8) sizeof (EFI_GUID);
1188 }
1189
1190 Xid = NET_RANDOM (NetRandomInitSeed ());
1191 Token.Packet->Dhcp4.Header.Xid = HTONL(Xid);
1192 Token.Packet->Dhcp4.Header.Reserved = HTONS((UINT16) ((IsBCast) ? 0x8000 : 0));
1193 CopyMem (&Token.Packet->Dhcp4.Header.ClientAddr, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));
1194
1195 Token.RemotePort = Sport;
1196
1197 if (IsBCast) {
1198 SetMem (&Token.RemoteAddress, sizeof (EFI_IPv4_ADDRESS), 0xff);
1199 } else {
1200 CopyMem (&Token.RemoteAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));
1201 }
1202
1203 CopyMem (&Token.GatewayAddress, &Private->GatewayIp, sizeof (EFI_IPv4_ADDRESS));
1204
1205 if (!IsBCast) {
1206 Token.ListenPointCount = 1;
1207 Token.ListenPoints = &ListenPoint;
1208 Token.ListenPoints[0].ListenPort = PXEBC_BS_DISCOVER_PORT;
1209 CopyMem (&Token.ListenPoints[0].ListenAddress, &Private->StationIp, sizeof(EFI_IPv4_ADDRESS));
1210 CopyMem (&Token.ListenPoints[0].SubnetMask, &Private->SubnetMask, sizeof(EFI_IPv4_ADDRESS));
1211 }
1212 //
1213 // Send Pxe Discover
1214 //
1215 for (TryIndex = 1; TryIndex <= PXEBC_BOOT_REQUEST_RETRIES; TryIndex++) {
1216
1217 Token.TimeoutValue = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * TryIndex);
1218 Token.Packet->Dhcp4.Header.Seconds = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * (TryIndex - 1));
1219
1220 Status = Dhcp4->TransmitReceive (Dhcp4, &Token);
1221
1222 if (Token.Status != EFI_TIMEOUT) {
1223 break;
1224 }
1225 }
1226
1227 if (TryIndex > PXEBC_BOOT_REQUEST_RETRIES) {
1228 //
1229 // No server response our PXE request
1230 //
1231 Status = EFI_TIMEOUT;
1232 }
1233
1234 if (!EFI_ERROR (Status)) {
1235 //
1236 // Find Pxe Reply
1237 //
1238 RepIndex = 0;
1239 SrvIndex = 0;
1240 Response = Token.ResponseList;
1241
1242 while (RepIndex < Token.ResponseCount) {
1243
1244 while (SrvIndex < IpCount) {
1245
1246 if (SrvList[SrvIndex].AcceptAnyResponse) {
1247 break;
1248 }
1249
1250 if ((SrvList[SrvIndex].Type == Type) && EFI_IP4_EQUAL (&(Response->Dhcp4.Header.ServerAddr), &(Private->ServerIp))) {
1251 break;
1252 }
1253
1254 SrvIndex++;
1255 }
1256
1257 if ((IpCount != SrvIndex) || (IpCount == 0)) {
1258 break;
1259 }
1260
1261 SrvIndex = 0;
1262 RepIndex++;
1263
1264 Response = (EFI_DHCP4_PACKET *) ((UINT8 *) Response + Response->Size);
1265 }
1266
1267 if (RepIndex < Token.ResponseCount) {
1268
1269 if (Reply != NULL) {
1270 PxeBcCopyEfiDhcp4Packet (Reply, Response);
1271 }
1272
1273 if (IsDiscv) {
1274 CopyMem (&(Mode->PxeDiscover), &(Token.Packet->Dhcp4), Token.Packet->Length);
1275 Mode->PxeDiscoverValid = TRUE;
1276
1277 CopyMem (Mode->PxeReply.Raw, &Response->Dhcp4, Response->Length);
1278 Mode->PxeReplyReceived = TRUE;
1279 }
1280 } else {
1281 Status = EFI_NOT_FOUND;
1282 }
1283
1284 //
1285 // free the responselist
1286 //
1287 if (Token.ResponseList != NULL) {
1288 FreePool (Token.ResponseList);
1289 }
1290 }
1291 //
1292 // Free the dhcp packet
1293 //
1294 FreePool (Token.Packet);
1295
1296 return Status;
1297 }
1298
1299
1300 /**
1301 Parse interested dhcp options.
1302
1303 @param Buffer Pointer to the dhcp options packet.
1304 @param Length The length of the dhcp options.
1305 @param OptTag The option OpCode.
1306
1307 @return NULL if the buffer length is 0 and OpCode is not
1308 PXEBC_DHCP4_TAG_EOP, or the pointer to the buffer.
1309
1310 **/
1311 EFI_DHCP4_PACKET_OPTION *
1312 PxeBcParseExtendOptions (
1313 IN UINT8 *Buffer,
1314 IN UINT32 Length,
1315 IN UINT8 OptTag
1316 )
1317 {
1318 EFI_DHCP4_PACKET_OPTION *Option;
1319 UINT32 Offset;
1320
1321 Option = (EFI_DHCP4_PACKET_OPTION *) Buffer;
1322 Offset = 0;
1323
1324 while (Offset < Length && Option->OpCode != PXEBC_DHCP4_TAG_EOP) {
1325
1326 if (Option->OpCode == OptTag) {
1327
1328 return Option;
1329 }
1330
1331 if (Option->OpCode == PXEBC_DHCP4_TAG_PAD) {
1332 Offset++;
1333 } else {
1334 Offset += Option->Length + 2;
1335 }
1336
1337 Option = (EFI_DHCP4_PACKET_OPTION *) (Buffer + Offset);
1338 }
1339
1340 return NULL;
1341 }
1342
1343
1344 /**
1345 This function is to parse and check vendor options.
1346
1347 @param Dhcp4Option Pointer to dhcp options
1348 @param VendorOption Pointer to vendor options
1349
1350 @return TRUE if valid for vendor options, or FALSE.
1351
1352 **/
1353 BOOLEAN
1354 PxeBcParseVendorOptions (
1355 IN EFI_DHCP4_PACKET_OPTION *Dhcp4Option,
1356 IN PXEBC_VENDOR_OPTION *VendorOption
1357 )
1358 {
1359 UINT32 *BitMap;
1360 UINT8 VendorOptionLen;
1361 EFI_DHCP4_PACKET_OPTION *PxeOption;
1362 UINT8 Offset;
1363
1364 BitMap = VendorOption->BitMap;
1365 VendorOptionLen = Dhcp4Option->Length;
1366 PxeOption = (EFI_DHCP4_PACKET_OPTION *) &Dhcp4Option->Data[0];
1367 Offset = 0;
1368
1369 while ((Offset < VendorOptionLen) && (PxeOption->OpCode != PXEBC_DHCP4_TAG_EOP)) {
1370 //
1371 // Parse every Vendor Option and set its BitMap
1372 //
1373 switch (PxeOption->OpCode) {
1374
1375 case PXEBC_VENDOR_TAG_MTFTP_IP:
1376
1377 CopyMem (&VendorOption->MtftpIp, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));
1378 break;
1379
1380 case PXEBC_VENDOR_TAG_MTFTP_CPORT:
1381
1382 CopyMem (&VendorOption->MtftpCPort, PxeOption->Data, sizeof (VendorOption->MtftpCPort));
1383 break;
1384
1385 case PXEBC_VENDOR_TAG_MTFTP_SPORT:
1386
1387 CopyMem (&VendorOption->MtftpSPort, PxeOption->Data, sizeof (VendorOption->MtftpSPort));
1388 break;
1389
1390 case PXEBC_VENDOR_TAG_MTFTP_TIMEOUT:
1391
1392 VendorOption->MtftpTimeout = *PxeOption->Data;
1393 break;
1394
1395 case PXEBC_VENDOR_TAG_MTFTP_DELAY:
1396
1397 VendorOption->MtftpDelay = *PxeOption->Data;
1398 break;
1399
1400 case PXEBC_VENDOR_TAG_DISCOVER_CTRL:
1401
1402 VendorOption->DiscoverCtrl = *PxeOption->Data;
1403 break;
1404
1405 case PXEBC_VENDOR_TAG_DISCOVER_MCAST:
1406
1407 CopyMem (&VendorOption->DiscoverMcastIp, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));
1408 break;
1409
1410 case PXEBC_VENDOR_TAG_BOOT_SERVERS:
1411
1412 VendorOption->BootSvrLen = PxeOption->Length;
1413 VendorOption->BootSvr = (PXEBC_BOOT_SVR_ENTRY *) PxeOption->Data;
1414 break;
1415
1416 case PXEBC_VENDOR_TAG_BOOT_MENU:
1417
1418 VendorOption->BootMenuLen = PxeOption->Length;
1419 VendorOption->BootMenu = (PXEBC_BOOT_MENU_ENTRY *) PxeOption->Data;
1420 break;
1421
1422 case PXEBC_VENDOR_TAG_MENU_PROMPT:
1423
1424 VendorOption->MenuPromptLen = PxeOption->Length;
1425 VendorOption->MenuPrompt = (PXEBC_MENU_PROMPT *) PxeOption->Data;
1426 break;
1427
1428 case PXEBC_VENDOR_TAG_MCAST_ALLOC:
1429
1430 CopyMem (&VendorOption->McastIpBase, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));
1431 CopyMem (&VendorOption->McastIpBlock, PxeOption->Data + 4, sizeof (VendorOption->McastIpBlock));
1432 CopyMem (&VendorOption->McastIpRange, PxeOption->Data + 6, sizeof (VendorOption->McastIpRange));
1433 break;
1434
1435 case PXEBC_VENDOR_TAG_CREDENTIAL_TYPES:
1436
1437 VendorOption->CredTypeLen = PxeOption->Length;
1438 VendorOption->CredType = (UINT32 *) PxeOption->Data;
1439 break;
1440
1441 case PXEBC_VENDOR_TAG_BOOT_ITEM:
1442
1443 CopyMem (&VendorOption->BootSrvType, PxeOption->Data, sizeof (VendorOption->BootSrvType));
1444 CopyMem (&VendorOption->BootSrvLayer, PxeOption->Data + 2, sizeof (VendorOption->BootSrvLayer));
1445 break;
1446 }
1447
1448 SET_VENDOR_OPTION_BIT_MAP (BitMap, PxeOption->OpCode);
1449
1450 if (PxeOption->OpCode == PXEBC_DHCP4_TAG_PAD) {
1451 Offset++;
1452 } else {
1453 Offset = (UINT8) (Offset + PxeOption->Length + 2);
1454 }
1455
1456 PxeOption = (EFI_DHCP4_PACKET_OPTION *) (Dhcp4Option->Data + Offset);
1457 }
1458
1459 //
1460 // FixMe, return falas if invalid of any vendor option
1461 //
1462
1463 return TRUE;
1464 }
1465
1466
1467 /**
1468 This function display boot item detail.
1469
1470 If the length of the boot item string over 70 Char, just display 70 Char.
1471
1472 @param Str Pointer to a string (boot item string).
1473 @param Len The length of string.
1474
1475 **/
1476 VOID
1477 PxeBcDisplayBootItem (
1478 IN UINT8 *Str,
1479 IN UINT8 Len
1480 )
1481 {
1482 UINT8 Tmp;
1483
1484 Len = (UINT8) MIN (70, Len);
1485 Tmp = Str[Len];
1486 Str[Len] = 0;
1487 AsciiPrint ("%a \n", Str);
1488 Str[Len] = Tmp;
1489 }
1490
1491
1492 /**
1493 Choose the boot prompt.
1494
1495 @param Private Pointer to PxeBc private data.
1496
1497 @retval EFI_SUCCESS Select boot prompt done.
1498 @retval EFI_TIMEOUT Select boot prompt time out.
1499 @retval EFI_NOT_FOUND The proxy offer is not Pxe10.
1500 @retval EFI_ABORTED User cancel the operation.
1501 @retval EFI_NOT_READY Read the input key from the keybroad has not finish.
1502
1503 **/
1504 EFI_STATUS
1505 PxeBcSelectBootPrompt (
1506 IN PXEBC_PRIVATE_DATA *Private
1507 )
1508 {
1509 PXEBC_CACHED_DHCP4_PACKET *Packet;
1510 PXEBC_VENDOR_OPTION *VendorOpt;
1511 EFI_EVENT TimeoutEvent;
1512 EFI_EVENT DescendEvent;
1513 EFI_INPUT_KEY InputKey;
1514 EFI_STATUS Status;
1515 UINT8 Timeout;
1516 UINT8 *Prompt;
1517 UINT8 PromptLen;
1518 INT32 SecCol;
1519 INT32 SecRow;
1520
1521 TimeoutEvent = NULL;
1522 DescendEvent = NULL;
1523
1524 if (Private->PxeBc.Mode->ProxyOfferReceived) {
1525
1526 Packet = &Private->ProxyOffer;
1527 } else {
1528
1529 Packet = &Private->Dhcp4Ack;
1530 }
1531
1532 if (Packet->OfferType != DHCP4_PACKET_TYPE_PXE10) {
1533 return EFI_NOT_FOUND;
1534 }
1535
1536 VendorOpt = &Packet->PxeVendorOption;
1537
1538 if (!IS_VALID_BOOT_PROMPT (VendorOpt->BitMap)) {
1539 return EFI_SUCCESS;
1540 }
1541
1542 Timeout = VendorOpt->MenuPrompt->Timeout;
1543 Prompt = VendorOpt->MenuPrompt->Prompt;
1544 PromptLen = (UINT8) (VendorOpt->MenuPromptLen - 1);
1545
1546 if (Timeout == 0) {
1547 return EFI_SUCCESS;
1548 }
1549
1550 if (Timeout == 255) {
1551 return EFI_TIMEOUT;
1552 }
1553
1554 Status = gBS->CreateEvent (
1555 EVT_TIMER,
1556 TPL_CALLBACK,
1557 NULL,
1558 NULL,
1559 &TimeoutEvent
1560 );
1561
1562 if (EFI_ERROR (Status)) {
1563 return Status;
1564 }
1565
1566 Status = gBS->SetTimer (
1567 TimeoutEvent,
1568 TimerRelative,
1569 Timeout * TICKS_PER_SECOND
1570 );
1571
1572 if (EFI_ERROR (Status)) {
1573 goto ON_EXIT;
1574 }
1575
1576 Status = gBS->CreateEvent (
1577 EVT_TIMER,
1578 TPL_CALLBACK,
1579 NULL,
1580 NULL,
1581 &DescendEvent
1582 );
1583
1584 if (EFI_ERROR (Status)) {
1585 goto ON_EXIT;
1586 }
1587
1588 Status = gBS->SetTimer (
1589 DescendEvent,
1590 TimerPeriodic,
1591 TICKS_PER_SECOND
1592 );
1593
1594 if (EFI_ERROR (Status)) {
1595 goto ON_EXIT;
1596 }
1597
1598 SecCol = gST->ConOut->Mode->CursorColumn;
1599 SecRow = gST->ConOut->Mode->CursorRow;
1600
1601 PxeBcDisplayBootItem (Prompt, PromptLen);
1602
1603 gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);
1604 AsciiPrint ("(%d) ", Timeout--);
1605
1606 while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))) {
1607
1608 if (!EFI_ERROR (gBS->CheckEvent (DescendEvent))) {
1609 gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);
1610 AsciiPrint ("(%d) ", Timeout--);
1611 }
1612
1613 if (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {
1614
1615 gBS->Stall (10 * TICKS_PER_MS);
1616 continue;
1617 }
1618
1619 if (InputKey.ScanCode == 0) {
1620
1621 switch (InputKey.UnicodeChar) {
1622 case CTRL ('c'):
1623 Status = EFI_ABORTED;
1624 break;
1625
1626 case CTRL ('m'):
1627 case 'm':
1628 case 'M':
1629 Status = EFI_TIMEOUT;
1630 break;
1631
1632 default:
1633 continue;
1634 }
1635 } else {
1636
1637 switch (InputKey.ScanCode) {
1638 case SCAN_F8:
1639 Status = EFI_TIMEOUT;
1640 break;
1641
1642 case SCAN_ESC:
1643 Status = EFI_ABORTED;
1644 break;
1645
1646 default:
1647 continue;
1648 }
1649 }
1650
1651 break;
1652 }
1653
1654 gST->ConOut->SetCursorPosition (gST->ConOut, 0 , SecRow + 1);
1655
1656 ON_EXIT:
1657
1658 if (DescendEvent != NULL) {
1659 gBS->CloseEvent (DescendEvent);
1660 }
1661
1662 if (TimeoutEvent != NULL) {
1663 gBS->CloseEvent (TimeoutEvent);
1664 }
1665
1666 return Status;
1667 }
1668
1669
1670 /**
1671 Select the boot menu.
1672
1673 @param Private Pointer to PxeBc private data.
1674 @param Type The type of the menu.
1675 @param UseDefaultItem Use default item or not.
1676
1677 @retval EFI_ABORTED User cancel operation.
1678 @retval EFI_SUCCESS Select the boot menu success.
1679 @retval EFI_NOT_READY Read the input key from the keybroad has not finish.
1680
1681 **/
1682 EFI_STATUS
1683 PxeBcSelectBootMenu (
1684 IN PXEBC_PRIVATE_DATA *Private,
1685 OUT UINT16 *Type,
1686 IN BOOLEAN UseDefaultItem
1687 )
1688 {
1689 PXEBC_CACHED_DHCP4_PACKET *Packet;
1690 PXEBC_VENDOR_OPTION *VendorOpt;
1691 EFI_INPUT_KEY InputKey;
1692 UINT8 MenuSize;
1693 UINT8 MenuNum;
1694 INT32 TopRow;
1695 UINT16 Select;
1696 UINT16 LastSelect;
1697 UINT8 Index;
1698 BOOLEAN Finish;
1699 CHAR8 Blank[70];
1700 PXEBC_BOOT_MENU_ENTRY *MenuItem;
1701 PXEBC_BOOT_MENU_ENTRY *MenuArray[PXEBC_MAX_MENU_NUM];
1702
1703 Finish = FALSE;
1704 Select = 1;
1705 Index = 0;
1706 *Type = 0;
1707
1708 if (Private->PxeBc.Mode->ProxyOfferReceived) {
1709
1710 Packet = &Private->ProxyOffer;
1711 } else {
1712
1713 Packet = &Private->Dhcp4Ack;
1714 }
1715
1716 ASSERT (Packet->OfferType == DHCP4_PACKET_TYPE_PXE10);
1717
1718 VendorOpt = &Packet->PxeVendorOption;
1719
1720 if (!IS_VALID_BOOT_MENU (VendorOpt->BitMap)) {
1721 return EFI_SUCCESS;
1722 }
1723
1724 SetMem (Blank, sizeof(Blank), ' ');
1725
1726 MenuSize = VendorOpt->BootMenuLen;
1727 MenuItem = VendorOpt->BootMenu;
1728
1729 if (MenuSize == 0) {
1730 return EFI_NOT_READY;
1731 }
1732
1733 while (MenuSize > 0) {
1734 MenuArray[Index++] = MenuItem;
1735 MenuSize = (UINT8) (MenuSize - (MenuItem->DescLen + 3));
1736 MenuItem = (PXEBC_BOOT_MENU_ENTRY *) ((UINT8 *) MenuItem + MenuItem->DescLen + 3);
1737 if (Index >= PXEBC_MAX_MENU_NUM) {
1738 break;
1739 }
1740 }
1741
1742 if (UseDefaultItem) {
1743 *Type = MenuArray[0]->Type;
1744 *Type = NTOHS (*Type);
1745 return EFI_SUCCESS;
1746 }
1747
1748 MenuNum = Index;
1749
1750 for (Index = 0; Index < MenuNum; Index++) {
1751 PxeBcDisplayBootItem (MenuArray[Index]->DescStr, MenuArray[Index]->DescLen);
1752 }
1753
1754 TopRow = gST->ConOut->Mode->CursorRow - MenuNum;
1755
1756 do {
1757 ASSERT (Select < PXEBC_MAX_MENU_NUM);
1758 //
1759 // highlight selected row
1760 //
1761 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));
1762 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + Select);
1763 Blank[MenuArray[Select]->DescLen] = 0;
1764 AsciiPrint ("%a\r", Blank);
1765 PxeBcDisplayBootItem (MenuArray[Select]->DescStr, MenuArray[Select]->DescLen);
1766 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);
1767 LastSelect = Select;
1768
1769 while (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {
1770 gBS->Stall (10 * TICKS_PER_MS);
1771 }
1772
1773 if (InputKey.ScanCode != 0) {
1774 switch (InputKey.UnicodeChar) {
1775 case CTRL ('c'):
1776 InputKey.ScanCode = SCAN_ESC;
1777 break;
1778
1779 case CTRL ('j'): /* linefeed */
1780 case CTRL ('m'): /* return */
1781 Finish = TRUE;
1782 break;
1783
1784 case CTRL ('i'): /* tab */
1785 case ' ':
1786 case 'd':
1787 case 'D':
1788 InputKey.ScanCode = SCAN_DOWN;
1789 break;
1790
1791 case CTRL ('h'): /* backspace */
1792 case 'u':
1793 case 'U':
1794 InputKey.ScanCode = SCAN_UP;
1795 break;
1796
1797 default:
1798 InputKey.ScanCode = 0;
1799 }
1800 }
1801
1802 switch (InputKey.ScanCode) {
1803 case SCAN_LEFT:
1804 case SCAN_UP:
1805 if (Select > 0) {
1806 --Select;
1807 }
1808
1809 break;
1810
1811 case SCAN_DOWN:
1812 case SCAN_RIGHT:
1813 if (++Select == MenuNum) {
1814 --Select;
1815 }
1816
1817 break;
1818
1819 case SCAN_PAGE_UP:
1820 case SCAN_HOME:
1821 Select = 0;
1822 break;
1823
1824 case SCAN_PAGE_DOWN:
1825 case SCAN_END:
1826 Select = (UINT16) (MenuNum - 1);
1827 break;
1828
1829 case SCAN_ESC:
1830 return EFI_ABORTED;
1831 }
1832
1833 /* unhighlight last selected row */
1834 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
1835 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + LastSelect);
1836 Blank[MenuArray[LastSelect]->DescLen] = 0;
1837 AsciiPrint ("%a\r", Blank);
1838 PxeBcDisplayBootItem (MenuArray[LastSelect]->DescStr, MenuArray[LastSelect]->DescLen);
1839 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);
1840 } while (!Finish);
1841
1842 ASSERT (Select < PXEBC_MAX_MENU_NUM);
1843
1844 //
1845 // Swap the byte order
1846 //
1847 CopyMem (Type, &MenuArray[Select]->Type, sizeof (UINT16));
1848 *Type = NTOHS (*Type);
1849
1850 return EFI_SUCCESS;
1851 }
1852