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