/** @file
Mtftp6 Wrq process functions implementation.
Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Mtftp6Impl.h"
/**
Build and send a Mtftp6 data packet for upload.
@param[in] Instance The pointer to the Mtftp6 instance.
@param[in] BlockNum The block num to be sent.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the packet.
@retval EFI_SUCCESS The data packet was sent.
@retval EFI_ABORTED The user aborted this process.
**/
)
{
//
// Allocate net buffer to create data packet.
//
return EFI_OUT_OF_RESOURCES;
}
);
//
// Read the block from either the buffer or PacketNeeded callback
//
}
if (DataLen > 0) {
}
} else {
//
// Get data from PacketNeeded
//
}
//
// The received packet has already been freed.
//
(UINT8 *) "User aborted the transfer"
);
return EFI_ABORTED;
}
}
if (DataLen > 0) {
}
}
//
// Reset current retry count of the instance.
//
}
/**
Function to handle received ACK packet. If the ACK number matches the
expected block number, with more data pending, send the next
block. Otherwise, tell the caller that we are done.
@param[in] Instance The pointer to the Mtftp6 instance.
@param[in] Packet The pointer to the received packet.
@param[in] Len The length of the packet.
@param[out] UdpPacket The net buf of received packet.
@param[out] IsCompleted If TRUE, the upload has been completed.
Otherwise, the upload has not been completed.
@retval EFI_SUCCESS The ACK packet successfully processed.
@retval EFI_TFTP_ERROR The block number loops back.
@retval Others Failed to transmit the next data packet.
**/
)
{
*IsCompleted = FALSE;
//
// Get an unwanted ACK, return EFI_SUCCESS to let Mtftp6WrqInput
// restart receive.
//
return EFI_SUCCESS;
}
//
// Remove the acked block number, if this is the last block number,
// tell the Mtftp6WrqInput to finish the transfer. This is the last
// block number if the block range are empty..
//
if (Expected < 0) {
//
// The block range is empty. It may either because the the last
// block has been ACKed, or the sequence number just looped back,
// that is, there is more than 0xffff blocks.
//
*IsCompleted = TRUE;
return EFI_SUCCESS;
} else {
//
// Free the received packet before send new packet in ReceiveNotify,
// since the udpio might need to be reconfigured.
//
NetbufFree (*UdpPacket);
//
// Send the Mtftp6 error message if block number rolls back.
//
(UINT8 *) "Block number rolls back, not supported, try blksize option"
);
return EFI_TFTP_ERROR;
}
}
//
// Free the receive buffer before send new packet since it might need
// reconfigure udpio.
//
NetbufFree (*UdpPacket);
}
/**
Check whether the received OACK is valid. The OACK is valid
only if:
1. It only include options requested by us.
2. It can only include a smaller block size.
3. It can't change the proposed time out value.
4. Other requirements of the individal MTFTP6 options as required.
@param[in] ReplyInfo The pointer to options information in reply packet.
@param[in] RequestInfo The pointer to requested options information.
@retval TRUE If the option in OACK is valid.
@retval FALSE If the option is invalid.
**/
)
{
//
// It is invalid for server to return options we don't request
//
return FALSE;
}
//
// Server can only specify a smaller block size to be used and
// return the timeout matches that requested.
//
if ((((ReplyInfo->BitMap & MTFTP6_OPT_BLKSIZE_BIT) != 0) && (ReplyInfo->BlkSize > RequestInfo->BlkSize)) ||
(((ReplyInfo->BitMap & MTFTP6_OPT_TIMEOUT_BIT) != 0) && (ReplyInfo->Timeout != RequestInfo->Timeout))
) {
return FALSE;
}
return TRUE;
}
/**
Process the OACK packet for Wrq.
@param[in] Instance The pointer to the Mtftp6 instance.
@param[in] Packet The pointer to the received packet.
@param[in] Len The length of the packet.
@param[out] UdpPacket The net buf of received packet.
@param[out] IsCompleted If TRUE, the upload has been completed.
Otherwise, the upload has not been completed.
@retval EFI_SUCCESS The OACK packet successfully processed.
@retval EFI_TFTP_ERROR An TFTP communication error happened.
@retval Others Failed to process the OACK packet.
**/
)
{
*IsCompleted = FALSE;
//
// Ignore the OACK if already started the upload
//
if (Expected != 0) {
return EFI_SUCCESS;
}
//
// Parse and validate the options from server
//
return Status;
}
//
// Don't send a MTFTP error packet when out of resource, it can
// only make it worse.
//
if (Status != EFI_OUT_OF_RESOURCES) {
//
// Free the received packet before send new packet in ReceiveNotify,
// since the udpio might need to be reconfigured.
//
NetbufFree (*UdpPacket);
//
// Send the Mtftp6 error message if invalid Oack packet received.
//
(UINT8 *) "Mal-formated OACK packet"
);
}
return EFI_TFTP_ERROR;
}
}
}
//
// Build a bogus ACK0 packet then pass it to the Mtftp6WrqHandleAck,
// which will start the transmission of the first data block.
//
return Mtftp6WrqHandleAck (
&Dummy,
sizeof (EFI_MTFTP6_ACK_HEADER),
);
}
/**
The packet process callback for Mtftp6 upload.
@param[in] UdpPacket The pointer to the packet received.
@param[in] UdpEpt The pointer to the Udp6 access point.
@param[in] IoStatus The status from Udp6 instance.
@param[in] Context The pointer to the context.
**/
)
{
IsCompleted = FALSE;
TotalNum = 0;
//
// Return error status if Udp6 instance failed to receive.
//
goto ON_EXIT;
}
goto ON_EXIT;
}
//
// Client send initial request to server's listening port. Server
// will select a UDP port to communicate with the client.
//
if (Instance->ServerDataPort != 0) {
goto ON_EXIT;
} else {
}
}
//
// Copy the MTFTP packet to a continuous buffer if it isn't already so.
//
if (TotalNum > 1) {
goto ON_EXIT;
}
} else {
}
//
// Callback to the user's CheckPacket if provided. Abort the transmission
// if CheckPacket returns an EFI_ERROR code.
//
) {
);
//
// Send an error message to the server to inform it
//
if (Opcode != EFI_MTFTP6_OPCODE_ERROR) {
//
// Free the received packet before send new packet in ReceiveNotify,
// since the udpio might need to be reconfigured.
//
//
// Send the Mtftp6 error message if user aborted the current session.
//
(UINT8 *) "User aborted the transfer"
);
}
goto ON_EXIT;
}
}
//
// Switch the process routines by the operation code.
//
switch (Opcode) {
case EFI_MTFTP6_OPCODE_ACK:
goto ON_EXIT;
}
//
// Handle the Ack packet of Wrq.
//
break;
case EFI_MTFTP6_OPCODE_OACK:
if (Len <= MTFTP6_OPCODE_LEN) {
goto ON_EXIT;
}
//
// Handle the Oack packet of Wrq.
//
break;
default:
//
// Drop and return eror if received error message.
//
break;
}
//
// Free the resources, then if !EFI_ERROR (Status) and not completed,
// restart the receive, otherwise end the session.
//
}
}
0
);
}
//
// Clean up the current session if failed to continue.
//
}
}
/**
Start the Mtftp6 instance to upload. It will first init some states,
then send the WRQ request packet, and start to receive the packet.
@param[in] Instance The pointer to the Mtftp6 instance.
@param[in] Operation The operation code of the current packet.
@retval EFI_SUCCESS The Mtftp6 was started to upload.
@retval Others Failed to start to upload.
**/
)
{
//
// The valid block number range are [0, 0xffff]. For example:
// the client sends an WRQ request to the server, the server
// ACK with an ACK0 to let client start transfer the first
// packet.
//
return Status;
}
return Status;
}
return UdpIoRecvDatagram (
0
);
}