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