• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   UEFI Multicast Trivial File Transfer Protocol v6 Definition, which is built upon
3   the EFI UDPv6 Protocol and provides basic services for client-side unicast and/or
4   multicast TFTP operations.
5 
6   Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
7   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
8 
9   This program and the accompanying materials
10   are licensed and made available under the terms and conditions of the BSD License
11   which accompanies this distribution.  The full text of the license may be found at
12   http://opensource.org/licenses/bsd-license.php
13 
14   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 
17   @par Revision Reference:
18   This Protocol is introduced in UEFI Specification 2.2
19 
20 **/
21 
22 #ifndef __EFI_MTFTP6_PROTOCOL_H__
23 #define __EFI_MTFTP6_PROTOCOL_H__
24 
25 
26 #define EFI_MTFTP6_SERVICE_BINDING_PROTOCOL_GUID \
27   { \
28     0xd9760ff3, 0x3cca, 0x4267, {0x80, 0xf9, 0x75, 0x27, 0xfa, 0xfa, 0x42, 0x23 } \
29   }
30 
31 #define EFI_MTFTP6_PROTOCOL_GUID \
32   { \
33     0xbf0a78ba, 0xec29, 0x49cf, {0xa1, 0xc9, 0x7a, 0xe5, 0x4e, 0xab, 0x6a, 0x51 } \
34   }
35 
36 typedef struct _EFI_MTFTP6_PROTOCOL EFI_MTFTP6_PROTOCOL;
37 typedef struct _EFI_MTFTP6_TOKEN    EFI_MTFTP6_TOKEN;
38 
39 ///
40 /// MTFTP Packet OpCodes
41 ///@{
42 #define EFI_MTFTP6_OPCODE_RRQ      1 ///< The MTFTPv6 packet is a read request.
43 #define EFI_MTFTP6_OPCODE_WRQ      2 ///< The MTFTPv6 packet is a write request.
44 #define EFI_MTFTP6_OPCODE_DATA     3 ///< The MTFTPv6 packet is a data packet.
45 #define EFI_MTFTP6_OPCODE_ACK      4 ///< The MTFTPv6 packet is an acknowledgement packet.
46 #define EFI_MTFTP6_OPCODE_ERROR    5 ///< The MTFTPv6 packet is an error packet.
47 #define EFI_MTFTP6_OPCODE_OACK     6 ///< The MTFTPv6 packet is an option acknowledgement packet.
48 #define EFI_MTFTP6_OPCODE_DIR      7 ///< The MTFTPv6 packet is a directory query packet.
49 #define EFI_MTFTP6_OPCODE_DATA8    8 ///< The MTFTPv6 packet is a data packet with a big block number.
50 #define EFI_MTFTP6_OPCODE_ACK8     9 ///< The MTFTPv6 packet is an acknowledgement packet with a big block number.
51 ///@}
52 
53 ///
54 /// MTFTP ERROR Packet ErrorCodes
55 ///@{
56 ///
57 /// The error code is not defined. See the error message in the packet (if any) for details.
58 ///
59 #define EFI_MTFTP6_ERRORCODE_NOT_DEFINED           0
60 ///
61 /// The file was not found.
62 ///
63 #define EFI_MTFTP6_ERRORCODE_FILE_NOT_FOUND        1
64 ///
65 /// There was an access violation.
66 ///
67 #define EFI_MTFTP6_ERRORCODE_ACCESS_VIOLATION      2
68 ///
69 /// The disk was full or its allocation was exceeded.
70 ///
71 #define EFI_MTFTP6_ERRORCODE_DISK_FULL             3
72 ///
73 /// The MTFTPv6 operation was illegal.
74 ///
75 #define EFI_MTFTP6_ERRORCODE_ILLEGAL_OPERATION     4
76 ///
77 /// The transfer ID is unknown.
78 ///
79 #define EFI_MTFTP6_ERRORCODE_UNKNOWN_TRANSFER_ID   5
80 ///
81 /// The file already exists.
82 ///
83 #define EFI_MTFTP6_ERRORCODE_FILE_ALREADY_EXISTS   6
84 ///
85 /// There is no such user.
86 ///
87 #define EFI_MTFTP6_ERRORCODE_NO_SUCH_USER          7
88 ///
89 /// The request has been denied due to option negotiation.
90 ///
91 #define EFI_MTFTP6_ERRORCODE_REQUEST_DENIED        8
92 ///@}
93 
94 #pragma pack(1)
95 
96 ///
97 /// EFI_MTFTP6_REQ_HEADER
98 ///
99 typedef struct {
100   ///
101   /// For this packet type, OpCode = EFI_MTFTP6_OPCODE_RRQ for a read request
102   /// or OpCode = EFI_MTFTP6_OPCODE_WRQ for a write request.
103   ///
104   UINT16    OpCode;
105   ///
106   /// The file name to be downloaded or uploaded.
107   ///
108   UINT8     Filename[1];
109 } EFI_MTFTP6_REQ_HEADER;
110 
111 ///
112 /// EFI_MTFTP6_OACK_HEADER
113 ///
114 typedef struct {
115   ///
116   /// For this packet type, OpCode = EFI_MTFTP6_OPCODE_OACK.
117   ///
118   UINT16    OpCode;
119   ///
120   /// The option strings in the option acknowledgement packet.
121   ///
122   UINT8     Data[1];
123 } EFI_MTFTP6_OACK_HEADER;
124 
125 ///
126 /// EFI_MTFTP6_DATA_HEADER
127 ///
128 typedef struct {
129   ///
130   /// For this packet type, OpCode = EFI_MTFTP6_OPCODE_DATA.
131   ///
132   UINT16    OpCode;
133   ///
134   /// Block number of this data packet.
135   ///
136   UINT16    Block;
137   ///
138   /// The content of this data packet.
139   ///
140   UINT8     Data[1];
141 } EFI_MTFTP6_DATA_HEADER;
142 
143 ///
144 /// EFI_MTFTP6_ACK_HEADER
145 ///
146 typedef struct {
147   ///
148   /// For this packet type, OpCode = EFI_MTFTP6_OPCODE_ACK.
149   ///
150   UINT16    OpCode;
151   ///
152   /// The block number of the data packet that is being acknowledged.
153   ///
154   UINT16    Block[1];
155 } EFI_MTFTP6_ACK_HEADER;
156 
157 ///
158 /// EFI_MTFTP6_DATA8_HEADER
159 ///
160 typedef struct {
161   ///
162   /// For this packet type, OpCode = EFI_MTFTP6_OPCODE_DATA8.
163   ///
164   UINT16    OpCode;
165   ///
166   /// The block number of data packet.
167   ///
168   UINT64    Block;
169   ///
170   /// The content of this data packet.
171   ///
172   UINT8     Data[1];
173 } EFI_MTFTP6_DATA8_HEADER;
174 
175 ///
176 /// EFI_MTFTP6_ACK8_HEADER
177 ///
178 typedef struct {
179   ///
180   /// For this packet type, OpCode = EFI_MTFTP6_OPCODE_ACK8.
181   ///
182   UINT16    OpCode;
183   ///
184   /// The block number of the data packet that is being acknowledged.
185   ///
186   UINT64    Block[1];
187 } EFI_MTFTP6_ACK8_HEADER;
188 
189 ///
190 /// EFI_MTFTP6_ERROR_HEADER
191 ///
192 typedef struct {
193   ///
194   /// For this packet type, OpCode = EFI_MTFTP6_OPCODE_ERROR.
195   ///
196   UINT16    OpCode;
197   ///
198   /// The error number as defined by the MTFTPv6 packet error codes.
199   ///
200   UINT16    ErrorCode;
201   ///
202   /// Error message string.
203   ///
204   UINT8     ErrorMessage[1];
205 } EFI_MTFTP6_ERROR_HEADER;
206 
207 ///
208 /// EFI_MTFTP6_PACKET
209 ///
210 typedef union {
211   UINT16                   OpCode; ///< Type of packets as defined by the MTFTPv6 packet opcodes.
212   EFI_MTFTP6_REQ_HEADER    Rrq;    ///< Read request packet header.
213   EFI_MTFTP6_REQ_HEADER    Wrq;    ///< write request packet header.
214   EFI_MTFTP6_OACK_HEADER   Oack;   ///< Option acknowledge packet header.
215   EFI_MTFTP6_DATA_HEADER   Data;   ///< Data packet header.
216   EFI_MTFTP6_ACK_HEADER    Ack;    ///< Acknowledgement packet header.
217   EFI_MTFTP6_DATA8_HEADER  Data8;  ///< Data packet header with big block number.
218   EFI_MTFTP6_ACK8_HEADER   Ack8;   ///< Acknowledgement header with big block number.
219   EFI_MTFTP6_ERROR_HEADER  Error;  ///< Error packet header.
220 } EFI_MTFTP6_PACKET;
221 
222 #pragma pack()
223 
224 ///
225 /// EFI_MTFTP6_CONFIG_DATA
226 ///
227 typedef struct {
228   ///
229   /// The local IP address to use. Set to zero to let the underlying IPv6
230   /// driver choose a source address. If not zero it must be one of the
231   /// configured IP addresses in the underlying IPv6 driver.
232   ///
233   EFI_IPv6_ADDRESS       StationIp;
234   ///
235   /// Local port number. Set to zero to use the automatically assigned port number.
236   ///
237   UINT16                 LocalPort;
238   ///
239   /// The IP address of the MTFTPv6 server.
240   ///
241   EFI_IPv6_ADDRESS       ServerIp;
242   ///
243   /// The initial MTFTPv6 server port number. Request packets are
244   /// sent to this port. This number is almost always 69 and using zero
245   /// defaults to 69.
246   UINT16                 InitialServerPort;
247   ///
248   /// The number of times to transmit MTFTPv6 request packets and wait for a response.
249   ///
250   UINT16                 TryCount;
251   ///
252   /// The number of seconds to wait for a response after sending the MTFTPv6 request packet.
253   ///
254   UINT16                 TimeoutValue;
255 } EFI_MTFTP6_CONFIG_DATA;
256 
257 ///
258 /// EFI_MTFTP6_MODE_DATA
259 ///
260 typedef struct {
261   ///
262   /// The configuration data of this instance.
263   ///
264   EFI_MTFTP6_CONFIG_DATA  ConfigData;
265   ///
266   /// The number of option strings in the following SupportedOptions array.
267   ///
268   UINT8                   SupportedOptionCount;
269   ///
270   /// An array of null-terminated ASCII option strings that are recognized and supported by
271   /// this EFI MTFTPv6 Protocol driver implementation. The buffer is
272   /// read only to the caller and the caller should NOT free the buffer.
273   ///
274   UINT8                   **SupportedOptions;
275 } EFI_MTFTP6_MODE_DATA;
276 
277 ///
278 /// EFI_MTFTP_OVERRIDE_DATA
279 ///
280 typedef struct {
281   ///
282   /// IP address of the MTFTPv6 server. If set to all zero, the value that
283   /// was set by the EFI_MTFTP6_PROTOCOL.Configure() function will be used.
284   ///
285   EFI_IPv6_ADDRESS       ServerIp;
286   ///
287   /// MTFTPv6 server port number. If set to zero, it will use the value
288   /// that was set by the EFI_MTFTP6_PROTOCOL.Configure() function.
289   ///
290   UINT16                 ServerPort;
291   ///
292   /// Number of times to transmit MTFTPv6 request packets and wait
293   /// for a response. If set to zero, the value that was set by
294   /// theEFI_MTFTP6_PROTOCOL.Configure() function will be used.
295   ///
296   UINT16                 TryCount;
297   ///
298   /// Number of seconds to wait for a response after sending the
299   /// MTFTPv6 request packet. If set to zero, the value that was set by
300   /// the EFI_MTFTP6_PROTOCOL.Configure() function will be used.
301   ///
302   UINT16                 TimeoutValue;
303 } EFI_MTFTP6_OVERRIDE_DATA;
304 
305 ///
306 /// EFI_MTFTP6_OPTION
307 ///
308 typedef struct {
309   UINT8                  *OptionStr; ///< Pointer to the null-terminated ASCII MTFTPv6 option string.
310   UINT8                  *ValueStr;  ///< Pointer to the null-terminated ASCII MTFTPv6 value string.
311 } EFI_MTFTP6_OPTION;
312 
313 /**
314   EFI_MTFTP6_TIMEOUT_CALLBACK is a callback function that the caller provides to capture the
315   timeout event in the EFI_MTFTP6_PROTOCOL.ReadFile(), EFI_MTFTP6_PROTOCOL.WriteFile() or
316   EFI_MTFTP6_PROTOCOL.ReadDirectory() functions.
317 
318   Whenever a timeout occurs, the EFI MTFTPv6 Protocol driver will call the EFI_MTFTP6_TIMEOUT_CALLBACK
319   function to notify the caller of the timeout event. Any status code other than EFI_SUCCESS
320   that is returned from this function will abort the current download process.
321 
322   @param[in] This          Pointer to the EFI_MTFTP6_PROTOCOL instance.
323   @param[in] Token         The token that the caller provided in the EFI_MTFTP6_PROTOCOl.ReadFile(),
324                            WriteFile() or ReadDirectory() function.
325   @param[in] PacketLen     Indicates the length of the packet.
326   @param[in] Packet        Pointer to an MTFTPv6 packet.
327 
328   @retval EFI_SUCCESS      Operation success.
329   @retval Others           Aborts session.
330 
331 **/
332 typedef
333 EFI_STATUS
334 (EFIAPI *EFI_MTFTP6_CHECK_PACKET)(
335   IN EFI_MTFTP6_PROTOCOL      *This,
336   IN EFI_MTFTP6_TOKEN         *Token,
337   IN UINT16                   PacketLen,
338   IN EFI_MTFTP6_PACKET        *Packet
339   );
340 
341 /**
342   EFI_MTFTP6_TIMEOUT_CALLBACK is a callback function that the caller provides to capture the
343   timeout event in the EFI_MTFTP6_PROTOCOL.ReadFile(), EFI_MTFTP6_PROTOCOL.WriteFile() or
344   EFI_MTFTP6_PROTOCOL.ReadDirectory() functions.
345 
346   Whenever a timeout occurs, the EFI MTFTPv6 Protocol driver will call the EFI_MTFTP6_TIMEOUT_CALLBACK
347   function to notify the caller of the timeout event. Any status code other than EFI_SUCCESS
348   that is returned from this function will abort the current download process.
349 
350   @param[in]      This     Pointer to the EFI_MTFTP6_PROTOCOL instance.
351   @param[in]      Token    The token that is provided in the EFI_MTFTP6_PROTOCOL.ReadFile() or
352                            EFI_MTFTP6_PROTOCOL.WriteFile() or EFI_MTFTP6_PROTOCOL.ReadDirectory()
353                            functions by the caller.
354 
355   @retval EFI_SUCCESS      Operation success.
356   @retval Others           Aborts session.
357 
358 **/
359 typedef
360 EFI_STATUS
361 (EFIAPI *EFI_MTFTP6_TIMEOUT_CALLBACK)(
362   IN EFI_MTFTP6_PROTOCOL      *This,
363   IN EFI_MTFTP6_TOKEN         *Token
364   );
365 
366 /**
367   EFI_MTFTP6_PACKET_NEEDED is a callback function that the caller provides to feed data to the
368   EFI_MTFTP6_PROTOCOL.WriteFile() function.
369 
370   EFI_MTFTP6_PACKET_NEEDED provides another mechanism for the caller to provide data to upload
371   other than a static buffer. The EFI MTFTP6 Protocol driver always calls EFI_MTFTP6_PACKET_NEEDED
372   to get packet data from the caller if no static buffer was given in the initial call to
373   EFI_MTFTP6_PROTOCOL.WriteFile() function. Setting *Length to zero signals the end of the session.
374   Returning a status code other than EFI_SUCCESS aborts the session.
375 
376   @param[in]      This     Pointer to the EFI_MTFTP6_PROTOCOL instance.
377   @param[in]      Token    The token provided in the EFI_MTFTP6_PROTOCOL.WriteFile() by the caller.
378   @param[in, out] Length   Indicates the length of the raw data wanted on input, and the
379                            length the data available on output.
380   @param[out]     Buffer   Pointer to the buffer where the data is stored.
381 
382   @retval EFI_SUCCESS      Operation success.
383   @retval Others           Aborts session.
384 
385 **/
386 typedef
387 EFI_STATUS
388 (EFIAPI *EFI_MTFTP6_PACKET_NEEDED)(
389   IN EFI_MTFTP6_PROTOCOL      *This,
390   IN EFI_MTFTP6_TOKEN         *Token,
391   IN OUT UINT16               *Length,
392   OUT VOID                    **Buffer
393   );
394 
395 struct _EFI_MTFTP6_TOKEN {
396   ///
397   /// The status that is returned to the caller at the end of the operation
398   /// to indicate whether this operation completed successfully.
399   /// Defined Status values are listed below.
400   ///
401   EFI_STATUS                  Status;
402   ///
403   /// The event that will be signaled when the operation completes. If
404   /// set to NULL, the corresponding function will wait until the read or
405   /// write operation finishes. The type of Event must be EVT_NOTIFY_SIGNAL.
406   ///
407   EFI_EVENT                   Event;
408   ///
409   /// If not NULL, the data that will be used to override the existing
410   /// configure data.
411   ///
412   EFI_MTFTP6_OVERRIDE_DATA    *OverrideData;
413   ///
414   /// Pointer to the null-terminated ASCII file name string.
415   ///
416   UINT8                       *Filename;
417   ///
418   /// Pointer to the null-terminated ASCII mode string. If NULL, octet is used.
419   ///
420   UINT8                       *ModeStr;
421   ///
422   /// Number of option/value string pairs.
423   ///
424   UINT32                      OptionCount;
425   ///
426   /// Pointer to an array of option/value string pairs. Ignored if
427   /// OptionCount is zero. Both a remote server and this driver
428   /// implementation should support these options. If one or more
429   /// options are unrecognized by this implementation, it is sent to the
430   /// remote server without being changed.
431   ///
432   EFI_MTFTP6_OPTION           *OptionList;
433   ///
434   /// On input, the size, in bytes, of Buffer. On output, the number
435   /// of bytes transferred.
436   ///
437   UINT64                      BufferSize;
438   ///
439   /// Pointer to the data buffer. Data that is downloaded from the
440   /// MTFTPv6 server is stored here. Data that is uploaded to the
441   /// MTFTPv6 server is read from here. Ignored if BufferSize is zero.
442   ///
443   VOID                        *Buffer;
444   ///
445   /// Pointer to the context that will be used by CheckPacket,
446   /// TimeoutCallback and PacketNeeded.
447   ///
448   VOID                        *Context;
449   ///
450   /// Pointer to the callback function to check the contents of the
451   /// received packet.
452   ///
453   EFI_MTFTP6_CHECK_PACKET      CheckPacket;
454   ///
455   /// Pointer to the function to be called when a timeout occurs.
456   ///
457   EFI_MTFTP6_TIMEOUT_CALLBACK  TimeoutCallback;
458   ///
459   /// Pointer to the function to provide the needed packet contents.
460   /// Only used in WriteFile() operation.
461   ///
462   EFI_MTFTP6_PACKET_NEEDED     PacketNeeded;
463 };
464 
465 /**
466   Read the current operational settings.
467 
468   The GetModeData() function reads the current operational settings of this EFI MTFTPv6
469   Protocol driver instance.
470 
471   @param[in]  This               Pointer to the EFI_MTFTP6_PROTOCOL instance.
472   @param[out] ModeData           The buffer in which the EFI MTFTPv6 Protocol driver mode
473                                  data is returned.
474 
475   @retval  EFI_SUCCESS           The configuration data was successfully returned.
476   @retval  EFI_OUT_OF_RESOURCES  The required mode data could not be allocated.
477   @retval  EFI_INVALID_PARAMETER This is NULL or ModeData is NULL.
478 
479 **/
480 typedef
481 EFI_STATUS
482 (EFIAPI *EFI_MTFTP6_GET_MODE_DATA)(
483   IN EFI_MTFTP6_PROTOCOL      *This,
484   OUT EFI_MTFTP6_MODE_DATA    *ModeData
485   );
486 
487 /**
488   Initializes, changes, or resets the default operational setting for this EFI MTFTPv6
489   Protocol driver instance.
490 
491   The Configure() function is used to set and change the configuration data for this EFI
492   MTFTPv6 Protocol driver instance. The configuration data can be reset to startup defaults by calling
493   Configure() with MtftpConfigData set to NULL. Whenever the instance is reset, any
494   pending operation is aborted. By changing the EFI MTFTPv6 Protocol driver instance configuration
495   data, the client can connect to different MTFTPv6 servers. The configuration parameters in
496   MtftpConfigData are used as the default parameters in later MTFTPv6 operations and can be
497   overridden in later operations.
498 
499   @param[in]  This               Pointer to the EFI_MTFTP6_PROTOCOL instance.
500   @param[in]  MtftpConfigData    Pointer to the configuration data structure.
501 
502   @retval  EFI_SUCCESS           The EFI MTFTPv6 Protocol instance was configured successfully.
503   @retval  EFI_INVALID_PARAMETER One or more following conditions are TRUE:
504                                  - This is NULL.
505                                  - MtftpConfigData.StationIp is neither zero nor one
506                                    of the configured IP addresses in the underlying IPv6 driver.
507                                  - MtftpCofigData.ServerIp is not a valid IPv6 unicast address.
508   @retval  EFI_ACCESS_DENIED     - The configuration could not be changed at this time because there
509                                    is some MTFTP background operation in progress.
510                                  - MtftpCofigData.LocalPort is already in use.
511   @retval  EFI_NO_MAPPING        The underlying IPv6 driver was responsible for choosing a source
512                                  address for this instance, but no source address was available for use.
513   @retval  EFI_OUT_OF_RESOURCES  The EFI MTFTPv6 Protocol driver instance data could not be
514                                  allocated.
515   @retval  EFI_DEVICE_ERROR      An unexpected system or network error occurred. The EFI
516                                  MTFTPv6 Protocol driver instance is not configured.
517 
518 
519 **/
520 typedef
521 EFI_STATUS
522 (EFIAPI *EFI_MTFTP6_CONFIGURE)(
523   IN EFI_MTFTP6_PROTOCOL      *This,
524   IN EFI_MTFTP6_CONFIG_DATA   *MtftpConfigData OPTIONAL
525 );
526 
527 /**
528   Get information about a file from an MTFTPv6 server.
529 
530   The GetInfo() function assembles an MTFTPv6 request packet with options, sends it to the
531   MTFTPv6 server, and may return an MTFTPv6 OACK, MTFTPv6 ERROR, or ICMP ERROR packet.
532   Retries occur only if no response packets are received from the MTFTPv6 server before the
533   timeout expires.
534 
535   @param[in]  This               Pointer to the EFI_MTFTP6_PROTOCOL instance.
536   @param[in]  OverrideData       Data that is used to override the existing parameters. If NULL, the
537                                  default parameters that were set in the EFI_MTFTP6_PROTOCOL.Configure()
538                                  function are used.
539   @param[in]  Filename           Pointer to null-terminated ASCII file name string.
540   @param[in]  ModeStr            Pointer to null-terminated ASCII mode string. If NULL, octet will be used
541   @param[in]  OptionCount        Number of option/value string pairs in OptionList.
542   @param[in]  OptionList         Pointer to array of option/value string pairs. Ignored if
543                                  OptionCount is zero.
544   @param[out] PacketLength       The number of bytes in the returned packet.
545   @param[out] Packet             The pointer to the received packet. This buffer must be freed by
546                                  the caller.
547 
548   @retval  EFI_SUCCESS              An MTFTPv6 OACK packet was received and is in the Packet.
549   @retval  EFI_INVALID_PARAMETER    One or more of the following conditions is TRUE:
550                                     - This is NULL.
551                                     - Filename is NULL
552                                     - OptionCount is not zero and OptionList is NULL.
553                                     - One or more options in OptionList have wrong format.
554                                     - PacketLength is NULL.
555                                     - OverrideData.ServerIp is not valid unicast IPv6 addresses.
556   @retval  EFI_UNSUPPORTED          One or more options in the OptionList are unsupported by
557                                     this implementation.
558   @retval  EFI_NOT_STARTED          The EFI MTFTPv6 Protocol driver has not been started.
559   @retval  EFI_NO_MAPPING           The underlying IPv6 driver was responsible for choosing a source
560                                     address for this instance, but no source address was available for use.
561   @retval  EFI_ACCESS_DENIED        The previous operation has not completed yet.
562   @retval  EFI_OUT_OF_RESOURCES     Required system resources could not be allocated.
563   @retval  EFI_TFTP_ERROR           An MTFTPv6 ERROR packet was received and is in the Packet.
564   @retval  EFI_NETWORK_UNREACHABLE  An ICMP network unreachable error packet was received and the Packet is set to NULL.
565   @retval  EFI_HOST_UNREACHABLE     An ICMP host unreachable error packet was received and the Packet is set to NULL.
566   @retval  EFI_PROTOCOL_UNREACHABLE An ICMP protocol unreachable error packet was received and the Packet is set to NULL.
567   @retval  EFI_PORT_UNREACHABLE     An ICMP port unreachable error packet was received and the Packet is set to NULL.
568   @retval  EFI_ICMP_ERROR           Some other ICMP ERROR packet was received and the Packet is set to NULL.
569   @retval  EFI_PROTOCOL_ERROR       An unexpected MTFTPv6 packet was received and is in the Packet.
570   @retval  EFI_TIMEOUT              No responses were received from the MTFTPv6 server.
571   @retval  EFI_DEVICE_ERROR         An unexpected network error or system error occurred.
572   @retval  EFI_NO_MEDIA             There was a media error.
573 
574 **/
575 typedef
576 EFI_STATUS
577 (EFIAPI *EFI_MTFTP6_GET_INFO)(
578   IN EFI_MTFTP6_PROTOCOL      *This,
579   IN EFI_MTFTP6_OVERRIDE_DATA *OverrideData OPTIONAL,
580   IN UINT8                    *Filename,
581   IN UINT8                    *ModeStr OPTIONAL,
582   IN UINT8                    OptionCount,
583   IN EFI_MTFTP6_OPTION        *OptionList OPTIONAL,
584   OUT UINT32                  *PacketLength,
585   OUT EFI_MTFTP6_PACKET       **Packet OPTIONAL
586 );
587 
588 /**
589   Parse the options in an MTFTPv6 OACK packet.
590 
591   The ParseOptions() function parses the option fields in an MTFTPv6 OACK packet and
592   returns the number of options that were found and optionally a list of pointers to
593   the options in the packet.
594   If one or more of the option fields are not valid, then EFI_PROTOCOL_ERROR is returned
595   and *OptionCount and *OptionList stop at the last valid option.
596 
597   @param[in]  This               Pointer to the EFI_MTFTP6_PROTOCOL instance.
598   @param[in]  PacketLen          Length of the OACK packet to be parsed.
599   @param[in]  Packet             Pointer to the OACK packet to be parsed.
600   @param[out] OptionCount        Pointer to the number of options in the following OptionList.
601   @param[out] OptionList         Pointer to EFI_MTFTP6_OPTION storage. Each pointer in the
602                                  OptionList points to the corresponding MTFTP option buffer
603                                  in the Packet. Call the EFI Boot Service FreePool() to
604                                  release the OptionList if the options in this OptionList
605                                  are not needed any more.
606 
607   @retval  EFI_SUCCESS           The OACK packet was valid and the OptionCount and
608                                  OptionList parameters have been updated.
609   @retval  EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
610                                  - PacketLen is 0.
611                                  - Packet is NULL or Packet is not a valid MTFTPv6 packet.
612                                  - OptionCount is NULL.
613   @retval  EFI_NOT_FOUND         No options were found in the OACK packet.
614   @retval  EFI_OUT_OF_RESOURCES  Storage for the OptionList array can not be allocated.
615   @retval  EFI_PROTOCOL_ERROR    One or more of the option fields is invalid.
616 
617 **/
618 typedef
619 EFI_STATUS
620 (EFIAPI *EFI_MTFTP6_PARSE_OPTIONS)(
621   IN EFI_MTFTP6_PROTOCOL      *This,
622   IN UINT32                   PacketLen,
623   IN EFI_MTFTP6_PACKET        *Packet,
624   OUT UINT32                  *OptionCount,
625   OUT EFI_MTFTP6_OPTION       **OptionList OPTIONAL
626   );
627 
628 /**
629   Download a file from an MTFTPv6 server.
630 
631   The ReadFile() function is used to initialize and start an MTFTPv6 download process and
632   optionally wait for completion. When the download operation completes, whether successfully or
633   not, the Token.Status field is updated by the EFI MTFTPv6 Protocol driver and then
634   Token.Event is signaled if it is not NULL.
635 
636   Data can be downloaded from the MTFTPv6 server into either of the following locations:
637   - A fixed buffer that is pointed to by Token.Buffer
638   - A download service function that is pointed to by Token.CheckPacket
639 
640   If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket
641   will be called first. If the call is successful, the packet will be stored in Token.Buffer.
642 
643   @param[in]  This               Pointer to the EFI_MTFTP6_PROTOCOL instance.
644   @param[in]  Token              Pointer to the token structure to provide the parameters that are
645                                  used in this operation.
646 
647   @retval  EFI_SUCCESS              The data file has been transferred successfully.
648   @retval  EFI_OUT_OF_RESOURCES     Required system resources could not be allocated.
649   @retval  EFI_BUFFER_TOO_SMALL     BufferSize is not zero but not large enough to hold the
650                                     downloaded data in downloading process.
651   @retval  EFI_ABORTED              Current operation is aborted by user.
652   @retval  EFI_NETWORK_UNREACHABLE  An ICMP network unreachable error packet was received.
653   @retval  EFI_HOST_UNREACHABLE     An ICMP host unreachable error packet was received.
654   @retval  EFI_PROTOCOL_UNREACHABLE An ICMP protocol unreachable error packet was received.
655   @retval  EFI_PORT_UNREACHABLE     An ICMP port unreachable error packet was received.
656   @retval  EFI_ICMP_ERROR           An ICMP ERROR packet was received.
657   @retval  EFI_TIMEOUT              No responses were received from the MTFTPv6 server.
658   @retval  EFI_TFTP_ERROR           An MTFTPv6 ERROR packet was received.
659   @retval  EFI_DEVICE_ERROR         An unexpected network error or system error occurred.
660   @retval  EFI_NO_MEDIA             There was a media error.
661 
662 **/
663 typedef
664 EFI_STATUS
665 (EFIAPI *EFI_MTFTP6_READ_FILE)(
666   IN EFI_MTFTP6_PROTOCOL      *This,
667   IN EFI_MTFTP6_TOKEN         *Token
668   );
669 
670 /**
671   Send a file to an MTFTPv6 server. May be unsupported in some implementations.
672 
673   The WriteFile() function is used to initialize an uploading operation with the given option list
674   and optionally wait for completion. If one or more of the options is not supported by the server, the
675   unsupported options are ignored and a standard TFTP process starts instead. When the upload
676   process completes, whether successfully or not, Token.Event is signaled, and the EFI MTFTPv6
677   Protocol driver updates Token.Status.
678 
679   The caller can supply the data to be uploaded in the following two modes:
680   - Through the user-provided buffer
681   - Through a callback function
682 
683   With the user-provided buffer, the Token.BufferSize field indicates the length of the buffer,
684   and the driver will upload the data in the buffer. With an EFI_MTFTP6_PACKET_NEEDED
685   callback function, the driver will call this callback function to get more data from the user to upload.
686   See the definition of EFI_MTFTP6_PACKET_NEEDED for more information. These two modes
687   cannot be used at the same time. The callback function will be ignored if the user provides the
688   buffer.
689 
690   @param[in]  This               Pointer to the EFI_MTFTP6_PROTOCOL instance.
691   @param[in]  Token              Pointer to the token structure to provide the parameters that are
692                                  used in this operation.
693 
694   @retval  EFI_SUCCESS           The upload session has started.
695   @retval  EFI_UNSUPPORTED       The operation is not supported by this implementation.
696   @retval  EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
697                                  - This is NULL.
698                                  - Token is NULL.
699                                  - Token.Filename is NULL.
700                                  - Token.OptionCount is not zero and Token.OptionList is NULL.
701                                  - One or more options in Token.OptionList have wrong format.
702                                  - Token.Buffer and Token.PacketNeeded are both NULL.
703                                  - Token.OverrideData.ServerIp is not valid unicast IPv6 addresses.
704   @retval  EFI_UNSUPPORTED       One or more options in the Token.OptionList are not
705                                  supported by this implementation.
706   @retval  EFI_NOT_STARTED       The EFI MTFTPv6 Protocol driver has not been started.
707   @retval  EFI_NO_MAPPING        The underlying IPv6 driver was responsible for choosing a source
708                                  address for this instance, but no source address was available for use.
709   @retval  EFI_ALREADY_STARTED   This Token is already being used in another MTFTPv6 session.
710   @retval  EFI_OUT_OF_RESOURCES  Required system resources could not be allocated.
711   @retval  EFI_ACCESS_DENIED     The previous operation has not completed yet.
712   @retval  EFI_DEVICE_ERROR      An unexpected network error or system error occurred.
713 
714 **/
715 typedef
716 EFI_STATUS
717 (EFIAPI *EFI_MTFTP6_WRITE_FILE)(
718   IN EFI_MTFTP6_PROTOCOL      *This,
719   IN EFI_MTFTP6_TOKEN         *Token
720   );
721 
722 /**
723   Download a data file directory from an MTFTPv6 server. May be unsupported in some implementations.
724 
725   The ReadDirectory() function is used to return a list of files on the MTFTPv6 server that are
726   logically (or operationally) related to Token.Filename. The directory request packet that is sent
727   to the server is built with the option list that was provided by caller, if present.
728 
729   The file information that the server returns is put into either of the following locations:
730   - A fixed buffer that is pointed to by Token.Buffer
731   - A download service function that is pointed to by Token.CheckPacket
732 
733   If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket
734   will be called first. If the call is successful, the packet will be stored in Token.Buffer.
735 
736   The returned directory listing in the Token.Buffer or EFI_MTFTP6_PACKET consists of a list
737   of two or three variable-length ASCII strings, each terminated by a null character, for each file in the
738   directory. If the multicast option is involved, the first field of each directory entry is the static
739   multicast IP address and UDP port number that is associated with the file name. The format of the
740   field is ip:ip:ip:ip:port. If the multicast option is not involved, this field and its terminating
741   null character are not present.
742 
743   The next field of each directory entry is the file name and the last field is the file information string.
744   The information string contains the file size and the create/modify timestamp. The format of the
745   information string is filesize yyyy-mm-dd hh:mm:ss:ffff. The timestamp is
746   Coordinated Universal Time (UTC; also known as Greenwich Mean Time [GMT]).
747 
748   @param[in]  This               Pointer to the EFI_MTFTP6_PROTOCOL instance.
749   @param[in]  Token              Pointer to the token structure to provide the parameters that are
750                                  used in this operation.
751 
752   @retval  EFI_SUCCESS           The MTFTPv6 related file "directory" has been downloaded.
753   @retval  EFI_UNSUPPORTED       The EFI MTFTPv6 Protocol driver does not support this function.
754   @retval  EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
755                                  - This is NULL.
756                                  - Token is NULL.
757                                  - Token.Filename is NULL.
758                                  - Token.OptionCount is not zero and Token.OptionList is NULL.
759                                  - One or more options in Token.OptionList have wrong format.
760                                  - Token.Buffer and Token.CheckPacket are both NULL.
761                                  - Token.OverrideData.ServerIp is not valid unicast IPv6 addresses.
762   @retval  EFI_UNSUPPORTED       One or more options in the Token.OptionList are not
763                                  supported by this implementation.
764   @retval  EFI_NOT_STARTED       The EFI MTFTPv6 Protocol driver has not been started.
765   @retval  EFI_NO_MAPPING        The underlying IPv6 driver was responsible for choosing a source
766                                  address for this instance, but no source address was available for use.
767   @retval  EFI_ALREADY_STARTED   This Token is already being used in another MTFTPv6 session.
768   @retval  EFI_OUT_OF_RESOURCES  Required system resources could not be allocated.
769   @retval  EFI_ACCESS_DENIED     The previous operation has not completed yet.
770   @retval  EFI_DEVICE_ERROR      An unexpected network error or system error occurred.
771 
772 **/
773 typedef
774 EFI_STATUS
775 (EFIAPI *EFI_MTFTP6_READ_DIRECTORY)(
776   IN EFI_MTFTP6_PROTOCOL      *This,
777   IN EFI_MTFTP6_TOKEN         *Token
778 );
779 
780 /**
781   Polls for incoming data packets and processes outgoing data packets.
782 
783   The Poll() function can be used by network drivers and applications to increase the rate that data
784   packets are moved between the communications device and the transmit and receive queues.
785   In some systems, the periodic timer event in the managed network driver may not poll the
786   underlying communications device fast enough to transmit and/or receive all data packets without
787   missing incoming packets or dropping outgoing packets. Drivers and applications that are
788   experiencing packet loss should try calling the Poll() function more often.
789 
790   @param[in]  This               Pointer to the EFI_MTFTP6_PROTOCOL instance.
791 
792   @retval  EFI_SUCCESS           Incoming or outgoing data was processed.
793   @retval  EFI_NOT_STARTED       This EFI MTFTPv6 Protocol instance has not been started.
794   @retval  EFI_INVALID_PARAMETER This is NULL.
795   @retval  EFI_DEVICE_ERROR      An unexpected system or network error occurred.
796   @retval  EFI_TIMEOUT           Data was dropped out of the transmit and/or receive queue.
797                                  Consider increasing the polling rate.
798 
799 **/
800 typedef
801 EFI_STATUS
802 (EFIAPI *EFI_MTFTP6_POLL)(
803   IN EFI_MTFTP6_PROTOCOL      *This
804   );
805 
806 ///
807 /// The EFI_MTFTP6_PROTOCOL is designed to be used by UEFI drivers and applications to transmit
808 /// and receive data files. The EFI MTFTPv6 Protocol driver uses the underlying EFI UDPv6 Protocol
809 /// driver and EFI IPv6 Protocol driver.
810 ///
811 struct _EFI_MTFTP6_PROTOCOL {
812   EFI_MTFTP6_GET_MODE_DATA  GetModeData;
813   EFI_MTFTP6_CONFIGURE      Configure;
814   EFI_MTFTP6_GET_INFO       GetInfo;
815   EFI_MTFTP6_PARSE_OPTIONS  ParseOptions;
816   EFI_MTFTP6_READ_FILE      ReadFile;
817   EFI_MTFTP6_WRITE_FILE     WriteFile;
818   EFI_MTFTP6_READ_DIRECTORY ReadDirectory;
819   EFI_MTFTP6_POLL           Poll;
820 };
821 
822 extern EFI_GUID gEfiMtftp6ServiceBindingProtocolGuid;
823 extern EFI_GUID gEfiMtftp6ProtocolGuid;
824 
825 #endif
826 
827