/** @file\r
Mtftp6 Rrq process functions implementation.\r
\r
- Copyright (c) 2009 - 2014, 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
{\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
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
BOOLEAN Completed;\r
\r
Completed = FALSE;\r
// to accept transfers of unlimited size. So TotalBlock is memorised as\r
// continuous block counter.\r
//\r
- Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &TotalBlock);\r
+ Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &Instance->TotalBlock);\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 (Instance->TotalBlock - 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 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, 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
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
//\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
\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
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