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