13#define IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH 32
25#define TFTP_PROGRESS_SLIDER_STEPS ((sizeof (mTftpProgressFrame) / sizeof (CHAR16)) - 3)
32#define TFTP_PROGRESS_MESSAGE_SIZE ((sizeof (mTftpProgressFrame) / sizeof (CHAR16)) + 12)
36STATIC CONST CHAR16 mTftpProgressDelete[] = L
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
39SHELL_FILE_HANDLE mFileHandle;
42CONST CHAR16 *mLocalFilePath;
243#define MTFTP_DEFAULT_BLKSIZE 512
247#define MTFTP_MIN_BLKSIZE 8
248#define MTFTP_MAX_BLKSIZE 65464
252#define MTFTP_DEFAULT_WINDOWSIZE 1
258#define MTFTP_MIN_WINDOWSIZE 1
259#define MTFTP_MAX_WINDOWSIZE 64
285 CHAR16 *ProblemParam;
287 CONST CHAR16 *UserNicName;
289 CONST CHAR16 *ValueStr;
290 CONST CHAR16 *RemoteFilePath;
291 CHAR8 *AsciiRemoteFilePath;
293 CONST CHAR16 *Walker;
298 CHAR16 NicName[IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH];
309 AsciiRemoteFilePath =
NULL;
319 if (EFI_ERROR (Status)) {
328 if (EFI_ERROR (Status)) {
329 if ((Status == EFI_VOLUME_CORRUPTED) &&
330 (ProblemParam !=
NULL))
353 if (ParamCount > 4) {
365 if (ParamCount < 3) {
384 if (EFI_ERROR (Status)) {
398 if (RemoteFilePath ==
NULL) {
399 ASSERT (RemoteFilePath !=
NULL);
403 FilePathSize =
StrLen (RemoteFilePath) + 1;
405 if (AsciiRemoteFilePath ==
NULL) {
412 if (ParamCount == 4) {
415 Walker = RemoteFilePath +
StrLen (RemoteFilePath);
416 while ((--Walker) >= RemoteFilePath) {
417 if ((*Walker == L
'\\') ||
424 mLocalFilePath = Walker + 1;
433 if (ValueStr !=
NULL) {
440 if (ValueStr !=
NULL) {
441 if (!
StringToUint16 (ValueStr, &Mtftp4ConfigData.InitialServerPort)) {
447 if (ValueStr !=
NULL) {
452 if (Mtftp4ConfigData.TryCount == 0) {
453 Mtftp4ConfigData.TryCount = 6;
458 if (ValueStr !=
NULL) {
463 if (Mtftp4ConfigData.TimeoutValue == 0) {
478 if (ValueStr !=
NULL) {
498 if (ValueStr !=
NULL) {
521 Status =
gBS->LocateHandleBuffer (
523 &gEfiManagedNetworkServiceBindingProtocolGuid,
528 if (EFI_ERROR (Status) || (HandleCount == 0)) {
543 ControllerHandle = Handles[NicNumber];
545 Status =
GetNicName (ControllerHandle, NicNumber, NicName);
546 if (EFI_ERROR (Status)) {
559 if (UserNicName !=
NULL) {
560 if (
StrCmp (NicName, UserNicName) != 0) {
569 &gEfiMtftp4ServiceBindingProtocolGuid,
570 &gEfiMtftp4ProtocolGuid,
574 if (EFI_ERROR (Status)) {
587 Status = Mtftp4->Configure (Mtftp4, &Mtftp4ConfigData);
588 if (EFI_ERROR (Status)) {
601 Status =
GetFileSize (Mtftp4, AsciiRemoteFilePath, &FileSize);
602 if (EFI_ERROR (Status)) {
616 Status =
DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, BlockSize, WindowSize);
617 if (EFI_ERROR (Status)) {
637 &gEfiMtftp4ServiceBindingProtocolGuid,
638 &gEfiMtftp4ProtocolGuid,
643 if ((UserNicName !=
NULL) && (!NicFound)) {
657 if (AsciiRemoteFilePath !=
NULL) {
661 if (Handles !=
NULL) {
665 if ((ShellStatus !=
SHELL_SUCCESS) && (EFI_ERROR (Status))) {
666 ShellStatus = Status & ~MAX_BIT;
691 if (Val > MAX_UINT16) {
704 *Value = (UINT16)Val;
741 &gEfiManagedNetworkServiceBindingProtocolGuid,
742 &gEfiManagedNetworkProtocolGuid,
746 if (EFI_ERROR (Status)) {
750 Status = Mnp->GetModeData (Mnp,
NULL, &SnpMode);
751 if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {
757 IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH,
758 SnpMode.
IfType == NET_IFTYPE_ETHERNET ?
768 if (MnpHandle !=
NULL) {
771 &gEfiManagedNetworkServiceBindingProtocolGuid,
772 &gEfiManagedNetworkProtocolGuid,
815 ServiceBindingProtocolGuid,
818 if (!EFI_ERROR (Status)) {
819 Status =
gBS->OpenProtocol (
825 EFI_OPEN_PROTOCOL_GET_PROTOCOL
827 if (EFI_ERROR (Status)) {
831 ServiceBindingProtocolGuid,
872 ServiceBindingProtocolGuid,
909 ReqOpt[0].OptionStr = (UINT8 *)
"tsize";
912 ReqOpt[0].ValueStr = OptBuf;
914 Status = Mtftp4->GetInfo (
925 if (EFI_ERROR (Status)) {
929 Status = Mtftp4->ParseOptions (
936 if (EFI_ERROR (Status)) {
940 Option = TableOfOptions;
941 while (OptCnt != 0) {
942 if (
AsciiStrnCmp ((CHAR8 *)Option->OptionStr,
"tsize", 5) == 0) {
954 Status = EFI_UNSUPPORTED;
993 UINT8 BlksizeBuf[10];
994 UINT8 WindowsizeBuf[10];
999 if (TftpContext ==
NULL) {
1000 Status = EFI_OUT_OF_RESOURCES;
1004 TftpContext->FileSize = FileSize;
1005 TftpContext->DownloadedNbOfBytes = 0;
1006 TftpContext->LastReportedNbOfBytes = 0;
1008 Mtftp4Token.
Filename = (UINT8 *)AsciiFilePath;
1010 Mtftp4Token.
Context = (VOID *)TftpContext;
1014 Status = EFI_OUT_OF_RESOURCES;
1020 AsciiSPrint ((CHAR8 *)BlksizeBuf,
sizeof (BlksizeBuf),
"%d", BlockSize);
1027 AsciiSPrint ((CHAR8 *)WindowsizeBuf,
sizeof (WindowsizeBuf),
"%d", WindowSize);
1051 EFI_FILE_MODE_CREATE |
1052 EFI_FILE_MODE_WRITE |
1056 if (EFI_ERROR (Status)) {
1069 Status = Mtftp4->ReadFile (Mtftp4, &Mtftp4Token);
1084 if (TftpContext !=
NULL) {
1113 IN UINT16 PacketLen,
1118 CHAR16 Progress[TFTP_PROGRESS_MESSAGE_SIZE];
1126 if ((NTOHS (Packet->OpCode)) != EFI_MTFTP4_OPCODE_DATA) {
1137 DownloadLen = (
UINTN)PacketLen -
sizeof (Packet->OpCode) -
sizeof (Packet->Data.Block);
1140 Status =
ShellWriteFile (mFileHandle, &DownloadLen, Packet->Data.Data);
1141 if (EFI_ERROR (Status)) {
1142 if (Context->DownloadedNbOfBytes > 0) {
1164 if (Context->DownloadedNbOfBytes == 0) {
1168 Context->DownloadedNbOfBytes += DownloadLen;
1169 NbOfKb = Context->DownloadedNbOfBytes / 1024;
1171 Progress[0] = L
'\0';
1172 LastStep = (Context->LastReportedNbOfBytes * TFTP_PROGRESS_SLIDER_STEPS) / Context->FileSize;
1173 Step = (Context->DownloadedNbOfBytes * TFTP_PROGRESS_SLIDER_STEPS) / Context->FileSize;
1175 if (Step <= LastStep) {
1181 Status =
StrCpyS (Progress, TFTP_PROGRESS_MESSAGE_SIZE, mTftpProgressFrame);
1182 if (EFI_ERROR (Status)) {
1186 for (Index = 1; Index < Step; Index++) {
1187 Progress[Index] = L
'=';
1190 Progress[Step] = L
'>';
1193 Progress + (
sizeof (mTftpProgressFrame) /
sizeof (CHAR16)) - 1,
1194 sizeof (Progress) -
sizeof (mTftpProgressFrame),
1198 Context->LastReportedNbOfBytes = Context->DownloadedNbOfBytes;
1224 Status =
gBS->OpenProtocol (
1226 &gEfiHiiPackageListProtocolGuid,
1227 (VOID **)&PackageList,
1230 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1233 if (EFI_ERROR (Status)) {
1247 if (EFI_ERROR (Status)) {
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
INTN EFIAPI AsciiStrnCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString, IN UINTN Length)
RETURN_STATUS EFIAPI UnicodeStrToAsciiStrS(IN CONST CHAR16 *Source, OUT CHAR8 *Destination, IN UINTN DestMax)
UINTN EFIAPI AsciiStrDecimalToUintn(IN CONST CHAR8 *String)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
#define ASSERT_EFI_ERROR(StatusParameter)
@ SHELL_INVALID_PARAMETER
EFI_STATUS EFIAPI NetLibCreateServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN OUT EFI_HANDLE *ChildHandle)
EFI_STATUS EFIAPI NetLibDestroyServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN EFI_HANDLE ChildHandle)
EFI_STATUS EFIAPI NetLibStrToIp4(IN CONST CHAR16 *String, OUT EFI_IPv4_ADDRESS *Ip4Address)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
CONST CHAR16 *EFIAPI ShellCommandLineGetValue(IN CONST LIST_ENTRY *CheckPackage, IN CHAR16 *KeyString)
UINTN EFIAPI ShellStrToUintn(IN CONST CHAR16 *String)
EFI_STATUS EFIAPI ShellDeleteFileByName(IN CONST CHAR16 *FileName)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
@ TypeValue
A flag that has some data following it with a space (IE "-a 1").
EFI_STATUS EFIAPI ShellOpenFileByName(IN CONST CHAR16 *FileName, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes)
EFI_STATUS EFIAPI ShellFileExists(IN CONST CHAR16 *Name)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
EFI_STATUS EFIAPI ShellSetFilePosition(IN SHELL_FILE_HANDLE FileHandle, IN UINT64 Position)
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellWriteFile(IN SHELL_FILE_HANDLE FileHandle, IN OUT UINTN *BufferSize, IN VOID *Buffer)
EFI_STATUS EFIAPI ShellCloseFile(IN SHELL_FILE_HANDLE *FileHandle)
STATIC VOID CloseProtocolAndDestroyServiceChild(IN EFI_HANDLE ControllerHandle, IN EFI_GUID *ServiceBindingProtocolGuid, IN EFI_GUID *ProtocolGuid, IN EFI_HANDLE ChildHandle)
STATIC BOOLEAN StringToUint16(IN CONST CHAR16 *ValueStr, OUT UINT16 *Value)
#define MTFTP_DEFAULT_BLKSIZE
EFI_HII_HANDLE InitializeHiiPackage(EFI_HANDLE ImageHandle)
STATIC EFI_STATUS DownloadFile(IN EFI_MTFTP4_PROTOCOL *Mtftp4, IN CONST CHAR16 *FilePath, IN CONST CHAR8 *AsciiFilePath, IN UINTN FileSize, IN UINT16 BlockSize, IN UINT16 WindowSize)
STATIC EFI_STATUS CreateServiceChildAndOpenProtocol(IN EFI_HANDLE ControllerHandle, IN EFI_GUID *ServiceBindingProtocolGuid, IN EFI_GUID *ProtocolGuid, OUT EFI_HANDLE *ChildHandle, OUT VOID **Interface)
#define MTFTP_MIN_BLKSIZE
STATIC EFI_STATUS GetNicName(IN EFI_HANDLE ControllerHandle, IN UINTN NicNumber, OUT CHAR16 *NicName)
#define MTFTP_DEFAULT_WINDOWSIZE
STATIC EFI_STATUS GetFileSize(IN EFI_MTFTP4_PROTOCOL *Mtftp4, IN CONST CHAR8 *FilePath, OUT UINTN *FileSize)
STATIC EFI_STATUS EFIAPI CheckPacket(IN EFI_MTFTP4_PROTOCOL *This, IN EFI_MTFTP4_TOKEN *Token, IN UINT16 PacketLen, IN EFI_MTFTP4_PACKET *Packet)
SHELL_STATUS RunTftp(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
#define MTFTP_MIN_WINDOWSIZE
EFI_HII_DATABASE_PROTOCOL * gHiiDatabase
EFI_MTFTP4_CHECK_PACKET CheckPacket
EFI_MTFTP4_OPTION * OptionList