/** @file\r
Interface routine for Mtftp4.\r
\r
-Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
-All rights reserved. This program and the accompanying materials\r
+(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
http://opensource.org/licenses/bsd-license.php<BR>\r
}\r
\r
ASSERT (Instance->UnicastPort != NULL);\r
- UdpIoCleanPort (Instance->UnicastPort);\r
+ UdpIoCleanIo (Instance->UnicastPort);\r
\r
if (Instance->LastPacket != NULL) {\r
NetbufFree (Instance->LastPacket);\r
}\r
\r
if (Instance->McastUdpPort != NULL) {\r
- UdpIoFreePort (Instance->McastUdpPort);\r
+ gBS->CloseProtocol (\r
+ Instance->McastUdpPort->UdpHandle,\r
+ &gEfiUdp4ProtocolGuid,\r
+ gMtftp4DriverBinding.DriverBindingHandle,\r
+ Instance->Handle\r
+ );\r
+ UdpIoFreeIo (Instance->McastUdpPort);\r
Instance->McastUdpPort = NULL;\r
}\r
\r
NET_LIST_FOR_EACH_SAFE (Entry, Next, &Instance->Blocks) {\r
Block = NET_LIST_USER_STRUCT (Entry, MTFTP4_BLOCK_RANGE, Link);\r
RemoveEntryList (Entry);\r
- gBS->FreePool (Block);\r
+ FreePool (Block);\r
}\r
\r
ZeroMem (&Instance->RequestOption, sizeof (MTFTP4_OPTION));\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
Mtftp4GetInfoCheckPacket (\r
IN EFI_MTFTP4_PROTOCOL *This,\r
IN EFI_MTFTP4_TOKEN *Token,\r
IN EFI_MTFTP4_PACKET *Packet\r
)\r
{\r
- MTFTP4_PROTOCOL *Instance;\r
MTFTP4_GETINFO_STATE *State;\r
EFI_STATUS Status;\r
UINT16 OpCode;\r
+ EFI_MTFTP4_ERROR_HEADER *ErrorHeader;\r
\r
- Instance = MTFTP4_PROTOCOL_FROM_THIS (This);\r
- State = &Instance->GetInfoState;\r
+ State = (MTFTP4_GETINFO_STATE *) Token->Context;\r
OpCode = NTOHS (Packet->OpCode);\r
\r
//\r
//\r
switch (OpCode) {\r
case EFI_MTFTP4_OPCODE_ERROR:\r
+ ErrorHeader = (EFI_MTFTP4_ERROR_HEADER *) Packet;\r
+ if (ErrorHeader->ErrorCode == EFI_MTFTP4_ERRORCODE_FILE_NOT_FOUND) {\r
+ DEBUG ((EFI_D_ERROR, "TFTP error code 1 (File Not Found)\n"));\r
+ } else {\r
+ DEBUG ((EFI_D_ERROR, "TFTP error code %d\n", ErrorHeader->ErrorCode));\r
+ }\r
State->Status = EFI_TFTP_ERROR;\r
break;\r
\r
IP4_ADDR Gateway;\r
\r
CopyMem (&Ip, &Override->ServerIp, sizeof (IP4_ADDR));\r
- if (!Ip4IsUnicast (NTOHL (Ip), 0)) {\r
+ if (IP4_IS_UNSPECIFIED (NTOHL (Ip)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip))) {\r
return FALSE;\r
}\r
\r
Netmask = NTOHL (Netmask);\r
Ip = NTOHL (Ip);\r
\r
- if (!Ip4IsUnicast (Gateway, Netmask) || !IP4_NET_EQUAL (Gateway, Ip, Netmask)) {\r
+ if ((Netmask != 0 && !NetIp4IsUnicast (Gateway, Netmask)) || !IP4_NET_EQUAL (Gateway, Ip, Netmask)) {\r
return FALSE;\r
}\r
}\r
the UDP is reconfigured.\r
\r
@param Instance The Mtftp instance\r
- @param UdpPort The UDP port to poll\r
- @param UdpCfgData The UDP configure data to reconfigure the UDP\r
- port.\r
+ @param UdpIo The UDP_IO to poll\r
+ @param UdpCfgData The UDP configure data to reconfigure the UDP_IO\r
\r
@retval TRUE The default address is retrieved and UDP is reconfigured.\r
@retval FALSE Some error occured.\r
BOOLEAN\r
Mtftp4GetMapping (\r
IN MTFTP4_PROTOCOL *Instance,\r
- IN UDP_IO_PORT *UdpPort,\r
+ IN UDP_IO *UdpIo,\r
IN EFI_UDP4_CONFIG_DATA *UdpCfgData\r
)\r
{\r
ASSERT (Instance->Config.UseDefaultSetting);\r
\r
Service = Instance->Service;\r
- Udp = UdpPort->Udp;\r
+ Udp = UdpIo->Protocol.Udp4;\r
\r
Status = gBS->SetTimer (\r
Service->TimerToGetMap,\r
return FALSE;\r
}\r
\r
- while (!EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) {\r
+ while (EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) {\r
Udp->Poll (Udp);\r
\r
if (!EFI_ERROR (Udp->GetModeData (Udp, NULL, &Ip4Mode, NULL, NULL)) &&\r
/**\r
Configure the UDP port for unicast receiving.\r
\r
- @param UdpIo The UDP port\r
+ @param UdpIo The UDP_IO instance\r
@param Instance The MTFTP session\r
\r
@retval EFI_SUCCESS The UDP port is successfully configured for the\r
**/\r
EFI_STATUS\r
Mtftp4ConfigUnicastPort (\r
- IN UDP_IO_PORT *UdpIo,\r
+ IN UDP_IO *UdpIo,\r
IN MTFTP4_PROTOCOL *Instance\r
)\r
{\r
UdpConfig.ReceiveTimeout = 0;\r
UdpConfig.TransmitTimeout = 0;\r
UdpConfig.UseDefaultAddress = Config->UseDefaultSetting;\r
- UdpConfig.StationAddress = Config->StationIp;\r
- UdpConfig.SubnetMask = Config->SubnetMask;\r
+ IP4_COPY_ADDRESS (&UdpConfig.StationAddress, &Config->StationIp);\r
+ IP4_COPY_ADDRESS (&UdpConfig.SubnetMask, &Config->SubnetMask);\r
UdpConfig.StationPort = 0;\r
UdpConfig.RemotePort = 0;\r
\r
Ip = HTONL (Instance->ServerIp);\r
- CopyMem (&UdpConfig.RemoteAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
+ IP4_COPY_ADDRESS (&UdpConfig.RemoteAddress, &Ip);\r
\r
- Status = UdpIo->Udp->Configure (UdpIo->Udp, &UdpConfig);\r
+ Status = UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfig);\r
\r
if ((Status == EFI_NO_MAPPING) && Mtftp4GetMapping (Instance, UdpIo, &UdpConfig)) {\r
return EFI_SUCCESS;\r
// The station IP address is manually configured and the Gateway IP is not 0.\r
// Add the default route for this UDP instance.\r
//\r
- Status = UdpIo->Udp->Routes (UdpIo->Udp, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, &Config->GatewayIp);\r
+ Status = UdpIo->Protocol.Udp4->Routes (\r
+ UdpIo->Protocol.Udp4,\r
+ FALSE,\r
+ &mZeroIp4Addr,\r
+ &mZeroIp4Addr,\r
+ &Config->GatewayIp\r
+ );\r
if (EFI_ERROR (Status)) {\r
- UdpIo->Udp->Configure (UdpIo->Udp, NULL);\r
+ UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, NULL);\r
}\r
}\r
return Status;\r
return Status;\r
}\r
\r
+ if ((Token->OverrideData != NULL) && !Mtftp4OverrideValid (Instance, Token->OverrideData)) {\r
+ Status = EFI_INVALID_PARAMETER;\r
+ gBS->RestoreTPL (OldTpl);\r
+ return Status;\r
+ }\r
+\r
//\r
// Set the Operation now to prevent the application start other\r
// operations.\r
Instance->Operation = Operation;\r
Override = Token->OverrideData;\r
\r
- if ((Override != NULL) && !Mtftp4OverrideValid (Instance, Override)) {\r
- Status = EFI_INVALID_PARAMETER;\r
- goto ON_ERROR;\r
- }\r
-\r
if (Token->OptionCount != 0) {\r
Status = Mtftp4ParseOption (\r
Token->OptionList,\r
);\r
\r
if (EFI_ERROR (Status)) {\r
+ Status = EFI_DEVICE_ERROR;\r
goto ON_ERROR;\r
}\r
}\r
Status = Mtftp4ConfigUnicastPort (Instance->UnicastPort, Instance);\r
\r
if (EFI_ERROR (Status)) {\r
+ Status = EFI_DEVICE_ERROR;\r
goto ON_ERROR;\r
}\r
\r
Status = Mtftp4RrqStart (Instance, Operation);\r
}\r
\r
- gBS->RestoreTPL (OldTpl);\r
-\r
if (EFI_ERROR (Status)) {\r
+ Status = EFI_DEVICE_ERROR;\r
goto ON_ERROR;\r
}\r
\r
if (Token->Event != NULL) {\r
+ gBS->RestoreTPL (OldTpl);\r
return EFI_SUCCESS;\r
}\r
\r
This->Poll (This);\r
}\r
\r
+ gBS->RestoreTPL (OldTpl);\r
return Token->Status;\r
\r
ON_ERROR:\r
Gateway = NTOHL (Gateway);\r
ServerIp = NTOHL (ServerIp);\r
\r
- if (!Ip4IsUnicast (ServerIp, 0)) {\r
+ if (ServerIp == 0 || IP4_IS_LOCAL_BROADCAST (ServerIp)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
if (!ConfigData->UseDefaultSetting &&\r
- ((!IP4_IS_VALID_NETMASK (Netmask) || !Ip4IsUnicast (Ip, Netmask)))) {\r
+ ((!IP4_IS_VALID_NETMASK (Netmask) || (Netmask != 0 && !NetIp4IsUnicast (Ip, Netmask))))) {\r
\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- if ((Gateway != 0) &&\r
- (!IP4_NET_EQUAL (Gateway, Ip, Netmask) || !Ip4IsUnicast (Gateway, Netmask))) {\r
+ if ((Gateway != 0) && \r
+ (!IP4_NET_EQUAL (Gateway, Ip, Netmask) || (Netmask != 0 && !NetIp4IsUnicast (Gateway, Netmask)))) {\r
\r
return EFI_INVALID_PARAMETER;\r
}\r
@retval EFI_TIMEOUT No responses were received from the MTFTPv4 server.\r
@retval EFI_TFTP_ERROR An MTFTPv4 ERROR packet was received.\r
@retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.\r
+ @retval EFI_NO_MEDIA There was a media error.\r
\r
**/\r
EFI_STATUS\r
parameters. If NULL, the default parameters that \r
were set in the EFI_MTFTP4_PROTOCOL.Configure() \r
function are used\r
- @param Filename Pointer to ASCIIZ file name string\r
- @param ModeStr Pointer to ASCIIZ mode string. If NULL, "octet" \r
+ @param Filename Pointer to null-terminated ASCII file name string\r
+ @param ModeStr Pointer to null-terminated ASCII mode string. If NULL, "octet" \r
will be used\r
@param OptionCount Number of option/value string pairs in OptionList\r
@param OptionList Pointer to array of option/value string pairs. \r
in the Buffer.\r
@retval EFI_TIMEOUT No responses were received from the MTFTPv4 server.\r
@retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.\r
- \r
+ @retval EFI_NO_MEDIA There was a media error.\r
+\r
**/\r
EFI_STATUS\r
EFIAPI\r
)\r
{\r
EFI_MTFTP4_TOKEN Token;\r
- MTFTP4_PROTOCOL *Instance;\r
- MTFTP4_GETINFO_STATE *State;\r
+ MTFTP4_GETINFO_STATE State;\r
EFI_STATUS Status;\r
\r
if ((This == NULL) || (Filename == NULL) || (PacketLength == NULL) ||\r
}\r
\r
*PacketLength = 0;\r
- Instance = MTFTP4_PROTOCOL_FROM_THIS (This);\r
- State = &Instance->GetInfoState;\r
- State->Packet = Packet;\r
- State->PacketLen = PacketLength;\r
- State->Status = EFI_SUCCESS;\r
+ State.Packet = Packet;\r
+ State.PacketLen = PacketLength;\r
+ State.Status = EFI_SUCCESS;\r
\r
//\r
// Fill in the Token to issue an synchronous ReadFile operation\r
Token.OptionList = OptionList;\r
Token.BufferSize = 0;\r
Token.Buffer = NULL;\r
+ Token.Context = &State;\r
Token.CheckPacket = Mtftp4GetInfoCheckPacket;\r
Token.TimeoutCallback = NULL;\r
Token.PacketNeeded = NULL;\r
Status = EfiMtftp4ReadFile (This, &Token);\r
\r
if (EFI_ABORTED == Status) {\r
- return State->Status;\r
+ return State.Status;\r
}\r
\r
return Status;\r
\r
if (Instance->State == MTFTP4_STATE_UNCONFIGED) {\r
return EFI_NOT_STARTED;\r
- } else if (Instance->State == MTFTP4_STATE_DESTORY) {\r
+ } else if (Instance->State == MTFTP4_STATE_DESTROY) {\r
return EFI_DEVICE_ERROR;\r
}\r
\r
- Udp = Instance->UnicastPort->Udp;\r
+ Udp = Instance->UnicastPort->Protocol.Udp4;\r
return Udp->Poll (Udp);\r
}\r
\r