/** @file\r
-\r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+ Support routines for Mtftp.\r
+ \r
+Copyright (c) 2006 - 2009, 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\r
+http://opensource.org/licenses/bsd-license.php<BR>\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
\r
-Module Name:\r
-\r
- Mtftp4Support.c\r
-\r
-Abstract:\r
-\r
- Support routines for Mtftp\r
-\r
-\r
**/\r
\r
#include "Mtftp4Impl.h"\r
\r
\r
/**\r
- Allocate a MTFTP4 block range, then init it to the\r
- range of [Start, End]\r
+ Allocate a MTFTP4 block range, then init it to the range of [Start, End]\r
\r
@param Start The start block number\r
@param End The last block number in the range\r
\r
- @return NULL if failed to allocate memory, otherwise the created block range.\r
+ @return Pointer to the created block range, NULL if failed to allocate memory.\r
\r
**/\r
-STATIC\r
MTFTP4_BLOCK_RANGE *\r
Mtftp4AllocateRange (\r
IN UINT16 Start,\r
\r
\r
/**\r
- Initialize the block range for either RRQ or WRQ. RRQ and WRQ have\r
- different requirements for Start and End. For example, during start\r
- up, WRQ initializes its whole valid block range to [0, 0xffff]. This\r
- is bacause the server will send us a ACK0 to inform us to start the\r
- upload. When the client received ACK0, it will remove 0 from the range,\r
- get the next block number, which is 1, then upload the BLOCK1. For RRQ\r
- without option negotiation, the server will directly send us the BLOCK1\r
- in response to the client's RRQ. When received BLOCK1, the client will\r
- remove it from the block range and send an ACK. It also works if there\r
- is option negotiation.\r
+ Initialize the block range for either RRQ or WRQ. \r
+ \r
+ RRQ and WRQ have different requirements for Start and End. \r
+ For example, during start up, WRQ initializes its whole valid block range \r
+ to [0, 0xffff]. This is bacause the server will send us a ACK0 to inform us \r
+ to start the upload. When the client received ACK0, it will remove 0 from the \r
+ range, get the next block number, which is 1, then upload the BLOCK1. For RRQ\r
+ without option negotiation, the server will directly send us the BLOCK1 in \r
+ response to the client's RRQ. When received BLOCK1, the client will remove \r
+ it from the block range and send an ACK. It also works if there is option \r
+ negotiation.\r
\r
@param Head The block range head to initialize\r
@param Start The Start block number.\r
\r
@param Head The block range head\r
\r
- @return -1: if the block range is empty. Otherwise the first valid block number.\r
+ @return The first valid block number, -1 if the block range is empty. \r
\r
**/\r
INTN\r
\r
\r
/**\r
- Set the last block number of the block range list. It will\r
- remove all the blocks after the Last. MTFTP initialize the\r
- block range to the maximum possible range, such as [0, 0xffff]\r
- for WRQ. When it gets the last block number, it will call\r
- this function to set the last block number.\r
+ Set the last block number of the block range list. \r
+ \r
+ It will remove all the blocks after the Last. MTFTP initialize the block range\r
+ to the maximum possible range, such as [0, 0xffff] for WRQ. When it gets the \r
+ last block number, it will call this function to set the last block number.\r
\r
@param Head The block range list\r
@param Last The last block number\r
\r
- @return None\r
-\r
**/\r
VOID\r
Mtftp4SetLastBlockNum (\r
\r
if (Range->Start > Last) {\r
RemoveEntryList (&Range->Link);\r
- gBS->FreePool (Range);\r
+ FreePool (Range);\r
continue;\r
}\r
\r
\r
if (Range->Start > Range->End) {\r
RemoveEntryList (&Range->Link);\r
- gBS->FreePool (Range);\r
+ FreePool (Range);\r
}\r
\r
return EFI_SUCCESS;\r
}\r
\r
Packet = (EFI_MTFTP4_PACKET *) NetbufAllocSpace (Nbuf, Len, FALSE);\r
+ ASSERT (Packet != NULL);\r
+\r
Packet->OpCode = HTONS (Instance->Operation);\r
Cur = Packet->Rrq.Filename;\r
Cur = (UINT8 *) AsciiStrCpy ((CHAR8 *) Cur, (CHAR8 *) Token->Filename);\r
\r
\r
/**\r
- Build then send an error message\r
+ Build then send an error message.\r
\r
@param Instance The MTFTP session\r
- @param ErrInfo The error code and message\r
+ @param ErrCode The error code \r
+ @param ErrInfo The error message\r
\r
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the error packet\r
@retval EFI_SUCCESS The error packet is transmitted.\r
Mtftp4SendError (\r
IN MTFTP4_PROTOCOL *Instance,\r
IN UINT16 ErrCode,\r
- IN UINT8* ErrInfo\r
+ IN UINT8 *ErrInfo\r
)\r
{\r
NET_BUF *Packet;\r
\r
Len = (UINT32) (AsciiStrLen ((CHAR8 *) ErrInfo) + sizeof (EFI_MTFTP4_ERROR_HEADER));\r
Packet = NetbufAlloc (Len);\r
-\r
if (Packet == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
TftpError = (EFI_MTFTP4_PACKET *) NetbufAllocSpace (Packet, Len, FALSE);\r
+ ASSERT (TftpError != NULL);\r
+\r
TftpError->OpCode = HTONS (EFI_MTFTP4_OPCODE_ERROR);\r
TftpError->Error.ErrorCode = HTONS (ErrCode);\r
\r
\r
/**\r
The callback function called when the packet is transmitted.\r
+ \r
It simply frees the packet.\r
\r
@param Packet The transmitted (or failed to) packet\r
- @param Points The local and remote UDP access point\r
+ @param EndPoint The local and remote UDP access point\r
@param IoStatus The result of the transmission\r
@param Context Opaque parameter to the callback\r
\r
- @return None\r
-\r
**/\r
-STATIC\r
VOID\r
+EFIAPI\r
Mtftp4OnPacketSent (\r
- NET_BUF *Packet,\r
- UDP_POINTS *Points,\r
- EFI_STATUS IoStatus,\r
- VOID *Context\r
+ IN NET_BUF *Packet,\r
+ IN UDP_END_POINT *EndPoint,\r
+ IN EFI_STATUS IoStatus,\r
+ IN VOID *Context\r
)\r
{\r
NetbufFree (Packet);\r
\r
\r
/**\r
- Set the timeout for the instance. User a longer time for\r
- passive instances.\r
+ Set the timeout for the instance. User a longer time for passive instances.\r
\r
@param Instance The Mtftp session to set time out\r
\r
- @return None\r
-\r
**/\r
VOID\r
Mtftp4SetTimeout (\r
- IN MTFTP4_PROTOCOL *Instance\r
+ IN OUT MTFTP4_PROTOCOL *Instance\r
)\r
{\r
if (Instance->Master) {\r
\r
\r
/**\r
- Send the packet for the instance. It will first save a reference to\r
- the packet for later retransmission. then determine the destination\r
- port, listen port for requests, and connected port for others. At last,\r
- send the packet out.\r
+ Send the packet for the instance. \r
+ \r
+ It will first save a reference to the packet for later retransmission. \r
+ Then determine the destination port, listen port for requests, and connected \r
+ port for others. At last, send the packet out.\r
\r
@param Instance The Mtftp instance\r
@param Packet The packet to send\r
**/\r
EFI_STATUS\r
Mtftp4SendPacket (\r
- IN MTFTP4_PROTOCOL *Instance,\r
- IN NET_BUF *Packet\r
+ IN OUT MTFTP4_PROTOCOL *Instance,\r
+ IN OUT NET_BUF *Packet\r
)\r
{\r
- UDP_POINTS UdpPoint;\r
+ UDP_END_POINT UdpPoint;\r
EFI_STATUS Status;\r
UINT16 OpCode;\r
UINT16 Value;\r
NetbufFree (Instance->LastPacket);\r
}\r
\r
- Instance->LastPacket = Packet;\r
+ Instance->LastPacket = Packet;\r
\r
- Instance->CurRetry = 0;\r
+ Instance->CurRetry = 0;\r
Mtftp4SetTimeout (Instance);\r
\r
- UdpPoint.LocalAddr = 0;\r
- UdpPoint.LocalPort = 0;\r
- UdpPoint.RemoteAddr = Instance->ServerIp;\r
+ ZeroMem (&UdpPoint, sizeof (UdpPoint));\r
+ UdpPoint.RemoteAddr.Addr[0] = Instance->ServerIp;\r
\r
//\r
// Send the requests to the listening port, other packets\r
Value = *((UINT16 *) NetbufGetByte (Packet, 0, NULL));\r
OpCode = NTOHS (Value);\r
\r
- if ((OpCode == EFI_MTFTP4_OPCODE_RRQ) || (OpCode == EFI_MTFTP4_OPCODE_DIR) ||\r
+ if ((OpCode == EFI_MTFTP4_OPCODE_RRQ) || \r
+ (OpCode == EFI_MTFTP4_OPCODE_DIR) ||\r
(OpCode == EFI_MTFTP4_OPCODE_WRQ)) {\r
UdpPoint.RemotePort = Instance->ListeningPort;\r
} else {\r
Instance->UnicastPort,\r
Packet,\r
&UdpPoint,\r
- 0,\r
+ NULL,\r
Mtftp4OnPacketSent,\r
Instance\r
);\r
\r
\r
/**\r
- Retransmit the last packet for the instance\r
+ Retransmit the last packet for the instance.\r
\r
@param Instance The Mtftp instance\r
\r
IN MTFTP4_PROTOCOL *Instance\r
)\r
{\r
- UDP_POINTS UdpPoint;\r
+ UDP_END_POINT UdpPoint;\r
EFI_STATUS Status;\r
UINT16 OpCode;\r
UINT16 Value;\r
\r
ASSERT (Instance->LastPacket != NULL);\r
\r
- UdpPoint.LocalAddr = 0;\r
- UdpPoint.LocalPort = 0;\r
- UdpPoint.RemoteAddr = Instance->ServerIp;\r
+ ZeroMem (&UdpPoint, sizeof (UdpPoint));\r
+ UdpPoint.RemoteAddr.Addr[0] = Instance->ServerIp;\r
\r
//\r
// Set the requests to the listening port, other packets to the connected port\r
Instance->UnicastPort,\r
Instance->LastPacket,\r
&UdpPoint,\r
- 0,\r
+ NULL,\r
Mtftp4OnPacketSent,\r
Instance\r
);\r
@param Event The ticking event\r
@param Context The Mtftp service instance\r
\r
- @return None\r
-\r
**/\r
VOID\r
EFIAPI\r