-/** @file
-
-Copyright (c) 2006, Intel Corporation
-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
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-Module Name:
-
- Mtftp4Support.h
-
-Abstract:
-
- Support routines for MTFTP
-
-
-**/
-
-#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 {
- NET_LIST_ENTRY Link;
- INTN Start;
- INTN End;
-} MTFTP4_BLOCK_RANGE;
-
-
-EFI_STATUS
-Mtftp4InitBlockRange (
- IN NET_LIST_ENTRY *Head,
- IN UINT16 Start,
- IN UINT16 End
- );
-
-INTN
-Mtftp4GetNextBlockNum (
- IN NET_LIST_ENTRY *Head
- );
-
-VOID
-Mtftp4SetLastBlockNum (
- IN NET_LIST_ENTRY *Head,
- IN UINT16 Last
- );
-
-EFI_STATUS
-Mtftp4RemoveBlockNum (
- IN NET_LIST_ENTRY *Head,
- IN UINT16 Num
- );
-
-VOID
-Mtftp4SetTimeout (
- IN MTFTP4_PROTOCOL *Instance
- );
-
-EFI_STATUS
-Mtftp4SendPacket (
- IN MTFTP4_PROTOCOL *Instance,
- IN NET_BUF *Packet
- );
-
-EFI_STATUS
-Mtftp4SendRequest (
- IN MTFTP4_PROTOCOL *Instance
- );
-
-EFI_STATUS
-Mtftp4SendError (
- IN MTFTP4_PROTOCOL *Instance,
- IN UINT16 ErrCode,
- IN UINT8* ErrInfo
- );
-
-EFI_STATUS
-Mtftp4Retransmit (
- IN MTFTP4_PROTOCOL *Instance
- );
-
-VOID
-EFIAPI
-Mtftp4OnTimerTick (
- IN EFI_EVENT Event,
- IN VOID *Context
- );
-#endif
+/** @file\r
+ Support routines for MTFTP.\r
+\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef __EFI_MTFTP4_SUPPORT_H__\r
+#define __EFI_MTFTP4_SUPPORT_H__\r
+\r
+//\r
+// The structure representing a range of block numbers, [Start, End].\r
+// It is used to remember the holes in the MTFTP block space. If all\r
+// the holes are filled in, then the download or upload has completed.\r
+//\r
+typedef struct {\r
+ LIST_ENTRY Link;\r
+ INTN Start;\r
+ INTN End;\r
+ INTN Round;\r
+ INTN Bound;\r
+} MTFTP4_BLOCK_RANGE;\r
+\r
+\r
+/**\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
+ @param End The last block number.\r
+\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for initial block range\r
+ @retval EFI_SUCCESS The initial block range is created.\r
+\r
+**/\r
+EFI_STATUS\r
+Mtftp4InitBlockRange (\r
+ IN LIST_ENTRY *Head,\r
+ IN UINT16 Start,\r
+ IN UINT16 End\r
+ );\r
+\r
+/**\r
+ Get the first valid block number on the range list.\r
+\r
+ @param Head The block range head\r
+\r
+ @return The first valid block number, -1 if the block range is empty.\r
+\r
+**/\r
+INTN\r
+Mtftp4GetNextBlockNum (\r
+ IN LIST_ENTRY *Head\r
+ );\r
+\r
+/**\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
+**/\r
+VOID\r
+Mtftp4SetLastBlockNum (\r
+ IN LIST_ENTRY *Head,\r
+ IN UINT16 Last\r
+ );\r
+\r
+/**\r
+ Remove the block number from the block range list.\r
+\r
+ @param Head The block range list to remove from\r
+ @param Num The block number to remove\r
+ @param Completed Whether Num is the last block number.\r
+ @param BlockCounter The continuous block counter instead of the value after roll-over.\r
+\r
+ @retval EFI_NOT_FOUND The block number isn't in the block range list\r
+ @retval EFI_SUCCESS The block number has been removed from the list\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate resource\r
+\r
+**/\r
+EFI_STATUS\r
+Mtftp4RemoveBlockNum (\r
+ IN LIST_ENTRY *Head,\r
+ IN UINT16 Num,\r
+ IN BOOLEAN Completed,\r
+ OUT UINT64 *BlockCounter\r
+ );\r
+\r
+/**\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
+**/\r
+VOID\r
+Mtftp4SetTimeout (\r
+ IN OUT MTFTP4_PROTOCOL *Instance\r
+ );\r
+\r
+/**\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
+ @retval EFI_SUCCESS The packet is sent out\r
+ @retval Others Failed to transmit the packet.\r
+\r
+**/\r
+EFI_STATUS\r
+Mtftp4SendPacket (\r
+ IN OUT MTFTP4_PROTOCOL *Instance,\r
+ IN OUT NET_BUF *Packet\r
+ );\r
+\r
+/**\r
+ Build then transmit the request packet for the MTFTP session.\r
+\r
+ @param Instance The Mtftp session\r
+\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the request\r
+ @retval EFI_SUCCESS The request is built and sent\r
+ @retval Others Failed to transmit the packet.\r
+\r
+**/\r
+EFI_STATUS\r
+Mtftp4SendRequest (\r
+ IN MTFTP4_PROTOCOL *Instance\r
+ );\r
+\r
+/**\r
+ Build then send an error message.\r
+\r
+ @param Instance The MTFTP session\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
+ @retval Others Failed to transmit the packet.\r
+\r
+**/\r
+EFI_STATUS\r
+Mtftp4SendError (\r
+ IN MTFTP4_PROTOCOL *Instance,\r
+ IN UINT16 ErrCode,\r
+ IN UINT8 *ErrInfo\r
+ );\r
+\r
+\r
+/**\r
+ The timer ticking function in TPL_NOTIFY level for the Mtftp service instance.\r
+\r
+ @param Event The ticking event\r
+ @param Context The Mtftp service instance\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+Mtftp4OnTimerTickNotifyLevel (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ );\r
+\r
+/**\r
+ The timer ticking function for the Mtftp service instance.\r
+\r
+ @param Event The ticking event\r
+ @param Context The Mtftp service instance\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+Mtftp4OnTimerTick (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ );\r
+#endif\r