/** @file\r
Mtftp6 Rrq process functions implementation.\r
\r
- Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
\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.\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
{\r
EFI_MTFTP6_PACKET *Ack;\r
NET_BUF *Packet;\r
+ EFI_STATUS Status;\r
+\r
+ Status = EFI_SUCCESS;\r
\r
//\r
// Allocate net buffer to create ack packet.\r
// Reset current retry count of the instance.\r
//\r
Instance->CurRetry = 0;\r
+ Instance->LastPacket = Packet;\r
\r
- return Mtftp6TransmitPacket (Instance, Packet);\r
+ Status = Mtftp6TransmitPacket (Instance, Packet);\r
+ if (!EFI_ERROR (Status)) {\r
+ Instance->AckedBlock = Instance->TotalBlock;\r
+ }\r
+\r
+ return Status;\r
}\r
\r
\r
UINT16 Block;\r
UINT64 Start;\r
UINT32 DataLen;\r
- UINT64 TotalBlock;\r
+ UINT64 BlockCounter;\r
BOOLEAN Completed;\r
\r
Completed = FALSE;\r
// This is the last block, save the block num\r
//\r
if (DataLen < Instance->BlkSize) {\r
- Completed = TRUE;\r
+ Completed = TRUE;\r
Instance->LastBlk = Block;\r
Mtftp6SetLastBlockNum (&Instance->BlkList, Block);\r
}\r
// Remove this block number from the file hole. If Mtftp6RemoveBlockNum\r
// returns EFI_NOT_FOUND, the block has been saved, don't save it again.\r
// Note that : For bigger files, allowing the block counter to roll over\r
- // to accept transfers of unlimited size. So TotalBlock is memorised as\r
+ // to accept transfers of unlimited size. So BlockCounter is memorised as\r
// continuous block counter.\r
//\r
- Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &TotalBlock);\r
+ Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &BlockCounter);\r
\r
if (Status == EFI_NOT_FOUND) {\r
return EFI_SUCCESS;\r
\r
if (Token->Buffer != NULL) {\r
\r
- Start = MultU64x32 (TotalBlock - 1, Instance->BlkSize);\r
+ Start = MultU64x32 (BlockCounter - 1, Instance->BlkSize);\r
if (Start + DataLen <= Token->BufferSize) {\r
CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen);\r
//\r
INTN Expected;\r
\r
*IsCompleted = FALSE;\r
+ Status = EFI_SUCCESS;\r
BlockNum = NTOHS (Packet->Data.Block);\r
Expected = Mtftp6GetNextBlockNum (&Instance->BlkList);\r
\r
ASSERT (Expected >= 0);\r
\r
//\r
- // If we are active and received an unexpected packet, retransmit\r
- // the last ACK then restart receiving. If we are passive, save\r
- // the block.\r
+ // If we are active (Master) and received an unexpected packet, transmit\r
+ // the ACK for the block we received, then restart receiving the\r
+ // expected one. If we are passive (Slave), save the block.\r
//\r
if (Instance->IsMaster && (Expected != BlockNum)) {\r
//\r
NetbufFree (*UdpPacket);\r
*UdpPacket = NULL;\r
\r
- Mtftp6TransmitPacket (Instance, Instance->LastPacket);\r
- return EFI_SUCCESS;\r
+ //\r
+ // If Expected is 0, (UINT16) (Expected - 1) is also the expected Ack number (65535).\r
+ //\r
+ return Mtftp6RrqSendAck (Instance, (UINT16) (Expected - 1));\r
}\r
\r
Status = Mtftp6RrqSaveBlock (Instance, Packet, Len, UdpPacket);\r
return Status;\r
}\r
\r
+ //\r
+ // Record the total received and saved block number.\r
+ //\r
+ Instance->TotalBlock ++;\r
+\r
//\r
// Reset the passive client's timer whenever it received a valid data packet.\r
//\r
NetbufFree (*UdpPacket);\r
*UdpPacket = NULL;\r
\r
- Mtftp6RrqSendAck (Instance, BlockNum);\r
+ if (Instance->WindowSize == (Instance->TotalBlock - Instance->AckedBlock) || Expected < 0) {\r
+ Status = Mtftp6RrqSendAck (Instance, BlockNum);\r
+ }\r
}\r
\r
- return EFI_SUCCESS;\r
+ return Status;\r
}\r
\r
\r
}\r
\r
//\r
- // Server can only specify a smaller block size to be used and\r
+ // Server can only specify a smaller block size and windowsize to be used and\r
// return the timeout matches that requested.\r
//\r
if ((((ReplyInfo->BitMap & MTFTP6_OPT_BLKSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||\r
+ (((ReplyInfo->BitMap & MTFTP6_OPT_WINDOWSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||\r
(((ReplyInfo->BitMap & MTFTP6_OPT_TIMEOUT_BIT) != 0) && (ReplyInfo->Timeout != RequestInfo->Timeout))\r
- ) {\r
+ ) {\r
return FALSE;\r
}\r
\r
MTFTP6_EXT_OPTION_INFO ExtInfo;\r
EFI_STATUS Status;\r
INTN Expected;\r
+ EFI_UDP6_PROTOCOL *Udp6;\r
\r
*IsCompleted = FALSE;\r
+ Options = NULL;\r
\r
//\r
// If already started the master download, don't change the\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
+ ASSERT (Options != NULL);\r
\r
//\r
// Parse the extensive options in the packet.\r
//\r
- Status = Mtftp6ParseExtensionOption (Options, Count, FALSE, &ExtInfo);\r
+ Status = Mtftp6ParseExtensionOption (Options, Count, FALSE, Instance->Operation, &ExtInfo);\r
\r
if (EFI_ERROR (Status) || !Mtftp6RrqOackValid (Instance, &ExtInfo, &Instance->ExtInfo)) {\r
//\r
Mtftp6SendError (\r
Instance,\r
EFI_MTFTP6_ERRORCODE_ILLEGAL_OPERATION,\r
- (UINT8 *) "Mal-formated OACK packet"\r
+ (UINT8 *) "Malformatted OACK packet"\r
);\r
}\r
\r
\r
//\r
// Save the multicast info. Always update the Master, only update the\r
- // multicast IP address, block size, timeoute at the first time. If IP\r
+ // multicast IP address, block size, window size, timeoute at the first time. If IP\r
// address is updated, create a UDP child to receive the multicast.\r
//\r
Instance->IsMaster = ExtInfo.IsMaster;\r
);\r
\r
Instance->McastPort = ExtInfo.McastPort;\r
- Instance->McastUdpIo = UdpIoCreateIo (\r
- Instance->Service->Controller,\r
- Instance->Service->Image,\r
- Mtftp6RrqConfigMcastUdpIo,\r
- UDP_IO_UDP6_VERSION,\r
- Instance\r
- );\r
+ if (Instance->McastUdpIo == NULL) {\r
+ Instance->McastUdpIo = UdpIoCreateIo (\r
+ Instance->Service->Controller,\r
+ Instance->Service->Image,\r
+ Mtftp6RrqConfigMcastUdpIo,\r
+ UDP_IO_UDP6_VERSION,\r
+ Instance\r
+ );\r
+ if (Instance->McastUdpIo != NULL) {\r
+ Status = gBS->OpenProtocol (\r
+ Instance->McastUdpIo->UdpHandle,\r
+ &gEfiUdp6ProtocolGuid,\r
+ (VOID **) &Udp6,\r
+ Instance->Service->Image,\r
+ Instance->Handle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ UdpIoFreeIo (Instance->McastUdpIo);\r
+ Instance->McastUdpIo = NULL;\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+ }\r
+ }\r
\r
if (Instance->McastUdpIo == NULL) {\r
return EFI_DEVICE_ERROR;\r
Instance->BlkSize = ExtInfo.BlkSize;\r
}\r
\r
+ if (ExtInfo.WindowSize != 0) {\r
+ Instance->WindowSize = ExtInfo.WindowSize;\r
+ }\r
+\r
if (ExtInfo.Timeout != 0) {\r
Instance->Timeout = ExtInfo.Timeout;\r
}\r
Instance->BlkSize = ExtInfo.BlkSize;\r
}\r
\r
+ if (ExtInfo.WindowSize != 0) {\r
+ Instance->WindowSize = ExtInfo.WindowSize;\r
+ }\r
+\r
if (ExtInfo.Timeout != 0) {\r
Instance->Timeout = ExtInfo.Timeout;\r
}\r
//\r
// For the subsequent exchange of requests, reconfigure the udpio as\r
// (serverip, serverport, localip, localport).\r
- // Ususally, the client set serverport as 0 to receive and reset it\r
+ // Usually, the client set serverport as 0 to receive and reset it\r
// once the first packet arrives to send ack.\r
//\r
Instance->ServerDataPort = UdpEpt->RemotePort;\r
\r
default:\r
//\r
- // Drop and return eror if received error message.\r
+ // Drop and return error if received error message.\r
//\r
Status = EFI_TFTP_ERROR;\r
break;\r
\r
/**\r
Start the Mtftp6 instance to download. It first initializes some\r
- of the internal states, then builds and sends an RRQ reqeuest packet.\r
+ of the internal states, then builds and sends an RRQ request packet.\r
Finally, it starts receive for the downloading.\r
\r
@param[in] Instance The pointer to the Mtftp6 instance.\r
//\r
// The valid block number range are [1, 0xffff]. For example:\r
// the client sends an RRQ request to the server, the server\r
- // transfers the DATA1 block. If option negoitation is ongoing,\r
+ // transfers the DATA1 block. If option negotiation is ongoing,\r
// the server will send back an OACK, then client will send ACK0.\r
//\r
Status = Mtftp6InitBlockRange (&Instance->BlkList, 1, 0xffff);\r