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