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