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