EFI_STATUS EFIAPI EblPerformDHCP ( IN BOOLEAN SortOffers ) { EFI_STATUS Status; EFI_PXE_BASE_CODE_PROTOCOL *Pxe; Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe); if (EFI_ERROR(Status)) { return Status; } Status = Pxe->Start (Pxe, gUseIpv6); if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) { return Status; } Status = Pxe->Dhcp(Pxe, TRUE); return Status; }
EFI_STATUS EFIAPI EblGetCurrentIpAddress ( IN OUT EFI_IP_ADDRESS *Ip ) { EFI_STATUS Status; EFI_PXE_BASE_CODE_PROTOCOL *Pxe; Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe); if (EFI_ERROR(Status)) { return Status; } Status = Pxe->Start (Pxe, gUseIpv6); if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) { return Status; } CopyMem (Ip, &Pxe->Mode->StationIp, sizeof (EFI_IP_ADDRESS)); return EFI_SUCCESS; }
EFI_STATUS BdsTftpLoadImage ( IN EFI_DEVICE_PATH* DevicePath, IN EFI_HANDLE Handle, IN EFI_DEVICE_PATH* RemainingDevicePath, IN EFI_ALLOCATE_TYPE Type, IN OUT EFI_PHYSICAL_ADDRESS *Image, OUT UINTN *ImageSize ) { EFI_STATUS Status; EFI_PXE_BASE_CODE_PROTOCOL *Pxe; UINT64 TftpBufferSize; VOID* TftpBuffer; EFI_IP_ADDRESS ServerIp; IPv4_DEVICE_PATH* IPv4DevicePathNode; FILEPATH_DEVICE_PATH* FilePathDevicePath; EFI_IP_ADDRESS LocalIp; ASSERT(IS_DEVICE_PATH_NODE(RemainingDevicePath,MESSAGING_DEVICE_PATH,MSG_IPv4_DP)); IPv4DevicePathNode = (IPv4_DEVICE_PATH*)RemainingDevicePath; FilePathDevicePath = (FILEPATH_DEVICE_PATH*)(IPv4DevicePathNode + 1); Status = gBS->LocateProtocol (&gEfiPxeBaseCodeProtocolGuid, NULL, (VOID **)&Pxe); if (EFI_ERROR(Status)) { return Status; } Status = Pxe->Start (Pxe, FALSE); if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) { return Status; } if (!IPv4DevicePathNode->StaticIpAddress) { Status = Pxe->Dhcp(Pxe, TRUE); } else { CopyMem (&LocalIp.v4, &IPv4DevicePathNode->LocalIpAddress, sizeof (EFI_IPv4_ADDRESS)); Status = Pxe->SetStationIp (Pxe, &LocalIp, NULL); } if (EFI_ERROR(Status)) { return Status; } CopyMem (&ServerIp.v4, &IPv4DevicePathNode->RemoteIpAddress, sizeof (EFI_IPv4_ADDRESS)); Status = Pxe->Mtftp ( Pxe, EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE, NULL, FALSE, &TftpBufferSize, NULL, &ServerIp, (UINT8 *)FilePathDevicePath->PathName, NULL, TRUE ); if (EFI_ERROR(Status)) { return Status; } // Allocate a buffer to hold the whole file. TftpBuffer = AllocatePool(TftpBufferSize); if (TftpBuffer == NULL) { return EFI_OUT_OF_RESOURCES; } Status = Pxe->Mtftp ( Pxe, EFI_PXE_BASE_CODE_TFTP_READ_FILE, TftpBuffer, FALSE, &TftpBufferSize, NULL, &ServerIp, (UINT8 *)FilePathDevicePath->PathName, NULL, FALSE ); if (EFI_ERROR(Status)) { FreePool(TftpBuffer); } else if (ImageSize != NULL) { *ImageSize = (UINTN)TftpBufferSize; } return Status; }