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