2007-09-30 05:08:02 +02:00
|
|
|
/** @file
|
2009-01-16 07:56:18 +01:00
|
|
|
Support routines for MTFTP.
|
|
|
|
|
|
|
|
Copyright (c) 2006, Intel Corporation<BR>
|
2007-09-30 05:08:02 +02:00
|
|
|
All rights reserved. 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
|
2009-01-16 07:56:18 +01:00
|
|
|
http://opensource.org/licenses/bsd-license.php<BR>
|
2007-09-30 05:08:02 +02:00
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef __EFI_MTFTP4_SUPPORT_H__
|
|
|
|
#define __EFI_MTFTP4_SUPPORT_H__
|
|
|
|
|
|
|
|
//
|
|
|
|
// The structure representing a range of block numbers, [Start, End].
|
|
|
|
// It is used to remember the holes in the MTFTP block space. If all
|
|
|
|
// the holes are filled in, then the download or upload has completed.
|
|
|
|
//
|
|
|
|
typedef struct {
|
2008-02-14 10:40:22 +01:00
|
|
|
LIST_ENTRY Link;
|
2007-09-30 05:08:02 +02:00
|
|
|
INTN Start;
|
|
|
|
INTN End;
|
|
|
|
} MTFTP4_BLOCK_RANGE;
|
|
|
|
|
|
|
|
|
2009-01-16 07:56:18 +01:00
|
|
|
/**
|
|
|
|
Initialize the block range for either RRQ or WRQ.
|
|
|
|
|
|
|
|
RRQ and WRQ have different requirements for Start and End.
|
|
|
|
For example, during start up, WRQ initializes its whole valid block range
|
|
|
|
to [0, 0xffff]. This is bacause the server will send us a ACK0 to inform us
|
|
|
|
to start the upload. When the client received ACK0, it will remove 0 from the
|
|
|
|
range, get the next block number, which is 1, then upload the BLOCK1. For RRQ
|
|
|
|
without option negotiation, the server will directly send us the BLOCK1 in
|
|
|
|
response to the client's RRQ. When received BLOCK1, the client will remove
|
|
|
|
it from the block range and send an ACK. It also works if there is option
|
|
|
|
negotiation.
|
|
|
|
|
|
|
|
@param Head The block range head to initialize
|
|
|
|
@param Start The Start block number.
|
|
|
|
@param End The last block number.
|
|
|
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for initial block range
|
|
|
|
@retval EFI_SUCCESS The initial block range is created.
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
EFI_STATUS
|
|
|
|
Mtftp4InitBlockRange (
|
2008-02-14 10:40:22 +01:00
|
|
|
IN LIST_ENTRY *Head,
|
2007-09-30 05:08:02 +02:00
|
|
|
IN UINT16 Start,
|
|
|
|
IN UINT16 End
|
|
|
|
);
|
|
|
|
|
2009-01-16 07:56:18 +01:00
|
|
|
/**
|
|
|
|
Get the first valid block number on the range list.
|
|
|
|
|
|
|
|
@param Head The block range head
|
|
|
|
|
|
|
|
@return The first valid block number, -1 if the block range is empty.
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
INTN
|
|
|
|
Mtftp4GetNextBlockNum (
|
2008-02-14 10:40:22 +01:00
|
|
|
IN LIST_ENTRY *Head
|
2007-09-30 05:08:02 +02:00
|
|
|
);
|
|
|
|
|
2009-01-16 07:56:18 +01:00
|
|
|
/**
|
|
|
|
Set the last block number of the block range list.
|
|
|
|
|
|
|
|
It will remove all the blocks after the Last. MTFTP initialize the block range
|
|
|
|
to the maximum possible range, such as [0, 0xffff] for WRQ. When it gets the
|
|
|
|
last block number, it will call this function to set the last block number.
|
|
|
|
|
|
|
|
@param Head The block range list
|
|
|
|
@param Last The last block number
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
VOID
|
|
|
|
Mtftp4SetLastBlockNum (
|
2008-02-14 10:40:22 +01:00
|
|
|
IN LIST_ENTRY *Head,
|
2007-09-30 05:08:02 +02:00
|
|
|
IN UINT16 Last
|
|
|
|
);
|
|
|
|
|
2009-01-16 07:56:18 +01:00
|
|
|
/**
|
|
|
|
Remove the block number from the block range list.
|
|
|
|
|
|
|
|
@param Head The block range list to remove from
|
|
|
|
@param Num The block number to remove
|
|
|
|
|
|
|
|
@retval EFI_NOT_FOUND The block number isn't in the block range list
|
|
|
|
@retval EFI_SUCCESS The block number has been removed from the list
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
EFI_STATUS
|
|
|
|
Mtftp4RemoveBlockNum (
|
2008-02-14 10:40:22 +01:00
|
|
|
IN LIST_ENTRY *Head,
|
2007-09-30 05:08:02 +02:00
|
|
|
IN UINT16 Num
|
|
|
|
);
|
|
|
|
|
2009-01-16 07:56:18 +01:00
|
|
|
/**
|
|
|
|
Set the timeout for the instance. User a longer time for passive instances.
|
|
|
|
|
|
|
|
@param Instance The Mtftp session to set time out
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
VOID
|
|
|
|
Mtftp4SetTimeout (
|
2009-01-16 07:56:18 +01:00
|
|
|
IN OUT MTFTP4_PROTOCOL *Instance
|
2007-09-30 05:08:02 +02:00
|
|
|
);
|
|
|
|
|
2009-01-16 07:56:18 +01:00
|
|
|
/**
|
|
|
|
Send the packet for the instance.
|
|
|
|
|
|
|
|
It will first save a reference to the packet for later retransmission.
|
|
|
|
Then determine the destination port, listen port for requests, and connected
|
|
|
|
port for others. At last, send the packet out.
|
|
|
|
|
|
|
|
@param Instance The Mtftp instance
|
|
|
|
@param Packet The packet to send
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The packet is sent out
|
|
|
|
@retval Others Failed to transmit the packet.
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
EFI_STATUS
|
|
|
|
Mtftp4SendPacket (
|
2009-01-16 07:56:18 +01:00
|
|
|
IN OUT MTFTP4_PROTOCOL *Instance,
|
|
|
|
IN OUT NET_BUF *Packet
|
2007-09-30 05:08:02 +02:00
|
|
|
);
|
|
|
|
|
2009-01-16 07:56:18 +01:00
|
|
|
/**
|
|
|
|
Build then transmit the request packet for the MTFTP session.
|
|
|
|
|
|
|
|
@param Instance The Mtftp session
|
|
|
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the request
|
|
|
|
@retval EFI_SUCCESS The request is built and sent
|
|
|
|
@retval Others Failed to transmit the packet.
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
EFI_STATUS
|
|
|
|
Mtftp4SendRequest (
|
|
|
|
IN MTFTP4_PROTOCOL *Instance
|
|
|
|
);
|
|
|
|
|
2009-01-16 07:56:18 +01:00
|
|
|
/**
|
|
|
|
Build then send an error message.
|
|
|
|
|
|
|
|
@param Instance The MTFTP session
|
|
|
|
@param ErrCode The error code
|
|
|
|
@param ErrInfo The error message
|
|
|
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the error packet
|
|
|
|
@retval EFI_SUCCESS The error packet is transmitted.
|
|
|
|
@retval Others Failed to transmit the packet.
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
EFI_STATUS
|
|
|
|
Mtftp4SendError (
|
|
|
|
IN MTFTP4_PROTOCOL *Instance,
|
|
|
|
IN UINT16 ErrCode,
|
2009-01-16 07:56:18 +01:00
|
|
|
IN UINT8 *ErrInfo
|
2007-09-30 05:08:02 +02:00
|
|
|
);
|
|
|
|
|
2009-01-16 07:56:18 +01:00
|
|
|
/**
|
|
|
|
Retransmit the last packet for the instance.
|
|
|
|
|
|
|
|
@param Instance The Mtftp instance
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The last packet is retransmitted.
|
|
|
|
@retval Others Failed to retransmit.
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
EFI_STATUS
|
|
|
|
Mtftp4Retransmit (
|
|
|
|
IN MTFTP4_PROTOCOL *Instance
|
|
|
|
);
|
|
|
|
|
2009-01-16 07:56:18 +01:00
|
|
|
/**
|
|
|
|
The timer ticking function for the Mtftp service instance.
|
|
|
|
|
|
|
|
@param Event The ticking event
|
|
|
|
@param Context The Mtftp service instance
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
Mtftp4OnTimerTick (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
);
|
|
|
|
#endif
|