MdeModulePke/Mtftp4Dxe: Support windowsize in read request operation.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=886

This patch is to support the TFTP windowsize option described in RFC 7440.
The feature allows the client and server to negotiate a window size of
consecutive blocks to send as an alternative for replacing the single-block
lockstep schema.

Currently, the windowsize for write request operation is not supported since
there is no real use cases.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Shao Ming <ming.shao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
This commit is contained in:
Jiaxin Wu
2018-09-14 15:47:20 +08:00
parent 6a147d6dae
commit 6c047cfab1
8 changed files with 89 additions and 37 deletions

View File

@@ -99,6 +99,9 @@ Mtftp4RrqSendAck (
{
EFI_MTFTP4_PACKET *Ack;
NET_BUF *Packet;
EFI_STATUS Status;
Status = EFI_SUCCESS;
Packet = NetbufAlloc (sizeof (EFI_MTFTP4_ACK_HEADER));
if (Packet == NULL) {
@@ -115,7 +118,12 @@ Mtftp4RrqSendAck (
Ack->Ack.OpCode = HTONS (EFI_MTFTP4_OPCODE_ACK);
Ack->Ack.Block[0] = HTONS (BlkNo);
return Mtftp4SendPacket (Instance, Packet);
Status = Mtftp4SendPacket (Instance, Packet);
if (!EFI_ERROR (Status)) {
Instance->AckedBlock = Instance->TotalBlock;
}
return Status;
}
@@ -146,7 +154,6 @@ Mtftp4RrqSaveBlock (
UINT16 Block;
UINT64 Start;
UINT32 DataLen;
UINT64 TotalBlock;
BOOLEAN Completed;
Completed = FALSE;
@@ -158,7 +165,7 @@ Mtftp4RrqSaveBlock (
// This is the last block, save the block no
//
if (DataLen < Instance->BlkSize) {
Completed = TRUE;
Completed = TRUE;
Instance->LastBlock = Block;
Mtftp4SetLastBlockNum (&Instance->Blocks, Block);
}
@@ -170,7 +177,7 @@ Mtftp4RrqSaveBlock (
// to accept transfers of unlimited size. So TotalBlock is memorised as
// continuous block counter.
//
Status = Mtftp4RemoveBlockNum (&Instance->Blocks, Block, Completed, &TotalBlock);
Status = Mtftp4RemoveBlockNum (&Instance->Blocks, Block, Completed, &Instance->TotalBlock);
if (Status == EFI_NOT_FOUND) {
return EFI_SUCCESS;
@@ -193,7 +200,7 @@ Mtftp4RrqSaveBlock (
}
if (Token->Buffer != NULL) {
Start = MultU64x32 (TotalBlock - 1, Instance->BlkSize);
Start = MultU64x32 (Instance->TotalBlock - 1, Instance->BlkSize);
if (Start + DataLen <= Token->BufferSize) {
CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen);
@@ -257,19 +264,22 @@ Mtftp4RrqHandleData (
INTN Expected;
*Completed = FALSE;
Status = EFI_SUCCESS;
BlockNum = NTOHS (Packet->Data.Block);
Expected = Mtftp4GetNextBlockNum (&Instance->Blocks);
ASSERT (Expected >= 0);
//
// If we are active and received an unexpected packet, retransmit
// the last ACK then restart receiving. If we are passive, save
// the block.
// If we are active and received an unexpected packet, transmit
// the ACK for the block we received, then restart receiving the
// expected one. If we are passive, save the block.
//
if (Instance->Master && (Expected != BlockNum)) {
Mtftp4Retransmit (Instance);
return EFI_SUCCESS;
//
// If Expected is 0, (UINT16) (Expected - 1) is also the expected Ack number (65535).
//
return Mtftp4RrqSendAck (Instance, (UINT16) (Expected - 1));
}
Status = Mtftp4RrqSaveBlock (Instance, Packet, Len);
@@ -309,10 +319,13 @@ Mtftp4RrqHandleData (
BlockNum = (UINT16) (Expected - 1);
}
Mtftp4RrqSendAck (Instance, BlockNum);
if (Instance->WindowSize == (Instance->TotalBlock - Instance->AckedBlock) || Expected < 0) {
Status = Mtftp4RrqSendAck (Instance, BlockNum);
}
}
return EFI_SUCCESS;
return Status;
}
@@ -349,11 +362,13 @@ Mtftp4RrqOackValid (
}
//
// Server can only specify a smaller block size to be used and
// Server can only specify a smaller block size and window size to be used and
// return the timeout matches that requested.
//
if ((((Reply->Exist & MTFTP4_BLKSIZE_EXIST) != 0)&& (Reply->BlkSize > Request->BlkSize)) ||
(((Reply->Exist & MTFTP4_TIMEOUT_EXIST) != 0) && (Reply->Timeout != Request->Timeout))) {
(((Reply->Exist & MTFTP4_WINDOWSIZE_EXIST) != 0)&& (Reply->WindowSize > Request->WindowSize)) ||
(((Reply->Exist & MTFTP4_TIMEOUT_EXIST) != 0) && (Reply->Timeout != Request->Timeout))
) {
return FALSE;
}
@@ -507,7 +522,7 @@ Mtftp4RrqHandleOack (
//
ZeroMem (&Reply, sizeof (MTFTP4_OPTION));
Status = Mtftp4ParseOptionOack (Packet, Len, &Reply);
Status = Mtftp4ParseOptionOack (Packet, Len, Instance->Operation, &Reply);
if (EFI_ERROR (Status) ||
!Mtftp4RrqOackValid (Instance, &Reply, &Instance->RequestOption)) {
@@ -529,7 +544,7 @@ Mtftp4RrqHandleOack (
//
// Save the multicast info. Always update the Master, only update the
// multicast IP address, block size, timeoute at the first time. If IP
// multicast IP address, block size, window size, timeoute at the first time. If IP
// address is updated, create a UDP child to receive the multicast.
//
Instance->Master = Reply.Master;
@@ -599,6 +614,10 @@ Mtftp4RrqHandleOack (
Instance->BlkSize = Reply.BlkSize;
}
if (Reply.WindowSize != 0) {
Instance->WindowSize = Reply.WindowSize;
}
if (Reply.Timeout != 0) {
Instance->Timeout = Reply.Timeout;
}
@@ -611,6 +630,10 @@ Mtftp4RrqHandleOack (
Instance->BlkSize = Reply.BlkSize;
}
if (Reply.WindowSize != 0) {
Instance->WindowSize = Reply.WindowSize;
}
if (Reply.Timeout != 0) {
Instance->Timeout = Reply.Timeout;
}