]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Mtftp6Dxe/Mtftp6Support.h
NetworkPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / NetworkPkg / Mtftp6Dxe / Mtftp6Support.h
CommitLineData
a3bcde70
HT
1/** @file\r
2 Mtftp6 support functions declaration.\r
3\r
2f6693c2 4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
a3bcde70 5\r
ecf98fbc 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a3bcde70
HT
7\r
8**/\r
9\r
10#ifndef __EFI_MTFTP6_SUPPORT_H__\r
11#define __EFI_MTFTP6_SUPPORT_H__\r
12\r
13//\r
14// The structure representing a range of block numbers, [Start, End].\r
15// It is used to remember the holes in the MTFTP block space. If all\r
16// the holes are filled in, then the download or upload has completed.\r
17//\r
18typedef struct {\r
19 LIST_ENTRY Link;\r
20 INTN Start;\r
21 INTN End;\r
22 INTN Round;\r
23 INTN Bound;\r
24} MTFTP6_BLOCK_RANGE;\r
25\r
26\r
27/**\r
28 Initialize the block range for either RRQ or WRQ. RRQ and WRQ have\r
29 different requirements for Start and End. For example, during startup,\r
30 WRQ initializes its whole valid block range to [0, 0xffff]. This\r
31 is because the server will send an ACK0 to inform the user to start the\r
32 upload. When the client receives an ACK0, it will remove 0 from the range,\r
33 get the next block number, which is 1, then upload the BLOCK1. For RRQ\r
34 without option negotiation, the server will directly send us the BLOCK1\r
35 in response to the client's RRQ. When BLOCK1 is received, the client will\r
36 remove it from the block range and send an ACK. It also works if there\r
37 is option negotiation.\r
38\r
39 @param[in] Head The block range head to initialize.\r
40 @param[in] Start The Start block number.\r
41 @param[in] End The last block number.\r
42\r
43 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for initial block range.\r
44 @retval EFI_SUCCESS The initial block range is created.\r
45\r
46**/\r
47EFI_STATUS\r
48Mtftp6InitBlockRange (\r
49 IN LIST_ENTRY *Head,\r
50 IN UINT16 Start,\r
51 IN UINT16 End\r
52 );\r
53\r
54\r
55/**\r
56 Get the first valid block number on the range list.\r
57\r
58 @param[in] Head The block range head.\r
59\r
60 @retval ==-1 If the block range is empty.\r
61 @retval >-1 The first valid block number.\r
62\r
63**/\r
64INTN\r
65Mtftp6GetNextBlockNum (\r
66 IN LIST_ENTRY *Head\r
67 );\r
68\r
69\r
70/**\r
71 Set the last block number of the block range list. It\r
72 removes all the blocks after the Last. MTFTP initialize the\r
73 block range to the maximum possible range, such as [0, 0xffff]\r
74 for WRQ. When it gets the last block number, it calls\r
75 this function to set the last block number.\r
76\r
77 @param[in] Head The block range list.\r
78 @param[in] Last The last block number.\r
79\r
80**/\r
81VOID\r
82Mtftp6SetLastBlockNum (\r
83 IN LIST_ENTRY *Head,\r
84 IN UINT16 Last\r
85 );\r
86\r
87\r
88/**\r
89 Remove the block number from the block range list.\r
90\r
91 @param[in] Head The block range list to remove from.\r
92 @param[in] Num The block number to remove.\r
2f6693c2
JW
93 @param[in] Completed Whether Num is the last block number.\r
94 @param[out] BlockCounter The continuous block counter instead of the value after roll-over.\r
a3bcde70
HT
95\r
96 @retval EFI_NOT_FOUND The block number isn't in the block range list.\r
97 @retval EFI_SUCCESS The block number has been removed from the list.\r
98 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.\r
99\r
100**/\r
101EFI_STATUS\r
102Mtftp6RemoveBlockNum (\r
103 IN LIST_ENTRY *Head,\r
104 IN UINT16 Num,\r
105 IN BOOLEAN Completed,\r
2f6693c2 106 OUT UINT64 *BlockCounter\r
a3bcde70
HT
107 );\r
108\r
109\r
110/**\r
111 Build and transmit the request packet for the Mtftp6 instance.\r
112\r
113 @param[in] Instance The pointer to the Mtftp6 instance.\r
114 @param[in] Operation The operation code of this packet.\r
115\r
116 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the request.\r
117 @retval EFI_SUCCESS The request was built and sent.\r
118 @retval Others Failed to transmit the packet.\r
119\r
120**/\r
121EFI_STATUS\r
122Mtftp6SendRequest (\r
123 IN MTFTP6_INSTANCE *Instance,\r
124 IN UINT16 Operation\r
125 );\r
126\r
127\r
128/**\r
129 Build and send an error packet.\r
130\r
131 @param[in] Instance The pointer to the Mtftp6 instance.\r
132 @param[in] ErrCode The error code in the packet.\r
133 @param[in] ErrInfo The error message in the packet.\r
134\r
135 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the error packet.\r
136 @retval EFI_SUCCESS The error packet was transmitted.\r
137 @retval Others Failed to transmit the packet.\r
138\r
139**/\r
140EFI_STATUS\r
141Mtftp6SendError (\r
142 IN MTFTP6_INSTANCE *Instance,\r
143 IN UINT16 ErrCode,\r
144 IN UINT8* ErrInfo\r
145 );\r
146\r
147\r
148/**\r
149 Send the packet for the Mtftp6 instance.\r
150\r
151 @param[in] Instance The pointer to the Mtftp6 instance.\r
152 @param[in] Packet The pointer to the packet to be sent.\r
153\r
154 @retval EFI_SUCCESS The packet was sent out\r
155 @retval Others Failed to transmit the packet.\r
156\r
157**/\r
158EFI_STATUS\r
159Mtftp6TransmitPacket (\r
160 IN MTFTP6_INSTANCE *Instance,\r
161 IN NET_BUF *Packet\r
162 );\r
163\r
164\r
165/**\r
166 Check packet for GetInfo callback routine.\r
167\r
168 @param[in] This The pointer to the Mtftp6 protocol.\r
169 @param[in] Token The pointer to the Mtftp6 token.\r
170 @param[in] PacketLen The length of the packet\r
171 @param[in] Packet The pointer to the received packet.\r
172\r
173 @retval EFI_SUCCESS The check process passed successfully.\r
174 @retval EFI_ABORTED Abort the Mtftp6 operation.\r
175\r
176**/\r
177EFI_STATUS\r
178EFIAPI\r
179Mtftp6CheckPacket (\r
180 IN EFI_MTFTP6_PROTOCOL *This,\r
181 IN EFI_MTFTP6_TOKEN *Token,\r
182 IN UINT16 PacketLen,\r
183 IN EFI_MTFTP6_PACKET *Packet\r
184 );\r
185\r
186\r
187/**\r
188 The dummy configure routine for create a new Udp6 Io.\r
189\r
190 @param[in] UdpIo The pointer to the Udp6 Io.\r
191 @param[in] Context The pointer to the context.\r
192\r
193 @retval EFI_SUCCESS The value is always returned.\r
194\r
195**/\r
196EFI_STATUS\r
197EFIAPI\r
198Mtftp6ConfigDummyUdpIo (\r
199 IN UDP_IO *UdpIo,\r
200 IN VOID *Context\r
201 );\r
202\r
203\r
204/**\r
205 The configure routine for the Mtftp6 instance to transmit/receive.\r
206\r
207 @param[in] UdpIo The pointer to the Udp6 Io.\r
208 @param[in] ServerIp The pointer to the server address.\r
209 @param[in] ServerPort The pointer to the server port.\r
210 @param[in] LocalIp The pointer to the local address.\r
211 @param[in] LocalPort The pointer to the local port.\r
212\r
213 @retval EFI_SUCCESS Configure the Udp6 Io for Mtftp6 successfully.\r
214 @retval EFI_NO_MAPPING The corresponding Ip6 instance has not been\r
215 configured yet.\r
216\r
217**/\r
218EFI_STATUS\r
219Mtftp6ConfigUdpIo (\r
220 IN UDP_IO *UdpIo,\r
221 IN EFI_IPv6_ADDRESS *ServerIp,\r
222 IN UINT16 ServerPort,\r
223 IN EFI_IPv6_ADDRESS *LocalIp,\r
224 IN UINT16 LocalPort\r
225 );\r
226\r
227\r
228/**\r
229 Clean up the current Mtftp6 operation.\r
230\r
231 @param[in] Instance The pointer to the Mtftp6 instance.\r
232 @param[in] Result The result to be returned to the user.\r
233\r
234**/\r
235VOID\r
236Mtftp6OperationClean (\r
237 IN MTFTP6_INSTANCE *Instance,\r
238 IN EFI_STATUS Result\r
239 );\r
240\r
241\r
242/**\r
243 Start the Mtftp6 instance to perform the operation, such as read file,\r
244 write file, and read directory.\r
245\r
246 @param[in] This The MTFTP session\r
247 @param[in] Token The token that encapsulates the user's request.\r
248 @param[in] OpCode The operation to perform.\r
249\r
250 @retval EFI_INVALID_PARAMETER Some of the parameters are invalid.\r
251 @retval EFI_NOT_STARTED The MTFTP session hasn't been configured.\r
252 @retval EFI_ALREADY_STARTED There is pending operation for the session.\r
253 @retval EFI_SUCCESS The operation was successfully started.\r
254\r
255**/\r
256EFI_STATUS\r
257Mtftp6OperationStart (\r
258 IN EFI_MTFTP6_PROTOCOL *This,\r
259 IN EFI_MTFTP6_TOKEN *Token,\r
260 IN UINT16 OpCode\r
261 );\r
262\r
263\r
264/**\r
265 The timer ticking routine for the Mtftp6 instance.\r
266\r
267 @param[in] Event The pointer to the ticking event.\r
268 @param[in] Context The pointer to the context.\r
269\r
270**/\r
271VOID\r
272EFIAPI\r
273Mtftp6OnTimerTick (\r
274 IN EFI_EVENT Event,\r
275 IN VOID *Context\r
276 );\r
277\r
278\r
279/**\r
280 The packet process callback for Mtftp6 upload.\r
281\r
282 @param[in] UdpPacket The pointer to the packet received.\r
283 @param[in] UdpEpt The pointer to the Udp6 access point.\r
284 @param[in] IoStatus The status from the Udp6 instance.\r
285 @param[in] Context The pointer to the context.\r
286\r
287**/\r
288VOID\r
289EFIAPI\r
290Mtftp6WrqInput (\r
291 IN NET_BUF *UdpPacket,\r
292 IN UDP_END_POINT *UdpEpt,\r
293 IN EFI_STATUS IoStatus,\r
294 IN VOID *Context\r
295 );\r
296\r
297\r
298/**\r
299 Start the Mtftp6 instance to upload. It will first init some states,\r
300 then send the WRQ request packet, and start to receive the packet.\r
301\r
302 @param[in] Instance The pointer to the Mtftp6 instance.\r
303 @param[in] Operation The operation code of current packet.\r
304\r
305 @retval EFI_SUCCESS The Mtftp6 was started to upload.\r
306 @retval Others Failed to start to upload.\r
307\r
308**/\r
309EFI_STATUS\r
310Mtftp6WrqStart (\r
311 IN MTFTP6_INSTANCE *Instance,\r
312 IN UINT16 Operation\r
313 );\r
314\r
315\r
316/**\r
317 The packet process callback for Mtftp6 download.\r
318\r
319 @param[in] UdpPacket The pointer to the packet received.\r
320 @param[in] UdpEpt The pointer to the Udp6 access point.\r
321 @param[in] IoStatus The status from Udp6 instance.\r
322 @param[in] Context The pointer to the context.\r
323\r
324**/\r
325VOID\r
326EFIAPI\r
327Mtftp6RrqInput (\r
328 IN NET_BUF *UdpPacket,\r
329 IN UDP_END_POINT *UdpEpt,\r
330 IN EFI_STATUS IoStatus,\r
331 IN VOID *Context\r
332 );\r
333\r
334\r
335/**\r
336 Start the Mtftp6 instance to download. It first initializes some\r
337 of the internal states then builds and sends an RRQ reqeuest packet.\r
338 Finally, it starts receive for the downloading.\r
339\r
340 @param[in] Instance The pointer to the Mtftp6 instance.\r
341 @param[in] Operation The operation code of current packet.\r
342\r
343 @retval EFI_SUCCESS The Mtftp6 was started to download.\r
344 @retval Others Failed to start to download.\r
345\r
346**/\r
347EFI_STATUS\r
348Mtftp6RrqStart (\r
349 IN MTFTP6_INSTANCE *Instance,\r
350 IN UINT16 Operation\r
351 );\r
352\r
353#endif\r