2 Interface routine for Mtftp4.
4 Copyright (c) 2006 - 2009, Intel Corporation<BR>
5 All rights reserved. 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 UdpIoCleanPort (Instance
->UnicastPort
);
55 if (Instance
->LastPacket
!= NULL
) {
56 NetbufFree (Instance
->LastPacket
);
57 Instance
->LastPacket
= NULL
;
60 if (Instance
->McastUdpPort
!= NULL
) {
61 UdpIoFreePort (Instance
->McastUdpPort
);
62 Instance
->McastUdpPort
= NULL
;
65 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &Instance
->Blocks
) {
66 Block
= NET_LIST_USER_STRUCT (Entry
, MTFTP4_BLOCK_RANGE
, Link
);
67 RemoveEntryList (Entry
);
68 gBS
->FreePool (Block
);
71 ZeroMem (&Instance
->RequestOption
, sizeof (MTFTP4_OPTION
));
73 Instance
->Operation
= 0;
75 Instance
->BlkSize
= MTFTP4_DEFAULT_BLKSIZE
;
76 Instance
->LastBlock
= 0;
77 Instance
->ServerIp
= 0;
78 Instance
->ListeningPort
= 0;
79 Instance
->ConnectedPort
= 0;
80 Instance
->Gateway
= 0;
81 Instance
->PacketToLive
= 0;
82 Instance
->MaxRetry
= 0;
83 Instance
->CurRetry
= 0;
84 Instance
->Timeout
= 0;
85 Instance
->McastIp
= 0;
86 Instance
->McastPort
= 0;
87 Instance
->Master
= TRUE
;
92 Check packet for GetInfo.
94 GetInfo is implemented with EfiMtftp4ReadFile. It use Mtftp4GetInfoCheckPacket
95 to inspect the first packet from server, then abort the session.
97 @param This The MTFTP4 protocol instance
98 @param Token The user's token
99 @param PacketLen The length of the packet
100 @param Packet The received packet.
102 @retval EFI_ABORTED Abort the ReadFile operation and return.
107 Mtftp4GetInfoCheckPacket (
108 IN EFI_MTFTP4_PROTOCOL
*This
,
109 IN EFI_MTFTP4_TOKEN
*Token
,
111 IN EFI_MTFTP4_PACKET
*Packet
114 MTFTP4_GETINFO_STATE
*State
;
118 State
= (MTFTP4_GETINFO_STATE
*) Token
->Context
;
119 OpCode
= NTOHS (Packet
->OpCode
);
122 // Set the GetInfo's return status according to the OpCode.
125 case EFI_MTFTP4_OPCODE_ERROR
:
126 State
->Status
= EFI_TFTP_ERROR
;
129 case EFI_MTFTP4_OPCODE_OACK
:
130 State
->Status
= EFI_SUCCESS
;
134 State
->Status
= EFI_PROTOCOL_ERROR
;
138 // Allocate buffer then copy the packet over. Use gBS->AllocatePool
139 // in case AllocatePool will implements something tricky.
141 Status
= gBS
->AllocatePool (EfiBootServicesData
, PacketLen
, (VOID
**) State
->Packet
);
143 if (EFI_ERROR (Status
)) {
144 State
->Status
= EFI_OUT_OF_RESOURCES
;
148 *(State
->PacketLen
) = PacketLen
;
149 CopyMem (*(State
->Packet
), Packet
, PacketLen
);
156 Check whether the override data is valid.
158 It will first validate whether the server is a valid unicast. If a gateway
159 is provided in the Override, it also check that it is a unicast on the
162 @param Instance The MTFTP instance
163 @param Override The override data to validate.
165 @retval TRUE The override data is valid
166 @retval FALSE The override data is invalid
170 Mtftp4OverrideValid (
171 IN MTFTP4_PROTOCOL
*Instance
,
172 IN EFI_MTFTP4_OVERRIDE_DATA
*Override
175 EFI_MTFTP4_CONFIG_DATA
*Config
;
180 CopyMem (&Ip
, &Override
->ServerIp
, sizeof (IP4_ADDR
));
181 if (!Ip4IsUnicast (NTOHL (Ip
), 0)) {
185 Config
= &Instance
->Config
;
187 CopyMem (&Gateway
, &Override
->GatewayIp
, sizeof (IP4_ADDR
));
188 Gateway
= NTOHL (Gateway
);
190 if (!Config
->UseDefaultSetting
&& (Gateway
!= 0)) {
191 CopyMem (&Netmask
, &Config
->SubnetMask
, sizeof (IP4_ADDR
));
192 CopyMem (&Ip
, &Config
->StationIp
, sizeof (IP4_ADDR
));
194 Netmask
= NTOHL (Netmask
);
197 if (!Ip4IsUnicast (Gateway
, Netmask
) || !IP4_NET_EQUAL (Gateway
, Ip
, Netmask
)) {
207 Poll the UDP to get the IP4 default address, which may be retrieved
210 The default time out value is 5 seconds. If IP has retrieved the default address,
211 the UDP is reconfigured.
213 @param Instance The Mtftp instance
214 @param UdpPort The UDP port to poll
215 @param UdpCfgData The UDP configure data to reconfigure the UDP
218 @retval TRUE The default address is retrieved and UDP is reconfigured.
219 @retval FALSE Some error occured.
224 IN MTFTP4_PROTOCOL
*Instance
,
225 IN UDP_IO_PORT
*UdpPort
,
226 IN EFI_UDP4_CONFIG_DATA
*UdpCfgData
229 MTFTP4_SERVICE
*Service
;
230 EFI_IP4_MODE_DATA Ip4Mode
;
231 EFI_UDP4_PROTOCOL
*Udp
;
234 ASSERT (Instance
->Config
.UseDefaultSetting
);
236 Service
= Instance
->Service
;
239 Status
= gBS
->SetTimer (
240 Service
->TimerToGetMap
,
242 MTFTP4_TIME_TO_GETMAP
* TICKS_PER_SECOND
244 if (EFI_ERROR (Status
)) {
248 while (!EFI_ERROR (gBS
->CheckEvent (Service
->TimerToGetMap
))) {
251 if (!EFI_ERROR (Udp
->GetModeData (Udp
, NULL
, &Ip4Mode
, NULL
, NULL
)) &&
252 Ip4Mode
.IsConfigured
) {
254 Udp
->Configure (Udp
, NULL
);
255 return (BOOLEAN
) (Udp
->Configure (Udp
, UdpCfgData
) == EFI_SUCCESS
);
264 Configure the UDP port for unicast receiving.
266 @param UdpIo The UDP port
267 @param Instance The MTFTP session
269 @retval EFI_SUCCESS The UDP port is successfully configured for the
270 session to unicast receive.
274 Mtftp4ConfigUnicastPort (
275 IN UDP_IO_PORT
*UdpIo
,
276 IN MTFTP4_PROTOCOL
*Instance
279 EFI_MTFTP4_CONFIG_DATA
*Config
;
280 EFI_UDP4_CONFIG_DATA UdpConfig
;
284 Config
= &Instance
->Config
;
286 UdpConfig
.AcceptBroadcast
= FALSE
;
287 UdpConfig
.AcceptPromiscuous
= FALSE
;
288 UdpConfig
.AcceptAnyPort
= FALSE
;
289 UdpConfig
.AllowDuplicatePort
= FALSE
;
290 UdpConfig
.TypeOfService
= 0;
291 UdpConfig
.TimeToLive
= 64;
292 UdpConfig
.DoNotFragment
= FALSE
;
293 UdpConfig
.ReceiveTimeout
= 0;
294 UdpConfig
.TransmitTimeout
= 0;
295 UdpConfig
.UseDefaultAddress
= Config
->UseDefaultSetting
;
296 UdpConfig
.StationAddress
= Config
->StationIp
;
297 UdpConfig
.SubnetMask
= Config
->SubnetMask
;
298 UdpConfig
.StationPort
= 0;
299 UdpConfig
.RemotePort
= 0;
301 Ip
= HTONL (Instance
->ServerIp
);
302 CopyMem (&UdpConfig
.RemoteAddress
, &Ip
, sizeof (EFI_IPv4_ADDRESS
));
304 Status
= UdpIo
->Udp
->Configure (UdpIo
->Udp
, &UdpConfig
);
306 if ((Status
== EFI_NO_MAPPING
) && Mtftp4GetMapping (Instance
, UdpIo
, &UdpConfig
)) {
310 if (!Config
->UseDefaultSetting
&& !EFI_IP4_EQUAL (&mZeroIp4Addr
, &Config
->GatewayIp
)) {
312 // The station IP address is manually configured and the Gateway IP is not 0.
313 // Add the default route for this UDP instance.
315 Status
= UdpIo
->Udp
->Routes (UdpIo
->Udp
, FALSE
, &mZeroIp4Addr
, &mZeroIp4Addr
, &Config
->GatewayIp
);
316 if (EFI_ERROR (Status
)) {
317 UdpIo
->Udp
->Configure (UdpIo
->Udp
, NULL
);
325 Start the MTFTP session to do the operation, such as read file,
326 write file, and read directory.
328 @param This The MTFTP session
329 @param Token The token than encapsues the user's request.
330 @param Operation The operation to do
332 @retval EFI_INVALID_PARAMETER Some of the parameters are invalid.
333 @retval EFI_NOT_STARTED The MTFTP session hasn't been configured.
334 @retval EFI_ALREADY_STARTED There is pending operation for the session.
335 @retval EFI_SUCCESS The operation is successfully started.
340 IN EFI_MTFTP4_PROTOCOL
*This
,
341 IN EFI_MTFTP4_TOKEN
*Token
,
345 MTFTP4_PROTOCOL
*Instance
;
346 EFI_MTFTP4_OVERRIDE_DATA
*Override
;
347 EFI_MTFTP4_CONFIG_DATA
*Config
;
352 // Validate the parameters
354 if ((This
== NULL
) || (Token
== NULL
) || (Token
->Filename
== NULL
) ||
355 ((Token
->OptionCount
!= 0) && (Token
->OptionList
== NULL
))) {
356 return EFI_INVALID_PARAMETER
;
360 // User must provide at least one method to collect the data for download.
362 if (((Operation
== EFI_MTFTP4_OPCODE_RRQ
) || (Operation
== EFI_MTFTP4_OPCODE_DIR
)) &&
363 ((Token
->Buffer
== NULL
) && (Token
->CheckPacket
== NULL
))) {
364 return EFI_INVALID_PARAMETER
;
368 // User must provide at least one method to provide the data for upload.
370 if ((Operation
== EFI_MTFTP4_OPCODE_WRQ
) &&
371 ((Token
->Buffer
== NULL
) && (Token
->PacketNeeded
== NULL
))) {
372 return EFI_INVALID_PARAMETER
;
375 Instance
= MTFTP4_PROTOCOL_FROM_THIS (This
);
377 Status
= EFI_SUCCESS
;
378 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
380 if (Instance
->State
!= MTFTP4_STATE_CONFIGED
) {
381 Status
= EFI_NOT_STARTED
;
384 if (Instance
->Operation
!= 0) {
385 Status
= EFI_ACCESS_DENIED
;
388 if (EFI_ERROR (Status
)) {
389 gBS
->RestoreTPL (OldTpl
);
394 // Set the Operation now to prevent the application start other
397 Instance
->Operation
= Operation
;
398 Override
= Token
->OverrideData
;
400 if ((Override
!= NULL
) && !Mtftp4OverrideValid (Instance
, Override
)) {
401 Status
= EFI_INVALID_PARAMETER
;
405 if (Token
->OptionCount
!= 0) {
406 Status
= Mtftp4ParseOption (
410 &Instance
->RequestOption
413 if (EFI_ERROR (Status
)) {
419 // Set the operation parameters from the configuration or override data.
421 Config
= &Instance
->Config
;
422 Instance
->Token
= Token
;
423 Instance
->BlkSize
= MTFTP4_DEFAULT_BLKSIZE
;
425 CopyMem (&Instance
->ServerIp
, &Config
->ServerIp
, sizeof (IP4_ADDR
));
426 Instance
->ServerIp
= NTOHL (Instance
->ServerIp
);
428 Instance
->ListeningPort
= Config
->InitialServerPort
;
429 Instance
->ConnectedPort
= 0;
431 CopyMem (&Instance
->Gateway
, &Config
->GatewayIp
, sizeof (IP4_ADDR
));
432 Instance
->Gateway
= NTOHL (Instance
->Gateway
);
434 Instance
->MaxRetry
= Config
->TryCount
;
435 Instance
->Timeout
= Config
->TimeoutValue
;
436 Instance
->Master
= TRUE
;
438 if (Override
!= NULL
) {
439 CopyMem (&Instance
->ServerIp
, &Override
->ServerIp
, sizeof (IP4_ADDR
));
440 CopyMem (&Instance
->Gateway
, &Override
->GatewayIp
, sizeof (IP4_ADDR
));
442 Instance
->ServerIp
= NTOHL (Instance
->ServerIp
);
443 Instance
->Gateway
= NTOHL (Instance
->Gateway
);
445 Instance
->ListeningPort
= Override
->ServerPort
;
446 Instance
->MaxRetry
= Override
->TryCount
;
447 Instance
->Timeout
= Override
->TimeoutValue
;
450 if (Instance
->ListeningPort
== 0) {
451 Instance
->ListeningPort
= MTFTP4_DEFAULT_SERVER_PORT
;
454 if (Instance
->MaxRetry
== 0) {
455 Instance
->MaxRetry
= MTFTP4_DEFAULT_RETRY
;
458 if (Instance
->Timeout
== 0) {
459 Instance
->Timeout
= MTFTP4_DEFAULT_TIMEOUT
;
463 // Config the unicast UDP child to send initial request
465 Status
= Mtftp4ConfigUnicastPort (Instance
->UnicastPort
, Instance
);
467 if (EFI_ERROR (Status
)) {
472 // Set initial status.
474 Token
->Status
= EFI_NOT_READY
;
477 // Build and send an initial requests
479 if (Operation
== EFI_MTFTP4_OPCODE_WRQ
) {
480 Status
= Mtftp4WrqStart (Instance
, Operation
);
482 Status
= Mtftp4RrqStart (Instance
, Operation
);
485 gBS
->RestoreTPL (OldTpl
);
487 if (EFI_ERROR (Status
)) {
491 if (Token
->Event
!= NULL
) {
496 // Return immediately for asynchronous operation or poll the
497 // instance for synchronous operation.
499 while (Token
->Status
== EFI_NOT_READY
) {
503 return Token
->Status
;
506 Mtftp4CleanOperation (Instance
, Status
);
507 gBS
->RestoreTPL (OldTpl
);
514 Reads the current operational settings.
516 The GetModeData()function reads the current operational settings of this
517 EFI MTFTPv4 Protocol driver instance.
519 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance.
520 @param ModeData Pointer to storage for the EFI MTFTPv4 Protocol
523 @retval EFI_SUCCESS The configuration data was successfully returned.
524 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.
525 @retval EFI_INVALID_PARAMETER This is NULL or ModeData is NULL.
530 EfiMtftp4GetModeData (
531 IN EFI_MTFTP4_PROTOCOL
*This
,
532 OUT EFI_MTFTP4_MODE_DATA
*ModeData
535 MTFTP4_PROTOCOL
*Instance
;
538 if ((This
== NULL
) || (ModeData
== NULL
)) {
539 return EFI_INVALID_PARAMETER
;
542 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
544 Instance
= MTFTP4_PROTOCOL_FROM_THIS (This
);
545 CopyMem(&ModeData
->ConfigData
, &Instance
->Config
, sizeof (Instance
->Config
));
546 ModeData
->SupportedOptionCount
= MTFTP4_SUPPORTED_OPTIONS
;
547 ModeData
->SupportedOptoins
= (UINT8
**) mMtftp4SupportedOptions
;
548 ModeData
->UnsupportedOptionCount
= 0;
549 ModeData
->UnsupportedOptoins
= NULL
;
551 gBS
->RestoreTPL (OldTpl
);
559 Initializes, changes, or resets the default operational setting for this
560 EFI MTFTPv4 Protocol driver instance.
562 The Configure() function is used to set and change the configuration data for
563 this EFI MTFTPv4 Protocol driver instance. The configuration data can be reset
564 to startup defaults by calling Configure() with MtftpConfigData set to NULL.
565 Whenever the instance is reset, any pending operation is aborted. By changing
566 the EFI MTFTPv4 Protocol driver instance configuration data, the client can
567 connect to different MTFTPv4 servers. The configuration parameters in
568 MtftpConfigData are used as the default parameters in later MTFTPv4 operations
569 and can be overridden in later operations.
571 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance
572 @param ConfigData MtftpConfigDataPointer to the configuration data
575 @retval EFI_SUCCESS The EFI MTFTPv4 Protocol driver was configured
577 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
579 2.MtftpConfigData.UseDefaultSetting is FALSE and
580 MtftpConfigData.StationIp is not a valid IPv4
582 3.MtftpCofigData.UseDefaultSetting is FALSE and
583 MtftpConfigData.SubnetMask is invalid.
584 4.MtftpCofigData.ServerIp is not a valid IPv4
586 5.MtftpConfigData.UseDefaultSetting is FALSE and
587 MtftpConfigData.GatewayIp is not a valid IPv4
588 unicast address or is not in the same subnet
589 with station address.
590 @retval EFI_ACCESS_DENIED The EFI configuration could not be changed at this
591 time because there is one MTFTP background operation
593 @retval EFI_NO_MAPPING When using a default address, configuration
594 (DHCP, BOOTP, RARP, etc.) has not finished yet.
595 @retval EFI_UNSUPPORTED A configuration protocol (DHCP, BOOTP, RARP, etc.)
596 could not be located when clients choose to use
597 the default address settings.
598 @retval EFI_OUT_OF_RESOURCES The EFI MTFTPv4 Protocol driver instance data could
600 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
601 The EFI MTFTPv4 Protocol driver instance is not
608 IN EFI_MTFTP4_PROTOCOL
*This
,
609 IN EFI_MTFTP4_CONFIG_DATA
*ConfigData
612 MTFTP4_PROTOCOL
*Instance
;
620 return EFI_INVALID_PARAMETER
;
623 Instance
= MTFTP4_PROTOCOL_FROM_THIS (This
);
625 if (ConfigData
== NULL
) {
627 // Reset the operation if ConfigData is NULL
629 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
631 Mtftp4CleanOperation (Instance
, EFI_ABORTED
);
632 ZeroMem (&Instance
->Config
, sizeof (EFI_MTFTP4_CONFIG_DATA
));
633 Instance
->State
= MTFTP4_STATE_UNCONFIGED
;
635 gBS
->RestoreTPL (OldTpl
);
639 // Configure the parameters for new operation.
641 CopyMem (&Ip
, &ConfigData
->StationIp
, sizeof (IP4_ADDR
));
642 CopyMem (&Netmask
, &ConfigData
->SubnetMask
, sizeof (IP4_ADDR
));
643 CopyMem (&Gateway
, &ConfigData
->GatewayIp
, sizeof (IP4_ADDR
));
644 CopyMem (&ServerIp
, &ConfigData
->ServerIp
, sizeof (IP4_ADDR
));
647 Netmask
= NTOHL (Netmask
);
648 Gateway
= NTOHL (Gateway
);
649 ServerIp
= NTOHL (ServerIp
);
651 if (!Ip4IsUnicast (ServerIp
, 0)) {
652 return EFI_INVALID_PARAMETER
;
655 if (!ConfigData
->UseDefaultSetting
&&
656 ((!IP4_IS_VALID_NETMASK (Netmask
) || !Ip4IsUnicast (Ip
, Netmask
)))) {
658 return EFI_INVALID_PARAMETER
;
661 if ((Gateway
!= 0) &&
662 (!IP4_NET_EQUAL (Gateway
, Ip
, Netmask
) || !Ip4IsUnicast (Gateway
, Netmask
))) {
664 return EFI_INVALID_PARAMETER
;
667 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
669 if ((Instance
->State
== MTFTP4_STATE_CONFIGED
) && (Instance
->Operation
!= 0)) {
670 gBS
->RestoreTPL (OldTpl
);
671 return EFI_ACCESS_DENIED
;
674 CopyMem(&Instance
->Config
, ConfigData
, sizeof (*ConfigData
));;
675 Instance
->State
= MTFTP4_STATE_CONFIGED
;
677 gBS
->RestoreTPL (OldTpl
);
686 Parses the options in an MTFTPv4 OACK packet.
688 The ParseOptions() function parses the option fields in an MTFTPv4 OACK packet
689 and returns the number of options that were found and optionally a list of
690 pointers to the options in the packet.
691 If one or more of the option fields are not valid, then EFI_PROTOCOL_ERROR is
692 returned and *OptionCount and *OptionList stop at the last valid option.
693 The OptionList is allocated by this function, and caller should free it when used.
695 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance.
696 @param PacketLen Length of the OACK packet to be parsed.
697 @param Packet Pointer to the OACK packet to be parsed.
698 @param OptionCount Pointer to the number of options in following OptionList.
699 @param OptionList Pointer to EFI_MTFTP4_OPTION storage. Call the
700 EFI Boot Service FreePool() to release theOptionList
701 if the options in this OptionList are not needed
704 @retval EFI_SUCCESS The OACK packet was valid and the OptionCount and
705 OptionList parameters have been updated.
706 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
708 2.Packet is NULL or Packet is not a valid MTFTPv4 packet.
709 3.OptionCount is NULL.
710 @retval EFI_NOT_FOUND No options were found in the OACK packet.
711 @retval EFI_OUT_OF_RESOURCES Storage for the OptionList array cannot be allocated.
712 @retval EFI_PROTOCOL_ERROR One or more of the option fields is invalid.
717 EfiMtftp4ParseOptions (
718 IN EFI_MTFTP4_PROTOCOL
*This
,
720 IN EFI_MTFTP4_PACKET
*Packet
,
721 OUT UINT32
*OptionCount
,
722 OUT EFI_MTFTP4_OPTION
**OptionList OPTIONAL
727 if ((This
== NULL
) || (PacketLen
< MTFTP4_OPCODE_LEN
) ||
728 (Packet
== NULL
) || (OptionCount
== NULL
)) {
730 return EFI_INVALID_PARAMETER
;
733 Status
= Mtftp4ExtractOptions (Packet
, PacketLen
, OptionCount
, OptionList
);
735 if (EFI_ERROR (Status
)) {
739 if (*OptionCount
== 0) {
740 return EFI_NOT_FOUND
;
748 Downloads a file from an MTFTPv4 server.
750 The ReadFile() function is used to initialize and start an MTFTPv4 download
751 process and optionally wait for completion. When the download operation completes,
752 whether successfully or not, the Token.Status field is updated by the EFI MTFTPv4
753 Protocol driver and then Token.Event is signaled (if it is not NULL).
754 Data can be downloaded from the MTFTPv4 server into either of the following locations:
755 1.A fixed buffer that is pointed to by Token.Buffer
756 2.A download service function that is pointed to by Token.CheckPacket
757 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket
758 will be called first. If the call is successful, the packet will be stored in
761 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance
762 @param Token Pointer to the token structure to provide the
763 parameters that are used in this operation.
765 @retval EFI_SUCCESS The data file has been transferred successfully.
766 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
767 @retval EFI_BUFFER_TOO_SMALL BufferSize is not large enough to hold the downloaded
768 data in downloading process.
769 @retval EFI_ABORTED Current operation is aborted by user.
770 @retval EFI_ICMP_ERROR An ICMP ERROR packet was received.
771 @retval EFI_TIMEOUT No responses were received from the MTFTPv4 server.
772 @retval EFI_TFTP_ERROR An MTFTPv4 ERROR packet was received.
773 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
779 IN EFI_MTFTP4_PROTOCOL
*This
,
780 IN EFI_MTFTP4_TOKEN
*Token
783 return Mtftp4Start (This
, Token
, EFI_MTFTP4_OPCODE_RRQ
);
788 Sends a data file to an MTFTPv4 server. May be unsupported in some EFI implementations
790 The WriteFile() function is used to initialize an uploading operation with the
791 given option list and optionally wait for completion. If one or more of the
792 options is not supported by the server, the unsupported options are ignored and
793 a standard TFTP process starts instead. When the upload process completes,
794 whether successfully or not, Token.Event is signaled, and the EFI MTFTPv4 Protocol
795 driver updates Token.Status.
796 The caller can supply the data to be uploaded in the following two modes:
797 1.Through the user-provided buffer
798 2.Through a callback function
799 With the user-provided buffer, the Token.BufferSize field indicates the length
800 of the buffer, and the driver will upload the data in the buffer. With an
801 EFI_MTFTP4_PACKET_NEEDED callback function, the driver will call this callback
802 function to get more data from the user to upload. See the definition of
803 EFI_MTFTP4_PACKET_NEEDED for more information. These two modes cannot be used at
804 the same time. The callback function will be ignored if the user provides the buffer.
806 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance.
807 @param Token Pointer to the token structure to provide the
808 parameters that are used in this function
810 @retval EFI_SUCCESS The upload session has started.
811 @retval EFI_UNSUPPORTED The operation is not supported by this implementation.
812 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
815 3. Token.Filename is NULL.
816 4. Token.OptionCount is not zero and
817 Token.OptionList is NULL.
818 5. One or more options in Token.OptionList have wrong
820 6. Token.Buffer and Token.PacketNeeded are both
822 7. One or more IPv4 addresses in Token.OverrideData
823 are not valid unicast IPv4 addresses if
824 Token.OverrideData is not NULL.
825 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are in the
826 unsupported list of structure EFI_MTFTP4_MODE_DATA.
827 @retval EFI_NOT_STARTED The EFI MTFTPv4 Protocol driver has not been started.
828 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
829 BOOTP, RARP, etc.) is not finished yet.
830 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv4
832 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
833 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
834 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
840 IN EFI_MTFTP4_PROTOCOL
*This
,
841 IN EFI_MTFTP4_TOKEN
*Token
844 return Mtftp4Start (This
, Token
, EFI_MTFTP4_OPCODE_WRQ
);
849 Downloads a data file "directory" from an MTFTPv4 server.
850 May be unsupported in some EFI implementations
852 The ReadDirectory() function is used to return a list of files on the MTFTPv4
853 server that are logically (or operationally) related to Token.Filename. The
854 directory request packet that is sent to the server is built with the option
855 list that was provided by caller, if present.
856 The file information that the server returns is put into either of the following
858 1.A fixed buffer that is pointed to by Token.Buffer
859 2.A download service function that is pointed to by Token.CheckPacket
860 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket will
861 be called first. If the call is successful, the packet will be stored in Token.Buffer.
862 The returned directory listing in the Token.Buffer or EFI_MTFTP4_PACKET consists
863 of a list of two or three variable-length ASCII strings, each terminated by a
864 null character, for each file in the directory. If the multicast option is involved,
865 the first field of each directory entry is the static multicast IP address and
866 UDP port number that is associated with the file name. The format of the field
867 is ip:ip:ip:ip:port. If the multicast option is not involved, this field and its
868 terminating null character are not present.
869 The next field of each directory entry is the file name and the last field is
870 the file information string. The information string contains the file size and
871 the create/modify timestamp. The format of the information string is filesize
872 yyyy-mm-dd hh:mm:ss:ffff. The timestamp is Coordinated Universal Time
873 (UTC; also known as Greenwich Mean Time [GMT]).
874 The only difference between ReadFile and ReadDirectory is the opcode used.
876 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance
877 @param Token Pointer to the token structure to provide the
878 parameters that are used in this function
880 @retval EFI_SUCCESS The MTFTPv4 related file "directory" has been downloaded.
881 @retval EFI_UNSUPPORTED The operation is not supported by this implementation.
882 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
885 3. Token.Filename is NULL.
886 4. Token.OptionCount is not zero and
887 Token.OptionList is NULL.
888 5. One or more options in Token.OptionList have wrong
890 6. Token.Buffer and Token.PacketNeeded are both
892 7. One or more IPv4 addresses in Token.OverrideData
893 are not valid unicast IPv4 addresses if
894 Token.OverrideData is not NULL.
895 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are in the
896 unsupported list of structure EFI_MTFTP4_MODE_DATA.
897 @retval EFI_NOT_STARTED The EFI MTFTPv4 Protocol driver has not been started.
898 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
899 BOOTP, RARP, etc.) is not finished yet.
900 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv4
902 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
903 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
904 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
909 EfiMtftp4ReadDirectory (
910 IN EFI_MTFTP4_PROTOCOL
*This
,
911 IN EFI_MTFTP4_TOKEN
*Token
914 return Mtftp4Start (This
, Token
, EFI_MTFTP4_OPCODE_DIR
);
919 Gets information about a file from an MTFTPv4 server.
921 The GetInfo() function assembles an MTFTPv4 request packet with options;
922 sends it to the MTFTPv4 server; and may return an MTFTPv4 OACK, MTFTPv4 ERROR,
923 or ICMP ERROR packet. Retries occur only if no response packets are received
924 from the MTFTPv4 server before the timeout expires.
925 It is implemented with EfiMtftp4ReadFile: build a token, then pass it to
926 EfiMtftp4ReadFile. In its check packet callback abort the opertions.
928 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance
929 @param OverrideData Data that is used to override the existing
930 parameters. If NULL, the default parameters that
931 were set in the EFI_MTFTP4_PROTOCOL.Configure()
933 @param Filename Pointer to ASCIIZ file name string
934 @param ModeStr Pointer to ASCIIZ mode string. If NULL, "octet"
936 @param OptionCount Number of option/value string pairs in OptionList
937 @param OptionList Pointer to array of option/value string pairs.
938 Ignored if OptionCount is zero
939 @param PacketLength The number of bytes in the returned packet
940 @param Packet PacketThe pointer to the received packet. This
941 buffer must be freed by the caller.
943 @retval EFI_SUCCESS An MTFTPv4 OACK packet was received and is in
945 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
948 3.OptionCount is not zero and OptionList is NULL.
949 4.One or more options in OptionList have wrong format.
950 5.PacketLength is NULL.
951 6.One or more IPv4 addresses in OverrideData are
952 not valid unicast IPv4 addresses if OverrideData
954 @retval EFI_UNSUPPORTED One or more options in the OptionList are in the
955 unsupported list of structure EFI_MTFTP4_MODE_DATA
956 @retval EFI_NOT_STARTED The EFI MTFTPv4 Protocol driver has not been started.
957 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
958 BOOTP, RARP, etc.) has not finished yet.
959 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.
960 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
961 @retval EFI_TFTP_ERROR An MTFTPv4 ERROR packet was received and is in
963 @retval EFI_ICMP_ERROR An ICMP ERROR packet was received and the Packet
965 @retval EFI_PROTOCOL_ERROR An unexpected MTFTPv4 packet was received and is
967 @retval EFI_TIMEOUT No responses were received from the MTFTPv4 server.
968 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.
974 IN EFI_MTFTP4_PROTOCOL
*This
,
975 IN EFI_MTFTP4_OVERRIDE_DATA
*OverrideData OPTIONAL
,
977 IN UINT8
*ModeStr OPTIONAL
,
978 IN UINT8 OptionCount
,
979 IN EFI_MTFTP4_OPTION
*OptionList OPTIONAL
,
980 OUT UINT32
*PacketLength
,
981 OUT EFI_MTFTP4_PACKET
**Packet OPTIONAL
984 EFI_MTFTP4_TOKEN Token
;
985 MTFTP4_GETINFO_STATE State
;
988 if ((This
== NULL
) || (Filename
== NULL
) || (PacketLength
== NULL
) ||
989 ((OptionCount
!= 0) && (OptionList
== NULL
))) {
990 return EFI_INVALID_PARAMETER
;
993 if (Packet
!= NULL
) {
998 State
.Packet
= Packet
;
999 State
.PacketLen
= PacketLength
;
1000 State
.Status
= EFI_SUCCESS
;
1003 // Fill in the Token to issue an synchronous ReadFile operation
1005 Token
.Status
= EFI_SUCCESS
;
1007 Token
.OverrideData
= OverrideData
;
1008 Token
.Filename
= Filename
;
1009 Token
.ModeStr
= ModeStr
;
1010 Token
.OptionCount
= OptionCount
;
1011 Token
.OptionList
= OptionList
;
1012 Token
.BufferSize
= 0;
1013 Token
.Buffer
= NULL
;
1014 Token
.Context
= &State
;
1015 Token
.CheckPacket
= Mtftp4GetInfoCheckPacket
;
1016 Token
.TimeoutCallback
= NULL
;
1017 Token
.PacketNeeded
= NULL
;
1019 Status
= EfiMtftp4ReadFile (This
, &Token
);
1021 if (EFI_ABORTED
== Status
) {
1022 return State
.Status
;
1029 Polls for incoming data packets and processes outgoing data packets.
1031 The Poll() function can be used by network drivers and applications to increase
1032 the rate that data packets are moved between the communications device and the
1033 transmit and receive queues.
1034 In some systems, the periodic timer event in the managed network driver may not
1035 poll the underlying communications device fast enough to transmit and/or receive
1036 all data packets without missing incoming packets or dropping outgoing packets.
1037 Drivers and applications that are experiencing packet loss should try calling
1038 the Poll() function more often.
1040 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance
1042 @retval EFI_SUCCESS Incoming or outgoing data was processed.
1043 @retval EFI_NOT_STARTED This EFI MTFTPv4 Protocol instance has not been started.
1044 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,
1045 BOOTP, RARP, etc.) is not finished yet.
1046 @retval EFI_INVALID_PARAMETER This is NULL.
1047 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
1048 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive
1049 queue. Consider increasing the polling rate.
1055 IN EFI_MTFTP4_PROTOCOL
*This
1058 MTFTP4_PROTOCOL
*Instance
;
1059 EFI_UDP4_PROTOCOL
*Udp
;
1062 return EFI_INVALID_PARAMETER
;
1065 Instance
= MTFTP4_PROTOCOL_FROM_THIS (This
);
1067 if (Instance
->State
== MTFTP4_STATE_UNCONFIGED
) {
1068 return EFI_NOT_STARTED
;
1069 } else if (Instance
->State
== MTFTP4_STATE_DESTORY
) {
1070 return EFI_DEVICE_ERROR
;
1073 Udp
= Instance
->UnicastPort
->Udp
;
1074 return Udp
->Poll (Udp
);
1077 EFI_MTFTP4_PROTOCOL gMtftp4ProtocolTemplate
= {
1078 EfiMtftp4GetModeData
,
1081 EfiMtftp4ParseOptions
,
1084 EfiMtftp4ReadDirectory
,