]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h
NetworkPkg/UefiPxeBcDxe: Add the clarification compared to UefiPxeBcDxe in MdeModulePkg.
[mirror_edk2.git] / NetworkPkg / Mtftp6Dxe / Mtftp6Impl.h
1 /** @file
2 Mtftp6 internal data structure and definition declaration.
3
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. <BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef __EFI_MTFTP6_IMPL_H__
17 #define __EFI_MTFTP6_IMPL_H__
18
19 #include <Uefi.h>
20
21 #include <Protocol/Udp6.h>
22 #include <Protocol/Mtftp6.h>
23 #include <Protocol/ServiceBinding.h>
24 #include <Protocol/DriverBinding.h>
25
26 #include <Library/DebugLib.h>
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/UefiLib.h>
30 #include <Library/BaseLib.h>
31 #include <Library/NetLib.h>
32 #include <Library/PrintLib.h>
33
34 typedef struct _MTFTP6_SERVICE MTFTP6_SERVICE;
35 typedef struct _MTFTP6_INSTANCE MTFTP6_INSTANCE;
36
37 #include "Mtftp6Driver.h"
38 #include "Mtftp6Option.h"
39 #include "Mtftp6Support.h"
40
41 #define MTFTP6_SERVICE_SIGNATURE SIGNATURE_32 ('M', 'F', '6', 'S')
42 #define MTFTP6_INSTANCE_SIGNATURE SIGNATURE_32 ('M', 'F', '6', 'I')
43
44 #define MTFTP6_DEFAULT_SERVER_CMD_PORT 69
45 #define MTFTP6_DEFAULT_TIMEOUT 3
46 #define MTFTP6_GET_MAPPING_TIMEOUT 3
47 #define MTFTP6_DEFAULT_MAX_RETRY 5
48 #define MTFTP6_DEFAULT_BLK_SIZE 512
49 #define MTFTP6_DEFAULT_WINDOWSIZE 1
50 #define MTFTP6_TICK_PER_SECOND 10000000U
51
52 #define MTFTP6_SERVICE_FROM_THIS(a) CR (a, MTFTP6_SERVICE, ServiceBinding, MTFTP6_SERVICE_SIGNATURE)
53 #define MTFTP6_INSTANCE_FROM_THIS(a) CR (a, MTFTP6_INSTANCE, Mtftp6, MTFTP6_INSTANCE_SIGNATURE)
54
55 extern EFI_MTFTP6_PROTOCOL gMtftp6ProtocolTemplate;
56
57 typedef struct _MTFTP6_GETINFO_CONTEXT{
58 EFI_MTFTP6_PACKET **Packet;
59 UINT32 *PacketLen;
60 EFI_STATUS Status;
61 } MTFTP6_GETINFO_CONTEXT;
62
63 //
64 // Control block for MTFTP6 instance, it's per configuration data.
65 //
66 struct _MTFTP6_INSTANCE {
67 UINT32 Signature;
68 EFI_HANDLE Handle;
69 LIST_ENTRY Link;
70 EFI_MTFTP6_PROTOCOL Mtftp6;
71 MTFTP6_SERVICE *Service;
72 EFI_MTFTP6_CONFIG_DATA *Config;
73
74 EFI_MTFTP6_TOKEN *Token;
75 MTFTP6_EXT_OPTION_INFO ExtInfo;
76
77 UINT16 BlkSize;
78 UINT16 LastBlk;
79 LIST_ENTRY BlkList;
80
81 UINT16 Operation;
82
83 UINT16 WindowSize;
84
85 //
86 // Record the total received block number and the already acked block number.
87 //
88 UINT64 TotalBlock;
89 UINT64 AckedBlock;
90
91 EFI_IPv6_ADDRESS ServerIp;
92 UINT16 ServerCmdPort;
93 UINT16 ServerDataPort;
94 UDP_IO *UdpIo;
95
96 EFI_IPv6_ADDRESS McastIp;
97 UINT16 McastPort;
98 UDP_IO *McastUdpIo;
99
100 NET_BUF *LastPacket;
101 UINT32 CurRetry;
102 UINT32 MaxRetry;
103 UINT32 PacketToLive;
104 UINT32 Timeout;
105
106 EFI_TPL OldTpl;
107 BOOLEAN IsTransmitted;
108 BOOLEAN IsMaster;
109 BOOLEAN InDestroy;
110 };
111
112 //
113 // Control block for MTFTP6 service, it's per Nic handle.
114 //
115 struct _MTFTP6_SERVICE {
116 UINT32 Signature;
117 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
118 EFI_HANDLE Controller;
119 EFI_HANDLE Image;
120
121 UINT16 ChildrenNum;
122 LIST_ENTRY Children;
123 //
124 // It is used to be as internal calculagraph for all instances.
125 //
126 EFI_EVENT Timer;
127 //
128 // It is used to maintain the parent-child relationship between
129 // mtftp driver and udp driver.
130 //
131 UDP_IO *DummyUdpIo;
132 };
133
134 typedef struct {
135 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
136 UINTN NumberOfChildren;
137 EFI_HANDLE *ChildHandleBuffer;
138 } MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT;
139
140 /**
141 Returns the current operating mode data for the MTFTP6 instance.
142
143 The GetModeData() function returns the current operating mode and
144 cached data packet for the MTFTP6 instance.
145
146 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
147 @param[out] ModeData The buffer in which the EFI MTFTPv6 Protocol driver mode
148 data is returned.
149
150 @retval EFI_SUCCESS The configuration data was returned successfully.
151 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
152 @retval EFI_INVALID_PARAMETER This is NULL, or ModeData is NULL.
153
154 **/
155 EFI_STATUS
156 EFIAPI
157 EfiMtftp6GetModeData (
158 IN EFI_MTFTP6_PROTOCOL *This,
159 OUT EFI_MTFTP6_MODE_DATA *ModeData
160 );
161
162 /**
163 Initializes, changes, or resets the default operational setting for
164 this EFI MTFTPv6 Protocol driver instance.
165
166 The Configure() function is used to set and change the configuration
167 data for this EFI MTFTPv6 Protocol driver instance. The configuration
168 data can be reset to startup defaults by calling Configure() with
169 MtftpConfigData set to NULL. Whenever the instance is reset, any
170 pending operation is aborted. By changing the EFI MTFTPv6 Protocol
171 driver instance configuration data, the client can connect to
172 different MTFTPv6 servers. The configuration parameters in
173 MtftpConfigData are used as the default parameters in later MTFTPv6
174 operations and can be overridden in later operations.
175
176 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
177 @param[in] MtftpConfigData Pointer to the configuration data structure.
178
179 @retval EFI_SUCCESS The EFI MTFTPv6 Protocol instance was configured successfully.
180 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
181 - This is NULL.
182 - MtftpConfigData.StationIp is neither zero nor one
183 of the configured IP addresses in the underlying IPv6 driver.
184 - MtftpCofigData.ServerIp is not a valid IPv6 unicast address.
185 Note: It does not match the UEFI 2.3 Specification.
186 @retval EFI_ACCESS_DENIED - The configuration could not be changed at this time because there
187 is some MTFTP background operation in progress.
188 - MtftpCofigData.LocalPort is already in use.
189 Note: It does not match the UEFI 2.3 Specification.
190 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source
191 address for this instance, but no source address was available for use.
192 @retval EFI_OUT_OF_RESOURCES The EFI MTFTPv6 Protocol driver instance data could not be
193 allocated.
194 Note: It is not defined in the UEFI 2.3 Specification.
195 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI
196 MTFTPv6 Protocol driver instance is not configured.
197 Note: It is not defined in the UEFI 2.3 Specification.
198
199 **/
200 EFI_STATUS
201 EFIAPI
202 EfiMtftp6Configure (
203 IN EFI_MTFTP6_PROTOCOL *This,
204 IN EFI_MTFTP6_CONFIG_DATA *MtftpConfigData OPTIONAL
205 );
206
207 /**
208 Get the information of the download from the server.
209
210 The GetInfo() function assembles an MTFTPv6 request packet
211 with options, sends it to the MTFTPv6 server, and may return
212 an MTFTPv6 OACK, MTFTPv6 ERROR, or ICMP ERROR packet. Retries
213 occur only if no response packets are received from the MTFTPv6
214 server before the timeout expires.
215
216 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
217 @param[in] OverrideData Data that is used to override the existing parameters. If NULL, the
218 default parameters that were set in the EFI_MTFTP6_PROTOCOL.Configure()
219 function are used.
220 @param[in] Filename Pointer to null-terminated ASCII file name string.
221 @param[in] ModeStr Pointer to null-terminated ASCII mode string. If NULL, octet will be used
222 @param[in] OptionCount Number of option/value string pairs in OptionList.
223 @param[in] OptionList Pointer to array of option/value string pairs. Ignored if
224 OptionCount is zero.
225 @param[out] PacketLength The number of bytes in the returned packet.
226 @param[out] Packet The pointer to the received packet. This buffer must be freed by
227 the caller.
228
229 @retval EFI_SUCCESS An MTFTPv6 OACK packet was received and is in the Packet.
230 Note: It does not match the UEFI 2.3 Specification.
231 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
232 - This is NULL.
233 - Filename is NULL.
234 - OptionCount is not zero and OptionList is NULL.
235 - One or more options in OptionList have wrong format.
236 - PacketLength is NULL.
237 - OverrideData.ServerIp is not a valid unicast IPv6 address.
238 @retval EFI_UNSUPPORTED One or more options in the OptionList are unsupported by
239 this implementation.
240 @retval EFI_NOT_STARTED The EFI MTFTPv6 Protocol driver has not been started.
241 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source
242 address for this instance, but no source address was available for use.
243 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
244 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
245 @retval EFI_TFTP_ERROR An MTFTPv6 ERROR packet was received and is in the Packet.
246 @retval EFI_NETWORK_UNREACHABLE An ICMP network unreachable error packet was received, and the Packet is set to NULL.
247 Note: It is not defined in the UEFI 2.3 Specification.
248 @retval EFI_HOST_UNREACHABLE An ICMP host unreachable error packet was received, and the Packet is set to NULL.
249 Note: It is not defined in the UEFI 2.3 Specification.
250 @retval EFI_PROTOCOL_UNREACHABLE An ICMP protocol unreachable error packet was received, and the Packet is set to NULL.
251 Note: It is not defined in the UEFI 2.3 Specification.
252 @retval EFI_PORT_UNREACHABLE An ICMP port unreachable error packet was received, and the Packet is set to NULL.
253 @retval EFI_ICMP_ERROR Some other ICMP ERROR packet was received, and the Packet is set to NULL.
254 Note: It does not match the UEFI 2.3 Specification.
255 @retval EFI_PROTOCOL_ERROR An unexpected MTFTPv6 packet was received and is in the Packet.
256 @retval EFI_TIMEOUT No responses were received from the MTFTPv6 server.
257 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
258
259 **/
260 EFI_STATUS
261 EFIAPI
262 EfiMtftp6GetInfo (
263 IN EFI_MTFTP6_PROTOCOL *This,
264 IN EFI_MTFTP6_OVERRIDE_DATA *OverrideData OPTIONAL,
265 IN UINT8 *Filename,
266 IN UINT8 *ModeStr OPTIONAL,
267 IN UINT8 OptionCount,
268 IN EFI_MTFTP6_OPTION *OptionList OPTIONAL,
269 OUT UINT32 *PacketLength,
270 OUT EFI_MTFTP6_PACKET **Packet OPTIONAL
271 );
272
273 /**
274 Parse the options in an MTFTPv6 OACK packet.
275
276 The ParseOptions() function parses the option fields in an MTFTPv6 OACK
277 packet and returns the number of options that were found, and optionally,
278 a list of pointers to the options in the packet. If one or more of the
279 option fields are not valid, then EFI_PROTOCOL_ERROR is returned and
280 *OptionCount and *OptionList stop at the last valid option.
281
282 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
283 @param[in] PacketLen Length of the OACK packet to be parsed.
284 @param[in] Packet Pointer to the OACK packet to be parsed.
285 @param[out] OptionCount Pointer to the number of options in the following OptionList.
286 @param[out] OptionList Pointer to EFI_MTFTP6_OPTION storage. Each pointer in the
287 OptionList points to the corresponding MTFTP option buffer
288 in the Packet. Call the EFI Boot Service FreePool() to
289 release the OptionList if the options in this OptionList
290 are not needed any more.
291
292 @retval EFI_SUCCESS The OACK packet was valid and the OptionCount, and
293 OptionList parameters have been updated.
294 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
295 - PacketLen is 0.
296 - Packet is NULL or Packet is not a valid MTFTPv6 packet.
297 - OptionCount is NULL.
298 @retval EFI_NOT_FOUND No options were found in the OACK packet.
299 @retval EFI_OUT_OF_RESOURCES Storage for the OptionList array can not be allocated.
300 @retval EFI_PROTOCOL_ERROR One or more of the option fields is invalid.
301
302 **/
303 EFI_STATUS
304 EFIAPI
305 EfiMtftp6ParseOptions (
306 IN EFI_MTFTP6_PROTOCOL *This,
307 IN UINT32 PacketLen,
308 IN EFI_MTFTP6_PACKET *Packet,
309 OUT UINT32 *OptionCount,
310 OUT EFI_MTFTP6_OPTION **OptionList OPTIONAL
311 );
312
313 /**
314 Download a file from an MTFTPv6 server.
315
316 The ReadFile() function is used to initialize and start an MTFTPv6 download
317 process and optionally wait for completion. When the download operation
318 completes, whether successfully or not, the Token.Status field is updated
319 by the EFI MTFTPv6 Protocol driver, and then Token.Event is signaled if it
320 is not NULL.
321 Data can be downloaded from the MTFTPv6 server into either of the following
322 locations:
323 - A fixed buffer that is pointed to by Token.Buffer.
324 - A download service function that is pointed to by Token.CheckPacket.
325 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket
326 will be called first. If the call is successful, the packet will be stored
327 in Token.Buffer.
328
329 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
330 @param[in] Token Pointer to the token structure to provide the parameters that are
331 used in this operation.
332
333 @retval EFI_SUCCESS The data file has been transferred successfully.
334 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
335 @retval EFI_BUFFER_TOO_SMALL BufferSize is not zero but not large enough to hold the
336 downloaded data in downloading process.
337 Note: It does not match the UEFI 2.3 Specification.
338 @retval EFI_ABORTED Current operation is aborted by user.
339 @retval EFI_NETWORK_UNREACHABLE An ICMP network unreachable error packet was received.
340 Note: It is not defined in the UEFI 2.3 Specification.
341 @retval EFI_HOST_UNREACHABLE An ICMP host unreachable error packet was received.
342 Note: It is not defined in the UEFI 2.3 Specification.
343 @retval EFI_PROTOCOL_UNREACHABLE An ICMP protocol unreachable error packet was received.
344 Note: It is not defined in the UEFI 2.3 Specification.
345 @retval EFI_PORT_UNREACHABLE An ICMP port unreachable error packet was received.
346 Note: It is not defined in the UEFI 2.3 Specification.
347 @retval EFI_ICMP_ERROR An ICMP ERROR packet was received.
348 @retval EFI_TIMEOUT No responses were received from the MTFTPv6 server.
349 @retval EFI_TFTP_ERROR An MTFTPv6 ERROR packet was received.
350 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
351
352 **/
353 EFI_STATUS
354 EFIAPI
355 EfiMtftp6ReadFile (
356 IN EFI_MTFTP6_PROTOCOL *This,
357 IN EFI_MTFTP6_TOKEN *Token
358 );
359
360 /**
361 Send a file to an MTFTPv6 server.
362
363 The WriteFile() function is used to initialize an uploading operation
364 with the given option list, and optionally, wait for completion. If one
365 or more of the options is not supported by the server, the unsupported
366 options are ignored and a standard TFTP process starts instead. When
367 the upload process completes, whether successfully or not, Token.Event
368 is signaled, and the EFI MTFTPv6 Protocol driver updates Token.Status.
369 The caller can supply the data to be uploaded in the following two modes:
370 - Through the user-provided buffer.
371 - Through a callback function.
372 With the user-provided buffer, the Token.BufferSize field indicates
373 the length of the buffer, and the driver will upload the data in the
374 buffer. With an EFI_MTFTP6_PACKET_NEEDED callback function, the driver
375 will call this callback function to get more data from the user to upload.
376
377 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
378 @param[in] Token Pointer to the token structure to provide the parameters that are
379 used in this operation.
380
381 @retval EFI_SUCCESS The upload session has started.
382 @retval EFI_UNSUPPORTED The operation is not supported by this implementation.
383 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
384 - This is NULL.
385 - Token is NULL.
386 - Token.Filename is NULL.
387 - Token.OptionCount is not zero and Token.OptionList is NULL.
388 - One or more options in Token.OptionList have wrong format.
389 - Token.Buffer and Token.PacketNeeded are both NULL.
390 - Token.OverrideData.ServerIp is not valid unicast IPv6 addresses.
391 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are not
392 supported by this implementation.
393 @retval EFI_NOT_STARTED The EFI MTFTPv6 Protocol driver has not been started.
394 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source
395 address for this instance, but no source address was available for use.
396 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv6 session.
397 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
398 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
399 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
400
401 **/
402 EFI_STATUS
403 EFIAPI
404 EfiMtftp6WriteFile (
405 IN EFI_MTFTP6_PROTOCOL *This,
406 IN EFI_MTFTP6_TOKEN *Token
407 );
408
409 /**
410 Download a data file directory from an MTFTPv6 server.
411
412 The ReadDirectory() function is used to return a list of files on the
413 MTFTPv6 server that are logically (or operationally) related to
414 Token.Filename. The directory request packet that is sent to the server
415 is built with the option list that was provided by caller, if present.
416 The file information that the server returns is put into either of
417 the following locations:
418 - A fixed buffer that is pointed to by Token.Buffer.
419 - A download service function that is pointed to by Token.CheckPacket.
420 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket
421 will be called first. If the call is successful, the packet will be stored
422 in Token.Buffer.
423
424 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
425 @param[in] Token Pointer to the token structure to provide the parameters that are
426 used in this operation.
427
428 @retval EFI_SUCCESS The MTFTPv6 related file "directory" has been downloaded.
429 @retval EFI_UNSUPPORTED The EFI MTFTPv6 Protocol driver does not support this function.
430 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
431 - This is NULL.
432 - Token is NULL.
433 - Token.Filename is NULL.
434 - Token.OptionCount is not zero and Token.OptionList is NULL.
435 - One or more options in Token.OptionList have wrong format.
436 - Token.Buffer and Token.CheckPacket are both NULL.
437 - Token.OverrideData.ServerIp is not valid unicast IPv6 addresses.
438 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are not
439 supported by this implementation.
440 @retval EFI_NOT_STARTED The EFI MTFTPv6 Protocol driver has not been started.
441 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source
442 address for this instance, but no source address was available for use.
443 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv6 session.
444 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
445 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
446 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
447
448 **/
449 EFI_STATUS
450 EFIAPI
451 EfiMtftp6ReadDirectory (
452 IN EFI_MTFTP6_PROTOCOL *This,
453 IN EFI_MTFTP6_TOKEN *Token
454 );
455
456 /**
457 Polls for incoming data packets and processes outgoing data packets.
458
459 The Poll() function can be used by network drivers and applications
460 to increase the rate that data packets are moved between the
461 communications device and the transmit and receive queues.In some
462 systems, the periodic timer event in the managed network driver may
463 not poll the underlying communications device fast enough to transmit
464 and/or receive all data packets without missing incoming packets or
465 dropping outgoing packets. Drivers and applications that are
466 experiencing packet loss should try calling the Poll() function
467 more often.
468
469 @param[in] This The MTFTP6 protocol instance.
470
471
472 @retval EFI_SUCCESS Incoming or outgoing data was processed.
473 @retval EFI_NOT_STARTED This EFI MTFTPv6 Protocol instance has not been started.
474 @retval EFI_INVALID_PARAMETER This is NULL.
475 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
476 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
477 Consider increasing the polling rate.
478
479 **/
480 EFI_STATUS
481 EFIAPI
482 EfiMtftp6Poll (
483 IN EFI_MTFTP6_PROTOCOL *This
484 );
485
486 #endif