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