Changeset 99404 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
- Timestamp:
- Apr 14, 2023 3:17:44 PM (22 months ago)
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-145445 /vendor/edk2/current 103735-103757,103769-103776,129194-156846
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
r85718 r99404 16 16 // ALL_DHCP_Relay_Agents_and_Servers address: FF02::1:2 17 17 // 18 EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress = {{0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2}}; 18 EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress = { 19 { 0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2 } 20 }; 19 21 20 22 /** … … 31 33 EFI_DHCP6_PACKET_OPTION * 32 34 PxeBcParseDhcp6Options ( 33 IN UINT8 34 IN UINT32 35 IN UINT16 35 IN UINT8 *Buffer, 36 IN UINT32 Length, 37 IN UINT16 OptTag 36 38 ) 37 39 { 38 EFI_DHCP6_PACKET_OPTION 39 UINT32 40 41 Option = (EFI_DHCP6_PACKET_OPTION *)Buffer;42 Offset 40 EFI_DHCP6_PACKET_OPTION *Option; 41 UINT32 Offset; 42 43 Option = (EFI_DHCP6_PACKET_OPTION *)Buffer; 44 Offset = 0; 43 45 44 46 // … … 46 48 // 47 49 while (Offset < Length) { 48 49 50 if (NTOHS (Option->OpCode) == OptTag) { 50 51 51 return Option; 52 52 } 53 53 54 Offset += (NTOHS (Option->OpLen) + 4);55 Option = (EFI_DHCP6_PACKET_OPTION *) 54 Offset += (NTOHS (Option->OpLen) + 4); 55 Option = (EFI_DHCP6_PACKET_OPTION *)(Buffer + Offset); 56 56 } 57 57 58 58 return NULL; 59 59 } 60 61 60 62 61 /** … … 72 71 UINT32 73 72 PxeBcBuildDhcp6Options ( 74 IN PXEBC_PRIVATE_DATA 75 OUT EFI_DHCP6_PACKET_OPTION 76 IN UINT8 73 IN PXEBC_PRIVATE_DATA *Private, 74 OUT EFI_DHCP6_PACKET_OPTION **OptList, 75 IN UINT8 *Buffer 77 76 ) 78 77 { 79 PXEBC_DHCP6_OPTION_ENTRY 80 UINT32 81 UINT16 82 83 Index 84 OptList[0] = (EFI_DHCP6_PACKET_OPTION *)Buffer;78 PXEBC_DHCP6_OPTION_ENTRY OptEnt; 79 UINT32 Index; 80 UINT16 Value; 81 82 Index = 0; 83 OptList[0] = (EFI_DHCP6_PACKET_OPTION *)Buffer; 85 84 86 85 // 87 86 // Append client option request option 88 87 // 89 OptList[Index]->OpCode 90 OptList[Index]->OpLen 91 OptEnt.Oro = (PXEBC_DHCP6_OPTION_ORO *)OptList[Index]->Data;92 OptEnt.Oro->OpCode[0] = HTONS(DHCP6_OPT_BOOT_FILE_URL);93 OptEnt.Oro->OpCode[1] = HTONS(DHCP6_OPT_BOOT_FILE_PARAM);94 OptEnt.Oro->OpCode[2] = HTONS(DHCP6_OPT_DNS_SERVERS);95 OptEnt.Oro->OpCode[3] = HTONS(DHCP6_OPT_VENDOR_CLASS);88 OptList[Index]->OpCode = HTONS (DHCP6_OPT_ORO); 89 OptList[Index]->OpLen = HTONS (8); 90 OptEnt.Oro = (PXEBC_DHCP6_OPTION_ORO *)OptList[Index]->Data; 91 OptEnt.Oro->OpCode[0] = HTONS (DHCP6_OPT_BOOT_FILE_URL); 92 OptEnt.Oro->OpCode[1] = HTONS (DHCP6_OPT_BOOT_FILE_PARAM); 93 OptEnt.Oro->OpCode[2] = HTONS (DHCP6_OPT_DNS_SERVERS); 94 OptEnt.Oro->OpCode[3] = HTONS (DHCP6_OPT_VENDOR_CLASS); 96 95 Index++; 97 OptList[Index] 96 OptList[Index] = GET_NEXT_DHCP6_OPTION (OptList[Index - 1]); 98 97 99 98 // 100 99 // Append client network device interface option 101 100 // 102 OptList[Index]->OpCode 103 OptList[Index]->OpLen 104 OptEnt.Undi = (PXEBC_DHCP6_OPTION_UNDI *)OptList[Index]->Data;101 OptList[Index]->OpCode = HTONS (DHCP6_OPT_UNDI); 102 OptList[Index]->OpLen = HTONS ((UINT16)3); 103 OptEnt.Undi = (PXEBC_DHCP6_OPTION_UNDI *)OptList[Index]->Data; 105 104 106 105 if (Private->Nii != NULL) { 107 OptEnt.Undi->Type 108 OptEnt.Undi->MajorVer 109 OptEnt.Undi->MinorVer 106 OptEnt.Undi->Type = Private->Nii->Type; 107 OptEnt.Undi->MajorVer = Private->Nii->MajorVer; 108 OptEnt.Undi->MinorVer = Private->Nii->MinorVer; 110 109 } else { 111 OptEnt.Undi->Type 112 OptEnt.Undi->MajorVer 113 OptEnt.Undi->MinorVer 110 OptEnt.Undi->Type = DEFAULT_UNDI_TYPE; 111 OptEnt.Undi->MajorVer = DEFAULT_UNDI_MAJOR; 112 OptEnt.Undi->MinorVer = DEFAULT_UNDI_MINOR; 114 113 } 115 114 116 115 Index++; 117 OptList[Index] 116 OptList[Index] = GET_NEXT_DHCP6_OPTION (OptList[Index - 1]); 118 117 119 118 // 120 119 // Append client system architecture option 121 120 // 122 OptList[Index]->OpCode 123 OptList[Index]->OpLen = HTONS ((UINT16)sizeof (PXEBC_DHCP6_OPTION_ARCH));124 OptEnt.Arch = (PXEBC_DHCP6_OPTION_ARCH *)OptList[Index]->Data;125 Value 121 OptList[Index]->OpCode = HTONS (DHCP6_OPT_ARCH); 122 OptList[Index]->OpLen = HTONS ((UINT16)sizeof (PXEBC_DHCP6_OPTION_ARCH)); 123 OptEnt.Arch = (PXEBC_DHCP6_OPTION_ARCH *)OptList[Index]->Data; 124 Value = HTONS (EFI_PXE_CLIENT_SYSTEM_ARCHITECTURE); 126 125 CopyMem (&OptEnt.Arch->Type, &Value, sizeof (UINT16)); 127 126 Index++; 128 OptList[Index] 127 OptList[Index] = GET_NEXT_DHCP6_OPTION (OptList[Index - 1]); 129 128 130 129 // … … 132 131 // 133 132 OptList[Index]->OpCode = HTONS (DHCP6_OPT_VENDOR_CLASS); 134 OptList[Index]->OpLen = HTONS ((UINT16) 135 OptEnt.VendorClass = (PXEBC_DHCP6_OPTION_VENDOR_CLASS *) 133 OptList[Index]->OpLen = HTONS ((UINT16)sizeof (PXEBC_DHCP6_OPTION_VENDOR_CLASS)); 134 OptEnt.VendorClass = (PXEBC_DHCP6_OPTION_VENDOR_CLASS *)OptList[Index]->Data; 136 135 OptEnt.VendorClass->Vendor = HTONL (PXEBC_DHCP6_ENTERPRISE_NUM); 137 OptEnt.VendorClass->ClassLen = HTONS ((UINT16) 136 OptEnt.VendorClass->ClassLen = HTONS ((UINT16)sizeof (PXEBC_CLASS_ID)); 138 137 CopyMem ( 139 138 &OptEnt.VendorClass->ClassId, … … 170 169 } 171 170 172 173 171 /** 174 172 Cache the DHCPv6 packet. … … 183 181 EFI_STATUS 184 182 PxeBcCacheDhcp6Packet ( 185 IN EFI_DHCP6_PACKET 186 IN EFI_DHCP6_PACKET 183 IN EFI_DHCP6_PACKET *Dst, 184 IN EFI_DHCP6_PACKET *Src 187 185 ) 188 186 { … … 212 210 EFI_STATUS 213 211 PxeBcDns6 ( 214 IN PXEBC_PRIVATE_DATA 215 IN CHAR16 216 OUT EFI_IPv6_ADDRESS*IpAddress212 IN PXEBC_PRIVATE_DATA *Private, 213 IN CHAR16 *HostName, 214 OUT EFI_IPv6_ADDRESS *IpAddress 217 215 ) 218 216 { 219 EFI_STATUS 220 EFI_DNS6_PROTOCOL 221 EFI_DNS6_CONFIG_DATA 222 EFI_DNS6_COMPLETION_TOKEN 223 EFI_HANDLE 224 EFI_IPv6_ADDRESS 225 BOOLEAN 226 227 Dns6 228 Dns6Handle 229 DnsServerList 217 EFI_STATUS Status; 218 EFI_DNS6_PROTOCOL *Dns6; 219 EFI_DNS6_CONFIG_DATA Dns6ConfigData; 220 EFI_DNS6_COMPLETION_TOKEN Token; 221 EFI_HANDLE Dns6Handle; 222 EFI_IPv6_ADDRESS *DnsServerList; 223 BOOLEAN IsDone; 224 225 Dns6 = NULL; 226 Dns6Handle = NULL; 227 DnsServerList = Private->DnsServer; 230 228 ZeroMem (&Token, sizeof (EFI_DNS6_COMPLETION_TOKEN)); 231 229 … … 246 244 Dns6Handle, 247 245 &gEfiDns6ProtocolGuid, 248 (VOID **) 246 (VOID **)&Dns6, 249 247 Private->Image, 250 248 Private->Controller, … … 309 307 goto Exit; 310 308 } 311 if (Token.RspData.H2AData->IpCount == 0 || Token.RspData.H2AData->IpList == NULL) { 309 310 if ((Token.RspData.H2AData->IpCount == 0) || (Token.RspData.H2AData->IpList == NULL)) { 312 311 Status = EFI_DEVICE_ERROR; 313 312 goto Exit; 314 313 } 314 315 315 // 316 316 // We just return the first IPv6 address from DNS protocol. … … 326 326 gBS->CloseEvent (Token.Event); 327 327 } 328 328 329 if (Token.RspData.H2AData != NULL) { 329 330 if (Token.RspData.H2AData->IpList != NULL) { 330 331 FreePool (Token.RspData.H2AData->IpList); 331 332 } 333 332 334 FreePool (Token.RspData.H2AData); 333 335 } … … 376 378 EFI_STATUS 377 379 PxeBcExtractBootFileUrl ( 378 IN PXEBC_PRIVATE_DATA 379 OUT UINT8**FileName,380 IN OUT EFI_IPv6_ADDRESS 381 IN CHAR8 382 IN UINT16 380 IN PXEBC_PRIVATE_DATA *Private, 381 OUT UINT8 **FileName, 382 IN OUT EFI_IPv6_ADDRESS *SrvAddr, 383 IN CHAR8 *BootFile, 384 IN UINT16 Length 383 385 ) 384 386 { 385 UINT16 386 CHAR8 387 CHAR8 388 UINT16 389 CHAR8 390 CHAR8 391 CHAR8 392 CHAR8 393 CHAR8 394 CHAR16 395 BOOLEAN 396 UINTN 397 EFI_STATUS 387 UINT16 PrefixLen; 388 CHAR8 *BootFileNamePtr; 389 CHAR8 *BootFileName; 390 UINT16 BootFileNameLen; 391 CHAR8 *TmpStr; 392 CHAR8 TmpChar; 393 CHAR8 *ServerAddressOption; 394 CHAR8 *ServerAddress; 395 CHAR8 *ModeStr; 396 CHAR16 *HostName; 397 BOOLEAN IpExpressedUrl; 398 UINTN Len; 399 EFI_STATUS Status; 398 400 399 401 IpExpressedUrl = TRUE; … … 418 420 // SERVER_ADDRESS is the ASCII encoding of an IPV6 address. 419 421 // 420 PrefixLen = (UINT16) AsciiStrLen (PXEBC_DHCP6_BOOT_FILE_URL_PREFIX); 421 422 if (Length <= PrefixLen || 423 CompareMem (BootFile, PXEBC_DHCP6_BOOT_FILE_URL_PREFIX, PrefixLen) != 0) { 422 PrefixLen = (UINT16)AsciiStrLen (PXEBC_DHCP6_BOOT_FILE_URL_PREFIX); 423 424 if ((Length <= PrefixLen) || 425 (CompareMem (BootFile, PXEBC_DHCP6_BOOT_FILE_URL_PREFIX, PrefixLen) != 0)) 426 { 424 427 return EFI_NOT_FOUND; 425 428 } 426 429 427 430 BootFile = BootFile + PrefixLen; 428 Length = (UINT16) 429 430 TmpStr = (CHAR8 *) 431 Length = (UINT16)(Length - PrefixLen); 432 433 TmpStr = (CHAR8 *)AllocateZeroPool (Length + 1); 431 434 if (TmpStr == NULL) { 432 435 return EFI_OUT_OF_RESOURCES; … … 441 444 ServerAddressOption = TmpStr; 442 445 if (*ServerAddressOption == PXEBC_ADDR_START_DELIMITER) { 443 ServerAddressOption 446 ServerAddressOption++; 444 447 ServerAddress = ServerAddressOption; 445 448 while (*ServerAddress != '\0' && *ServerAddress != PXEBC_ADDR_END_DELIMITER) { … … 462 465 return Status; 463 466 } 464 465 467 } else { 466 468 IpExpressedUrl = FALSE; 467 ServerAddress = ServerAddressOption;469 ServerAddress = ServerAddressOption; 468 470 while (*ServerAddress != '\0' && *ServerAddress != PXEBC_TFTP_URL_SEPARATOR) { 469 471 ServerAddress++; … … 474 476 return EFI_INVALID_PARAMETER; 475 477 } 478 476 479 *ServerAddress = '\0'; 477 480 478 Len = AsciiStrSize (ServerAddressOption);481 Len = AsciiStrSize (ServerAddressOption); 479 482 HostName = AllocateZeroPool (Len * sizeof (CHAR16)); 480 483 if (HostName == NULL) { … … 482 485 return EFI_OUT_OF_RESOURCES; 483 486 } 487 484 488 AsciiStrToUnicodeStrS ( 485 489 ServerAddressOption, … … 491 495 // Perform DNS resolution. 492 496 // 493 Status = PxeBcDns6 (Private, HostName, SrvAddr);497 Status = PxeBcDns6 (Private, HostName, SrvAddr); 494 498 if (EFI_ERROR (Status)) { 495 499 FreePool (TmpStr); … … 501 505 // Get the part of BOOTFILE_NAME string. 502 506 // 503 BootFileNamePtr = (CHAR8 *)((UINTN)ServerAddress + 1);507 BootFileNamePtr = (CHAR8 *)((UINTN)ServerAddress + 1); 504 508 if (IpExpressedUrl) { 505 509 if (*BootFileNamePtr != PXEBC_TFTP_URL_SEPARATOR) { … … 507 511 return EFI_INVALID_PARAMETER; 508 512 } 513 509 514 ++BootFileNamePtr; 510 515 } 511 516 512 BootFileNameLen = (UINT16)(Length - (UINT16) 513 if ( BootFileNameLen != 0 || FileName != NULL) {517 BootFileNameLen = (UINT16)(Length - (UINT16)((UINTN)BootFileNamePtr - (UINTN)TmpStr) + 1); 518 if ((BootFileNameLen != 0) || (FileName != NULL)) { 514 519 // 515 520 // Remove trailing mode=octet if present and ignore. All other modes are … … 517 522 // 518 523 ModeStr = AsciiStrStr (BootFileNamePtr, ";mode=octet"); 519 if ( ModeStr != NULL && *(ModeStr + AsciiStrLen (";mode=octet")) == '\0') {524 if ((ModeStr != NULL) && (*(ModeStr + AsciiStrLen (";mode=octet")) == '\0')) { 520 525 *ModeStr = '\0'; 521 526 } else if (AsciiStrStr (BootFileNamePtr, ";mode=") != NULL) { … … 527 532 // Extract boot file name from URL. 528 533 // 529 BootFileName = (CHAR8 *) 534 BootFileName = (CHAR8 *)AllocateZeroPool (BootFileNameLen); 530 535 if (BootFileName == NULL) { 531 536 FreePool (TmpStr); 532 537 return EFI_OUT_OF_RESOURCES; 533 538 } 534 *FileName = (UINT8*) BootFileName; 539 540 *FileName = (UINT8 *)BootFileName; 535 541 536 542 // … … 539 545 while (*BootFileNamePtr != '\0') { 540 546 if (*BootFileNamePtr == '%') { 541 TmpChar = *(BootFileNamePtr+ 3);547 TmpChar = *(BootFileNamePtr+ 3); 542 548 *(BootFileNamePtr+ 3) = '\0'; 543 *BootFileName = (UINT8) AsciiStrHexToUintn ((CHAR8*)(BootFileNamePtr + 1));549 *BootFileName = (UINT8)AsciiStrHexToUintn ((CHAR8 *)(BootFileNamePtr + 1)); 544 550 BootFileName++; 545 551 *(BootFileNamePtr+ 3) = TmpChar; 546 BootFileNamePtr += 3;552 BootFileNamePtr += 3; 547 553 } else { 548 554 *BootFileName = *BootFileNamePtr; … … 551 557 } 552 558 } 559 553 560 *BootFileName = '\0'; 554 561 } … … 558 565 return EFI_SUCCESS; 559 566 } 560 561 567 562 568 /** … … 572 578 EFI_STATUS 573 579 PxeBcExtractBootFileParam ( 574 IN CHAR8 575 OUT UINT16 580 IN CHAR8 *BootFilePara, 581 OUT UINT16 *BootFileSize 576 582 ) 577 583 { 578 UINT16 579 UINT8 580 UINT8 581 UINT32 584 UINT16 Length; 585 UINT8 Index; 586 UINT8 Digit; 587 UINT32 Size; 582 588 583 589 CopyMem (&Length, BootFilePara, sizeof (UINT16)); … … 587 593 // The BootFile Size should be 1~5 byte ASCII strings 588 594 // 589 if ( Length < 1 || Length > 5) {595 if ((Length < 1) || (Length > 5)) { 590 596 return EFI_NOT_FOUND; 591 597 } … … 609 615 } 610 616 611 *BootFileSize = (UINT16) 617 *BootFileSize = (UINT16)Size; 612 618 return EFI_SUCCESS; 613 619 } 614 615 620 616 621 /** … … 628 633 ) 629 634 { 630 EFI_DHCP6_PACKET 631 EFI_DHCP6_PACKET_OPTION 632 EFI_DHCP6_PACKET_OPTION 633 PXEBC_OFFER_TYPE 634 BOOLEAN 635 BOOLEAN 636 UINT32 637 UINT32 638 UINT32 635 EFI_DHCP6_PACKET *Offer; 636 EFI_DHCP6_PACKET_OPTION **Options; 637 EFI_DHCP6_PACKET_OPTION *Option; 638 PXEBC_OFFER_TYPE OfferType; 639 BOOLEAN IsProxyOffer; 640 BOOLEAN IsPxeOffer; 641 UINT32 Offset; 642 UINT32 Length; 643 UINT32 EnterpriseNum; 639 644 640 645 IsProxyOffer = TRUE; … … 645 650 ZeroMem (Cache6->OptList, sizeof (Cache6->OptList)); 646 651 647 Option = (EFI_DHCP6_PACKET_OPTION *)(Offer->Dhcp6.Option);648 Offset 649 Length 652 Option = (EFI_DHCP6_PACKET_OPTION *)(Offer->Dhcp6.Option); 653 Offset = 0; 654 Length = GET_DHCP6_OPTION_SIZE (Offer); 650 655 651 656 // … … 653 658 // 654 659 while (Offset < Length) { 655 656 660 if (NTOHS (Option->OpCode) == DHCP6_OPT_IA_NA) { 657 661 Options[PXEBC_DHCP6_IDX_IA_NA] = Option; … … 670 674 671 675 Offset += (NTOHS (Option->OpLen) + 4); 672 Option = (EFI_DHCP6_PACKET_OPTION *) 676 Option = (EFI_DHCP6_PACKET_OPTION *)(Offer->Dhcp6.Option + Offset); 673 677 } 674 678 … … 684 688 DHCP6_OPT_STATUS_CODE 685 689 ); 686 if (( Option != NULL && Option->Data[0] == 0) || (Option == NULL)) {690 if (((Option != NULL) && (Option->Data[0] == 0)) || (Option == NULL)) { 687 691 IsProxyOffer = FALSE; 688 692 } … … 693 697 // 694 698 Option = Options[PXEBC_DHCP6_IDX_VENDOR_CLASS]; 695 EnterpriseNum = HTONL(PXEBC_DHCP6_ENTERPRISE_NUM); 696 697 if (Option != NULL && 698 NTOHS(Option->OpLen) >= 13 && 699 CompareMem (Option->Data, &EnterpriseNum, sizeof (UINT32)) == 0 && 700 CompareMem (&Option->Data[6], DEFAULT_CLASS_ID_DATA, 9) == 0) { 699 EnterpriseNum = HTONL (PXEBC_DHCP6_ENTERPRISE_NUM); 700 701 if ((Option != NULL) && 702 (NTOHS (Option->OpLen) >= 13) && 703 (CompareMem (Option->Data, &EnterpriseNum, sizeof (UINT32)) == 0) && 704 (CompareMem (&Option->Data[6], DEFAULT_CLASS_ID_DATA, 9) == 0)) 705 { 701 706 IsPxeOffer = TRUE; 702 707 } … … 721 726 return EFI_SUCCESS; 722 727 } 723 724 728 725 729 /** … … 736 740 EFI_STATUS 737 741 PxeBcCopyDhcp6Ack ( 738 IN PXEBC_PRIVATE_DATA 739 IN EFI_DHCP6_PACKET 740 IN BOOLEAN 742 IN PXEBC_PRIVATE_DATA *Private, 743 IN EFI_DHCP6_PACKET *Ack, 744 IN BOOLEAN Verified 741 745 ) 742 746 { … … 763 767 } 764 768 765 766 769 /** 767 770 Cache the DHCPv6 proxy offer packet according to the received order. … … 776 779 EFI_STATUS 777 780 PxeBcCopyDhcp6Proxy ( 778 IN PXEBC_PRIVATE_DATA 779 IN UINT32 781 IN PXEBC_PRIVATE_DATA *Private, 782 IN UINT32 OfferIndex 780 783 ) 781 784 { 782 EFI_PXE_BASE_CODE_MODE 783 EFI_DHCP6_PACKET 785 EFI_PXE_BASE_CODE_MODE *Mode; 786 EFI_DHCP6_PACKET *Offer; 784 787 EFI_STATUS Status; 785 788 … … 794 797 // 795 798 Status = PxeBcCacheDhcp6Packet (&Private->ProxyOffer.Dhcp6.Packet.Offer, Offer); 796 if (EFI_ERROR (Status)) {799 if (EFI_ERROR (Status)) { 797 800 return Status; 798 801 } 802 799 803 PxeBcParseDhcp6Packet (&Private->ProxyOffer.Dhcp6); 800 804 … … 821 825 UINT8 * 822 826 PxeBcDhcp6SeekOption ( 823 IN UINT8 824 IN UINT32 825 IN UINT16 827 IN UINT8 *Buf, 828 IN UINT32 SeekLen, 829 IN UINT16 OptType 826 830 ) 827 831 { 828 UINT8 829 UINT8 830 UINT16 831 UINT16 832 UINT8 *Cursor; 833 UINT8 *Option; 834 UINT16 DataLen; 835 UINT16 OpCode; 832 836 833 837 Option = NULL; … … 835 839 836 840 while (Cursor < Buf + SeekLen) { 837 OpCode = ReadUnaligned16 ((UINT16 *) 841 OpCode = ReadUnaligned16 ((UINT16 *)Cursor); 838 842 if (OpCode == HTONS (OptType)) { 839 843 Option = Cursor; 840 844 break; 841 845 } 842 DataLen = NTOHS (ReadUnaligned16 ((UINT16 *) (Cursor + 2))); 846 847 DataLen = NTOHS (ReadUnaligned16 ((UINT16 *)(Cursor + 2))); 843 848 Cursor += (DataLen + 4); 844 849 } … … 846 851 return Option; 847 852 } 848 849 853 850 854 /** … … 862 866 EFI_STATUS 863 867 PxeBcRequestBootService ( 864 IN PXEBC_PRIVATE_DATA 865 IN UINT32 868 IN PXEBC_PRIVATE_DATA *Private, 869 IN UINT32 Index 866 870 ) 867 871 { 868 EFI_PXE_BASE_CODE_UDP_PORT 869 EFI_PXE_BASE_CODE_UDP_PORT 870 EFI_PXE_BASE_CODE_PROTOCOL 871 EFI_PXE_BASE_CODE_DHCPV6_PACKET 872 UINTN 873 EFI_DHCP6_PACKET 874 UINTN 875 EFI_DHCP6_PACKET 876 UINT8 877 UINT8 878 UINTN 879 UINT16 880 UINT16 881 UINT16 882 EFI_STATUS 883 EFI_DHCP6_PACKET 884 UINT8 885 886 PxeBc 887 Request 888 IndexOffer 889 SrcPort 890 DestPort 891 OpFlags 872 EFI_PXE_BASE_CODE_UDP_PORT SrcPort; 873 EFI_PXE_BASE_CODE_UDP_PORT DestPort; 874 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc; 875 EFI_PXE_BASE_CODE_DHCPV6_PACKET *Discover; 876 UINTN DiscoverLen; 877 EFI_DHCP6_PACKET *Request; 878 UINTN RequestLen; 879 EFI_DHCP6_PACKET *Reply; 880 UINT8 *RequestOpt; 881 UINT8 *DiscoverOpt; 882 UINTN ReadSize; 883 UINT16 OpFlags; 884 UINT16 OpCode; 885 UINT16 OpLen; 886 EFI_STATUS Status; 887 EFI_DHCP6_PACKET *IndexOffer; 888 UINT8 *Option; 889 890 PxeBc = &Private->PxeBc; 891 Request = Private->Dhcp6Request; 892 IndexOffer = &Private->OfferBuffer[Index].Dhcp6.Packet.Offer; 893 SrcPort = PXEBC_BS_DISCOVER_PORT; 894 DestPort = PXEBC_BS_DISCOVER_PORT; 895 OpFlags = 0; 892 896 893 897 if (Request == NULL) { … … 926 930 // Add Server ID Option. 927 931 // 928 OpLen = NTOHS (((EFI_DHCP6_PACKET_OPTION *) 932 OpLen = NTOHS (((EFI_DHCP6_PACKET_OPTION *)Option)->OpLen); 929 933 CopyMem (DiscoverOpt, Option, OpLen + 4); 930 934 DiscoverOpt += (OpLen + 4); … … 933 937 934 938 while (RequestLen < Request->Length) { 935 OpCode = NTOHS (((EFI_DHCP6_PACKET_OPTION *) RequestOpt)->OpCode); 936 OpLen = NTOHS (((EFI_DHCP6_PACKET_OPTION *) RequestOpt)->OpLen); 937 if (OpCode != EFI_DHCP6_IA_TYPE_NA && 938 OpCode != EFI_DHCP6_IA_TYPE_TA && 939 OpCode != DHCP6_OPT_SERVER_ID 940 ) { 939 OpCode = NTOHS (((EFI_DHCP6_PACKET_OPTION *)RequestOpt)->OpCode); 940 OpLen = NTOHS (((EFI_DHCP6_PACKET_OPTION *)RequestOpt)->OpLen); 941 if ((OpCode != EFI_DHCP6_IA_TYPE_NA) && 942 (OpCode != EFI_DHCP6_IA_TYPE_TA) && 943 (OpCode != DHCP6_OPT_SERVER_ID) 944 ) 945 { 941 946 // 942 947 // Copy all the options except IA option and Server ID … … 946 951 DiscoverLen += (OpLen + 4); 947 952 } 953 948 954 RequestOpt += (OpLen + 4); 949 955 RequestLen += (OpLen + 4); … … 960 966 if (Option != NULL) { 961 967 CalcElapsedTime (Private); 962 WriteUnaligned16 ((UINT16 *)(Option + 4), HTONS((UINT16)Private->ElapsedTime));968 WriteUnaligned16 ((UINT16 *)(Option + 4), HTONS ((UINT16)Private->ElapsedTime)); 963 969 } 964 970 … … 974 980 NULL, 975 981 &DiscoverLen, 976 (VOID *) 982 (VOID *)Discover 977 983 ); 978 984 … … 985 991 // Especially for PXE discover packet, store it into mode data here. 986 992 // 987 Reply = &Private->ProxyOffer.Dhcp6.Packet.Offer;988 ReadSize = (UINTN) 993 Reply = &Private->ProxyOffer.Dhcp6.Packet.Offer; 994 ReadSize = (UINTN)Reply->Size; 989 995 990 996 // … … 1006 1012 NULL, 1007 1013 &ReadSize, 1008 (VOID *) 1014 (VOID *)&Reply->Dhcp6 1009 1015 ); 1010 1016 // … … 1020 1026 // Update length 1021 1027 // 1022 Reply->Length = (UINT32) 1028 Reply->Length = (UINT32)ReadSize; 1023 1029 1024 1030 return EFI_SUCCESS; … … 1031 1037 return Status; 1032 1038 } 1033 1034 1039 1035 1040 /** … … 1055 1060 1056 1061 ASSERT (Index < PXEBC_OFFER_MAX_NUM); 1057 ASSERT (Private->OfferBuffer[Index].Dhcp6.OfferType == PxeOfferTypeDhcpBinl || 1058 Private->OfferBuffer[Index].Dhcp6.OfferType == PxeOfferTypeProxyBinl); 1062 ASSERT ( 1063 Private->OfferBuffer[Index].Dhcp6.OfferType == PxeOfferTypeDhcpBinl || 1064 Private->OfferBuffer[Index].Dhcp6.OfferType == PxeOfferTypeProxyBinl 1065 ); 1059 1066 1060 1067 Mode = Private->PxeBc.Mode; … … 1079 1086 &Private->BootFileName, 1080 1087 &Private->ServerIp.v6, 1081 (CHAR8 *) 1088 (CHAR8 *)(Offer->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL]->Data), 1082 1089 NTOHS (Offer->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL]->OpLen) 1083 1090 ); … … 1102 1109 } 1103 1110 1104 if (Cache6->OfferType != PxeOfferTypeProxyPxe10 && 1105 Cache6->OfferType != PxeOfferTypeProxyWfm11a && 1106 Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] == NULL) { 1111 if ((Cache6->OfferType != PxeOfferTypeProxyPxe10) && 1112 (Cache6->OfferType != PxeOfferTypeProxyWfm11a) && 1113 (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] == NULL)) 1114 { 1107 1115 // 1108 1116 // This BINL ack doesn't have discovery option set or multicast option set … … 1122 1130 } 1123 1131 1124 1125 1132 /** 1126 1133 Cache all the received DHCPv6 offers, and set OfferIndex and OfferCount. … … 1134 1141 EFI_STATUS 1135 1142 PxeBcCacheDhcp6Offer ( 1136 IN PXEBC_PRIVATE_DATA 1137 IN EFI_DHCP6_PACKET 1143 IN PXEBC_PRIVATE_DATA *Private, 1144 IN EFI_DHCP6_PACKET *RcvdOffer 1138 1145 ) 1139 1146 { … … 1180 1187 Private->OfferIndex[OfferType][Private->OfferCount[OfferType]] = Private->OfferNum; 1181 1188 Private->OfferCount[OfferType]++; 1182 } else if ((OfferType == PxeOfferTypeProxyPxe10 || OfferType == PxeOfferTypeProxyWfm11a) && 1183 Private->OfferCount[OfferType] < 1) { 1189 } else if (((OfferType == PxeOfferTypeProxyPxe10) || (OfferType == PxeOfferTypeProxyWfm11a)) && 1190 (Private->OfferCount[OfferType] < 1)) 1191 { 1184 1192 // 1185 1193 // Only cache the first PXE10/WFM11a offer, and discard the others. … … 1203 1211 } 1204 1212 1205 1206 1213 /** 1207 1214 Select an DHCPv6 offer, and record SelectIndex and SelectProxyType. … … 1212 1219 VOID 1213 1220 PxeBcSelectDhcp6Offer ( 1214 IN PXEBC_PRIVATE_DATA 1221 IN PXEBC_PRIVATE_DATA *Private 1215 1222 ) 1216 1223 { 1217 UINT32 1218 UINT32 1219 PXEBC_OFFER_TYPE 1224 UINT32 Index; 1225 UINT32 OfferIndex; 1226 PXEBC_OFFER_TYPE OfferType; 1220 1227 1221 1228 Private->SelectIndex = 0; … … 1230 1237 // 1231 1238 Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpPxe10][0] + 1; 1232 1233 1239 } else if (Private->OfferCount[PxeOfferTypeDhcpWfm11a] > 0) { 1234 1240 // … … 1236 1242 // 1237 1243 Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpWfm11a][0] + 1; 1238 1239 } else if (Private->OfferCount[PxeOfferTypeDhcpOnly] > 0 &&1240 Private->OfferCount[PxeOfferTypeProxyPxe10] > 0){1244 } else if ((Private->OfferCount[PxeOfferTypeDhcpOnly] > 0) && 1245 (Private->OfferCount[PxeOfferTypeProxyPxe10] > 0)) 1246 { 1241 1247 // 1242 1248 // 3. DhcpOnly offer and ProxyPxe10 offer. … … 1244 1250 Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpOnly][0] + 1; 1245 1251 Private->SelectProxyType = PxeOfferTypeProxyPxe10; 1246 1247 } else if (Private->OfferCount[PxeOfferTypeDhcpOnly] > 0 &&1248 Private->OfferCount[PxeOfferTypeProxyWfm11a] > 0){1252 } else if ((Private->OfferCount[PxeOfferTypeDhcpOnly] > 0) && 1253 (Private->OfferCount[PxeOfferTypeProxyWfm11a] > 0)) 1254 { 1249 1255 // 1250 1256 // 4. DhcpOnly offer and ProxyWfm11a offer. … … 1252 1258 Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpOnly][0] + 1; 1253 1259 Private->SelectProxyType = PxeOfferTypeProxyWfm11a; 1254 1255 1260 } else if (Private->OfferCount[PxeOfferTypeDhcpBinl] > 0) { 1256 1261 // … … 1258 1263 // 1259 1264 Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpBinl][0] + 1; 1260 1261 } else if (Private->OfferCount[PxeOfferTypeDhcpOnly] > 0 &&1262 Private->OfferCount[PxeOfferTypeProxyBinl] > 0){1265 } else if ((Private->OfferCount[PxeOfferTypeDhcpOnly] > 0) && 1266 (Private->OfferCount[PxeOfferTypeProxyBinl] > 0)) 1267 { 1263 1268 // 1264 1269 // 6. DhcpOnly offer and ProxyBinl offer. … … 1266 1271 Private->SelectIndex = Private->OfferIndex[PxeOfferTypeDhcpOnly][0] + 1; 1267 1272 Private->SelectProxyType = PxeOfferTypeProxyBinl; 1268 1269 1273 } else { 1270 1274 // … … 1284 1288 // 1285 1289 for (Index = 0; Index < Private->OfferNum; Index++) { 1286 1287 1290 OfferType = Private->OfferBuffer[Index].Dhcp6.OfferType; 1288 1291 … … 1295 1298 1296 1299 if (!Private->IsProxyRecved && 1297 OfferType == PxeOfferTypeDhcpOnly && 1298 Private->OfferBuffer[Index].Dhcp6.OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] == NULL) { 1300 (OfferType == PxeOfferTypeDhcpOnly) && 1301 (Private->OfferBuffer[Index].Dhcp6.OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] == NULL)) 1302 { 1299 1303 // 1300 1304 // Skip if DhcpOnly offer without any other proxy offers or bootfilename. … … 1309 1313 } 1310 1314 1311 1312 1315 /** 1313 1316 Handle the DHCPv6 offer packet. … … 1323 1326 EFI_STATUS 1324 1327 PxeBcHandleDhcp6Offer ( 1325 IN PXEBC_PRIVATE_DATA 1328 IN PXEBC_PRIVATE_DATA *Private 1326 1329 ) 1327 1330 { 1328 PXEBC_DHCP6_PACKET_CACHE 1329 EFI_STATUS 1330 PXEBC_OFFER_TYPE 1331 UINT32 1332 UINT32 1333 UINT32 1331 PXEBC_DHCP6_PACKET_CACHE *Cache6; 1332 EFI_STATUS Status; 1333 PXEBC_OFFER_TYPE OfferType; 1334 UINT32 ProxyIndex; 1335 UINT32 SelectIndex; 1336 UINT32 Index; 1334 1337 1335 1338 ASSERT (Private->SelectIndex > 0); 1336 SelectIndex = (UINT32) 1339 SelectIndex = (UINT32)(Private->SelectIndex - 1); 1337 1340 ASSERT (SelectIndex < PXEBC_OFFER_MAX_NUM); 1338 Cache6 1339 Status 1341 Cache6 = &Private->OfferBuffer[SelectIndex].Dhcp6; 1342 Status = EFI_SUCCESS; 1340 1343 1341 1344 // … … 1347 1350 return EFI_OUT_OF_RESOURCES; 1348 1351 } 1352 1349 1353 CopyMem (Private->DnsServer, Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->Data, sizeof (EFI_IPv6_ADDRESS)); 1350 1354 } … … 1358 1362 } 1359 1363 } else if (Cache6->OfferType == PxeOfferTypeDhcpOnly) { 1360 1361 1364 if (Private->IsProxyRecved) { 1362 1365 // … … 1376 1379 // 1377 1380 for (Index = 0; Index < Private->OfferCount[Private->SelectProxyType]; Index++) { 1378 1379 1381 ProxyIndex = Private->OfferIndex[Private->SelectProxyType][Index]; 1380 1382 if (!EFI_ERROR (PxeBcRetryDhcp6Binl (Private, ProxyIndex))) { … … 1382 1384 } 1383 1385 } 1386 1384 1387 if (Index == Private->OfferCount[Private->SelectProxyType]) { 1385 1388 Status = EFI_NO_RESPONSE; … … 1398 1401 1399 1402 for (Index = 0; Index < Private->OfferNum; Index++) { 1400 1401 1403 OfferType = Private->OfferBuffer[Index].Dhcp6.OfferType; 1402 1404 … … 1424 1426 } 1425 1427 1426 if (!EFI_ERROR (Status) && Private->SelectProxyType != PxeOfferTypeProxyBinl) {1428 if (!EFI_ERROR (Status) && (Private->SelectProxyType != PxeOfferTypeProxyBinl)) { 1427 1429 // 1428 1430 // Success to try to request by a ProxyPxe10 or ProxyWfm11a offer, copy and parse it. … … 1442 1444 // All PXE boot information is ready by now. 1443 1445 // 1444 Status = PxeBcCopyDhcp6Ack (Private, &Private->DhcpAck.Dhcp6.Packet.Ack, TRUE);1446 Status = PxeBcCopyDhcp6Ack (Private, &Private->DhcpAck.Dhcp6.Packet.Ack, TRUE); 1445 1447 Private->PxeBc.Mode->DhcpDiscoverValid = TRUE; 1446 1448 } … … 1448 1450 return Status; 1449 1451 } 1450 1451 1452 1452 1453 /** … … 1458 1459 VOID 1459 1460 PxeBcUnregisterIp6Address ( 1460 IN PXEBC_PRIVATE_DATA 1461 IN PXEBC_PRIVATE_DATA *Private 1461 1462 ) 1462 1463 { … … 1486 1487 EFI_STATUS 1487 1488 PxeBcCheckRouteTable ( 1488 IN PXEBC_PRIVATE_DATA 1489 IN UINTN 1490 OUT EFI_IPv6_ADDRESS 1489 IN PXEBC_PRIVATE_DATA *Private, 1490 IN UINTN TimeOutInSecond, 1491 OUT EFI_IPv6_ADDRESS *GatewayAddr 1491 1492 ) 1492 1493 { 1493 EFI_STATUS 1494 EFI_IP6_PROTOCOL 1495 EFI_IP6_MODE_DATA 1496 UINTN 1497 EFI_EVENT 1498 UINTN 1499 BOOLEAN 1494 EFI_STATUS Status; 1495 EFI_IP6_PROTOCOL *Ip6; 1496 EFI_IP6_MODE_DATA Ip6ModeData; 1497 UINTN Index; 1498 EFI_EVENT TimeOutEvt; 1499 UINTN RetryCount; 1500 BOOLEAN GatewayIsFound; 1500 1501 1501 1502 ASSERT (GatewayAddr != NULL); … … 1528 1529 FreePool (Ip6ModeData.AddressList); 1529 1530 } 1531 1530 1532 if (Ip6ModeData.GroupTable != NULL) { 1531 1533 FreePool (Ip6ModeData.GroupTable); 1532 1534 } 1535 1533 1536 if (Ip6ModeData.RouteTable != NULL) { 1534 1537 FreePool (Ip6ModeData.RouteTable); 1535 1538 } 1539 1536 1540 if (Ip6ModeData.NeighborCache != NULL) { 1537 1541 FreePool (Ip6ModeData.NeighborCache); 1538 1542 } 1543 1539 1544 if (Ip6ModeData.PrefixTable != NULL) { 1540 1545 FreePool (Ip6ModeData.PrefixTable); 1541 1546 } 1547 1542 1548 if (Ip6ModeData.IcmpTypeList != NULL) { 1543 1549 FreePool (Ip6ModeData.IcmpTypeList); 1544 1550 } 1545 1551 1546 if (GatewayIsFound || RetryCount == TimeOutInSecond) {1552 if (GatewayIsFound || (RetryCount == TimeOutInSecond)) { 1547 1553 break; 1548 1554 } … … 1570 1576 goto ON_EXIT; 1571 1577 } 1578 1572 1579 while (EFI_ERROR (gBS->CheckEvent (TimeOutEvt))) { 1573 1580 Ip6->Poll (Ip6); … … 1601 1608 EFI_STATUS 1602 1609 PxeBcRegisterIp6Address ( 1603 IN PXEBC_PRIVATE_DATA 1604 IN EFI_IPv6_ADDRESS 1610 IN PXEBC_PRIVATE_DATA *Private, 1611 IN EFI_IPv6_ADDRESS *Address 1605 1612 ) 1606 1613 { 1607 EFI_IP6_PROTOCOL 1608 EFI_IP6_CONFIG_PROTOCOL 1609 EFI_IP6_CONFIG_POLICY 1610 EFI_IP6_CONFIG_MANUAL_ADDRESS 1611 EFI_IPv6_ADDRESS 1612 UINTN 1613 EFI_EVENT 1614 EFI_STATUS 1615 BOOLEAN 1616 EFI_IPv6_ADDRESS 1617 UINTN 1618 1619 Status 1620 MappedEvt 1621 Ip6Addr 1622 DataSize 1623 Ip6Cfg 1624 Ip6 1625 NoGateway 1614 EFI_IP6_PROTOCOL *Ip6; 1615 EFI_IP6_CONFIG_PROTOCOL *Ip6Cfg; 1616 EFI_IP6_CONFIG_POLICY Policy; 1617 EFI_IP6_CONFIG_MANUAL_ADDRESS CfgAddr; 1618 EFI_IPv6_ADDRESS GatewayAddr; 1619 UINTN DataSize; 1620 EFI_EVENT MappedEvt; 1621 EFI_STATUS Status; 1622 BOOLEAN NoGateway; 1623 EFI_IPv6_ADDRESS *Ip6Addr; 1624 UINTN Index; 1625 1626 Status = EFI_SUCCESS; 1627 MappedEvt = NULL; 1628 Ip6Addr = NULL; 1629 DataSize = sizeof (EFI_IP6_CONFIG_POLICY); 1630 Ip6Cfg = Private->Ip6Cfg; 1631 Ip6 = Private->Ip6; 1632 NoGateway = FALSE; 1626 1633 1627 1634 ZeroMem (&CfgAddr, sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS)); … … 1649 1656 Ip6Cfg, 1650 1657 Ip6ConfigDataTypePolicy, 1651 sizeof (EFI_IP6_CONFIG_POLICY),1658 sizeof (EFI_IP6_CONFIG_POLICY), 1652 1659 &Policy 1653 1660 ); … … 1675 1682 1676 1683 Private->IsAddressOk = FALSE; 1677 Status = Ip6Cfg->RegisterDataNotify (1678 Ip6Cfg,1679 Ip6ConfigDataTypeManualAddress,1680 MappedEvt1681 );1682 if (EFI_ERROR (Status)) {1684 Status = Ip6Cfg->RegisterDataNotify ( 1685 Ip6Cfg, 1686 Ip6ConfigDataTypeManualAddress, 1687 MappedEvt 1688 ); 1689 if (EFI_ERROR (Status)) { 1683 1690 goto ON_EXIT; 1684 1691 } … … 1687 1694 Ip6Cfg, 1688 1695 Ip6ConfigDataTypeManualAddress, 1689 sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS),1696 sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS), 1690 1697 &CfgAddr 1691 1698 ); 1692 if (EFI_ERROR (Status) && Status != EFI_NOT_READY) {1699 if (EFI_ERROR (Status) && (Status != EFI_NOT_READY)) { 1693 1700 goto ON_EXIT; 1694 1701 } else if (Status == EFI_NOT_READY) { … … 1699 1706 Ip6->Poll (Ip6); 1700 1707 } 1708 1701 1709 // 1702 1710 // Check whether the IP6 address setting is successed. 1703 1711 // 1704 1712 DataSize = 0; 1713 Status = Ip6Cfg->GetData ( 1714 Ip6Cfg, 1715 Ip6ConfigDataTypeManualAddress, 1716 &DataSize, 1717 NULL 1718 ); 1719 if ((Status != EFI_BUFFER_TOO_SMALL) || (DataSize == 0)) { 1720 Status = EFI_DEVICE_ERROR; 1721 goto ON_EXIT; 1722 } 1723 1724 Ip6Addr = AllocatePool (DataSize); 1725 if (Ip6Addr == NULL) { 1726 return EFI_OUT_OF_RESOURCES; 1727 } 1728 1705 1729 Status = Ip6Cfg->GetData ( 1706 1730 Ip6Cfg, 1707 1731 Ip6ConfigDataTypeManualAddress, 1708 1732 &DataSize, 1709 NULL 1710 ); 1711 if (Status != EFI_BUFFER_TOO_SMALL || DataSize == 0) { 1712 Status = EFI_DEVICE_ERROR; 1713 goto ON_EXIT; 1714 } 1715 1716 Ip6Addr = AllocatePool (DataSize); 1717 if (Ip6Addr == NULL) { 1718 return EFI_OUT_OF_RESOURCES; 1719 } 1720 Status = Ip6Cfg->GetData ( 1721 Ip6Cfg, 1722 Ip6ConfigDataTypeManualAddress, 1723 &DataSize, 1724 (VOID*) Ip6Addr 1733 (VOID *)Ip6Addr 1725 1734 ); 1726 1735 if (EFI_ERROR (Status)) { … … 1734 1743 } 1735 1744 } 1745 1736 1746 if (Index == DataSize / sizeof (EFI_IPv6_ADDRESS)) { 1737 1747 Status = EFI_ABORTED; … … 1764 1774 gBS->CloseEvent (MappedEvt); 1765 1775 } 1776 1766 1777 if (Ip6Addr != NULL) { 1767 1778 FreePool (Ip6Addr); 1768 1779 } 1780 1769 1781 return Status; 1770 1782 } … … 1781 1793 EFI_STATUS 1782 1794 PxeBcSetIp6Policy ( 1783 IN PXEBC_PRIVATE_DATA 1795 IN PXEBC_PRIVATE_DATA *Private 1784 1796 ) 1785 1797 { 1786 EFI_IP6_CONFIG_POLICY 1787 EFI_STATUS 1788 EFI_IP6_CONFIG_PROTOCOL 1789 UINTN 1790 1791 Ip6Cfg 1792 DataSize 1798 EFI_IP6_CONFIG_POLICY Policy; 1799 EFI_STATUS Status; 1800 EFI_IP6_CONFIG_PROTOCOL *Ip6Cfg; 1801 UINTN DataSize; 1802 1803 Ip6Cfg = Private->Ip6Cfg; 1804 DataSize = sizeof (EFI_IP6_CONFIG_POLICY); 1793 1805 1794 1806 // … … 1810 1822 Ip6Cfg, 1811 1823 Ip6ConfigDataTypePolicy, 1812 sizeof (EFI_IP6_CONFIG_POLICY),1824 sizeof (EFI_IP6_CONFIG_POLICY), 1813 1825 &Policy 1814 1826 ); … … 1835 1847 EFI_STATUS 1836 1848 PxeBcSetIp6Address ( 1837 IN PXEBC_PRIVATE_DATA 1849 IN PXEBC_PRIVATE_DATA *Private 1838 1850 ) 1839 1851 { 1840 EFI_STATUS 1841 EFI_DHCP6_PROTOCOL 1852 EFI_STATUS Status; 1853 EFI_DHCP6_PROTOCOL *Dhcp6; 1842 1854 1843 1855 Dhcp6 = Private->Dhcp6; … … 1886 1898 EFIAPI 1887 1899 PxeBcDhcp6CallBack ( 1888 IN EFI_DHCP6_PROTOCOL 1889 IN VOID 1890 IN EFI_DHCP6_STATE 1891 IN EFI_DHCP6_EVENT 1892 IN EFI_DHCP6_PACKET 1893 OUT EFI_DHCP6_PACKET 1900 IN EFI_DHCP6_PROTOCOL *This, 1901 IN VOID *Context, 1902 IN EFI_DHCP6_STATE CurrentState, 1903 IN EFI_DHCP6_EVENT Dhcp6Event, 1904 IN EFI_DHCP6_PACKET *Packet, 1905 OUT EFI_DHCP6_PACKET **NewPacket OPTIONAL 1894 1906 ) 1895 1907 { 1896 PXEBC_PRIVATE_DATA *Private;1897 EFI_PXE_BASE_CODE_MODE *Mode;1898 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *Callback;1899 EFI_DHCP6_PACKET *SelectAd;1900 EFI_STATUS Status;1901 BOOLEAN Received;1908 PXEBC_PRIVATE_DATA *Private; 1909 EFI_PXE_BASE_CODE_MODE *Mode; 1910 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *Callback; 1911 EFI_DHCP6_PACKET *SelectAd; 1912 EFI_STATUS Status; 1913 BOOLEAN Received; 1902 1914 1903 1915 if ((Dhcp6Event != Dhcp6RcvdAdvertise) && … … 1905 1917 (Dhcp6Event != Dhcp6SendSolicit) && 1906 1918 (Dhcp6Event != Dhcp6SendRequest) && 1907 (Dhcp6Event != Dhcp6RcvdReply)) { 1919 (Dhcp6Event != Dhcp6RcvdReply)) 1920 { 1908 1921 return EFI_SUCCESS; 1909 1922 } … … 1911 1924 ASSERT (Packet != NULL); 1912 1925 1913 Private = (PXEBC_PRIVATE_DATA *)Context;1914 Mode 1915 Callback 1926 Private = (PXEBC_PRIVATE_DATA *)Context; 1927 Mode = Private->PxeBc.Mode; 1928 Callback = Private->PxeBcCallback; 1916 1929 1917 1930 // 1918 1931 // Callback to user when any traffic occurred if has. 1919 1932 // 1920 if ( Dhcp6Event != Dhcp6SelectAdvertise && Callback != NULL) {1921 Received = (BOOLEAN) 1922 Status = Callback->Callback (1923 Callback,1924 Private->Function,1925 Received,1926 Packet->Length,1927 (EFI_PXE_BASE_CODE_PACKET *)&Packet->Dhcp61928 );1933 if ((Dhcp6Event != Dhcp6SelectAdvertise) && (Callback != NULL)) { 1934 Received = (BOOLEAN)(Dhcp6Event == Dhcp6RcvdAdvertise || Dhcp6Event == Dhcp6RcvdReply); 1935 Status = Callback->Callback ( 1936 Callback, 1937 Private->Function, 1938 Received, 1939 Packet->Length, 1940 (EFI_PXE_BASE_CODE_PACKET *)&Packet->Dhcp6 1941 ); 1929 1942 if (Status != EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE) { 1930 1943 return EFI_ABORTED; … … 1935 1948 1936 1949 switch (Dhcp6Event) { 1937 1938 case Dhcp6SendSolicit: 1939 if (Packet->Length > PXEBC_DHCP6_PACKET_MAX_SIZE) { 1940 // 1941 // If the to be sent packet exceeds the maximum length, abort the DHCP process. 1942 // 1943 Status = EFI_ABORTED; 1950 case Dhcp6SendSolicit: 1951 if (Packet->Length > PXEBC_DHCP6_PACKET_MAX_SIZE) { 1952 // 1953 // If the to be sent packet exceeds the maximum length, abort the DHCP process. 1954 // 1955 Status = EFI_ABORTED; 1956 break; 1957 } 1958 1959 // 1960 // Record the first Solicate msg time 1961 // 1962 if (Private->SolicitTimes == 0) { 1963 CalcElapsedTime (Private); 1964 Private->SolicitTimes++; 1965 } 1966 1967 // 1968 // Cache the dhcp discover packet to mode data directly. 1969 // 1970 CopyMem (&Mode->DhcpDiscover.Dhcpv4, &Packet->Dhcp6, Packet->Length); 1944 1971 break; 1945 } 1946 1947 // 1948 // Record the first Solicate msg time 1949 // 1950 if (Private->SolicitTimes == 0) { 1951 CalcElapsedTime (Private); 1952 Private->SolicitTimes++; 1953 } 1954 // 1955 // Cache the dhcp discover packet to mode data directly. 1956 // 1957 CopyMem (&Mode->DhcpDiscover.Dhcpv4, &Packet->Dhcp6, Packet->Length); 1958 break; 1959 1960 case Dhcp6RcvdAdvertise: 1961 Status = EFI_NOT_READY; 1962 if (Packet->Length > PXEBC_DHCP6_PACKET_MAX_SIZE) { 1963 // 1964 // Ignore the incoming packets which exceed the maximum length. 1965 // 1972 1973 case Dhcp6RcvdAdvertise: 1974 Status = EFI_NOT_READY; 1975 if (Packet->Length > PXEBC_DHCP6_PACKET_MAX_SIZE) { 1976 // 1977 // Ignore the incoming packets which exceed the maximum length. 1978 // 1979 break; 1980 } 1981 1982 if (Private->OfferNum < PXEBC_OFFER_MAX_NUM) { 1983 // 1984 // Cache the dhcp offers to OfferBuffer[] for select later, and record 1985 // the OfferIndex and OfferCount. 1986 // 1987 PxeBcCacheDhcp6Offer (Private, Packet); 1988 } 1989 1966 1990 break; 1967 } 1968 if (Private->OfferNum < PXEBC_OFFER_MAX_NUM) { 1969 // 1970 // Cache the dhcp offers to OfferBuffer[] for select later, and record 1971 // the OfferIndex and OfferCount. 1972 // 1973 PxeBcCacheDhcp6Offer (Private, Packet); 1974 } 1975 break; 1976 1977 case Dhcp6SendRequest: 1978 if (Packet->Length > PXEBC_DHCP6_PACKET_MAX_SIZE) { 1979 // 1980 // If the to be sent packet exceeds the maximum length, abort the DHCP process. 1981 // 1982 Status = EFI_ABORTED; 1991 1992 case Dhcp6SendRequest: 1993 if (Packet->Length > PXEBC_DHCP6_PACKET_MAX_SIZE) { 1994 // 1995 // If the to be sent packet exceeds the maximum length, abort the DHCP process. 1996 // 1997 Status = EFI_ABORTED; 1998 break; 1999 } 2000 2001 // 2002 // Store the request packet as seed packet for discover. 2003 // 2004 if (Private->Dhcp6Request != NULL) { 2005 FreePool (Private->Dhcp6Request); 2006 } 2007 2008 Private->Dhcp6Request = AllocateZeroPool (Packet->Size); 2009 if (Private->Dhcp6Request != NULL) { 2010 CopyMem (Private->Dhcp6Request, Packet, Packet->Size); 2011 } 2012 1983 2013 break; 1984 } 1985 1986 // 1987 // Store the request packet as seed packet for discover. 1988 // 1989 if (Private->Dhcp6Request != NULL) { 1990 FreePool (Private->Dhcp6Request); 1991 } 1992 Private->Dhcp6Request = AllocateZeroPool (Packet->Size); 1993 if (Private->Dhcp6Request != NULL) { 1994 CopyMem (Private->Dhcp6Request, Packet, Packet->Size); 1995 } 1996 break; 1997 1998 case Dhcp6SelectAdvertise: 1999 // 2000 // Select offer by the default policy or by order, and record the SelectIndex 2001 // and SelectProxyType. 2002 // 2003 PxeBcSelectDhcp6Offer (Private); 2004 2005 if (Private->SelectIndex == 0) { 2006 Status = EFI_ABORTED; 2007 } else { 2008 ASSERT (NewPacket != NULL); 2009 SelectAd = &Private->OfferBuffer[Private->SelectIndex - 1].Dhcp6.Packet.Offer; 2010 *NewPacket = AllocateZeroPool (SelectAd->Size); 2011 ASSERT (*NewPacket != NULL); 2012 if (*NewPacket == NULL) { 2013 return EFI_ABORTED; 2014 2015 case Dhcp6SelectAdvertise: 2016 // 2017 // Select offer by the default policy or by order, and record the SelectIndex 2018 // and SelectProxyType. 2019 // 2020 PxeBcSelectDhcp6Offer (Private); 2021 2022 if (Private->SelectIndex == 0) { 2023 Status = EFI_ABORTED; 2024 } else { 2025 ASSERT (NewPacket != NULL); 2026 SelectAd = &Private->OfferBuffer[Private->SelectIndex - 1].Dhcp6.Packet.Offer; 2027 *NewPacket = AllocateZeroPool (SelectAd->Size); 2028 ASSERT (*NewPacket != NULL); 2029 if (*NewPacket == NULL) { 2030 return EFI_ABORTED; 2031 } 2032 2033 CopyMem (*NewPacket, SelectAd, SelectAd->Size); 2014 2034 } 2015 CopyMem (*NewPacket, SelectAd, SelectAd->Size); 2016 }2017 break; 2018 2019 case Dhcp6RcvdReply:2020 //2021 // Cache the dhcp ack to Private->Dhcp6Ack, but it's not the final ack in mode data2022 // without verification.2023 //2024 ASSERT (Private->SelectIndex != 0);2025 Status = PxeBcCopyDhcp6Ack (Private, Packet, FALSE);2026 if (EFI_ERROR (Status)) {2027 Status = EFI_ABORTED;2028 } 2029 break;2030 2031 default:2032 ASSERT (0);2035 2036 break; 2037 2038 case Dhcp6RcvdReply: 2039 // 2040 // Cache the dhcp ack to Private->Dhcp6Ack, but it's not the final ack in mode data 2041 // without verification. 2042 // 2043 ASSERT (Private->SelectIndex != 0); 2044 Status = PxeBcCopyDhcp6Ack (Private, Packet, FALSE); 2045 if (EFI_ERROR (Status)) { 2046 Status = EFI_ABORTED; 2047 } 2048 2049 break; 2050 2051 default: 2052 ASSERT (0); 2033 2053 } 2034 2054 2035 2055 return Status; 2036 2056 } 2037 2038 2057 2039 2058 /** … … 2054 2073 EFI_STATUS 2055 2074 PxeBcDhcp6Discover ( 2056 IN PXEBC_PRIVATE_DATA 2057 IN UINT16 2058 IN UINT16 2059 IN BOOLEAN 2060 IN EFI_IP_ADDRESS 2075 IN PXEBC_PRIVATE_DATA *Private, 2076 IN UINT16 Type, 2077 IN UINT16 *Layer, 2078 IN BOOLEAN UseBis, 2079 IN EFI_IP_ADDRESS *DestIp 2061 2080 ) 2062 2081 { 2063 EFI_PXE_BASE_CODE_UDP_PORT 2064 EFI_PXE_BASE_CODE_UDP_PORT 2065 EFI_PXE_BASE_CODE_MODE 2066 EFI_PXE_BASE_CODE_PROTOCOL 2067 EFI_PXE_BASE_CODE_DHCPV6_PACKET 2068 UINTN 2069 EFI_DHCP6_PACKET 2070 UINTN 2071 EFI_DHCP6_PACKET 2072 UINT8 2073 UINT8 2074 UINTN 2075 UINT16 2076 UINT16 2077 UINT32 2078 EFI_STATUS 2079 2080 PxeBc 2081 Mode 2082 Request 2083 SrcPort 2084 DestPort 2085 2086 if (!UseBis && Layer != NULL) {2082 EFI_PXE_BASE_CODE_UDP_PORT SrcPort; 2083 EFI_PXE_BASE_CODE_UDP_PORT DestPort; 2084 EFI_PXE_BASE_CODE_MODE *Mode; 2085 EFI_PXE_BASE_CODE_PROTOCOL *PxeBc; 2086 EFI_PXE_BASE_CODE_DHCPV6_PACKET *Discover; 2087 UINTN DiscoverLen; 2088 EFI_DHCP6_PACKET *Request; 2089 UINTN RequestLen; 2090 EFI_DHCP6_PACKET *Reply; 2091 UINT8 *RequestOpt; 2092 UINT8 *DiscoverOpt; 2093 UINTN ReadSize; 2094 UINT16 OpCode; 2095 UINT16 OpLen; 2096 UINT32 Xid; 2097 EFI_STATUS Status; 2098 2099 PxeBc = &Private->PxeBc; 2100 Mode = PxeBc->Mode; 2101 Request = Private->Dhcp6Request; 2102 SrcPort = PXEBC_BS_DISCOVER_PORT; 2103 DestPort = PXEBC_BS_DISCOVER_PORT; 2104 2105 if (!UseBis && (Layer != NULL)) { 2087 2106 *Layer &= EFI_PXE_BASE_CODE_BOOT_LAYER_MASK; 2088 2107 } … … 2109 2128 2110 2129 while (RequestLen < Request->Length) { 2111 OpCode = NTOHS (((EFI_DHCP6_PACKET_OPTION *) RequestOpt)->OpCode); 2112 OpLen = NTOHS (((EFI_DHCP6_PACKET_OPTION *) RequestOpt)->OpLen); 2113 if (OpCode != EFI_DHCP6_IA_TYPE_NA && 2114 OpCode != EFI_DHCP6_IA_TYPE_TA) { 2130 OpCode = NTOHS (((EFI_DHCP6_PACKET_OPTION *)RequestOpt)->OpCode); 2131 OpLen = NTOHS (((EFI_DHCP6_PACKET_OPTION *)RequestOpt)->OpLen); 2132 if ((OpCode != EFI_DHCP6_IA_TYPE_NA) && 2133 (OpCode != EFI_DHCP6_IA_TYPE_TA)) 2134 { 2115 2135 // 2116 2136 // Copy all the options except IA option. … … 2120 2140 DiscoverLen += (OpLen + 4); 2121 2141 } 2142 2122 2143 RequestOpt += (OpLen + 4); 2123 2144 RequestLen += (OpLen + 4); … … 2135 2156 NULL, 2136 2157 &DiscoverLen, 2137 (VOID *) 2158 (VOID *)Discover 2138 2159 ); 2139 2160 if (EFI_ERROR (Status)) { … … 2151 2172 Reply = &Private->ProxyOffer.Dhcp6.Packet.Offer; 2152 2173 } 2153 ReadSize = (UINTN) Reply->Size; 2174 2175 ReadSize = (UINTN)Reply->Size; 2154 2176 2155 2177 // … … 2171 2193 NULL, 2172 2194 &ReadSize, 2173 (VOID *) 2195 (VOID *)&Reply->Dhcp6 2174 2196 ); 2175 2197 // … … 2191 2213 } 2192 2214 2193 2194 2215 /** 2195 2216 Start the DHCPv6 S.A.R.R. process to acquire the IPv6 address and other PXE boot information. … … 2204 2225 EFI_STATUS 2205 2226 PxeBcDhcp6Sarr ( 2206 IN PXEBC_PRIVATE_DATA 2207 IN EFI_DHCP6_PROTOCOL 2227 IN PXEBC_PRIVATE_DATA *Private, 2228 IN EFI_DHCP6_PROTOCOL *Dhcp6 2208 2229 ) 2209 2230 { 2210 EFI_PXE_BASE_CODE_MODE *PxeMode;2211 EFI_DHCP6_CONFIG_DATA Config;2212 EFI_DHCP6_MODE_DATA Mode;2213 EFI_DHCP6_RETRANSMISSION *Retransmit;2214 EFI_DHCP6_PACKET_OPTION *OptList[PXEBC_DHCP6_OPTION_MAX_NUM];2215 UINT8 Buffer[PXEBC_DHCP6_OPTION_MAX_SIZE];2216 UINT32 OptCount;2217 EFI_STATUS Status;2218 EFI_IP6_CONFIG_PROTOCOL *Ip6Cfg;2219 EFI_STATUS TimerStatus;2220 EFI_EVENT Timer;2221 UINT64 GetMappingTimeOut;2222 UINTN DataSize;2223 EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS 2224 2225 Status 2226 PxeMode 2227 Ip6Cfg 2228 Timer 2231 EFI_PXE_BASE_CODE_MODE *PxeMode; 2232 EFI_DHCP6_CONFIG_DATA Config; 2233 EFI_DHCP6_MODE_DATA Mode; 2234 EFI_DHCP6_RETRANSMISSION *Retransmit; 2235 EFI_DHCP6_PACKET_OPTION *OptList[PXEBC_DHCP6_OPTION_MAX_NUM]; 2236 UINT8 Buffer[PXEBC_DHCP6_OPTION_MAX_SIZE]; 2237 UINT32 OptCount; 2238 EFI_STATUS Status; 2239 EFI_IP6_CONFIG_PROTOCOL *Ip6Cfg; 2240 EFI_STATUS TimerStatus; 2241 EFI_EVENT Timer; 2242 UINT64 GetMappingTimeOut; 2243 UINTN DataSize; 2244 EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS DadXmits; 2245 2246 Status = EFI_SUCCESS; 2247 PxeMode = Private->PxeBc.Mode; 2248 Ip6Cfg = Private->Ip6Cfg; 2249 Timer = NULL; 2229 2250 2230 2251 // 2231 2252 // Build option list for the request packet. 2232 2253 // 2233 OptCount 2234 ASSERT (OptCount > 0);2254 OptCount = PxeBcBuildDhcp6Options (Private, OptList, Buffer); 2255 ASSERT (OptCount > 0); 2235 2256 2236 2257 Retransmit = AllocateZeroPool (sizeof (EFI_DHCP6_RETRANSMISSION)); … … 2275 2296 ZeroMem (Private->OfferIndex, sizeof (Private->OfferIndex)); 2276 2297 2277 2278 2298 // 2279 2299 // Start DHCPv6 S.A.R.R. process to acquire IPv6 address. … … 2291 2311 // 2292 2312 DataSize = sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS); 2293 Status = Ip6Cfg->GetData (2294 Ip6Cfg,2295 Ip6ConfigDataTypeDupAddrDetectTransmits,2296 &DataSize,2297 &DadXmits2298 );2313 Status = Ip6Cfg->GetData ( 2314 Ip6Cfg, 2315 Ip6ConfigDataTypeDupAddrDetectTransmits, 2316 &DataSize, 2317 &DadXmits 2318 ); 2299 2319 if (EFI_ERROR (Status)) { 2300 2320 Dhcp6->Configure (Dhcp6, NULL); … … 2309 2329 2310 2330 GetMappingTimeOut = TICKS_PER_SECOND * DadXmits.DupAddrDetectTransmits + PXEBC_DAD_ADDITIONAL_DELAY; 2311 Status = gBS->SetTimer (Timer, TimerRelative, GetMappingTimeOut);2331 Status = gBS->SetTimer (Timer, TimerRelative, GetMappingTimeOut); 2312 2332 if (EFI_ERROR (Status)) { 2313 2333 gBS->CloseEvent (Timer); … … 2317 2337 2318 2338 do { 2319 2320 2339 TimerStatus = gBS->CheckEvent (Timer); 2321 2340 if (!EFI_ERROR (TimerStatus)) { … … 2326 2345 gBS->CloseEvent (Timer); 2327 2346 } 2347 2328 2348 if (EFI_ERROR (Status)) { 2329 2349 if (Status == EFI_ICMP_ERROR) { 2330 2350 PxeMode->IcmpErrorReceived = TRUE; 2331 2351 } 2352 2332 2353 Dhcp6->Configure (Dhcp6, NULL); 2333 2354 return Status; … … 2355 2376 FreePool (Mode.ClientId); 2356 2377 } 2378 2357 2379 if (Mode.Ia != NULL) { 2358 2380 FreePool (Mode.Ia); 2359 2381 } 2382 2360 2383 // 2361 2384 // Check the selected offer whether BINL retry is needed.
Note:
See TracChangeset
for help on using the changeset viewer.