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