]>
Commit | Line | Data |
---|---|---|
dc361cc5 | 1 | /** @file\r |
f737cfb9 | 2 | Interface routines for PxeBc.\r |
3 | \r | |
434ce3fe | 4 | Copyright (c) 2007 - 2009, Intel Corporation.<BR>\r |
dc361cc5 | 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\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 | |
dc361cc5 | 13 | **/\r |
14 | \r | |
15 | \r | |
16 | #include "PxeBcImpl.h"\r | |
17 | \r | |
434ce3fe | 18 | UINT32 mPxeDhcpTimeout[4] = { 4, 8, 16, 32 };\r |
f737cfb9 | 19 | \r |
982a9eae | 20 | /**\r |
f737cfb9 | 21 | Get and record the arp cache.\r |
982a9eae | 22 | \r |
23 | @param This Pointer to EFI_PXE_BC_PROTOCOL\r | |
24 | \r | |
25 | @retval EFI_SUCCESS Arp cache updated successfully\r | |
f737cfb9 | 26 | @retval others If error occurs when getting arp cache\r |
982a9eae | 27 | \r |
28 | **/\r | |
982a9eae | 29 | EFI_STATUS\r |
30 | UpdateArpCache (\r | |
31 | IN EFI_PXE_BASE_CODE_PROTOCOL * This\r | |
32 | )\r | |
33 | {\r | |
34 | PXEBC_PRIVATE_DATA *Private;\r | |
35 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
36 | EFI_STATUS Status;\r | |
37 | UINT32 EntryLength;\r | |
38 | UINT32 EntryCount;\r | |
39 | EFI_ARP_FIND_DATA *Entries;\r | |
40 | UINT32 Index;\r | |
41 | \r | |
42 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
43 | Mode = Private->PxeBc.Mode;\r | |
44 | \r | |
f737cfb9 | 45 | Status = Private->Arp->Find (\r |
46 | Private->Arp,\r | |
47 | TRUE,\r | |
48 | NULL,\r | |
49 | &EntryLength,\r | |
50 | &EntryCount,\r | |
51 | &Entries,\r | |
52 | TRUE\r | |
53 | );\r | |
982a9eae | 54 | if (EFI_ERROR (Status)) {\r |
55 | return Status;\r | |
56 | }\r | |
57 | \r | |
f737cfb9 | 58 | Mode->ArpCacheEntries = MIN (\r |
59 | EntryCount,\r | |
60 | EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES\r | |
61 | );\r | |
982a9eae | 62 | for (Index = 0; Index < Mode->ArpCacheEntries; Index ++) {\r |
f737cfb9 | 63 | CopyMem (\r |
64 | &Mode->ArpCache[Index].IpAddr, \r | |
65 | Entries + 1, \r | |
66 | Entries->SwAddressLength\r | |
67 | );\r | |
68 | CopyMem (\r | |
69 | &Mode->ArpCache[Index].MacAddr,\r | |
70 | (UINT8 *) (Entries + 1) + Entries->SwAddressLength,\r | |
71 | Entries->HwAddressLength\r | |
72 | );\r | |
982a9eae | 73 | //\r |
74 | // Slip to the next FindData.\r | |
75 | //\r | |
f737cfb9 | 76 | Entries = (EFI_ARP_FIND_DATA *) ((UINT8 *) Entries + EntryLength);\r |
982a9eae | 77 | }\r |
78 | \r | |
79 | return EFI_SUCCESS;\r | |
80 | }\r | |
81 | \r | |
82 | /**\r | |
f737cfb9 | 83 | Timeout routine to update arp cache.\r |
982a9eae | 84 | \r |
85 | @param Event Pointer to EFI_PXE_BC_PROTOCOL\r | |
86 | @param Context Context of the timer event\r | |
f737cfb9 | 87 | \r |
88 | @return None.\r | |
982a9eae | 89 | \r |
90 | **/\r | |
982a9eae | 91 | VOID\r |
92 | EFIAPI\r | |
93 | ArpCacheUpdateTimeout (\r | |
94 | IN EFI_EVENT Event,\r | |
95 | IN VOID *Context\r | |
96 | )\r | |
97 | {\r | |
98 | UpdateArpCache ((EFI_PXE_BASE_CODE_PROTOCOL *) Context);\r | |
99 | }\r | |
100 | \r | |
101 | /**\r | |
f737cfb9 | 102 | Do arp resolution from arp cache in PxeBcMode.\r |
103 | \r | |
104 | @param PxeBcMode The PXE BC mode to look into.\r | |
105 | @param Ip4Addr The Ip4 address for resolution.\r | |
106 | @param MacAddress The resoluted MAC address if the resolution is successful.\r | |
107 | The value is undefined if resolution fails.\r | |
108 | \r | |
109 | @retval TRUE The resolution is successful.\r | |
110 | @retval FALSE Otherwise.\r | |
982a9eae | 111 | \r |
112 | **/\r | |
982a9eae | 113 | BOOLEAN\r |
114 | FindInArpCache (\r | |
f737cfb9 | 115 | IN EFI_PXE_BASE_CODE_MODE *PxeBcMode,\r |
116 | IN EFI_IPv4_ADDRESS *Ip4Addr,\r | |
117 | OUT EFI_MAC_ADDRESS *MacAddress\r | |
982a9eae | 118 | )\r |
119 | {\r | |
120 | UINT32 Index;\r | |
121 | \r | |
122 | for (Index = 0; Index < PxeBcMode->ArpCacheEntries; Index ++) {\r | |
123 | if (EFI_IP4_EQUAL (&PxeBcMode->ArpCache[Index].IpAddr.v4, Ip4Addr)) {\r | |
f737cfb9 | 124 | CopyMem (\r |
125 | MacAddress,\r | |
126 | &PxeBcMode->ArpCache[Index].MacAddr,\r | |
127 | sizeof (EFI_MAC_ADDRESS)\r | |
128 | );\r | |
982a9eae | 129 | return TRUE;\r |
130 | }\r | |
131 | }\r | |
132 | \r | |
133 | return FALSE;\r | |
134 | }\r | |
135 | \r | |
136 | /**\r | |
137 | Notify function for the ICMP receive token, used to process\r | |
138 | the received ICMP packets.\r | |
139 | \r | |
f737cfb9 | 140 | @param Context The PXEBC private data.\r |
982a9eae | 141 | \r |
142 | @return None.\r | |
143 | \r | |
144 | **/\r | |
982a9eae | 145 | VOID\r |
146 | EFIAPI\r | |
147 | IcmpErrorListenHandlerDpc (\r | |
148 | IN VOID *Context\r | |
149 | )\r | |
150 | {\r | |
151 | EFI_STATUS Status;\r | |
152 | EFI_IP4_RECEIVE_DATA *RxData;\r | |
153 | EFI_IP4_PROTOCOL *Ip4;\r | |
154 | PXEBC_PRIVATE_DATA *Private;\r | |
155 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
156 | UINTN Index;\r | |
157 | UINT32 CopiedLen;\r | |
158 | UINT8 *CopiedPointer;\r | |
159 | \r | |
160 | Private = (PXEBC_PRIVATE_DATA *) Context;\r | |
161 | Mode = &Private->Mode;\r | |
162 | Status = Private->IcmpErrorRcvToken.Status;\r | |
163 | RxData = Private->IcmpErrorRcvToken.Packet.RxData;\r | |
164 | Ip4 = Private->Ip4;\r | |
165 | \r | |
f737cfb9 | 166 | if (Status == EFI_ABORTED) {\r |
982a9eae | 167 | //\r |
168 | // The reception is actively aborted by the consumer, directly return.\r | |
169 | //\r | |
170 | return;\r | |
171 | }\r | |
172 | \r | |
f737cfb9 | 173 | if (EFI_ERROR (Status) || (RxData == NULL)) {\r |
982a9eae | 174 | //\r |
175 | // Only process the normal packets and the icmp error packets, if RxData is NULL\r | |
176 | // with Status == EFI_SUCCESS or EFI_ICMP_ERROR, just resume the receive although\r | |
177 | // this should be a bug of the low layer (IP).\r | |
178 | //\r | |
179 | goto Resume;\r | |
180 | }\r | |
181 | \r | |
f737cfb9 | 182 | if (EFI_IP4 (RxData->Header->SourceAddress) != 0 &&\r |
183 | !Ip4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), 0)) {\r | |
982a9eae | 184 | //\r |
185 | // The source address is not zero and it's not a unicast IP address, discard it.\r | |
186 | //\r | |
187 | goto CleanUp;\r | |
188 | }\r | |
189 | \r | |
190 | if (!EFI_IP4_EQUAL (&RxData->Header->DestinationAddress, &Mode->StationIp.v4)) {\r | |
191 | //\r | |
192 | // The dest address is not equal to Station Ip address, discard it.\r | |
193 | //\r | |
194 | goto CleanUp;\r | |
195 | }\r | |
196 | \r | |
197 | //\r | |
198 | // Constructor ICMP error packet\r | |
199 | //\r | |
200 | CopiedLen = 0;\r | |
201 | CopiedPointer = (UINT8 *) &Mode->IcmpError;\r | |
202 | \r | |
203 | for (Index = 0; Index < RxData->FragmentCount; Index ++) {\r | |
204 | CopiedLen += RxData->FragmentTable[Index].FragmentLength;\r | |
205 | if (CopiedLen <= sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR)) {\r | |
f737cfb9 | 206 | CopyMem (\r |
207 | CopiedPointer,\r | |
208 | RxData->FragmentTable[Index].FragmentBuffer,\r | |
209 | RxData->FragmentTable[Index].FragmentLength\r | |
210 | );\r | |
982a9eae | 211 | } else {\r |
f737cfb9 | 212 | CopyMem (\r |
213 | CopiedPointer,\r | |
214 | RxData->FragmentTable[Index].FragmentBuffer,\r | |
215 | CopiedLen - sizeof (EFI_PXE_BASE_CODE_ICMP_ERROR)\r | |
216 | );\r | |
982a9eae | 217 | }\r |
218 | CopiedPointer += CopiedLen;\r | |
219 | }\r | |
220 | \r | |
221 | goto Resume;\r | |
222 | \r | |
223 | CleanUp:\r | |
224 | gBS->SignalEvent (RxData->RecycleSignal);\r | |
225 | \r | |
226 | Resume:\r | |
227 | Ip4->Receive (Ip4, &(Private->IcmpErrorRcvToken));\r | |
228 | }\r | |
229 | \r | |
230 | /**\r | |
231 | Request IcmpErrorListenHandlerDpc as a DPC at TPL_CALLBACK\r | |
232 | \r | |
233 | @param Event The event signaled.\r | |
234 | @param Context The context passed in by the event notifier.\r | |
235 | \r | |
236 | @return None.\r | |
237 | \r | |
238 | **/\r | |
982a9eae | 239 | VOID\r |
240 | EFIAPI\r | |
241 | IcmpErrorListenHandler (\r | |
242 | IN EFI_EVENT Event,\r | |
243 | IN VOID *Context\r | |
244 | )\r | |
245 | {\r | |
246 | //\r | |
247 | // Request IpIoListenHandlerDpc as a DPC at TPL_CALLBACK\r | |
248 | //\r | |
249 | NetLibQueueDpc (TPL_CALLBACK, IcmpErrorListenHandlerDpc, Context);\r | |
250 | }\r | |
dc361cc5 | 251 | \r |
f737cfb9 | 252 | /** \r |
253 | Enables the use of the PXE Base Code Protocol functions.\r | |
254 | \r | |
255 | This function enables the use of the PXE Base Code Protocol functions. If the\r | |
256 | Started field of the EFI_PXE_BASE_CODE_MODE structure is already TRUE, then\r | |
257 | EFI_ALREADY_STARTED will be returned. If UseIpv6 is TRUE, then IPv6 formatted\r | |
258 | addresses will be used in this session. If UseIpv6 is FALSE, then IPv4 formatted\r | |
259 | addresses will be used in this session. If UseIpv6 is TRUE, and the Ipv6Supported\r | |
260 | field of the EFI_PXE_BASE_CODE_MODE structure is FALSE, then EFI_UNSUPPORTED will\r | |
261 | be returned. If there is not enough memory or other resources to start the PXE\r | |
262 | Base Code Protocol, then EFI_OUT_OF_RESOURCES will be returned. Otherwise, the\r | |
263 | PXE Base Code Protocol will be started, and all of the fields of the EFI_PXE_BASE_CODE_MODE\r | |
264 | structure will be initialized as follows:\r | |
265 | StartedSet to TRUE.\r | |
266 | Ipv6SupportedUnchanged.\r | |
267 | Ipv6AvailableUnchanged.\r | |
268 | UsingIpv6Set to UseIpv6.\r | |
269 | BisSupportedUnchanged.\r | |
270 | BisDetectedUnchanged.\r | |
271 | AutoArpSet to TRUE.\r | |
272 | SendGUIDSet to FALSE.\r | |
273 | TTLSet to DEFAULT_TTL.\r | |
274 | ToSSet to DEFAULT_ToS.\r | |
275 | DhcpCompletedSet to FALSE.\r | |
276 | ProxyOfferReceivedSet to FALSE.\r | |
277 | StationIpSet to an address of all zeros.\r | |
278 | SubnetMaskSet to a subnet mask of all zeros.\r | |
279 | DhcpDiscoverZero-filled.\r | |
280 | DhcpAckZero-filled.\r | |
281 | ProxyOfferZero-filled.\r | |
282 | PxeDiscoverValidSet to FALSE.\r | |
283 | PxeDiscoverZero-filled.\r | |
284 | PxeReplyValidSet to FALSE.\r | |
285 | PxeReplyZero-filled.\r | |
286 | PxeBisReplyValidSet to FALSE.\r | |
287 | PxeBisReplyZero-filled.\r | |
288 | IpFilterSet the Filters field to 0 and the IpCnt field to 0.\r | |
289 | ArpCacheEntriesSet to 0.\r | |
290 | ArpCacheZero-filled.\r | |
291 | RouteTableEntriesSet to 0.\r | |
292 | RouteTableZero-filled.\r | |
293 | IcmpErrorReceivedSet to FALSE.\r | |
294 | IcmpErrorZero-filled.\r | |
295 | TftpErroReceivedSet to FALSE.\r | |
296 | TftpErrorZero-filled.\r | |
297 | MakeCallbacksSet to TRUE if the PXE Base Code Callback Protocol is available.\r | |
298 | Set to FALSE if the PXE Base Code Callback Protocol is not available.\r | |
299 | \r | |
300 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
301 | @param UseIpv6 Specifies the type of IP addresses that are to be used during the session\r | |
302 | that is being started. Set to TRUE for IPv6 addresses, and FALSE for \r | |
303 | IPv4 addresses. \r | |
304 | \r | |
305 | @retval EFI_SUCCESS The PXE Base Code Protocol was started.\r | |
306 | @retval EFI_DEVICE_ERROR The network device encountered an error during this oper \r | |
307 | @retval EFI_UNSUPPORTED UseIpv6 is TRUE, but the Ipv6Supported field of the\r | |
308 | EFI_PXE_BASE_CODE_MODE structure is FALSE. \r | |
309 | @retval EFI_ALREADY_STARTED The PXE Base Code Protocol is already in the started state. \r | |
310 | @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid\r | |
311 | EFI_PXE_BASE_CODE_PROTOCOL structure. \r | |
312 | @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory or other resources to start the \r | |
313 | PXE Base Code Protocol. \r | |
314 | \r | |
dc361cc5 | 315 | **/\r |
316 | EFI_STATUS\r | |
317 | EFIAPI\r | |
318 | EfiPxeBcStart (\r | |
319 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
320 | IN BOOLEAN UseIpv6\r | |
321 | )\r | |
322 | {\r | |
323 | PXEBC_PRIVATE_DATA *Private;\r | |
324 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
325 | EFI_STATUS Status;\r | |
326 | \r | |
327 | if (This == NULL) {\r | |
328 | return EFI_INVALID_PARAMETER;\r | |
329 | }\r | |
330 | \r | |
331 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
332 | Mode = Private->PxeBc.Mode;\r | |
333 | \r | |
334 | if (Mode->Started) {\r | |
335 | return EFI_ALREADY_STARTED;\r | |
336 | }\r | |
337 | \r | |
338 | if (UseIpv6) {\r | |
339 | //\r | |
340 | // IPv6 is not supported now.\r | |
341 | //\r | |
342 | return EFI_UNSUPPORTED;\r | |
343 | }\r | |
344 | \r | |
345 | //\r | |
346 | // Configure the udp4 instance to let it receive data\r | |
347 | //\r | |
f737cfb9 | 348 | Status = Private->Udp4Read->Configure (\r |
349 | Private->Udp4Read, \r | |
350 | &Private->Udp4CfgData\r | |
351 | );\r | |
dc361cc5 | 352 | if (EFI_ERROR (Status)) {\r |
353 | return Status;\r | |
354 | }\r | |
355 | \r | |
356 | Private->AddressIsOk = FALSE;\r | |
357 | \r | |
358 | ZeroMem (Mode, sizeof (EFI_PXE_BASE_CODE_MODE));\r | |
359 | \r | |
360 | Mode->Started = TRUE;\r | |
361 | Mode->TTL = DEFAULT_TTL;\r | |
362 | Mode->ToS = DEFAULT_ToS;\r | |
363 | Mode->AutoArp = TRUE;\r | |
364 | \r | |
982a9eae | 365 | //\r |
366 | // Create the event for Arp Cache checking.\r | |
367 | //\r | |
368 | Status = gBS->CreateEvent (\r | |
369 | EVT_TIMER | EVT_NOTIFY_SIGNAL,\r | |
370 | TPL_CALLBACK,\r | |
371 | ArpCacheUpdateTimeout,\r | |
372 | This,\r | |
373 | &Private->GetArpCacheEvent\r | |
374 | );\r | |
375 | if (EFI_ERROR (Status)) {\r | |
376 | goto ON_EXIT;\r | |
377 | }\r | |
378 | \r | |
379 | //\r | |
380 | // Start the timeout timer event.\r | |
381 | //\r | |
382 | Status = gBS->SetTimer (\r | |
383 | Private->GetArpCacheEvent,\r | |
384 | TimerPeriodic,\r | |
385 | TICKS_PER_SECOND\r | |
386 | );\r | |
387 | \r | |
388 | if (EFI_ERROR (Status)) {\r | |
389 | goto ON_EXIT;\r | |
390 | }\r | |
391 | \r | |
392 | //\r | |
393 | // Create ICMP error receiving event\r | |
394 | //\r | |
395 | Status = gBS->CreateEvent (\r | |
396 | EVT_NOTIFY_SIGNAL,\r | |
397 | TPL_NOTIFY,\r | |
398 | IcmpErrorListenHandler,\r | |
399 | Private,\r | |
400 | &(Private->IcmpErrorRcvToken.Event)\r | |
401 | );\r | |
402 | if (EFI_ERROR (Status)) {\r | |
403 | goto ON_EXIT;\r | |
404 | }\r | |
405 | \r | |
406 | Status = Private->Ip4->Configure (Private->Ip4, &Private->Ip4ConfigData);\r | |
407 | if (EFI_ERROR (Status)) {\r | |
408 | goto ON_EXIT;\r | |
409 | }\r | |
410 | \r | |
411 | //\r | |
412 | // start to listen incoming packet\r | |
413 | //\r | |
414 | Status = Private->Ip4->Receive (Private->Ip4, &Private->IcmpErrorRcvToken);\r | |
415 | if (!EFI_ERROR (Status)) {\r | |
416 | return Status;\r | |
417 | }\r | |
418 | \r | |
419 | ON_EXIT:\r | |
420 | Private->Ip4->Configure (Private->Ip4, NULL);\r | |
421 | \r | |
422 | if (Private->IcmpErrorRcvToken.Event != NULL) {\r | |
423 | gBS->CloseEvent (Private->IcmpErrorRcvToken.Event);\r | |
424 | }\r | |
425 | \r | |
426 | if (Private->GetArpCacheEvent != NULL) {\r | |
427 | gBS->SetTimer (Private->GetArpCacheEvent, TimerCancel, 0);\r | |
428 | gBS->CloseEvent (Private->GetArpCacheEvent);\r | |
429 | }\r | |
430 | \r | |
431 | Mode->Started = FALSE;\r | |
432 | Mode->TTL = 0;\r | |
433 | Mode->ToS = 0;\r | |
434 | Mode->AutoArp = FALSE;\r | |
435 | \r | |
436 | return Status;\r | |
dc361cc5 | 437 | }\r |
438 | \r | |
439 | \r | |
f737cfb9 | 440 | /** \r |
441 | Disables the use of the PXE Base Code Protocol functions.\r | |
442 | \r | |
443 | This function stops all activity on the network device. All the resources allocated\r | |
444 | in Start() are released, the Started field of the EFI_PXE_BASE_CODE_MODE structure is\r | |
445 | set to FALSE and EFI_SUCCESS is returned. If the Started field of the EFI_PXE_BASE_CODE_MODE\r | |
446 | structure is already FALSE, then EFI_NOT_STARTED will be returned.\r | |
447 | \r | |
448 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
449 | \r | |
450 | @retval EFI_SUCCESS The PXE Base Code Protocol was stopped.\r | |
451 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is already in the stopped state. \r | |
452 | @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid\r | |
453 | EFI_PXE_BASE_CODE_PROTOCOL structure. \r | |
454 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation. \r | |
455 | \r | |
dc361cc5 | 456 | **/\r |
457 | EFI_STATUS\r | |
458 | EFIAPI\r | |
459 | EfiPxeBcStop (\r | |
460 | IN EFI_PXE_BASE_CODE_PROTOCOL *This\r | |
461 | )\r | |
462 | {\r | |
463 | PXEBC_PRIVATE_DATA *Private;\r | |
464 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
465 | \r | |
466 | if (This == NULL) {\r | |
467 | return EFI_INVALID_PARAMETER;\r | |
468 | }\r | |
469 | \r | |
470 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
471 | Mode = Private->PxeBc.Mode;\r | |
472 | \r | |
473 | if (!Mode->Started) {\r | |
474 | return EFI_NOT_STARTED;\r | |
475 | }\r | |
476 | \r | |
982a9eae | 477 | Private->Ip4->Cancel (Private->Ip4, NULL);\r |
478 | //\r | |
479 | // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's\r | |
480 | // events.\r | |
481 | //\r | |
482 | NetLibDispatchDpc ();\r | |
483 | \r | |
484 | Private->Ip4->Configure (Private->Ip4, NULL);\r | |
485 | \r | |
486 | //\r | |
487 | // Close the ICMP error receiving event.\r | |
488 | //\r | |
489 | gBS->CloseEvent (Private->IcmpErrorRcvToken.Event);\r | |
490 | \r | |
491 | //\r | |
492 | // Cancel the TimeoutEvent timer.\r | |
493 | //\r | |
494 | gBS->SetTimer (Private->GetArpCacheEvent, TimerCancel, 0);\r | |
495 | \r | |
496 | //\r | |
497 | // Close the TimeoutEvent event.\r | |
498 | //\r | |
499 | gBS->CloseEvent (Private->GetArpCacheEvent);\r | |
500 | \r | |
dc361cc5 | 501 | Mode->Started = FALSE;\r |
502 | \r | |
8792362f | 503 | Private->CurrentUdpSrcPort = 0;\r |
504 | Private->Udp4Write->Configure (Private->Udp4Write, NULL);\r | |
434ce3fe | 505 | Private->Udp4Read->Groups (Private->Udp4Read, FALSE, NULL);\r |
8792362f | 506 | Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r |
dc361cc5 | 507 | \r |
508 | Private->Dhcp4->Stop (Private->Dhcp4);\r | |
509 | Private->Dhcp4->Configure (Private->Dhcp4, NULL);\r | |
510 | \r | |
511 | Private->FileSize = 0;\r | |
512 | \r | |
513 | return EFI_SUCCESS;\r | |
514 | }\r | |
515 | \r | |
516 | \r | |
f737cfb9 | 517 | /** \r |
518 | Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request / acknowledge) or DHCPv6\r | |
519 | S.A.R.R (solicit / advertise / request / reply) sequence.\r | |
520 | \r | |
521 | This function attempts to complete the DHCP sequence. If this sequence is completed,\r | |
522 | then EFI_SUCCESS is returned, and the DhcpCompleted, ProxyOfferReceived, StationIp,\r | |
523 | SubnetMask, DhcpDiscover, DhcpAck, and ProxyOffer fields of the EFI_PXE_BASE_CODE_MODE\r | |
524 | structure are filled in.\r | |
525 | If SortOffers is TRUE, then the cached DHCP offer packets will be sorted before\r | |
526 | they are tried. If SortOffers is FALSE, then the cached DHCP offer packets will\r | |
527 | be tried in the order in which they are received. Please see the Preboot Execution\r | |
528 | Environment (PXE) Specification for additional details on the implementation of DHCP.\r | |
529 | This function can take at least 31 seconds to timeout and return control to the\r | |
530 | caller. If the DHCP sequence does not complete, then EFI_TIMEOUT will be returned.\r | |
531 | If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,\r | |
532 | then the DHCP sequence will be stopped and EFI_ABORTED will be returned.\r | |
533 | \r | |
534 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
535 | @param SortOffers TRUE if the offers received should be sorted. Set to FALSE to try the\r | |
536 | offers in the order that they are received. \r | |
537 | \r | |
538 | @retval EFI_SUCCESS Valid DHCP has completed.\r | |
539 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
540 | @retval EFI_INVALID_PARAMETER The This parameter is NULL or does not point to a valid\r | |
541 | EFI_PXE_BASE_CODE_PROTOCOL structure. \r | |
542 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation. \r | |
543 | @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete the DHCP Protocol.\r | |
544 | @retval EFI_ABORTED The callback function aborted the DHCP Protocol.\r | |
545 | @retval EFI_TIMEOUT The DHCP Protocol timed out.\r | |
546 | @retval EFI_ICMP_ERROR An ICMP error packet was received during the DHCP session.\r | |
547 | @retval EFI_NO_RESPONSE Valid PXE offer was not received.\r | |
548 | \r | |
dc361cc5 | 549 | **/\r |
550 | EFI_STATUS\r | |
551 | EFIAPI\r | |
552 | EfiPxeBcDhcp (\r | |
553 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
554 | IN BOOLEAN SortOffers\r | |
555 | )\r | |
556 | {\r | |
557 | PXEBC_PRIVATE_DATA *Private;\r | |
558 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
559 | EFI_DHCP4_PROTOCOL *Dhcp4;\r | |
560 | EFI_DHCP4_CONFIG_DATA Dhcp4CfgData;\r | |
561 | EFI_DHCP4_MODE_DATA Dhcp4Mode;\r | |
562 | EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM];\r | |
563 | UINT32 OptCount;\r | |
dc361cc5 | 564 | EFI_STATUS Status;\r |
8d285ec0 | 565 | EFI_ARP_CONFIG_DATA ArpConfigData;\r |
dc361cc5 | 566 | \r |
567 | if (This == NULL) {\r | |
568 | return EFI_INVALID_PARAMETER;\r | |
569 | }\r | |
570 | \r | |
571 | Status = EFI_SUCCESS;\r | |
572 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
573 | Mode = Private->PxeBc.Mode;\r | |
574 | Dhcp4 = Private->Dhcp4;\r | |
575 | Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DHCP;\r | |
576 | Private->SortOffers = SortOffers;\r | |
577 | \r | |
578 | if (!Mode->Started) {\r | |
579 | return EFI_NOT_STARTED;\r | |
580 | }\r | |
982a9eae | 581 | \r |
582 | Mode->IcmpErrorReceived = FALSE;\r | |
583 | \r | |
dc361cc5 | 584 | //\r |
585 | // Initialize the DHCP options and build the option list\r | |
586 | //\r | |
587 | OptCount = PxeBcBuildDhcpOptions (Private, OptList, TRUE);\r | |
588 | \r | |
589 | //\r | |
590 | // Set the DHCP4 config data.\r | |
434ce3fe | 591 | // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.\r |
dc361cc5 | 592 | //\r |
e48e37fc | 593 | ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));\r |
dc361cc5 | 594 | Dhcp4CfgData.OptionCount = OptCount;\r |
595 | Dhcp4CfgData.OptionList = OptList;\r | |
596 | Dhcp4CfgData.Dhcp4Callback = PxeBcDhcpCallBack;\r | |
597 | Dhcp4CfgData.CallbackContext = Private;\r | |
434ce3fe | 598 | Dhcp4CfgData.DiscoverTryCount = 4;\r |
599 | Dhcp4CfgData.DiscoverTimeout = mPxeDhcpTimeout;\r | |
dc361cc5 | 600 | \r |
434ce3fe | 601 | Status = Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);\r |
602 | if (EFI_ERROR (Status)) {\r | |
603 | goto ON_EXIT;\r | |
604 | }\r | |
605 | \r | |
606 | //\r | |
607 | // Zero those arrays to record the varies numbers of DHCP OFFERS.\r | |
608 | //\r | |
609 | Private->GotProxyOffer = FALSE;\r | |
610 | Private->NumOffers = 0;\r | |
611 | Private->BootpIndex = 0;\r | |
612 | ZeroMem (Private->ServerCount, sizeof (Private->ServerCount));\r | |
613 | ZeroMem (Private->ProxyIndex, sizeof (Private->ProxyIndex));\r | |
dc361cc5 | 614 | \r |
434ce3fe | 615 | Status = Dhcp4->Start (Dhcp4, NULL);\r |
616 | if (EFI_ERROR (Status)) {\r | |
617 | if (Status == EFI_ICMP_ERROR) {\r | |
618 | Mode->IcmpErrorReceived = TRUE;\r | |
dc361cc5 | 619 | }\r |
434ce3fe | 620 | goto ON_EXIT;\r |
621 | }\r | |
dc361cc5 | 622 | \r |
434ce3fe | 623 | Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);\r |
624 | if (EFI_ERROR (Status)) {\r | |
625 | goto ON_EXIT;\r | |
626 | }\r | |
dc361cc5 | 627 | \r |
434ce3fe | 628 | ASSERT (Dhcp4Mode.State == Dhcp4Bound);\r |
dc361cc5 | 629 | \r |
434ce3fe | 630 | CopyMem (&Private->StationIp, &Dhcp4Mode.ClientAddress, sizeof (EFI_IPv4_ADDRESS));\r |
631 | CopyMem (&Private->SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r | |
632 | CopyMem (&Private->GatewayIp, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));\r | |
319075ff | 633 | \r |
434ce3fe | 634 | CopyMem (&Mode->StationIp, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r |
635 | CopyMem (&Mode->SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r | |
dc361cc5 | 636 | \r |
434ce3fe | 637 | //\r |
638 | // Check the selected offer to see whether BINL is required, if no or BINL is\r | |
639 | // finished, set the various Mode members.\r | |
640 | //\r | |
641 | Status = PxeBcCheckSelectedOffer (Private);\r | |
642 | if (!EFI_ERROR (Status)) {\r | |
643 | goto ON_EXIT;\r | |
dc361cc5 | 644 | }\r |
645 | \r | |
434ce3fe | 646 | ON_EXIT:\r |
dc361cc5 | 647 | if (EFI_ERROR (Status)) {\r |
648 | Dhcp4->Stop (Dhcp4);\r | |
649 | Dhcp4->Configure (Dhcp4, NULL);\r | |
650 | } else {\r | |
651 | //\r | |
652 | // Remove the previously configured option list and callback function\r | |
653 | //\r | |
e48e37fc | 654 | ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));\r |
dc361cc5 | 655 | Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);\r |
656 | \r | |
657 | Private->AddressIsOk = TRUE;\r | |
8d285ec0 | 658 | \r |
659 | if (!Mode->UsingIpv6) {\r | |
660 | //\r | |
661 | // If in IPv4 mode, configure the corresponding ARP with this new\r | |
662 | // station IP address.\r | |
663 | //\r | |
664 | ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA));\r | |
665 | \r | |
666 | ArpConfigData.SwAddressType = 0x0800;\r | |
667 | ArpConfigData.SwAddressLength = sizeof (EFI_IPv4_ADDRESS);\r | |
668 | ArpConfigData.StationAddress = &Private->StationIp.v4;\r | |
669 | \r | |
670 | Private->Arp->Configure (Private->Arp, NULL);\r | |
671 | Private->Arp->Configure (Private->Arp, &ArpConfigData);\r | |
982a9eae | 672 | \r |
673 | //\r | |
674 | // Updated the route table. Fill the first entry.\r | |
675 | //\r | |
676 | Mode->RouteTableEntries = 1;\r | |
677 | Mode->RouteTable[0].IpAddr.Addr[0] = Private->StationIp.Addr[0] & Private->SubnetMask.Addr[0];\r | |
678 | Mode->RouteTable[0].SubnetMask.Addr[0] = Private->SubnetMask.Addr[0];\r | |
679 | Mode->RouteTable[0].GwAddr.Addr[0] = 0;\r | |
680 | \r | |
681 | //\r | |
682 | // Create the default route entry if there is a default router.\r | |
683 | //\r | |
684 | if (Private->GatewayIp.Addr[0] != 0) {\r | |
685 | Mode->RouteTableEntries = 2;\r | |
686 | Mode->RouteTable[1].IpAddr.Addr[0] = 0;\r | |
687 | Mode->RouteTable[1].SubnetMask.Addr[0] = 0;\r | |
688 | Mode->RouteTable[1].GwAddr.Addr[0] = Private->GatewayIp.Addr[0];\r | |
689 | }\r | |
8d285ec0 | 690 | }\r |
dc361cc5 | 691 | }\r |
692 | \r | |
693 | return Status;\r | |
694 | }\r | |
695 | \r | |
696 | \r | |
f737cfb9 | 697 | /** \r |
698 | Attempts to complete the PXE Boot Server and/or boot image discovery sequence.\r | |
699 | \r | |
700 | This function attempts to complete the PXE Boot Server and/or boot image discovery\r | |
701 | sequence. If this sequence is completed, then EFI_SUCCESS is returned, and the\r | |
702 | PxeDiscoverValid, PxeDiscover, PxeReplyReceived, and PxeReply fields of the\r | |
703 | EFI_PXE_BASE_CODE_MODE structure are filled in. If UseBis is TRUE, then the\r | |
704 | PxeBisReplyReceived and PxeBisReply fields of the EFI_PXE_BASE_CODE_MODE structure\r | |
705 | will also be filled in. If UseBis is FALSE, then PxeBisReplyValid will be set to FALSE.\r | |
706 | In the structure referenced by parameter Info, the PXE Boot Server list, SrvList[],\r | |
707 | has two uses: It is the Boot Server IP address list used for unicast discovery\r | |
708 | (if the UseUCast field is TRUE), and it is the list used for Boot Server verification\r | |
709 | (if the MustUseList field is TRUE). Also, if the MustUseList field in that structure\r | |
710 | is TRUE and the AcceptAnyResponse field in the SrvList[] array is TRUE, any Boot\r | |
711 | Server reply of that type will be accepted. If the AcceptAnyResponse field is\r | |
712 | FALSE, only responses from Boot Servers with matching IP addresses will be accepted.\r | |
713 | This function can take at least 10 seconds to timeout and return control to the\r | |
714 | caller. If the Discovery sequence does not complete, then EFI_TIMEOUT will be\r | |
715 | returned. Please see the Preboot Execution Environment (PXE) Specification for\r | |
716 | additional details on the implementation of the Discovery sequence.\r | |
717 | If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,\r | |
718 | then the Discovery sequence is stopped and EFI_ABORTED will be returned.\r | |
719 | \r | |
720 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
721 | @param Type The type of bootstrap to perform.\r | |
722 | @param Layer Pointer to the boot server layer number to discover, which must be\r | |
723 | PXE_BOOT_LAYER_INITIAL when a new server type is being \r | |
724 | discovered. \r | |
725 | @param UseBis TRUE if Boot Integrity Services are to be used. FALSE otherwise. \r | |
726 | @param Info Pointer to a data structure that contains additional information on the\r | |
727 | type of discovery operation that is to be performed. \r | |
728 | \r | |
729 | @retval EFI_SUCCESS The Discovery sequence has been completed.\r | |
730 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
731 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. \r | |
732 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation. \r | |
733 | @retval EFI_OUT_OF_RESOURCES Could not allocate enough memory to complete Discovery.\r | |
734 | @retval EFI_ABORTED The callback function aborted the Discovery sequence.\r | |
735 | @retval EFI_TIMEOUT The Discovery sequence timed out.\r | |
736 | @retval EFI_ICMP_ERROR An ICMP error packet was received during the PXE discovery\r | |
737 | session. \r | |
738 | \r | |
dc361cc5 | 739 | **/\r |
740 | EFI_STATUS\r | |
741 | EFIAPI\r | |
742 | EfiPxeBcDiscover (\r | |
743 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
744 | IN UINT16 Type,\r | |
745 | IN UINT16 *Layer,\r | |
746 | IN BOOLEAN UseBis,\r | |
747 | IN EFI_PXE_BASE_CODE_DISCOVER_INFO *Info OPTIONAL\r | |
748 | )\r | |
749 | {\r | |
750 | PXEBC_PRIVATE_DATA *Private;\r | |
751 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
752 | EFI_PXE_BASE_CODE_DISCOVER_INFO DefaultInfo;\r | |
753 | EFI_PXE_BASE_CODE_SRVLIST *SrvList;\r | |
754 | EFI_PXE_BASE_CODE_SRVLIST DefaultSrvList;\r | |
755 | PXEBC_CACHED_DHCP4_PACKET *Packet;\r | |
f737cfb9 | 756 | PXEBC_VENDOR_OPTION *VendorOpt;\r |
dc361cc5 | 757 | UINT16 Index;\r |
758 | EFI_STATUS Status;\r | |
759 | PXEBC_BOOT_SVR_ENTRY *BootSvrEntry;\r | |
760 | \r | |
761 | if (This == NULL) {\r | |
762 | return EFI_INVALID_PARAMETER;\r | |
763 | }\r | |
764 | \r | |
765 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
766 | Mode = Private->PxeBc.Mode;\r | |
767 | BootSvrEntry = NULL;\r | |
768 | SrvList = NULL;\r | |
769 | Status = EFI_DEVICE_ERROR;\r | |
770 | Private->Function = EFI_PXE_BASE_CODE_FUNCTION_DISCOVER;\r | |
771 | \r | |
772 | if (!Private->AddressIsOk) {\r | |
773 | return EFI_INVALID_PARAMETER;\r | |
774 | }\r | |
775 | \r | |
776 | if (!Mode->Started) {\r | |
777 | return EFI_NOT_STARTED;\r | |
778 | }\r | |
779 | \r | |
982a9eae | 780 | Mode->IcmpErrorReceived = FALSE;\r |
781 | \r | |
dc361cc5 | 782 | //\r |
783 | // If layer isn't EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL,\r | |
784 | // use the previous setting;\r | |
785 | // If info isn't offered,\r | |
786 | // use the cached DhcpAck and ProxyOffer packets.\r | |
787 | //\r | |
788 | if (*Layer != EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL) {\r | |
789 | \r | |
790 | if (!Mode->PxeDiscoverValid || !Mode->PxeReplyReceived || (!Mode->PxeBisReplyReceived && UseBis)) {\r | |
791 | \r | |
792 | return EFI_INVALID_PARAMETER;\r | |
793 | }\r | |
794 | \r | |
795 | DefaultInfo.IpCnt = 1;\r | |
796 | DefaultInfo.UseUCast = TRUE;\r | |
797 | \r | |
798 | DefaultSrvList.Type = Type;\r | |
799 | DefaultSrvList.AcceptAnyResponse = FALSE;\r | |
800 | DefaultSrvList.IpAddr.Addr[0] = Private->ServerIp.Addr[0];\r | |
801 | \r | |
802 | SrvList = &DefaultSrvList;\r | |
803 | Info = &DefaultInfo;\r | |
804 | } else if (Info == NULL) {\r | |
805 | //\r | |
806 | // Create info by the cached packet before\r | |
807 | //\r | |
808 | Packet = (Mode->ProxyOfferReceived) ? &Private->ProxyOffer : &Private->Dhcp4Ack;\r | |
809 | VendorOpt = &Packet->PxeVendorOption;\r | |
810 | \r | |
811 | if (!Mode->DhcpAckReceived || !IS_VALID_DISCOVER_VENDOR_OPTION (VendorOpt->BitMap)) {\r | |
812 | //\r | |
813 | // Address is not acquired or no discovery options.\r | |
814 | //\r | |
815 | return EFI_INVALID_PARAMETER;\r | |
816 | }\r | |
817 | \r | |
818 | DefaultInfo.UseMCast = (BOOLEAN)!IS_DISABLE_MCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r | |
819 | DefaultInfo.UseBCast = (BOOLEAN)!IS_DISABLE_BCAST_DISCOVER (VendorOpt->DiscoverCtrl);\r | |
820 | DefaultInfo.MustUseList = (BOOLEAN) IS_ENABLE_USE_SERVER_LIST (VendorOpt->DiscoverCtrl);\r | |
821 | DefaultInfo.UseUCast = DefaultInfo.MustUseList;\r | |
822 | \r | |
823 | if (DefaultInfo.UseMCast) {\r | |
824 | //\r | |
825 | // Get the multicast discover ip address from vendor option.\r | |
826 | //\r | |
f737cfb9 | 827 | CopyMem (\r |
828 | &DefaultInfo.ServerMCastIp.Addr, \r | |
829 | &VendorOpt->DiscoverMcastIp, \r | |
830 | sizeof (EFI_IPv4_ADDRESS)\r | |
831 | );\r | |
dc361cc5 | 832 | }\r |
833 | \r | |
834 | DefaultInfo.IpCnt = 0;\r | |
835 | \r | |
836 | if (DefaultInfo.MustUseList) {\r | |
837 | BootSvrEntry = VendorOpt->BootSvr;\r | |
838 | Status = EFI_INVALID_PARAMETER;\r | |
839 | \r | |
840 | while (((UINT8) (BootSvrEntry - VendorOpt->BootSvr)) < VendorOpt->BootSvrLen) {\r | |
841 | \r | |
842 | if (BootSvrEntry->Type == HTONS (Type)) {\r | |
843 | Status = EFI_SUCCESS;\r | |
844 | break;\r | |
845 | }\r | |
846 | \r | |
847 | BootSvrEntry = GET_NEXT_BOOT_SVR_ENTRY (BootSvrEntry);\r | |
848 | }\r | |
849 | \r | |
850 | if (EFI_ERROR (Status)) {\r | |
851 | return Status;\r | |
852 | }\r | |
853 | \r | |
854 | DefaultInfo.IpCnt = BootSvrEntry->IpCnt;\r | |
855 | }\r | |
856 | \r | |
857 | Info = &DefaultInfo;\r | |
858 | } else {\r | |
859 | \r | |
860 | SrvList = Info->SrvList;\r | |
861 | \r | |
862 | if (!SrvList[0].AcceptAnyResponse) {\r | |
863 | \r | |
864 | for (Index = 1; Index < Info->IpCnt; Index++) {\r | |
865 | if (SrvList[Index].AcceptAnyResponse) {\r | |
866 | break;\r | |
867 | }\r | |
868 | }\r | |
869 | \r | |
870 | if (Index != Info->IpCnt) {\r | |
871 | return EFI_INVALID_PARAMETER;\r | |
872 | }\r | |
873 | }\r | |
874 | }\r | |
875 | \r | |
876 | if ((!Info->UseUCast && !Info->UseBCast && !Info->UseMCast) || (Info->MustUseList && Info->IpCnt == 0)) {\r | |
877 | \r | |
878 | return EFI_INVALID_PARAMETER;\r | |
879 | }\r | |
880 | //\r | |
881 | // Execute discover by UniCast/BroadCast/MultiCast\r | |
882 | //\r | |
883 | if (Info->UseUCast) {\r | |
884 | \r | |
885 | for (Index = 0; Index < Info->IpCnt; Index++) {\r | |
886 | \r | |
887 | if (BootSvrEntry == NULL) {\r | |
888 | Private->ServerIp.Addr[0] = SrvList[Index].IpAddr.Addr[0];\r | |
889 | } else {\r | |
f737cfb9 | 890 | CopyMem (\r |
891 | &Private->ServerIp, \r | |
892 | &BootSvrEntry->IpAddr[Index], \r | |
893 | sizeof (EFI_IPv4_ADDRESS)\r | |
894 | );\r | |
dc361cc5 | 895 | }\r |
896 | \r | |
897 | Status = PxeBcDiscvBootService (\r | |
898 | Private,\r | |
899 | Type,\r | |
900 | Layer,\r | |
901 | UseBis,\r | |
902 | &SrvList[Index].IpAddr,\r | |
903 | 0,\r | |
904 | NULL,\r | |
905 | TRUE,\r | |
906 | &Private->PxeReply.Packet.Ack\r | |
907 | );\r | |
908 | }\r | |
909 | \r | |
910 | } else if (Info->UseMCast) {\r | |
911 | \r | |
912 | Status = PxeBcDiscvBootService (\r | |
913 | Private,\r | |
914 | Type,\r | |
915 | Layer,\r | |
916 | UseBis,\r | |
917 | &Info->ServerMCastIp,\r | |
918 | 0,\r | |
919 | NULL,\r | |
920 | TRUE,\r | |
921 | &Private->PxeReply.Packet.Ack\r | |
922 | );\r | |
923 | \r | |
924 | } else if (Info->UseBCast) {\r | |
925 | \r | |
926 | Status = PxeBcDiscvBootService (\r | |
927 | Private,\r | |
928 | Type,\r | |
929 | Layer,\r | |
930 | UseBis,\r | |
931 | NULL,\r | |
932 | Info->IpCnt,\r | |
933 | SrvList,\r | |
934 | TRUE,\r | |
935 | &Private->PxeReply.Packet.Ack\r | |
936 | );\r | |
937 | }\r | |
938 | \r | |
939 | if (EFI_ERROR (Status) || !Mode->PxeReplyReceived || (!Mode->PxeBisReplyReceived && UseBis)) {\r | |
982a9eae | 940 | if (Status == EFI_ICMP_ERROR) {\r |
941 | Mode->IcmpErrorReceived = TRUE;\r | |
942 | } else {\r | |
943 | Status = EFI_DEVICE_ERROR;\r | |
944 | }\r | |
dc361cc5 | 945 | } else {\r |
946 | PxeBcParseCachedDhcpPacket (&Private->PxeReply);\r | |
947 | }\r | |
948 | \r | |
949 | if (Mode->PxeBisReplyReceived) {\r | |
f737cfb9 | 950 | CopyMem (\r |
951 | &Private->ServerIp, \r | |
952 | &Mode->PxeReply.Dhcpv4.BootpSiAddr, \r | |
953 | sizeof (EFI_IPv4_ADDRESS)\r | |
954 | );\r | |
dc361cc5 | 955 | }\r |
956 | \r | |
957 | return Status;\r | |
958 | }\r | |
959 | \r | |
960 | \r | |
f737cfb9 | 961 | /** \r |
962 | Used to perform TFTP and MTFTP services.\r | |
963 | \r | |
964 | This function is used to perform TFTP and MTFTP services. This includes the\r | |
965 | TFTP operations to get the size of a file, read a directory, read a file, and\r | |
966 | write a file. It also includes the MTFTP operations to get the size of a file,\r | |
967 | read a directory, and read a file. The type of operation is specified by Operation.\r | |
968 | If the callback function that is invoked during the TFTP/MTFTP operation does\r | |
969 | not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will\r | |
970 | be returned.\r | |
971 | For read operations, the return data will be placed in the buffer specified by\r | |
972 | BufferPtr. If BufferSize is too small to contain the entire downloaded file,\r | |
973 | then EFI_BUFFER_TOO_SMALL will be returned and BufferSize will be set to zero\r | |
974 | or the size of the requested file (the size of the requested file is only returned\r | |
975 | if the TFTP server supports TFTP options). If BufferSize is large enough for the\r | |
976 | read operation, then BufferSize will be set to the size of the downloaded file,\r | |
977 | and EFI_SUCCESS will be returned. Applications using the PxeBc.Mtftp() services\r | |
978 | should use the get-file-size operations to determine the size of the downloaded\r | |
979 | file prior to using the read-file operations-especially when downloading large\r | |
980 | (greater than 64 MB) files-instead of making two calls to the read-file operation.\r | |
981 | Following this recommendation will save time if the file is larger than expected\r | |
982 | and the TFTP server does not support TFTP option extensions. Without TFTP option\r | |
983 | extension support, the client has to download the entire file, counting and discarding\r | |
984 | the received packets, to determine the file size.\r | |
985 | For write operations, the data to be sent is in the buffer specified by BufferPtr.\r | |
986 | BufferSize specifies the number of bytes to send. If the write operation completes\r | |
987 | successfully, then EFI_SUCCESS will be returned.\r | |
988 | For TFTP "get file size" operations, the size of the requested file or directory\r | |
989 | is returned in BufferSize, and EFI_SUCCESS will be returned. If the TFTP server\r | |
990 | does not support options, the file will be downloaded into a bit bucket and the\r | |
991 | length of the downloaded file will be returned. For MTFTP "get file size" operations,\r | |
992 | if the MTFTP server does not support the "get file size" option, EFI_UNSUPPORTED\r | |
993 | will be returned.\r | |
994 | This function can take up to 10 seconds to timeout and return control to the caller.\r | |
995 | If the TFTP sequence does not complete, EFI_TIMEOUT will be returned.\r | |
996 | If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE,\r | |
997 | then the TFTP sequence is stopped and EFI_ABORTED will be returned.\r | |
998 | The format of the data returned from a TFTP read directory operation is a null-terminated\r | |
999 | filename followed by a null-terminated information string, of the form\r | |
1000 | "size year-month-day hour:minute:second" (i.e. %d %d-%d-%d %d:%d:%f - note that\r | |
1001 | the seconds field can be a decimal number), where the date and time are UTC. For\r | |
1002 | an MTFTP read directory command, there is additionally a null-terminated multicast\r | |
1003 | IP address preceding the filename of the form %d.%d.%d.%d for IP v4. The final\r | |
1004 | entry is itself null-terminated, so that the final information string is terminated\r | |
1005 | with two null octets.\r | |
1006 | \r | |
1007 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
1008 | @param Operation The type of operation to perform.\r | |
1009 | @param BufferPtr A pointer to the data buffer. \r | |
1010 | @param Overwrite Only used on write file operations. TRUE if a file on a remote server can\r | |
1011 | be overwritten. \r | |
1012 | @param BufferSize For get-file-size operations, *BufferSize returns the size of the\r | |
1013 | requested file. \r | |
1014 | @param BlockSize The requested block size to be used during a TFTP transfer.\r | |
1015 | @param ServerIp The TFTP / MTFTP server IP address.\r | |
1016 | @param Filename A Null-terminated ASCII string that specifies a directory name or a file\r | |
1017 | name. \r | |
1018 | @param Info Pointer to the MTFTP information.\r | |
1019 | @param DontUseBuffer Set to FALSE for normal TFTP and MTFTP read file operation. \r | |
1020 | \r | |
1021 | @retval EFI_SUCCESS The TFTP/MTFTP operation was completed.\r | |
1022 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
1023 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. \r | |
1024 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation. \r | |
1025 | @retval EFI_BUFFER_TOO_SMALL The buffer is not large enough to complete the read operation. \r | |
1026 | @retval EFI_ABORTED The callback function aborted the TFTP/MTFTP operation.\r | |
1027 | @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.\r | |
1028 | @retval EFI_ICMP_ERROR An ICMP error packet was received during the MTFTP session.\r | |
1029 | @retval EFI_TFTP_ERROR A TFTP error packet was received during the MTFTP session.\r | |
1030 | \r | |
dc361cc5 | 1031 | **/\r |
1032 | EFI_STATUS\r | |
1033 | EFIAPI\r | |
1034 | EfiPxeBcMtftp (\r | |
1035 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
1036 | IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation,\r | |
1037 | IN OUT VOID *BufferPtr,\r | |
1038 | IN BOOLEAN Overwrite,\r | |
1039 | IN OUT UINT64 *BufferSize,\r | |
1040 | IN UINTN *BlockSize OPTIONAL,\r | |
1041 | IN EFI_IP_ADDRESS *ServerIp,\r | |
1042 | IN UINT8 *Filename,\r | |
1043 | IN EFI_PXE_BASE_CODE_MTFTP_INFO *Info OPTIONAL,\r | |
1044 | IN BOOLEAN DontUseBuffer\r | |
1045 | )\r | |
1046 | {\r | |
1047 | PXEBC_PRIVATE_DATA *Private;\r | |
1048 | EFI_MTFTP4_CONFIG_DATA Mtftp4Config;\r | |
1049 | EFI_STATUS Status;\r | |
982a9eae | 1050 | EFI_PXE_BASE_CODE_MODE *Mode;\r |
1051 | EFI_MAC_ADDRESS TempMacAddr;\r | |
dc361cc5 | 1052 | \r |
f737cfb9 | 1053 | if ((This == NULL) ||\r |
1054 | (Filename == NULL) ||\r | |
1055 | (BufferSize == NULL) ||\r | |
dc361cc5 | 1056 | ((ServerIp == NULL) || !Ip4IsUnicast (NTOHL (ServerIp->Addr[0]), 0)) ||\r |
f737cfb9 | 1057 | ((BufferPtr == NULL) && DontUseBuffer) ||\r |
dc361cc5 | 1058 | ((BlockSize != NULL) && (*BlockSize < 512))) {\r |
1059 | \r | |
1060 | return EFI_INVALID_PARAMETER;\r | |
1061 | }\r | |
1062 | \r | |
1063 | Status = EFI_DEVICE_ERROR;\r | |
1064 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
982a9eae | 1065 | Mode = &Private->Mode;\r |
1066 | \r | |
1067 | if (!Mode->AutoArp) {\r | |
1068 | //\r | |
1069 | // If AutoArp is set false, check arp cache\r | |
1070 | //\r | |
1071 | UpdateArpCache (This);\r | |
1072 | if (!FindInArpCache (Mode, &ServerIp->v4, &TempMacAddr)) {\r | |
1073 | return EFI_DEVICE_ERROR;\r | |
1074 | }\r | |
1075 | }\r | |
1076 | \r | |
1077 | Mode->TftpErrorReceived = FALSE;\r | |
1078 | Mode->IcmpErrorReceived = FALSE;\r | |
dc361cc5 | 1079 | \r |
1080 | Mtftp4Config.UseDefaultSetting = FALSE;\r | |
1081 | Mtftp4Config.TimeoutValue = PXEBC_MTFTP_TIMEOUT;\r | |
1082 | Mtftp4Config.TryCount = PXEBC_MTFTP_RETRIES;\r | |
1083 | \r | |
f737cfb9 | 1084 | CopyMem (\r |
1085 | &Mtftp4Config.StationIp, \r | |
1086 | &Private->StationIp, \r | |
1087 | sizeof (EFI_IPv4_ADDRESS)\r | |
1088 | );\r | |
1089 | CopyMem (\r | |
1090 | &Mtftp4Config.SubnetMask, \r | |
1091 | &Private->SubnetMask, \r | |
1092 | sizeof (EFI_IPv4_ADDRESS)\r | |
1093 | );\r | |
1094 | CopyMem (\r | |
1095 | &Mtftp4Config.GatewayIp, \r | |
1096 | &Private->GatewayIp, \r | |
1097 | sizeof (EFI_IPv4_ADDRESS)\r | |
1098 | );\r | |
1099 | CopyMem (\r | |
1100 | &Mtftp4Config.ServerIp, \r | |
1101 | ServerIp, \r | |
1102 | sizeof (EFI_IPv4_ADDRESS)\r | |
1103 | );\r | |
dc361cc5 | 1104 | \r |
1105 | switch (Operation) {\r | |
1106 | \r | |
1107 | case EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE:\r | |
1108 | \r | |
1109 | Status = PxeBcTftpGetFileSize (\r | |
1110 | Private,\r | |
1111 | &Mtftp4Config,\r | |
1112 | Filename,\r | |
1113 | BlockSize,\r | |
1114 | BufferSize\r | |
1115 | );\r | |
1116 | \r | |
dc361cc5 | 1117 | break;\r |
1118 | \r | |
1119 | case EFI_PXE_BASE_CODE_TFTP_READ_FILE:\r | |
1120 | \r | |
1121 | Status = PxeBcTftpReadFile (\r | |
1122 | Private,\r | |
1123 | &Mtftp4Config,\r | |
1124 | Filename,\r | |
1125 | BlockSize,\r | |
1126 | BufferPtr,\r | |
1127 | BufferSize,\r | |
1128 | DontUseBuffer\r | |
1129 | );\r | |
1130 | \r | |
1131 | break;\r | |
1132 | \r | |
1133 | case EFI_PXE_BASE_CODE_TFTP_WRITE_FILE:\r | |
1134 | \r | |
1135 | Status = PxeBcTftpWriteFile (\r | |
1136 | Private,\r | |
1137 | &Mtftp4Config,\r | |
1138 | Filename,\r | |
1139 | Overwrite,\r | |
1140 | BlockSize,\r | |
1141 | BufferPtr,\r | |
1142 | BufferSize\r | |
1143 | );\r | |
1144 | \r | |
1145 | break;\r | |
1146 | \r | |
1147 | case EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY:\r | |
1148 | \r | |
1149 | Status = PxeBcTftpReadDirectory (\r | |
1150 | Private,\r | |
1151 | &Mtftp4Config,\r | |
1152 | Filename,\r | |
1153 | BlockSize,\r | |
1154 | BufferPtr,\r | |
1155 | BufferSize,\r | |
1156 | DontUseBuffer\r | |
1157 | );\r | |
1158 | \r | |
1159 | break;\r | |
1160 | \r | |
1161 | case EFI_PXE_BASE_CODE_MTFTP_GET_FILE_SIZE:\r | |
1162 | case EFI_PXE_BASE_CODE_MTFTP_READ_FILE:\r | |
1163 | case EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY:\r | |
1164 | Status = EFI_UNSUPPORTED;\r | |
1165 | break;\r | |
1166 | \r | |
1167 | default:\r | |
1168 | \r | |
1169 | Status = EFI_INVALID_PARAMETER;\r | |
1170 | break;\r | |
1171 | }\r | |
1172 | \r | |
982a9eae | 1173 | if (Status == EFI_ICMP_ERROR) {\r |
1174 | Mode->IcmpErrorReceived = TRUE;\r | |
1175 | }\r | |
1176 | \r | |
dc361cc5 | 1177 | return Status;\r |
1178 | }\r | |
1179 | \r | |
1180 | \r | |
f737cfb9 | 1181 | /** \r |
1182 | Writes a UDP packet to the network interface.\r | |
1183 | \r | |
1184 | This function writes a UDP packet specified by the (optional HeaderPtr and)\r | |
1185 | BufferPtr parameters to the network interface. The UDP header is automatically\r | |
1186 | built by this routine. It uses the parameters OpFlags, DestIp, DestPort, GatewayIp,\r | |
1187 | SrcIp, and SrcPort to build this header. If the packet is successfully built and\r | |
1188 | transmitted through the network interface, then EFI_SUCCESS will be returned.\r | |
1189 | If a timeout occurs during the transmission of the packet, then EFI_TIMEOUT will\r | |
1190 | be returned. If an ICMP error occurs during the transmission of the packet, then\r | |
1191 | the IcmpErrorReceived field is set to TRUE, the IcmpError field is filled in and\r | |
1192 | EFI_ICMP_ERROR will be returned. If the Callback Protocol does not return\r | |
1193 | EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, then EFI_ABORTED will be returned.\r | |
1194 | \r | |
1195 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
1196 | @param OpFlags The UDP operation flags. \r | |
1197 | @param DestIp The destination IP address.\r | |
1198 | @param DestPort The destination UDP port number. \r | |
1199 | @param GatewayIp The gateway IP address. \r | |
1200 | @param SrcIp The source IP address.\r | |
1201 | @param SrcPort The source UDP port number.\r | |
1202 | @param HeaderSize An optional field which may be set to the length of a header at\r | |
1203 | HeaderPtr to be prefixed to the data at BufferPtr. \r | |
1204 | @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the\r | |
1205 | data at BufferPtr. \r | |
1206 | @param BufferSize A pointer to the size of the data at BufferPtr.\r | |
1207 | @param BufferPtr A pointer to the data to be written.\r | |
1208 | \r | |
1209 | @retval EFI_SUCCESS The UDP Write operation was completed.\r | |
1210 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
1211 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. \r | |
1212 | @retval EFI_BAD_BUFFER_SIZE The buffer is too long to be transmitted. \r | |
1213 | @retval EFI_ABORTED The callback function aborted the UDP Write operation.\r | |
1214 | @retval EFI_TIMEOUT The UDP Write operation timed out.\r | |
1215 | @retval EFI_ICMP_ERROR An ICMP error packet was received during the UDP write session. \r | |
1216 | \r | |
dc361cc5 | 1217 | **/\r |
1218 | EFI_STATUS\r | |
1219 | EFIAPI\r | |
1220 | EfiPxeBcUdpWrite (\r | |
1221 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
1222 | IN UINT16 OpFlags,\r | |
1223 | IN EFI_IP_ADDRESS *DestIp,\r | |
1224 | IN EFI_PXE_BASE_CODE_UDP_PORT *DestPort,\r | |
1225 | IN EFI_IP_ADDRESS *GatewayIp OPTIONAL,\r | |
1226 | IN EFI_IP_ADDRESS *SrcIp OPTIONAL,\r | |
1227 | IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,\r | |
1228 | IN UINTN *HeaderSize OPTIONAL,\r | |
1229 | IN VOID *HeaderPtr OPTIONAL,\r | |
1230 | IN UINTN *BufferSize,\r | |
1231 | IN VOID *BufferPtr\r | |
1232 | )\r | |
1233 | {\r | |
1234 | PXEBC_PRIVATE_DATA *Private;\r | |
1235 | EFI_UDP4_PROTOCOL *Udp4;\r | |
1236 | EFI_UDP4_COMPLETION_TOKEN Token;\r | |
1237 | EFI_UDP4_TRANSMIT_DATA *Udp4TxData;\r | |
1238 | UINT32 FragCount;\r | |
1239 | UINT32 DataLength;\r | |
1240 | EFI_UDP4_SESSION_DATA Udp4Session;\r | |
1241 | EFI_STATUS Status;\r | |
1242 | BOOLEAN IsDone;\r | |
982a9eae | 1243 | EFI_PXE_BASE_CODE_MODE *Mode;\r |
1244 | EFI_MAC_ADDRESS TempMacAddr;\r | |
dc361cc5 | 1245 | \r |
1246 | IsDone = FALSE;\r | |
1247 | \r | |
1248 | if ((This == NULL) || (DestIp == NULL) || (DestPort == NULL)) {\r | |
1249 | return EFI_INVALID_PARAMETER;\r | |
1250 | }\r | |
1251 | \r | |
1252 | if ((GatewayIp != NULL) && !Ip4IsUnicast (NTOHL (GatewayIp->Addr[0]), 0)) {\r | |
1253 | //\r | |
1254 | // Gateway is provided but it's not a unicast IP address.\r | |
1255 | //\r | |
1256 | return EFI_INVALID_PARAMETER;\r | |
1257 | }\r | |
1258 | \r | |
1259 | if ((HeaderSize != NULL) && ((*HeaderSize == 0) || (HeaderPtr == NULL))) {\r | |
1260 | //\r | |
1261 | // The HeaderSize ptr isn't NULL and: 1. the value is zero; or 2. the HeaderPtr\r | |
1262 | // is NULL.\r | |
1263 | //\r | |
1264 | return EFI_INVALID_PARAMETER;\r | |
1265 | }\r | |
1266 | \r | |
1267 | if ((BufferSize == NULL) || ((*BufferSize != 0) && (BufferPtr == NULL))) {\r | |
1268 | return EFI_INVALID_PARAMETER;\r | |
1269 | }\r | |
1270 | \r | |
1271 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
8792362f | 1272 | Udp4 = Private->Udp4Write;\r |
982a9eae | 1273 | Mode = &Private->Mode;\r |
8792362f | 1274 | if (!Mode->Started) {\r |
1275 | return EFI_NOT_STARTED;\r | |
1276 | }\r | |
dc361cc5 | 1277 | \r |
1278 | if (!Private->AddressIsOk && (SrcIp == NULL)) {\r | |
1279 | return EFI_INVALID_PARAMETER;\r | |
1280 | }\r | |
1281 | \r | |
982a9eae | 1282 | if (!Mode->AutoArp) {\r |
1283 | //\r | |
1284 | // If AutoArp is set false, check arp cache\r | |
1285 | //\r | |
1286 | UpdateArpCache (This);\r | |
1287 | if (!FindInArpCache (Mode, &DestIp->v4, &TempMacAddr)) {\r | |
1288 | return EFI_DEVICE_ERROR;\r | |
1289 | }\r | |
1290 | }\r | |
1291 | \r | |
1292 | Mode->IcmpErrorReceived = FALSE;\r | |
1293 | \r | |
8792362f | 1294 | if ((Private->CurrentUdpSrcPort == 0) ||\r |
f737cfb9 | 1295 | ((SrcPort != NULL) && (*SrcPort != Private->CurrentUdpSrcPort))) {\r |
8792362f | 1296 | //\r |
1297 | // Port is changed, (re)configure the Udp4Write instance\r | |
1298 | //\r | |
1299 | if (SrcPort != NULL) {\r | |
1300 | Private->CurrentUdpSrcPort = *SrcPort;\r | |
dc361cc5 | 1301 | }\r |
dc361cc5 | 1302 | \r |
8792362f | 1303 | Status = PxeBcConfigureUdpWriteInstance (\r |
1304 | Udp4,\r | |
1305 | &Private->StationIp.v4,\r | |
1306 | &Private->SubnetMask.v4,\r | |
1307 | &Private->GatewayIp.v4,\r | |
1308 | &Private->CurrentUdpSrcPort\r | |
1309 | );\r | |
1310 | if (EFI_ERROR (Status)) {\r | |
1311 | Private->CurrentUdpSrcPort = 0;\r | |
1312 | return EFI_INVALID_PARAMETER;\r | |
dc361cc5 | 1313 | }\r |
1314 | }\r | |
1315 | \r | |
1316 | ZeroMem (&Token, sizeof (EFI_UDP4_COMPLETION_TOKEN));\r | |
1317 | ZeroMem (&Udp4Session, sizeof (EFI_UDP4_SESSION_DATA));\r | |
1318 | \r | |
e48e37fc | 1319 | CopyMem (&Udp4Session.DestinationAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));\r |
dc361cc5 | 1320 | Udp4Session.DestinationPort = *DestPort;\r |
8792362f | 1321 | if (SrcIp != NULL) {\r |
1322 | CopyMem (&Udp4Session.SourceAddress, SrcIp, sizeof (EFI_IPv4_ADDRESS));\r | |
1323 | }\r | |
1324 | if (SrcPort != NULL) {\r | |
1325 | Udp4Session.SourcePort = *SrcPort;\r | |
1326 | }\r | |
dc361cc5 | 1327 | \r |
1328 | FragCount = (HeaderSize != NULL) ? 2 : 1;\r | |
05c0e3cb | 1329 | Udp4TxData = (EFI_UDP4_TRANSMIT_DATA *) AllocateZeroPool (sizeof (EFI_UDP4_TRANSMIT_DATA) + (FragCount - 1) * sizeof (EFI_UDP4_FRAGMENT_DATA));\r |
dc361cc5 | 1330 | if (Udp4TxData == NULL) {\r |
1331 | return EFI_OUT_OF_RESOURCES;\r | |
1332 | }\r | |
1333 | \r | |
1334 | Udp4TxData->FragmentCount = FragCount;\r | |
1335 | Udp4TxData->FragmentTable[FragCount - 1].FragmentLength = (UINT32) *BufferSize;\r | |
1336 | Udp4TxData->FragmentTable[FragCount - 1].FragmentBuffer = BufferPtr;\r | |
1337 | DataLength = (UINT32) *BufferSize;\r | |
1338 | \r | |
1339 | if (FragCount == 2) {\r | |
1340 | \r | |
1341 | Udp4TxData->FragmentTable[0].FragmentLength = (UINT32) *HeaderSize;\r | |
1342 | Udp4TxData->FragmentTable[0].FragmentBuffer = HeaderPtr;\r | |
1343 | DataLength += (UINT32) *HeaderSize;\r | |
1344 | }\r | |
1345 | \r | |
8792362f | 1346 | if (GatewayIp != NULL) {\r |
1347 | Udp4TxData->GatewayAddress = (EFI_IPv4_ADDRESS *) GatewayIp;\r | |
1348 | }\r | |
dc361cc5 | 1349 | Udp4TxData->UdpSessionData = &Udp4Session;\r |
1350 | Udp4TxData->DataLength = DataLength;\r | |
1351 | Token.Packet.TxData = Udp4TxData;\r | |
1352 | \r | |
1353 | Status = gBS->CreateEvent (\r | |
1354 | EVT_NOTIFY_SIGNAL,\r | |
e48e37fc | 1355 | TPL_NOTIFY,\r |
dc361cc5 | 1356 | PxeBcCommonNotify,\r |
1357 | &IsDone,\r | |
1358 | &Token.Event\r | |
1359 | );\r | |
1360 | if (EFI_ERROR (Status)) {\r | |
1361 | goto ON_EXIT;\r | |
1362 | }\r | |
1363 | \r | |
1364 | Status = Udp4->Transmit (Udp4, &Token);\r | |
1365 | if (EFI_ERROR (Status)) {\r | |
982a9eae | 1366 | if (Status == EFI_ICMP_ERROR) {\r |
1367 | Mode->IcmpErrorReceived = TRUE;\r | |
1368 | }\r | |
dc361cc5 | 1369 | goto ON_EXIT;\r |
1370 | }\r | |
1371 | \r | |
1372 | while (!IsDone) {\r | |
1373 | \r | |
1374 | Udp4->Poll (Udp4);\r | |
1375 | }\r | |
1376 | \r | |
1377 | Status = Token.Status;\r | |
1378 | \r | |
1379 | ON_EXIT:\r | |
1380 | \r | |
1381 | if (Token.Event != NULL) {\r | |
1382 | gBS->CloseEvent (Token.Event);\r | |
1383 | }\r | |
1384 | \r | |
e48e37fc | 1385 | gBS->FreePool (Udp4TxData);\r |
dc361cc5 | 1386 | \r |
1387 | return Status;\r | |
1388 | }\r | |
1389 | \r | |
8d285ec0 | 1390 | /**\r |
f737cfb9 | 1391 | Decide whether the incoming UDP packet is acceptable per IP filter settings\r |
1392 | in provided PxeBcMode.\r | |
8d285ec0 | 1393 | \r |
f737cfb9 | 1394 | @param PxeBcMode Pointer to EFI_PXE_BASE_CODE_MODE.\r |
1395 | @param Session Received UDP session.\r | |
8d285ec0 | 1396 | \r |
f737cfb9 | 1397 | @retval TRUE The UDP package matches IP filters.\r |
1398 | @retval FALSE The UDP package doesn't matches IP filters.\r | |
8d285ec0 | 1399 | \r |
1400 | **/\r | |
8d285ec0 | 1401 | BOOLEAN\r |
1402 | CheckIpByFilter (\r | |
f737cfb9 | 1403 | IN EFI_PXE_BASE_CODE_MODE *PxeBcMode,\r |
1404 | IN EFI_UDP4_SESSION_DATA *Session\r | |
8d285ec0 | 1405 | )\r |
1406 | {\r | |
1407 | UINTN Index;\r | |
1408 | EFI_IPv4_ADDRESS Ip4Address;\r | |
1409 | EFI_IPv4_ADDRESS DestIp4Address;\r | |
1410 | \r | |
f737cfb9 | 1411 | if ((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS) != 0) {\r |
8d285ec0 | 1412 | return TRUE;\r |
1413 | }\r | |
1414 | \r | |
1415 | CopyMem (&DestIp4Address, &Session->DestinationAddress, sizeof (DestIp4Address));\r | |
1416 | if ((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST) &&\r | |
982a9eae | 1417 | IP4_IS_MULTICAST (EFI_NTOHL (DestIp4Address))\r |
8d285ec0 | 1418 | ) {\r |
1419 | return TRUE;\r | |
1420 | }\r | |
1421 | \r | |
1422 | if ((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST) &&\r | |
1423 | IP4_IS_LOCAL_BROADCAST (EFI_NTOHL (DestIp4Address))\r | |
1424 | ) {\r | |
1425 | return TRUE;\r | |
1426 | }\r | |
1427 | \r | |
1428 | CopyMem (&Ip4Address, &PxeBcMode->StationIp.v4, sizeof (Ip4Address));\r | |
1429 | if ((PxeBcMode->IpFilter.Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) &&\r | |
982a9eae | 1430 | EFI_IP4_EQUAL (&Ip4Address, &DestIp4Address)\r |
8d285ec0 | 1431 | ) {\r |
1432 | return TRUE;\r | |
1433 | }\r | |
1434 | \r | |
f737cfb9 | 1435 | for (Index = 0; Index < PxeBcMode->IpFilter.IpCnt; Index++) {\r |
1436 | CopyMem (\r | |
1437 | &Ip4Address, \r | |
1438 | &PxeBcMode->IpFilter.IpList[Index].v4, \r | |
1439 | sizeof (Ip4Address)\r | |
1440 | );\r | |
8d285ec0 | 1441 | if (EFI_IP4_EQUAL (&Ip4Address, &DestIp4Address)) {\r |
1442 | return TRUE;\r | |
1443 | }\r | |
1444 | }\r | |
1445 | \r | |
1446 | return FALSE;\r | |
1447 | }\r | |
dc361cc5 | 1448 | \r |
f737cfb9 | 1449 | /** \r |
1450 | Reads a UDP packet from the network interface.\r | |
1451 | \r | |
1452 | This function reads a UDP packet from a network interface. The data contents\r | |
1453 | are returned in (the optional HeaderPtr and) BufferPtr, and the size of the\r | |
1454 | buffer received is returned in BufferSize . If the input BufferSize is smaller\r | |
1455 | than the UDP packet received (less optional HeaderSize), it will be set to the\r | |
1456 | required size, and EFI_BUFFER_TOO_SMALL will be returned. In this case, the\r | |
1457 | contents of BufferPtr are undefined, and the packet is lost. If a UDP packet is\r | |
1458 | successfully received, then EFI_SUCCESS will be returned, and the information\r | |
1459 | from the UDP header will be returned in DestIp, DestPort, SrcIp, and SrcPort if\r | |
1460 | they are not NULL. Depending on the values of OpFlags and the DestIp, DestPort, \r | |
1461 | SrcIp, and SrcPort input values, different types of UDP packet receive filtering \r | |
1462 | will be performed. The following tables summarize these receive filter operations.\r | |
1463 | \r | |
1464 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
1465 | @param OpFlags The UDP operation flags. \r | |
1466 | @param DestIp The destination IP address.\r | |
1467 | @param DestPort The destination UDP port number.\r | |
1468 | @param SrcIp The source IP address.\r | |
1469 | @param SrcPort The source UDP port number.\r | |
1470 | @param HeaderSize An optional field which may be set to the length of a header at\r | |
1471 | HeaderPtr to be prefixed to the data at BufferPtr. \r | |
1472 | @param HeaderPtr If HeaderSize is not NULL, a pointer to a header to be prefixed to the\r | |
1473 | data at BufferPtr. \r | |
1474 | @param BufferSize A pointer to the size of the data at BufferPtr.\r | |
1475 | @param BufferPtr A pointer to the data to be read.\r | |
1476 | \r | |
1477 | @retval EFI_SUCCESS The UDP Read operation was completed.\r | |
1478 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
1479 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. \r | |
1480 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation.\r | |
1481 | @retval EFI_BUFFER_TOO_SMALL The packet is larger than Buffer can hold.\r | |
1482 | @retval EFI_ABORTED The callback function aborted the UDP Read operation.\r | |
1483 | @retval EFI_TIMEOUT The UDP Read operation timed out. \r | |
1484 | \r | |
dc361cc5 | 1485 | **/\r |
1486 | EFI_STATUS\r | |
1487 | EFIAPI\r | |
1488 | EfiPxeBcUdpRead (\r | |
f737cfb9 | 1489 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r |
1490 | IN UINT16 OpFlags,\r | |
1491 | IN OUT EFI_IP_ADDRESS *DestIp OPTIONAL,\r | |
1492 | IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort OPTIONAL,\r | |
1493 | IN OUT EFI_IP_ADDRESS *SrcIp OPTIONAL,\r | |
1494 | IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,\r | |
1495 | IN UINTN *HeaderSize OPTIONAL,\r | |
1496 | IN VOID *HeaderPtr OPTIONAL,\r | |
1497 | IN OUT UINTN *BufferSize,\r | |
1498 | IN VOID *BufferPtr\r | |
dc361cc5 | 1499 | )\r |
1500 | {\r | |
1501 | PXEBC_PRIVATE_DATA *Private;\r | |
1502 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
1503 | EFI_UDP4_PROTOCOL *Udp4;\r | |
1504 | EFI_UDP4_COMPLETION_TOKEN Token;\r | |
1505 | EFI_UDP4_RECEIVE_DATA *RxData;\r | |
1506 | EFI_UDP4_SESSION_DATA *Session;\r | |
1507 | EFI_STATUS Status;\r | |
1508 | BOOLEAN IsDone;\r | |
1509 | BOOLEAN Matched;\r | |
1510 | UINTN CopyLen;\r | |
1511 | \r | |
1512 | if (This == NULL || DestIp == NULL || DestPort == NULL) {\r | |
1513 | return EFI_INVALID_PARAMETER;\r | |
1514 | }\r | |
1515 | \r | |
f737cfb9 | 1516 | if (((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) == 0 && (DestPort == NULL)) ||\r |
1517 | ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) == 0 && (SrcIp == NULL)) ||\r | |
1518 | ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) == 0 && (SrcPort == NULL))) {\r | |
dc361cc5 | 1519 | return EFI_INVALID_PARAMETER;\r |
1520 | }\r | |
1521 | \r | |
8792362f | 1522 | if (((HeaderSize != NULL) && (*HeaderSize == 0)) || ((HeaderSize != NULL) && (HeaderPtr == NULL))) {\r |
dc361cc5 | 1523 | return EFI_INVALID_PARAMETER;\r |
1524 | }\r | |
1525 | \r | |
1526 | if ((BufferSize == NULL) || ((BufferPtr == NULL) && (*BufferSize != 0))) {\r | |
1527 | return EFI_INVALID_PARAMETER;\r | |
1528 | }\r | |
1529 | \r | |
1530 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
1531 | Mode = Private->PxeBc.Mode;\r | |
8792362f | 1532 | Udp4 = Private->Udp4Read;\r |
dc361cc5 | 1533 | \r |
1534 | if (!Mode->Started) {\r | |
1535 | return EFI_NOT_STARTED;\r | |
1536 | }\r | |
1537 | \r | |
982a9eae | 1538 | Mode->IcmpErrorReceived = FALSE;\r |
1539 | \r | |
dc361cc5 | 1540 | Status = gBS->CreateEvent (\r |
1541 | EVT_NOTIFY_SIGNAL,\r | |
e48e37fc | 1542 | TPL_NOTIFY,\r |
dc361cc5 | 1543 | PxeBcCommonNotify,\r |
1544 | &IsDone,\r | |
1545 | &Token.Event\r | |
1546 | );\r | |
1547 | if (EFI_ERROR (Status)) {\r | |
1548 | return EFI_OUT_OF_RESOURCES;\r | |
1549 | }\r | |
1550 | \r | |
8792362f | 1551 | TRY_AGAIN:\r |
1552 | \r | |
dc361cc5 | 1553 | IsDone = FALSE;\r |
1554 | Status = Udp4->Receive (Udp4, &Token);\r | |
1555 | if (EFI_ERROR (Status)) {\r | |
982a9eae | 1556 | if (Status == EFI_ICMP_ERROR) {\r |
1557 | Mode->IcmpErrorReceived = TRUE;\r | |
1558 | }\r | |
dc361cc5 | 1559 | goto ON_EXIT;\r |
1560 | }\r | |
1561 | \r | |
1562 | Udp4->Poll (Udp4);\r | |
1563 | \r | |
1564 | if (!IsDone) {\r | |
1565 | Status = EFI_TIMEOUT;\r | |
1566 | } else {\r | |
1567 | \r | |
1568 | //\r | |
1569 | // check whether this packet matches the filters\r | |
1570 | //\r | |
1571 | if (EFI_ERROR (Token.Status)){\r | |
1572 | goto ON_EXIT;\r | |
1573 | }\r | |
1574 | \r | |
1575 | RxData = Token.Packet.RxData;\r | |
1576 | Session = &RxData->UdpSession;\r | |
1577 | \r | |
319075ff | 1578 | Matched = TRUE;\r |
dc361cc5 | 1579 | \r |
f737cfb9 | 1580 | if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_USE_FILTER) != 0) {\r |
319075ff | 1581 | Matched = FALSE;\r |
8d285ec0 | 1582 | //\r |
1583 | // Check UDP package by IP filter settings\r | |
1584 | //\r | |
1585 | if (CheckIpByFilter (Mode, Session)) {\r | |
1586 | Matched = TRUE;\r | |
dc361cc5 | 1587 | }\r |
8d285ec0 | 1588 | }\r |
1589 | \r | |
1590 | if (Matched) {\r | |
8792362f | 1591 | Matched = FALSE;\r |
1592 | \r | |
8d285ec0 | 1593 | //\r |
1594 | // Match the destination ip of the received udp dgram\r | |
1595 | //\r | |
f737cfb9 | 1596 | if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_IP) != 0) {\r |
8d285ec0 | 1597 | Matched = TRUE;\r |
1598 | \r | |
1599 | if (DestIp != NULL) {\r | |
1600 | CopyMem (DestIp, &Session->DestinationAddress, sizeof (EFI_IPv4_ADDRESS));\r | |
dc361cc5 | 1601 | }\r |
1602 | } else {\r | |
8d285ec0 | 1603 | if (DestIp != NULL) {\r |
1604 | if (EFI_IP4_EQUAL (DestIp, &Session->DestinationAddress)) {\r | |
1605 | Matched = TRUE;\r | |
1606 | }\r | |
1607 | } else {\r | |
1608 | if (EFI_IP4_EQUAL (&Private->StationIp, &Session->DestinationAddress)) {\r | |
1609 | Matched = TRUE;\r | |
1610 | }\r | |
dc361cc5 | 1611 | }\r |
1612 | }\r | |
1613 | }\r | |
1614 | \r | |
1615 | if (Matched) {\r | |
1616 | //\r | |
1617 | // Match the destination port of the received udp dgram\r | |
1618 | //\r | |
f737cfb9 | 1619 | if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_DEST_PORT) != 0) {\r |
dc361cc5 | 1620 | \r |
1621 | if (DestPort != NULL) {\r | |
1622 | *DestPort = Session->DestinationPort;\r | |
1623 | }\r | |
1624 | } else {\r | |
1625 | \r | |
1626 | if (*DestPort != Session->DestinationPort) {\r | |
1627 | Matched = FALSE;\r | |
1628 | }\r | |
1629 | }\r | |
1630 | }\r | |
1631 | \r | |
1632 | if (Matched) {\r | |
1633 | //\r | |
1634 | // Match the source ip of the received udp dgram\r | |
1635 | //\r | |
f737cfb9 | 1636 | if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_IP) != 0) {\r |
dc361cc5 | 1637 | \r |
1638 | if (SrcIp != NULL) {\r | |
e48e37fc | 1639 | CopyMem (SrcIp, &Session->SourceAddress, sizeof (EFI_IPv4_ADDRESS));\r |
dc361cc5 | 1640 | }\r |
1641 | } else {\r | |
1642 | \r | |
1643 | if (!EFI_IP4_EQUAL (SrcIp, &Session->SourceAddress)) {\r | |
1644 | Matched = FALSE;\r | |
1645 | }\r | |
1646 | }\r | |
1647 | }\r | |
1648 | \r | |
1649 | if (Matched) {\r | |
1650 | //\r | |
1651 | // Match the source port of the received udp dgram\r | |
1652 | //\r | |
f737cfb9 | 1653 | if ((OpFlags & EFI_PXE_BASE_CODE_UDP_OPFLAGS_ANY_SRC_PORT) != 0) {\r |
dc361cc5 | 1654 | \r |
1655 | if (SrcPort != NULL) {\r | |
1656 | *SrcPort = Session->SourcePort;\r | |
1657 | }\r | |
1658 | } else {\r | |
1659 | \r | |
1660 | if (*SrcPort != Session->SourcePort) {\r | |
1661 | Matched = FALSE;\r | |
1662 | }\r | |
1663 | }\r | |
1664 | }\r | |
1665 | \r | |
1666 | if (Matched) {\r | |
1667 | \r | |
1668 | CopyLen = 0;\r | |
1669 | \r | |
1670 | if (HeaderSize != NULL) {\r | |
1671 | CopyLen = MIN (*HeaderSize, RxData->DataLength);\r | |
e48e37fc | 1672 | CopyMem (HeaderPtr, RxData->FragmentTable[0].FragmentBuffer, CopyLen);\r |
dc361cc5 | 1673 | *HeaderSize = CopyLen;\r |
1674 | }\r | |
1675 | \r | |
1676 | if (RxData->DataLength - CopyLen > *BufferSize) {\r | |
1677 | \r | |
1678 | Status = EFI_BUFFER_TOO_SMALL;\r | |
1679 | } else {\r | |
1680 | \r | |
1681 | *BufferSize = RxData->DataLength - CopyLen;\r | |
f737cfb9 | 1682 | CopyMem (\r |
1683 | BufferPtr, \r | |
1684 | (UINT8 *) RxData->FragmentTable[0].FragmentBuffer + CopyLen, \r | |
1685 | *BufferSize\r | |
1686 | );\r | |
dc361cc5 | 1687 | }\r |
1688 | } else {\r | |
1689 | \r | |
1690 | Status = EFI_TIMEOUT;\r | |
1691 | }\r | |
1692 | \r | |
1693 | //\r | |
1694 | // Recycle the RxData\r | |
1695 | //\r | |
1696 | gBS->SignalEvent (RxData->RecycleSignal);\r | |
8792362f | 1697 | \r |
1698 | if (!Matched) {\r | |
1699 | goto TRY_AGAIN;\r | |
1700 | }\r | |
dc361cc5 | 1701 | }\r |
1702 | \r | |
1703 | ON_EXIT:\r | |
1704 | \r | |
1705 | Udp4->Cancel (Udp4, &Token);\r | |
1706 | \r | |
1707 | gBS->CloseEvent (Token.Event);\r | |
1708 | \r | |
1709 | return Status;\r | |
1710 | }\r | |
1711 | \r | |
f737cfb9 | 1712 | /** \r |
1713 | Updates the IP receive filters of a network device and enables software filtering.\r | |
1714 | \r | |
1715 | The NewFilter field is used to modify the network device's current IP receive\r | |
1716 | filter settings and to enable a software filter. This function updates the IpFilter\r | |
1717 | field of the EFI_PXE_BASE_CODE_MODE structure with the contents of NewIpFilter.\r | |
1718 | The software filter is used when the USE_FILTER in OpFlags is set to UdpRead().\r | |
1719 | The current hardware filter remains in effect no matter what the settings of OpFlags\r | |
1720 | are, so that the meaning of ANY_DEST_IP set in OpFlags to UdpRead() is from those\r | |
1721 | packets whose reception is enabled in hardware-physical NIC address (unicast),\r | |
1722 | broadcast address, logical address or addresses (multicast), or all (promiscuous).\r | |
1723 | UdpRead() does not modify the IP filter settings.\r | |
1724 | Dhcp(), Discover(), and Mtftp() set the IP filter, and return with the IP receive\r | |
1725 | filter list emptied and the filter set to EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP.\r | |
1726 | If an application or driver wishes to preserve the IP receive filter settings,\r | |
1727 | it will have to preserve the IP receive filter settings before these calls, and\r | |
1728 | use SetIpFilter() to restore them after the calls. If incompatible filtering is\r | |
1729 | requested (for example, PROMISCUOUS with anything else) or if the device does not\r | |
1730 | support a requested filter setting and it cannot be accommodated in software\r | |
1731 | (for example, PROMISCUOUS not supported), EFI_INVALID_PARAMETER will be returned.\r | |
1732 | The IPlist field is used to enable IPs other than the StationIP. They may be\r | |
1733 | multicast or unicast. If IPcnt is set as well as EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP,\r | |
1734 | then both the StationIP and the IPs from the IPlist will be used.\r | |
1735 | \r | |
1736 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
1737 | @param NewFilter Pointer to the new set of IP receive filters.\r | |
1738 | \r | |
1739 | @retval EFI_SUCCESS The IP receive filter settings were updated.\r | |
1740 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
1741 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. \r | |
1742 | \r | |
dc361cc5 | 1743 | **/\r |
1744 | EFI_STATUS\r | |
1745 | EFIAPI\r | |
1746 | EfiPxeBcSetIpFilter (\r | |
1747 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
1748 | IN EFI_PXE_BASE_CODE_IP_FILTER *NewFilter\r | |
1749 | )\r | |
1750 | {\r | |
8d285ec0 | 1751 | EFI_STATUS Status;\r |
1752 | PXEBC_PRIVATE_DATA *Private;\r | |
1753 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
1754 | UINTN Index;\r | |
1755 | BOOLEAN PromiscuousNeed;\r | |
1756 | \r | |
1757 | if (This == NULL) {\r | |
1758 | DEBUG ((EFI_D_ERROR, "BC *This pointer == NULL.\n"));\r | |
1759 | return EFI_INVALID_PARAMETER;\r | |
1760 | }\r | |
1761 | \r | |
1762 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
1763 | Mode = Private->PxeBc.Mode;\r | |
1764 | \r | |
1765 | if (Private == NULL) {\r | |
1766 | DEBUG ((EFI_D_ERROR, "PXEBC_PRIVATE_DATA poiner == NULL.\n"));\r | |
1767 | return EFI_INVALID_PARAMETER;\r | |
1768 | }\r | |
1769 | \r | |
1770 | if (NewFilter == NULL) {\r | |
1771 | DEBUG ((EFI_D_ERROR, "IP Filter *NewFilter == NULL.\n"));\r | |
1772 | return EFI_INVALID_PARAMETER;\r | |
1773 | }\r | |
1774 | \r | |
1775 | if (!Mode->Started) {\r | |
1776 | DEBUG ((EFI_D_ERROR, "BC was not started.\n"));\r | |
1777 | return EFI_NOT_STARTED;\r | |
1778 | }\r | |
1779 | \r | |
1780 | PromiscuousNeed = FALSE;\r | |
1781 | for (Index = 0; Index < NewFilter->IpCnt; ++Index) {\r | |
1782 | if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (NewFilter->IpList[Index].v4))) {\r | |
1783 | //\r | |
1784 | // The IP is a broadcast address.\r | |
1785 | //\r | |
1786 | DEBUG ((EFI_D_ERROR, "There is broadcast address in NewFilter.\n"));\r | |
1787 | return EFI_INVALID_PARAMETER;\r | |
1788 | }\r | |
1789 | if (Ip4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), 0) &&\r | |
1790 | (NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP)\r | |
1791 | ) {\r | |
1792 | //\r | |
1793 | // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList,\r | |
1794 | // promiscuous mode is needed.\r | |
1795 | //\r | |
1796 | PromiscuousNeed = TRUE;\r | |
1797 | }\r | |
1798 | }\r | |
1799 | \r | |
1800 | //\r | |
1801 | // Clear the UDP instance configuration, all joined groups will be left\r | |
1802 | // during the operation.\r | |
1803 | //\r | |
8792362f | 1804 | Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r |
8d285ec0 | 1805 | Private->Udp4CfgData.AcceptPromiscuous = FALSE;\r |
1806 | Private->Udp4CfgData.AcceptBroadcast = FALSE;\r | |
1807 | \r | |
1808 | if (PromiscuousNeed ||\r | |
1809 | NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS ||\r | |
1810 | NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST\r | |
1811 | ) {\r | |
1812 | //\r | |
1813 | // Configure the udp4 filter to receive all packages\r | |
1814 | //\r | |
1815 | Private->Udp4CfgData.AcceptPromiscuous = TRUE;\r | |
1816 | \r | |
1817 | //\r | |
1818 | // Configure the UDP instance with the new configuration.\r | |
1819 | //\r | |
8792362f | 1820 | Status = Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r |
8d285ec0 | 1821 | if (EFI_ERROR (Status)) {\r |
1822 | return Status;\r | |
1823 | }\r | |
1824 | \r | |
1825 | } else {\r | |
1826 | \r | |
1827 | if (NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST) {\r | |
1828 | //\r | |
1829 | // Configure the udp4 filter to receive all broadcast packages\r | |
1830 | //\r | |
1831 | Private->Udp4CfgData.AcceptBroadcast = TRUE;\r | |
1832 | }\r | |
1833 | \r | |
1834 | //\r | |
1835 | // Configure the UDP instance with the new configuration.\r | |
1836 | //\r | |
8792362f | 1837 | Status = Private->Udp4Read->Configure (Private->Udp4Read, &Private->Udp4CfgData);\r |
8d285ec0 | 1838 | if (EFI_ERROR (Status)) {\r |
1839 | return Status;\r | |
1840 | }\r | |
1841 | \r | |
1842 | if (NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) {\r | |
1843 | \r | |
1844 | for (Index = 0; Index < NewFilter->IpCnt; ++Index) {\r | |
1845 | if (IP4_IS_MULTICAST (EFI_NTOHL (NewFilter->IpList[Index].v4))) {\r | |
1846 | //\r | |
1847 | // Join the mutilcast group\r | |
1848 | //\r | |
8792362f | 1849 | Status = Private->Udp4Read->Groups (Private->Udp4Read, TRUE, &NewFilter->IpList[Index].v4);\r |
8d285ec0 | 1850 | if (EFI_ERROR (Status)) {\r |
1851 | return Status;\r | |
1852 | }\r | |
1853 | }\r | |
1854 | }\r | |
1855 | }\r | |
1856 | }\r | |
1857 | \r | |
1858 | \r | |
1859 | //\r | |
1860 | // Save the new filter.\r | |
1861 | //\r | |
1862 | CopyMem (&Mode->IpFilter, NewFilter, sizeof (Mode->IpFilter));\r | |
1863 | \r | |
1864 | return EFI_SUCCESS;\r | |
dc361cc5 | 1865 | }\r |
1866 | \r | |
1867 | \r | |
f737cfb9 | 1868 | /** \r |
1869 | Uses the ARP protocol to resolve a MAC address.\r | |
1870 | \r | |
1871 | This function uses the ARP protocol to resolve a MAC address. The UsingIpv6 field\r | |
1872 | of the EFI_PXE_BASE_CODE_MODE structure is used to determine if IPv4 or IPv6\r | |
1873 | addresses are being used. The IP address specified by IpAddr is used to resolve\r | |
1874 | a MAC address. If the ARP protocol succeeds in resolving the specified address,\r | |
1875 | then the ArpCacheEntries and ArpCache fields of the EFI_PXE_BASE_CODE_MODE structure\r | |
1876 | are updated, and EFI_SUCCESS is returned. If MacAddr is not NULL, the resolved\r | |
1877 | MAC address is placed there as well. If the PXE Base Code protocol is in the \r | |
1878 | stopped state, then EFI_NOT_STARTED is returned. If the ARP protocol encounters \r | |
1879 | a timeout condition while attempting to resolve an address, then EFI_TIMEOUT is \r | |
1880 | returned. If the Callback Protocol does not return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE, \r | |
1881 | then EFI_ABORTED is returned.\r | |
1882 | \r | |
1883 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
1884 | @param IpAddr Pointer to the IP address that is used to resolve a MAC address.\r | |
1885 | @param MacAddr If not NULL, a pointer to the MAC address that was resolved with the\r | |
1886 | ARP protocol. \r | |
1887 | \r | |
1888 | @retval EFI_SUCCESS The IP or MAC address was resolved.\r | |
1889 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
1890 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. \r | |
1891 | @retval EFI_DEVICE_ERROR The network device encountered an error during this operation. \r | |
1892 | @retval EFI_ICMP_ERROR Something error occur with the ICMP packet message. \r | |
1893 | \r | |
dc361cc5 | 1894 | **/\r |
1895 | EFI_STATUS\r | |
1896 | EFIAPI\r | |
1897 | EfiPxeBcArp (\r | |
1898 | IN EFI_PXE_BASE_CODE_PROTOCOL * This,\r | |
1899 | IN EFI_IP_ADDRESS * IpAddr,\r | |
1900 | IN EFI_MAC_ADDRESS * MacAddr OPTIONAL\r | |
1901 | )\r | |
1902 | {\r | |
8d285ec0 | 1903 | PXEBC_PRIVATE_DATA *Private;\r |
1904 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
1905 | EFI_STATUS Status;\r | |
1906 | EFI_MAC_ADDRESS TempMacAddr;\r | |
1907 | \r | |
1908 | if (This == NULL || IpAddr == NULL) {\r | |
1909 | return EFI_INVALID_PARAMETER;\r | |
1910 | }\r | |
1911 | \r | |
1912 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
1913 | Mode = Private->PxeBc.Mode;\r | |
1914 | \r | |
1915 | if (!Mode->Started) {\r | |
1916 | return EFI_NOT_STARTED;\r | |
1917 | }\r | |
1918 | \r | |
1919 | if (!Private->AddressIsOk || Mode->UsingIpv6) {\r | |
1920 | //\r | |
1921 | // We can't resolve the IP address if we don't have a local address now.\r | |
1922 | // Don't have ARP for IPv6.\r | |
1923 | //\r | |
1924 | return EFI_INVALID_PARAMETER;\r | |
1925 | }\r | |
1926 | \r | |
982a9eae | 1927 | Mode->IcmpErrorReceived = FALSE;\r |
1928 | \r | |
1929 | if (!Mode->AutoArp) {\r | |
1930 | //\r | |
1931 | // If AutoArp is set false, check arp cache\r | |
1932 | //\r | |
1933 | UpdateArpCache (This);\r | |
1934 | if (!FindInArpCache (Mode, &IpAddr->v4, &TempMacAddr)) {\r | |
1935 | return EFI_DEVICE_ERROR;\r | |
1936 | }\r | |
1937 | } else {\r | |
1938 | Status = Private->Arp->Request (Private->Arp, &IpAddr->v4, NULL, &TempMacAddr);\r | |
1939 | if (EFI_ERROR (Status)) {\r | |
1940 | if (Status == EFI_ICMP_ERROR) {\r | |
1941 | Mode->IcmpErrorReceived = TRUE;\r | |
1942 | }\r | |
1943 | return Status;\r | |
1944 | }\r | |
8d285ec0 | 1945 | }\r |
1946 | \r | |
1947 | if (MacAddr != NULL) {\r | |
1948 | CopyMem (MacAddr, &TempMacAddr, sizeof (EFI_MAC_ADDRESS));\r | |
1949 | }\r | |
1950 | \r | |
1951 | return EFI_SUCCESS;\r | |
dc361cc5 | 1952 | }\r |
1953 | \r | |
f737cfb9 | 1954 | /** \r |
1955 | Updates the parameters that affect the operation of the PXE Base Code Protocol.\r | |
1956 | \r | |
1957 | This function sets parameters that affect the operation of the PXE Base Code Protocol.\r | |
1958 | The parameter specified by NewAutoArp is used to control the generation of ARP\r | |
1959 | protocol packets. If NewAutoArp is TRUE, then ARP Protocol packets will be generated\r | |
1960 | as required by the PXE Base Code Protocol. If NewAutoArp is FALSE, then no ARP\r | |
1961 | Protocol packets will be generated. In this case, the only mappings that are\r | |
1962 | available are those stored in the ArpCache of the EFI_PXE_BASE_CODE_MODE structure.\r | |
1963 | If there are not enough mappings in the ArpCache to perform a PXE Base Code Protocol\r | |
1964 | service, then the service will fail. This function updates the AutoArp field of\r | |
1965 | the EFI_PXE_BASE_CODE_MODE structure to NewAutoArp.\r | |
1966 | The SetParameters() call must be invoked after a Callback Protocol is installed\r | |
1967 | to enable the use of callbacks.\r | |
1968 | \r | |
1969 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
1970 | @param NewAutoArp If not NULL, a pointer to a value that specifies whether to replace the\r | |
1971 | current value of AutoARP. \r | |
1972 | @param NewSendGUID If not NULL, a pointer to a value that specifies whether to replace the\r | |
1973 | current value of SendGUID. \r | |
1974 | @param NewTTL If not NULL, a pointer to be used in place of the current value of TTL,\r | |
1975 | the "time to live" field of the IP header. \r | |
1976 | @param NewToS If not NULL, a pointer to be used in place of the current value of ToS,\r | |
1977 | the "type of service" field of the IP header. \r | |
1978 | @param NewMakeCallback If not NULL, a pointer to a value that specifies whether to replace the\r | |
1979 | current value of the MakeCallback field of the Mode structure. \r | |
1980 | \r | |
1981 | @retval EFI_SUCCESS The new parameters values were updated.\r | |
1982 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
1983 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. \r | |
1984 | \r | |
dc361cc5 | 1985 | **/\r |
1986 | EFI_STATUS\r | |
1987 | EFIAPI\r | |
1988 | EfiPxeBcSetParameters (\r | |
1989 | IN EFI_PXE_BASE_CODE_PROTOCOL *This,\r | |
f737cfb9 | 1990 | IN BOOLEAN *NewAutoArp OPTIONAL,\r |
1991 | IN BOOLEAN *NewSendGUID OPTIONAL,\r | |
1992 | IN UINT8 *NewTTL OPTIONAL,\r | |
1993 | IN UINT8 *NewToS OPTIONAL,\r | |
dc361cc5 | 1994 | IN BOOLEAN *NewMakeCallback // OPTIONAL\r |
1995 | )\r | |
1996 | {\r | |
1997 | PXEBC_PRIVATE_DATA *Private;\r | |
1998 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
1999 | EFI_STATUS Status;\r | |
2000 | \r | |
2001 | Status = EFI_SUCCESS;\r | |
2002 | \r | |
2003 | if (This == NULL) {\r | |
2004 | Status = EFI_INVALID_PARAMETER;\r | |
2005 | goto ON_EXIT;\r | |
2006 | }\r | |
2007 | \r | |
2008 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
2009 | Mode = Private->PxeBc.Mode;\r | |
2010 | \r | |
f737cfb9 | 2011 | if (NewSendGUID != NULL && *NewSendGUID) {\r |
dc361cc5 | 2012 | //\r |
2013 | // FixMe, cann't locate SendGuid\r | |
2014 | //\r | |
2015 | }\r | |
2016 | \r | |
f737cfb9 | 2017 | if (NewMakeCallback != NULL && *NewMakeCallback) {\r |
dc361cc5 | 2018 | \r |
2019 | Status = gBS->HandleProtocol (\r | |
2020 | Private->Controller,\r | |
2021 | &gEfiPxeBaseCodeCallbackProtocolGuid,\r | |
2022 | (VOID **) &Private->PxeBcCallback\r | |
2023 | );\r | |
2024 | if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback == NULL)) {\r | |
2025 | \r | |
2026 | Status = EFI_INVALID_PARAMETER;\r | |
2027 | goto ON_EXIT;\r | |
2028 | }\r | |
2029 | }\r | |
2030 | \r | |
2031 | if (!Mode->Started) {\r | |
2032 | Status = EFI_NOT_STARTED;\r | |
2033 | goto ON_EXIT;\r | |
2034 | }\r | |
2035 | \r | |
2036 | if (NewMakeCallback != NULL) {\r | |
2037 | \r | |
2038 | if (*NewMakeCallback) {\r | |
2039 | //\r | |
2040 | // Update the Callback protocol.\r | |
2041 | //\r | |
2042 | Status = gBS->HandleProtocol (\r | |
2043 | Private->Controller,\r | |
2044 | &gEfiPxeBaseCodeCallbackProtocolGuid,\r | |
2045 | (VOID **) &Private->PxeBcCallback\r | |
2046 | );\r | |
2047 | \r | |
2048 | if (EFI_ERROR (Status) || (Private->PxeBcCallback->Callback == NULL)) {\r | |
2049 | Status = EFI_INVALID_PARAMETER;\r | |
2050 | goto ON_EXIT;\r | |
2051 | }\r | |
2052 | } else {\r | |
2053 | Private->PxeBcCallback = NULL;\r | |
2054 | }\r | |
2055 | \r | |
2056 | Mode->MakeCallbacks = *NewMakeCallback;\r | |
2057 | }\r | |
2058 | \r | |
2059 | if (NewAutoArp != NULL) {\r | |
2060 | Mode->AutoArp = *NewAutoArp;\r | |
2061 | }\r | |
2062 | \r | |
2063 | if (NewSendGUID != NULL) {\r | |
2064 | Mode->SendGUID = *NewSendGUID;\r | |
2065 | }\r | |
2066 | \r | |
2067 | if (NewTTL != NULL) {\r | |
2068 | Mode->TTL = *NewTTL;\r | |
2069 | }\r | |
2070 | \r | |
2071 | if (NewToS != NULL) {\r | |
2072 | Mode->ToS = *NewToS;\r | |
2073 | }\r | |
2074 | \r | |
2075 | ON_EXIT:\r | |
2076 | return Status;\r | |
2077 | }\r | |
2078 | \r | |
f737cfb9 | 2079 | /** \r |
2080 | Updates the station IP address and/or subnet mask values of a network device.\r | |
2081 | \r | |
2082 | This function updates the station IP address and/or subnet mask values of a network\r | |
2083 | device. The NewStationIp field is used to modify the network device's current IP address.\r | |
2084 | If NewStationIP is NULL, then the current IP address will not be modified. Otherwise,\r | |
2085 | this function updates the StationIp field of the EFI_PXE_BASE_CODE_MODE structure\r | |
2086 | with NewStationIp. The NewSubnetMask field is used to modify the network device's current subnet\r | |
2087 | mask. If NewSubnetMask is NULL, then the current subnet mask will not be modified.\r | |
2088 | Otherwise, this function updates the SubnetMask field of the EFI_PXE_BASE_CODE_MODE\r | |
2089 | structure with NewSubnetMask.\r | |
2090 | \r | |
2091 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
2092 | @param NewStationIp Pointer to the new IP address to be used by the network device. \r | |
2093 | @param NewSubnetMask Pointer to the new subnet mask to be used by the network device. \r | |
2094 | \r | |
2095 | @retval EFI_SUCCESS The new station IP address and/or subnet mask were updated.\r | |
2096 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
2097 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid. \r | |
2098 | \r | |
dc361cc5 | 2099 | **/\r |
2100 | EFI_STATUS\r | |
2101 | EFIAPI\r | |
2102 | EfiPxeBcSetStationIP (\r | |
2103 | IN EFI_PXE_BASE_CODE_PROTOCOL * This,\r | |
f737cfb9 | 2104 | IN EFI_IP_ADDRESS * NewStationIp OPTIONAL,\r |
dc361cc5 | 2105 | IN EFI_IP_ADDRESS * NewSubnetMask OPTIONAL\r |
2106 | )\r | |
2107 | {\r | |
2108 | PXEBC_PRIVATE_DATA *Private;\r | |
2109 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
8d285ec0 | 2110 | EFI_ARP_CONFIG_DATA ArpConfigData;\r |
dc361cc5 | 2111 | \r |
2112 | if (This == NULL) {\r | |
2113 | return EFI_INVALID_PARAMETER;\r | |
2114 | }\r | |
2115 | \r | |
2116 | if (NewStationIp != NULL && !Ip4IsUnicast (NTOHL (NewStationIp->Addr[0]), 0)) {\r | |
2117 | return EFI_INVALID_PARAMETER;\r | |
2118 | }\r | |
2119 | \r | |
2120 | if (NewSubnetMask != NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) {\r | |
2121 | return EFI_INVALID_PARAMETER;\r | |
2122 | }\r | |
2123 | \r | |
2124 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
2125 | Mode = Private->PxeBc.Mode;\r | |
2126 | \r | |
2127 | if (!Mode->Started) {\r | |
2128 | return EFI_NOT_STARTED;\r | |
2129 | }\r | |
2130 | \r | |
2131 | if (NewStationIp != NULL) {\r | |
555e76f8 | 2132 | CopyMem (&Mode->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));\r |
2133 | CopyMem (&Private->StationIp, NewStationIp, sizeof (EFI_IP_ADDRESS));\r | |
dc361cc5 | 2134 | }\r |
2135 | \r | |
2136 | if (NewSubnetMask != NULL) {\r | |
555e76f8 | 2137 | CopyMem (&Mode->SubnetMask, NewSubnetMask, sizeof (EFI_IP_ADDRESS));\r |
2138 | CopyMem (&Private->SubnetMask ,NewSubnetMask, sizeof (EFI_IP_ADDRESS));\r | |
dc361cc5 | 2139 | }\r |
2140 | \r | |
2141 | Private->AddressIsOk = TRUE;\r | |
2142 | \r | |
8d285ec0 | 2143 | if (!Mode->UsingIpv6) {\r |
2144 | //\r | |
2145 | // If in IPv4 mode, configure the corresponding ARP with this new\r | |
2146 | // station IP address.\r | |
2147 | //\r | |
2148 | ZeroMem (&ArpConfigData, sizeof (EFI_ARP_CONFIG_DATA));\r | |
2149 | \r | |
2150 | ArpConfigData.SwAddressType = 0x0800;\r | |
2151 | ArpConfigData.SwAddressLength = sizeof (EFI_IPv4_ADDRESS);\r | |
2152 | ArpConfigData.StationAddress = &Private->StationIp.v4;\r | |
2153 | \r | |
2154 | Private->Arp->Configure (Private->Arp, NULL);\r | |
2155 | Private->Arp->Configure (Private->Arp, &ArpConfigData);\r | |
982a9eae | 2156 | \r |
2157 | //\r | |
2158 | // Update the route table.\r | |
2159 | //\r | |
2160 | Mode->RouteTableEntries = 1;\r | |
2161 | Mode->RouteTable[0].IpAddr.Addr[0] = Private->StationIp.Addr[0] & Private->SubnetMask.Addr[0];\r | |
2162 | Mode->RouteTable[0].SubnetMask.Addr[0] = Private->SubnetMask.Addr[0];\r | |
2163 | Mode->RouteTable[0].GwAddr.Addr[0] = 0;\r | |
8d285ec0 | 2164 | }\r |
2165 | \r | |
dc361cc5 | 2166 | return EFI_SUCCESS;\r |
2167 | }\r | |
2168 | \r | |
f737cfb9 | 2169 | /** \r |
2170 | Updates the contents of the cached DHCP and Discover packets.\r | |
2171 | \r | |
2172 | The pointers to the new packets are used to update the contents of the cached\r | |
2173 | packets in the EFI_PXE_BASE_CODE_MODE structure.\r | |
2174 | \r | |
2175 | @param This Pointer to the EFI_PXE_BASE_CODE_PROTOCOL instance.\r | |
2176 | @param NewDhcpDiscoverValid Pointer to a value that will replace the current\r | |
2177 | DhcpDiscoverValid field. \r | |
2178 | @param NewDhcpAckReceived Pointer to a value that will replace the current\r | |
2179 | DhcpAckReceived field. \r | |
2180 | @param NewProxyOfferReceived Pointer to a value that will replace the current\r | |
2181 | ProxyOfferReceived field. \r | |
2182 | @param NewPxeDiscoverValid Pointer to a value that will replace the current \r | |
2183 | ProxyOfferReceived field. \r | |
2184 | @param NewPxeReplyReceived Pointer to a value that will replace the current\r | |
2185 | PxeReplyReceived field. \r | |
2186 | @param NewPxeBisReplyReceived Pointer to a value that will replace the current\r | |
2187 | PxeBisReplyReceived field. \r | |
2188 | @param NewDhcpDiscover Pointer to the new cached DHCP Discover packet contents. \r | |
2189 | @param NewDhcpAck Pointer to the new cached DHCP Ack packet contents.\r | |
2190 | @param NewProxyOffer Pointer to the new cached Proxy Offer packet contents.\r | |
2191 | @param NewPxeDiscover Pointer to the new cached PXE Discover packet contents.\r | |
2192 | @param NewPxeReply Pointer to the new cached PXE Reply packet contents.\r | |
2193 | @param NewPxeBisReply Pointer to the new cached PXE BIS Reply packet contents.\r | |
2194 | \r | |
2195 | @retval EFI_SUCCESS The cached packet contents were updated.\r | |
2196 | @retval EFI_NOT_STARTED The PXE Base Code Protocol is in the stopped state.\r | |
2197 | @retval EFI_INVALID_PARAMETER This is NULL or not point to a valid EFI_PXE_BASE_CODE_PROTOCOL structure.\r | |
2198 | \r | |
dc361cc5 | 2199 | **/\r |
2200 | EFI_STATUS\r | |
2201 | EFIAPI\r | |
2202 | EfiPxeBcSetPackets (\r | |
2203 | IN EFI_PXE_BASE_CODE_PROTOCOL * This,\r | |
f737cfb9 | 2204 | IN BOOLEAN * NewDhcpDiscoverValid OPTIONAL,\r |
2205 | IN BOOLEAN * NewDhcpAckReceived OPTIONAL,\r | |
2206 | IN BOOLEAN * NewProxyOfferReceived OPTIONAL,\r | |
2207 | IN BOOLEAN * NewPxeDiscoverValid OPTIONAL,\r | |
2208 | IN BOOLEAN * NewPxeReplyReceived OPTIONAL,\r | |
2209 | IN BOOLEAN * NewPxeBisReplyReceived OPTIONAL,\r | |
2210 | IN EFI_PXE_BASE_CODE_PACKET * NewDhcpDiscover OPTIONAL,\r | |
2211 | IN EFI_PXE_BASE_CODE_PACKET * NewDhcpAck OPTIONAL,\r | |
2212 | IN EFI_PXE_BASE_CODE_PACKET * NewProxyOffer OPTIONAL,\r | |
2213 | IN EFI_PXE_BASE_CODE_PACKET * NewPxeDiscover OPTIONAL,\r | |
2214 | IN EFI_PXE_BASE_CODE_PACKET * NewPxeReply OPTIONAL,\r | |
dc361cc5 | 2215 | IN EFI_PXE_BASE_CODE_PACKET * NewPxeBisReply OPTIONAL\r |
2216 | )\r | |
2217 | {\r | |
2218 | PXEBC_PRIVATE_DATA *Private;\r | |
2219 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
2220 | \r | |
2221 | if (This == NULL) {\r | |
2222 | return EFI_INVALID_PARAMETER;\r | |
2223 | }\r | |
2224 | \r | |
2225 | Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);\r | |
2226 | Mode = Private->PxeBc.Mode;\r | |
2227 | \r | |
2228 | if (!Mode->Started) {\r | |
2229 | return EFI_NOT_STARTED;\r | |
2230 | }\r | |
2231 | \r | |
2232 | Private->FileSize = 0;\r | |
2233 | \r | |
2234 | if (NewDhcpDiscoverValid != NULL) {\r | |
2235 | Mode->DhcpDiscoverValid = *NewDhcpDiscoverValid;\r | |
2236 | }\r | |
2237 | \r | |
2238 | if (NewDhcpAckReceived != NULL) {\r | |
2239 | Mode->DhcpAckReceived = *NewDhcpAckReceived;\r | |
2240 | }\r | |
2241 | \r | |
2242 | if (NewProxyOfferReceived != NULL) {\r | |
2243 | Mode->ProxyOfferReceived = *NewProxyOfferReceived;\r | |
2244 | }\r | |
2245 | \r | |
2246 | if (NewPxeDiscoverValid != NULL) {\r | |
2247 | Mode->PxeDiscoverValid = *NewPxeDiscoverValid;\r | |
2248 | }\r | |
2249 | \r | |
2250 | if (NewPxeReplyReceived != NULL) {\r | |
2251 | Mode->PxeReplyReceived = *NewPxeReplyReceived;\r | |
2252 | }\r | |
2253 | \r | |
2254 | if (NewPxeBisReplyReceived != NULL) {\r | |
2255 | Mode->PxeBisReplyReceived = *NewPxeBisReplyReceived;\r | |
2256 | }\r | |
2257 | \r | |
2258 | if (NewDhcpDiscover != NULL) {\r | |
e48e37fc | 2259 | CopyMem (&Mode->DhcpDiscover, NewDhcpDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2260 | }\r |
2261 | \r | |
2262 | if (NewDhcpAck != NULL) {\r | |
e48e37fc | 2263 | CopyMem (&Mode->DhcpAck, NewDhcpAck, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2264 | }\r |
2265 | \r | |
2266 | if (NewProxyOffer != NULL) {\r | |
e48e37fc | 2267 | CopyMem (&Mode->ProxyOffer, NewProxyOffer, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2268 | }\r |
2269 | \r | |
2270 | if (NewPxeDiscover != NULL) {\r | |
e48e37fc | 2271 | CopyMem (&Mode->PxeDiscover, NewPxeDiscover, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2272 | }\r |
2273 | \r | |
2274 | if (NewPxeReply != NULL) {\r | |
e48e37fc | 2275 | CopyMem (&Mode->PxeReply, NewPxeReply, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2276 | }\r |
2277 | \r | |
2278 | if (NewPxeBisReply != NULL) {\r | |
e48e37fc | 2279 | CopyMem (&Mode->PxeBisReply, NewPxeBisReply, sizeof (EFI_PXE_BASE_CODE_PACKET));\r |
dc361cc5 | 2280 | }\r |
2281 | \r | |
2282 | return EFI_SUCCESS;\r | |
2283 | }\r | |
2284 | \r | |
2285 | EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate = {\r | |
2286 | EFI_PXE_BASE_CODE_PROTOCOL_REVISION,\r | |
2287 | EfiPxeBcStart,\r | |
2288 | EfiPxeBcStop,\r | |
2289 | EfiPxeBcDhcp,\r | |
2290 | EfiPxeBcDiscover,\r | |
2291 | EfiPxeBcMtftp,\r | |
2292 | EfiPxeBcUdpWrite,\r | |
2293 | EfiPxeBcUdpRead,\r | |
2294 | EfiPxeBcSetIpFilter,\r | |
2295 | EfiPxeBcArp,\r | |
2296 | EfiPxeBcSetParameters,\r | |
2297 | EfiPxeBcSetStationIP,\r | |
2298 | EfiPxeBcSetPackets,\r | |
2299 | NULL\r | |
2300 | };\r | |
2301 | \r | |
f737cfb9 | 2302 | /** \r |
2303 | Callback function that is invoked when the PXE Base Code Protocol is about to transmit, has\r | |
2304 | received, or is waiting to receive a packet. \r | |
2305 | \r | |
2306 | This function is invoked when the PXE Base Code Protocol is about to transmit, has received,\r | |
2307 | or is waiting to receive a packet. Parameters Function and Received specify the type of event.\r | |
2308 | Parameters PacketLen and Packet specify the packet that generated the event. If these fields\r | |
2309 | are zero and NULL respectively, then this is a status update callback. If the operation specified\r | |
2310 | by Function is to continue, then CALLBACK_STATUS_CONTINUE should be returned. If the operation\r | |
2311 | specified by Function should be aborted, then CALLBACK_STATUS_ABORT should be returned. Due to\r | |
2312 | the polling nature of UEFI device drivers, a callback function should not execute for more than 5 ms.\r | |
2313 | The SetParameters() function must be called after a Callback Protocol is installed to enable the\r | |
2314 | use of callbacks.\r | |
2315 | \r | |
2316 | @param This Pointer to the EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL instance.\r | |
2317 | @param Function The PXE Base Code Protocol function that is waiting for an event. \r | |
2318 | @param Received TRUE if the callback is being invoked due to a receive event. FALSE if\r | |
2319 | the callback is being invoked due to a transmit event. \r | |
2320 | @param PacketLength The length, in bytes, of Packet. This field will have a value of zero if\r | |
2321 | this is a wait for receive event. \r | |
2322 | @param PacketPtr If Received is TRUE, a pointer to the packet that was just received;\r | |
2323 | otherwise a pointer to the packet that is about to be transmitted. \r | |
2324 | \r | |
2325 | @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE if Function specifies a continue operation \r | |
2326 | @retval EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT if Function specifies an abort operation\r | |
2327 | \r | |
dc361cc5 | 2328 | **/\r |
2329 | EFI_PXE_BASE_CODE_CALLBACK_STATUS\r | |
2330 | EFIAPI\r | |
2331 | EfiPxeLoadFileCallback (\r | |
2332 | IN EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL * This,\r | |
2333 | IN EFI_PXE_BASE_CODE_FUNCTION Function,\r | |
2334 | IN BOOLEAN Received,\r | |
2335 | IN UINT32 PacketLength,\r | |
2336 | IN EFI_PXE_BASE_CODE_PACKET * PacketPtr OPTIONAL\r | |
2337 | )\r | |
2338 | {\r | |
2339 | EFI_INPUT_KEY Key;\r | |
2340 | EFI_STATUS Status;\r | |
2341 | \r | |
2342 | //\r | |
2343 | // Catch Ctrl-C or ESC to abort.\r | |
2344 | //\r | |
2345 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
2346 | \r | |
2347 | if (!EFI_ERROR (Status)) {\r | |
2348 | \r | |
2349 | if (Key.ScanCode == SCAN_ESC || Key.UnicodeChar == (0x1F & 'c')) {\r | |
2350 | \r | |
2351 | return EFI_PXE_BASE_CODE_CALLBACK_STATUS_ABORT;\r | |
2352 | }\r | |
2353 | }\r | |
2354 | //\r | |
2355 | // No print if receive packet\r | |
2356 | //\r | |
2357 | if (Received) {\r | |
2358 | return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r | |
2359 | }\r | |
2360 | //\r | |
2361 | // Print only for three functions\r | |
2362 | //\r | |
2363 | switch (Function) {\r | |
2364 | \r | |
2365 | case EFI_PXE_BASE_CODE_FUNCTION_MTFTP:\r | |
2366 | //\r | |
2367 | // Print only for open MTFTP packets, not every MTFTP packets\r | |
2368 | //\r | |
2369 | if (PacketLength != 0 && PacketPtr != NULL) {\r | |
2370 | if (PacketPtr->Raw[0x1C] != 0x00 || PacketPtr->Raw[0x1D] != 0x01) {\r | |
2371 | return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r | |
2372 | }\r | |
2373 | }\r | |
2374 | break;\r | |
2375 | \r | |
2376 | case EFI_PXE_BASE_CODE_FUNCTION_DHCP:\r | |
2377 | case EFI_PXE_BASE_CODE_FUNCTION_DISCOVER:\r | |
2378 | break;\r | |
2379 | \r | |
2380 | default:\r | |
2381 | return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r | |
2382 | }\r | |
2383 | \r | |
2384 | if (PacketLength != 0 && PacketPtr != NULL) {\r | |
2385 | //\r | |
2386 | // Print '.' when transmit a packet\r | |
2387 | //\r | |
2388 | AsciiPrint (".");\r | |
2389 | \r | |
2390 | }\r | |
2391 | \r | |
2392 | return EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE;\r | |
2393 | }\r | |
2394 | \r | |
2395 | EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL mPxeBcCallBackTemplate = {\r | |
2396 | EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_REVISION,\r | |
2397 | EfiPxeLoadFileCallback\r | |
2398 | };\r | |
2399 | \r | |
2400 | \r | |
2401 | /**\r | |
f737cfb9 | 2402 | Find the boot file.\r |
dc361cc5 | 2403 | \r |
f737cfb9 | 2404 | @param Private Pointer to PxeBc private data. \r |
2405 | @param BufferSize Pointer to buffer size. \r | |
2406 | @param Buffer Pointer to buffer. \r | |
dc361cc5 | 2407 | \r |
f737cfb9 | 2408 | @retval EFI_SUCCESS Discover the boot file successfully.\r |
2409 | @retval EFI_TIMEOUT The TFTP/MTFTP operation timed out.\r | |
2410 | @retval EFI_ABORTED PXE bootstrap server, so local boot need abort.\r | |
2411 | @retval EFI_BUFFER_TOO_SMALL The buffer is too small to load the boot file.\r | |
2412 | \r | |
dc361cc5 | 2413 | **/\r |
2414 | EFI_STATUS\r | |
2415 | DiscoverBootFile (\r | |
2416 | IN PXEBC_PRIVATE_DATA *Private,\r | |
2417 | IN OUT UINT64 *BufferSize,\r | |
2418 | IN VOID *Buffer\r | |
2419 | )\r | |
2420 | {\r | |
2421 | EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r | |
2422 | EFI_PXE_BASE_CODE_MODE *Mode;\r | |
2423 | EFI_STATUS Status;\r | |
2424 | UINT16 Type;\r | |
2425 | UINT16 Layer;\r | |
2426 | BOOLEAN UseBis;\r | |
2427 | UINTN BlockSize;\r | |
2428 | PXEBC_CACHED_DHCP4_PACKET *Packet;\r | |
2429 | UINT16 Value;\r | |
2430 | \r | |
2431 | PxeBc = &Private->PxeBc;\r | |
2432 | Mode = PxeBc->Mode;\r | |
2433 | Type = EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP;\r | |
2434 | Layer = EFI_PXE_BASE_CODE_BOOT_LAYER_INITIAL;\r | |
2435 | \r | |
2436 | //\r | |
2437 | // do DHCP.\r | |
2438 | //\r | |
2439 | Status = PxeBc->Dhcp (PxeBc, TRUE);\r | |
2440 | if (EFI_ERROR (Status)) {\r | |
2441 | return Status;\r | |
2442 | }\r | |
2443 | \r | |
2444 | //\r | |
2445 | // Select a boot server\r | |
2446 | //\r | |
2447 | Status = PxeBcSelectBootPrompt (Private);\r | |
2448 | \r | |
2449 | if (Status == EFI_SUCCESS) {\r | |
2450 | Status = PxeBcSelectBootMenu (Private, &Type, TRUE);\r | |
2451 | } else if (Status == EFI_TIMEOUT) {\r | |
2452 | Status = PxeBcSelectBootMenu (Private, &Type, FALSE);\r | |
2453 | }\r | |
2454 | \r | |
2455 | if (!EFI_ERROR (Status)) {\r | |
2456 | \r | |
2457 | if (Type == EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP) {\r | |
2458 | //\r | |
2459 | // Local boot(PXE bootstrap server) need abort\r | |
2460 | //\r | |
2461 | return EFI_ABORTED;\r | |
2462 | }\r | |
2463 | \r | |
2464 | UseBis = (BOOLEAN) (Mode->BisSupported && Mode->BisDetected);\r | |
2465 | Status = PxeBc->Discover (PxeBc, Type, &Layer, UseBis, NULL);\r | |
2466 | if (EFI_ERROR (Status)) {\r | |
2467 | return Status;\r | |
2468 | }\r | |
2469 | }\r | |
2470 | \r | |
2471 | *BufferSize = 0;\r | |
2472 | BlockSize = 0x8000;\r | |
2473 | \r | |
2474 | //\r | |
2475 | // Get bootfile name and (m)tftp server ip addresss\r | |
2476 | //\r | |
2477 | if (Mode->PxeReplyReceived) {\r | |
2478 | Packet = &Private->PxeReply;\r | |
2479 | } else if (Mode->ProxyOfferReceived) {\r | |
2480 | Packet = &Private->ProxyOffer;\r | |
2481 | } else {\r | |
2482 | Packet = &Private->Dhcp4Ack;\r | |
2483 | }\r | |
2484 | \r | |
319075ff | 2485 | //\r |
2486 | // use option 54, if zero, use siaddr in header\r | |
2487 | //\r | |
2488 | if (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER_ID] != NULL) {\r | |
e48e37fc | 2489 | CopyMem (\r |
dc361cc5 | 2490 | &Private->ServerIp,\r |
2491 | Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_SERVER_ID]->Data,\r | |
2492 | sizeof (EFI_IPv4_ADDRESS)\r | |
2493 | );\r | |
319075ff | 2494 | } else {\r |
2495 | CopyMem (\r | |
2496 | &Private->ServerIp, \r | |
2497 | &Packet->Packet.Offer.Dhcp4.Header.ServerAddr, \r | |
2498 | sizeof (EFI_IPv4_ADDRESS)\r | |
2499 | );\r | |
2500 | }\r | |
2501 | if (Private->ServerIp.Addr[0] == 0) {\r | |
2502 | return EFI_DEVICE_ERROR;\r | |
dc361cc5 | 2503 | }\r |
2504 | \r | |
2505 | ASSERT (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL);\r | |
2506 | \r | |
2507 | //\r | |
2508 | // bootlfile name\r | |
2509 | //\r | |
2510 | Private->BootFileName = (CHAR8 *) (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE]->Data);\r | |
2511 | \r | |
2512 | if (Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN] != NULL) {\r | |
2513 | //\r | |
2514 | // Already have the bootfile length option, compute the file size\r | |
2515 | //\r | |
e48e37fc | 2516 | CopyMem (&Value, Packet->Dhcp4Option[PXEBC_DHCP4_TAG_INDEX_BOOTFILE_LEN]->Data, sizeof (Value));\r |
dc361cc5 | 2517 | Value = NTOHS (Value);\r |
2518 | *BufferSize = 512 * Value;\r | |
2519 | Status = EFI_BUFFER_TOO_SMALL;\r | |
2520 | } else {\r | |
2521 | //\r | |
2522 | // Get the bootfile size from tftp\r | |
2523 | //\r | |
2524 | Status = PxeBc->Mtftp (\r | |
2525 | PxeBc,\r | |
2526 | EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,\r | |
2527 | Buffer,\r | |
2528 | FALSE,\r | |
2529 | BufferSize,\r | |
2530 | &BlockSize,\r | |
2531 | &Private->ServerIp,\r | |
2532 | (UINT8 *) Private->BootFileName,\r | |
2533 | NULL,\r | |
2534 | FALSE\r | |
2535 | );\r | |
2536 | }\r | |
2537 | \r | |
2538 | Private->FileSize = (UINTN) *BufferSize;\r | |
2539 | \r | |
2540 | return Status;\r | |
2541 | }\r | |
2542 | \r | |
dc361cc5 | 2543 | /**\r |
f737cfb9 | 2544 | Causes the driver to load a specified file.\r |
2545 | \r | |
2546 | @param This Protocol instance pointer.\r | |
2547 | @param FilePath The device specific path of the file to load.\r | |
2548 | @param BootPolicy If TRUE, indicates that the request originates from the \r | |
2549 | boot manager is attempting to load FilePath as a boot\r | |
2550 | selection. If FALSE, then FilePath must match as exact file\r | |
2551 | to be loaded.\r | |
2552 | @param BufferSize On input the size of Buffer in bytes. On output with a return\r | |
2553 | code of EFI_SUCCESS, the amount of data transferred to \r | |
2554 | Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,\r | |
2555 | the size of Buffer required to retrieve the requested file.\r | |
2556 | @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,\r | |
2557 | then no the size of the requested file is returned in \r | |
2558 | BufferSize.\r | |
2559 | \r | |
2560 | @retval EFI_SUCCESS The file was loaded.\r | |
2561 | @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy\r | |
2562 | @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or \r | |
2563 | BufferSize is NULL.\r | |
2564 | @retval EFI_NO_MEDIA No medium was present to load the file.\r | |
2565 | @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.\r | |
2566 | @retval EFI_NO_RESPONSE The remote system did not respond.\r | |
2567 | @retval EFI_NOT_FOUND The file was not found.\r | |
2568 | @retval EFI_ABORTED The file load process was manually cancelled.\r | |
dc361cc5 | 2569 | \r |
2570 | **/\r | |
2571 | EFI_STATUS\r | |
2572 | EFIAPI\r | |
2573 | EfiPxeLoadFile (\r | |
2574 | IN EFI_LOAD_FILE_PROTOCOL * This,\r | |
2575 | IN EFI_DEVICE_PATH_PROTOCOL * FilePath,\r | |
2576 | IN BOOLEAN BootPolicy,\r | |
2577 | IN OUT UINTN *BufferSize,\r | |
2578 | IN VOID *Buffer OPTIONAL\r | |
2579 | )\r | |
2580 | {\r | |
2581 | PXEBC_PRIVATE_DATA *Private;\r | |
2582 | EFI_PXE_BASE_CODE_PROTOCOL *PxeBc;\r | |
2583 | BOOLEAN NewMakeCallback;\r | |
2584 | UINTN BlockSize;\r | |
2585 | EFI_STATUS Status;\r | |
2586 | UINT64 TmpBufSize;\r | |
2587 | \r | |
2588 | Private = PXEBC_PRIVATE_DATA_FROM_LOADFILE (This);\r | |
2589 | PxeBc = &Private->PxeBc;\r | |
2590 | NewMakeCallback = FALSE;\r | |
2591 | BlockSize = 0x8000;\r | |
2592 | Status = EFI_DEVICE_ERROR;\r | |
2593 | \r | |
2594 | if (This == NULL || BufferSize == NULL) {\r | |
2595 | \r | |
2596 | return EFI_INVALID_PARAMETER;\r | |
2597 | }\r | |
2598 | \r | |
2599 | //\r | |
2600 | // Only support BootPolicy\r | |
2601 | //\r | |
2602 | if (!BootPolicy) {\r | |
2603 | return EFI_UNSUPPORTED;\r | |
2604 | }\r | |
2605 | \r | |
2606 | Status = PxeBc->Start (PxeBc, FALSE);\r | |
2607 | if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {\r | |
2608 | return Status;\r | |
2609 | }\r | |
2610 | \r | |
2611 | Status = gBS->HandleProtocol (\r | |
2612 | Private->Controller,\r | |
2613 | &gEfiPxeBaseCodeCallbackProtocolGuid,\r | |
2614 | (VOID **) &Private->PxeBcCallback\r | |
2615 | );\r | |
2616 | if (Status == EFI_UNSUPPORTED) {\r | |
2617 | \r | |
2618 | CopyMem (&Private->LoadFileCallback, &mPxeBcCallBackTemplate, sizeof (Private->LoadFileCallback));\r | |
2619 | \r | |
2620 | Status = gBS->InstallProtocolInterface (\r | |
2621 | &Private->Controller,\r | |
2622 | &gEfiPxeBaseCodeCallbackProtocolGuid,\r | |
2623 | EFI_NATIVE_INTERFACE,\r | |
2624 | &Private->LoadFileCallback\r | |
2625 | );\r | |
2626 | \r | |
2627 | NewMakeCallback = (BOOLEAN) (Status == EFI_SUCCESS);\r | |
2628 | \r | |
2629 | Status = PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);\r | |
2630 | if (EFI_ERROR (Status)) {\r | |
2631 | PxeBc->Stop (PxeBc);\r | |
2632 | return Status;\r | |
2633 | }\r | |
2634 | }\r | |
2635 | \r | |
2636 | if (Private->FileSize == 0) {\r | |
2637 | TmpBufSize = 0;\r | |
2638 | Status = DiscoverBootFile (Private, &TmpBufSize, Buffer);\r | |
2639 | \r | |
2640 | if (sizeof (UINTN) < sizeof (UINT64) && (TmpBufSize > 0xFFFFFFFF)) {\r | |
2641 | Status = EFI_DEVICE_ERROR;\r | |
39941daf | 2642 | } else if (TmpBufSize > 0 && *BufferSize >= (UINTN) TmpBufSize && Buffer != NULL) {\r |
319075ff | 2643 | *BufferSize = (UINTN) TmpBufSize;\r |
2644 | Status = PxeBc->Mtftp (\r | |
2645 | PxeBc,\r | |
2646 | EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r | |
2647 | Buffer,\r | |
2648 | FALSE,\r | |
2649 | &TmpBufSize,\r | |
2650 | &BlockSize,\r | |
2651 | &Private->ServerIp,\r | |
2652 | (UINT8 *) Private->BootFileName,\r | |
2653 | NULL,\r | |
2654 | FALSE\r | |
2655 | );\r | |
39941daf | 2656 | } else if (TmpBufSize > 0) {\r |
dc361cc5 | 2657 | *BufferSize = (UINTN) TmpBufSize;\r |
319075ff | 2658 | Status = EFI_BUFFER_TOO_SMALL;\r |
dc361cc5 | 2659 | }\r |
319075ff | 2660 | } else if (Buffer == NULL || Private->FileSize > *BufferSize) {\r |
dc361cc5 | 2661 | *BufferSize = Private->FileSize;\r |
2662 | Status = EFI_BUFFER_TOO_SMALL;\r | |
2663 | } else {\r | |
2664 | //\r | |
2665 | // Download the file.\r | |
2666 | //\r | |
2667 | TmpBufSize = (UINT64) (*BufferSize);\r | |
2668 | Status = PxeBc->Mtftp (\r | |
2669 | PxeBc,\r | |
2670 | EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r | |
2671 | Buffer,\r | |
2672 | FALSE,\r | |
2673 | &TmpBufSize,\r | |
2674 | &BlockSize,\r | |
2675 | &Private->ServerIp,\r | |
2676 | (UINT8 *) Private->BootFileName,\r | |
2677 | NULL,\r | |
2678 | FALSE\r | |
2679 | );\r | |
2680 | }\r | |
2681 | //\r | |
2682 | // If we added a callback protocol, now is the time to remove it.\r | |
2683 | //\r | |
2684 | if (NewMakeCallback) {\r | |
2685 | \r | |
2686 | NewMakeCallback = FALSE;\r | |
2687 | \r | |
2688 | PxeBc->SetParameters (PxeBc, NULL, NULL, NULL, NULL, &NewMakeCallback);\r | |
2689 | \r | |
2690 | gBS->UninstallProtocolInterface (\r | |
2691 | Private->Controller,\r | |
2692 | &gEfiPxeBaseCodeCallbackProtocolGuid,\r | |
2693 | &Private->LoadFileCallback\r | |
2694 | );\r | |
2695 | }\r | |
619eff3f | 2696 | \r |
dc361cc5 | 2697 | //\r |
2698 | // Check download status\r | |
2699 | //\r | |
619eff3f | 2700 | if (Status == EFI_SUCCESS) {\r |
8792362f | 2701 | return EFI_SUCCESS;\r |
dc361cc5 | 2702 | \r |
619eff3f | 2703 | } else if (Status == EFI_BUFFER_TOO_SMALL) {\r |
dc361cc5 | 2704 | if (Buffer != NULL) {\r |
2705 | AsciiPrint ("PXE-E05: Download buffer is smaller than requested file.\n");\r | |
2706 | } else {\r | |
2707 | return Status;\r | |
2708 | }\r | |
dc361cc5 | 2709 | \r |
619eff3f | 2710 | } else if (Status == EFI_DEVICE_ERROR) {\r |
dc361cc5 | 2711 | AsciiPrint ("PXE-E07: Network device error.\n");\r |
dc361cc5 | 2712 | \r |
619eff3f | 2713 | } else if (Status == EFI_OUT_OF_RESOURCES) {\r |
dc361cc5 | 2714 | AsciiPrint ("PXE-E09: Could not allocate I/O buffers.\n");\r |
dc361cc5 | 2715 | \r |
619eff3f | 2716 | } else if (Status == EFI_NO_MEDIA) {\r |
dc361cc5 | 2717 | AsciiPrint ("PXE-E12: Could not detect network connection.\n");\r |
dc361cc5 | 2718 | \r |
619eff3f | 2719 | } else if (Status == EFI_NO_RESPONSE) {\r |
dc361cc5 | 2720 | AsciiPrint ("PXE-E16: No offer received.\n");\r |
dc361cc5 | 2721 | \r |
619eff3f | 2722 | } else if (Status == EFI_TIMEOUT) {\r |
dc361cc5 | 2723 | AsciiPrint ("PXE-E18: Server response timeout.\n");\r |
dc361cc5 | 2724 | \r |
619eff3f | 2725 | } else if (Status == EFI_ABORTED) {\r |
dc361cc5 | 2726 | AsciiPrint ("PXE-E21: Remote boot cancelled.\n");\r |
dc361cc5 | 2727 | \r |
619eff3f | 2728 | } else if (Status == EFI_ICMP_ERROR) {\r |
dc361cc5 | 2729 | AsciiPrint ("PXE-E22: Client received ICMP error from server.\n");\r |
dc361cc5 | 2730 | \r |
619eff3f | 2731 | } else if (Status == EFI_TFTP_ERROR) {\r |
dc361cc5 | 2732 | AsciiPrint ("PXE-E23: Client received TFTP error from server.\n");\r |
dc361cc5 | 2733 | \r |
619eff3f | 2734 | } else {\r |
dc361cc5 | 2735 | AsciiPrint ("PXE-E99: Unexpected network error.\n");\r |
dc361cc5 | 2736 | }\r |
2737 | \r | |
2738 | PxeBc->Stop (PxeBc);\r | |
2739 | \r | |
2740 | return Status;\r | |
2741 | }\r | |
2742 | \r | |
434ce3fe | 2743 | EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate = { EfiPxeLoadFile };\r |
2744 | \r |