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