]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.h
Use ASSERT to check the expression.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Support.h
CommitLineData
83cbd279 1/** @file\r
dab714aa 2 Support routines for MTFTP.\r
3 \r
f1f11ea2 4Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
83cbd279 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
dab714aa 8http://opensource.org/licenses/bsd-license.php<BR>\r
83cbd279 9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
83cbd279 13**/\r
14\r
15#ifndef __EFI_MTFTP4_SUPPORT_H__\r
16#define __EFI_MTFTP4_SUPPORT_H__\r
17\r
18//\r
19// The structure representing a range of block numbers, [Start, End].\r
20// It is used to remember the holes in the MTFTP block space. If all\r
21// the holes are filled in, then the download or upload has completed.\r
22//\r
23typedef struct {\r
e48e37fc 24 LIST_ENTRY Link;\r
83cbd279 25 INTN Start;\r
26 INTN End;\r
f1f11ea2 27 INTN Round;\r
28 INTN Bound;\r
83cbd279 29} MTFTP4_BLOCK_RANGE;\r
30\r
31\r
dab714aa 32/**\r
33 Initialize the block range for either RRQ or WRQ. \r
34 \r
35 RRQ and WRQ have different requirements for Start and End. \r
36 For example, during start up, WRQ initializes its whole valid block range \r
37 to [0, 0xffff]. This is bacause the server will send us a ACK0 to inform us \r
38 to start the upload. When the client received ACK0, it will remove 0 from the \r
39 range, get the next block number, which is 1, then upload the BLOCK1. For RRQ\r
40 without option negotiation, the server will directly send us the BLOCK1 in \r
41 response to the client's RRQ. When received BLOCK1, the client will remove \r
42 it from the block range and send an ACK. It also works if there is option \r
43 negotiation.\r
44\r
45 @param Head The block range head to initialize\r
46 @param Start The Start block number.\r
47 @param End The last block number.\r
48\r
49 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for initial block range\r
50 @retval EFI_SUCCESS The initial block range is created.\r
51\r
52**/\r
83cbd279 53EFI_STATUS\r
54Mtftp4InitBlockRange (\r
e48e37fc 55 IN LIST_ENTRY *Head,\r
83cbd279 56 IN UINT16 Start,\r
57 IN UINT16 End\r
58 );\r
59\r
dab714aa 60/**\r
61 Get the first valid block number on the range list.\r
62\r
63 @param Head The block range head\r
64\r
65 @return The first valid block number, -1 if the block range is empty. \r
66\r
67**/\r
83cbd279 68INTN\r
69Mtftp4GetNextBlockNum (\r
e48e37fc 70 IN LIST_ENTRY *Head\r
83cbd279 71 );\r
72\r
dab714aa 73/**\r
74 Set the last block number of the block range list. \r
75 \r
76 It will remove all the blocks after the Last. MTFTP initialize the block range\r
77 to the maximum possible range, such as [0, 0xffff] for WRQ. When it gets the \r
78 last block number, it will call this function to set the last block number.\r
79\r
80 @param Head The block range list\r
81 @param Last The last block number\r
82\r
83**/\r
83cbd279 84VOID\r
85Mtftp4SetLastBlockNum (\r
e48e37fc 86 IN LIST_ENTRY *Head,\r
83cbd279 87 IN UINT16 Last\r
88 );\r
89\r
dab714aa 90/**\r
91 Remove the block number from the block range list.\r
92\r
93 @param Head The block range list to remove from\r
94 @param Num The block number to remove\r
f1f11ea2 95 @param TotalBlock The continuous block number in all \r
dab714aa 96\r
97 @retval EFI_NOT_FOUND The block number isn't in the block range list\r
98 @retval EFI_SUCCESS The block number has been removed from the list\r
99 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource\r
100\r
101**/\r
83cbd279 102EFI_STATUS\r
103Mtftp4RemoveBlockNum (\r
e48e37fc 104 IN LIST_ENTRY *Head,\r
f1f11ea2 105 IN UINT16 Num,\r
106 OUT UINT64 *TotalBlock\r
83cbd279 107 );\r
108\r
dab714aa 109/**\r
110 Set the timeout for the instance. User a longer time for passive instances.\r
111\r
112 @param Instance The Mtftp session to set time out\r
113\r
114**/\r
83cbd279 115VOID\r
116Mtftp4SetTimeout (\r
dab714aa 117 IN OUT MTFTP4_PROTOCOL *Instance\r
83cbd279 118 );\r
119\r
dab714aa 120/**\r
121 Send the packet for the instance. \r
122 \r
123 It will first save a reference to the packet for later retransmission. \r
124 Then determine the destination port, listen port for requests, and connected \r
125 port for others. At last, send the packet out.\r
126\r
127 @param Instance The Mtftp instance\r
128 @param Packet The packet to send\r
129\r
130 @retval EFI_SUCCESS The packet is sent out\r
131 @retval Others Failed to transmit the packet.\r
132\r
133**/\r
83cbd279 134EFI_STATUS\r
135Mtftp4SendPacket (\r
dab714aa 136 IN OUT MTFTP4_PROTOCOL *Instance,\r
137 IN OUT NET_BUF *Packet\r
83cbd279 138 );\r
139\r
dab714aa 140/**\r
141 Build then transmit the request packet for the MTFTP session.\r
142\r
143 @param Instance The Mtftp session\r
144\r
145 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the request\r
146 @retval EFI_SUCCESS The request is built and sent\r
147 @retval Others Failed to transmit the packet.\r
148\r
149**/\r
83cbd279 150EFI_STATUS\r
151Mtftp4SendRequest (\r
152 IN MTFTP4_PROTOCOL *Instance\r
153 );\r
154\r
dab714aa 155/**\r
156 Build then send an error message.\r
157\r
158 @param Instance The MTFTP session\r
159 @param ErrCode The error code \r
160 @param ErrInfo The error message\r
161\r
162 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the error packet\r
163 @retval EFI_SUCCESS The error packet is transmitted.\r
164 @retval Others Failed to transmit the packet.\r
165\r
166**/\r
83cbd279 167EFI_STATUS\r
168Mtftp4SendError (\r
169 IN MTFTP4_PROTOCOL *Instance,\r
170 IN UINT16 ErrCode,\r
dab714aa 171 IN UINT8 *ErrInfo\r
83cbd279 172 );\r
173\r
dab714aa 174/**\r
175 Retransmit the last packet for the instance.\r
176\r
177 @param Instance The Mtftp instance\r
178\r
179 @retval EFI_SUCCESS The last packet is retransmitted.\r
180 @retval Others Failed to retransmit.\r
181\r
182**/\r
83cbd279 183EFI_STATUS\r
184Mtftp4Retransmit (\r
185 IN MTFTP4_PROTOCOL *Instance\r
186 );\r
187\r
dab714aa 188/**\r
189 The timer ticking function for the Mtftp service instance.\r
190\r
191 @param Event The ticking event\r
192 @param Context The Mtftp service instance\r
193\r
194**/\r
83cbd279 195VOID\r
196EFIAPI\r
197Mtftp4OnTimerTick (\r
198 IN EFI_EVENT Event,\r
199 IN VOID *Context\r
200 );\r
201#endif\r