2 Mtftp6 internal data structure and definition declaration.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. <BR>
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.
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.
16 #ifndef __EFI_MTFTP6_IMPL_H__
17 #define __EFI_MTFTP6_IMPL_H__
21 #include <Protocol/Udp6.h>
22 #include <Protocol/Mtftp6.h>
23 #include <Protocol/ServiceBinding.h>
24 #include <Protocol/DriverBinding.h>
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>
34 typedef struct _MTFTP6_SERVICE MTFTP6_SERVICE
;
35 typedef struct _MTFTP6_INSTANCE MTFTP6_INSTANCE
;
37 #include "Mtftp6Driver.h"
38 #include "Mtftp6Option.h"
39 #include "Mtftp6Support.h"
41 #define MTFTP6_SERVICE_SIGNATURE SIGNATURE_32 ('M', 'F', '6', 'S')
42 #define MTFTP6_INSTANCE_SIGNATURE SIGNATURE_32 ('M', 'F', '6', 'I')
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
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)
55 extern EFI_MTFTP6_PROTOCOL gMtftp6ProtocolTemplate
;
57 typedef struct _MTFTP6_GETINFO_CONTEXT
{
58 EFI_MTFTP6_PACKET
**Packet
;
61 } MTFTP6_GETINFO_CONTEXT
;
64 // Control block for MTFTP6 instance, it's per configuration data.
66 struct _MTFTP6_INSTANCE
{
70 EFI_MTFTP6_PROTOCOL Mtftp6
;
71 MTFTP6_SERVICE
*Service
;
72 EFI_MTFTP6_CONFIG_DATA
*Config
;
74 EFI_MTFTP6_TOKEN
*Token
;
75 MTFTP6_EXT_OPTION_INFO ExtInfo
;
86 // Record the total received and saved block number.
91 // Record the acked block number.
95 EFI_IPv6_ADDRESS ServerIp
;
97 UINT16 ServerDataPort
;
100 EFI_IPv6_ADDRESS McastIp
;
111 BOOLEAN IsTransmitted
;
117 // Control block for MTFTP6 service, it's per Nic handle.
119 struct _MTFTP6_SERVICE
{
121 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;
122 EFI_HANDLE Controller
;
128 // It is used to be as internal calculagraph for all instances.
132 // It is used to maintain the parent-child relationship between
133 // mtftp driver and udp driver.
139 EFI_SERVICE_BINDING_PROTOCOL
*ServiceBinding
;
140 UINTN NumberOfChildren
;
141 EFI_HANDLE
*ChildHandleBuffer
;
142 } MTFTP6_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT
;
145 Returns the current operating mode data for the MTFTP6 instance.
147 The GetModeData() function returns the current operating mode and
148 cached data packet for the MTFTP6 instance.
150 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
151 @param[out] ModeData The buffer in which the EFI MTFTPv6 Protocol driver mode
154 @retval EFI_SUCCESS The configuration data was returned successfully.
155 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
156 @retval EFI_INVALID_PARAMETER This is NULL, or ModeData is NULL.
161 EfiMtftp6GetModeData (
162 IN EFI_MTFTP6_PROTOCOL
*This
,
163 OUT EFI_MTFTP6_MODE_DATA
*ModeData
167 Initializes, changes, or resets the default operational setting for
168 this EFI MTFTPv6 Protocol driver instance.
170 The Configure() function is used to set and change the configuration
171 data for this EFI MTFTPv6 Protocol driver instance. The configuration
172 data can be reset to startup defaults by calling Configure() with
173 MtftpConfigData set to NULL. Whenever the instance is reset, any
174 pending operation is aborted. By changing the EFI MTFTPv6 Protocol
175 driver instance configuration data, the client can connect to
176 different MTFTPv6 servers. The configuration parameters in
177 MtftpConfigData are used as the default parameters in later MTFTPv6
178 operations and can be overridden in later operations.
180 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
181 @param[in] MtftpConfigData Pointer to the configuration data structure.
183 @retval EFI_SUCCESS The EFI MTFTPv6 Protocol instance was configured successfully.
184 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
186 - MtftpConfigData.StationIp is neither zero nor one
187 of the configured IP addresses in the underlying IPv6 driver.
188 - MtftpCofigData.ServerIp is not a valid IPv6 unicast address.
189 Note: It does not match the UEFI 2.3 Specification.
190 @retval EFI_ACCESS_DENIED - The configuration could not be changed at this time because there
191 is some MTFTP background operation in progress.
192 - MtftpCofigData.LocalPort is already in use.
193 Note: It does not match the UEFI 2.3 Specification.
194 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source
195 address for this instance, but no source address was available for use.
196 @retval EFI_OUT_OF_RESOURCES The EFI MTFTPv6 Protocol driver instance data could not be
198 Note: It is not defined in the UEFI 2.3 Specification.
199 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The EFI
200 MTFTPv6 Protocol driver instance is not configured.
201 Note: It is not defined in the UEFI 2.3 Specification.
207 IN EFI_MTFTP6_PROTOCOL
*This
,
208 IN EFI_MTFTP6_CONFIG_DATA
*MtftpConfigData OPTIONAL
212 Get the information of the download from the server.
214 The GetInfo() function assembles an MTFTPv6 request packet
215 with options, sends it to the MTFTPv6 server, and may return
216 an MTFTPv6 OACK, MTFTPv6 ERROR, or ICMP ERROR packet. Retries
217 occur only if no response packets are received from the MTFTPv6
218 server before the timeout expires.
220 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
221 @param[in] OverrideData Data that is used to override the existing parameters. If NULL, the
222 default parameters that were set in the EFI_MTFTP6_PROTOCOL.Configure()
224 @param[in] Filename Pointer to null-terminated ASCII file name string.
225 @param[in] ModeStr Pointer to null-terminated ASCII mode string. If NULL, octet will be used
226 @param[in] OptionCount Number of option/value string pairs in OptionList.
227 @param[in] OptionList Pointer to array of option/value string pairs. Ignored if
229 @param[out] PacketLength The number of bytes in the returned packet.
230 @param[out] Packet The pointer to the received packet. This buffer must be freed by
233 @retval EFI_SUCCESS An MTFTPv6 OACK packet was received and is in the Packet.
234 Note: It does not match the UEFI 2.3 Specification.
235 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
238 - OptionCount is not zero and OptionList is NULL.
239 - One or more options in OptionList have wrong format.
240 - PacketLength is NULL.
241 - OverrideData.ServerIp is not a valid unicast IPv6 address.
242 @retval EFI_UNSUPPORTED One or more options in the OptionList are unsupported by
244 @retval EFI_NOT_STARTED The EFI MTFTPv6 Protocol driver has not been started.
245 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source
246 address for this instance, but no source address was available for use.
247 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
248 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
249 @retval EFI_TFTP_ERROR An MTFTPv6 ERROR packet was received and is in the Packet.
250 @retval EFI_NETWORK_UNREACHABLE An ICMP network 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_HOST_UNREACHABLE An ICMP host unreachable error packet was received, and the Packet is set to NULL.
253 Note: It is not defined in the UEFI 2.3 Specification.
254 @retval EFI_PROTOCOL_UNREACHABLE An ICMP protocol unreachable error packet was received, and the Packet is set to NULL.
255 Note: It is not defined in the UEFI 2.3 Specification.
256 @retval EFI_PORT_UNREACHABLE An ICMP port unreachable error packet was received, and the Packet is set to NULL.
257 @retval EFI_ICMP_ERROR Some other ICMP ERROR packet was received, and the Packet is set to NULL.
258 Note: It does not match the UEFI 2.3 Specification.
259 @retval EFI_PROTOCOL_ERROR An unexpected MTFTPv6 packet was received and is in the Packet.
260 @retval EFI_TIMEOUT No responses were received from the MTFTPv6 server.
261 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
267 IN EFI_MTFTP6_PROTOCOL
*This
,
268 IN EFI_MTFTP6_OVERRIDE_DATA
*OverrideData OPTIONAL
,
270 IN UINT8
*ModeStr OPTIONAL
,
271 IN UINT8 OptionCount
,
272 IN EFI_MTFTP6_OPTION
*OptionList OPTIONAL
,
273 OUT UINT32
*PacketLength
,
274 OUT EFI_MTFTP6_PACKET
**Packet OPTIONAL
278 Parse the options in an MTFTPv6 OACK packet.
280 The ParseOptions() function parses the option fields in an MTFTPv6 OACK
281 packet and returns the number of options that were found, and optionally,
282 a list of pointers to the options in the packet. If one or more of the
283 option fields are not valid, then EFI_PROTOCOL_ERROR is returned and
284 *OptionCount and *OptionList stop at the last valid option.
286 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
287 @param[in] PacketLen Length of the OACK packet to be parsed.
288 @param[in] Packet Pointer to the OACK packet to be parsed.
289 @param[out] OptionCount Pointer to the number of options in the following OptionList.
290 @param[out] OptionList Pointer to EFI_MTFTP6_OPTION storage. Each pointer in the
291 OptionList points to the corresponding MTFTP option buffer
292 in the Packet. Call the EFI Boot Service FreePool() to
293 release the OptionList if the options in this OptionList
294 are not needed any more.
296 @retval EFI_SUCCESS The OACK packet was valid and the OptionCount, and
297 OptionList parameters have been updated.
298 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
300 - Packet is NULL or Packet is not a valid MTFTPv6 packet.
301 - OptionCount is NULL.
302 @retval EFI_NOT_FOUND No options were found in the OACK packet.
303 @retval EFI_OUT_OF_RESOURCES Storage for the OptionList array can not be allocated.
304 @retval EFI_PROTOCOL_ERROR One or more of the option fields is invalid.
309 EfiMtftp6ParseOptions (
310 IN EFI_MTFTP6_PROTOCOL
*This
,
312 IN EFI_MTFTP6_PACKET
*Packet
,
313 OUT UINT32
*OptionCount
,
314 OUT EFI_MTFTP6_OPTION
**OptionList OPTIONAL
318 Download a file from an MTFTPv6 server.
320 The ReadFile() function is used to initialize and start an MTFTPv6 download
321 process and optionally wait for completion. When the download operation
322 completes, whether successfully or not, the Token.Status field is updated
323 by the EFI MTFTPv6 Protocol driver, and then Token.Event is signaled if it
325 Data can be downloaded from the MTFTPv6 server into either of the following
327 - A fixed buffer that is pointed to by Token.Buffer.
328 - A download service function that is pointed to by Token.CheckPacket.
329 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket
330 will be called first. If the call is successful, the packet will be stored
333 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
334 @param[in] Token Pointer to the token structure to provide the parameters that are
335 used in this operation.
337 @retval EFI_SUCCESS The data file has been transferred successfully.
338 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
339 @retval EFI_BUFFER_TOO_SMALL BufferSize is not zero but not large enough to hold the
340 downloaded data in downloading process.
341 Note: It does not match the UEFI 2.3 Specification.
342 @retval EFI_ABORTED Current operation is aborted by user.
343 @retval EFI_NETWORK_UNREACHABLE An ICMP network unreachable error packet was received.
344 Note: It is not defined in the UEFI 2.3 Specification.
345 @retval EFI_HOST_UNREACHABLE An ICMP host unreachable error packet was received.
346 Note: It is not defined in the UEFI 2.3 Specification.
347 @retval EFI_PROTOCOL_UNREACHABLE An ICMP protocol unreachable error packet was received.
348 Note: It is not defined in the UEFI 2.3 Specification.
349 @retval EFI_PORT_UNREACHABLE An ICMP port unreachable error packet was received.
350 Note: It is not defined in the UEFI 2.3 Specification.
351 @retval EFI_ICMP_ERROR An ICMP ERROR packet was received.
352 @retval EFI_TIMEOUT No responses were received from the MTFTPv6 server.
353 @retval EFI_TFTP_ERROR An MTFTPv6 ERROR packet was received.
354 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
360 IN EFI_MTFTP6_PROTOCOL
*This
,
361 IN EFI_MTFTP6_TOKEN
*Token
365 Send a file to an MTFTPv6 server.
367 The WriteFile() function is used to initialize an uploading operation
368 with the given option list, and optionally, wait for completion. If one
369 or more of the options is not supported by the server, the unsupported
370 options are ignored and a standard TFTP process starts instead. When
371 the upload process completes, whether successfully or not, Token.Event
372 is signaled, and the EFI MTFTPv6 Protocol driver updates Token.Status.
373 The caller can supply the data to be uploaded in the following two modes:
374 - Through the user-provided buffer.
375 - Through a callback function.
376 With the user-provided buffer, the Token.BufferSize field indicates
377 the length of the buffer, and the driver will upload the data in the
378 buffer. With an EFI_MTFTP6_PACKET_NEEDED callback function, the driver
379 will call this callback function to get more data from the user to upload.
381 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
382 @param[in] Token Pointer to the token structure to provide the parameters that are
383 used in this operation.
385 @retval EFI_SUCCESS The upload session has started.
386 @retval EFI_UNSUPPORTED The operation is not supported by this implementation.
387 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
390 - Token.Filename is NULL.
391 - Token.OptionCount is not zero and Token.OptionList is NULL.
392 - One or more options in Token.OptionList have wrong format.
393 - Token.Buffer and Token.PacketNeeded are both NULL.
394 - Token.OverrideData.ServerIp is not valid unicast IPv6 addresses.
395 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are not
396 supported by this implementation.
397 @retval EFI_NOT_STARTED The EFI MTFTPv6 Protocol driver has not been started.
398 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source
399 address for this instance, but no source address was available for use.
400 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv6 session.
401 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
402 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
403 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
409 IN EFI_MTFTP6_PROTOCOL
*This
,
410 IN EFI_MTFTP6_TOKEN
*Token
414 Download a data file directory from an MTFTPv6 server.
416 The ReadDirectory() function is used to return a list of files on the
417 MTFTPv6 server that are logically (or operationally) related to
418 Token.Filename. The directory request packet that is sent to the server
419 is built with the option list that was provided by caller, if present.
420 The file information that the server returns is put into either of
421 the following locations:
422 - A fixed buffer that is pointed to by Token.Buffer.
423 - A download service function that is pointed to by Token.CheckPacket.
424 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket
425 will be called first. If the call is successful, the packet will be stored
428 @param[in] This Pointer to the EFI_MTFTP6_PROTOCOL instance.
429 @param[in] Token Pointer to the token structure to provide the parameters that are
430 used in this operation.
432 @retval EFI_SUCCESS The MTFTPv6 related file "directory" has been downloaded.
433 @retval EFI_UNSUPPORTED The EFI MTFTPv6 Protocol driver does not support this function.
434 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
437 - Token.Filename is NULL.
438 - Token.OptionCount is not zero and Token.OptionList is NULL.
439 - One or more options in Token.OptionList have wrong format.
440 - Token.Buffer and Token.CheckPacket are both NULL.
441 - Token.OverrideData.ServerIp is not valid unicast IPv6 addresses.
442 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are not
443 supported by this implementation.
444 @retval EFI_NOT_STARTED The EFI MTFTPv6 Protocol driver has not been started.
445 @retval EFI_NO_MAPPING The underlying IPv6 driver was responsible for choosing a source
446 address for this instance, but no source address was available for use.
447 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv6 session.
448 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
449 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
450 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
455 EfiMtftp6ReadDirectory (
456 IN EFI_MTFTP6_PROTOCOL
*This
,
457 IN EFI_MTFTP6_TOKEN
*Token
461 Polls for incoming data packets and processes outgoing data packets.
463 The Poll() function can be used by network drivers and applications
464 to increase the rate that data packets are moved between the
465 communications device and the transmit and receive queues.In some
466 systems, the periodic timer event in the managed network driver may
467 not poll the underlying communications device fast enough to transmit
468 and/or receive all data packets without missing incoming packets or
469 dropping outgoing packets. Drivers and applications that are
470 experiencing packet loss should try calling the Poll() function
473 @param[in] This The MTFTP6 protocol instance.
476 @retval EFI_SUCCESS Incoming or outgoing data was processed.
477 @retval EFI_NOT_STARTED This EFI MTFTPv6 Protocol instance has not been started.
478 @retval EFI_INVALID_PARAMETER This is NULL.
479 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
480 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
481 Consider increasing the polling rate.
487 IN EFI_MTFTP6_PROTOCOL
*This