2 Interface routine for Mtftp4.
4 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php<BR>
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "Mtftp4Impl.h"
20 Clean up the MTFTP session to get ready for new operation.
22 @param Instance The MTFTP session to clean up
23 @param Result The result to return to the caller who initiated
27 Mtftp4CleanOperation (
28 IN OUT MTFTP4_PROTOCOL
*Instance
,
34 MTFTP4_BLOCK_RANGE
*Block
;
35 EFI_MTFTP4_TOKEN
*Token
;
38 // Free various resources.
40 Token
= Instance
->Token
;
43 Token
->Status
= Result
;
45 if (Token
->Event
!= NULL
) {
46 gBS
->SignalEvent (Token
->Event
);
49 Instance
->Token
= NULL
;
52 ASSERT (Instance
->UnicastPort
!= NULL
);
53 UdpIoCleanIo (Instance
->UnicastPort
);
55 if (Instance
->LastPacket
!= NULL
) {
56 NetbufFree (Instance
->LastPacket
);
57 Instance
->LastPacket
= NULL
;
60 if (Instance
->McastUdpPort
!= NULL
) {
62 Instance
->McastUdpPort
->UdpHandle
,
63 &gEfiUdp4ProtocolGuid
,
64 gMtftp4DriverBinding
.DriverBindingHandle
,
67 UdpIoFreeIo (Instance
->McastUdpPort
);
68 Instance
->McastUdpPort
= NULL
;
71 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Instance
->Blocks
) {
72 Block
= NET_LIST_USER_STRUCT (Entry
, MTFTP4_BLOCK_RANGE
, Link
);
73 RemoveEntryList (Entry
);
77 ZeroMem (&Instance
->RequestOption
, sizeof (MTFTP4_OPTION
));
79 Instance
->Operation
= 0;
81 Instance
->BlkSize
= MTFTP4_DEFAULT_BLKSIZE
;
82 Instance
->LastBlock
= 0;
83 Instance
->ServerIp
= 0;
84 Instance
->ListeningPort
= 0;
85 Instance
->ConnectedPort
= 0;
86 Instance
->Gateway
= 0;
87 Instance
->PacketToLive
= 0;
88 Instance
->MaxRetry
= 0;
89 Instance
->CurRetry
= 0;
90 Instance
->Timeout
= 0;
91 Instance
->McastIp
= 0;
92 Instance
->McastPort
= 0;
93 Instance
->Master
= TRUE
;
98 Check packet for GetInfo.
100 GetInfo is implemented with EfiMtftp4ReadFile. It use Mtftp4GetInfoCheckPacket
101 to inspect the first packet from server, then abort the session.
103 @param This The MTFTP4 protocol instance
104 @param Token The user's token
105 @param PacketLen The length of the packet
106 @param Packet The received packet.
108 @retval EFI_ABORTED Abort the ReadFile operation and return.
113 Mtftp4GetInfoCheckPacket (
114 IN EFI_MTFTP4_PROTOCOL
*This
,
115 IN EFI_MTFTP4_TOKEN
*Token
,
117 IN EFI_MTFTP4_PACKET
*Packet
120 MTFTP4_GETINFO_STATE
*State
;
123 EFI_MTFTP4_ERROR_HEADER
*ErrorHeader
;
125 State
= (MTFTP4_GETINFO_STATE
*) Token
->Context
;
126 OpCode
= NTOHS (Packet
->OpCode
);
129 // Set the GetInfo's return status according to the OpCode.
132 case EFI_MTFTP4_OPCODE_ERROR
:
133 ErrorHeader
= (EFI_MTFTP4_ERROR_HEADER
*) Packet
;
134 if (ErrorHeader
->ErrorCode
== EFI_MTFTP4_ERRORCODE_FILE_NOT_FOUND
) {
135 DEBUG ((EFI_D_ERROR
, "TFTP error code 1 (File Not Found)\n"));
137 DEBUG ((EFI_D_ERROR
, "TFTP error code %d\n", ErrorHeader
->ErrorCode
));
139 State
->Status
= EFI_TFTP_ERROR
;
142 case EFI_MTFTP4_OPCODE_OACK
:
143 State
->Status
= EFI_SUCCESS
;
147 State
->Status
= EFI_PROTOCOL_ERROR
;
151 // Allocate buffer then copy the packet over. Use gBS->AllocatePool
152 // in case AllocatePool will implements something tricky.
154 Status
= gBS
->AllocatePool (EfiBootServicesData
, PacketLen
, (VOID
**) State
->Packet
);
156 if (EFI_ERROR (Status
)) {
157 State
->Status
= EFI_OUT_OF_RESOURCES
;
161 *(State
->PacketLen
) = PacketLen
;
162 CopyMem (*(State
->Packet
), Packet
, PacketLen
);
169 Check whether the override data is valid.
171 It will first validate whether the server is a valid unicast. If a gateway
172 is provided in the Override, it also check that it is a unicast on the
175 @param Instance The MTFTP instance
176 @param Override The override data to validate.
178 @retval TRUE The override data is valid
179 @retval FALSE The override data is invalid
183 Mtftp4OverrideValid (
184 IN MTFTP4_PROTOCOL
*Instance
,
185 IN EFI_MTFTP4_OVERRIDE_DATA
*Override
188 EFI_MTFTP4_CONFIG_DATA
*Config
;
193 CopyMem (&Ip
, &Override
->ServerIp
, sizeof (IP4_ADDR
));
194 if (!NetIp4IsUnicast (NTOHL (Ip
), 0)) {
198 Config
= &Instance
->Config
;
200 CopyMem (&Gateway
, &Override
->GatewayIp
, sizeof (IP4_ADDR
));
201 Gateway
= NTOHL (Gateway
);
203 if (!Config
->UseDefaultSetting
&& (Gateway
!= 0)) {
204 CopyMem (&Netmask
, &Config
->SubnetMask
, sizeof (IP4_ADDR
));
205 CopyMem (&Ip
, &Config
->StationIp
, sizeof (IP4_ADDR
));
207 Netmask
= NTOHL (Netmask
);
210 if (!NetIp4IsUnicast (Gateway
, Netmask
) || !IP4_NET_EQUAL (Gateway
, Ip
, Netmask
)) {
220 Poll the UDP to get the IP4 default address, which may be retrieved
223 The default time out value is 5 seconds. If IP has retrieved the default address,
224 the UDP is reconfigured.
226 @param Instance The Mtftp instance
227 @param UdpIo The UDP_IO to poll
228 @param UdpCfgData The UDP configure data to reconfigure the UDP_IO
230 @retval TRUE The default address is retrieved and UDP is reconfigured.
231 @retval FALSE Some error occured.
236 IN MTFTP4_PROTOCOL
*Instance
,
238 IN EFI_UDP4_CONFIG_DATA
*UdpCfgData
241 MTFTP4_SERVICE
*Service
;
242 EFI_IP4_MODE_DATA Ip4Mode
;
243 EFI_UDP4_PROTOCOL
*Udp
;
246 ASSERT (Instance
->Config
.UseDefaultSetting
);
248 Service
= Instance
->Service
;
249 Udp
= UdpIo
->Protocol
.Udp4
;
251 Status
= gBS
->SetTimer (
252 Service
->TimerToGetMap
,
254 MTFTP4_TIME_TO_GETMAP
* TICKS_PER_SECOND
256 if (EFI_ERROR (Status
)) {
260 while (!EFI_ERROR (gBS
->CheckEvent (Service
->TimerToGetMap
))) {
263 if (!EFI_ERROR (Udp
->GetModeData (Udp
, NULL
, &Ip4Mode
, NULL
, NULL
)) &&
264 Ip4Mode
.IsConfigured
) {
266 Udp
->Configure (Udp
, NULL
);
267 return (BOOLEAN
) (Udp
->Configure (Udp
, UdpCfgData
) == EFI_SUCCESS
);
276 Configure the UDP port for unicast receiving.
278 @param UdpIo The UDP_IO instance
279 @param Instance The MTFTP session
281 @retval EFI_SUCCESS The UDP port is successfully configured for the
282 session to unicast receive.
286 Mtftp4ConfigUnicastPort (
288 IN MTFTP4_PROTOCOL
*Instance
291 EFI_MTFTP4_CONFIG_DATA
*Config
;
292 EFI_UDP4_CONFIG_DATA UdpConfig
;
296 Config
= &Instance
->Config
;
298 UdpConfig
.AcceptBroadcast
= FALSE
;
299 UdpConfig
.AcceptPromiscuous
= FALSE
;
300 UdpConfig
.AcceptAnyPort
= FALSE
;
301 UdpConfig
.AllowDuplicatePort
= FALSE
;
302 UdpConfig
.TypeOfService
= 0;
303 UdpConfig
.TimeToLive
= 64;
304 UdpConfig
.DoNotFragment
= FALSE
;
305 UdpConfig
.ReceiveTimeout
= 0;
306 UdpConfig
.TransmitTimeout
= 0;
307 UdpConfig
.UseDefaultAddress
= Config
->UseDefaultSetting
;
308 UdpConfig
.StationAddress
= Config
->StationIp
;
309 UdpConfig
.SubnetMask
= Config
->SubnetMask
;
310 UdpConfig
.StationPort
= 0;
311 UdpConfig
.RemotePort
= 0;
313 Ip
= HTONL (Instance
->ServerIp
);
314 CopyMem (&UdpConfig
.RemoteAddress
, &Ip
, sizeof (EFI_IPv4_ADDRESS
));
316 Status
= UdpIo
->Protocol
.Udp4
->Configure (UdpIo
->Protocol
.Udp4
, &UdpConfig
);
318 if ((Status
== EFI_NO_MAPPING
) && Mtftp4GetMapping (Instance
, UdpIo
, &UdpConfig
)) {
322 if (!Config
->UseDefaultSetting
&& !EFI_IP4_EQUAL (&mZeroIp4Addr
, &Config
->GatewayIp
)) {
324 // The station IP address is manually configured and the Gateway IP is not 0.
325 // Add the default route for this UDP instance.
327 Status
= UdpIo
->Protocol
.Udp4
->Routes (
328 UdpIo
->Protocol
.Udp4
,
334 if (EFI_ERROR (Status
)) {
335 UdpIo
->Protocol
.Udp4
->Configure (UdpIo
->Protocol
.Udp4
, NULL
);
343 Start the MTFTP session to do the operation, such as read file,
344 write file, and read directory.
346 @param This The MTFTP session
347 @param Token The token than encapsues the user's request.
348 @param Operation The operation to do
350 @retval EFI_INVALID_PARAMETER Some of the parameters are invalid.
351 @retval EFI_NOT_STARTED The MTFTP session hasn't been configured.
352 @retval EFI_ALREADY_STARTED There is pending operation for the session.
353 @retval EFI_SUCCESS The operation is successfully started.
358 IN EFI_MTFTP4_PROTOCOL
*This
,
359 IN EFI_MTFTP4_TOKEN
*Token
,
363 MTFTP4_PROTOCOL
*Instance
;
364 EFI_MTFTP4_OVERRIDE_DATA
*Override
;
365 EFI_MTFTP4_CONFIG_DATA
*Config
;
370 // Validate the parameters
372 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Filename
== NULL
) ||
373 ((Token
->OptionCount
!= 0) && (Token
->OptionList
== NULL
))) {
374 return EFI_INVALID_PARAMETER
;
378 // User must provide at least one method to collect the data for download.
380 if (((Operation
== EFI_MTFTP4_OPCODE_RRQ
) || (Operation
== EFI_MTFTP4_OPCODE_DIR
)) &&
381 ((Token
->Buffer
== NULL
) && (Token
->CheckPacket
== NULL
))) {
382 return EFI_INVALID_PARAMETER
;
386 // User must provide at least one method to provide the data for upload.
388 if ((Operation
== EFI_MTFTP4_OPCODE_WRQ
) &&
389 ((Token
->Buffer
== NULL
) && (Token
->PacketNeeded
== NULL
))) {
390 return EFI_INVALID_PARAMETER
;
393 Instance
= MTFTP4_PROTOCOL_FROM_THIS (This
);
395 Status
= EFI_SUCCESS
;
396 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
398 if (Instance
->State
!= MTFTP4_STATE_CONFIGED
) {
399 Status
= EFI_NOT_STARTED
;
402 if (Instance
->Operation
!= 0) {
403 Status
= EFI_ACCESS_DENIED
;
406 if (EFI_ERROR (Status
)) {
407 gBS
->RestoreTPL (OldTpl
);
412 // Set the Operation now to prevent the application start other
415 Instance
->Operation
= Operation
;
416 Override
= Token
->OverrideData
;
418 if ((Override
!= NULL
) && !Mtftp4OverrideValid (Instance
, Override
)) {
419 Status
= EFI_INVALID_PARAMETER
;
423 if (Token
->OptionCount
!= 0) {
424 Status
= Mtftp4ParseOption (
428 &Instance
->RequestOption
431 if (EFI_ERROR (Status
)) {
437 // Set the operation parameters from the configuration or override data.
439 Config
= &Instance
->Config
;
440 Instance
->Token
= Token
;
441 Instance
->BlkSize
= MTFTP4_DEFAULT_BLKSIZE
;
443 CopyMem (&Instance
->ServerIp
, &Config
->ServerIp
, sizeof (IP4_ADDR
));
444 Instance
->ServerIp
= NTOHL (Instance
->ServerIp
);
446 Instance
->ListeningPort
= Config
->InitialServerPort
;
447 Instance
->ConnectedPort
= 0;
449 CopyMem (&Instance
->Gateway
, &Config
->GatewayIp
, sizeof (IP4_ADDR
));
450 Instance
->Gateway
= NTOHL (Instance
->Gateway
);
452 Instance
->MaxRetry
= Config
->TryCount
;
453 Instance
->Timeout
= Config
->TimeoutValue
;
454 Instance
->Master
= TRUE
;
456 if (Override
!= NULL
) {
457 CopyMem (&Instance
->ServerIp
, &Override
->ServerIp
, sizeof (IP4_ADDR
));
458 CopyMem (&Instance
->Gateway
, &Override
->GatewayIp
, sizeof (IP4_ADDR
));
460 Instance
->ServerIp
= NTOHL (Instance
->ServerIp
);
461 Instance
->Gateway
= NTOHL (Instance
->Gateway
);
463 Instance
->ListeningPort
= Override
->ServerPort
;
464 Instance
->MaxRetry
= Override
->TryCount
;
465 Instance
->Timeout
= Override
->TimeoutValue
;
468 if (Instance
->ListeningPort
== 0) {
469 Instance
->ListeningPort
= MTFTP4_DEFAULT_SERVER_PORT
;
472 if (Instance
->MaxRetry
== 0) {
473 Instance
->MaxRetry
= MTFTP4_DEFAULT_RETRY
;
476 if (Instance
->Timeout
== 0) {
477 Instance
->Timeout
= MTFTP4_DEFAULT_TIMEOUT
;
481 // Config the unicast UDP child to send initial request
483 Status
= Mtftp4ConfigUnicastPort (Instance
->UnicastPort
, Instance
);
485 if (EFI_ERROR (Status
)) {
490 // Set initial status.
492 Token
->Status
= EFI_NOT_READY
;
495 // Build and send an initial requests
497 if (Operation
== EFI_MTFTP4_OPCODE_WRQ
) {
498 Status
= Mtftp4WrqStart (Instance
, Operation
);
500 Status
= Mtftp4RrqStart (Instance
, Operation
);
503 gBS
->RestoreTPL (OldTpl
);
505 if (EFI_ERROR (Status
)) {
509 if (Token
->Event
!= NULL
) {
514 // Return immediately for asynchronous operation or poll the
515 // instance for synchronous operation.
517 while (Token
->Status
== EFI_NOT_READY
) {
521 return Token
->Status
;
524 Mtftp4CleanOperation (Instance
, Status
);
525 gBS
->RestoreTPL (OldTpl
);
532 Reads the current operational settings.
534 The GetModeData()function reads the current operational settings of this
535 EFI MTFTPv4 Protocol driver instance.
537 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance.
538 @param ModeData Pointer to storage for the EFI MTFTPv4 Protocol
541 @retval EFI_SUCCESS The configuration data was successfully returned.
542 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
543 @retval EFI_INVALID_PARAMETER This is NULL or ModeData is NULL.
548 EfiMtftp4GetModeData (
549 IN EFI_MTFTP4_PROTOCOL
*This
,
550 OUT EFI_MTFTP4_MODE_DATA
*ModeData
553 MTFTP4_PROTOCOL
*Instance
;
556 if ((This
== NULL
) || (ModeData
== NULL
)) {
557 return EFI_INVALID_PARAMETER
;
560 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
562 Instance
= MTFTP4_PROTOCOL_FROM_THIS (This
);
563 CopyMem(&ModeData
->ConfigData
, &Instance
->Config
, sizeof (Instance
->Config
));
564 ModeData
->SupportedOptionCount
= MTFTP4_SUPPORTED_OPTIONS
;
565 ModeData
->SupportedOptoins
= (UINT8
**) mMtftp4SupportedOptions
;
566 ModeData
->UnsupportedOptionCount
= 0;
567 ModeData
->UnsupportedOptoins
= NULL
;
569 gBS
->RestoreTPL (OldTpl
);
577 Initializes, changes, or resets the default operational setting for this
578 EFI MTFTPv4 Protocol driver instance.
580 The Configure() function is used to set and change the configuration data for
581 this EFI MTFTPv4 Protocol driver instance. The configuration data can be reset
582 to startup defaults by calling Configure() with MtftpConfigData set to NULL.
583 Whenever the instance is reset, any pending operation is aborted. By changing
584 the EFI MTFTPv4 Protocol driver instance configuration data, the client can
585 connect to different MTFTPv4 servers. The configuration parameters in
586 MtftpConfigData are used as the default parameters in later MTFTPv4 operations
587 and can be overridden in later operations.
589 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance
590 @param ConfigData MtftpConfigDataPointer to the configuration data
593 @retval EFI_SUCCESS The EFI MTFTPv4 Protocol driver was configured
595 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
597 2.MtftpConfigData.UseDefaultSetting is FALSE and
598 MtftpConfigData.StationIp is not a valid IPv4
600 3.MtftpCofigData.UseDefaultSetting is FALSE and
601 MtftpConfigData.SubnetMask is invalid.
602 4.MtftpCofigData.ServerIp is not a valid IPv4
604 5.MtftpConfigData.UseDefaultSetting is FALSE and
605 MtftpConfigData.GatewayIp is not a valid IPv4
606 unicast address or is not in the same subnet
607 with station address.
608 @retval EFI_ACCESS_DENIED The EFI configuration could not be changed at this
609 time because there is one MTFTP background operation
611 @retval EFI_NO_MAPPING When using a default address, configuration
612 (DHCP, BOOTP, RARP, etc.) has not finished yet.
613 @retval EFI_UNSUPPORTED A configuration protocol (DHCP, BOOTP, RARP, etc.)
614 could not be located when clients choose to use
615 the default address settings.
616 @retval EFI_OUT_OF_RESOURCES The EFI MTFTPv4 Protocol driver instance data could
618 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
619 The EFI MTFTPv4 Protocol driver instance is not
626 IN EFI_MTFTP4_PROTOCOL
*This
,
627 IN EFI_MTFTP4_CONFIG_DATA
*ConfigData
630 MTFTP4_PROTOCOL
*Instance
;
638 return EFI_INVALID_PARAMETER
;
641 Instance
= MTFTP4_PROTOCOL_FROM_THIS (This
);
643 if (ConfigData
== NULL
) {
645 // Reset the operation if ConfigData is NULL
647 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
649 Mtftp4CleanOperation (Instance
, EFI_ABORTED
);
650 ZeroMem (&Instance
->Config
, sizeof (EFI_MTFTP4_CONFIG_DATA
));
651 Instance
->State
= MTFTP4_STATE_UNCONFIGED
;
653 gBS
->RestoreTPL (OldTpl
);
657 // Configure the parameters for new operation.
659 CopyMem (&Ip
, &ConfigData
->StationIp
, sizeof (IP4_ADDR
));
660 CopyMem (&Netmask
, &ConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
661 CopyMem (&Gateway
, &ConfigData
->GatewayIp
, sizeof (IP4_ADDR
));
662 CopyMem (&ServerIp
, &ConfigData
->ServerIp
, sizeof (IP4_ADDR
));
665 Netmask
= NTOHL (Netmask
);
666 Gateway
= NTOHL (Gateway
);
667 ServerIp
= NTOHL (ServerIp
);
669 if (!NetIp4IsUnicast (ServerIp
, 0)) {
670 return EFI_INVALID_PARAMETER
;
673 if (!ConfigData
->UseDefaultSetting
&&
674 ((!IP4_IS_VALID_NETMASK (Netmask
) || !NetIp4IsUnicast (Ip
, Netmask
)))) {
676 return EFI_INVALID_PARAMETER
;
679 if ((Gateway
!= 0) &&
680 (!IP4_NET_EQUAL (Gateway
, Ip
, Netmask
) || !NetIp4IsUnicast (Gateway
, Netmask
))) {
682 return EFI_INVALID_PARAMETER
;
685 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
687 if ((Instance
->State
== MTFTP4_STATE_CONFIGED
) && (Instance
->Operation
!= 0)) {
688 gBS
->RestoreTPL (OldTpl
);
689 return EFI_ACCESS_DENIED
;
692 CopyMem(&Instance
->Config
, ConfigData
, sizeof (*ConfigData
));;
693 Instance
->State
= MTFTP4_STATE_CONFIGED
;
695 gBS
->RestoreTPL (OldTpl
);
704 Parses the options in an MTFTPv4 OACK packet.
706 The ParseOptions() function parses the option fields in an MTFTPv4 OACK packet
707 and returns the number of options that were found and optionally a list of
708 pointers to the options in the packet.
709 If one or more of the option fields are not valid, then EFI_PROTOCOL_ERROR is
710 returned and *OptionCount and *OptionList stop at the last valid option.
711 The OptionList is allocated by this function, and caller should free it when used.
713 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance.
714 @param PacketLen Length of the OACK packet to be parsed.
715 @param Packet Pointer to the OACK packet to be parsed.
716 @param OptionCount Pointer to the number of options in following OptionList.
717 @param OptionList Pointer to EFI_MTFTP4_OPTION storage. Call the
718 EFI Boot Service FreePool() to release theOptionList
719 if the options in this OptionList are not needed
722 @retval EFI_SUCCESS The OACK packet was valid and the OptionCount and
723 OptionList parameters have been updated.
724 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
726 2.Packet is NULL or Packet is not a valid MTFTPv4 packet.
727 3.OptionCount is NULL.
728 @retval EFI_NOT_FOUND No options were found in the OACK packet.
729 @retval EFI_OUT_OF_RESOURCES Storage for the OptionList array cannot be allocated.
730 @retval EFI_PROTOCOL_ERROR One or more of the option fields is invalid.
735 EfiMtftp4ParseOptions (
736 IN EFI_MTFTP4_PROTOCOL
*This
,
738 IN EFI_MTFTP4_PACKET
*Packet
,
739 OUT UINT32
*OptionCount
,
740 OUT EFI_MTFTP4_OPTION
**OptionList OPTIONAL
745 if ((This
== NULL
) || (PacketLen
< MTFTP4_OPCODE_LEN
) ||
746 (Packet
== NULL
) || (OptionCount
== NULL
)) {
748 return EFI_INVALID_PARAMETER
;
751 Status
= Mtftp4ExtractOptions (Packet
, PacketLen
, OptionCount
, OptionList
);
753 if (EFI_ERROR (Status
)) {
757 if (*OptionCount
== 0) {
758 return EFI_NOT_FOUND
;
766 Downloads a file from an MTFTPv4 server.
768 The ReadFile() function is used to initialize and start an MTFTPv4 download
769 process and optionally wait for completion. When the download operation completes,
770 whether successfully or not, the Token.Status field is updated by the EFI MTFTPv4
771 Protocol driver and then Token.Event is signaled (if it is not NULL).
772 Data can be downloaded from the MTFTPv4 server into either of the following locations:
773 1.A fixed buffer that is pointed to by Token.Buffer
774 2.A download service function that is pointed to by Token.CheckPacket
775 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket
776 will be called first. If the call is successful, the packet will be stored in
779 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance
780 @param Token Pointer to the token structure to provide the
781 parameters that are used in this operation.
783 @retval EFI_SUCCESS The data file has been transferred successfully.
784 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
785 @retval EFI_BUFFER_TOO_SMALL BufferSize is not large enough to hold the downloaded
786 data in downloading process.
787 @retval EFI_ABORTED Current operation is aborted by user.
788 @retval EFI_ICMP_ERROR An ICMP ERROR packet was received.
789 @retval EFI_TIMEOUT No responses were received from the MTFTPv4 server.
790 @retval EFI_TFTP_ERROR An MTFTPv4 ERROR packet was received.
791 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
792 @retval EFI_NO_MEDIA There was a media error.
798 IN EFI_MTFTP4_PROTOCOL
*This
,
799 IN EFI_MTFTP4_TOKEN
*Token
802 return Mtftp4Start (This
, Token
, EFI_MTFTP4_OPCODE_RRQ
);
807 Sends a data file to an MTFTPv4 server. May be unsupported in some EFI implementations
809 The WriteFile() function is used to initialize an uploading operation with the
810 given option list and optionally wait for completion. If one or more of the
811 options is not supported by the server, the unsupported options are ignored and
812 a standard TFTP process starts instead. When the upload process completes,
813 whether successfully or not, Token.Event is signaled, and the EFI MTFTPv4 Protocol
814 driver updates Token.Status.
815 The caller can supply the data to be uploaded in the following two modes:
816 1.Through the user-provided buffer
817 2.Through a callback function
818 With the user-provided buffer, the Token.BufferSize field indicates the length
819 of the buffer, and the driver will upload the data in the buffer. With an
820 EFI_MTFTP4_PACKET_NEEDED callback function, the driver will call this callback
821 function to get more data from the user to upload. See the definition of
822 EFI_MTFTP4_PACKET_NEEDED for more information. These two modes cannot be used at
823 the same time. The callback function will be ignored if the user provides the buffer.
825 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance.
826 @param Token Pointer to the token structure to provide the
827 parameters that are used in this function
829 @retval EFI_SUCCESS The upload session has started.
830 @retval EFI_UNSUPPORTED The operation is not supported by this implementation.
831 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
834 3. Token.Filename is NULL.
835 4. Token.OptionCount is not zero and
836 Token.OptionList is NULL.
837 5. One or more options in Token.OptionList have wrong
839 6. Token.Buffer and Token.PacketNeeded are both
841 7. One or more IPv4 addresses in Token.OverrideData
842 are not valid unicast IPv4 addresses if
843 Token.OverrideData is not NULL.
844 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are in the
845 unsupported list of structure EFI_MTFTP4_MODE_DATA.
846 @retval EFI_NOT_STARTED The EFI MTFTPv4 Protocol driver has not been started.
847 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
848 BOOTP, RARP, etc.) is not finished yet.
849 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv4
851 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
852 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
853 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
859 IN EFI_MTFTP4_PROTOCOL
*This
,
860 IN EFI_MTFTP4_TOKEN
*Token
863 return Mtftp4Start (This
, Token
, EFI_MTFTP4_OPCODE_WRQ
);
868 Downloads a data file "directory" from an MTFTPv4 server.
869 May be unsupported in some EFI implementations
871 The ReadDirectory() function is used to return a list of files on the MTFTPv4
872 server that are logically (or operationally) related to Token.Filename. The
873 directory request packet that is sent to the server is built with the option
874 list that was provided by caller, if present.
875 The file information that the server returns is put into either of the following
877 1.A fixed buffer that is pointed to by Token.Buffer
878 2.A download service function that is pointed to by Token.CheckPacket
879 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket will
880 be called first. If the call is successful, the packet will be stored in Token.Buffer.
881 The returned directory listing in the Token.Buffer or EFI_MTFTP4_PACKET consists
882 of a list of two or three variable-length ASCII strings, each terminated by a
883 null character, for each file in the directory. If the multicast option is involved,
884 the first field of each directory entry is the static multicast IP address and
885 UDP port number that is associated with the file name. The format of the field
886 is ip:ip:ip:ip:port. If the multicast option is not involved, this field and its
887 terminating null character are not present.
888 The next field of each directory entry is the file name and the last field is
889 the file information string. The information string contains the file size and
890 the create/modify timestamp. The format of the information string is filesize
891 yyyy-mm-dd hh:mm:ss:ffff. The timestamp is Coordinated Universal Time
892 (UTC; also known as Greenwich Mean Time [GMT]).
893 The only difference between ReadFile and ReadDirectory is the opcode used.
895 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance
896 @param Token Pointer to the token structure to provide the
897 parameters that are used in this function
899 @retval EFI_SUCCESS The MTFTPv4 related file "directory" has been downloaded.
900 @retval EFI_UNSUPPORTED The operation is not supported by this implementation.
901 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
904 3. Token.Filename is NULL.
905 4. Token.OptionCount is not zero and
906 Token.OptionList is NULL.
907 5. One or more options in Token.OptionList have wrong
909 6. Token.Buffer and Token.PacketNeeded are both
911 7. One or more IPv4 addresses in Token.OverrideData
912 are not valid unicast IPv4 addresses if
913 Token.OverrideData is not NULL.
914 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are in the
915 unsupported list of structure EFI_MTFTP4_MODE_DATA.
916 @retval EFI_NOT_STARTED The EFI MTFTPv4 Protocol driver has not been started.
917 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
918 BOOTP, RARP, etc.) is not finished yet.
919 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv4
921 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
922 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
923 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
928 EfiMtftp4ReadDirectory (
929 IN EFI_MTFTP4_PROTOCOL
*This
,
930 IN EFI_MTFTP4_TOKEN
*Token
933 return Mtftp4Start (This
, Token
, EFI_MTFTP4_OPCODE_DIR
);
938 Gets information about a file from an MTFTPv4 server.
940 The GetInfo() function assembles an MTFTPv4 request packet with options;
941 sends it to the MTFTPv4 server; and may return an MTFTPv4 OACK, MTFTPv4 ERROR,
942 or ICMP ERROR packet. Retries occur only if no response packets are received
943 from the MTFTPv4 server before the timeout expires.
944 It is implemented with EfiMtftp4ReadFile: build a token, then pass it to
945 EfiMtftp4ReadFile. In its check packet callback abort the opertions.
947 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance
948 @param OverrideData Data that is used to override the existing
949 parameters. If NULL, the default parameters that
950 were set in the EFI_MTFTP4_PROTOCOL.Configure()
952 @param Filename Pointer to null-terminated ASCII file name string
953 @param ModeStr Pointer to null-terminated ASCII mode string. If NULL, "octet"
955 @param OptionCount Number of option/value string pairs in OptionList
956 @param OptionList Pointer to array of option/value string pairs.
957 Ignored if OptionCount is zero
958 @param PacketLength The number of bytes in the returned packet
959 @param Packet PacketThe pointer to the received packet. This
960 buffer must be freed by the caller.
962 @retval EFI_SUCCESS An MTFTPv4 OACK packet was received and is in
964 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
967 3.OptionCount is not zero and OptionList is NULL.
968 4.One or more options in OptionList have wrong format.
969 5.PacketLength is NULL.
970 6.One or more IPv4 addresses in OverrideData are
971 not valid unicast IPv4 addresses if OverrideData
973 @retval EFI_UNSUPPORTED One or more options in the OptionList are in the
974 unsupported list of structure EFI_MTFTP4_MODE_DATA
975 @retval EFI_NOT_STARTED The EFI MTFTPv4 Protocol driver has not been started.
976 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
977 BOOTP, RARP, etc.) has not finished yet.
978 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
979 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
980 @retval EFI_TFTP_ERROR An MTFTPv4 ERROR packet was received and is in
982 @retval EFI_ICMP_ERROR An ICMP ERROR packet was received and the Packet
984 @retval EFI_PROTOCOL_ERROR An unexpected MTFTPv4 packet was received and is
986 @retval EFI_TIMEOUT No responses were received from the MTFTPv4 server.
987 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
988 @retval EFI_NO_MEDIA There was a media error.
994 IN EFI_MTFTP4_PROTOCOL
*This
,
995 IN EFI_MTFTP4_OVERRIDE_DATA
*OverrideData OPTIONAL
,
997 IN UINT8
*ModeStr OPTIONAL
,
998 IN UINT8 OptionCount
,
999 IN EFI_MTFTP4_OPTION
*OptionList OPTIONAL
,
1000 OUT UINT32
*PacketLength
,
1001 OUT EFI_MTFTP4_PACKET
**Packet OPTIONAL
1004 EFI_MTFTP4_TOKEN Token
;
1005 MTFTP4_GETINFO_STATE State
;
1008 if ((This
== NULL
) || (Filename
== NULL
) || (PacketLength
== NULL
) ||
1009 ((OptionCount
!= 0) && (OptionList
== NULL
))) {
1010 return EFI_INVALID_PARAMETER
;
1013 if (Packet
!= NULL
) {
1018 State
.Packet
= Packet
;
1019 State
.PacketLen
= PacketLength
;
1020 State
.Status
= EFI_SUCCESS
;
1023 // Fill in the Token to issue an synchronous ReadFile operation
1025 Token
.Status
= EFI_SUCCESS
;
1027 Token
.OverrideData
= OverrideData
;
1028 Token
.Filename
= Filename
;
1029 Token
.ModeStr
= ModeStr
;
1030 Token
.OptionCount
= OptionCount
;
1031 Token
.OptionList
= OptionList
;
1032 Token
.BufferSize
= 0;
1033 Token
.Buffer
= NULL
;
1034 Token
.Context
= &State
;
1035 Token
.CheckPacket
= Mtftp4GetInfoCheckPacket
;
1036 Token
.TimeoutCallback
= NULL
;
1037 Token
.PacketNeeded
= NULL
;
1039 Status
= EfiMtftp4ReadFile (This
, &Token
);
1041 if (EFI_ABORTED
== Status
) {
1042 return State
.Status
;
1049 Polls for incoming data packets and processes outgoing data packets.
1051 The Poll() function can be used by network drivers and applications to increase
1052 the rate that data packets are moved between the communications device and the
1053 transmit and receive queues.
1054 In some systems, the periodic timer event in the managed network driver may not
1055 poll the underlying communications device fast enough to transmit and/or receive
1056 all data packets without missing incoming packets or dropping outgoing packets.
1057 Drivers and applications that are experiencing packet loss should try calling
1058 the Poll() function more often.
1060 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance
1062 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1063 @retval EFI_NOT_STARTED This EFI MTFTPv4 Protocol instance has not been started.
1064 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
1065 BOOTP, RARP, etc.) is not finished yet.
1066 @retval EFI_INVALID_PARAMETER This is NULL.
1067 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1068 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive
1069 queue. Consider increasing the polling rate.
1075 IN EFI_MTFTP4_PROTOCOL
*This
1078 MTFTP4_PROTOCOL
*Instance
;
1079 EFI_UDP4_PROTOCOL
*Udp
;
1082 return EFI_INVALID_PARAMETER
;
1085 Instance
= MTFTP4_PROTOCOL_FROM_THIS (This
);
1087 if (Instance
->State
== MTFTP4_STATE_UNCONFIGED
) {
1088 return EFI_NOT_STARTED
;
1089 } else if (Instance
->State
== MTFTP4_STATE_DESTROY
) {
1090 return EFI_DEVICE_ERROR
;
1093 Udp
= Instance
->UnicastPort
->Protocol
.Udp4
;
1094 return Udp
->Poll (Udp
);
1097 EFI_MTFTP4_PROTOCOL gMtftp4ProtocolTemplate
= {
1098 EfiMtftp4GetModeData
,
1101 EfiMtftp4ParseOptions
,
1104 EfiMtftp4ReadDirectory
,