Add 'file not found' debug message to MTFTP.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Impl.c
CommitLineData
772db4bb 1/** @file\r
dab714aa 2 Interface routine for Mtftp4.\r
3 \r
21def103 4Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
772db4bb 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
dab714aa 8http://opensource.org/licenses/bsd-license.php<BR>\r
772db4bb 9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
772db4bb 13**/\r
14\r
772db4bb 15\r
dab714aa 16#include "Mtftp4Impl.h"\r
772db4bb 17\r
18\r
772db4bb 19/**\r
20 Clean up the MTFTP session to get ready for new operation.\r
21\r
22 @param Instance The MTFTP session to clean up\r
23 @param Result The result to return to the caller who initiated\r
24 the operation.\r
772db4bb 25**/\r
26VOID\r
27Mtftp4CleanOperation (\r
dab714aa 28 IN OUT MTFTP4_PROTOCOL *Instance,\r
29 IN EFI_STATUS Result\r
772db4bb 30 )\r
31{\r
e48e37fc 32 LIST_ENTRY *Entry;\r
33 LIST_ENTRY *Next;\r
772db4bb 34 MTFTP4_BLOCK_RANGE *Block;\r
35 EFI_MTFTP4_TOKEN *Token;\r
36\r
37 //\r
38 // Free various resources.\r
39 //\r
40 Token = Instance->Token;\r
41\r
42 if (Token != NULL) {\r
43 Token->Status = Result;\r
44\r
45 if (Token->Event != NULL) {\r
46 gBS->SignalEvent (Token->Event);\r
47 }\r
48\r
49 Instance->Token = NULL;\r
50 }\r
51\r
52 ASSERT (Instance->UnicastPort != NULL);\r
b45b45b2 53 UdpIoCleanIo (Instance->UnicastPort);\r
772db4bb 54\r
55 if (Instance->LastPacket != NULL) {\r
56 NetbufFree (Instance->LastPacket);\r
57 Instance->LastPacket = NULL;\r
58 }\r
59\r
60 if (Instance->McastUdpPort != NULL) {\r
216f7970 61 gBS->CloseProtocol (\r
62 Instance->McastUdpPort->UdpHandle,\r
63 &gEfiUdp4ProtocolGuid,\r
64 gMtftp4DriverBinding.DriverBindingHandle,\r
65 Instance->Handle\r
66 );\r
b45b45b2 67 UdpIoFreeIo (Instance->McastUdpPort);\r
772db4bb 68 Instance->McastUdpPort = NULL;\r
69 }\r
70\r
71 NET_LIST_FOR_EACH_SAFE (Entry, Next, &Instance->Blocks) {\r
72 Block = NET_LIST_USER_STRUCT (Entry, MTFTP4_BLOCK_RANGE, Link);\r
e48e37fc 73 RemoveEntryList (Entry);\r
766c7483 74 FreePool (Block);\r
772db4bb 75 }\r
76\r
e48e37fc 77 ZeroMem (&Instance->RequestOption, sizeof (MTFTP4_OPTION));\r
772db4bb 78\r
79 Instance->Operation = 0;\r
80\r
81 Instance->BlkSize = MTFTP4_DEFAULT_BLKSIZE;\r
82 Instance->LastBlock = 0;\r
83 Instance->ServerIp = 0;\r
84 Instance->ListeningPort = 0;\r
85 Instance->ConnectedPort = 0;\r
86 Instance->Gateway = 0;\r
87 Instance->PacketToLive = 0;\r
88 Instance->MaxRetry = 0;\r
89 Instance->CurRetry = 0;\r
90 Instance->Timeout = 0;\r
91 Instance->McastIp = 0;\r
92 Instance->McastPort = 0;\r
93 Instance->Master = TRUE;\r
94}\r
95\r
96\r
772db4bb 97/**\r
dab714aa 98 Check packet for GetInfo. \r
99 \r
100 GetInfo is implemented with EfiMtftp4ReadFile. It use Mtftp4GetInfoCheckPacket \r
101 to inspect the first packet from server, then abort the session.\r
772db4bb 102\r
103 @param This The MTFTP4 protocol instance\r
104 @param Token The user's token\r
105 @param PacketLen The length of the packet\r
106 @param Packet The received packet.\r
107\r
108 @retval EFI_ABORTED Abort the ReadFile operation and return.\r
109\r
110**/\r
772db4bb 111EFI_STATUS\r
6d3ea23f 112EFIAPI\r
772db4bb 113Mtftp4GetInfoCheckPacket (\r
114 IN EFI_MTFTP4_PROTOCOL *This,\r
115 IN EFI_MTFTP4_TOKEN *Token,\r
116 IN UINT16 PacketLen,\r
117 IN EFI_MTFTP4_PACKET *Packet\r
118 )\r
119{\r
120 MTFTP4_GETINFO_STATE *State;\r
121 EFI_STATUS Status;\r
122 UINT16 OpCode;\r
21def103 123 EFI_MTFTP4_ERROR_HEADER *ErrorHeader;\r
772db4bb 124\r
ea886bef 125 State = (MTFTP4_GETINFO_STATE *) Token->Context;\r
a5867703 126 OpCode = NTOHS (Packet->OpCode);\r
772db4bb 127\r
128 //\r
129 // Set the GetInfo's return status according to the OpCode.\r
130 //\r
131 switch (OpCode) {\r
132 case EFI_MTFTP4_OPCODE_ERROR:\r
21def103
BJ
133 ErrorHeader = (EFI_MTFTP4_ERROR_HEADER *) Packet;\r
134 if (ErrorHeader->ErrorCode == EFI_MTFTP4_ERRORCODE_FILE_NOT_FOUND) {\r
135 DEBUG ((EFI_D_ERROR, "TFTP error code 1 (File Not Found)\n"));\r
136 } else {\r
137 DEBUG ((EFI_D_ERROR, "TFTP error code %d\n", ErrorHeader->ErrorCode));\r
138 }\r
772db4bb 139 State->Status = EFI_TFTP_ERROR;\r
140 break;\r
141\r
142 case EFI_MTFTP4_OPCODE_OACK:\r
143 State->Status = EFI_SUCCESS;\r
144 break;\r
145\r
146 default:\r
147 State->Status = EFI_PROTOCOL_ERROR;\r
148 }\r
149\r
150 //\r
151 // Allocate buffer then copy the packet over. Use gBS->AllocatePool\r
e48e37fc 152 // in case AllocatePool will implements something tricky.\r
772db4bb 153 //\r
154 Status = gBS->AllocatePool (EfiBootServicesData, PacketLen, (VOID **) State->Packet);\r
155\r
156 if (EFI_ERROR (Status)) {\r
157 State->Status = EFI_OUT_OF_RESOURCES;\r
158 return EFI_ABORTED;\r
159 }\r
160\r
161 *(State->PacketLen) = PacketLen;\r
e48e37fc 162 CopyMem (*(State->Packet), Packet, PacketLen);\r
772db4bb 163\r
164 return EFI_ABORTED;\r
165}\r
166\r
167\r
772db4bb 168/**\r
dab714aa 169 Check whether the override data is valid. \r
170 \r
171 It will first validate whether the server is a valid unicast. If a gateway\r
172 is provided in the Override, it also check that it is a unicast on the \r
173 connected network.\r
772db4bb 174\r
175 @param Instance The MTFTP instance\r
176 @param Override The override data to validate.\r
177\r
dab714aa 178 @retval TRUE The override data is valid\r
179 @retval FALSE The override data is invalid\r
180 \r
772db4bb 181**/\r
772db4bb 182BOOLEAN\r
183Mtftp4OverrideValid (\r
184 IN MTFTP4_PROTOCOL *Instance,\r
185 IN EFI_MTFTP4_OVERRIDE_DATA *Override\r
186 )\r
187{\r
188 EFI_MTFTP4_CONFIG_DATA *Config;\r
189 IP4_ADDR Ip;\r
190 IP4_ADDR Netmask;\r
191 IP4_ADDR Gateway;\r
192\r
e48e37fc 193 CopyMem (&Ip, &Override->ServerIp, sizeof (IP4_ADDR));\r
f6b7393c 194 if (!NetIp4IsUnicast (NTOHL (Ip), 0)) {\r
772db4bb 195 return FALSE;\r
196 }\r
197\r
198 Config = &Instance->Config;\r
199\r
e48e37fc 200 CopyMem (&Gateway, &Override->GatewayIp, sizeof (IP4_ADDR));\r
772db4bb 201 Gateway = NTOHL (Gateway);\r
202\r
203 if (!Config->UseDefaultSetting && (Gateway != 0)) {\r
e48e37fc 204 CopyMem (&Netmask, &Config->SubnetMask, sizeof (IP4_ADDR));\r
205 CopyMem (&Ip, &Config->StationIp, sizeof (IP4_ADDR));\r
772db4bb 206\r
207 Netmask = NTOHL (Netmask);\r
208 Ip = NTOHL (Ip);\r
209\r
f6b7393c 210 if (!NetIp4IsUnicast (Gateway, Netmask) || !IP4_NET_EQUAL (Gateway, Ip, Netmask)) {\r
772db4bb 211 return FALSE;\r
212 }\r
213 }\r
214\r
215 return TRUE;\r
216}\r
217\r
218\r
219/**\r
220 Poll the UDP to get the IP4 default address, which may be retrieved\r
dab714aa 221 by DHCP. \r
222 \r
223 The default time out value is 5 seconds. If IP has retrieved the default address, \r
224 the UDP is reconfigured.\r
772db4bb 225\r
226 @param Instance The Mtftp instance\r
b45b45b2 227 @param UdpIo The UDP_IO to poll\r
228 @param UdpCfgData The UDP configure data to reconfigure the UDP_IO\r
772db4bb 229\r
dab714aa 230 @retval TRUE The default address is retrieved and UDP is reconfigured.\r
231 @retval FALSE Some error occured.\r
772db4bb 232\r
233**/\r
234BOOLEAN\r
235Mtftp4GetMapping (\r
236 IN MTFTP4_PROTOCOL *Instance,\r
b45b45b2 237 IN UDP_IO *UdpIo,\r
772db4bb 238 IN EFI_UDP4_CONFIG_DATA *UdpCfgData\r
239 )\r
240{\r
241 MTFTP4_SERVICE *Service;\r
242 EFI_IP4_MODE_DATA Ip4Mode;\r
243 EFI_UDP4_PROTOCOL *Udp;\r
244 EFI_STATUS Status;\r
245\r
246 ASSERT (Instance->Config.UseDefaultSetting);\r
247\r
248 Service = Instance->Service;\r
b45b45b2 249 Udp = UdpIo->Protocol.Udp4;\r
772db4bb 250\r
251 Status = gBS->SetTimer (\r
252 Service->TimerToGetMap,\r
253 TimerRelative,\r
254 MTFTP4_TIME_TO_GETMAP * TICKS_PER_SECOND\r
255 );\r
256 if (EFI_ERROR (Status)) {\r
257 return FALSE;\r
258 }\r
259\r
260 while (!EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) {\r
261 Udp->Poll (Udp);\r
262\r
263 if (!EFI_ERROR (Udp->GetModeData (Udp, NULL, &Ip4Mode, NULL, NULL)) &&\r
264 Ip4Mode.IsConfigured) {\r
265\r
266 Udp->Configure (Udp, NULL);\r
267 return (BOOLEAN) (Udp->Configure (Udp, UdpCfgData) == EFI_SUCCESS);\r
268 }\r
269 }\r
270\r
271 return FALSE;\r
272}\r
273\r
274\r
275/**\r
276 Configure the UDP port for unicast receiving.\r
277\r
b45b45b2 278 @param UdpIo The UDP_IO instance\r
772db4bb 279 @param Instance The MTFTP session\r
280\r
281 @retval EFI_SUCCESS The UDP port is successfully configured for the\r
282 session to unicast receive.\r
283\r
284**/\r
772db4bb 285EFI_STATUS\r
286Mtftp4ConfigUnicastPort (\r
b45b45b2 287 IN UDP_IO *UdpIo,\r
772db4bb 288 IN MTFTP4_PROTOCOL *Instance\r
289 )\r
290{\r
291 EFI_MTFTP4_CONFIG_DATA *Config;\r
292 EFI_UDP4_CONFIG_DATA UdpConfig;\r
293 EFI_STATUS Status;\r
294 IP4_ADDR Ip;\r
295\r
296 Config = &Instance->Config;\r
297\r
298 UdpConfig.AcceptBroadcast = FALSE;\r
299 UdpConfig.AcceptPromiscuous = FALSE;\r
300 UdpConfig.AcceptAnyPort = FALSE;\r
301 UdpConfig.AllowDuplicatePort = FALSE;\r
302 UdpConfig.TypeOfService = 0;\r
303 UdpConfig.TimeToLive = 64;\r
304 UdpConfig.DoNotFragment = FALSE;\r
305 UdpConfig.ReceiveTimeout = 0;\r
306 UdpConfig.TransmitTimeout = 0;\r
307 UdpConfig.UseDefaultAddress = Config->UseDefaultSetting;\r
308 UdpConfig.StationAddress = Config->StationIp;\r
309 UdpConfig.SubnetMask = Config->SubnetMask;\r
310 UdpConfig.StationPort = 0;\r
311 UdpConfig.RemotePort = 0;\r
312\r
313 Ip = HTONL (Instance->ServerIp);\r
e48e37fc 314 CopyMem (&UdpConfig.RemoteAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
772db4bb 315\r
b45b45b2 316 Status = UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfig);\r
772db4bb 317\r
318 if ((Status == EFI_NO_MAPPING) && Mtftp4GetMapping (Instance, UdpIo, &UdpConfig)) {\r
319 return EFI_SUCCESS;\r
320 }\r
321\r
c4a62a12 322 if (!Config->UseDefaultSetting && !EFI_IP4_EQUAL (&mZeroIp4Addr, &Config->GatewayIp)) {\r
323 //\r
324 // The station IP address is manually configured and the Gateway IP is not 0.\r
325 // Add the default route for this UDP instance.\r
326 //\r
b45b45b2 327 Status = UdpIo->Protocol.Udp4->Routes (\r
328 UdpIo->Protocol.Udp4,\r
329 FALSE,\r
330 &mZeroIp4Addr,\r
331 &mZeroIp4Addr,\r
332 &Config->GatewayIp\r
333 );\r
c4a62a12 334 if (EFI_ERROR (Status)) {\r
b45b45b2 335 UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, NULL);\r
c4a62a12 336 }\r
337 }\r
772db4bb 338 return Status;\r
339}\r
340\r
341\r
342/**\r
343 Start the MTFTP session to do the operation, such as read file,\r
344 write file, and read directory.\r
345\r
346 @param This The MTFTP session\r
347 @param Token The token than encapsues the user's request.\r
348 @param Operation The operation to do\r
349\r
350 @retval EFI_INVALID_PARAMETER Some of the parameters are invalid.\r
351 @retval EFI_NOT_STARTED The MTFTP session hasn't been configured.\r
352 @retval EFI_ALREADY_STARTED There is pending operation for the session.\r
353 @retval EFI_SUCCESS The operation is successfully started.\r
354\r
355**/\r
772db4bb 356EFI_STATUS\r
357Mtftp4Start (\r
358 IN EFI_MTFTP4_PROTOCOL *This,\r
359 IN EFI_MTFTP4_TOKEN *Token,\r
360 IN UINT16 Operation\r
361 )\r
362{\r
363 MTFTP4_PROTOCOL *Instance;\r
364 EFI_MTFTP4_OVERRIDE_DATA *Override;\r
365 EFI_MTFTP4_CONFIG_DATA *Config;\r
366 EFI_TPL OldTpl;\r
367 EFI_STATUS Status;\r
368\r
369 //\r
370 // Validate the parameters\r
371 //\r
372 if ((This == NULL) || (Token == NULL) || (Token->Filename == NULL) ||\r
373 ((Token->OptionCount != 0) && (Token->OptionList == NULL))) {\r
374 return EFI_INVALID_PARAMETER;\r
375 }\r
376\r
377 //\r
378 // User must provide at least one method to collect the data for download.\r
379 //\r
380 if (((Operation == EFI_MTFTP4_OPCODE_RRQ) || (Operation == EFI_MTFTP4_OPCODE_DIR)) &&\r
381 ((Token->Buffer == NULL) && (Token->CheckPacket == NULL))) {\r
382 return EFI_INVALID_PARAMETER;\r
383 }\r
384\r
385 //\r
386 // User must provide at least one method to provide the data for upload.\r
387 //\r
388 if ((Operation == EFI_MTFTP4_OPCODE_WRQ) &&\r
389 ((Token->Buffer == NULL) && (Token->PacketNeeded == NULL))) {\r
390 return EFI_INVALID_PARAMETER;\r
391 }\r
392\r
393 Instance = MTFTP4_PROTOCOL_FROM_THIS (This);\r
394\r
395 Status = EFI_SUCCESS;\r
e48e37fc 396 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
772db4bb 397\r
398 if (Instance->State != MTFTP4_STATE_CONFIGED) {\r
399 Status = EFI_NOT_STARTED;\r
400 }\r
401\r
402 if (Instance->Operation != 0) {\r
403 Status = EFI_ACCESS_DENIED;\r
404 }\r
405\r
406 if (EFI_ERROR (Status)) {\r
e48e37fc 407 gBS->RestoreTPL (OldTpl);\r
772db4bb 408 return Status;\r
409 }\r
410\r
411 //\r
412 // Set the Operation now to prevent the application start other\r
413 // operations.\r
414 //\r
415 Instance->Operation = Operation;\r
416 Override = Token->OverrideData;\r
417\r
418 if ((Override != NULL) && !Mtftp4OverrideValid (Instance, Override)) {\r
419 Status = EFI_INVALID_PARAMETER;\r
420 goto ON_ERROR;\r
421 }\r
422\r
423 if (Token->OptionCount != 0) {\r
424 Status = Mtftp4ParseOption (\r
425 Token->OptionList,\r
426 Token->OptionCount,\r
427 TRUE,\r
428 &Instance->RequestOption\r
429 );\r
430\r
431 if (EFI_ERROR (Status)) {\r
432 goto ON_ERROR;\r
433 }\r
434 }\r
435\r
436 //\r
437 // Set the operation parameters from the configuration or override data.\r
438 //\r
439 Config = &Instance->Config;\r
440 Instance->Token = Token;\r
441 Instance->BlkSize = MTFTP4_DEFAULT_BLKSIZE;\r
442\r
e48e37fc 443 CopyMem (&Instance->ServerIp, &Config->ServerIp, sizeof (IP4_ADDR));\r
772db4bb 444 Instance->ServerIp = NTOHL (Instance->ServerIp);\r
445\r
446 Instance->ListeningPort = Config->InitialServerPort;\r
447 Instance->ConnectedPort = 0;\r
448\r
e48e37fc 449 CopyMem (&Instance->Gateway, &Config->GatewayIp, sizeof (IP4_ADDR));\r
772db4bb 450 Instance->Gateway = NTOHL (Instance->Gateway);\r
451\r
452 Instance->MaxRetry = Config->TryCount;\r
453 Instance->Timeout = Config->TimeoutValue;\r
454 Instance->Master = TRUE;\r
455\r
456 if (Override != NULL) {\r
e48e37fc 457 CopyMem (&Instance->ServerIp, &Override->ServerIp, sizeof (IP4_ADDR));\r
458 CopyMem (&Instance->Gateway, &Override->GatewayIp, sizeof (IP4_ADDR));\r
772db4bb 459\r
460 Instance->ServerIp = NTOHL (Instance->ServerIp);\r
461 Instance->Gateway = NTOHL (Instance->Gateway);\r
462\r
463 Instance->ListeningPort = Override->ServerPort;\r
464 Instance->MaxRetry = Override->TryCount;\r
465 Instance->Timeout = Override->TimeoutValue;\r
466 }\r
467\r
468 if (Instance->ListeningPort == 0) {\r
469 Instance->ListeningPort = MTFTP4_DEFAULT_SERVER_PORT;\r
470 }\r
471\r
472 if (Instance->MaxRetry == 0) {\r
473 Instance->MaxRetry = MTFTP4_DEFAULT_RETRY;\r
474 }\r
475\r
476 if (Instance->Timeout == 0) {\r
477 Instance->Timeout = MTFTP4_DEFAULT_TIMEOUT;\r
478 }\r
479\r
480 //\r
481 // Config the unicast UDP child to send initial request\r
482 //\r
483 Status = Mtftp4ConfigUnicastPort (Instance->UnicastPort, Instance);\r
484\r
485 if (EFI_ERROR (Status)) {\r
486 goto ON_ERROR;\r
487 }\r
488\r
174f03d2 489 //\r
490 // Set initial status.\r
491 //\r
492 Token->Status = EFI_NOT_READY;\r
493\r
772db4bb 494 //\r
495 // Build and send an initial requests\r
496 //\r
497 if (Operation == EFI_MTFTP4_OPCODE_WRQ) {\r
498 Status = Mtftp4WrqStart (Instance, Operation);\r
499 } else {\r
500 Status = Mtftp4RrqStart (Instance, Operation);\r
501 }\r
502\r
e48e37fc 503 gBS->RestoreTPL (OldTpl);\r
772db4bb 504\r
505 if (EFI_ERROR (Status)) {\r
506 goto ON_ERROR;\r
507 }\r
772db4bb 508\r
509 if (Token->Event != NULL) {\r
510 return EFI_SUCCESS;\r
511 }\r
512\r
174f03d2 513 //\r
514 // Return immediately for asynchronous operation or poll the\r
515 // instance for synchronous operation.\r
516 //\r
772db4bb 517 while (Token->Status == EFI_NOT_READY) {\r
518 This->Poll (This);\r
519 }\r
520\r
521 return Token->Status;\r
522\r
523ON_ERROR:\r
524 Mtftp4CleanOperation (Instance, Status);\r
e48e37fc 525 gBS->RestoreTPL (OldTpl);\r
772db4bb 526\r
527 return Status;\r
528}\r
529\r
530\r
3dc3861a 531/**\r
532 Reads the current operational settings.\r
533\r
534 The GetModeData()function reads the current operational settings of this \r
535 EFI MTFTPv4 Protocol driver instance.\r
536\r
537 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance.\r
538 @param ModeData Pointer to storage for the EFI MTFTPv4 Protocol\r
539 driver mode data. \r
540\r
541 @retval EFI_SUCCESS The configuration data was successfully returned.\r
542 @retval EFI_OUT_OF_RESOURCES The required mode data could not be allocated.\r
543 @retval EFI_INVALID_PARAMETER This is NULL or ModeData is NULL.\r
544 \r
545**/\r
546EFI_STATUS\r
547EFIAPI\r
548EfiMtftp4GetModeData (\r
549 IN EFI_MTFTP4_PROTOCOL *This,\r
550 OUT EFI_MTFTP4_MODE_DATA *ModeData\r
551 )\r
552{\r
553 MTFTP4_PROTOCOL *Instance;\r
554 EFI_TPL OldTpl;\r
555\r
556 if ((This == NULL) || (ModeData == NULL)) {\r
557 return EFI_INVALID_PARAMETER;\r
558 }\r
559\r
560 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
561\r
562 Instance = MTFTP4_PROTOCOL_FROM_THIS (This);\r
563 CopyMem(&ModeData->ConfigData, &Instance->Config, sizeof (Instance->Config));\r
564 ModeData->SupportedOptionCount = MTFTP4_SUPPORTED_OPTIONS;\r
565 ModeData->SupportedOptoins = (UINT8 **) mMtftp4SupportedOptions;\r
566 ModeData->UnsupportedOptionCount = 0;\r
567 ModeData->UnsupportedOptoins = NULL;\r
568\r
569 gBS->RestoreTPL (OldTpl);\r
570\r
571 return EFI_SUCCESS;\r
572}\r
573\r
574\r
575\r
576/**\r
577 Initializes, changes, or resets the default operational setting for this \r
578 EFI MTFTPv4 Protocol driver instance.\r
579 \r
580 The Configure() function is used to set and change the configuration data for \r
581 this EFI MTFTPv4 Protocol driver instance. The configuration data can be reset \r
582 to startup defaults by calling Configure() with MtftpConfigData set to NULL. \r
583 Whenever the instance is reset, any pending operation is aborted. By changing \r
584 the EFI MTFTPv4 Protocol driver instance configuration data, the client can \r
585 connect to different MTFTPv4 servers. The configuration parameters in \r
586 MtftpConfigData are used as the default parameters in later MTFTPv4 operations \r
587 and can be overridden in later operations.\r
588 \r
589 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance\r
590 @param ConfigData MtftpConfigDataPointer to the configuration data \r
591 structure\r
592\r
593 @retval EFI_SUCCESS The EFI MTFTPv4 Protocol driver was configured \r
594 successfully.\r
595 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:\r
596 1.This is NULL.\r
597 2.MtftpConfigData.UseDefaultSetting is FALSE and \r
598 MtftpConfigData.StationIp is not a valid IPv4 \r
599 unicast address.\r
600 3.MtftpCofigData.UseDefaultSetting is FALSE and \r
601 MtftpConfigData.SubnetMask is invalid.\r
602 4.MtftpCofigData.ServerIp is not a valid IPv4 \r
603 unicast address.\r
604 5.MtftpConfigData.UseDefaultSetting is FALSE and \r
605 MtftpConfigData.GatewayIp is not a valid IPv4 \r
606 unicast address or is not in the same subnet \r
607 with station address.\r
608 @retval EFI_ACCESS_DENIED The EFI configuration could not be changed at this \r
609 time because there is one MTFTP background operation \r
610 in progress.\r
611 @retval EFI_NO_MAPPING When using a default address, configuration \r
612 (DHCP, BOOTP, RARP, etc.) has not finished yet.\r
613 @retval EFI_UNSUPPORTED A configuration protocol (DHCP, BOOTP, RARP, etc.) \r
614 could not be located when clients choose to use \r
615 the default address settings.\r
616 @retval EFI_OUT_OF_RESOURCES The EFI MTFTPv4 Protocol driver instance data could \r
617 not be allocated.\r
618 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. \r
619 The EFI MTFTPv4 Protocol driver instance is not \r
620 configured.\r
621\r
622**/\r
623EFI_STATUS\r
624EFIAPI\r
625EfiMtftp4Configure (\r
626 IN EFI_MTFTP4_PROTOCOL *This,\r
627 IN EFI_MTFTP4_CONFIG_DATA *ConfigData\r
628 )\r
629{\r
630 MTFTP4_PROTOCOL *Instance;\r
631 EFI_TPL OldTpl;\r
632 IP4_ADDR Ip;\r
633 IP4_ADDR Netmask;\r
634 IP4_ADDR Gateway;\r
635 IP4_ADDR ServerIp;\r
636\r
637 if (This == NULL) {\r
638 return EFI_INVALID_PARAMETER;\r
639 }\r
640\r
641 Instance = MTFTP4_PROTOCOL_FROM_THIS (This);\r
642\r
643 if (ConfigData == NULL) {\r
644 //\r
645 // Reset the operation if ConfigData is NULL\r
646 //\r
647 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
648\r
649 Mtftp4CleanOperation (Instance, EFI_ABORTED);\r
650 ZeroMem (&Instance->Config, sizeof (EFI_MTFTP4_CONFIG_DATA));\r
651 Instance->State = MTFTP4_STATE_UNCONFIGED;\r
652\r
653 gBS->RestoreTPL (OldTpl);\r
654\r
655 } else {\r
656 //\r
657 // Configure the parameters for new operation.\r
658 //\r
659 CopyMem (&Ip, &ConfigData->StationIp, sizeof (IP4_ADDR));\r
660 CopyMem (&Netmask, &ConfigData->SubnetMask, sizeof (IP4_ADDR));\r
661 CopyMem (&Gateway, &ConfigData->GatewayIp, sizeof (IP4_ADDR));\r
662 CopyMem (&ServerIp, &ConfigData->ServerIp, sizeof (IP4_ADDR));\r
663\r
664 Ip = NTOHL (Ip);\r
665 Netmask = NTOHL (Netmask);\r
666 Gateway = NTOHL (Gateway);\r
667 ServerIp = NTOHL (ServerIp);\r
668\r
f6b7393c 669 if (!NetIp4IsUnicast (ServerIp, 0)) {\r
3dc3861a 670 return EFI_INVALID_PARAMETER;\r
671 }\r
672\r
673 if (!ConfigData->UseDefaultSetting &&\r
f6b7393c 674 ((!IP4_IS_VALID_NETMASK (Netmask) || !NetIp4IsUnicast (Ip, Netmask)))) {\r
3dc3861a 675\r
676 return EFI_INVALID_PARAMETER;\r
677 }\r
678\r
679 if ((Gateway != 0) &&\r
f6b7393c 680 (!IP4_NET_EQUAL (Gateway, Ip, Netmask) || !NetIp4IsUnicast (Gateway, Netmask))) {\r
3dc3861a 681\r
682 return EFI_INVALID_PARAMETER;\r
683 }\r
684\r
685 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
686\r
687 if ((Instance->State == MTFTP4_STATE_CONFIGED) && (Instance->Operation != 0)) {\r
688 gBS->RestoreTPL (OldTpl);\r
689 return EFI_ACCESS_DENIED;\r
690 }\r
691\r
692 CopyMem(&Instance->Config, ConfigData, sizeof (*ConfigData));;\r
693 Instance->State = MTFTP4_STATE_CONFIGED;\r
694\r
695 gBS->RestoreTPL (OldTpl);\r
696 }\r
697\r
698 return EFI_SUCCESS;\r
699}\r
700\r
701\r
702\r
703/**\r
704 Parses the options in an MTFTPv4 OACK packet.\r
705 \r
706 The ParseOptions() function parses the option fields in an MTFTPv4 OACK packet \r
707 and returns the number of options that were found and optionally a list of \r
708 pointers to the options in the packet.\r
709 If one or more of the option fields are not valid, then EFI_PROTOCOL_ERROR is \r
710 returned and *OptionCount and *OptionList stop at the last valid option.\r
711 The OptionList is allocated by this function, and caller should free it when used.\r
712\r
713 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance.\r
714 @param PacketLen Length of the OACK packet to be parsed.\r
715 @param Packet Pointer to the OACK packet to be parsed. \r
716 @param OptionCount Pointer to the number of options in following OptionList.\r
717 @param OptionList Pointer to EFI_MTFTP4_OPTION storage. Call the \r
718 EFI Boot Service FreePool() to release theOptionList\r
719 if the options in this OptionList are not needed \r
720 any more\r
721\r
722 @retval EFI_SUCCESS The OACK packet was valid and the OptionCount and\r
723 OptionList parameters have been updated.\r
724 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
725 1.PacketLen is 0.\r
726 2.Packet is NULL or Packet is not a valid MTFTPv4 packet.\r
727 3.OptionCount is NULL.\r
728 @retval EFI_NOT_FOUND No options were found in the OACK packet.\r
729 @retval EFI_OUT_OF_RESOURCES Storage for the OptionList array cannot be allocated.\r
730 @retval EFI_PROTOCOL_ERROR One or more of the option fields is invalid.\r
731\r
732**/\r
733EFI_STATUS\r
734EFIAPI\r
735EfiMtftp4ParseOptions (\r
736 IN EFI_MTFTP4_PROTOCOL *This,\r
737 IN UINT32 PacketLen,\r
738 IN EFI_MTFTP4_PACKET *Packet,\r
739 OUT UINT32 *OptionCount,\r
740 OUT EFI_MTFTP4_OPTION **OptionList OPTIONAL\r
741 )\r
742{\r
743 EFI_STATUS Status;\r
744\r
745 if ((This == NULL) || (PacketLen < MTFTP4_OPCODE_LEN) ||\r
746 (Packet == NULL) || (OptionCount == NULL)) {\r
747\r
748 return EFI_INVALID_PARAMETER;\r
749 }\r
750\r
751 Status = Mtftp4ExtractOptions (Packet, PacketLen, OptionCount, OptionList);\r
752\r
753 if (EFI_ERROR (Status)) {\r
754 return Status;\r
755 }\r
756\r
757 if (*OptionCount == 0) {\r
758 return EFI_NOT_FOUND;\r
759 }\r
760\r
761 return EFI_SUCCESS;\r
762}\r
763\r
764\r
772db4bb 765/**\r
dab714aa 766 Downloads a file from an MTFTPv4 server.\r
767 \r
768 The ReadFile() function is used to initialize and start an MTFTPv4 download \r
769 process and optionally wait for completion. When the download operation completes, \r
770 whether successfully or not, the Token.Status field is updated by the EFI MTFTPv4 \r
771 Protocol driver and then Token.Event is signaled (if it is not NULL).\r
772 Data can be downloaded from the MTFTPv4 server into either of the following locations:\r
773 1.A fixed buffer that is pointed to by Token.Buffer\r
774 2.A download service function that is pointed to by Token.CheckPacket\r
775 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket \r
776 will be called first. If the call is successful, the packet will be stored in \r
777 Token.Buffer.\r
778\r
779 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance\r
780 @param Token Pointer to the token structure to provide the \r
781 parameters that are used in this operation.\r
782\r
783 @retval EFI_SUCCESS The data file has been transferred successfully.\r
784 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r
785 @retval EFI_BUFFER_TOO_SMALL BufferSize is not large enough to hold the downloaded \r
786 data in downloading process.\r
787 @retval EFI_ABORTED Current operation is aborted by user.\r
788 @retval EFI_ICMP_ERROR An ICMP ERROR packet was received.\r
789 @retval EFI_TIMEOUT No responses were received from the MTFTPv4 server.\r
790 @retval EFI_TFTP_ERROR An MTFTPv4 ERROR packet was received.\r
791 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.\r
dd29f3ed 792 @retval EFI_NO_MEDIA There was a media error.\r
772db4bb 793\r
794**/\r
772db4bb 795EFI_STATUS\r
796EFIAPI\r
797EfiMtftp4ReadFile (\r
798 IN EFI_MTFTP4_PROTOCOL *This,\r
799 IN EFI_MTFTP4_TOKEN *Token\r
800 )\r
801{\r
802 return Mtftp4Start (This, Token, EFI_MTFTP4_OPCODE_RRQ);\r
803}\r
804\r
805\r
806/**\r
dab714aa 807 Sends a data file to an MTFTPv4 server. May be unsupported in some EFI implementations\r
808\r
809 The WriteFile() function is used to initialize an uploading operation with the \r
810 given option list and optionally wait for completion. If one or more of the \r
811 options is not supported by the server, the unsupported options are ignored and \r
812 a standard TFTP process starts instead. When the upload process completes, \r
813 whether successfully or not, Token.Event is signaled, and the EFI MTFTPv4 Protocol \r
814 driver updates Token.Status.\r
815 The caller can supply the data to be uploaded in the following two modes:\r
816 1.Through the user-provided buffer\r
817 2.Through a callback function\r
818 With the user-provided buffer, the Token.BufferSize field indicates the length\r
819 of the buffer, and the driver will upload the data in the buffer. With an \r
820 EFI_MTFTP4_PACKET_NEEDED callback function, the driver will call this callback \r
821 function to get more data from the user to upload. See the definition of \r
822 EFI_MTFTP4_PACKET_NEEDED for more information. These two modes cannot be used at \r
823 the same time. The callback function will be ignored if the user provides the buffer.\r
824\r
825 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance.\r
826 @param Token Pointer to the token structure to provide the \r
827 parameters that are used in this function\r
828\r
829 @retval EFI_SUCCESS The upload session has started.\r
830 @retval EFI_UNSUPPORTED The operation is not supported by this implementation.\r
831 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
832 1. This is NULL.\r
833 2. Token is NULL.\r
834 3. Token.Filename is NULL.\r
835 4. Token.OptionCount is not zero and\r
836 Token.OptionList is NULL.\r
837 5. One or more options in Token.OptionList have wrong\r
838 format.\r
839 6. Token.Buffer and Token.PacketNeeded are both\r
840 NULL.\r
841 7. One or more IPv4 addresses in Token.OverrideData \r
842 are not valid unicast IPv4 addresses if \r
843 Token.OverrideData is not NULL.\r
844 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are in the\r
845 unsupported list of structure EFI_MTFTP4_MODE_DATA.\r
846 @retval EFI_NOT_STARTED The EFI MTFTPv4 Protocol driver has not been started.\r
847 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, \r
848 BOOTP, RARP, etc.) is not finished yet.\r
849 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv4 \r
850 session.\r
851 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r
852 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.\r
853 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.\r
772db4bb 854\r
855**/\r
772db4bb 856EFI_STATUS\r
857EFIAPI\r
858EfiMtftp4WriteFile (\r
859 IN EFI_MTFTP4_PROTOCOL *This,\r
860 IN EFI_MTFTP4_TOKEN *Token\r
861 )\r
862{\r
863 return Mtftp4Start (This, Token, EFI_MTFTP4_OPCODE_WRQ);\r
864}\r
865\r
866\r
867/**\r
dab714aa 868 Downloads a data file "directory" from an MTFTPv4 server. \r
869 May be unsupported in some EFI implementations\r
870 \r
871 The ReadDirectory() function is used to return a list of files on the MTFTPv4 \r
872 server that are logically (or operationally) related to Token.Filename. The \r
873 directory request packet that is sent to the server is built with the option \r
874 list that was provided by caller, if present.\r
875 The file information that the server returns is put into either of the following \r
876 locations:\r
877 1.A fixed buffer that is pointed to by Token.Buffer\r
878 2.A download service function that is pointed to by Token.CheckPacket\r
879 If both Token.Buffer and Token.CheckPacket are used, then Token.CheckPacket will \r
880 be called first. If the call is successful, the packet will be stored in Token.Buffer.\r
881 The returned directory listing in the Token.Buffer or EFI_MTFTP4_PACKET consists \r
882 of a list of two or three variable-length ASCII strings, each terminated by a \r
883 null character, for each file in the directory. If the multicast option is involved, \r
884 the first field of each directory entry is the static multicast IP address and \r
885 UDP port number that is associated with the file name. The format of the field \r
886 is ip:ip:ip:ip:port. If the multicast option is not involved, this field and its \r
887 terminating null character are not present.\r
888 The next field of each directory entry is the file name and the last field is \r
889 the file information string. The information string contains the file size and \r
890 the create/modify timestamp. The format of the information string is filesize \r
891 yyyy-mm-dd hh:mm:ss:ffff. The timestamp is Coordinated Universal Time \r
892 (UTC; also known as Greenwich Mean Time [GMT]).\r
893 The only difference between ReadFile and ReadDirectory is the opcode used.\r
894\r
895 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance\r
896 @param Token Pointer to the token structure to provide the \r
897 parameters that are used in this function\r
898\r
899 @retval EFI_SUCCESS The MTFTPv4 related file "directory" has been downloaded.\r
900 @retval EFI_UNSUPPORTED The operation is not supported by this implementation.\r
901 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
902 1. This is NULL.\r
903 2. Token is NULL.\r
904 3. Token.Filename is NULL.\r
905 4. Token.OptionCount is not zero and\r
906 Token.OptionList is NULL.\r
907 5. One or more options in Token.OptionList have wrong\r
908 format.\r
909 6. Token.Buffer and Token.PacketNeeded are both\r
910 NULL.\r
911 7. One or more IPv4 addresses in Token.OverrideData \r
912 are not valid unicast IPv4 addresses if \r
913 Token.OverrideData is not NULL.\r
914 @retval EFI_UNSUPPORTED One or more options in the Token.OptionList are in the\r
915 unsupported list of structure EFI_MTFTP4_MODE_DATA.\r
916 @retval EFI_NOT_STARTED The EFI MTFTPv4 Protocol driver has not been started.\r
917 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, \r
918 BOOTP, RARP, etc.) is not finished yet.\r
919 @retval EFI_ALREADY_STARTED This Token is already being used in another MTFTPv4 \r
920 session.\r
921 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r
922 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.\r
923 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.\r
772db4bb 924\r
925**/\r
772db4bb 926EFI_STATUS\r
927EFIAPI\r
928EfiMtftp4ReadDirectory (\r
929 IN EFI_MTFTP4_PROTOCOL *This,\r
930 IN EFI_MTFTP4_TOKEN *Token\r
931 )\r
932{\r
933 return Mtftp4Start (This, Token, EFI_MTFTP4_OPCODE_DIR);\r
934}\r
935\r
936\r
937/**\r
dab714aa 938 Gets information about a file from an MTFTPv4 server. \r
939 \r
940 The GetInfo() function assembles an MTFTPv4 request packet with options; \r
941 sends it to the MTFTPv4 server; and may return an MTFTPv4 OACK, MTFTPv4 ERROR, \r
942 or ICMP ERROR packet. Retries occur only if no response packets are received \r
943 from the MTFTPv4 server before the timeout expires.\r
944 It is implemented with EfiMtftp4ReadFile: build a token, then pass it to \r
945 EfiMtftp4ReadFile. In its check packet callback abort the opertions.\r
946\r
947 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance\r
948 @param OverrideData Data that is used to override the existing \r
949 parameters. If NULL, the default parameters that \r
950 were set in the EFI_MTFTP4_PROTOCOL.Configure() \r
951 function are used\r
4f077902
SZ
952 @param Filename Pointer to null-terminated ASCII file name string\r
953 @param ModeStr Pointer to null-terminated ASCII mode string. If NULL, "octet" \r
dab714aa 954 will be used\r
955 @param OptionCount Number of option/value string pairs in OptionList\r
956 @param OptionList Pointer to array of option/value string pairs. \r
957 Ignored if OptionCount is zero\r
958 @param PacketLength The number of bytes in the returned packet\r
959 @param Packet PacketThe pointer to the received packet. This \r
960 buffer must be freed by the caller.\r
961\r
962 @retval EFI_SUCCESS An MTFTPv4 OACK packet was received and is in \r
963 the Buffer.\r
964 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
965 1.This is NULL.\r
966 2.Filename is NULL.\r
967 3.OptionCount is not zero and OptionList is NULL.\r
968 4.One or more options in OptionList have wrong format.\r
969 5.PacketLength is NULL.\r
970 6.One or more IPv4 addresses in OverrideData are \r
971 not valid unicast IPv4 addresses if OverrideData \r
972 is not NULL.\r
973 @retval EFI_UNSUPPORTED One or more options in the OptionList are in the\r
974 unsupported list of structure EFI_MTFTP4_MODE_DATA\r
975 @retval EFI_NOT_STARTED The EFI MTFTPv4 Protocol driver has not been started.\r
976 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, \r
977 BOOTP, RARP, etc.) has not finished yet.\r
978 @retval EFI_ACCESS_DENIED The previous operation has not completed yet.\r
979 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r
980 @retval EFI_TFTP_ERROR An MTFTPv4 ERROR packet was received and is in \r
981 the Buffer.\r
982 @retval EFI_ICMP_ERROR An ICMP ERROR packet was received and the Packet \r
983 is set to NULL.\r
984 @retval EFI_PROTOCOL_ERROR An unexpected MTFTPv4 packet was received and is \r
985 in the Buffer.\r
986 @retval EFI_TIMEOUT No responses were received from the MTFTPv4 server.\r
987 @retval EFI_DEVICE_ERROR An unexpected network error or system error occurred.\r
dd29f3ed 988 @retval EFI_NO_MEDIA There was a media error.\r
989\r
dab714aa 990**/\r
991EFI_STATUS\r
992EFIAPI\r
993EfiMtftp4GetInfo (\r
994 IN EFI_MTFTP4_PROTOCOL *This,\r
995 IN EFI_MTFTP4_OVERRIDE_DATA *OverrideData OPTIONAL,\r
996 IN UINT8 *Filename,\r
997 IN UINT8 *ModeStr OPTIONAL,\r
998 IN UINT8 OptionCount,\r
999 IN EFI_MTFTP4_OPTION *OptionList OPTIONAL,\r
1000 OUT UINT32 *PacketLength,\r
1001 OUT EFI_MTFTP4_PACKET **Packet OPTIONAL\r
1002 )\r
1003{\r
1004 EFI_MTFTP4_TOKEN Token;\r
ea886bef 1005 MTFTP4_GETINFO_STATE State;\r
dab714aa 1006 EFI_STATUS Status;\r
1007\r
1008 if ((This == NULL) || (Filename == NULL) || (PacketLength == NULL) ||\r
1009 ((OptionCount != 0) && (OptionList == NULL))) {\r
1010 return EFI_INVALID_PARAMETER;\r
1011 }\r
1012\r
1013 if (Packet != NULL) {\r
1014 *Packet = NULL;\r
1015 }\r
1016\r
1017 *PacketLength = 0;\r
ea886bef 1018 State.Packet = Packet;\r
1019 State.PacketLen = PacketLength;\r
1020 State.Status = EFI_SUCCESS;\r
dab714aa 1021\r
1022 //\r
1023 // Fill in the Token to issue an synchronous ReadFile operation\r
1024 //\r
1025 Token.Status = EFI_SUCCESS;\r
1026 Token.Event = NULL;\r
1027 Token.OverrideData = OverrideData;\r
1028 Token.Filename = Filename;\r
1029 Token.ModeStr = ModeStr;\r
1030 Token.OptionCount = OptionCount;\r
1031 Token.OptionList = OptionList;\r
1032 Token.BufferSize = 0;\r
1033 Token.Buffer = NULL;\r
ea886bef 1034 Token.Context = &State;\r
dab714aa 1035 Token.CheckPacket = Mtftp4GetInfoCheckPacket;\r
1036 Token.TimeoutCallback = NULL;\r
1037 Token.PacketNeeded = NULL;\r
1038\r
1039 Status = EfiMtftp4ReadFile (This, &Token);\r
772db4bb 1040\r
dab714aa 1041 if (EFI_ABORTED == Status) {\r
ea886bef 1042 return State.Status;\r
dab714aa 1043 }\r
1044\r
1045 return Status;\r
1046}\r
772db4bb 1047\r
dab714aa 1048/**\r
1049 Polls for incoming data packets and processes outgoing data packets.\r
1050\r
1051 The Poll() function can be used by network drivers and applications to increase \r
1052 the rate that data packets are moved between the communications device and the \r
1053 transmit and receive queues.\r
1054 In some systems, the periodic timer event in the managed network driver may not \r
1055 poll the underlying communications device fast enough to transmit and/or receive \r
1056 all data packets without missing incoming packets or dropping outgoing packets. \r
1057 Drivers and applications that are experiencing packet loss should try calling \r
1058 the Poll() function more often.\r
1059 \r
1060 @param This Pointer to the EFI_MTFTP4_PROTOCOL instance\r
1061\r
1062 @retval EFI_SUCCESS Incoming or outgoing data was processed.\r
1063 @retval EFI_NOT_STARTED This EFI MTFTPv4 Protocol instance has not been started.\r
1064 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP,\r
1065 BOOTP, RARP, etc.) is not finished yet.\r
772db4bb 1066 @retval EFI_INVALID_PARAMETER This is NULL.\r
dab714aa 1067 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
1068 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive \r
1069 queue. Consider increasing the polling rate.\r
772db4bb 1070\r
1071**/\r
772db4bb 1072EFI_STATUS\r
1073EFIAPI\r
1074EfiMtftp4Poll (\r
1075 IN EFI_MTFTP4_PROTOCOL *This\r
1076 )\r
1077{\r
1078 MTFTP4_PROTOCOL *Instance;\r
1079 EFI_UDP4_PROTOCOL *Udp;\r
1080\r
1081 if (This == NULL) {\r
1082 return EFI_INVALID_PARAMETER;\r
1083 }\r
1084\r
1085 Instance = MTFTP4_PROTOCOL_FROM_THIS (This);\r
1086\r
1087 if (Instance->State == MTFTP4_STATE_UNCONFIGED) {\r
1088 return EFI_NOT_STARTED;\r
75dce340 1089 } else if (Instance->State == MTFTP4_STATE_DESTROY) {\r
772db4bb 1090 return EFI_DEVICE_ERROR;\r
1091 }\r
1092\r
b45b45b2 1093 Udp = Instance->UnicastPort->Protocol.Udp4;\r
772db4bb 1094 return Udp->Poll (Udp);\r
1095}\r
1096\r
1097EFI_MTFTP4_PROTOCOL gMtftp4ProtocolTemplate = {\r
1098 EfiMtftp4GetModeData,\r
1099 EfiMtftp4Configure,\r
1100 EfiMtftp4GetInfo,\r
1101 EfiMtftp4ParseOptions,\r
1102 EfiMtftp4ReadFile,\r
1103 EfiMtftp4WriteFile,\r
1104 EfiMtftp4ReadDirectory,\r
1105 EfiMtftp4Poll\r
1106};\r