]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Mtftp6Dxe/Mtftp6Impl.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / Mtftp6Dxe / Mtftp6Impl.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 This EFI_MTFTP6_PROTOCOL interface implementation.\r
3\r
4 It supports the following RFCs:\r
5 RFC1350 - THE TFTP PROTOCOL (REVISION 2)\r
6 RFC2090 - TFTP Multicast Option\r
7 RFC2347 - TFTP Option Extension\r
8 RFC2348 - TFTP Blocksize Option\r
9 RFC2349 - TFTP Timeout Interval and Transfer Size Options\r
10\r
75dce340 11 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
a3bcde70 12\r
ecf98fbc 13 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a3bcde70
HT
14\r
15**/\r
16\r
17#include "Mtftp6Impl.h"\r
18\r
d1050b9d 19EFI_MTFTP6_PROTOCOL gMtftp6ProtocolTemplate = {\r
a3bcde70
HT
20 EfiMtftp6GetModeData,\r
21 EfiMtftp6Configure,\r
22 EfiMtftp6GetInfo,\r
23 EfiMtftp6ParseOptions,\r
24 EfiMtftp6ReadFile,\r
25 EfiMtftp6WriteFile,\r
26 EfiMtftp6ReadDirectory,\r
27 EfiMtftp6Poll\r
d1050b9d 28};\r
a3bcde70
HT
29\r
30/**\r
31 Returns the current operating mode data for the MTFTP6 instance.\r
32\r
33 The GetModeData() function returns the current operating mode and\r
34 cached data packet for the MTFTP6 instance.\r
35\r
36 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.\r
37 @param[out] ModeData The buffer in which the EFI MTFTPv6 Protocol driver mode\r
38 data is returned.\r
39\r
40 @retval EFI_SUCCESS The configuration data was returned successfully.\r
41 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.\r
42 @retval EFI_INVALID_PARAMETER This is NULL or ModeData is NULL.\r
43\r
44**/\r
45EFI_STATUS\r
46EFIAPI\r
47EfiMtftp6GetModeData (\r
d1050b9d
MK
48 IN EFI_MTFTP6_PROTOCOL *This,\r
49 OUT EFI_MTFTP6_MODE_DATA *ModeData\r
a3bcde70
HT
50 )\r
51{\r
52 MTFTP6_INSTANCE *Instance;\r
53 EFI_TPL OldTpl;\r
54\r
d1050b9d 55 if ((This == NULL) || (ModeData == NULL)) {\r
a3bcde70
HT
56 return EFI_INVALID_PARAMETER;\r
57 }\r
58\r
59 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
60 Instance = MTFTP6_INSTANCE_FROM_THIS (This);\r
61\r
62 //\r
63 // Copy back the configure data if the instance already configured.\r
64 //\r
65 if (Instance->Config != NULL) {\r
66 CopyMem (\r
67 &ModeData->ConfigData,\r
68 Instance->Config,\r
69 sizeof (EFI_MTFTP6_CONFIG_DATA)\r
70 );\r
71 } else {\r
72 ZeroMem (\r
73 &ModeData->ConfigData,\r
74 sizeof (EFI_MTFTP6_CONFIG_DATA)\r
75 );\r
76 }\r
77\r
78 //\r
79 // Set the current support options in mode data.\r
80 //\r
81 ModeData->SupportedOptionCount = MTFTP6_SUPPORTED_OPTIONS_NUM;\r
d1050b9d 82 ModeData->SupportedOptions = (UINT8 **)mMtftp6SupportedOptions;\r
a3bcde70
HT
83\r
84 gBS->RestoreTPL (OldTpl);\r
85\r
86 return EFI_SUCCESS;\r
87}\r
88\r
a3bcde70
HT
89/**\r
90 Initializes, changes, or resets the default operational setting for\r
91 this EFI MTFTPv6 Protocol driver instance.\r
92\r
93 The Configure() function is used to set and change the configuration\r
94 data for this EFI MTFTPv6 Protocol driver instance. The configuration\r
95 data can be reset to startup defaults by calling Configure() with\r
96 MtftpConfigData set to NULL. Whenever the instance is reset, any\r
97 pending operation is aborted. By changing the EFI MTFTPv6 Protocol\r
98 driver instance configuration data, the client can connect to\r
99 different MTFTPv6 servers. The configuration parameters in\r
100 MtftpConfigData are used as the default parameters in later MTFTPv6\r
101 operations and can be overridden in later operations.\r
102\r
103 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.\r
104 @param[in] MtftpConfigData Pointer to the configuration data structure.\r
105\r
106 @retval EFI_SUCCESS The EFI MTFTPv6 Protocol instance was configured successfully.\r
107 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:\r
108 - This is NULL.\r
109 - MtftpConfigData.StationIp is neither zero nor one\r
110 of the configured IP addresses in the underlying IPv6 driver.\r
f6c8bbbe 111 - MtftpConfigData.ServerIp is not a valid IPv6 unicast address.\r
a3bcde70
HT
112 Note: It does not match the UEFI 2.3 Specification.\r
113 @retval EFI_ACCESS_DENIED - The configuration could not be changed at this time because there\r
114 is some MTFTP background operation in progress.\r
f6c8bbbe 115 - MtftpConfigData.LocalPort is already in use.\r
a3bcde70
HT
116 Note: It does not match the UEFI 2.3 Specification.\r
117 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source\r
118 address for this instance, but no source address was available for use.\r
119 @retval EFI_OUT_OF_RESOURCES The EFI MTFTPv6 Protocol driver instance data could not be\r
120 allocated.\r
121 Note: It is not defined in the UEFI 2.3 Specification.\r
122 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI\r
123 MTFTPv6 Protocol driver instance is not configured.\r
124 Note: It is not defined in the UEFI 2.3 Specification.\r
125\r
126**/\r
127EFI_STATUS\r
128EFIAPI\r
129EfiMtftp6Configure (\r
d1050b9d
MK
130 IN EFI_MTFTP6_PROTOCOL *This,\r
131 IN EFI_MTFTP6_CONFIG_DATA *MtftpConfigData OPTIONAL\r
a3bcde70
HT
132 )\r
133{\r
d1050b9d
MK
134 MTFTP6_SERVICE *Service;\r
135 MTFTP6_INSTANCE *Instance;\r
136 EFI_UDP6_PROTOCOL *Udp6;\r
137 EFI_UDP6_CONFIG_DATA Udp6Cfg;\r
138 EFI_STATUS Status;\r
139 EFI_TPL OldTpl;\r
a3bcde70
HT
140\r
141 if (This == NULL) {\r
142 return EFI_INVALID_PARAMETER;\r
143 }\r
144\r
d1050b9d 145 if ((MtftpConfigData != NULL) && !NetIp6IsValidUnicast (&MtftpConfigData->ServerIp)) {\r
a3bcde70
HT
146 return EFI_INVALID_PARAMETER;\r
147 }\r
148\r
149 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
150 Instance = MTFTP6_INSTANCE_FROM_THIS (This);\r
151 Service = Instance->Service;\r
152 Status = EFI_SUCCESS;\r
153\r
154 if (MtftpConfigData == NULL) {\r
155 //\r
156 // Configure the instance as NULL to abort the current session.\r
157 //\r
158 Mtftp6OperationClean (Instance, EFI_ABORTED);\r
159 FreePool (Instance->Config);\r
160 Instance->Config = NULL;\r
161 } else {\r
162 //\r
163 // It's not allowed to configure one instance twice without configure null.\r
164 //\r
165 if (Instance->Config != NULL) {\r
166 Status = EFI_ACCESS_DENIED;\r
167 goto ON_EXIT;\r
168 }\r
d1050b9d 169\r
a3bcde70
HT
170 //\r
171 // Allocate the configure buffer of the instance and store the user's data.\r
172 //\r
173 Instance->Config = AllocateZeroPool (sizeof (EFI_MTFTP6_CONFIG_DATA));\r
174\r
175 if (Instance->Config == NULL) {\r
176 Status = EFI_OUT_OF_RESOURCES;\r
177 goto ON_EXIT;\r
178 }\r
179\r
180 CopyMem (Instance->Config, MtftpConfigData, sizeof (EFI_MTFTP6_CONFIG_DATA));\r
181\r
182 //\r
183 // Don't configure the udpio here because each operation might override\r
184 // the configuration, so delay udpio configuration in each operation.\r
185 //\r
75dce340 186 if (Instance->UdpIo == NULL) {\r
187 Instance->UdpIo = UdpIoCreateIo (\r
188 Service->Controller,\r
189 Service->Image,\r
190 Mtftp6ConfigDummyUdpIo,\r
191 UDP_IO_UDP6_VERSION,\r
192 NULL\r
193 );\r
216f7970 194 if (Instance->UdpIo != NULL) {\r
195 Status = gBS->OpenProtocol (\r
196 Instance->UdpIo->UdpHandle,\r
197 &gEfiUdp6ProtocolGuid,\r
d1050b9d 198 (VOID **)&Udp6,\r
216f7970 199 Service->Image,\r
200 Instance->Handle,\r
201 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
202 );\r
203 if (EFI_ERROR (Status)) {\r
204 goto ON_EXIT;\r
205 }\r
206 }\r
75dce340 207 }\r
a3bcde70
HT
208\r
209 if (Instance->UdpIo == NULL) {\r
210 Status = EFI_OUT_OF_RESOURCES;\r
211 goto ON_EXIT;\r
212 }\r
213\r
214 //\r
215 // Continue to configure the downside Udp6 instance by user's data.\r
216 //\r
217 ZeroMem (&Udp6Cfg, sizeof (EFI_UDP6_CONFIG_DATA));\r
218\r
219 Udp6Cfg.AcceptPromiscuous = FALSE;\r
220 Udp6Cfg.AcceptAnyPort = FALSE;\r
221 Udp6Cfg.AllowDuplicatePort = FALSE;\r
222 Udp6Cfg.TrafficClass = 0;\r
223 Udp6Cfg.HopLimit = 128;\r
224 Udp6Cfg.ReceiveTimeout = 0;\r
225 Udp6Cfg.TransmitTimeout = 0;\r
226 Udp6Cfg.StationPort = Instance->Config->LocalPort;\r
227 Udp6Cfg.RemotePort = Instance->Config->InitialServerPort;\r
228\r
229 CopyMem (\r
230 &Udp6Cfg.StationAddress,\r
231 &Instance->Config->StationIp,\r
d1050b9d 232 sizeof (EFI_IPv6_ADDRESS)\r
a3bcde70
HT
233 );\r
234\r
235 CopyMem (\r
236 &Udp6Cfg.RemoteAddress,\r
237 &Instance->Config->ServerIp,\r
238 sizeof (EFI_IPv6_ADDRESS)\r
239 );\r
240\r
241 Udp6 = Instance->UdpIo->Protocol.Udp6;\r
242 Status = Udp6->Configure (Udp6, &Udp6Cfg);\r
243\r
244 if (EFI_ERROR (Status)) {\r
245 goto ON_EXIT;\r
246 }\r
247 }\r
248\r
249ON_EXIT:\r
250 if (EFI_ERROR (Status)) {\r
251 if (Instance->Config != NULL) {\r
252 FreePool (Instance->Config);\r
253 Instance->Config = NULL;\r
254 }\r
d1050b9d 255\r
a3bcde70
HT
256 if (Instance->UdpIo != NULL) {\r
257 UdpIoFreeIo (Instance->UdpIo);\r
258 Instance->UdpIo = NULL;\r
259 }\r
260 }\r
d1050b9d 261\r
a3bcde70
HT
262 gBS->RestoreTPL (OldTpl);\r
263 return Status;\r
264}\r
265\r
a3bcde70
HT
266/**\r
267 Get the information of the download from the server.\r
268\r
269 The GetInfo() function assembles an MTFTPv6 request packet\r
270 with options, sends it to the MTFTPv6 server, and may return\r
271 an MTFTPv6 OACK, MTFTPv6 ERROR, or ICMP ERROR packet. Retries\r
272 occur only if no response packets are received from the MTFTPv6\r
273 server before the timeout expires.\r
274\r
275 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.\r
276 @param[in] OverrideData Data that is used to override the existing parameters. If NULL, the\r
277 default parameters that were set in the EFI_MTFTP6_PROTOCOL.Configure()\r
278 function are used.\r
4f077902
SZ
279 @param[in] Filename Pointer to null-terminated ASCII file name string.\r
280 @param[in] ModeStr Pointer to null-terminated ASCII mode string. If NULL, octet will be used.\r
a3bcde70
HT
281 @param[in] OptionCount Number of option/value string pairs in OptionList.\r
282 @param[in] OptionList Pointer to array of option/value string pairs. Ignored if\r
283 OptionCount is zero.\r
284 @param[out] PacketLength The number of bytes in the returned packet.\r
285 @param[out] Packet The pointer to the received packet. This buffer must be freed by\r
286 the caller.\r
287\r
288 @retval EFI_SUCCESS An MTFTPv6 OACK packet was received and is in the Packet.\r
289 Note: It does not match the UEFI 2.3 Specification.\r
290 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
291 - This is NULL.\r
292 - Filename is NULL.\r
293 - OptionCount is not zero and OptionList is NULL.\r
294 - One or more options in OptionList have wrong format.\r
295 - PacketLength is NULL.\r
296 - OverrideData.ServerIp is not valid unicast IPv6 addresses.\r
297 @retval EFI_UNSUPPORTED One or more options in the OptionList are unsupported by\r
298 this implementation.\r
299 @retval EFI_NOT_STARTED The EFI MTFTPv6 Protocol driver has not been started.\r
300 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source\r
301 address for this instance, but no source address was available for use.\r
302 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.\r
303 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r
304 @retval EFI_TFTP_ERROR An MTFTPv6 ERROR packet was received and is in the Packet.\r
305 @retval EFI_NETWORK_UNREACHABLE An ICMP network unreachable error packet was received and the Packet is set to NULL.\r
306 Note: It is not defined in UEFI 2.3 Specification.\r
307 @retval EFI_HOST_UNREACHABLE An ICMP host unreachable error packet was received and the Packet is set to NULL.\r
308 Note: It is not defined in the UEFI 2.3 Specification.\r
309 @retval EFI_PROTOCOL_UNREACHABLE An ICMP protocol unreachable error packet was received and the Packet is set to NULL.\r
310 Note: It is not defined in the UEFI 2.3 Specification.\r
311 @retval EFI_PORT_UNREACHABLE An ICMP port unreachable error packet was received and the Packet is set to NULL.\r
312 @retval EFI_ICMP_ERROR Some other ICMP ERROR packet was received and the Packet is set to NULL.\r
313 Note: It does not match the UEFI 2.3 Specification.\r
314 @retval EFI_PROTOCOL_ERROR An unexpected MTFTPv6 packet was received and is in the Packet.\r
315 @retval EFI_TIMEOUT No responses were received from the MTFTPv6 server.\r
316 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.\r
317 @retval EFI_NO_MEDIA There was a media error.\r
318\r
319**/\r
320EFI_STATUS\r
321EFIAPI\r
322EfiMtftp6GetInfo (\r
d1050b9d
MK
323 IN EFI_MTFTP6_PROTOCOL *This,\r
324 IN EFI_MTFTP6_OVERRIDE_DATA *OverrideData OPTIONAL,\r
325 IN UINT8 *Filename,\r
326 IN UINT8 *ModeStr OPTIONAL,\r
327 IN UINT8 OptionCount,\r
328 IN EFI_MTFTP6_OPTION *OptionList OPTIONAL,\r
329 OUT UINT32 *PacketLength,\r
330 OUT EFI_MTFTP6_PACKET **Packet OPTIONAL\r
a3bcde70
HT
331 )\r
332{\r
d1050b9d
MK
333 EFI_STATUS Status;\r
334 EFI_MTFTP6_TOKEN Token;\r
335 MTFTP6_GETINFO_CONTEXT Context;\r
336\r
337 if ((This == NULL) ||\r
338 (Filename == NULL) ||\r
339 (PacketLength == NULL) ||\r
340 ((OptionCount != 0) && (OptionList == NULL)) ||\r
341 ((OverrideData != NULL) && !NetIp6IsValidUnicast (&OverrideData->ServerIp))\r
342 )\r
343 {\r
a3bcde70
HT
344 return EFI_INVALID_PARAMETER;\r
345 }\r
346\r
347 if (Packet != NULL) {\r
348 *Packet = NULL;\r
349 }\r
350\r
d1050b9d 351 *PacketLength = 0;\r
a3bcde70 352\r
d1050b9d
MK
353 Context.Packet = Packet;\r
354 Context.PacketLen = PacketLength;\r
355 Context.Status = EFI_SUCCESS;\r
a3bcde70
HT
356\r
357 //\r
358 // Fill fields of the Token for GetInfo operation.\r
359 //\r
360 Token.Status = EFI_SUCCESS;\r
361 Token.Event = NULL;\r
362 Token.OverrideData = OverrideData;\r
363 Token.Filename = Filename;\r
364 Token.ModeStr = ModeStr;\r
365 Token.OptionCount = OptionCount;\r
366 Token.OptionList = OptionList;\r
367 Token.BufferSize = 0;\r
368 Token.Buffer = NULL;\r
369 Token.Context = &Context;\r
370 Token.CheckPacket = Mtftp6CheckPacket;\r
371 Token.TimeoutCallback = NULL;\r
372 Token.PacketNeeded = NULL;\r
373\r
374 //\r
375 // Start the GetInfo operation by issue the Token.\r
376 //\r
377 Status = Mtftp6OperationStart (This, &Token, EFI_MTFTP6_OPCODE_RRQ);\r
378\r
379 if (Status == EFI_ABORTED) {\r
380 //\r
381 // Return the status if failed to issue.\r
382 //\r
383 return Context.Status;\r
384 }\r
385\r
386 return Status;\r
387}\r
388\r
a3bcde70
HT
389/**\r
390 Parse the options in an MTFTPv6 OACK packet.\r
391\r
392 The ParseOptions() function parses the option fields in an MTFTPv6 OACK\r
393 packet and returns the number of options that were found, and optionally,\r
394 a list of pointers to the options in the packet. If one or more of the\r
395 option fields are not valid, then EFI_PROTOCOL_ERROR is returned and\r
396 *OptionCount and *OptionList stop at the last valid option.\r
397\r
398 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.\r
399 @param[in] PacketLen Length of the OACK packet to be parsed.\r
400 @param[in] Packet Pointer to the OACK packet to be parsed.\r
401 @param[out] OptionCount Pointer to the number of options in the following OptionList.\r
402 @param[out] OptionList Pointer to EFI_MTFTP6_OPTION storage. Each pointer in the\r
403 OptionList points to the corresponding MTFTP option buffer\r
404 in the Packet. Call the EFI Boot Service FreePool() to\r
405 release the OptionList if the options in this OptionList\r
406 are not needed anymore.\r
407\r
408 @retval EFI_SUCCESS The OACK packet was valid and the OptionCount and\r
409 OptionList parameters have been updated.\r
410 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
411 - PacketLen is 0.\r
412 - Packet is NULL or Packet is not a valid MTFTPv6 packet.\r
413 - OptionCount is NULL.\r
414 @retval EFI_NOT_FOUND No options were found in the OACK packet.\r
415 @retval EFI_OUT_OF_RESOURCES Storage for the OptionList array can not be allocated.\r
416 @retval EFI_PROTOCOL_ERROR One or more of the option fields is invalid.\r
417\r
418**/\r
419EFI_STATUS\r
420EFIAPI\r
421EfiMtftp6ParseOptions (\r
d1050b9d
MK
422 IN EFI_MTFTP6_PROTOCOL *This,\r
423 IN UINT32 PacketLen,\r
424 IN EFI_MTFTP6_PACKET *Packet,\r
425 OUT UINT32 *OptionCount,\r
426 OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL\r
a3bcde70
HT
427 )\r
428{\r
429 if (This == NULL) {\r
430 return EFI_INVALID_PARAMETER;\r
431 }\r
432\r
433 return Mtftp6ParseStart (Packet, PacketLen, OptionCount, OptionList);\r
434}\r
435\r
a3bcde70
HT
436/**\r
437 Download a file from an MTFTPv6 server.\r
438\r
439 The ReadFile() function is used to initialize and start an MTFTPv6 download\r
440 process, and optionally, wait for completion. When the download operation\r
441 completes, whether successfully or not, the Token.Status field is updated\r
442 by the EFI MTFTPv6 Protocol driver, and then Token.Event is signaled if it\r
443 is not NULL.\r
444 Data can be downloaded from the MTFTPv6 server into either of the following\r
445 locations:\r
446 - A fixed buffer that is pointed to by Token.Buffer\r
447 - A download service function that is pointed to by Token.CheckPacket.\r
448 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket\r
449 will be called first. If the call is successful, the packet will be stored\r
450 in Token.Buffer.\r
451\r
452 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.\r
453 @param[in] Token Pointer to the token structure to provide the parameters that are\r
454 used in this operation.\r
455\r
456 @retval EFI_SUCCESS The data file has been transferred successfully.\r
457 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r
458 @retval EFI_BUFFER_TOO_SMALL BufferSize is not zero but not large enough to hold the\r
459 downloaded data in downloading process.\r
460 Note: It does not match the UEFI 2.3 Specification.\r
461 @retval EFI_ABORTED Current operation is aborted by user.\r
462 @retval EFI_NETWORK_UNREACHABLE An ICMP network unreachable error packet was received.\r
463 Note: It is not defined in the UEFI 2.3 Specification.\r
464 @retval EFI_HOST_UNREACHABLE An ICMP host unreachable error packet was received.\r
465 Note: It is not defined in the UEFI 2.3 Specification.\r
466 @retval EFI_PROTOCOL_UNREACHABLE An ICMP protocol unreachable error packet was received.\r
467 Note: It is not defined in the UEFI 2.3 Specification.\r
468 @retval EFI_PORT_UNREACHABLE An ICMP port unreachable error packet was received.\r
469 Note: It is not defined in the UEFI 2.3 Specification.\r
470 @retval EFI_ICMP_ERROR An ICMP ERROR packet was received.\r
471 @retval EFI_TIMEOUT No responses were received from the MTFTPv6 server.\r
472 @retval EFI_TFTP_ERROR An MTFTPv6 ERROR packet was received.\r
473 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.\r
474 @retval EFI_NO_MEDIA There was a media error.\r
475\r
476**/\r
477EFI_STATUS\r
478EFIAPI\r
479EfiMtftp6ReadFile (\r
d1050b9d
MK
480 IN EFI_MTFTP6_PROTOCOL *This,\r
481 IN EFI_MTFTP6_TOKEN *Token\r
a3bcde70
HT
482 )\r
483{\r
484 return Mtftp6OperationStart (This, Token, EFI_MTFTP6_OPCODE_RRQ);\r
485}\r
486\r
a3bcde70
HT
487/**\r
488 Send a file to an MTFTPv6 server.\r
489\r
490 The WriteFile() function is used to initialize an uploading operation\r
491 with the given option list and optionally wait for completion. If one\r
492 or more of the options is not supported by the server, the unsupported\r
493 options are ignored and a standard TFTP process starts instead. When\r
494 the upload process completes, whether successfully or not, Token.Event\r
495 is signaled, and the EFI MTFTPv6 Protocol driver updates Token.Status.\r
496 The caller can supply the data to be uploaded in the following two modes:\r
497 - Through the user-provided buffer\r
498 - Through a callback function\r
499 With the user-provided buffer, the Token.BufferSize field indicates\r
500 the length of the buffer, and the driver will upload the data in the\r
501 buffer. With an EFI_MTFTP6_PACKET_NEEDED callback function, the driver\r
502 will call this callback function to get more data from the user to upload.\r
503\r
504 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.\r
505 @param[in] Token Pointer to the token structure to provide the parameters that are\r
506 used in this operation.\r
507\r
508 @retval EFI_SUCCESS The upload session has started.\r
509 @retval EFI_UNSUPPORTED The operation is not supported by this implementation.\r
510 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
511 - This is NULL.\r
512 - Token is NULL.\r
513 - Token.Filename is NULL.\r
514 - Token.OptionCount is not zero and Token.OptionList is NULL.\r
515 - One or more options in Token.OptionList have wrong format.\r
516 - Token.Buffer and Token.PacketNeeded are both NULL.\r
517 - Token.OverrideData.ServerIp is not a valid unicast IPv6 address.\r
518 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are not\r
519 supported by this implementation.\r
520 @retval EFI_NOT_STARTED The EFI MTFTPv6 Protocol driver has not been started.\r
521 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source\r
522 address for this instance, but no source address was available for use.\r
523 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv6 session.\r
524 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r
525 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.\r
526 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.\r
527\r
528**/\r
529EFI_STATUS\r
530EFIAPI\r
531EfiMtftp6WriteFile (\r
d1050b9d
MK
532 IN EFI_MTFTP6_PROTOCOL *This,\r
533 IN EFI_MTFTP6_TOKEN *Token\r
a3bcde70
HT
534 )\r
535{\r
536 return Mtftp6OperationStart (This, Token, EFI_MTFTP6_OPCODE_WRQ);\r
537}\r
538\r
a3bcde70
HT
539/**\r
540 Download a data file directory from an MTFTPv6 server.\r
541\r
542 The ReadDirectory() function is used to return a list of files on the\r
543 MTFTPv6 server that are logically (or operationally) related to\r
544 Token.Filename. The directory request packet that is sent to the server\r
545 is built with the option list that was provided by the caller, if present.\r
546 The file information that the server returns is put into either of\r
547 the following locations:\r
548 - A fixed buffer that is pointed to by Token.Buffer.\r
549 - A download service function that is pointed to by Token.CheckPacket.\r
550 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket\r
551 will be called first. If the call is successful, the packet will be stored\r
552 in Token.Buffer.\r
553\r
554 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.\r
555 @param[in] Token Pointer to the token structure to provide the parameters that are\r
556 used in this operation.\r
557\r
558 @retval EFI_SUCCESS The MTFTPv6 related file "directory" has been downloaded.\r
559 @retval EFI_UNSUPPORTED The EFI MTFTPv6 Protocol driver does not support this function.\r
560 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
561 - This is NULL.\r
562 - Token is NULL.\r
563 - Token.Filename is NULL.\r
564 - Token.OptionCount is not zero and Token.OptionList is NULL.\r
565 - One or more options in Token.OptionList have wrong format.\r
566 - Token.Buffer and Token.CheckPacket are both NULL.\r
567 - Token.OverrideData.ServerIp is not valid unicast IPv6 addresses.\r
568 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are not\r
569 supported by this implementation.\r
570 @retval EFI_NOT_STARTED The EFI MTFTPv6 Protocol driver has not been started.\r
571 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source\r
572 address for this instance, but no source address was available for use.\r
573 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv6 session.\r
574 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r
575 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.\r
576 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.\r
577\r
578**/\r
579EFI_STATUS\r
580EFIAPI\r
581EfiMtftp6ReadDirectory (\r
d1050b9d
MK
582 IN EFI_MTFTP6_PROTOCOL *This,\r
583 IN EFI_MTFTP6_TOKEN *Token\r
a3bcde70
HT
584 )\r
585{\r
586 return Mtftp6OperationStart (This, Token, EFI_MTFTP6_OPCODE_DIR);\r
587}\r
588\r
a3bcde70
HT
589/**\r
590 Polls for incoming data packets and processes outgoing data packets.\r
591\r
592 The Poll() function can be used by network drivers and applications\r
593 to increase the rate that data packets are moved between the\r
594 communications device and the transmit and receive queues. In some\r
595 systems, the periodic timer event in the managed network driver may\r
596 not poll the underlying communications device fast enough to transmit\r
597 and/or receive all data packets without missing incoming packets or\r
598 dropping outgoing packets. Drivers and applications that are\r
599 experiencing packet loss should try calling the Poll() function\r
600 more often.\r
601\r
602 @param[in] This The MTFTP6 protocol instance.\r
603\r
604\r
605 @retval EFI_SUCCESS Incoming or outgoing data was processed.\r
606 @retval EFI_NOT_STARTED This EFI MTFTPv6 Protocol instance has not been started.\r
607 @retval EFI_INVALID_PARAMETER This is NULL.\r
608 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
609 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.\r
610 Consider increasing the polling rate.\r
611\r
612**/\r
613EFI_STATUS\r
614EFIAPI\r
615EfiMtftp6Poll (\r
d1050b9d 616 IN EFI_MTFTP6_PROTOCOL *This\r
a3bcde70
HT
617 )\r
618{\r
d1050b9d
MK
619 MTFTP6_INSTANCE *Instance;\r
620 EFI_UDP6_PROTOCOL *Udp6;\r
a3bcde70
HT
621\r
622 if (This == NULL) {\r
623 return EFI_INVALID_PARAMETER;\r
624 }\r
625\r
626 Instance = MTFTP6_INSTANCE_FROM_THIS (This);\r
627\r
628 //\r
75dce340 629 // Check the instance whether configured or in destroy.\r
a3bcde70
HT
630 //\r
631 if (Instance->Config == NULL) {\r
632 return EFI_NOT_STARTED;\r
a3bcde70
HT
633 }\r
634\r
635 Udp6 = Instance->UdpIo->Protocol.Udp6;\r
636\r
637 return Udp6->Poll (Udp6);\r
638}\r