TianoCore EDK2 master
Loading...
Searching...
No Matches
Tftp.c File Reference
#include "Tftp.h"

Go to the source code of this file.

Macros

#define IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH   32
 
#define TFTP_PROGRESS_SLIDER_STEPS   ((sizeof (mTftpProgressFrame) / sizeof (CHAR16)) - 3)
 
#define TFTP_PROGRESS_MESSAGE_SIZE   ((sizeof (mTftpProgressFrame) / sizeof (CHAR16)) + 12)
 
#define MTFTP_DEFAULT_BLKSIZE   512
 
#define MTFTP_MIN_BLKSIZE   8
 
#define MTFTP_MAX_BLKSIZE   65464
 
#define MTFTP_DEFAULT_WINDOWSIZE   1
 
#define MTFTP_MIN_WINDOWSIZE   1
 
#define MTFTP_MAX_WINDOWSIZE   64
 

Functions

STATIC BOOLEAN StringToUint16 (IN CONST CHAR16 *ValueStr, OUT UINT16 *Value)
 
STATIC EFI_STATUS GetNicName (IN EFI_HANDLE ControllerHandle, IN UINTN NicNumber, OUT CHAR16 *NicName)
 
STATIC EFI_STATUS CreateServiceChildAndOpenProtocol (IN EFI_HANDLE ControllerHandle, IN EFI_GUID *ServiceBindingProtocolGuid, IN EFI_GUID *ProtocolGuid, OUT EFI_HANDLE *ChildHandle, OUT VOID **Interface)
 
STATIC VOID CloseProtocolAndDestroyServiceChild (IN EFI_HANDLE ControllerHandle, IN EFI_GUID *ServiceBindingProtocolGuid, IN EFI_GUID *ProtocolGuid, IN EFI_HANDLE ChildHandle)
 
STATIC EFI_STATUS GetFileSize (IN EFI_MTFTP4_PROTOCOL *Mtftp4, IN CONST CHAR8 *FilePath, OUT UINTN *FileSize)
 
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 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)
 
EFI_HII_HANDLE InitializeHiiPackage (EFI_HANDLE ImageHandle)
 

Variables

EFI_HII_HANDLE mTftpHiiHandle
 
STATIC CONST CHAR16 mTftpProgressFrame [] = L"[ ]"
 
STATIC 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"
 
SHELL_FILE_HANDLE mFileHandle
 
CONST CHAR16 * mLocalFilePath
 
EFI_MTFTP4_CONFIG_DATA DefaultMtftp4ConfigData
 
STATIC CONST SHELL_PARAM_ITEM ParamList []
 

Detailed Description

The implementation for the 'tftp' Shell command.

Copyright (c) 2015, ARM Ltd. All rights reserved.
Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Tftp.c.

Macro Definition Documentation

◆ IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH

#define IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH   32

Definition at line 13 of file Tftp.c.

◆ MTFTP_DEFAULT_BLKSIZE

#define MTFTP_DEFAULT_BLKSIZE   512

The default block size (512) of tftp is defined in the RFC1350.

Definition at line 243 of file Tftp.c.

◆ MTFTP_DEFAULT_WINDOWSIZE

#define MTFTP_DEFAULT_WINDOWSIZE   1

The default windowsize (1) of tftp.

Definition at line 252 of file Tftp.c.

◆ MTFTP_MAX_BLKSIZE

#define MTFTP_MAX_BLKSIZE   65464

Definition at line 248 of file Tftp.c.

◆ MTFTP_MAX_WINDOWSIZE

#define MTFTP_MAX_WINDOWSIZE   64

Definition at line 259 of file Tftp.c.

◆ MTFTP_MIN_BLKSIZE

#define MTFTP_MIN_BLKSIZE   8

The valid range of block size option is defined in the RFC2348.

Definition at line 247 of file Tftp.c.

◆ MTFTP_MIN_WINDOWSIZE

#define MTFTP_MIN_WINDOWSIZE   1

The valid range of window size option. Note that: RFC 7440 does not mention max window size value, but for the stability reason, the value is limited to 64.

Definition at line 258 of file Tftp.c.

◆ TFTP_PROGRESS_MESSAGE_SIZE

#define TFTP_PROGRESS_MESSAGE_SIZE   ((sizeof (mTftpProgressFrame) / sizeof (CHAR16)) + 12)

Definition at line 32 of file Tftp.c.

◆ TFTP_PROGRESS_SLIDER_STEPS

#define TFTP_PROGRESS_SLIDER_STEPS   ((sizeof (mTftpProgressFrame) / sizeof (CHAR16)) - 3)

Definition at line 25 of file Tftp.c.

Function Documentation

◆ CheckPacket()

STATIC EFI_STATUS EFIAPI CheckPacket ( IN EFI_MTFTP4_PROTOCOL This,
IN EFI_MTFTP4_TOKEN Token,
IN UINT16  PacketLen,
IN EFI_MTFTP4_PACKET Packet 
)

Update the progress of a file download This procedure is called each time a new TFTP packet is received.

Parameters
[in]ThisMTFTP4 protocol interface
[in]TokenParameters for the download of the file
[in]PacketLenLength of the packet
[in]PacketAddress of the packet
Return values
EFI_SUCCESSAll packets are accepted.

Definition at line 1110 of file Tftp.c.

◆ CloseProtocolAndDestroyServiceChild()

STATIC VOID CloseProtocolAndDestroyServiceChild ( IN EFI_HANDLE  ControllerHandle,
IN EFI_GUID ServiceBindingProtocolGuid,
IN EFI_GUID ProtocolGuid,
IN EFI_HANDLE  ChildHandle 
)

Close the protocol identified by its GUID on the child handle of the service identified by its service binding protocol GUID, then destroy the child handle.

Parameters
[in]ControllerHandleController handle.
[in]ServiceBindingProtocolGuidService binding protocol GUID of the service to be destroyed.
[in]ProtocolGuidGUID of the protocol to be closed.
[in]ChildHandleHandle of the child to be destroyed.

Definition at line 855 of file Tftp.c.

◆ CreateServiceChildAndOpenProtocol()

STATIC EFI_STATUS CreateServiceChildAndOpenProtocol ( IN EFI_HANDLE  ControllerHandle,
IN EFI_GUID ServiceBindingProtocolGuid,
IN EFI_GUID ProtocolGuid,
OUT EFI_HANDLE ChildHandle,
OUT VOID **  Interface 
)

Create a child for the service identified by its service binding protocol GUID and get from the child the interface of the protocol identified by its GUID.

Parameters
[in]ControllerHandleController handle.
[in]ServiceBindingProtocolGuidService binding protocol GUID of the service to be created.
[in]ProtocolGuidGUID of the protocol to be open.
[out]ChildHandleAddress where the handler of the created child is returned. NULL is returned in case of error.
[out]InterfaceAddress where a pointer to the protocol interface is returned in case of success.
Returns
EFI_SUCCESS The child was created and the protocol opened.
Others Either the creation of the child or the opening of the protocol failed.

Definition at line 801 of file Tftp.c.

◆ DownloadFile()

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 
)

Worker function that download the data of a file from a TFTP server given the path of the file and its size.

Parameters
[in]Mtftp4MTFTP4 protocol interface
[in]FilePathPath of the file, Unicode encoded
[in]AsciiFilePathPath of the file, ASCII encoded
[in]FileSizeSize of the file in number of bytes
[in]BlockSizeValue of the TFTP blksize option
[in]WindowSizeValue of the TFTP window size option
Return values
EFI_SUCCESSThe file was downloaded.
EFI_OUT_OF_RESOURCESA memory allocation failed.
OthersThe downloading of the file from the server failed (see EFI_MTFTP4_PROTOCOL.ReadFile() status codes).

Definition at line 981 of file Tftp.c.

◆ GetFileSize()

STATIC EFI_STATUS GetFileSize ( IN EFI_MTFTP4_PROTOCOL Mtftp4,
IN CONST CHAR8 *  FilePath,
OUT UINTN FileSize 
)

Worker function that gets the size in numbers of bytes of a file from a TFTP server before to download the file.

Parameters
[in]Mtftp4MTFTP4 protocol interface
[in]FilePathPath of the file, ASCII encoded
[out]FileSizeAddress where to store the file size in number of bytes.
Return values
EFI_SUCCESSThe size of the file was returned.
EFI_UNSUPPORTEDThe server does not support the "tsize" option.
OthersError when retrieving the information from the server (see EFI_MTFTP4_PROTOCOL.GetInfo() status codes) or error when parsing the response of the server.

Definition at line 894 of file Tftp.c.

◆ GetNicName()

STATIC EFI_STATUS GetNicName ( IN EFI_HANDLE  ControllerHandle,
IN UINTN  NicNumber,
OUT CHAR16 *  NicName 
)

Get the name of the NIC.

Parameters
[in]ControllerHandleThe network physical device handle.
[in]NicNumberThe network physical device number.
[out]NicNameAddress where to store the NIC name. The memory area has to be at least IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH double byte wide.
Returns
EFI_SUCCESS The name of the NIC was returned.
Others The creation of the child for the Managed Network Service failed or the opening of the Managed Network Protocol failed or the operational parameters for the Managed Network Protocol could not be read.

Definition at line 728 of file Tftp.c.

◆ InitializeHiiPackage()

EFI_HII_HANDLE InitializeHiiPackage ( EFI_HANDLE  ImageHandle)

Retrieve HII package list from ImageHandle and publish to HII database.

Parameters
ImageHandleThe image handle of the process.
Returns
HII handle.

Definition at line 1213 of file Tftp.c.

◆ RunTftp()

SHELL_STATUS RunTftp ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

Function for 'tftp' command.

Parameters
[in]ImageHandleHandle to the Image (NULL if Internal).
[in]SystemTablePointer to the System Table (NULL if Internal).
Returns
SHELL_SUCCESS The 'tftp' command completed successfully.
SHELL_ABORTED The Shell Library initialization failed.
SHELL_INVALID_PARAMETER At least one of the command's arguments is not valid.
SHELL_OUT_OF_RESOURCES A memory allocation failed.
SHELL_NOT_FOUND Network Interface Card not found or server error or file error.

Definition at line 277 of file Tftp.c.

◆ StringToUint16()

STATIC BOOLEAN StringToUint16 ( IN CONST CHAR16 *  ValueStr,
OUT UINT16 *  Value 
)

Check and convert the UINT16 option values of the 'tftp' command

Parameters
[in]ValueStrValue as an Unicode encoded string
[out]ValueUINT16 value
Returns
TRUE The value was returned.
FALSE A parsing error occurred.

Definition at line 683 of file Tftp.c.

Variable Documentation

◆ DefaultMtftp4ConfigData

EFI_MTFTP4_CONFIG_DATA DefaultMtftp4ConfigData
Initial value:
= {
TRUE,
{
{ 0, 0, 0, 0 }
},
{
{ 0, 0, 0, 0 }
},
0,
{
{ 0, 0, 0, 0 }
},
{
{ 0, 0, 0, 0 }
},
69,
6,
4
}
#define TRUE
Definition: Base.h:301

Definition at line 209 of file Tftp.c.

◆ mFileHandle

SHELL_FILE_HANDLE mFileHandle

Definition at line 39 of file Tftp.c.

◆ mLocalFilePath

CONST CHAR16* mLocalFilePath

Definition at line 42 of file Tftp.c.

◆ mTftpHiiHandle

EFI_HII_HANDLE mTftpHiiHandle

Definition at line 14 of file Tftp.c.

◆ mTftpProgressDelete

STATIC 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"

Definition at line 36 of file Tftp.c.

◆ mTftpProgressFrame

STATIC CONST CHAR16 mTftpProgressFrame[] = L"[ ]"

Definition at line 22 of file Tftp.c.

◆ ParamList

Initial value:
= {
{ L"-i", TypeValue },
{ L"-l", TypeValue },
{ L"-r", TypeValue },
{ L"-c", TypeValue },
{ L"-t", TypeValue },
{ L"-s", TypeValue },
{ L"-w", TypeValue },
{ NULL, TypeMax }
}
#define NULL
Definition: Base.h:319
@ TypeValue
A flag that has some data following it with a space (IE "-a 1").
Definition: ShellLib.h:700

Definition at line 229 of file Tftp.c.