]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
6bca31967c95088a389ba11ac8056543440d66eb
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcDhcp.c
1 /** @file
2 Support for PxeBc dhcp functions.
3
4 Copyright (c) 2007 - 2013, 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 destroy 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 if (OfferType >= DHCP4_PACKET_TYPE_MAX) {
569 return ;
570 }
571
572 if (OfferType == DHCP4_PACKET_TYPE_BOOTP) {
573
574 if (Private->BootpIndex != 0) {
575 //
576 // Only cache the first bootp offer, discard others.
577 //
578 return ;
579 } else {
580 //
581 // Take as a dhcp only offer, but record index specifically.
582 //
583 Private->BootpIndex = Private->NumOffers + 1;
584 }
585 } else {
586
587 if (IS_PROXY_DHCP_OFFER (Offer)) {
588 //
589 // It's a proxy dhcp offer with no your address, including pxe10, wfm11a or binl offer.
590 //
591 Private->GotProxyOffer = TRUE;
592
593 if (OfferType == DHCP4_PACKET_TYPE_BINL) {
594 //
595 // Cache all binl offers.
596 //
597 Private->BinlIndex[Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]] = Private->NumOffers;
598 Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL]++;
599 } else if (Private->ProxyIndex[OfferType] != 0) {
600 //
601 // Only cache the first pxe10/wfm11a offers each, discard the others.
602 //
603 return ;
604 } else {
605 //
606 // Record index of the proxy dhcp offer with type other than binl.
607 //
608 Private->ProxyIndex[OfferType] = Private->NumOffers + 1;
609 }
610 } else {
611 //
612 // It's a dhcp offer with your address.
613 //
614 ASSERT (Private->ServerCount[OfferType] < PXEBC_MAX_OFFER_NUM);
615 Private->OfferIndex[OfferType][Private->ServerCount[OfferType]] = Private->NumOffers;
616 Private->ServerCount[OfferType]++;
617 }
618 }
619
620 //
621 // Count the accepted offers.
622 //
623 Private->NumOffers++;
624 }
625
626
627 /**
628 Select the specified proxy offer, such as BINL, DHCP_ONLY and so on.
629 If the proxy does not exist, try offers with bootfile.
630
631 @param Private Pointer to PxeBc private data.
632
633 **/
634 VOID
635 PxeBcSelectOffer (
636 IN PXEBC_PRIVATE_DATA *Private
637 )
638 {
639 UINT32 Index;
640 UINT32 OfferIndex;
641 EFI_DHCP4_PACKET *Offer;
642
643 Private->SelectedOffer = 0;
644
645 if (Private->SortOffers) {
646 //
647 // Select offer according to the priority
648 //
649 if (Private->ServerCount[DHCP4_PACKET_TYPE_PXE10] > 0) {
650 //
651 // DHCP with PXE10
652 //
653 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_PXE10][0] + 1;
654
655 } else if (Private->ServerCount[DHCP4_PACKET_TYPE_WFM11A] > 0) {
656 //
657 // DHCP with WfM
658 //
659 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_WFM11A][0] + 1;
660
661 } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_PXE10] > 0) &&
662 (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)
663 ) {
664 //
665 // DHCP only and proxy DHCP with PXE10
666 //
667 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;
668 Private->ProxyOfferType = DHCP4_PACKET_TYPE_PXE10;
669
670 } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_WFM11A] > 0) &&
671 (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)
672 ) {
673 //
674 // DHCP only and proxy DHCP with WfM
675 //
676 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;
677 Private->ProxyOfferType = DHCP4_PACKET_TYPE_WFM11A;
678
679 } else if (Private->ServerCount[DHCP4_PACKET_TYPE_BINL] > 0) {
680 //
681 // DHCP with BINL
682 //
683 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_BINL][0] + 1;
684
685 } else if ((Private->ProxyIndex[DHCP4_PACKET_TYPE_BINL] > 0) &&
686 (Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY] > 0)
687 ) {
688 //
689 // DHCP only and proxy DHCP with BINL
690 //
691 Private->SelectedOffer = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][0] + 1;
692 Private->ProxyOfferType = DHCP4_PACKET_TYPE_BINL;
693
694 } else {
695 //
696 // Try offers with bootfile
697 //
698 for (Index = 0; Index < Private->ServerCount[DHCP4_PACKET_TYPE_DHCP_ONLY]; Index++) {
699 //
700 // Select the first DHCP only offer with bootfile
701 //
702 OfferIndex = Private->OfferIndex[DHCP4_PACKET_TYPE_DHCP_ONLY][Index];
703 if (Private->Dhcp4Offers[OfferIndex].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {
704 Private->SelectedOffer = OfferIndex + 1;
705 break;
706 }
707 }
708
709 if (Private->SelectedOffer == 0) {
710 //
711 // Select the Bootp reply with bootfile if any
712 //
713 Private->SelectedOffer = Private->BootpIndex;
714 }
715 }
716 } else {
717 //
718 // Try the offers in the received order.
719 //
720 for (Index = 0; Index < Private->NumOffers; Index++) {
721
722 Offer = &Private->Dhcp4Offers[Index].Packet.Offer;
723
724 if (IS_PROXY_DHCP_OFFER (Offer)) {
725 //
726 // Skip proxy offers
727 //
728 continue;
729 }
730
731 if ((Private->Dhcp4Offers[Index].OfferType == DHCP4_PACKET_TYPE_DHCP_ONLY) &&
732 ((!Private->GotProxyOffer) && (Private->Dhcp4Offers[Index].Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL))) {
733 //
734 // DHCP only offer but no proxy offer received and no bootfile option in this offer
735 //
736 continue;
737 }
738
739 Private->SelectedOffer = Index + 1;
740 break;
741 }
742 }
743 }
744
745
746 /**
747 Callback routine.
748
749 EFI_DHCP4_CALLBACK is provided by the consumer of the EFI DHCPv4 Protocol driver
750 to intercept events that occurred in the configuration process. This structure
751 provides advanced control of each state transition of the DHCP process. The
752 returned status code determines the behavior of the EFI DHCPv4 Protocol driver.
753 There are three possible returned values, which are described in the following
754 table.
755
756 @param This Pointer to the EFI DHCPv4 Protocol instance that is used to
757 configure this callback function.
758 @param Context Pointer to the context that is initialized by
759 EFI_DHCP4_PROTOCOL.Configure().
760 @param CurrentState The current operational state of the EFI DHCPv4 Protocol
761 driver.
762 @param Dhcp4Event The event that occurs in the current state, which usually means a
763 state transition.
764 @param Packet The DHCP packet that is going to be sent or already received.
765 @param NewPacket The packet that is used to replace the above Packet.
766
767 @retval EFI_SUCCESS Tells the EFI DHCPv4 Protocol driver to continue the DHCP process.
768 @retval EFI_NOT_READY Only used in the Dhcp4Selecting state. The EFI DHCPv4 Protocol
769 driver will continue to wait for more DHCPOFFER packets until the retry
770 timeout expires.
771 @retval EFI_ABORTED Tells the EFI DHCPv4 Protocol driver to abort the current process and
772 return to the Dhcp4Init or Dhcp4InitReboot state.
773
774 **/
775 EFI_STATUS
776 EFIAPI
777 PxeBcDhcpCallBack (
778 IN EFI_DHCP4_PROTOCOL * This,
779 IN VOID *Context,
780 IN EFI_DHCP4_STATE CurrentState,
781 IN EFI_DHCP4_EVENT Dhcp4Event,
782 IN EFI_DHCP4_PACKET * Packet OPTIONAL,
783 OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL
784 )
785 {
786 PXEBC_PRIVATE_DATA *Private;
787 EFI_PXE_BASE_CODE_MODE *Mode;
788 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *Callback;
789 EFI_DHCP4_PACKET_OPTION *MaxMsgSize;
790 UINT16 Value;
791 EFI_STATUS Status;
792 BOOLEAN Received;
793 EFI_DHCP4_HEADER *DhcpHeader;
794
795 if ((Dhcp4Event != Dhcp4RcvdOffer) &&
796 (Dhcp4Event != Dhcp4SelectOffer) &&
797 (Dhcp4Event != Dhcp4SendDiscover) &&
798 (Dhcp4Event != Dhcp4RcvdAck) &&
799 (Dhcp4Event != Dhcp4SendRequest)) {
800 return EFI_SUCCESS;
801 }
802
803 Private = (PXEBC_PRIVATE_DATA *) Context;
804 Mode = Private->PxeBc.Mode;
805 Callback = Private->PxeBcCallback;
806
807 //
808 // Override the Maximum DHCP Message Size.
809 //
810 MaxMsgSize = PxeBcParseExtendOptions (
811 Packet->Dhcp4.Option,
812 GET_OPTION_BUFFER_LEN (Packet),
813 PXEBC_DHCP4_TAG_MAXMSG
814 );
815 if (MaxMsgSize != NULL) {
816 Value = HTONS (PXEBC_DHCP4_MAX_PACKET_SIZE);
817 CopyMem (MaxMsgSize->Data, &Value, sizeof (Value));
818 }
819
820 if ((Dhcp4Event != Dhcp4SelectOffer) && (Callback != NULL)) {
821 Received = (BOOLEAN) ((Dhcp4Event == Dhcp4RcvdOffer) || (Dhcp4Event == Dhcp4RcvdAck));
822 Status = Callback->Callback (
823 Callback,
824 Private->Function,
825 Received,
826 Packet->Length,
827 (EFI_PXE_BASE_CODE_PACKET *) &Packet->Dhcp4
828 );
829 if (Status != EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE) {
830 return EFI_ABORTED;
831 }
832 }
833
834 Status = EFI_SUCCESS;
835
836 switch (Dhcp4Event) {
837
838 case Dhcp4SendDiscover:
839 case Dhcp4SendRequest:
840 if (Mode->SendGUID) {
841 //
842 // send the system GUID instead of the MAC address as the hardware address
843 // in the DHCP packet header.
844 //
845 DhcpHeader = &Packet->Dhcp4.Header;
846
847 if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) {
848 //
849 // GUID not yet set - send all 0xff's to show programable (via SetVariable)
850 // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff);
851 // GUID not yet set - send all 0's to show not programable
852 //
853 ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID));
854 }
855
856 DhcpHeader->HwAddrLen = (UINT8) sizeof (EFI_GUID);
857 }
858
859 if (Dhcp4Event == Dhcp4SendDiscover) {
860 //
861 // Cache the dhcp discover packet, of which some information will be used later.
862 //
863 CopyMem (Mode->DhcpDiscover.Raw, &Packet->Dhcp4, Packet->Length);
864 }
865
866 break;
867
868 case Dhcp4RcvdOffer:
869 Status = EFI_NOT_READY;
870 if (Private->NumOffers < PXEBC_MAX_OFFER_NUM) {
871 //
872 // Cache the dhcp offers in Private->Dhcp4Offers[]
873 //
874 PxeBcCacheDhcpOffer (Private, Packet);
875 }
876
877 break;
878
879 case Dhcp4SelectOffer:
880 //
881 // Select an offer, if succeeded, Private->SelectedOffer points to
882 // the index of the selected one.
883 //
884 PxeBcSelectOffer (Private);
885
886 if (Private->SelectedOffer == 0) {
887 Status = EFI_ABORTED;
888 } else {
889 *NewPacket = &Private->Dhcp4Offers[Private->SelectedOffer - 1].Packet.Offer;
890 }
891
892 break;
893
894 case Dhcp4RcvdAck:
895 //
896 // Cache Ack
897 //
898 ASSERT (Private->SelectedOffer != 0);
899
900 PxeBcCopyEfiDhcp4Packet (&Private->Dhcp4Ack.Packet.Ack, Packet);
901 break;
902
903 default:
904 break;
905 }
906
907 return Status;
908 }
909
910
911 /**
912 Initialize the DHCP options and build the option list.
913
914 @param Private Pointer to PxeBc private data.
915 @param OptList Pointer to a DHCP option list.
916
917 @param IsDhcpDiscover Discover dhcp option or not.
918
919 @return The index item number of the option list.
920
921 **/
922 UINT32
923 PxeBcBuildDhcpOptions (
924 IN PXEBC_PRIVATE_DATA *Private,
925 IN EFI_DHCP4_PACKET_OPTION **OptList,
926 IN BOOLEAN IsDhcpDiscover
927 )
928 {
929 UINT32 Index;
930 PXEBC_DHCP4_OPTION_ENTRY OptEnt;
931 UINT16 Value;
932
933 Index = 0;
934 OptList[0] = (EFI_DHCP4_PACKET_OPTION *) Private->OptionBuffer;
935
936 if (!IsDhcpDiscover) {
937 //
938 // Append message type.
939 //
940 OptList[Index]->OpCode = PXEBC_DHCP4_TAG_MSG_TYPE;
941 OptList[Index]->Length = 1;
942 OptEnt.Mesg = (PXEBC_DHCP4_OPTION_MESG *) OptList[Index]->Data;
943 OptEnt.Mesg->Type = PXEBC_DHCP4_MSG_TYPE_REQUEST;
944 Index++;
945 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
946
947 //
948 // Append max message size.
949 //
950 OptList[Index]->OpCode = PXEBC_DHCP4_TAG_MAXMSG;
951 OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE);
952 OptEnt.MaxMesgSize = (PXEBC_DHCP4_OPTION_MAX_MESG_SIZE *) OptList[Index]->Data;
953 Value = NTOHS (PXEBC_DHCP4_MAX_PACKET_SIZE);
954 CopyMem (&OptEnt.MaxMesgSize->Size, &Value, sizeof (UINT16));
955 Index++;
956 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
957 }
958 //
959 // Parameter request list option.
960 //
961 OptList[Index]->OpCode = PXEBC_DHCP4_TAG_PARA_LIST;
962 OptList[Index]->Length = 35;
963 OptEnt.Para = (PXEBC_DHCP4_OPTION_PARA *) OptList[Index]->Data;
964 OptEnt.Para->ParaList[0] = PXEBC_DHCP4_TAG_NETMASK;
965 OptEnt.Para->ParaList[1] = PXEBC_DHCP4_TAG_TIME_OFFSET;
966 OptEnt.Para->ParaList[2] = PXEBC_DHCP4_TAG_ROUTER;
967 OptEnt.Para->ParaList[3] = PXEBC_DHCP4_TAG_TIME_SERVER;
968 OptEnt.Para->ParaList[4] = PXEBC_DHCP4_TAG_NAME_SERVER;
969 OptEnt.Para->ParaList[5] = PXEBC_DHCP4_TAG_DNS_SERVER;
970 OptEnt.Para->ParaList[6] = PXEBC_DHCP4_TAG_HOSTNAME;
971 OptEnt.Para->ParaList[7] = PXEBC_DHCP4_TAG_BOOTFILE_LEN;
972 OptEnt.Para->ParaList[8] = PXEBC_DHCP4_TAG_DOMAINNAME;
973 OptEnt.Para->ParaList[9] = PXEBC_DHCP4_TAG_ROOTPATH;
974 OptEnt.Para->ParaList[10] = PXEBC_DHCP4_TAG_EXTEND_PATH;
975 OptEnt.Para->ParaList[11] = PXEBC_DHCP4_TAG_EMTU;
976 OptEnt.Para->ParaList[12] = PXEBC_DHCP4_TAG_TTL;
977 OptEnt.Para->ParaList[13] = PXEBC_DHCP4_TAG_BROADCAST;
978 OptEnt.Para->ParaList[14] = PXEBC_DHCP4_TAG_NIS_DOMAIN;
979 OptEnt.Para->ParaList[15] = PXEBC_DHCP4_TAG_NIS_SERVER;
980 OptEnt.Para->ParaList[16] = PXEBC_DHCP4_TAG_NTP_SERVER;
981 OptEnt.Para->ParaList[17] = PXEBC_DHCP4_TAG_VENDOR;
982 OptEnt.Para->ParaList[18] = PXEBC_DHCP4_TAG_REQUEST_IP;
983 OptEnt.Para->ParaList[19] = PXEBC_DHCP4_TAG_LEASE;
984 OptEnt.Para->ParaList[20] = PXEBC_DHCP4_TAG_SERVER_ID;
985 OptEnt.Para->ParaList[21] = PXEBC_DHCP4_TAG_T1;
986 OptEnt.Para->ParaList[22] = PXEBC_DHCP4_TAG_T2;
987 OptEnt.Para->ParaList[23] = PXEBC_DHCP4_TAG_CLASS_ID;
988 OptEnt.Para->ParaList[24] = PXEBC_DHCP4_TAG_TFTP;
989 OptEnt.Para->ParaList[25] = PXEBC_DHCP4_TAG_BOOTFILE;
990 OptEnt.Para->ParaList[26] = PXEBC_PXE_DHCP4_TAG_UUID;
991 OptEnt.Para->ParaList[27] = 0x80;
992 OptEnt.Para->ParaList[28] = 0x81;
993 OptEnt.Para->ParaList[29] = 0x82;
994 OptEnt.Para->ParaList[30] = 0x83;
995 OptEnt.Para->ParaList[31] = 0x84;
996 OptEnt.Para->ParaList[32] = 0x85;
997 OptEnt.Para->ParaList[33] = 0x86;
998 OptEnt.Para->ParaList[34] = 0x87;
999 Index++;
1000 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
1001
1002 //
1003 // Append UUID/Guid-based client identifier option
1004 //
1005 OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_UUID;
1006 OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_UUID);
1007 OptEnt.Uuid = (PXEBC_DHCP4_OPTION_UUID *) OptList[Index]->Data;
1008 OptEnt.Uuid->Type = 0;
1009 Index++;
1010 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
1011
1012 if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) OptEnt.Uuid->Guid))) {
1013 //
1014 // GUID not yet set - send all 0xff's to show programable (via SetVariable)
1015 // SetMem(DHCPV4_OPTIONS_BUFFER.DhcpPlatformId.Guid, sizeof(EFI_GUID), 0xff);
1016 // GUID not yet set - send all 0's to show not programable
1017 //
1018 ZeroMem (OptEnt.Uuid->Guid, sizeof (EFI_GUID));
1019 }
1020
1021 //
1022 // Append client network device interface option
1023 //
1024 OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_UNDI;
1025 OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_UNDI);
1026 OptEnt.Undi = (PXEBC_DHCP4_OPTION_UNDI *) OptList[Index]->Data;
1027 if (Private->Nii != NULL) {
1028 OptEnt.Undi->Type = Private->Nii->Type;
1029 OptEnt.Undi->MajorVer = Private->Nii->MajorVer;
1030 OptEnt.Undi->MinorVer = Private->Nii->MinorVer;
1031 } else {
1032 OptEnt.Undi->Type = DEFAULT_UNDI_TYPE;
1033 OptEnt.Undi->MajorVer = DEFAULT_UNDI_MAJOR;
1034 OptEnt.Undi->MinorVer = DEFAULT_UNDI_MINOR;
1035 }
1036
1037 Index++;
1038 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
1039
1040 //
1041 // Append client system architecture option
1042 //
1043 OptList[Index]->OpCode = PXEBC_PXE_DHCP4_TAG_ARCH;
1044 OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_ARCH);
1045 OptEnt.Arch = (PXEBC_DHCP4_OPTION_ARCH *) OptList[Index]->Data;
1046 Value = HTONS (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE);
1047 CopyMem (&OptEnt.Arch->Type, &Value, sizeof (UINT16));
1048 Index++;
1049 OptList[Index] = GET_NEXT_DHCP_OPTION (OptList[Index - 1]);
1050
1051 //
1052 // Append client system architecture option
1053 //
1054 OptList[Index]->OpCode = PXEBC_DHCP4_TAG_CLASS_ID;
1055 OptList[Index]->Length = (UINT8) sizeof (PXEBC_DHCP4_OPTION_CLID);
1056 OptEnt.Clid = (PXEBC_DHCP4_OPTION_CLID *) OptList[Index]->Data;
1057 CopyMem (OptEnt.Clid, DEFAULT_CLASS_ID_DATA, sizeof (PXEBC_DHCP4_OPTION_CLID));
1058 CvtNum (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE, OptEnt.Clid->ArchitectureType, sizeof (OptEnt.Clid->ArchitectureType));
1059
1060 if (Private->Nii != NULL) {
1061 //
1062 // If NII protocol exists, update DHCP option data
1063 //
1064 CopyMem (OptEnt.Clid->InterfaceName, Private->Nii->StringId, sizeof (OptEnt.Clid->InterfaceName));
1065 CvtNum (Private->Nii->MajorVer, OptEnt.Clid->UndiMajor, sizeof (OptEnt.Clid->UndiMajor));
1066 CvtNum (Private->Nii->MinorVer, OptEnt.Clid->UndiMinor, sizeof (OptEnt.Clid->UndiMinor));
1067 }
1068
1069 Index++;
1070
1071 return Index;
1072 }
1073
1074
1075 /**
1076 Discover the boot of service and initialize the vendor option if exists.
1077
1078 @param Private Pointer to PxeBc private data.
1079 @param Type PxeBc option boot item type
1080 @param Layer PxeBc option boot item layer
1081 @param UseBis Use BIS or not
1082 @param DestIp Ip address for server
1083 @param IpCount The total count of the server ip address
1084 @param SrvList Server list
1085 @param IsDiscv Discover the vendor or not
1086 @param Reply The dhcp4 packet of Pxe reply
1087
1088 @retval EFI_SUCCESS Operation succeeds.
1089 @retval EFI_OUT_OF_RESOURCES Allocate memory pool failed.
1090 @retval EFI_NOT_FOUND There is no vendor option exists.
1091 @retval EFI_TIMEOUT Send Pxe Discover time out.
1092
1093 **/
1094 EFI_STATUS
1095 PxeBcDiscvBootService (
1096 IN PXEBC_PRIVATE_DATA * Private,
1097 IN UINT16 Type,
1098 IN UINT16 *Layer,
1099 IN BOOLEAN UseBis,
1100 IN EFI_IP_ADDRESS * DestIp,
1101 IN UINT16 IpCount,
1102 IN EFI_PXE_BASE_CODE_SRVLIST * SrvList,
1103 IN BOOLEAN IsDiscv,
1104 OUT EFI_DHCP4_PACKET * Reply OPTIONAL
1105 )
1106 {
1107 EFI_PXE_BASE_CODE_UDP_PORT Sport;
1108 EFI_PXE_BASE_CODE_MODE *Mode;
1109 EFI_DHCP4_PROTOCOL *Dhcp4;
1110 EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN Token;
1111 BOOLEAN IsBCast;
1112 EFI_STATUS Status;
1113 UINT16 RepIndex;
1114 UINT16 SrvIndex;
1115 UINT16 TryIndex;
1116 EFI_DHCP4_LISTEN_POINT ListenPoint;
1117 EFI_DHCP4_PACKET *Response;
1118 EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM];
1119 UINT32 OptCount;
1120 EFI_DHCP4_PACKET_OPTION *PxeOpt;
1121 PXEBC_OPTION_BOOT_ITEM *PxeBootItem;
1122 UINT8 VendorOptLen;
1123 EFI_DHCP4_HEADER *DhcpHeader;
1124 UINT32 Xid;
1125
1126 Mode = Private->PxeBc.Mode;
1127 Dhcp4 = Private->Dhcp4;
1128 Status = EFI_SUCCESS;
1129
1130 ZeroMem (&Token, sizeof (EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN));
1131
1132 if (DestIp == NULL) {
1133 Sport = PXEBC_DHCP4_S_PORT;
1134 IsBCast = TRUE;
1135 } else {
1136 Sport = PXEBC_BS_DISCOVER_PORT;
1137 IsBCast = FALSE;
1138 }
1139
1140 if (!UseBis && Layer != NULL) {
1141 *Layer &= EFI_PXE_BASE_CODE_BOOT_LAYER_MASK;
1142 }
1143
1144 OptCount = PxeBcBuildDhcpOptions (Private, OptList, FALSE);
1145
1146 if (IsDiscv) {
1147 ASSERT (Layer != NULL);
1148 //
1149 // Add vendor option of PXE_BOOT_ITEM
1150 //
1151 VendorOptLen = (UINT8) ((sizeof (EFI_DHCP4_PACKET_OPTION) - 1) * 2 + sizeof (PXEBC_OPTION_BOOT_ITEM) + 1);
1152 OptList[OptCount] = AllocatePool (VendorOptLen);
1153 if (OptList[OptCount] == NULL) {
1154 return EFI_OUT_OF_RESOURCES;
1155 }
1156
1157 OptList[OptCount]->OpCode = PXEBC_DHCP4_TAG_VENDOR;
1158 OptList[OptCount]->Length = (UINT8) (VendorOptLen - 2);
1159 PxeOpt = (EFI_DHCP4_PACKET_OPTION *) OptList[OptCount]->Data;
1160 PxeOpt->OpCode = PXEBC_VENDOR_TAG_BOOT_ITEM;
1161 PxeOpt->Length = (UINT8) sizeof (PXEBC_OPTION_BOOT_ITEM);
1162 PxeBootItem = (PXEBC_OPTION_BOOT_ITEM *) PxeOpt->Data;
1163 PxeBootItem->Type = HTONS (Type);
1164 PxeBootItem->Layer = HTONS (*Layer);
1165 PxeOpt->Data[PxeOpt->Length] = PXEBC_DHCP4_TAG_EOP;
1166
1167 OptCount++;
1168 }
1169
1170 Status = Dhcp4->Build (Dhcp4, &Private->SeedPacket, 0, NULL, OptCount, OptList, &Token.Packet);
1171
1172 if (IsDiscv) {
1173 FreePool (OptList[OptCount - 1]);
1174 }
1175
1176 if (EFI_ERROR (Status)) {
1177 return Status;
1178 }
1179
1180 DhcpHeader = &Token.Packet->Dhcp4.Header;
1181 if (Mode->SendGUID) {
1182 if (EFI_ERROR (NetLibGetSystemGuid ((EFI_GUID *) DhcpHeader->ClientHwAddr))) {
1183 //
1184 // GUID not yet set - send all 0's to show not programable
1185 //
1186 ZeroMem (DhcpHeader->ClientHwAddr, sizeof (EFI_GUID));
1187 }
1188
1189 DhcpHeader->HwAddrLen = (UINT8) sizeof (EFI_GUID);
1190 }
1191
1192 Xid = NET_RANDOM (NetRandomInitSeed ());
1193 Token.Packet->Dhcp4.Header.Xid = HTONL(Xid);
1194 Token.Packet->Dhcp4.Header.Reserved = HTONS((UINT16) ((IsBCast) ? 0x8000 : 0));
1195 CopyMem (&Token.Packet->Dhcp4.Header.ClientAddr, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));
1196
1197 Token.RemotePort = Sport;
1198
1199 if (IsBCast) {
1200 SetMem (&Token.RemoteAddress, sizeof (EFI_IPv4_ADDRESS), 0xff);
1201 } else {
1202 CopyMem (&Token.RemoteAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));
1203 }
1204
1205 CopyMem (&Token.GatewayAddress, &Private->GatewayIp, sizeof (EFI_IPv4_ADDRESS));
1206
1207 if (!IsBCast) {
1208 Token.ListenPointCount = 1;
1209 Token.ListenPoints = &ListenPoint;
1210 Token.ListenPoints[0].ListenPort = PXEBC_BS_DISCOVER_PORT;
1211 CopyMem (&Token.ListenPoints[0].ListenAddress, &Private->StationIp, sizeof(EFI_IPv4_ADDRESS));
1212 CopyMem (&Token.ListenPoints[0].SubnetMask, &Private->SubnetMask, sizeof(EFI_IPv4_ADDRESS));
1213 }
1214 //
1215 // Send Pxe Discover
1216 //
1217 for (TryIndex = 1; TryIndex <= PXEBC_BOOT_REQUEST_RETRIES; TryIndex++) {
1218
1219 Token.TimeoutValue = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * TryIndex);
1220 Token.Packet->Dhcp4.Header.Seconds = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * (TryIndex - 1));
1221
1222 Status = Dhcp4->TransmitReceive (Dhcp4, &Token);
1223
1224 if (Token.Status != EFI_TIMEOUT) {
1225 break;
1226 }
1227 }
1228
1229 if (TryIndex > PXEBC_BOOT_REQUEST_RETRIES) {
1230 //
1231 // No server response our PXE request
1232 //
1233 Status = EFI_TIMEOUT;
1234 }
1235
1236 if (!EFI_ERROR (Status)) {
1237 //
1238 // Find Pxe Reply
1239 //
1240 RepIndex = 0;
1241 SrvIndex = 0;
1242 Response = Token.ResponseList;
1243
1244 while (RepIndex < Token.ResponseCount) {
1245
1246 while (SrvIndex < IpCount) {
1247
1248 if (SrvList[SrvIndex].AcceptAnyResponse) {
1249 break;
1250 }
1251
1252 if ((SrvList[SrvIndex].Type == Type) && EFI_IP4_EQUAL (&(Response->Dhcp4.Header.ServerAddr), &(Private->ServerIp))) {
1253 break;
1254 }
1255
1256 SrvIndex++;
1257 }
1258
1259 if ((IpCount != SrvIndex) || (IpCount == 0)) {
1260 break;
1261 }
1262
1263 SrvIndex = 0;
1264 RepIndex++;
1265
1266 Response = (EFI_DHCP4_PACKET *) ((UINT8 *) Response + Response->Size);
1267 }
1268
1269 if (RepIndex < Token.ResponseCount) {
1270
1271 if (Reply != NULL) {
1272 PxeBcCopyEfiDhcp4Packet (Reply, Response);
1273 }
1274
1275 if (IsDiscv) {
1276 CopyMem (&(Mode->PxeDiscover), &(Token.Packet->Dhcp4), Token.Packet->Length);
1277 Mode->PxeDiscoverValid = TRUE;
1278
1279 CopyMem (Mode->PxeReply.Raw, &Response->Dhcp4, Response->Length);
1280 Mode->PxeReplyReceived = TRUE;
1281 }
1282 } else {
1283 Status = EFI_NOT_FOUND;
1284 }
1285
1286 //
1287 // free the responselist
1288 //
1289 if (Token.ResponseList != NULL) {
1290 FreePool (Token.ResponseList);
1291 }
1292 }
1293 //
1294 // Free the dhcp packet
1295 //
1296 FreePool (Token.Packet);
1297
1298 return Status;
1299 }
1300
1301
1302 /**
1303 Parse interested dhcp options.
1304
1305 @param Buffer Pointer to the dhcp options packet.
1306 @param Length The length of the dhcp options.
1307 @param OptTag The option OpCode.
1308
1309 @return NULL if the buffer length is 0 and OpCode is not
1310 PXEBC_DHCP4_TAG_EOP, or the pointer to the buffer.
1311
1312 **/
1313 EFI_DHCP4_PACKET_OPTION *
1314 PxeBcParseExtendOptions (
1315 IN UINT8 *Buffer,
1316 IN UINT32 Length,
1317 IN UINT8 OptTag
1318 )
1319 {
1320 EFI_DHCP4_PACKET_OPTION *Option;
1321 UINT32 Offset;
1322
1323 Option = (EFI_DHCP4_PACKET_OPTION *) Buffer;
1324 Offset = 0;
1325
1326 while (Offset < Length && Option->OpCode != PXEBC_DHCP4_TAG_EOP) {
1327
1328 if (Option->OpCode == OptTag) {
1329
1330 return Option;
1331 }
1332
1333 if (Option->OpCode == PXEBC_DHCP4_TAG_PAD) {
1334 Offset++;
1335 } else {
1336 Offset += Option->Length + 2;
1337 }
1338
1339 Option = (EFI_DHCP4_PACKET_OPTION *) (Buffer + Offset);
1340 }
1341
1342 return NULL;
1343 }
1344
1345
1346 /**
1347 This function is to parse and check vendor options.
1348
1349 @param Dhcp4Option Pointer to dhcp options
1350 @param VendorOption Pointer to vendor options
1351
1352 @return TRUE if valid for vendor options, or FALSE.
1353
1354 **/
1355 BOOLEAN
1356 PxeBcParseVendorOptions (
1357 IN EFI_DHCP4_PACKET_OPTION *Dhcp4Option,
1358 IN PXEBC_VENDOR_OPTION *VendorOption
1359 )
1360 {
1361 UINT32 *BitMap;
1362 UINT8 VendorOptionLen;
1363 EFI_DHCP4_PACKET_OPTION *PxeOption;
1364 UINT8 Offset;
1365
1366 BitMap = VendorOption->BitMap;
1367 VendorOptionLen = Dhcp4Option->Length;
1368 PxeOption = (EFI_DHCP4_PACKET_OPTION *) &Dhcp4Option->Data[0];
1369 Offset = 0;
1370
1371 while ((Offset < VendorOptionLen) && (PxeOption->OpCode != PXEBC_DHCP4_TAG_EOP)) {
1372 //
1373 // Parse every Vendor Option and set its BitMap
1374 //
1375 switch (PxeOption->OpCode) {
1376
1377 case PXEBC_VENDOR_TAG_MTFTP_IP:
1378
1379 CopyMem (&VendorOption->MtftpIp, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));
1380 break;
1381
1382 case PXEBC_VENDOR_TAG_MTFTP_CPORT:
1383
1384 CopyMem (&VendorOption->MtftpCPort, PxeOption->Data, sizeof (VendorOption->MtftpCPort));
1385 break;
1386
1387 case PXEBC_VENDOR_TAG_MTFTP_SPORT:
1388
1389 CopyMem (&VendorOption->MtftpSPort, PxeOption->Data, sizeof (VendorOption->MtftpSPort));
1390 break;
1391
1392 case PXEBC_VENDOR_TAG_MTFTP_TIMEOUT:
1393
1394 VendorOption->MtftpTimeout = *PxeOption->Data;
1395 break;
1396
1397 case PXEBC_VENDOR_TAG_MTFTP_DELAY:
1398
1399 VendorOption->MtftpDelay = *PxeOption->Data;
1400 break;
1401
1402 case PXEBC_VENDOR_TAG_DISCOVER_CTRL:
1403
1404 VendorOption->DiscoverCtrl = *PxeOption->Data;
1405 break;
1406
1407 case PXEBC_VENDOR_TAG_DISCOVER_MCAST:
1408
1409 CopyMem (&VendorOption->DiscoverMcastIp, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));
1410 break;
1411
1412 case PXEBC_VENDOR_TAG_BOOT_SERVERS:
1413
1414 VendorOption->BootSvrLen = PxeOption->Length;
1415 VendorOption->BootSvr = (PXEBC_BOOT_SVR_ENTRY *) PxeOption->Data;
1416 break;
1417
1418 case PXEBC_VENDOR_TAG_BOOT_MENU:
1419
1420 VendorOption->BootMenuLen = PxeOption->Length;
1421 VendorOption->BootMenu = (PXEBC_BOOT_MENU_ENTRY *) PxeOption->Data;
1422 break;
1423
1424 case PXEBC_VENDOR_TAG_MENU_PROMPT:
1425
1426 VendorOption->MenuPromptLen = PxeOption->Length;
1427 VendorOption->MenuPrompt = (PXEBC_MENU_PROMPT *) PxeOption->Data;
1428 break;
1429
1430 case PXEBC_VENDOR_TAG_MCAST_ALLOC:
1431
1432 CopyMem (&VendorOption->McastIpBase, PxeOption->Data, sizeof (EFI_IPv4_ADDRESS));
1433 CopyMem (&VendorOption->McastIpBlock, PxeOption->Data + 4, sizeof (VendorOption->McastIpBlock));
1434 CopyMem (&VendorOption->McastIpRange, PxeOption->Data + 6, sizeof (VendorOption->McastIpRange));
1435 break;
1436
1437 case PXEBC_VENDOR_TAG_CREDENTIAL_TYPES:
1438
1439 VendorOption->CredTypeLen = PxeOption->Length;
1440 VendorOption->CredType = (UINT32 *) PxeOption->Data;
1441 break;
1442
1443 case PXEBC_VENDOR_TAG_BOOT_ITEM:
1444
1445 CopyMem (&VendorOption->BootSrvType, PxeOption->Data, sizeof (VendorOption->BootSrvType));
1446 CopyMem (&VendorOption->BootSrvLayer, PxeOption->Data + 2, sizeof (VendorOption->BootSrvLayer));
1447 break;
1448 }
1449
1450 SET_VENDOR_OPTION_BIT_MAP (BitMap, PxeOption->OpCode);
1451
1452 if (PxeOption->OpCode == PXEBC_DHCP4_TAG_PAD) {
1453 Offset++;
1454 } else {
1455 Offset = (UINT8) (Offset + PxeOption->Length + 2);
1456 }
1457
1458 PxeOption = (EFI_DHCP4_PACKET_OPTION *) (Dhcp4Option->Data + Offset);
1459 }
1460
1461 //
1462 // FixMe, return falas if invalid of any vendor option
1463 //
1464
1465 return TRUE;
1466 }
1467
1468
1469 /**
1470 This function display boot item detail.
1471
1472 If the length of the boot item string over 70 Char, just display 70 Char.
1473
1474 @param Str Pointer to a string (boot item string).
1475 @param Len The length of string.
1476
1477 **/
1478 VOID
1479 PxeBcDisplayBootItem (
1480 IN UINT8 *Str,
1481 IN UINT8 Len
1482 )
1483 {
1484 UINT8 Tmp;
1485
1486 Len = (UINT8) MIN (70, Len);
1487 Tmp = Str[Len];
1488 Str[Len] = 0;
1489 AsciiPrint ("%a \n", Str);
1490 Str[Len] = Tmp;
1491 }
1492
1493
1494 /**
1495 Choose the boot prompt.
1496
1497 @param Private Pointer to PxeBc private data.
1498
1499 @retval EFI_SUCCESS Select boot prompt done.
1500 @retval EFI_TIMEOUT Select boot prompt time out.
1501 @retval EFI_NOT_FOUND The proxy offer is not Pxe10.
1502 @retval EFI_ABORTED User cancel the operation.
1503 @retval EFI_NOT_READY Read the input key from the keybroad has not finish.
1504
1505 **/
1506 EFI_STATUS
1507 PxeBcSelectBootPrompt (
1508 IN PXEBC_PRIVATE_DATA *Private
1509 )
1510 {
1511 PXEBC_CACHED_DHCP4_PACKET *Packet;
1512 PXEBC_VENDOR_OPTION *VendorOpt;
1513 EFI_EVENT TimeoutEvent;
1514 EFI_EVENT DescendEvent;
1515 EFI_INPUT_KEY InputKey;
1516 EFI_STATUS Status;
1517 UINT8 Timeout;
1518 UINT8 *Prompt;
1519 UINT8 PromptLen;
1520 INT32 SecCol;
1521 INT32 SecRow;
1522
1523 TimeoutEvent = NULL;
1524 DescendEvent = NULL;
1525
1526 if (Private->PxeBc.Mode->ProxyOfferReceived) {
1527
1528 Packet = &Private->ProxyOffer;
1529 } else {
1530
1531 Packet = &Private->Dhcp4Ack;
1532 }
1533
1534 if (Packet->OfferType != DHCP4_PACKET_TYPE_PXE10) {
1535 return EFI_NOT_FOUND;
1536 }
1537
1538 VendorOpt = &Packet->PxeVendorOption;
1539 //
1540 // According to the PXE specification 2.1, Table 2-1 PXE DHCP Options,
1541 // we must not consider a boot prompt or boot menu if all of the following hold:
1542 // - the PXE_DISCOVERY_CONTROL tag(6) is present inside the Vendor Options(43), and has bit 3 set
1543 // - a boot file name has been presented in the initial DHCP or ProxyDHCP offer packet.
1544 //
1545 if (IS_DISABLE_PROMPT_MENU (VendorOpt->DiscoverCtrl) &&
1546 Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL) {
1547 return EFI_ABORTED;
1548 }
1549
1550 if (!IS_VALID_BOOT_PROMPT (VendorOpt->BitMap)) {
1551 return EFI_SUCCESS;
1552 }
1553
1554 Timeout = VendorOpt->MenuPrompt->Timeout;
1555 Prompt = VendorOpt->MenuPrompt->Prompt;
1556 PromptLen = (UINT8) (VendorOpt->MenuPromptLen - 1);
1557
1558 if (Timeout == 0) {
1559 return EFI_SUCCESS;
1560 }
1561
1562 if (Timeout == 255) {
1563 return EFI_TIMEOUT;
1564 }
1565
1566 Status = gBS->CreateEvent (
1567 EVT_TIMER,
1568 TPL_CALLBACK,
1569 NULL,
1570 NULL,
1571 &TimeoutEvent
1572 );
1573
1574 if (EFI_ERROR (Status)) {
1575 return Status;
1576 }
1577
1578 Status = gBS->SetTimer (
1579 TimeoutEvent,
1580 TimerRelative,
1581 Timeout * TICKS_PER_SECOND
1582 );
1583
1584 if (EFI_ERROR (Status)) {
1585 goto ON_EXIT;
1586 }
1587
1588 Status = gBS->CreateEvent (
1589 EVT_TIMER,
1590 TPL_CALLBACK,
1591 NULL,
1592 NULL,
1593 &DescendEvent
1594 );
1595
1596 if (EFI_ERROR (Status)) {
1597 goto ON_EXIT;
1598 }
1599
1600 Status = gBS->SetTimer (
1601 DescendEvent,
1602 TimerPeriodic,
1603 TICKS_PER_SECOND
1604 );
1605
1606 if (EFI_ERROR (Status)) {
1607 goto ON_EXIT;
1608 }
1609
1610 SecCol = gST->ConOut->Mode->CursorColumn;
1611 SecRow = gST->ConOut->Mode->CursorRow;
1612
1613 PxeBcDisplayBootItem (Prompt, PromptLen);
1614
1615 gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);
1616 AsciiPrint ("(%d) ", Timeout--);
1617
1618 while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))) {
1619
1620 if (!EFI_ERROR (gBS->CheckEvent (DescendEvent))) {
1621 gST->ConOut->SetCursorPosition (gST->ConOut, SecCol + PromptLen, SecRow);
1622 AsciiPrint ("(%d) ", Timeout--);
1623 }
1624
1625 if (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {
1626
1627 gBS->Stall (10 * TICKS_PER_MS);
1628 continue;
1629 }
1630
1631 if (InputKey.ScanCode == 0) {
1632
1633 switch (InputKey.UnicodeChar) {
1634 case CTRL ('c'):
1635 Status = EFI_ABORTED;
1636 break;
1637
1638 case CTRL ('m'):
1639 case 'm':
1640 case 'M':
1641 Status = EFI_TIMEOUT;
1642 break;
1643
1644 default:
1645 continue;
1646 }
1647 } else {
1648
1649 switch (InputKey.ScanCode) {
1650 case SCAN_F8:
1651 Status = EFI_TIMEOUT;
1652 break;
1653
1654 case SCAN_ESC:
1655 Status = EFI_ABORTED;
1656 break;
1657
1658 default:
1659 continue;
1660 }
1661 }
1662
1663 break;
1664 }
1665
1666 gST->ConOut->SetCursorPosition (gST->ConOut, 0 , SecRow + 1);
1667
1668 ON_EXIT:
1669
1670 if (DescendEvent != NULL) {
1671 gBS->CloseEvent (DescendEvent);
1672 }
1673
1674 if (TimeoutEvent != NULL) {
1675 gBS->CloseEvent (TimeoutEvent);
1676 }
1677
1678 return Status;
1679 }
1680
1681
1682 /**
1683 Select the boot menu.
1684
1685 @param Private Pointer to PxeBc private data.
1686 @param Type The type of the menu.
1687 @param UseDefaultItem Use default item or not.
1688
1689 @retval EFI_ABORTED User cancel operation.
1690 @retval EFI_SUCCESS Select the boot menu success.
1691 @retval EFI_NOT_READY Read the input key from the keybroad has not finish.
1692
1693 **/
1694 EFI_STATUS
1695 PxeBcSelectBootMenu (
1696 IN PXEBC_PRIVATE_DATA *Private,
1697 OUT UINT16 *Type,
1698 IN BOOLEAN UseDefaultItem
1699 )
1700 {
1701 PXEBC_CACHED_DHCP4_PACKET *Packet;
1702 PXEBC_VENDOR_OPTION *VendorOpt;
1703 EFI_INPUT_KEY InputKey;
1704 UINT8 MenuSize;
1705 UINT8 MenuNum;
1706 INT32 TopRow;
1707 UINT16 Select;
1708 UINT16 LastSelect;
1709 UINT8 Index;
1710 BOOLEAN Finish;
1711 CHAR8 Blank[70];
1712 PXEBC_BOOT_MENU_ENTRY *MenuItem;
1713 PXEBC_BOOT_MENU_ENTRY *MenuArray[PXEBC_MAX_MENU_NUM];
1714
1715 Finish = FALSE;
1716 Select = 1;
1717 Index = 0;
1718 *Type = 0;
1719
1720 if (Private->PxeBc.Mode->ProxyOfferReceived) {
1721
1722 Packet = &Private->ProxyOffer;
1723 } else {
1724
1725 Packet = &Private->Dhcp4Ack;
1726 }
1727
1728 ASSERT (Packet->OfferType == DHCP4_PACKET_TYPE_PXE10);
1729
1730 VendorOpt = &Packet->PxeVendorOption;
1731
1732 if (!IS_VALID_BOOT_MENU (VendorOpt->BitMap)) {
1733 return EFI_SUCCESS;
1734 }
1735
1736 SetMem (Blank, sizeof(Blank), ' ');
1737
1738 MenuSize = VendorOpt->BootMenuLen;
1739 MenuItem = VendorOpt->BootMenu;
1740
1741 if (MenuSize == 0) {
1742 return EFI_NOT_READY;
1743 }
1744
1745 while (MenuSize > 0) {
1746 MenuArray[Index++] = MenuItem;
1747 MenuSize = (UINT8) (MenuSize - (MenuItem->DescLen + 3));
1748 MenuItem = (PXEBC_BOOT_MENU_ENTRY *) ((UINT8 *) MenuItem + MenuItem->DescLen + 3);
1749 if (Index >= PXEBC_MAX_MENU_NUM) {
1750 break;
1751 }
1752 }
1753
1754 if (UseDefaultItem) {
1755 *Type = MenuArray[0]->Type;
1756 *Type = NTOHS (*Type);
1757 return EFI_SUCCESS;
1758 }
1759
1760 MenuNum = Index;
1761
1762 for (Index = 0; Index < MenuNum; Index++) {
1763 PxeBcDisplayBootItem (MenuArray[Index]->DescStr, MenuArray[Index]->DescLen);
1764 }
1765
1766 TopRow = gST->ConOut->Mode->CursorRow - MenuNum;
1767
1768 do {
1769 ASSERT (Select < PXEBC_MAX_MENU_NUM);
1770 //
1771 // highlight selected row
1772 //
1773 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));
1774 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + Select);
1775 Blank[MenuArray[Select]->DescLen] = 0;
1776 AsciiPrint ("%a\r", Blank);
1777 PxeBcDisplayBootItem (MenuArray[Select]->DescStr, MenuArray[Select]->DescLen);
1778 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);
1779 LastSelect = Select;
1780
1781 while (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {
1782 gBS->Stall (10 * TICKS_PER_MS);
1783 }
1784
1785 if (InputKey.ScanCode != 0) {
1786 switch (InputKey.UnicodeChar) {
1787 case CTRL ('c'):
1788 InputKey.ScanCode = SCAN_ESC;
1789 break;
1790
1791 case CTRL ('j'): /* linefeed */
1792 case CTRL ('m'): /* return */
1793 Finish = TRUE;
1794 break;
1795
1796 case CTRL ('i'): /* tab */
1797 case ' ':
1798 case 'd':
1799 case 'D':
1800 InputKey.ScanCode = SCAN_DOWN;
1801 break;
1802
1803 case CTRL ('h'): /* backspace */
1804 case 'u':
1805 case 'U':
1806 InputKey.ScanCode = SCAN_UP;
1807 break;
1808
1809 default:
1810 InputKey.ScanCode = 0;
1811 }
1812 }
1813
1814 switch (InputKey.ScanCode) {
1815 case SCAN_LEFT:
1816 case SCAN_UP:
1817 if (Select > 0) {
1818 --Select;
1819 }
1820
1821 break;
1822
1823 case SCAN_DOWN:
1824 case SCAN_RIGHT:
1825 if (++Select == MenuNum) {
1826 --Select;
1827 }
1828
1829 break;
1830
1831 case SCAN_PAGE_UP:
1832 case SCAN_HOME:
1833 Select = 0;
1834 break;
1835
1836 case SCAN_PAGE_DOWN:
1837 case SCAN_END:
1838 Select = (UINT16) (MenuNum - 1);
1839 break;
1840
1841 case SCAN_ESC:
1842 return EFI_ABORTED;
1843 }
1844
1845 /* unhighlight last selected row */
1846 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
1847 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + LastSelect);
1848 Blank[MenuArray[LastSelect]->DescLen] = 0;
1849 AsciiPrint ("%a\r", Blank);
1850 PxeBcDisplayBootItem (MenuArray[LastSelect]->DescStr, MenuArray[LastSelect]->DescLen);
1851 gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);
1852 } while (!Finish);
1853
1854 ASSERT (Select < PXEBC_MAX_MENU_NUM);
1855
1856 //
1857 // Swap the byte order
1858 //
1859 CopyMem (Type, &MenuArray[Select]->Type, sizeof (UINT16));
1860 *Type = NTOHS (*Type);
1861
1862 return EFI_SUCCESS;
1863 }
1864